[tex-k] How read_ln works in Pascal?

Igor Liferenko igor.liferenko at gmail.com
Thu Mar 24 04:54:00 CET 2022


Hi all,

I'm trying to interpret the behavior of the pascal compiler,
which Knuth used to compile dvitype.web, in terms of the C language.
So far I came up with these rules:

   Pascal      <-->           C
------------------------------------------------
reset(term_in)        term_in.f=stdin,get(term_in)
get(term_in)          term_in.d=fgetc(term_in.f)
read_ln(term_in)      do get(term_in); while (!eoln(term_in))
eoln(term_in)         term_in.d=='\n' || eof(term_in)
eof(term_in)          term_in.f==NULL || feof(term_in.f)

where term_in is the variable of type

  struct { FILE *f; char d; }

So, if we apply these rules to this code from dvitype.web

    reset(term_in);
    if eoln(term_in) then read_ln(term_in);

we will have this pseudocode:

1. read one character from stdin
2. if the read character is '\n' or if user closed stdin, then read
one character from stdin
3. if the read character is '\n' or if user closed stdin, then
continue program execution, else read one character from stdin
4. if the read character is '\n' or if user closed stdin, then
continue program execution, else read one character from stdin
5. etc

>From this we see that if we type <return> as the first key after
starting the program, the program will wait for another <return> to
continue program execution.
And if we type something except <return>, program execution will be continued.
What bothers me is that we have to type <return> twice if we do not
want to keep default value.
This means that something in my interpretation of original Pascal is wrong.
And I do not understand what exactly, because I do not know the rules
of the pascal dialect, that Knuth used to compile dvitype.web.
Maybe somebody knows where this is described?

What is curious: Pascal-H, on which TeX is based, can be configured to
suppress the first get on terminal input, and Knuth uses this feature in
tex.web:

    reset(term_in,'TTY:','/O/I')

But it seems that dvitype.web was compiled with a different dialect of
Pascal, because there is no 'TTY:' argument.

Thank you,
Igor


More information about the tex-k mailing list.