|
From: | Elias Mårtenson |
Subject: | Re: [Bug-apl] Request to add to the ⎕fio[] a 'function_common_name' as argument |
Date: | Wed, 4 Jan 2017 15:52:52 +0800 |
Not *exactly*. Since QuadFIO is part of gnu-apl, why not improve the QuadFIO so it is essayer to use.
Xtian.
On 2017-01-04 01:59, Elias Mårtenson wrote:
Isn't this exactly what wslib5/FILE_IO.apl is?
Regards,
Elias
On 4 January 2017 at 14:16, Christian Robert <address@hidden <mailto:address@hiddentl.ca >> wrote:
I would love to be able to do:
fd ←⎕fio['open'] '.bashrc'
⎕fio['fclose'] fd
and so on ...
I have a Workspace named "fio" who just do that, but I would love if gnu-apl could just understand 'open'/'close'/... rather than just random numbers, as actually.
Numbers are fine, but a tagged name as in ⎕fio['bind'] would be a *plus*. (no need for us to remember the random numbers, only the function name)
Yes, a couple of hours for Juergen to code it, but so much reliefs/and/easier on our side, as end user.
my wishes for 2017 ;-)
Xtian.
)load fio
SAVED 2016-12-27 20:04:36 (GMT-5)
df
errno ╔════════════╗
║z←errno ║
║z←⎕fio[1] ''║
╚════════════╝
fio ╔══════════╗
║fio ║
║'' ⎕fio ''║
╚══════════╝
getcwd ╔═════════╗
║z←getcwd ║
║z←⎕fio 30║
╚═════════╝
helper ╔═══════════════════════════════════════════════════════════ ═══╗
║z←helper what;this;t ║
║→((≡what)<2)/Single ║
║z←helper ¨ what ║
║→(∧/1=,⊃⍴¨,¨z)/FinalDisclose ║
║⎕ES 'Error: Problem converting at least one of the parameters'║
║→0 ║
║FinalDisclose: ║
║z←,⊃⊃¨z ⍝ Be sure we return a vector of hopefully integers ║
║→0 ║
║Single: ║
║⍝ ║
║⍝ Most usefull socket constant ║
║⍝ ║
║t←0 2⍴'' 0 ║
║t←t⍪"AF_UNSPEC" 0 ║
║t←t⍪"AF_LOCAL" 1 ║
║t←t⍪"AF_UNIX" 1 ║
║t←t⍪"AF_INET" 2 ║
║t←t⍪"AF_SNA" 22 ║
║t←t⍪"AF_DECnet" 12 ║
║t←t⍪"AF_APPLETALK" 5 ║
║t←t⍪"AF_ROUTE" 16 ║
║t←t⍪"AF_IPX" 4 ║
║t←t⍪"AF_ISDN" 34 ║
║t←t⍪"AF_INET6" 10 ║
║t←t⍪"AF_BLUETOOTH" 31 ║
║t←t⍪"AF_MAX" 41 ║
║t←t⍪"PF_INET" 2 ║
║t←t⍪"PF_LOCAL" 1 ║
║t←t⍪"PF_UNIX" 1 ║
║t←t⍪"SOCK_STREAM" 1 ║
║t←t⍪"SOCK_DGRAM" 2 ║
║t←t⍪"SOCK_RAW" 3 ║
║t←t⍪"SOCK_RDM" 4 ║
║t←t⍪"SOCK_SEQPACKET" 5 ║
║t←t⍪"SOCK_DCCP" 6 ║
║t←t⍪"SOCK_PACKET" 10 ║
║t←t⍪"SOCK_CLOEXEC" 524288 ║
║t←t⍪"SOCK_NONBLOCK" 2048 ║
║t←t⍪"IPPROTO_IP" 0 ║
║t←t⍪"IPPROTO_ICMP" 1 ║
║t←t⍪"IPPROTO_IPIP" 4 ║
║t←t⍪"IPPROTO_TCP" 6 ║
║t←t⍪"IPPROTO_PUP" 12 ║
║t←t⍪"IPPROTO_UDP" 17 ║
║t←t⍪"IPPROTO_IDP" 22 ║
║t←t⍪"IPPROTO_TP" 29 ║
║t←t⍪"IPPROTO_DCCP" 33 ║
║t←t⍪"IPPROTO_IPV6" 41 ║
║t←t⍪"IPPROTO_ROUTING" 43 ║
║t←t⍪"IPPROTO_FRAGMENT" 44 ║
║t←t⍪"IPPROTO_RSVP" 46 ║
║t←t⍪"IPPROTO_GRE" 47 ║
║t←t⍪"IPPROTO_ESP" 50 ║
║t←t⍪"IPPROTO_AH" 51 ║
║t←t⍪"IPPROTO_ICMPV6" 58 ║
║t←t⍪"IPPROTO_NONE" 59 ║
║t←t⍪"IPPROTO_DSTOPTS" 60 ║
║t←t⍪"IPPROTO_MTP" 92 ║
║t←t⍪"IPPROTO_ENCAP" 98 ║
║t←t⍪"IPPROTO_PIM" 103 ║
║t←t⍪"IPPROTO_COMP" 108 ║
║t←t⍪"IPPROTO_SCTP" 132 ║
║t←t⍪"IPPROTO_UDPLITE" 136 ║
║t←t⍪"IPPROTO_RAW" 255 ║
║t←t⍪"SOL_SOCKET" 1 ║
║t←t⍪"SO_BINDTODEVICE" 25 ║
║t←t⍪"SO_REUSEADDR" 2 ║
║t←t⍪"SO_BROADCAST" 6 ║
║t←t⍪"INADDR_ANY" 0 ║
║⍝ ║
║⍝ Replace thoses I recognize by their value ║
║⍝ leaving the rest as they were ║
║⍝ ║
║→(0=↑0⍴what)/NotSpecial ⍝ can't be an IP ║
║→(3≠+/'.'=,what)/NotSpecial ⍝ can't be an IP ║
║this←,what ⍝ an IP address ║
║(('.'=this)/this)←' ' ⍝ DOT to space ║
║z←(4⍴256)⊥⍎this ⍝ change this IP to integer ║
║→0 ║
║NotSpecial: ║
║this←⊂what ⍝ enclose the input for diadic '⍳' ║
║z←(,t[;1]) ⍳ this ⍝ search for recognized constants into 't'║
║→(z>↑⍴t)/ReturnAsis ⍝ no match ║
║z←t[z;2] ⍝ do the substitution ║
║→0 ║
║ReturnAsis: z←what ⍝ return original parameter unchanged ║
╚═══════════════════════════════════════════════════════════ ═══╝
readfile_fast ╔═══════════════════════════════════════════════════════════ ══════════════════════════╗
║z←readfile_fast name;fd;lines;⎕io ║
║⎕io←1 ⍝ Bring a file into a vector of strings, utf8 aware for both name and contents.║
║→(0≠"r" ⎕fio[31] 18 ⎕cr name)/Error ⍝ Can not read file ? → Error ║
║z←⎕fio[26] 18 ⎕cr name ⍝ First pass, read the whole file ║
║lines←⍳+/((↑"\n")=z) ⍝ Compute the iota for each line ║
║z←(⍴lines)⍴⍬ ⍝ Preallocate "z" to the right size ║
║fd←⎕fio[3] 18 ⎕cr name ⍝ Open the file ║
║⊣ {⊣z[⍵]←⊂19 ⎕cr ⎕ucs ¯1↓⎕fio[8] fd} ⍤0 lines ⍝ Put each line in the preallocated "z"║
║⊣ ⎕fio[4] fd ⋄ →0 ⍝ Close the file and return ║
║Error: ⎕ES ∊'Error on file "',name,'": ',⎕fio[2] | ⎕fio[1] '' ║
╚══════════════════════════════════════════════════════════ ═══════════════════════════╝
accept←{⎕fio[35] ⍵}
access←{⍺ ⎕fio[31] ⍵}
bind←{⍺ ⎕fio[33] ⍵}
connect←{⍺ ⎕fio[36] ⍵}
fclose←{⎕fio[4] ⍵}
feof←{⎕fio[10] ⍵}
ferror←{⎕fio[11] ⍵}
fflush←{⎕fio[16] ⍵}
fgetc←{⎕fio[9] ⍵}
fgets←{⍺ ⎕fio[8] ⍵}
fopen←{⍺ ⎕fio[3] ⍵}
fread←{⍺ ⎕fio[6] ⍵}
fscanf←{⍺ ⎕fio[48] ⍵}
fseek_cur←{⍺ ⎕fio[14] ⍵}
fseek_end←{⍺ ⎕fio[15] ⍵}
fseek_set←{⍺ ⎕fio[13] ⍵}
fstat←{⎕fio[18] ⍵}
fsync←{⎕fio[17] ⍵}
ftell←{⎕fio[12] ⍵}
fwrite←{⍺ ⎕fio[7] ⍵}
getpeername←{⎕fio[45] ⍵}
getsockname←{⎕fio[44] ⍵}
getsockopt←{⍺ ⎕fio[46] ⍵}
listen←{⍺ ⎕fio[34] ⍵}
ls←{⎕fio[29] ⍵}
ls_full←{⎕fio[28] ⍵}
ltrim←{(+/^\' '=⍵)↓⍵}
mkdir←{⍺ ⎕fio[20] ⍵}
pclose←{⎕fio[25] ⍵}
popen←{⍺ ⎕fio[24] ⍵}
read←{⍺ ⎕fio[41] ⍵}
readfile←{⎕fio[26] ⍵}
recv←{⍺ ⎕fio[37] ⍵}
rename←{⍺ ⎕fio[27] ⍵}
rmdir←{⎕fio[21] ⍵}
rtrim←{⌽ ltrim ⌽ ⍵}
select←{⎕fio[40] ⍵}
send←{⍺ ⎕fio[38] ⍵}
setsockopt←{⍺ ⎕fio[47] ⍵}
socket←{⎕fio[32] ⍵}
strerror←{⎕fio[2] |⍵}
unlink←{⎕fio[19] ⍵}
usend←{⍺ ⎕fio[39] ⍵}
uwrite←{⍺ ⎕fio[43] ⍵}
write←{⍺ ⎕fio[42] ⍵}
[Prev in Thread] | Current Thread | [Next in Thread] |