<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:10.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.E-MailFormatvorlage19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="DE-CH" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US">Peter<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">The idea with the state machine is good.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">One remark:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">I don’t understand you remark “ReadText is external to this byte padding”<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">In my point of view in the ELSE part of state 3 you would have to strip the stuffed period.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">In other words: you would have to reposition and copy the Files.Write(R, ch); to almost all your cases</span><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">br<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">Jörg<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div id="mail-editor-reference-message-container">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">Von:
</span></b><span style="font-size:12.0pt;color:black">Oberon <oberon-bounces@lists.inf.ethz.ch> im Auftrag von peter@easthope.ca <peter@easthope.ca><br>
<b>Datum: </b>Sonntag, 12. November 2023 um 15:58<br>
<b>An: </b>oberon@lists.inf.ethz.ch <oberon@lists.inf.ethz.ch><br>
<b>Betreff: </b>Re: [Oberon] Removing unnecessary and embedded RETURNs.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">This is my alternative Mail.ReadText with no RETURN. ReportError was
<br>
helpful in debugging; probably can be deleted now.<br>
<br>
Apology for the verbose comments. Added to help a non-expert <br>
understand the non-obvious activity. =8~)<br>
<br>
I wonder whether this use of CASE is good practise. Observations? <br>
<br>
Thanks, ... P.L.<br>
<br>
PROCEDURE ReportError(c: CHAR);<br>
BEGIN<br>
Texts.WriteString(W, "Mail.ReadText(): LF absent at CASE "); Texts.Write(W, c);<br>
Texts.Write(W, "."); Texts.WriteLn(W);<br>
Texts.Append(Oberon.Log, W.buf); HALT(6)<br>
END ReportError;<br>
<br>
(* According to Post Office Protocol, the end of a message body is<br>
marked by character sequence CR LF "." CR LF.<br>
A message line can begin with a period. To distinguish from end-of-message,
<br>
the message sender prepends an additional period which is removed before the
<br>
message is displayed to the recipient. ReadText is external to this byte padding.<br>
<a href="https://en.wikipedia.org/wiki/Post_Office_Protocol">https://en.wikipedia.org/wiki/Post_Office_Protocol</a><br>
<a href="https://tools.ietf.org/html/rfc1939#section-3">https://tools.ietf.org/html/rfc1939#section-3</a> *)<br>
PROCEDURE ReadText(S: NetTools.Session; VAR R: Files.Rider);<br>
VAR<br>
buffer: ARRAY BufLen OF CHAR;<br>
len, readLen, i: SIGNED32;<br>
ch: CHAR;<br>
progress: CHAR; (*<br>
"0"= continuing<br>
"1"= CR<br>
"2"= CR LF<br>
"3"= CR LF "."<br>
"4"= CR LF "." CR<br>
"5"= CR LF "." CR LF = end-of-message; or no more characters *)<br>
BEGIN<br>
readLen := 0;<br>
i := readLen;<br>
progress := "0";<br>
WHILE progress < "5" DO (* Write byte to the MailMessages file. *)<br>
IF i = readLen THEN (* More characters required. *)<br>
len := NetSystem.Available(S.C);<br>
IF (len = 0) & (NetSystem.State(S.C) # NetSystem.inout) THEN<br>
progress := "5"<br>
ELSE<br>
IF len > (BufLen-2) THEN readLen := BufLen-2 ELSE readLen := len END;<br>
NetSystem.ReadBytes(S.C, 0, readLen, buffer);<br>
DEC(len, readLen);<br>
i := 0<br>
END<br>
ELSE (* i < readLen. character available *)<br>
ch := buffer[i];<br>
CASE progress OF<br>
"0": IF ch = Strings.CR THEN progress := "1" END |<br>
"1": IF ch = Strings.LF THEN progress := "2" ELSE ReportError(progress) END |<br>
"2": IF ch = Strings.CR THEN progress := "1"<br>
ELSIF ch = "." THEN progress := "3" ELSE progress := "0" END |<br>
"3": IF ch = Strings.CR THEN progress := "4" ELSE progress := "0" END |<br>
"4": IF ch = Strings.LF THEN progress := "5" ELSE ReportError(progress) END<br>
END;<br>
Files.Write(R, ch);<br>
INC(i)<br>
END<br>
END<br>
END ReadText;<br>
<br>
- <br>
VoIP: +1 604 670 0140<br>
work: <a href="https://en.wikibooks.org/wiki/User:PeterEasthope">https://en.wikibooks.org/wiki/User:PeterEasthope</a><br>
<br>
--<br>
Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems<br>
<a href="https://lists.inf.ethz.ch/mailman/listinfo/oberon">https://lists.inf.ethz.ch/mailman/listinfo/oberon</a><o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</body>
</html>