nr@Princeton.EDU (Norman Ramsey) (02/15/91)
If the last character of a text is a blank, it doesn't get flushed correctly by Formatter.Flush. Evidence is below. This problem isn't affected by Jorge's fix. I assume that this problem is related to the special treatment of blanks in Formatter.PutChar (they don't get added to t.chars, but instead a special Ref containing only the blank is added). I can't quite puzzle out what's wrongby looking at Formatter.Flush and Formatter.WaitUntilEmpty. Norman nr@hart (22) % m3 Bugs15.mo Formatter.?o nr@hart (23) % a.out Formatter.T: input `prompt> ' emerges as `prompt>'. Formatter.T: input `prompt> ' emerges as ` prompt>'. Formatter.T: input `hello there' emerges as ` hello there'. Formatter.T: input `army boots! ' emerges as `army boots!'. Wr.T: input `prompt> ' emerges as `prompt> '. Wr.T: input `prompt> ' emerges as `prompt> '. Wr.T: input `hello there' emerges as `hello there'. Wr.T: input `army boots! ' emerges as `army boots! '. # To unbundle, "sed '1,/^# To unbundle/d' < thisfile | sh" # Thu Feb 14 12:58:23 EST 1991 echo Bugs15.m3 1>&2 sed 's/^-//' >'Bugs15.m3' <<'End of Bugs15.m3' -MODULE Bugs15 EXPORTS Main; -IMPORT Fmt, Formatter, Stdio, TextWr, Wr; - -VAR - under := TextWr.New(); - wr := Formatter.New(under); - -CONST - test = "prompt> "; - -PROCEDURE Check(msg:TEXT) = -BEGIN - Formatter.PutText(wr,msg); - Formatter.Flush(wr); - Wr.Flush(Formatter.UnderlyingWr(wr)); - - Wr.PutText(Stdio.stdout, - Fmt.F("Formatter.T: input `%s\' emerges as `%s\'.\n",msg,TextWr.To Text(under))); -END Check; - -PROCEDURE Check2(msg:TEXT) = -BEGIN - Wr.PutText(under,msg); - Wr.Flush(under); - - Wr.PutText(Stdio.stdout, - Fmt.F("Wr.T: input `%s\' emerges as `%s\'.\n",msg,TextWr.ToText(un der))); -END Check2; - -BEGIN - Check(test); - Check(test); - Check("hello there"); - Check("army boots! "); - Check2(test); - Check2(test); - Check2("hello there"); - Check2("army boots! "); -END Bugs15. - End of Bugs15.m3
stolfi (Jorge Stolfi) (02/15/91)
> [Norman Ramsey:] If the last character of a text is a blank, it > doesn't get flushed correctly by Formatter.Flush. This is a feature, not a bug. The Formatter code takes pains to suppress trailing blanks before line breaks (check DoPrintChar). You probably can solve your problem by using PutText(" ", raw := TRUE), instead of PutChar or plain PutText. The "raw" flag causes it to treat blanks as ordinary printing characters. By the way, note that Formatter.Flush is not a harmless operation like Wr.Flush, that you can insert anywhere without affecting the output. Formatter.Flush also closes all pending Begin and Align groups, and chooses breakpoints as if the expression ended there. (I intend to add a harmless Flush once Eric gets the ESP package working. 8-) --jorge