[tex-k] Misplaced 'end' for 'endcases' in tex.web source code of 2014.

Shuo Chen giantchen at gmail.com
Sun Dec 15 07:17:59 CET 2019


Make sense. Thanks for the explanation.

On Sat, Dec 14, 2019 at 1:51 PM Shreevatsa R
<shreevatsa.public at gmail.com> wrote:
>
> Short version: There is no bug; the program uses "endcases" only when "othercases" is used. (That's why you see "{there are no other cases}" mentioned in most of the examples in your diff.)
>
> To elaborate (based on section 10 of the program):
>
> A lot of these details of tex.web exist to account for the variety of Pascal compilers that were in use at the time, each of them providing additional features.
> In this case, the idea is that "standard" / "common denominator" Pascal (as specified in the book by Jensen and Wirth) already contains a "case ... end" statement, that was available on all Pascal compilers. An example usage:
>
>     case c of
>         "Q": begin print_esc("batchmode"); decr(selector); end;
>         "R": print_esc("nonstopmode");
>         "S": print_esc("scrollmode");
>     end; {there are no other cases}
>
> But this statement as described in the standard did not provide a way to specify the "default" case, and different compilers provided this extension differently.
>
> In the Pascal compiler that Knuth had access to and on which TeX was developed (called "Pascal-H' in section 3), it could be written like this:
>
>     case chr_code of
>         output_routine_loc: print_esc("output");
>         every_par_loc: print_esc("everypar");
>         every_math_loc: print_esc("everymath");
>         every_display_loc: print_esc("everydisplay");
>         every_hbox_loc: print_esc("everyhbox");
>         every_vbox_loc: print_esc("everyvbox");
>         every_job_loc: print_esc("everyjob");
>         every_cr_loc: print_esc("everycr");
>         others: print_esc("errhelp")
>     end;
>
> In other Pascal compilers, the syntax was different, in two ways:
> 1. in some, instead of "others:" the syntax was "otherwise:" or "otherwise" (without the colon) or "else" or something like that.
> 2. in some, a semicolon was required before the final "end".
>
> To account for these two differences (i.e. to make the program portable, by making it as easy as possible for system administrators to adapt TeX to their local Pascal compiler), Knuth defined
>
> @d othercases == others: {default for cases not listed explicitly}
> @d endcases == end {follows the default case in an extended |case| statement}
>
> and consistently used those whenever he used an extended case statement, instead of using the local-to-Pascal-H version with "others:" and "end". That way, someone could simply redefine "endcases" to "; end" if their compiler required a semicolon before the final end.
>
> When a non-extended case statement is used (i.e., one without a default case), there is no need to use this workaround, so tex.web uses the standard "end" directly. There is no need to change it.
>
> On Fri, 13 Dec 2019 at 18:12, Shuo Chen <giantchen at gmail.com> wrote:
>>
>> Dear TeX maintainers,
>>
>> In section 10 of 2014 Jan version of tex.web, on page 6, it says a
>> 'case' statement
>> should end with the 'endcases' keyword in the WEB source code. But I
>> noticed that
>> some 'case' statements end with 'end' keyword instead.
>>
>> This is not a bug of the TeX program per se. Because 'endcases' is
>> replaced with 'end'
>> by the tangle program by default. However, I think it might be worth
>> to update the
>> pretty-printing version of the program for consistency.
>>
>> Here's one example, with Linux shell:
>>
>> $ diff -U 8 tex.web tex2.web | head -15
>> --- tex.web    2019-09-09 14:16:36.022037462 -0700
>> +++ tex2.web    2019-12-13 09:39:24.865189980 -0800
>> @@ -1951,17 +1951,17 @@
>>  @<Change the interaction...@>=
>>  begin error_count:=0; interaction:=batch_mode+c-"Q";
>>  print("OK, entering ");
>>  case c of
>>  "Q":begin print_esc("batchmode"); decr(selector);
>>    end;
>>  "R":print_esc("nonstopmode");
>>  "S":print_esc("scrollmode");
>> -end; {there are no other cases}
>> +endcases; {there are no other cases}
>>  print("..."); print_ln; update_terminal; return;
>>  end
>>
>> There are about two dozens such cases, see full diff output:
>> https://gist.github.com/chenshuo/f4e15b63ebaf361fc9af2fda7a1d45e3
>>
>> With this update, the tangled tex.p source file is not affected, only
>> the weaved tex.pdf changes a tiny bit.
>> See example of page 75: https://ibb.co/tqDjdBT
>>
>> Also, there are some trailing spaces in tex.web, which can be found
>> with 'grep -n ' $' tex.web' on Linux.
>>
>> Regards,
>> Shuo Chen



More information about the tex-k mailing list