Produced from testfile.l on 25–Feb–2000 08:39

File testfile.l

1 Block comment examples

3 /∗
4  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
5  <<<<<<<<<<<<<<<<<<<<<<<<∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗>>>>>>>>>>>>>>>>>>>>
6  <∗ filenamex : testfile.l  ∗>
7  <∗ purpose : this is a little lex file as an example for a simple  ∗>
8  <∗ iiiiiiiii  : converter using the position macros. Only a few  ∗>
9  <∗ mmmmmmmmm : basic conversions are implemented; all fonts etc. are  ∗>
10  <∗  : hard–coded. You may use this file as example for use  ∗>
11  <∗  : of the position macros or as starting point for an own  ∗>
12  <∗  : converter project.  ∗>
13  <<<<<<<<<<<<<<<<<<<<<<<<∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗>>>>>>>>>>>>>>>>>>>>
14  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
15 ∗/

16

17  /∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗
18  ∗ filename  : testfile.l (using the block comment mode)  ∗
19  ∗ purpose  : this is a little lex file as an example for a simple  ∗
20  ∗ jjjjjjjjjj  : converter using the position macros. Only a few basic iii  ∗
21  ∗ aaaaaaaaaa : conversions are implemented; all fonts etc are hardcoded.  ∗
22  ∗ xxxxxxxxxx : You may use this file as example for use of the position  ∗
23  ∗ iiiiiiiiii  : or as starting point for an own converter project.  ∗
24  ∗ vvvvvvvvvv : Note: vertical alignment of the colon depends here not on ∗
25  ∗ uuuuuuuuuu : the number of blanks before the colon; also the star at  ∗
26  ∗ mmmmmmmmmm : line end is aligned even with a single blank.  ∗
27  ∗∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗/

28

29  /∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗
30  ∗ filename  : testfile.l (using the normal comment mode)  ∗
31  ∗ purpose  : this is a test for the normal comment mode.  ∗
32  ∗ vvvvvvvvvv : Note: vertical alignment of the colon in this example de– ∗
33  ∗ uuuuuuuuuu : pends on the number of blanks before the colon; also the ∗
34 ∗ mmmmmmmmmm : star at line end is not aligned with a single blank. ∗
35  ∗∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗/

2 Handling of overlong Lines:

2.1 Preprocessor Statements

40 #define DUMMY1 stmt without blanks();stmt();stmt();stmt();stmt();stmt();stmt(); \
stmt();stmt();stmt();stmt();stmt();stmt();stmt();stmt();stmt();stmt();stmt();stmt(); \
stmt();stmt();stmt();stmt();stmt();stmt();stmt();stmt();stmt();stmt();stmt();

41

42 #define DUMMY2 stmt with blanks(); stmt(); stmt(); stmt(); stmt(); stmt(); stmt(); \
stmt(); stmt(); stmt(); stmt(); stmt(); stmt(); stmt(); stmt(); stmt(); stmt(); \
stmt(); stmt(); stmt(); stmt(); stmt(); stmt(); stmt(); stmt();

2.2 General Statements

45  dummy statement(); dummy statement(); dummy statement(); dummy statement();

Page 1

Produced from testfile.l on 25–Feb–2000 08:39

dummy statement(); dummy statement(); dummy statement(); dummy statement();
dummy statement(); dummy statement(); dummy statement(); dummy statement();
dummy statement(); dummy statement();

46

47  this is(not(fine));because(we/you(also?grrrrrrr:better for us));didnt(include);
any spaces(into(this line)/but(it));seems to be(no(problem));this is(notatall(fine));
because(we/you(also));didnt(include)||insert any spaces(into(this line)/but(it));

seems to be(no(problem));

2.3 Strings

50  “this is a very long string   this is a very long string   this is a \
very long string   this is a very long string   this is a very long \
string   this is a very long string   this is a very long string   this is \
a very long string   this is a very long string”

51

52  “this is a very long string   this is a very long string   this is a \
very long string   this is a very long string   this is a very long \
string   this is a very long string   this is a very long string\
53  this is a very long string   this is a very long string   this is a \
very long string   this is a very long string   this is a very long \
string   this is a very long string   this is a very long string\
54  this is a very long string   this is a very long string   this is a \
very long string   this is a very long string   this is a very long \
string   this is a very long string   this is a very long string\
55  this is a very long string   this is a very long string   this is a \
very long string   this is a very long string   this is a very long \
string   this is a very long string   this is a very long string”

56

57  “another string with \n another string with \n another string with \n\
 another string with \n another string with \n another string with \n\
 another string with \n another string with \n another string with \n”

2.4 Comments

60  /∗this is a very long comment this is a very long comment this is a
∗very long comment this is a very long comment this is a very long
∗comment this is a very long comment this is a very long comment
∗this is a very long comment ∗/

61

62  MMMMMMMMM(); /∗ NOTE: This comment start at the same ASCII position as the
∗ last one; but the LaTeX position is shifted right because the
∗ MMMMMMMM characters need a lot of space. The continuation
∗ lines are aligned to the comment start in both cases. ∗/

63

64  stmt();  /∗ Again the same ASCII position this is a very long comment this
∗ is a very long comment this is a very long comment this is a very
∗ long comment this is a very long comment this is a very long
∗ comment this is a very long comment ∗/

65

66  for(ptr=buffer;∗ptr++;)stmt(ptr,var); // this is a very long comment this is a
// very long comment this is a very long
// comment this is a very long comment this
// is a very long comment this is a very

Page 2

Produced from testfile.l on 25–Feb–2000 08:39

// long comment this is a very long
// comment

67

68  for(ptr=buffer;∗ptr++;)stmt(ptr,var); /∗ this
∗ comment starts at ASCII position > 50;
∗ the indentation of continuation lines is
∗ taken from the code instead of the
∗ comment start ∗/

69

70  stmt(); /∗ 1 This is a test for line breaking in a long multi–line comment. We
∗ need some more text so here is some more nonsense. We need some more
∗ text so here is some more nonsense. We need some more text so here is
∗ some more nonsense.
71  ∗ 2 This is a test for line breaking in a long multi–line comment. We
∗ need some more text so here is some more nonsense. We need some more
∗ text so here is some more nonsense. We need some more text so here is
∗ some more nonsense.
72  ∗ 3 This is a test for line breaking in a long multi–line comment. We
∗ need some more text so here is some more nonsense. We need some more
∗ text so here is some more nonsense. We need some more text so here is
∗ some more nonsense.
73  ∗ 4 This is a test for line breaking in a long multi–line comment. We
∗ need some more text so here is some more nonsense. We need some more
∗ text so here is some more nonsense. We need some more text so here is
∗ some more nonsense. ∗/

74

75 stmt();  /∗ 1 This is a test for line breaking in a long multi–line comment. We
∗ need some more text so here is some more nonsense. We need some more
∗ text so here is some more nonsense. We need some more text so here is
∗ some more nonsense.
76  ∗ 2 This is a test for line breaking in a long multi–line comment. We
∗ need some more text so here is some more nonsense. We need some more
∗ text so here is some more nonsense. We need some more text so here is
∗ some more nonsense.
77  ∗ 3 This is a test for line breaking in a long multi–line comment. We
∗ need some more text so here is some more nonsense. We need some more
∗ text so here is some more nonsense. We need some more text so here is
∗ some more nonsense.
78  ∗ 4 This is a test for line breaking in a long multi–line comment. We
∗ need some more text so here is some more nonsense. We need some more
∗ text so here is some more nonsense. We need some more text so here is
∗ some more nonsense. ∗/

79

80 MMMMMMM(); /∗ 1 This is a test for line breaking in a long multi–line comment. We
∗ need some more text so here is some more nonsense. We need some more
∗ text so here is some more nonsense. We need some more text so here is
∗ some more nonsense.
81  ∗ 2 This is a test for line breaking in a long multi–line comment.
∗ We need some more text so here is some more nonsense. We need
∗ some more text so here is some more nonsense. We need some more
∗ text so here is some more nonsense.
82 ∗ 3 This is a test for line breaking in a long multi–line comment.
∗  We need some more text so here is some more nonsense. We need
∗  some more text so here is some more nonsense. We need some more

∗  text so here is some more nonsense.
83  ∗ 4 This is a test for line breaking in a long multi–line comment.
∗ We need some more text so here is some more nonsense. We need some
∗ more text so here is some more nonsense. We need some more text so
∗ here is some more nonsense.
84  ∗5 This is a test for line breaking in a long multi–line comment. We
∗need some more text so here is some more nonsense. We need some more
∗text so here is some more nonsense. We need some more text so here is
∗some more nonsense.
85  ∗/

86

87  stmt(); /∗ this is a special form of comment (fill comment): for the continuation
∗ lines of the source text the newline characters and the leading blanks and
∗ ∗ are replaced by a single blank; so linebreaking is done by the TeX
∗ macros.
∗ To force a linebreak, put a blank and a single @ character to the end of
∗ the line, as above.
∗ To insert a blank line into the output, you may use the syntax as in the
∗ last source line (only a @ character after the star).
∗ If you insert just a blank line, this is preserved too; the indentation does
∗ not change (as in this example).

∗

∗ Finally you could use this form, with only a star in the comment. The
∗ star is left in the output, as it should be. ;–)))

∗/

104

105  MMMM(); /∗ This comment starts at the same ASCII position as the comment
∗ above; but the MMMM() characters need much more place in the output.
∗ The new indentation is preserved for all special cases again:

∗

∗ This is a special form of comment (fill comment): for the continuation
∗ lines of the source text the newline characters and the leading blanks
∗ and ∗ are replaced by a single blank; so linebreaking is done by the TeX
∗ macros.
∗ To force a linebreak, put a blank and a single @ character to the end
∗ of the line, as above.
∗ To insert a blank line into the output, you may use the syntax as in
∗ the last source line (only a @ character after the star).
∗ If you insert just a blank line, this is preserved too; the indentation
∗ does not change (as in this example).

∗

∗ Finally you could use this form, with only a star in the comment. The
∗ star is left in the output, as it should be. ;–)))

∗/

126

127  iiii(); /∗ This is again another form of the fill comment; the leading stars are
∗ omitted in the input; but they are written in the output.
∗ Line breaking works just as in the standard form of fill comments (with
∗ stars).

∗ Blank lines work as in the standard form, as you can see here.
∗/

134 135 136

137  stmt(); // This is a little example/demo for a fill comment for the C++/Java
// language (we need some more text here to get the line full).
// The syntax is just the same as in C comments, only the comment start
// uses //\f instead of the C comment start. To get an "empty" line insert
// a commented out line or a line containing just a @ after the comment
// characters. The comment characters are written in this case; a completely
// empty line requires a new fill comment start.

//

// Blank lines are not allowed in this form of comment; if you insert a
// blank line, the fill comment is ended (as after this line).

149

150  // Here is again a normal C++ comment. The indentation changed slightly
// because the previous comment position was forced by the stmt() (there is
// only one blank after the statement). We need again some more text to
// show that normal linebreaking is in effect.
151  // Here begins a new comment line; the fill comment was terminated by
// the empty line.

152

153  stmt(); /∗ iiiiiiiiiiiiii  this is just a reference to show the effect of the
∗ \jmpo and \xnjo macro ∗/
154  MMMMMMM(); /∗ iiiiiiiiiiii this is just a reference to show the effect of the
∗ \jmpo and \xnjo macro ∗/
155  stmt(); /∗ iiiiiiiiiiii this is a fill comment again: the blanks are replaced by fix
∗ space, (\xnjo macro) instead of using the \jmpo macro to jump to a
∗ specific position, as is done in the normal comments above
∗/

3 Deklarations

160  i  = 3;
161  j  = 4;
162  veryvery long var = 5; /∗ with Tab: the = character is aligned with the others ∗/
163  veryvery long var = 5; /∗ with Blank: no alignment, because only one blank before
∗ the = ∗/

4 Embedded L^{A}TEX comments

166 dummy statement(); /∗ ∑_{n=0}^{N} g_{n}(x) = ∫_{a}^{b} f(x) dx = ∫_{a}^{b} f(x) dx = ∮_{c}^{d} F (z) dz ∗/

170 dummy statement(); this is a verbatim-comment; it appears without comment characters!

171

172 xxx(); // Again an embedded L^{A}TEX comment, using C++ comment: ∑_{n=0}^{N} g_{n}(x) = ∮_{c}^{d} F (z) dz

Produced from testfile.l on 25–Feb–2000 08:39

5 LEX Rules

175 [#$%{} &] fprintf(yyout,“\\%c”,∗yytext); LEN(2);  /∗ | ∗/
176 \\  fprintf(yyout,“$\\backslash$”); LEN(12);  /∗ | ∗/
177 \ˆ  fprintf(yyout,“$\\hat{∼}$”); LEN(9);  /∗ | ∗/
178 [<>]  fprintf(yyout,“$%c$”,∗yytext); LEN(3);  /∗ | ∗/
179 \<{2,9} fprintf(yyout,“\\mlt{%d}”,yyleng); LEN(7);  /∗ | ∗/
180 \>{2,9} fprintf(yyout,“\\mgt{%d}”,yyleng); LEN(7);  /∗ | ∗/
181 \\{2,}  fprintf(yyout,“\\bs{%d}”,yyleng); LEN(6);  /∗ | ∗/

6 Omitting Code

184

/∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗∗ SKIP 3 LINES ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗∗/

190

/∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗∗ SKIP A LINE ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗∗/
193  will+be+omitted–
194  fromˆ output();

195

199  fromˆ output();

200

/∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗∗ SKIP 3 LINES ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗∗/
205  ∗ Comments are recognized
206  ∗ even if they begin in the
207  ∗ omitted text!
208  ∗/

209

214  ∗ Comments are recognized
215  ∗ even if they begin in the
216  ∗ omitted text!
217  ∗/

218

219  /∗ NOTE: The following omit statement has no ’\o–’; it ends at end of the file. ∗/

220

/∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗∗ SKIP 7 LINES ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗∗/

Produced from tiny c2l.l on 25–Feb–2000 08:39

File tiny c2l.l

/∗

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
10  <<<<<<<<<<<<<<<<<<<<<<<<∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗>>>>>>>>>>>>>>>>>>>>
<∗ filename : tiny c2l.l  ∗>
<∗ purpose : this is a little lex file as an example for a simple  ∗>
<∗  : converter using the position macros. Only a few  ∗>
<∗  : basic conversions are implemented; all fonts etc. are  ∗>
15  <∗  : hard–coded. You may use this file as example for use  ∗>
<∗  : of the position macros or as starting point for an own  ∗>
<∗  : converter project.  ∗>
<∗  :  ∗>
<∗ cvt2ltx : This file is the tiny version of c2ltx; keywords,  ∗>
20 <∗ equiv. : strings and comments are recognized. A very simple ∗>
<∗  : version of embedded LaTeX is implemented (only append ∗>
<∗  : mode and verbatim mode; everything is copied verbatim  ∗>
<∗  : to the output file in both cases.  ∗>
<∗  :  ∗>
25  <∗ version : 1.4.0 from 25–feb–2000  ∗>
<∗ author  : Michael Plugge <m.plugge@fh–mannheim.de>  ∗>
<<<<<<<<<<<<<<<<<<<<<<<<∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
∗/

30

%{

7 Declaration Part

#define VERSION “1.4.0”
#define VERSION DATE “25-feb-2000”

35

#define TAB2SPC 3
#define BASE FONT “basefont”
#define BLOCK FONT “blockfont”
#define KEYWORD FONT “keywordfont”
40 #define STRING FONT “stringfont”
#define COMMENT FONT “commentfont”
#define HEADFONT “headfont”
#define FOOTFONT “footfont”
#define LHEAD ""

45 #define CHEAD “Produced from %f on %D %t”

#define RHEAD ""
#define LFOOT ""
#define CFOOT “Page %p”
#define RFOOT ""

50 #define L2E STYLE “ \\documentclass[10pt]{article}\n\
 \\usepackage{a4,position,fancyhdr}\n\
 \\usepackage[latin1]{inputenc}\n\

 \\textwidth18cm\\textheight25cm\\hoffset-3cm\\voffset-1cm”

#define L209 STYLE “ \\documentstyle[a4,position,fancyhdr]{article}\n\
55 \\textwidth18cm\\textheight25cm\\hoffset-3cm\\voffset-1cm”
#define L2E STYLE LINE “ \\documentclass[10pt]{article}\n\

Page 7

Produced from tiny c2l.l on 25–Feb–2000 08:39

 \\usepackage{a4,position,fancyhdr}\n\
 \\usepackage[latin1]{inputenc}\n\

 \\textwidth18cm\\textheight25cm\\hoffset--3cm\\voffset--1cm”

60 #define L209 STYLE LINE “ \

\\documentstyle[a4,position,fancyhdr]{article}\n\

 \\textwidth18cm\\textheight25cm\\hoffset-3cm\\voffset-1cm”

/∗ The following definition controls the behavior of linebreaks for comments: after
∗ this ASCII position, continuation lines use the current indentation

∗/

#define ALIGN CMT LIMIT 50
#define LEN(val) if((leng+=val)>70){leng=0; fprintf(yyout,“%%\n ”);}
#if VMS
70 #undef ECHO
#define ECHO yyleng==1 ? fputc(∗yytext,yyout) : fprintf(yyout,“%s”,yytext)
#endif
#include <string.h>
75 #include <time.h>
char ∗ptr,∗ptr1,∗kern,∗inputname,buffer[256],init=1,cmt mode;
int pos,old pos,brace open,tmp,leng,tab2spc=TAB2SPC,sc,sc1,
pes old= –1,cmt blanks,skip cnt,cmt pos,line=1,show lines,use header=1;
80 long year;
time t time val;
struct tm ∗atime;
char ∗lhead=LHEAD,∗chead=CHEAD,∗rhead=RHEAD,∗headfont=HEADFONT,
85  ∗lfoot=LFOOT,∗cfoot=CFOOT,∗rfoot=RFOOT,∗footfont=FOOTFONT,
∗latex prolog1=

“%%%% This file was generated by tiny c2l (version %s, %s)\n\n\
\\ifx\\getformat\\undefined\n\
 \\newcount\\getformat\\getformat0\n\

90 \\else\n\

 \\mfilestrue\\getformat3\n\

\\fi\n\

\\ifx\\documentclass\\undefined\\advance\\getformat1\\fi\n\n\
\\ifcase\\getformat\n\

95 %s\n\
\\or\n\

%s\n\
\\else\\fi %% multiple file input: don't load format\n%s”,

100  ∗latex prolog2=“\

\\gdef\\cmt#1#2{\\psinit{#1}{\\hphantom{/}$\\ast$\\mblank{#2}}\\%s}\n\
\\gdef\\cmtpp#1#2{\\psinit{#1}{//\\mblank{#2}}\\%s}\n\
\\gdef\\ccmtend{\\setbox\\pstartbox=\\hbox{\\hphantom{/}}}\n\
\\ifmfiles\\else\\begin{document}\\fi\\begin{flushleft}\n\n”,

105 ∗month[]={

   “January”,
   “February”,
   “March”,

“April”,

110  “May”,

“June”,
“July”,
“August”,
“September”,
115  “October”,
“November”,
“December”

},
∗local month[]={

120  “Januar”,
“Februar”,
“März”,
“April”,
“Mai”,

125  “Juni”,

“Juli”,
“August”,
“September”,
“Oktober”,
130  “November”,
“Dezember”

},
∗month1[]={“Jan”,“Feb”,“Mar”,“Apr”,“May”,“Jun”,“Jul”,“Aug”,“Sep”,“Oct”,“Nov”,“Dec”},
∗local month1[]={“Jan”,“Feb”,“Mrz”,“Apr”,“Mai”,“Jun”,“Jul”,“Aug”,“Sep”,“Okt”,“Nov”,“\

Dez”},
135 ∗usage text1=“ Usage: tiny c2l [options] [infile [outfile]] [options]\n\
infile and/or outfile may be omitted; in this case stdin/stdout are \
used.\n\
valid options are:\n\
 -hn        don't generate header or footer text\n\
 -hl<txt> header text: left side (default \"\")\n\
140  -hc<txt> header text: center (default \"Produced from %f on %D \
%t\")\n\
 -hr<txt> header text: right side (default \"\")\n\
 -fl<txt> footer text: left side (default \"\")\n\
 -fc<txt> footer text: center (default \"Page %p\")\n\
 -fr<txt> footer text: right side (default \"\")\n\
145  possible escape sequences for the -h. and -f. switches \
are:\n\
      %f: input file name        %m: month (numeric value)\n\
      %p: page number            %n: (english) name of month \
(full form)\n\
      %t: time (HH:MM)           %s: (english) name of \
month (short form)\n\
      %D: date (DD-MMM-YYYY)     %N: (local) name of month \
(full form)\n\
150  %h: hour                   %S: (local) name of \
month (short form)\n\
      %M: minute                 %y: year\n\
      %d: day of month           %: the `%' character \
itself\n\
 -l[cnt]    output line numbers\n\

    -+         C++ mode\n\
155  --j         java mode\n\
    --o         outputname (if stdin is used for \
input)\n\
    --t<cnt>  number of spaces per tab character \
(default: ”,

∗usage text2=“)\n\

    -d         debug (debug output is written to tiny c2l.dbg)\n\
160  -?         show this help screen\n”;

void keyword(void);
void skip msg(void);
void chk cmt(void);
165 void print jmpo(int linebegin);
void init out(int mode);
int die(char ∗cmd,int mode);
void substitute format(char ∗format);
char ∗subst(int c);
170 void current line(void);

%}

/∗ preprocessor keywords (without the leading #) ∗/
PP KEY (define[ \t])|(undef[ \t])|(ifn?(def)?[ \t(])|(elif[ \t(])|(else[ \t\n])|(endif[
\t\n])|(error[ \t])|(line[ \t])|(pragma[ \t])|(include[ \t<\"])
175 SP  [ \t]+
SPO  [ \t]∗
WS  [ \t\n]
WSO  [ \t\n]∗
WSSEMI [ \t\n;]
180 WSBRSEMI [ \t\n(;]
WSBR [ \t\n(]
WSBR2 [ \t\n)]
WSBC [ \t\n{]
WSS  [ \t\n∗]
185 WSSB [ \t\n∗)]
WSC  [ \t\n:]
OPER [ \t\n+\–∗/%|&ˆ ∼!=<>\[(,]
CA  [ \t\n<]
WSB2 [ \t\n\[(]
190 NEW DEL [ \t\n\[(<]
%x LINE BEGIN OMIT
%x STRING C CMT CPP CMT FILL CMT FILL CPP CMT
%x EL CMT1 EL CMT2 EL CMT3 PREPROCESSOR
195 %s JAVA CPLUSPLUS
%option 8bit noyywrap outfile=“tiny c2l.c” debug
%%

8 Rules section

8.1 L^{A}TEXProlog

if(show lines)

fprintf(yyout,latex prolog1,VERSION,VERSION DATE,L2E STYLE LINE,
L209 STYLE LINE,use header¿‘\\pagestyle{fancy}\n”:"");

else

205  fprintf(yyout,latex prolog1,VERSION,VERSION DATE,L2E STYLE,
L209 STYLE,use header¿‘\\pagestyle{fancy}\n”:"");
fprintf(yyout,“\\plcntmargin{777}\n”);
if(use header){
fprintf(yyout,“\\lhead{\\%s ”,headfont);
210  substitute format(lhead);
fprintf(yyout,“\\chead{\\%s ”,headfont);

substitute format(chead);

fprintf(yyout,“\\rhead{\\%s ”,headfont);

substitute format(rhead);

215  fprintf(yyout,“\\lfoot{\\%s ”,footfont);

substitute format(lfoot);

fprintf(yyout,“\\cfoot{\\%s ”,footfont);

substitute format(cfoot);

fprintf(yyout,“\\rfoot{\\%s ”,footfont);
220  substitute format(rfoot);

} if(!show lines)

fprintf(yyout,“\\plinenowidth0pt\n”);

else

225  fprintf(yyout,“\\plcntmargin{77}\n”);
fprintf(yyout,latex prolog2,COMMENT FONT,COMMENT FONT);

BEGIN(LINE BEGIN);

8.2 Rules for Line Begin

230 <LINE BEGIN>{
/∗ special cases: blank lines, Blanks at end of line ∗/
ˆ {SPO}\n {
fprintf(yyout,“\\init0”);

current line();

235  fprintf(yyout,“\\n\\ped\n”);
pos=brace open=0;

line++; }

{SP}$  /∗ ignore spaces at end of line ∗/

240

/∗ general line begin (we need the \init macro here) ∗/
ˆ “ ”  pos++; fprintf(yyout,“\\init1”); current line(); fprintf(yyout,“\\njo{-1}{”);
brace open=1; leng=16; BEGIN(sc);
ˆ {SP} print jmpo(1); BEGIN(sc);
ˆ [ˆ \t\n] {
245  fprintf(yyout,“\\init0”); current line(); fprintf(yyout,“\\njo0{”);

yyless(0);

pes old= –1;

brace open=1;
leng=14;
250  cmt pos=1;

BEGIN(sc); }

.  yyless(0); cmt pos=pos+1; BEGIN(sc1);

}

255

8.3 Rules for Blanks and Tabs

<INITIAL,CPLUSPLUS,JAVA,PREPROCESSOR,C CMT,CPP CMT,FILL CMT,
FILL CPP CMT>{
“ ” {

pos++;

260  if(brace open)fputc('}',yyout);

chk cmt();

fprintf(yyout,“\\njo{%d}{”,pos);
brace open=1;

LEN(10);

265  }
{SP} print jmpo(0);

}

<C CMT>{
270 \n{SPO}“∗/” {
if(brace open)fputc('}',yyout);

line++;

pos=leng=brace open=cmt mode=0;
fprintf(yyout,“\\n\n\\initc{0}{5}{0}”);
275  current line();
fprintf(yyout,“\\ccmtend\\%s”,BASE FONT);
leng=30;

init out(0);

fprintf(yyout,“/}”);
280  brace open=cmt mode=0;
LEN(17+strlen(BASE FONT));

BEGIN(sc1); }

\n{SPO}\∗{SPO} {
285  if(brace open)fputc('}',yyout);

line++;

for(ptr=yytext+yyleng–1,cmt blanks=0;∗ptr==' ';ptr––)cmt blanks++;
pos=cmt pos+cmt blanks;
fprintf(yyout,“\\n\n\\initc{0}{5}{%d}”,cmt blanks);
290  current line();
leng=brace open=0;

LEN(25); }

\n{SPO}\∗+\/? {
295  if(brace open)fputc('}',yyout);

line++; LEN(15);

for(ptr=yytext+yyleng–1,cmt blanks=0;∗ptr==' ';ptr––)cmt blanks++;

pos=cmt pos;
300  for(ptr=yytext,tmp=0;∗ptr;)if(∗ptr++=='∗')tmp++;
if(∗(yytext+yyleng–1)=='/'){
fprintf(yyout,“\\ccmtend\\%s”,BASE FONT);

BEGIN(sc1); }

305  fprintf(yyout,“\\n\n\\initc{0}{5}{0}”);

current line();

if(tmp>4){

LEN(31);

fprintf(yyout,“\\mpout{%d}{%d}{%s}{%s}”,cmt pos,cmt pos+tmp–2,“$\\ast$”,“\

2pt”);

310  if(∗(yytext+yyleng–1)=='/')fprintf(yyout,“\\njo0{/}”);

}

else{
fprintf(yyout,“\\njo0{\\mast{%d}/}”,tmp);
if(∗(yytext+yyleng–1)=='/')fputc('/',yyout);
315  LEN(10+strlen(BASE FONT)+yyleng);

}

brace open=0;

}

\n{SPO} {
320  if(brace open)fputc('}',yyout);

line++;

leng=brace open=0;
for(pos=0,ptr=yytext+1;∗ptr;ptr++){
if(∗ptr=='\t')
325  pos+=tab2spc–pos%tab2spc;

else

pos++; } LEN(20);

330  fprintf(yyout,“\\n\n\\initc{%d}{0}{0}”,pos);

current line(); }

}

335 <INITIAL,CPLUSPLUS,JAVA,CPP CMT,FILL CMT,FILL CPP CMT>\n {
if(brace open)fputc('}',yyout);

line++;

pos=leng=brace open=0;
fprintf(yyout,“\\n\\ped\n”);
340  pes old= –1;
if(YY START==CPP CMT || YY START==FILL CPP CMT){
sc=sc1;
fprintf(yyout,“\\%s ”,BASE FONT);
LEN(2+strlen(BASE FONT));
345  }

else

sc=YY START;

BEGIN(LINE BEGIN); }

350

<INITIAL,CPLUSPLUS,JAVA,STRING,C CMT,CPP CMT,FILL CMT,

FILL CPP CMT>{
{SP}$  /∗ ignore spaces at end of line ∗/

8.4 Rules for special characters

355 \<{2,9}  init out(0); fprintf(yyout,“\\mlt{%d}”,yyleng); LEN(7);
\>{2,9}  init out(0); fprintf(yyout,“\\mgt{%d}”,yyleng); LEN(7);
\\{2,}  init out(0); fprintf(yyout,“\\bs{%d}”,yyleng); LEN(6);
\∗{2,9}  init out(0); fprintf(yyout,“\\mast{%d}”,yyleng); LEN(8);

8.5 “Leader” rules

\<{10,} |
\>{10,} |
\+{10,} |
\${10,} |
365 \#{10,} |
\%{10,} |
\∼{10,} |
\∗{10,} {
switch(∗yytext){
370 case '<': kern=“-2pt”; ptr=“$<$”; break;
case '>': kern=“-2pt”; ptr=“$>$”;  break;
case '+': kern=“0pt”; ptr=“+”;  break;
case '$': kern=“0pt”; ptr=“\\$”;  break;
case '#': kern=“0pt”; ptr=“\\#”;  break;
375 case '%': kern=“0pt”; ptr=“\\%”; break;
case '∼': kern=“0pt”; ptr=“$\\sim$”; break;
case '∗': kern=“2pt”; ptr=“$\\ast$”; break;
default: kern=“0pt”; ptr="";  break;
}
380  if(brace open)fputc('}',yyout);
fprintf(yyout,“\\mpout{%d}{%d}{%s}{%s}”,pos,pos+yyleng–1,ptr,kern);
pos+=yyleng;
brace open=0;
LEN(strlen(kern)+strlen(ptr)+19);
385  }

}

8.6 Rules for Preprocessor Keywords

/∗ (first handle just the leading #) ∗/
390 \#{SPO}{PP KEY} {

yyless(1); init out(0);

fprintf(yyout,“{\\%s \\#}}\\pes{ \\bs{1}}{%d}”,KEYWORD FONT,pos+2);
pes old=pos+2;
395  brace open=0;
LEN(18+strlen(KEYWORD FONT));

BEGIN(PREPROCESSOR); }

400 <PREPROCESSOR>.|\n yyless(0); BEGIN(sc1);  /∗ this should not occur ∗/
<PREPROCESSOR>{PP KEY} yyless(yyleng–1); keyword();

8.7 Rules for common C/C++/Java Keywords

break[ \t\n;]  |
405 case[ \t\n(]  |
char[ \t\n∗)]  |
continue[ \t\n;]  |
default[ \t\n:]  |
do[ \t\n{]  |
410 double[ \t\n∗)]  |
else[ \t\n{]  |
float[ \t\n∗)]  |
for[ \t\n(]  |
goto{WS}  |
415 if[ \t\n(]  |
int[ \t\n∗)]  |
long[ \t\n∗)]  |
return[ \t\n(;]  |
short[ \t\n∗)]  |
420 static[ \t\n∗)]  |
switch[ \t\n(]  |
void[ \t\n)]  |
volatile{WS}  |
while[ \t\n(]  yyless(yyleng–1); keyword();

425

8.8 Rules for C/C++ only Keywords

<INITIAL,CPLUSPLUS>{
auto{WS}  |
const{WS}  |
430 defined[ \t\n(]  |
enum{WS}  |
extern{WS}  |
register{WS}  |
sizeof[ \t\n(]  |
435 struct[ \t\n{]  |
typedef{WS}  |
union[ \t\n{]  yyless(yyleng–1); keyword();

8.9 Rules for special VMS Keywords

440 align[ \t\n(]  |
globaldef[ \t\n{]  |
globalref[ \t\n{]  |
globalvalue[ \t\n{]  |
main program[ \t\n{]  |
445 MAIN PROGRAM[ \t\n{] |
noshare[ \t\n{]  |

Page 15

Produced from tiny c2l.l on 25–Feb–2000 08:39

readonly[ \t\n{]  |
variant struct[ \t\n{]  |
variant union[ \t\n{]  yyless(yyleng–1); keyword();
450 }

8.10 Rules for C++ Keywords

<CPLUSPLUS>{
and[ \t\n(]  |
455 and eq[ \t\n(]  |
asm[ \t\n{]  |
bitand[ \t\n(]  |
bitor[ \t\n(]  |
bool{WS}  |
460 compl{WS}  |
const cast[ \t\n<]  |
dynamic cast[ \t\n<]  |
explicit{WS}  |
export{WS}  |
465 friend{WS}  |
inline[ \t\n{]  |
mutable[ \t\n∗)]  |
namespace[ \t\n{]  |
not[ \t\n(]  |
470 not eq[ \t\n(]  |
or[ \t\n(]  |
or eq[ \t\n(]  |
reinterpret cast[ \t\n<]  |
static cast[ \t\n<]  |
475 template[ \t\n:]  |
typeid[ \t\n(]  |
typename[ \t\n(]  |
using{WS}  |
virtual{WS}  |
480 wchar t[ \t\n∗)]  |
xor[ \t\n(]  |
xor eq[ \t\n(]  yyless(yyleng–1); keyword();

}

485

8.11 Rules for Java only Keywords

<JAVA>{
abstract{WS}  |
boolean{WS}  |
490 byte{WS}  |
byvalue{WS}  |
extends{WS}  |
final{WS}  |
finally[ \t\n{]  |
495 implements{WS}  |
import{WS}  |

Page 16

inner{WS}  |
instanceof{WS}  |
interface{WS}  |
500 native{WS}  |
null[ \t\n)]  |
package{WS}  |
super[ \t\n(]  |
synchronized{WS}  |
505 throws{WS}  |
transient{WS}  keyword();

}

8.12 Rules for C++/Java Keywords

510 <CPLUSPLUS,JAVA>{
catch[ \t\n(]  |
class{WS}  |
const[ \t\n∗]  |
delete[ \t\n\[(<]  |
515 false[ \t\n;]  |
new[ \t\n\[(<]  |
operator[ \t\n+\–∗/%|&ˆ ∼!=<>\[(,] |
private[ \t\n:]  |
protected[ \t\n:]  |
520 public[ \t\n:]  |
this[ \t\n\–.∗]  |
throw[ \t\n(]  |
true[ \t\n;]  |
try[ \t\n{]  yyless(yyleng–1); keyword();
525 }

8.13 Rules for Strings

\"\" init out(0); fprintf(yyout,“{\\tt \"\"}”); LEN(8);
\\∗\" {
530  if(yyleng%2){ /∗ even number of ‘\’: begin string ∗/

init out(0); if(yyleng>1)

fprintf(yyout,“\\bs{%d}\\qql}\\%s\\pes{\\bs{1}}{0}”,yyleng–1,

STRING FONT); else

535  fprintf(yyout,“\\qql}\\%s\\pes{\\bs{1}}{0}”,STRING FONT);
LEN(21+strlen(STRING FONT));
brace open=0;

BEGIN(STRING); }

540  else{ /∗ odd number of ‘\’: no string ∗/

init out(0);

fprintf(yyout,“\\bs{%d}{\\tt \"}”,yyleng–1);

LEN(14); }

545  }

<STRING>{
\n {
if(brace open)fputc('}',yyout);
550  line++;
pos=leng=brace open=0;
fprintf(yyout,“\\n\n\\initc000”);

current line(); LEN(20);

555  }
“ ”+ init out(0); for(tmp=0;tmp<yyleng;tmp++)fputc('∼',yyout); fputc('}',
yyout); brace open=0; LEN(yyleng+1);
\t  print jmpo(0);
\\+n init out(0); fprintf(yyout,“\\bs{%d}n}”,yyleng–1); LEN(9); brace open=0;
560 \\∗\" {
if(yyleng%2){ /∗ even number of ‘\’: end string ∗/

init out(0);

if(yyleng>1)

fprintf(yyout,“\\bs{%d}\\%s \\qqr}\\%s”,yyleng–1,BASE FONT,

BASE FONT);

565  else
fprintf(yyout,“\\%s \\qqr}\\%s”,BASE FONT,BASE FONT);
if(pes old>=0)
fprintf(yyout,“\\pes{ \\bs{1}}{%d}\\njo0{”,pes old);

else

570  fprintf(yyout,“\\ped\\pstart\\pstarta\\njo0{”);
LEN(36+strlen(BASE FONT));

BEGIN(sc1); }

else{ /∗ odd number of ‘\’: no string ∗/
575  init out(0);
fprintf(yyout,“\\bs{%d}{\\tt \"}”,yyleng–1);

LEN(14); }

}

580 }

8.14 Rules for Comments

“/∗\\f”[ ]∗ {
if(pos<ALIGN CMT LIMIT)cmt pos=pos+2;
585  init out(1);
cmt mode=3;
old pos=pos–yyleng>ALIGN CMT LIMIT ? –2 : pos–yyleng;
fprintf(yyout,“/$\\ast$\\%s”,COMMENT FONT);
cmt blanks=0;
590  if(∗(yytext+yyleng–1)==' ')
for(ptr=yytext;∗ptr;)if(∗ptr++==' '){
fputc('∼',yyout);

cmt blanks++; }

595  LEN(13+strlen(COMMENT FONT));

BEGIN(FILL CMT); }

“/∗”(\\b)?[ ]∗ {
if(pos<ALIGN CMT LIMIT)cmt pos=pos+2;
600  init out(1);
if(∗(yytext+3)!='b'){ /∗ no block comment ∗/
cmt mode=1;
old pos=pos–yyleng>ALIGN CMT LIMIT ? –2 : pos–yyleng;

}

605  else
cmt mode=2;
cmt blanks=0;
fprintf(yyout,“/$\\ast$”);
if(∗(yytext+yyleng–1)==' '){
610  if(cmt mode==1){
fprintf(yyout,“\\%s”,COMMENT FONT);
LEN(13+strlen(COMMENT FONT));

}

else{
615  fprintf(yyout,“\\%s”,BLOCK FONT);
LEN(13+strlen(BLOCK FONT));

}

for(ptr=yytext;∗ptr;)if(∗ptr++==' '){
fputc('∼',yyout);
620  cmt blanks++;

} } BEGIN(C CMT);

}

625 \/\∗+\/  |
\/\∗{2,}(\\b)? {
if(pos<ALIGN CMT LIMIT)cmt pos=pos+2;

init out(1);

if(∗(yytext+yyleng–1)!='b'){ /∗ no block comment ∗/
630  cmt mode=1;
old pos=pos–yyleng>ALIGN CMT LIMIT ? –2 : pos–yyleng;

} else

cmt mode=2; /∗ block comment ∗/
635  cmt blanks=0;
if(yyleng==2 || yyleng==4 && ∗(yytext+3)=='b')
fprintf(yyout,“/$\\ast$”);
else if(∗(yytext+2)=='∗' && yyleng<11){
for(ptr=yytext+1,tmp=0;∗ptr++=='∗';tmp++);
640  fprintf(yyout,“/\\mast{%d}}”,tmp);
brace open=0;

}

else{
fprintf(yyout,“/}”);
645  brace open=0;
if(cmt mode==1)
tmp=pos;

else

tmp=pos–2;

650  fprintf(yyout,“\\mpout{%d}{%d}{%s}{%s}”,
tmp–yyleng+1,tmp–1,“$\\ast$”,“2pt”);

} LEN(15);

if(∗(yytext+yyleng–1)=='/'){
655  yyless(yyleng–1);
cmt mode=0;

} else

BEGIN(C CMT);

660  }
<CPLUSPLUS,JAVA>{
“//\\f”[ ]∗ |
\/{2,}[ ]∗ {

init out(2);

665  if(∗(yytext+3)=='f')

BEGIN(FILL CPP CMT); else

BEGIN(CPP CMT);

fprintf(yyout,“//”);
670  for(ptr=yytext,cmt blanks=0;∗ptr;)if(∗ptr++==' '){
fputc('∼',yyout);

cmt blanks++; }

old pos=pos–yyleng>ALIGN CMT LIMIT ? –2 : pos–yyleng;
675  fprintf(yyout,“}\\cmtpp{%d}{%d}”,old pos,cmt blanks);
brace open=0;

} }

680 <C CMT>\∗+\/ {
if(brace open)fputc('}',yyout);
brace open=cmt mode=0;
fprintf(yyout,“\\ccmtend\\%s”,BASE FONT);
pos+=yyleng;
685  if(yyleng>5){

LEN(31);

   fprintf(yyout,“\\mpout{%d}{%d}{%s}{%s}\\njo0{/}”,

pos–yyleng,pos–2,“$\\ast$”,“2pt”);

}

690  else{
fprintf(yyout,“\\njo0{\\mast{%d}/}”,yyleng–1);
LEN(10+strlen(BASE FONT)+yyleng);

} BEGIN(sc1);

695  }
<C CMT,FILL CMT>{
“ :” {

yyless(1);

700  if(cmt mode==2 || cmt mode==5)

print jmpo(0);

else{

pos++;

if(brace open)fputc('}',yyout);
705  chk cmt();
fprintf(yyout,“\\njo{%d}{”,pos);
brace open=1;

LEN(10); }

710  }
[ ][ˆ \t\n]\n {

yyless(1);

if(brace open)fputc('}',yyout);

chk cmt();

715  if(cmt mode==2 || cmt mode==5){
fprintf(yyout,“\\jmpo{%d}{”,++pos);

LEN(10); }

else{
720  fprintf(yyout,“\\njo{%d}{”,++pos);

LEN(9); }

brace open=1;

}

725 }
<FILL CMT>{ /∗ special rules for / ∗\f (fill comments for C) ∗/
“∗/” |
\n{SPO}\∗\/  {
730  if(brace open)fputc('}',yyout);
for(ptr=yytext;∗ptr;)if(∗ptr++=='\n')line++;

chk cmt();

brace open=cmt mode=0;
fprintf(yyout,“\\ccmtend\\%s”,BASE FONT);
735  pos+=yyleng;
fprintf(yyout,“\\jmpo{%d}{$\\ast$/}”,pos+=100);  /∗ force line break ∗/

LEN(20); BEGIN(sc1);

}

740 {SPO}\n{SPO} |
\n{SPO}\∗{SPO} {
if(brace open)fputc('}',yyout);

line++; chk cmt();

745 fprintf(yyout,“\\njo{%d}{”,++pos); /∗ replace pattern by a blank ∗/

LEN(9);

brace open=1;

}

(\n{SPO}\∗{SPO}){2,} {
750  if(brace open)fputc('}',yyout);
for(ptr=yytext;∗ptr;)if(∗ptr++=='\n')line++;
fprintf(yyout,“\\jmpo{%d}{}\\jmpo{%d}{”,pos+100,pos+200);  /∗ empty line
∗ with star ∗/
pos+=200;

LEN(23);

755  brace open=1;

}

(\n{SPO}){2,}(\∗{SPO})? |
\n{SPO}@\n{SPO} |
\n{SPO}\∗{SPO}@\n{SPO}\∗{SPO} {
760  if(brace open)fputc('}',yyout);
for(ptr=yytext;∗ptr;)if(∗ptr++=='\n')line++;
fprintf(yyout,“\\n\\jmpo{%d}{”,pos+=100);  /∗ empty line ∗/

LEN(12);

brace open=1;
765  }
{SP}@\n{SPO} |
{SP}@\n{SPO}\∗{SPO} {
if(brace open)fputc('}',yyout);

line++;

770  chk cmt();
fprintf(yyout,“\\jmpo{%d}{”,pos+=100);  /∗ force linebreak ∗/

LEN(9);

brace open=1;

}

775 }
<FILL CPP CMT>{ /∗ special rules for //\f (fill comments for C++/Java ) ∗/
\n{SPO}“//”{SPO} {
if(brace open)fputc('}',yyout);
780  line++;

chk cmt();

fprintf(yyout,“\\njo{%d}{”,++pos);  /∗ replace pattern by a blank ∗/

LEN(9);

brace open=1;
785  }
\n{SPO}“//”{SPO}@?\n{SPO}“//”{SPO} {
if(brace open)fputc('}',yyout);
for(ptr=yytext;∗ptr;)if(∗ptr++=='\n')line++;
fprintf(yyout,“\\jmpo{%d}{}\\jmpo{%d}{”,pos+100,pos+200);  /∗ empty line ∗/
790  pos+=200;

LEN(23);

brace open=1;

}

{SP}@\n{SPO}“//”{SPO} {
795  if(brace open)fputc('}',yyout);

line++; chk cmt();

fprintf(yyout,“\\jmpo{%d}{”,pos+=100);  /∗ force linebreak ∗/

LEN(9);

800  brace open=1;

} }

<C CMT,CPP CMT,FILL CMT,FILL CPP CMT,STRING>[‘'] init out(0); fprintf(yyout,
“{%c}”,∗yytext);

805

8.15 Rules for line breaking without spaces

\–{2,} { /∗ don’t split ++ –– ∗/

init out(0);

fputc('{',yyout);
810  for(tmp=0;tmp<yyleng;tmp++)fprintf(yyout,“\\mm”);
fputc('}',yyout);
LEN(yyleng∗3+2);

}

\+{2,} init out(0); ECHO; LEN(yyleng);

815

“<<=” |
“>>=” {
/∗ allow a linebreak before these patterns ∗/
if(brace open)fputc('}',yyout);
820  fprintf(yyout,“\\njo0{”);
if(∗ptr=='<')
fprintf(yyout,“\\mlt{2}=”);

else

fprintf(yyout,“\\mgt{2}=”);
825  brace open=1;

LEN(8); }

“||”  |
830 “&&”  |
“+=”  |
“-=”  |
“∗=”  |
“/=”  |
835 “&=”  |
“|=”  |
“%=”  |
“<=”  |
“>=”  |
840 “==”  |
“!=”  |
[+\–∗/%={] {
/∗ allow a linebreak before these patterns ∗/
if(brace open)fputc('}',yyout);
845  brace open=0;

init out(0);

for(ptr=yytext;∗ptr;ptr++)fprintf(yyout,“%s”,subst(∗ptr));

LEN(9); }

850 [,;}] init out(0); fprintf(yyout,“%s}”,subst(∗yytext)); brace open=0;
[a–zA–Z0–9$ ]+ {  /∗ C identifier: print them out ∗/

init out(0);

for(ptr=yytext;∗ptr;ptr++)switch(∗ptr){
case ' ':
855  case '$': fprintf(yyout,“%s”,subst(∗ptr)); break;
default: fputc(∗ptr,yyout); break;

} LEN(yyleng);

}

860

<INITIAL,CPLUSPLUS,JAVA>\'.\' {

init out(0);

fprintf(yyout,“{\\sq}%s{\\sq}”,subst(∗(yytext+1)));

}

865

<INITIAL,CPLUSPLUS,JAVA,STRING,C CMT,CPP CMT,FILL CMT,
FILL CPP CMT>{
. {

init out(0);

fprintf(yyout,“%s”,subst(∗yytext));
870  }
\f\n?  fprintf(yyout,“\\newpage\n”); if(∗(yytext+yyleng–1)=='\n')line++;
[a–zA–Z0–9]+ init out(0); fprintf(yyout,“%s”,yytext);

}

8.16 Rules for omitting Code

<LINE BEGIN>{
{SPO}“/∗”\\o[q+]“∗/”{SPO}\n {
for(ptr=yytext;∗ptr++!='o';);
if(∗ptr=='+')
880  skip cnt=0;

else

skip cnt= –1;
tmp= –1;
sc=YY START;
885  BEGIN(OMIT);

line++; }

{SPO}“/∗”\\o[1–9]+q¿‘∗/”{SPO}\n {
for(ptr=yytext;∗ptr++!='o';);
890  tmp=atoi(ptr);
skip cnt= –1;
for(;∗ptr && ∗ptr!='q';ptr++)if(∗ptr=='∗')skip cnt=0;

BEGIN(OMIT); line++;

895  }

}

<OMIT>{
{SPO}“/∗\\o-∗/”{SPO}\n {
900  if(sc==C CMT)chk cmt();
if(sc==STRING)fprintf(yyout,“\\%s”,STRING FONT);

skip msg();

brace open=0;

BEGIN(LINE BEGIN);

905  line++;

}

\/\∗+(\\b)? sc=C CMT; if(∗(yytext+yyleng–1)=='b')cmt mode=2; else cmt mode

=1;

\∗+\/  sc=sc1; cmt mode=0;
\\∗\" {
910  if(yyleng%2 && sc!=C CMT)
if(sc!=STRING)

sc=STRING; /∗ begin of string ∗/

else

sc=sc1;  /∗ end of string ∗/
915  }
\∗+
\/+

\\

[ˆ \\\"∗\/\n]+  /∗ skip ∗/
920 \n {
if(skip cnt>=0)skip cnt++;

line++;

if(!––tmp){
if(sc==C CMT)chk cmt();
925  skip msg();
brace open=0;

BEGIN(LINE BEGIN); }

}

930 <<EOF>> skip msg(); yyterminate();

}

8.17 Rules for Embedded L^{A}TEX

<CPLUSPLUS>“//\\a ” init out(0); fprintf(yyout,“}// ”); brace open=0;

BEGIN(EL CMT3);

935 <EL CMT3>\n yyless(0); BEGIN(CPLUSPLUS);
<INITIAL,CPLUSPLUS,LINE BEGIN>{
“/∗\\a”  init out(0); fprintf(yyout,“}\\ped{}/$\\ast$”); brace open=0;

BEGIN(EL CMT1);

{SPO}“/∗\\v”  |
{WSO}“/∗\\v1” {
940  for(ptr=yytext;∗ptr;)if(∗ptr++=='\n')line++;
if(brace open)fputc('}',yyout);
brace open=0;
fprintf(yyout,“\\ped{}\n”);

BEGIN(EL CMT2);

945  }

}

<EL CMT1,EL CMT2>{
\n ECHO; line++;
950 “∗/”{SPO}\n? {
if(YY START==EL CMT1)fprintf(yyout,“$\\ast$/”);
if(∗(yytext+yyleng–1)=='\n'){
pos=leng=brace open=0;
sc=sc1;
955  line++;
fputc('\n',yyout);

BEGIN(LINE BEGIN); }

else{
960  BEGIN(sc1);

LEN(7);

} }

}

965 <EL CMT1,EL CMT2,EL CMT3>[ˆ \t\n∗]+ ECHO;
%%

9 C Code section

9.1 Function chk cmt(void)

void chk cmt(void)
970 {
/∗ values for cmt mode:
∗ cmt mode==1: normal comment mode (first line)
∗ cmt mode==2: block comment mode
∗ cmt mode==3: fill mode (Started with / ∗\f)
975  ∗ cmt mode==4: normal comment mode (not in the first line)
∗ cmt mode==5: block comment mode (continuation)
∗/
if(cmt mode==1 || cmt mode==3){
fprintf(yyout,“\\cmt{%d}{%d}”,old pos,cmt blanks);
980  cmt mode=0;

}

else if(cmt mode==2){
fprintf(yyout,“\\%s ”,BLOCK FONT);
LEN(2+strlen(BLOCK FONT));
985  cmt mode=5;

} }

9.2 Function skip msg(void)

990 void skip msg(void)

{

if(skip cnt==1)

   fprintf(yyout,“\\par\\centerline{/\\mast{20}{ \\commentfont SKIP A LINE \
}\\mast{20}/}\\par\n”);

else if(skip cnt>1)

995  fprintf(yyout,“\\par\\centerline{/\\mast{20}{ \\commentfont SKIP %d LINES \

}\\mast{20}/}\\par\n”,skip cnt);

}

9.3 Function keyword(void)

void keyword(void)
1000 {

init out(0);

fprintf(yyout,“{\\%s ”,KEYWORD FONT);
for(ptr=yytext;∗ptr;)fprintf(yyout,“%s”,subst(∗ptr++));
fputc('}',yyout);
1005  LEN(3+strlen(KEYWORD FONT)+yyleng);

Page 26 yy set bol(0);

if(YY START==PREPROCESSOR)BEGIN(sc1);

}

9.4 Function init out(void)

void init out(int mode)

{

/∗ mode==0: kein \cmtinit
∗ mode==1: \cmtinit für C–Kommentar
1015  ∗ mode==2: \cmtinit für C++–Kommentar
∗/
pos+=yyleng;
if(mode==0){
if(!brace open){
1020  chk cmt();
fprintf(yyout,“\\njo0{”);
leng+=7;

} }

1025  else{
if(brace open)fputc('}',yyout);
if(pos–yyleng>ALIGN CMT LIMIT){ /∗ position is too far right; omit \cmtinit
∗/
fprintf(yyout,“\\njo0{”);
leng+=7;
1030  }
else{
fprintf(yyout,“\\cmtinit\\njo0{”);
leng+=15;

}

1035  }
brace open=1;

}

9.5 Function print jmpo(int linebegin)

1040 void print jmpo(int linebegin)

{

int old=pos;
for(ptr=yytext;∗ptr==' ' || ∗ptr=='\t';ptr++){
if(∗ptr=='\t')
1045  pos+=tab2spc–pos%tab2spc;

else

pos++; }

if(linebegin){
1050  fprintf(yyout,“\\init{%d}”,pos);

current line();

fprintf(yyout,“\\njo{%d}{”,–pos);
leng=18;

}

1055  else if(brace open){
fputc('}',yyout);

chk cmt();

if(YY START==FILL CMT || YY START==FILL CPP CMT){
fprintf(yyout,“\\xnjo{%d}{%d}{”,pos–old,pos);
1060  LEN(13);

}

else{
fprintf(yyout,“\\jmpo{%d}{”,pos);

LEN(10);

1065  }

}

else{

chk cmt();

if(YY START==FILL CMT || YY START==FILL CPP CMT){
1070  fprintf(yyout,“\\xnjo{%d}{%d}{”,pos–old,pos);

LEN(13); }

else{
fprintf(yyout,“\\jmpo{%d}{”,pos);
1075  LEN(10);

} }

brace open=1;

}

1080

9.6 Function die(char *cmd,int mode)

int die(char ∗cmd,int mode)

{

switch(mode){
1085  case 1:

   fprintf(stderr,“Can't open %s for read; exit\n”,cmd);

exit(4);

case 2:

   fprintf(stderr,“Can't open %s for write; exit\n”,cmd);

1090  exit(4);
case 3:
fprintf(stderr,“%s\n”,cmd);

exit(4); default:

1095  return 0;

} }

9.7 Function subst(int c)

1100 char ∗subst(int c)

{

static char retbuffer[2];
if(c<0)c+=256;

1105  switch(c){
case '#': leng+=2; return “\\#”;
case '$': leng+=2; return “\\$”;
case '%': leng+=2; return “\\%”;
case '&': leng+=2; return “\\&”;
1110  case '\'': leng+=3; return “\\sq{}”;
case '∗': leng+=6; return “$\\ast$”;
case '–': leng+=5; return “{\\mm}”;
case '<': leng+=3; return “$<$”;
case '>': leng+=3; return “$>$”;
1115  case '[': leng+=3; return “{[}”;
case '\\': leng+=4; return “\\bs{1}”;
case ']': leng+=3; return “{]}”;
case 'ˆ ': leng+=9; return “$\\hat{∼}$”;
case ' ': leng+=5; return “{\\ul}”;
1120  case '‘': leng+=3; return “{`}”;
case '{': leng+=6; return “\\brl{}”;
case '|': leng+=6; return “$\\mid$”;
case '}': leng+=6; return “\\brr{}”;
case '∼': leng+=6; return “$\\sim$”;
1125  case '"': leng+=7; return “{\\tt \"}”;
default:  leng++; ∗retbuffer=c; return retbuffer;

} }

9.8 Function substitute format(char *format)

void substitute format(char ∗format)

{

char c,∗ptr1;
1135  for(ptr=format;∗ptr;ptr++){
if(∗ptr=='%'){  /∗ escape sequences: ∗/
switch(∗++ptr){
case 'd':  /∗ %d: day of month ∗/
fprintf(yyout,“%d”,atime–>tm mday);
1140  break;
case 'D':  /∗ %D: date (format DD–MMM–YYYY) ∗/
fprintf(yyout,“%d{\\mm}%s{\\mm}%ld”,atime–>tm mday,month1[atime
–>tm mon],year);

break;

case 'f':  /∗ %f: input file name ∗/
1145  for(ptr1=inputname;∗ptr1;)fprintf(yyout,“%s”,subst(∗ptr1++));

break;

case 'h':
fprintf(yyout,“%02d”,atime–>tm hour);

break;

1150 case 'm': /∗ %m: month (numeric value) ∗/
fprintf(yyout,“%d”,atime–>tm mon+1);

break;

case 'M':  /∗ %M: minute ∗/
fprintf(yyout,“%02d”,atime–>tm min);
1155  break;

case 'n':  /∗ %n: (english) name of month (full form) ∗/
fprintf(yyout,“%s”,month[atime–>tm mon]);

break;

case 'N':  /∗ %N: (local) name of month (full form) ∗/
1160  fprintf(yyout,“%s”,local month[atime–>tm mon]);

break;

case 's':  /∗ %s: (english) name of month (short form) ∗/
fprintf(yyout,“%s”,month1[atime–>tm mon]);

break;

1165 case 'S': /∗ %S: (local) name of month (short form) ∗/
fprintf(yyout,“%s”,local month1[atime–>tm mon]);

break;

case 'p':  /∗ %p: page (in the LaTeX file) ∗/
fprintf(yyout,“\\thepage”);
1170  break;
case 't':  /∗ %t: time (format HH:MM) ∗/
fprintf(yyout,“%02d:%02d”,atime–>tm hour,atime–>tm min);

break;

case 'y':  /∗ %y: year ∗/
1175  fprintf(yyout,“%ld”,year);

break;

case '%':  /∗ %%: the ‘%’ character itself ∗/
fputc('\\',yyout);
fputc('%',yyout);
1180  break;
default:  /∗ unknown escape sequence: just print it out ∗/

fprintf(stderr,“Unknown escape sequence `%%%c' detected; print \

it out.\n”,∗ptr);
fprintf(stderr,“(format string was >%s<)\n”,format);
fputc('%',yyout);
1185  fprintf(yyout,“%s”,subst(∗ptr));

break; }

} else

1190  fprintf(yyout,“%s”,subst(∗ptr));

}

fprintf(yyout,“}\n”);

}

9.9 Function current line(void)

void current line(void)

{

if(show lines>0 && line%show lines==0){
fprintf(yyout,“{%d}”,line);
1200  }

else

fprintf(yyout,“{}”);

LEN(10); }

1205

Produced from tiny c2l.l on 25–Feb–2000 08:39

9.10 Function main(int argc, char **argv)

int main(int argc, char ∗∗argv)

{

int i;

1210

#ifdef FLEX DEBUG
yy flex debug=0;
#endif /∗ FLEX DEBUG ∗/

time(&time val);

1215  atime=localtime(&time val);
year=time val/(365L∗24L∗60L∗60L)+1970L;
sc=sc1=INITIAL;
for(i=1;i<argc;i++){
if(∗argv[i]=='–'){
1220  for(ptr=argv[i]+1;∗ptr;)switch(∗ptr++){
case 'd':
#ifdef FLEX DEBUG
yy flex debug=1;
#else

1225  fprintf(stderr,“tiny c2l was compiled without debug info; ignore \
switch -d\n”);

#endif

break;

case '+':
sc=sc1=CPLUSPLUS;
1230  break;
case 'j':
sc=sc1=JAVA;

break;

case 'h':
1235  switch(∗ptr++){
case 'n': use header=0; break; /∗ no header ∗/
case 'l': lhead=ptr; break;  /∗ left header text ∗/
case 'c': chead=ptr; break;  /∗ center header text ∗/
case 'r': rhead=ptr; break;  /∗ right header text ∗/
1240  default: break;

}

while(∗ptr)ptr++; /∗ forget the rest of the argument ∗/

break;

case 'l':
1245  if(∗ptr)
show lines=atoi(ptr);

else

show lines=5;
while(∗ptr)ptr++; /∗ forget the rest of the argument ∗/
1250  break;
case 'f':
switch(∗ptr++){
case 'l': lfoot=ptr; break;  /∗ left footer text ∗/
case 'c': cfoot=ptr; break;  /∗ center footer text ∗/
1255 case 'r': rfoot=ptr; break; /∗ right footer text ∗/
default: break;

} Page 31

while(∗ptr)ptr++; /∗ forget the rest of the argument ∗/

break;

1260  case 'o': /∗ output name ∗/
if(!yyout)(yyout=fopen(ptr,“w”)) || die(ptr,2);

break;

case 't':
tab2spc=atoi(ptr);
1265  break;
case '?':

                   fprintf(stderr,“tiny c2l Version %s (%s)\n%s%d%s”,

VERSION,VERSION DATE,usage text1,TAB2SPC,usage text2);
#if VMS
1270  exit(1);
#else

exit(0);

#endif

default:

1275  break;

}

}
else if(!yyin)  /∗ argument without leading ’–’: input or output name ∗/
(yyin=fopen(inputname=argv[i],“r”)) || die(inputname,1);
1280  else if(!yyout)
(yyout=fopen(argv[i],“w”)) || die(argv[i],2);
}
if(!yyin)yyin=stdin;  /∗ no inputname specified ∗/
if(!yyout)yyout=stdout;  /∗ no outputname specified ∗/
1285  if(inputname){
for(ptr=inputname,ptr1=buffer;∗ptr;)
switch(∗ptr){
case ' ':
case '$': ∗ptr1++='\\';
1290  default:
∗ptr1++= ∗ptr++;

break; }

∗ptr1=0;
1295  }

else

strcpy(buffer,inputname=“(stdin)”);
#ifdef FLEX DEBUG
if(yy flex debug){
1300  /∗ FLEX gives very much debug info; write the stuff to a file ∗/

           fprintf(stderr,“redirect stderr to file tiny c2l.dbg\n”);

(freopen(“tiny c2l.dbg”,“w”,stderr))

              || die(“error opening file tiny c2l.dbg for stderr (freopen)”,3);

}

1305 #endif /∗ FLEX DEBUG ∗/

yylex();

/∗ write the end of the LaTeX file ∗/
if(brace open)fputc('}',yyout);
1310  fprintf(yyout,“\\end{flushleft}\n\

     \\ifmfiles\\def\\END{\\relax}\\else\\def\\END{\\end{document}}\\fi\n\

\\END\n”);

fclose(yyin); fclose(yyout);

1315 }