Re : Pipes
Fadi Osman <[email protected]> Mon, 19 Dec 2011 07:23:57 +0000 (GMT)
| Newsgroups | gmane.comp.lang.sather.announce |
|---|---|
| Message-ID | <[email protected]> |
--840867960-2120912210-1324279437=:90096 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Hello Mike,=0A=0AI'll be away for two weeks - I think I can dedicate some t= ime for "maintenance" at the beginning of the year. (think of it as a New Y= ear's Resolution)=0A=0AHave you re-considered the offer of "officially" tak= ing care of GNU sather?=0A=0AMerry Christmas and a happy New Year,=0A=0AFad= i.=0A=0A=0A=0A>________________________________=0A> De=A0: Sather User <sat= [email protected]>=0A>=C0=A0: [email protected] =0A>Envoy=E9 le : Vendredi = 16 D=E9cembre 2011 9h18=0A>Objet=A0: Pipes=0A> =0A>Hello, all.=A0 In too mu= ch of a tizz to look in since my last super=0A>roughie. Sorry about it.=A0 = I quickly abandoned libtiff.=A0 I decided that=0A>re-implementation in Sath= er directly was a better approach than=0A>digesting the libtiff documentati= on.=A0 For example several TIFF tag=0A>values are rationals and Sather has = a rational type (RAT) but C does=0A>not so libtiff does a workaround and yo= u never seen the numerator and=0A>denominator of an XResolution, for exampl= e, only a floating point value.=0A>=0A>To hastily move on, here is an addit= ion you can make to=0A>Library/IO/file.sa.=A0 You can put it anywhere, but = that's what I did.=0A>I needed to look up the date from Sather, you see, to= put the DateTime=0A>tag into TIFF files, and I had to do that by running t= he shell=0A>command, date, and reading the response.=0A>=0A>This, I guess, = is another roughie.=A0 It works, that's all I know.=0A>=0A>----------------= ---------------------------------------------------=0A>partial class FILE_P= IPE is=0A>=A0 -- Things common to both=0A>=A0 readonly attr fp:EXT_OB;=A0= =A0 =A0 -- The FILE pointer readonly attr=0A>=0A>=A0 get_char:CHAR pre ~v= oid(fp) is=0A>=A0 =A0 =A0 return RUNTIME::fgetc(fp);=0A>=A0 end;=0A>=0A>= =A0 get_str:STR is=0A>=A0 =A0 =A0 -- A string containing the characters up= to the next newline.=0A>=A0 =A0 =A0 return get_line.str;=0A>=A0 end;=0A>= =0A>=A0 get_line:FSTR is=0A>=A0 =A0 =A0 -- A string buffer containing the = characters up to the next newline.=0A>=A0 =A0 =A0 res::=3D#FSTR;=0A>=A0 =A0= =A0 loop=0A>=A0 =A0 =A0 =A0 =A0 c::=3Dget_char;=0A>=A0 =A0 =A0 =A0 =A0 if = eof then return res end;=0A>=A0 =A0 =A0 =A0 =A0 -- Next 2 lines reversed mt= w Sep 2011=0A>=A0 =A0 =A0 =A0 =A0 until!(c=3D'\n');=0A>=A0 =A0 =A0 =A0 =A0 = res:=3Dres.push(c);=0A>=A0 =A0 =A0 end;=0A>=A0 =A0 =A0 return res;=0A>=A0 = end;=0A>=0A>=A0 get(s:STR):FLIST{STR} is=0A>=A0 =A0 =A0 p::=3Dopen_for_rea= d(s);=0A>=A0 =A0 =A0 if p.error then raise "oops" end;=0A>=A0 =A0 =A0 ans::= =3D#FLIST{STR};=0A>=A0 =A0 =A0 loop=0A>=A0 =A0 =A0 =A0 t::=3Dp.get_str;=0A= >=A0 =A0 =A0 =A0 while!(~p.eof);=0A>=A0 =A0 =A0 =A0 ans:=3Dans.push(t)=0A= >=A0 =A0 =A0 end;=0A>=A0 =A0 =A0 p.close;=0A>=A0 =A0 =A0 return ans=0A>=A0 = end;=0A>=0A>=0A>=0A>end;=0A>=0A>class PIPE is=0A>=A0 -- Not < $OSTREAM be= cause no plus...=0A>=A0 -- MTW Oct 2011=0A>=A0 -- The stdin/stdout of FIL= E maybe should be here.=0A>=A0 --=0A>=A0 -- Example:=0A>=A0 -- class MAI= N is=0A>=A0 --=A0 =A0 main is=0A>=A0 --=A0 =A0 =A0 p::=3DPIPE::open_for_= read("date +'%Y:%m:%d %H:%M:%S'");=0A>=A0 --=A0 =A0 =A0 s:STR:=3Dp.get_st= r;=0A>=A0 --=A0 =A0 =A0 p.close;=0A>=A0 --=A0 =A0 =A0 #OUT+s+"\n"; -- p= rints formatted date=0A>=A0 --=A0 =A0 end=0A>=A0 -- end=0A>=A0 --=0A>=A0= include FILE_PIPE;=0A>=0A>=A0 open_for_read(command:STR):SAME is=0A>=A0 = =A0 =A0 -- Open pipe for reading.=0A>=A0 =A0 =A0 r::=3Dnew;=0A>=A0 =A0 =A0 = r.fp:=3DRUNTIME::popen(command,"r");=0A>=A0 =A0 =A0 return r=0A>=A0 end;= =0A>=0A>=A0 close pre ~void(fp) is=0A>=A0 =A0 =A0 -- Close the pipe corres= ponding to self.=0A>=A0 =A0 =A0 RUNTIME::pclose(fp)=0A>=A0 end;=0A>=0A>=A0= error:BOOL is=0A>=A0 =A0 =A0 -- true is an error has occurred with this f= ile.=A0 Cleared by "clear".=0A>=A0 =A0 =A0 return void(fp) or RUNTIME::ferr= or(fp)=0A>=A0 end;=0A>=0A>=0A>=A0 eof:BOOL pre ~void(fp) is=0A>=A0 =A0 = =A0 -- true if EOF has been encountered.=A0 Cleared by "clear".=0A>=A0 =A0 = =A0 return RUNTIME::feof(fp)=0A>=A0 end;=0A>=0A>end;=0A>=0A>class FILE < $= OSTREAM is ... etc=0A>=0A>-------------------------------------------------= ------------=0A>=0A>Library/System/runtime.sa:=0A>=0A>external class RUNTIM= E is=0A>=A0=A0=A0 ...=0A>=A0=A0=A0 popen(nm:STR,tp:STR):EXT_OB;=0A>=A0=A0= =A0 pclose(fp:EXT_OB);=0A>=A0=A0=A0 ...=0A>=0A>----------------------------= -----------------------------------------=0A>=0A>Hope I haven't missed anyt= hing there.=A0 You can see from the commented=0A>example that it's easy as = pie, just one of the loose ends left undone=0A>in ICSI Sather.=0A>=0A>Merry= Christmas to all.=0A>=0A>--Mike=0A>=0A>=0A>-- =0A>Michael Talbot-Wilson=0A= >=0A>=0A>=0A> --840867960-2120912210-1324279437=:90096 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable <html><body><div style=3D"color:#000; background-color:#fff; font-family:ar= ial, helvetica, sans-serif;font-size:12pt"><div><span><div><span><font clas= s=3D"Apple-style-span">Hello Mike,</font></span></div><div><span><br></span= ></div><div><span>I'll be away for two weeks - I think I can dedicate some = time for "maintenance" at the beginning of the year. (think of it as a New = Year's Resolution)</span></div><div><span><br></span></div><div>Have you re= -considered the offer of "officially" taking care of GNU sather?</div><div>= <br></div><div>Merry Christmas and a happy New Year,<br></div><div>Fadi.</d= iv></span></div><div><br><blockquote style=3D"border-left: 2px solid rgb(16= , 16, 255); margin-left: 5px; margin-top: 5px; padding-left: 5px;"> <div s= tyle=3D"font-size: 12pt; font-family: arial, helvetica, sans-serif; "> <div= style=3D"font-size: 12pt; font-family: 'times new roman', 'new york', time= s, serif; "> <font size=3D"2" face=3D"Arial"> <hr size=3D"1"> <b><span style=3D"font-weight:bold;">De :</span></b> Sather User <sather@vi= ew.net.au><br> <b><span style=3D"font-weight: bold;">=C0 :</span></= b> [email protected] <br> <b><span style=3D"font-weight: bold;">Envoy=E9 = le :</span></b> Vendredi 16 D=E9cembre 2011 9h18<br> <b><span style=3D"font= -weight: bold;">Objet :</span></b> Pipes<br> </font> <br>Hello, all.&n= bsp; In too much of a tizz to look in since my last super<br>roughie. Sorry= about it. I quickly abandoned libtiff. I decided that<br>re-im= plementation in Sather directly was a better approach than<br>digesting the= libtiff documentation. For example several TIFF tag<br>values are ra= tionals and Sather has a rational type (RAT) but C does<br>not so libtiff d= oes a workaround and you never seen the numerator and<br>denominator of an = XResolution, for example, only a floating point value.<br><br>To hastily mo= ve on, here is an addition you can make to<br>Library/IO/file.sa. You= can put it anywhere, but that's what I did.<br>I needed to look up the date fr= om Sather, you see, to put the DateTime<br>tag into TIFF files, and I had t= o do that by running the shell<br>command, date, and reading the response.<= br><br>This, I guess, is another roughie. It works, that's all I know= .<br><br>------------------------------------------------------------------= -<br>partial class FILE_PIPE is<br> -- Things common to both<br>&nbs= p; readonly attr fp:EXT_OB; -- The FILE pointer readon= ly attr<br><br> get_char:CHAR pre ~void(fp) is<br> &nbs= p; return RUNTIME::fgetc(fp);<br> end;<br><br> get_str:STR is= <br> -- A string containing the characters up to the ne= xt newline.<br> return get_line.str;<br> end;<br= ><br> get_line:FSTR is<br> -- A string buffer co= ntaining the characters up to the next newline.<br> res::=3D#FSTR;<br> loop<br> = c::=3Dget_char;<br> if eof= then return res end;<br> -- Next 2 lines= reversed mtw Sep 2011<br> until!(c=3D'\n= ');<br> res:=3Dres.push(c);<br> &nb= sp; end;<br> return res;<br> end;<br><br>= get(s:STR):FLIST{STR} is<br> p::=3Dopen_for_rea= d(s);<br> if p.error then raise "oops" end;<br> &= nbsp; ans::=3D#FLIST{STR};<br> loop<br> &n= bsp; t::=3Dp.get_str;<br> while!= (~p.eof);<br> ans:=3Dans.push(t)<br> &nbs= p; end;<br> p.close;<br> ret= urn ans<br> end;<br><br><br><br>end;<br><br>class PIPE is<br> = -- Not < $OSTREAM because no plus...<br> -- MTW Oct 2011<br> -- = The stdin/stdout of FILE maybe should be here.<br> --<br> -- = Example:<br> -- class MAIN is<br> -- main is<br>= -- p::=3DPIPE::open_for_read("date +'%Y:%m:%d = %H:%M:%S'");<br> -- s:STR:=3Dp.get_str;<br>&nbs= p; -- p.close;<br> -- #OU= T+s+"\n"; -- prints formatted date<br> -- end<br> = -- end<br> --<br> include FILE_PIPE;<br><br> open_fo= r_read(command:STR):SAME is<br> -- Open pipe for readin= g.<br> r::=3Dnew;<br> r.fp:=3DRUNTI= ME::popen(command,"r");<br> return r<br> end;<br= ><br> close pre ~void(fp) is<br> -- Close the pi= pe corresponding to self.<br> RUNTIME::pclose(fp)<br> end;<br><br> error:BOOL is<br> = -- true is an error has occurred with this file. Clear= ed by "clear".<br> return void(fp) or RUNTIME::ferror(f= p)<br> end;<br><br><br> eof:BOOL pre ~void(fp) is<br> &= nbsp; -- true if EOF has been encountered. Cleared by "clear".= <br> return RUNTIME::feof(fp)<br> end;<br><br>en= d;<br><br>class FILE < $OSTREAM is ... etc<br><br>----------------------= ---------------------------------------<br><br>Library/System/runtime.sa:<b= r><br>external class RUNTIME is<br> ...<br> &n= bsp; popen(nm:STR,tp:STR):EXT_OB;<br> pclose(fp:EXT_OB);<= br> ...<br><br>------------------------------------------= ---------------------------<br><br>Hope I haven't missed anything there.&nb= sp; You can see from the commented<br>example that it's easy as pie, just one of the loose ends left undone<br>in ICSI Sather.<br><br>Merry Chr= istmas to all.<br><br>--Mike<br><br><br>-- <br>Michael Talbot-Wilson<br><br= ><br><br> </div> </div> </blockquote></div> </div></body></html> --840867960-2120912210-1324279437=:90096--