bug-apl
[Top][All Lists]
Advanced

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

Re: [Bug-apl] edit 'function_name' (2)


From: Christian Robert
Subject: Re: [Bug-apl] edit 'function_name' (2)
Date: Fri, 23 Dec 2016 22:06:00 -0500
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1

Bad formatting, second try.

------------ cut from here --------
      )sic
      )erase  edit
      ∇skipwrite edit funct;fd;lines;fs_name;z;r;SaveTTY
fs_name←18 ⎕cr funct                                     ⍝ The file name in the 
filesystem
⍝ ---------------------------------------------------------------------------
⍝ Check if it is  a request to reedit the previous written file in filesystem
⍝ very usefull in case of a syntax error while ⎕fx 'ing the function ...
⍝ ---------------------------------------------------------------------------
→(2=⎕nc 'skipwrite')/SkipWrite                           ⍝ If a left arg then 
skip write to the file
lines←{(⎕ucs 10),⍨(∼⌽∧\⌽⍵=' ')/⍵} ¨ ⊂[⎕io+1] ⎕cr funct   ⍝ The lines of the 
function
⍝ --------------------------------------------------
⍝ write the contents of this "funct" into the file
⍝ --------------------------------------------------
→(0>fd← "w" ⎕FIO[3] fs_name)/Error                       ⍝ Open for writing
⊣ {⍵ ⎕FIO[23] fd} ¨ lines                                ⍝ write all lines
⊣ ⎕FIO[4] fd                                             ⍝ Close the file
⍝ --------------------------------------------------
⍝ Now do the actual edition ...
⍝ --------------------------------------------------
SkipWrite:
SaveTTY←⎕IO⊃⍎')HOST stty -g'
⊣⍎')HOST >/dev/tty stty sane'⊣⍎')HOST >/dev/tty ','/usr/bin/vi',' ',fs_name
⊣⍎')HOST >/dev/tty stty ',SaveTTY
⍝ ----------------
⍝ and try ⎕fx it
⍝ ----------------
→(0≠"r" ⎕fio[31] fs_name)/Error                          ⍝ Can not read file ? 
→ Error
z←⎕fio[26] fs_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] fs_name                                       ⍝ Open the file
⊣ {⊣z[⍵]←⊂19 ⎕cr ⎕ucs ¯1↓⎕fio[8] fd} ⍤0 lines            ⍝ Put each line in the 
preallocated "z"
⊣ ⎕fio[4] fd ⋄ →Fix                                      ⍝ Close the file and 
⎕FX it
Error: ⎕ES ∊'Error on file "',fs_name,'": ',⎕fio[2] | ⎕fio[1] ''
Fix: r←⎕fx z
⍝ 
----------------------------------------------------------------------------------------
⍝ Well, if "r" is an integer then it is a syntax error, if it is a string then 
it succeed.
⍝ 
----------------------------------------------------------------------------------------
⍝
→(0=↑0⍴r)/Syntax                                         ⍝ A number → then a 
systax error
Ok: ⎕←∊ "Function '" (r) ("' saved.") ⋄ →0                 ⍝ Probably a 
succesfull save or a rename.
⍝ ----------------------------------
⍝ We get here on errors while saving
⍝ ----------------------------------
Syntax: 9 ⎕cr "Beware that you can not edit a running function or a suspended function on the 
stack, try )sic before launching \"edit\"."
∊ "Error at line:" (z) ("( Use: 1 edit '" funct "' ) to have a chance to fix it 
without having to reenter all your latest modifications.")
∇
------------ to here --------

sorry,
Xtian.

On 2016-12-23 21:52, Christian Robert wrote:
Much better than yesterday. It work like a charm. Not completely tested through.

Feel free to improve.

Xtian.



reply via email to

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