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&nbsp;:</span></b> Sather User &lt;sather@vi=
ew.net.au&gt;<br> <b><span style=3D"font-weight: bold;">=C0&nbsp;:</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&nbsp;:</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.&nbsp; I quickly abandoned libtiff.&nbsp; I decided that<br>re-im=
plementation in Sather directly was a better approach than<br>digesting the=
 libtiff documentation.&nbsp; 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.&nbsp; 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.&nbsp; It works, that's all I know=
.<br><br>------------------------------------------------------------------=
-<br>partial class FILE_PIPE is<br>&nbsp;  -- Things common to both<br>&nbs=
p;  readonly attr fp:EXT_OB;&nbsp; &nbsp; &nbsp; -- The FILE pointer readon=
ly attr<br><br>&nbsp;  get_char:CHAR pre ~void(fp) is<br>&nbsp; &nbsp; &nbs=
p; return RUNTIME::fgetc(fp);<br>&nbsp;  end;<br><br>&nbsp;  get_str:STR is=
<br>&nbsp; &nbsp; &nbsp; -- A string containing the characters up to the ne=
xt newline.<br>&nbsp; &nbsp; &nbsp; return get_line.str;<br>&nbsp;  end;<br=
><br>&nbsp;  get_line:FSTR is<br>&nbsp; &nbsp; &nbsp; -- A string buffer co=
ntaining the characters up to the next newline.<br>&nbsp; &nbsp;
 &nbsp; res::=3D#FSTR;<br>&nbsp; &nbsp; &nbsp; loop<br>&nbsp; &nbsp; &nbsp;=
 &nbsp; &nbsp; c::=3Dget_char;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if eof=
 then return res end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- Next 2 lines=
 reversed mtw Sep 2011<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; until!(c=3D'\n=
');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res:=3Dres.push(c);<br>&nbsp; &nb=
sp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; return res;<br>&nbsp;  end;<br><br>=
&nbsp;  get(s:STR):FLIST{STR} is<br>&nbsp; &nbsp; &nbsp; p::=3Dopen_for_rea=
d(s);<br>&nbsp; &nbsp; &nbsp; if p.error then raise "oops" end;<br>&nbsp; &=
nbsp; &nbsp; ans::=3D#FLIST{STR};<br>&nbsp; &nbsp; &nbsp; loop<br>&nbsp; &n=
bsp; &nbsp; &nbsp;  t::=3Dp.get_str;<br>&nbsp; &nbsp; &nbsp; &nbsp;  while!=
(~p.eof);<br>&nbsp; &nbsp; &nbsp; &nbsp;  ans:=3Dans.push(t)<br>&nbsp; &nbs=
p; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; p.close;<br>&nbsp; &nbsp; &nbsp; ret=
urn ans<br>&nbsp;  end;<br><br><br><br>end;<br><br>class PIPE is<br>&nbsp; =
 -- Not
 &lt; $OSTREAM because no plus...<br>&nbsp;  -- MTW Oct 2011<br>&nbsp;  -- =
The stdin/stdout of FILE maybe should be here.<br>&nbsp;  --<br>&nbsp;  -- =
Example:<br>&nbsp;  -- class MAIN is<br>&nbsp;  --&nbsp; &nbsp; main is<br>=
&nbsp;  --&nbsp; &nbsp; &nbsp;  p::=3DPIPE::open_for_read("date +'%Y:%m:%d =
%H:%M:%S'");<br>&nbsp;  --&nbsp; &nbsp; &nbsp;  s:STR:=3Dp.get_str;<br>&nbs=
p;  --&nbsp; &nbsp; &nbsp;  p.close;<br>&nbsp;  --&nbsp; &nbsp; &nbsp;  #OU=
T+s+"\n"; -- prints formatted date<br>&nbsp;  --&nbsp; &nbsp; end<br>&nbsp;=
  -- end<br>&nbsp;  --<br>&nbsp;  include FILE_PIPE;<br><br>&nbsp;  open_fo=
r_read(command:STR):SAME is<br>&nbsp; &nbsp; &nbsp; -- Open pipe for readin=
g.<br>&nbsp; &nbsp; &nbsp; r::=3Dnew;<br>&nbsp; &nbsp; &nbsp; r.fp:=3DRUNTI=
ME::popen(command,"r");<br>&nbsp; &nbsp; &nbsp; return r<br>&nbsp;  end;<br=
><br>&nbsp;  close pre ~void(fp) is<br>&nbsp; &nbsp; &nbsp; -- Close the pi=
pe corresponding to self.<br>&nbsp; &nbsp; &nbsp;
 RUNTIME::pclose(fp)<br>&nbsp;  end;<br><br>&nbsp;  error:BOOL is<br>&nbsp;=
 &nbsp; &nbsp; -- true is an error has occurred with this file.&nbsp; Clear=
ed by "clear".<br>&nbsp; &nbsp; &nbsp; return void(fp) or RUNTIME::ferror(f=
p)<br>&nbsp;  end;<br><br><br>&nbsp;  eof:BOOL pre ~void(fp) is<br>&nbsp; &=
nbsp; &nbsp; -- true if EOF has been encountered.&nbsp; Cleared by "clear".=
<br>&nbsp; &nbsp; &nbsp; return RUNTIME::feof(fp)<br>&nbsp;  end;<br><br>en=
d;<br><br>class FILE &lt; $OSTREAM is ... etc<br><br>----------------------=
---------------------------------------<br><br>Library/System/runtime.sa:<b=
r><br>external class RUNTIME is<br>&nbsp;&nbsp;&nbsp; ...<br>&nbsp;&nbsp;&n=
bsp; popen(nm:STR,tp:STR):EXT_OB;<br>&nbsp;&nbsp;&nbsp; pclose(fp:EXT_OB);<=
br>&nbsp;&nbsp;&nbsp; ...<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--