bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] Reverse of ⎕FIO[43] ?


From: Christian Robert
Subject: Re: [Bug-apl] Reverse of ⎕FIO[43] ?
Date: Fri, 11 Mar 2016 13:56:42 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0

Thanks,  *18⎕CR* and *19⎕CR* work like a charm !

Xtian.

On 2016-03-10 16:18, Juergen Sauermann wrote:
Hi Christian,

the problem with *read()* and UTF8 is that you don't know beforehand
if a file is properly UTF8 encoded.

To convert between byte vectors (as returned by *read()*) and text vectors (= 
APL strings),
you can use *18⎕CR* and *19⎕CR* in GNU APL.

/// Jürgen


On 03/10/2016 03:18 AM, Christian Robert wrote:
Assume f2c take a function name and return each function line, removing 
trailings blanks and adding LINEFEED to each one.

      f2c←{(⎕ucs 10),⍨¨{(∼⌽∧\⌽⍵=' ')/⍵}¨{⊂[2]⎕cr ⍵} ⍵}

      f2c 'Execute'  ⍝ Execute is an example function. Any function is ok here
 z←Execute cmd;⎕io;fh
 ⎕io←0
 fh ← ⎕FIO[24] cmd
 z←⊂¯1↓⎕av[⎕fio [8] fh]
 Loop: →(0≠⎕FIO[10] fh)/Fini
 z←z,⊂¯1↓⎕av[⎕fio [8] fh]
 →Loop
 Fini: ⊣ ⎕FIO[25] fh
 z←⊃z

      ⍴ f2c 'Execute'
9
      ⍝ it's a vector of 9 enclosed LF terminated lines.

      'w' ⎕fio[3] 'Execute.apl' ⍝ Open output file ie: fopen("Execute.apl","w")
6
      {⍵ ⎕FIO[43] 6} ¨ f2c 'Execute'   ⍝ Write each line to the Output file 
returning the length/bytes of each written line
25 10 22 34 34 36 8 24 9

      ⎕FIO[4] 6  ⍝ Close the output file
0

      ⎕FIO[26] 'Execute.apl' ⍝ read the whole file
zâExecute cmd;âio;fh
âioâ0
fh â âFIO[24] cmd
zââ¯1ââav[âfio [8] fh]
Loop: â(0â âFIO[10] fh)/Fini
zâz,â¯1ââav[âfio [8] fh]
âLoop
Fini: ⣠âFIO[25] fh
zââz

It has not been read in UTF8 mode, only in bytes mode.

The problem is that there is no ⎕FIO, to my knowledge, able to read it back 
(eg: From UTF8 to Ac style)

      ⎕FIO ''
   Functions provided by ⎕FIO...

   Legend: a - address family, IPv4 address, port (or errno)
           d - table of dirent structs
           e - error code (integer as per errno.h)
           h - file handle (integer)
           i - integer
           n - names (nested vector of strings)
           s - string
           A1, A2, ...  nested vector with elements A1, A2, ...

           ⎕FIO     ''    print this text on stderr
        '' ⎕FIO     ''    print this text on stdout
           ⎕FIO[ 0] ''    print this text on stderr
        '' ⎕FIO[ 0] ''    print this text on stdout

   Zi ←    ⎕FIO[ 1] ''    errno (of last call)
   Zs ←    ⎕FIO[ 2] Be    strerror(Be)
   Zh ← As ⎕FIO[ 3] Bs    fopen(Bs, As) filename Bs mode As
   Zh ←    ⎕FIO[ 3] Bs    fopen(Bs, "r") filename Bs

File I/O functions:

   Ze ←    ⎕FIO[ 4] Bh    fclose(Bh)
   Ze ←    ⎕FIO[ 5] Bh    errno (of last call on Bh)
   Zi ←    ⎕FIO[ 6] Bh    fread(Zi, 1, 5000, Bh) 1 byte per Zi
   Zi ← Ai ⎕FIO[ 6] Bh    fread(Zi, 1, Ai, Bh) 1 byte per Zi
   Zi ← Ai ⎕FIO[ 7] Bh    fwrite(Ai, 1, ⍴Ai, Bh) 1 byte per Ai
   Zi ←    ⎕FIO[ 8] Bh    fgets(Zi, 5000, Bh) 1 byte per Zi
   Zi ← Ai ⎕FIO[ 8] Bh    fgets(Zi, Ai, Bh) 1 byte per Zi
   Zi ←    ⎕FIO[ 9] Bh    fgetc(Zi, Bh) 1 byte
   Zi ←    ⎕FIO[10] Bh    feof(Bh)
   Zi ←    ⎕FIO[11] Bh    ferror(Bh)
   Zi ←    ⎕FIO[12] Bh    ftell(Bh)
   Zi ← Ai ⎕FIO[13] Bh    fseek(Bh, Ai, SEEK_SET)
   Zi ← Ai ⎕FIO[14] Bh    fseek(Bh, Ai, SEEK_CUR)
   Zi ← Ai ⎕FIO[15] Bh    fseek(Bh, Ai, SEEK_END)
   Zi ←    ⎕FIO[16] Bh    fflush(Bh)
   Zi ←    ⎕FIO[17] Bh    fsync(Bh)
   Zi ←    ⎕FIO[18] Bh    fstat(Bh)
   Zi ←    ⎕FIO[19] Bh    unlink(Bc)
   Zi ←    ⎕FIO[20] Bh    mkdir(Bc, 0777)
   Zi ← Ai ⎕FIO[20] Bh    mkdir(Bc, AI)
   Zi ←    ⎕FIO[21] Bh    rmdir(Bc)
   Zi ← A  ⎕FIO[22] 1     printf(         A1, A2...) format A1
   Zi ← A  ⎕FIO[22] 2     fprintf(stderr, A1, A2...) format A1
   Zi ← A  ⎕FIO[22] Bh    fprintf(Bh,     A1, A2...) format A1
   Zi ← Ac ⎕FIO[23] Bh    fwrite(Ac, 1, ⍴Ac, Bh) 1 Unicode per Ac, Output UTF8
   Zh ← As ⎕FIO[24] Bs    popen(Bs, As) command Bs mode As
   Zh ←    ⎕FIO[24] Bs    popen(Bs, "r") command Bs
   Ze ←    ⎕FIO[25] Bh    pclose(Bh)
   Zs ←    ⎕FIO[26] Bs    return entire file Bs as byte vector
   Zs ← As ⎕FIO[27] Bs    rename file As to Bs
   Zd ←    ⎕FIO[28] Bs    return content of directory Bs
   Zn ←    ⎕FIO[29] Bs    return file names in directory Bs
   Zs ←    ⎕FIO 30        getcwd()
   Zn ← As ⎕FIO[31] Bs    access(As, Bs) As ∈ 'RWXF'
   Zh ←    ⎕FIO[32] Bi    socket(Bi=AF_INET, SOCK_STREAM, 0)
   Ze ← Aa ⎕FIO[33] Bh    bind(Bh, Aa)
   Ze ←    ⎕FIO[34] Bh    listen(Bh, 10)
   Ze ← Ai ⎕FIO[34] Bh    listen(Bh, Ai)
   Za ←    ⎕FIO[35] Bh    accept(Bh)
   Ze ← Aa ⎕FIO[36] Bh    connect(Bh, Aa)
   Zi ←    ⎕FIO[37] Bh    recv(Bh, Zi, 5000, 0) 1 byte per Zi
   Zi ← Ai ⎕FIO[37] Bh    recv(Bh, Zi, Ai, 0) 1 byte per Zi
   Zi ← Ai ⎕FIO[38] Bh    send(Bh, Ai, ⍴Ai, 0) 1 byte per Ai
   Zi ← Ac ⎕FIO[39] Bh    send(Bh, Ac, ⍴Ac, 0) 1 Unicode per Ac, Output UTF8
   Zi ←    ⎕FIO[40] B     select(B_read, B_write, B_exception, B_timeout)
   Zi ←    ⎕FIO[41] Bh    read(Bh, Zi, 5000) 1 byte per Zi
   Zi ← Ai ⎕FIO[41] Bh    read(Bh, Zi, Ai) 1 byte per Zi
   Zi ← Ai ⎕FIO[42] Bh    write(Bh, Ai, ⍴Ai) 1 byte per Ai
   Zi ← Ac ⎕FIO[43] Bh    write(Bh, Ac, ⍴Ac) 1 Unicode per Ac, Output UTF8
   Za ←    ⎕FIO[44] Bh    getsockname(Bh)
   Za ←    ⎕FIO[45] Bh    getpeername(Bh)
   Zi ← Ai ⎕FIO[46] Bh    getsockopt(Bh, A_level, A_optname, Zi)
   Ze ← Ai ⎕FIO[47] Bh    setsockopt(Bh, A_level, A_optname, A_optval)

Benchmarking functions:

           ⎕FIO[200] Bi    clear statistics with ID Bi
   Zn ←    ⎕FIO[201] Bi    get statistics with ID Bi
           ⎕FIO[202] Bs    get monadic parallel threshold for primitive Bs
        Ai ⎕FIO[202] Bs    set monadic parallel threshold for primitive Bs
           ⎕FIO[203] Bs    get dyadic parallel threshold for primitive Bs
        Ai ⎕FIO[203] Bs    set dyadic parallel threshold for primitive Bs




this is missing. An intelligent/utf8 read.

Xtian.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]