Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > Peculiarities of ascii file processing with GT.M
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 5th November 08:56
sébastien_de_mapias
External User
 
Posts: 1
Default Peculiarities of ascii file processing with GT.M



Hello,


readfile
w "in test rf",!
n f
s f="gtm/t.txt"
o fexception="g BADOPEN")
w "OK file open",!
u f:exception="g EOF"
f u f r line u $p w line,!
c f
u 0
w "ok out of loop now",!
w "ok file closed",!
q
EOF if '$ZEOf zm +$ZS
close f
q
BADOPEN if $P($ZS,",",1)=2 d q
.write !,"The file ",f," does not exist."
if $P($ZS,",",1)=13 d q
. w !,"The file ",f," is not accessible."
ZM +$ZS
q

I have a few questions:
1/ is there a way to tell the 'mumps' program not to
remove the carriage returns from the text lines ?
how come I have to add a '!' to the 'write' function ?
2/ 'r[ead] line' processes an entire line - is it possible
to deal with characters one at a time only when
reading from a file ?
3/ at the GTM prompt I do see my "in test rf" but
once I'm out of the 'for' loop I don't see my 2
other 'write' instructions ("ok out of loop now" and
"ok file closed"): what's wrong ? (I tried with 'use 0'
and 'use $p')

Thanks !
Regards,
Sébastien
  Reply With Quote


 


2 5th November 08:56
sébastien_de_mapias
External User
 
Posts: 1
Default Peculiarities of ascii file processing with GT.M



sneak around and properly leave the FOR loop to continue with the
lines that follow it here ?:

~ readfile
~ w "in test rf",!
~ ....
~ f u f r line u $p w line,!
~ c f ; <= I want to reach this line
~ u 0 ; and those that follow...
~ w "ok out of loop now",!
~ w "ok file closed",!
~ q
  Reply With Quote
3 5th November 08:56
sébastien_de_mapias
External User
 
Posts: 1
Default Peculiarities of ascii file processing with GT.M


I've found on http://vmth.ucdavis.edu/us/jaself's pages
beautiful examples of M[umps], and could answer my
3rd question by doing the following:
~ for do quit:fdf
~ . use f read line set fdf=$zeof
~ . w "fdf = "_fdf
~ . use $p w " line is "_line,!

(you really have to get accustomed to such a syntax !!:
no 'while' construct, this "two-space" very delicate way
of writing your instructions -"for do quit"-, the colon to
give the exit condition etc etc... something really unusual)

Thanks.
  Reply With Quote
4 5th November 08:56
rodd
External User
 
Posts: 1
Default Peculiarities of ascii file processing with GT.M


Most (all?) implementations allow you to open the file in a raw just
gimme all the bytes mode. Most of the time you don't want that, you
just want to read a 'line' and let the underlying implementation deal
with how the line is 'ended'.

Don't forget, in addition to the Mac carriage return line endings you
apparently are dealing with it could might be a Unix line feed line
ending. In fact, I remember hearing about some other obscure system
that couldn't make up its mind and uses both carriage return and line feed.


You don't have to. Its only needed then you want to cause a new line operation.


Yes, lookup what "READ *X" and "READ X#1" will do in your MUMPS
manual.

--
-- Rod --
rodd(at)polylogics(dot)com
  Reply With Quote


 


Reply


Thread Tools
Display Modes




666