§1  c2cweb (Version 1.5)  INTRODUCTION 1

1. Introduction.

This is the  program by Werner Lemberg (  ).

The “banner line” defined here should be changed whenever is modified.

#define banner  ␣  ␣      ␣        ␣   ␣␣   ␣    ␣   ␣      ␣

2.

will transform ordinary C or C^{++} source code into formatted code. Three primary functions are performed: inserting -commands between code blocks, transforming comments into TEX-text, and replacing offending characters like , , etc. with commands TEX (and ) can understand.

The only changes the user has to do normally is to insert ‘  ’ or ‘  ’ starting a line outside of

a comment or string (the rest of these lines will be ignored):

• starts a new section and switches the function block algorithm on (see below).

• starts a new section and switches the function block algorithm off. This is the default when begins to scan a file.

Both ‘commands’ will be suppressed in the output (two additional commands are described in the ‘Hints and Tricks’-section).

3.

Normal C code consists of two parts: the code before function blocks (  and  statements,

prototypes, structure definitions, global variables, etc.) and the function blocks (i.e. ) itselves (possibly mixed with global definitions of variables, structures etc.). The main reason to separate them are memory constraints of ; inserting causes each function block to be written into an own section.

In header files, nothing is to do because there are no function blocks. In C code files, it’s usually sufficient to insert once, but you can structure your code further by inserting (and if necessary). See also the example file delivered with this package.

You will need a special executable which has among others two additional control codes sometimes needed. See also the section ‘Hints and Tricks’.

From now on, the words  and  will be used mutually in spite of the fact that  consists
of both the programs  and  —  is intended to create a well printed listing, and the

use of is of course possible but senseless.

2  THE PROGRAM  c2cweb (Version 1.5) §4

4. The program.

The use of response( ), wildcard ( ), and getname( ) is compiler specific. If you don’t use emx-gcc, it’s likely that you have to use different functions. If you use this program under DOS, consider the UNIX-like behavior of the “∗”-wildcard character.

After processing the options, the global variable optind (defined in ) is the index to the first file name.

#define  0
#define  1
#define  2
#define  3

⟨ Include files 5 ⟩;

⟨ Prototypes 11 ⟩;

⟨ Global variables 8 ⟩;

void main(argc, argv )

int argc; char ∗argv [ ];

{int i;

char buffer [ + + 1]; char ∗p, ∗q;

printf (banner );

#ifdef response(&argc, &argv ); /∗ to expand response files ∗/ wildcard (&argc, &argv ); /∗ to expand wildcards ∗/

#endif

⟨ Get command switches 9 ⟩;

⟨ Processing all files except the last one 6 ⟩;

⟨ Processing the last file 7 ⟩;

fclose(in); fclose(out ); }

5.

contains the UNIX-specific getopt ( ). If your system doesn’t support this function, get the GNU C-library for an implementation.

⟨ Include files 5 ⟩ ≡ #include #include #include #include #include

This code is used in section 4.

6.

⟨ Processing all files except the last one 6 ⟩ ≡ for (i = optind ; i < argc − 1; i^{++}) {printf ( ␣␣ ␣ , argv [i]);

§6  c2cweb (Version 1.5)  THE PROGRAM 3

open files (argv [i]);

q = protect underlines ( getname(argv [i]));

if ((p = strrchr (q, )) ≠ Λ) /∗ the macro suppresses the final dot after the section title

if the filename contains a dot ∗/ fprintf (out ,

, q, p); else

fprintf (out ,

, q);

handle input ( );

fclose(in);

fclose(out ); }

This code is used in section 4.

7.

The last file will be the ‘master’ file; you have to call with this file as the argument; all other files will be included.

⟨ Processing the last file 7 ⟩ ≡ printf ( ␣␣ ␣ , argv [i]);

open files (argv [i]); ⟨ Write limbo 13 ⟩; q = protect underlines ( getname(argv [i])); if ((p = strrchr (q, )) ≠ Λ)

fprintf (out ,

, q, p); else

fprintf (out ,

, q);

handle input ( ); ⟨ Write index section 32 ⟩;

strcpy (buffer , argv [argc − 1]); modify filename(buffer );

printf (

␣   ␣    ␣   ␣     ␣      ␣    ␣

␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ , outdir , getname(buffer )); if (optind < argc − 1)

printf ( ␣ ␣ ␣ ␣ ); printf ( );

This code is used in section 4.

4  THE INPUT SWITCHES  c2cweb (Version 1.5) §8

8. The input switches.

If the switch is set, all comments are written in typewriter type; comments starting a line will also start a line in the output.

All tabs will be expanded, and the switch defines the tab length (default value is 4).

The switch causes all linefeeds inside of C-text to be output explicitly by inserting a command at the end of each code line.

The output directory will be set with the option; this directory must already exist. Probably you have to adjust and pathsepchar [ ] to make it work correctly under your operating system.

To get a title, use the switch with the titlestring enclosed in double quotes; this string will be passed directly to TEX.

To include a format file (additionally to ), use the switch.

One-sided output is enabled with the option set.

The global variable optarg (defined in ) points to the option argument; the string optswchar [ ]

is modified to allow  and  as characters which start options (not under UNIX).
#define  80
#define  100
#define

⟨ Global variables 8 ⟩ ≡ int tab length = 4; int verbatim = ; int user linefeed = ; int one side = ; char outdir [ + 1]; char include file[ + 1]; char title[ + 1];

#ifdef char optchar [ ] = ; char pathsepchar [ ] = ;

#else char optchar [ ] = ; char pathsepchar [ ] = ;

#endif

char at nmb[ ] =  ;  /∗ the  command for inserting vertical space ∗/

See also sections 10, 15, 37, and 40. This code is used in section 4.

9.

⟨ Get command switches 9 ⟩ ≡ {char c; int i;

§9  c2cweb (Version 1.5)  THE INPUT SWITCHES 5

outdir [0] = ; include file[0] = ; title[0] = ; #ifdef

optswchar = optchar ; #endif

strcpy (title,  ␣  );  /∗ the default title ∗/

while ((c = getopt (argc, argv , )) ≠ ) {switch (c)

{case :

if (strchr (optchar , optarg [0])) /∗ check if argument is an option ∗/ usage( );

if (strlen(optarg ) ≥ )

fprintf (stderr ,

  ␣   ␣     ␣     ␣   ␣        ␣  );

else

strcpy (title, optarg ); break;

case :

if (strchr (optchar , optarg [0]))

usage( );

if (strlen(optarg ) ≥ )

fprintf (stderr ,

  ␣    ␣     ␣   ␣     ␣    ␣  ␣  );

else

strcpy (include file, optarg ); break;

case : user linefeed = ; break;

case :

if (strchr (optchar , optarg [0]))

usage( );

if ((i = strlen(optarg )) ≥ )

fprintf (stderr ,

  ␣         ␣     ␣   ␣     ␣    ␣   ␣  );

else {strcpy (outdir , optarg ); if (! strchr (pathsepchar , outdir [i − 1])) /∗ check if last character is a path separator ∗/ {outdir [i] = ; outdir [i + 1] = ; }

} break;

case :

if (strchr (optchar , optarg [0]))

usage( );

tab length = atoi (optarg ); if (tab length ≡ 0 ∨ tab length > 8)

tab length = 4; /∗ default value ∗/ break;

case : verbatim = ;

break; case :

one side = ; break; default: usage( ); break;

} }

if (optind ≡ argc) usage( );

}

This code is used in section 4.

10.

The output file has the same name as the input file but a different extension: it will append a or, if the extension is three characters long, substitute the third character with a , i.e. becomes , becomes , will be replaced by and so on (notice that for example also becomes ). If the character to be changed is a , an is used instead of. This will be done by the function modify filename( ). No checking for overwriting existing files is done.

#define  80

⟨ Global variables 8 ⟩ +≡ FILE ∗in, ∗out ;

11.

⟨ Prototypes 11 ⟩ ≡

void open files (char ∗);

See also sections 14, 33, 35, 38, 41, and 43. This code is used in section 4.

12.

void open files (filename)

char ∗filename;

{char buffer [  +  + 1];

if (strlen(filename) > − 2)

{fprintf (stderr , ␣␣ ␣ ␣ ␣ );

exit (−1);

}

if ((in = fopen(filename, )) ≡ Λ)

{fprintf (stderr , ␣␣ ␣ ␣ ␣ ␣ , filename); exit (−1); }

strcpy (buffer , outdir ); strcat (buffer , filename); modify filename(buffer ); if ((out = fopen(buffer , )) ≡ Λ) {fprintf (stderr , ␣␣ ␣ ␣ ␣ ␣ , buffer ); exit (−1); }

}

8  THE OUTPUT HEADER  c2cweb (Version 1.5) §13

13. The output header.

This is the header of the last output file. You must call with this file as an argument—all other processed files will be included.

Additionally this ‘master’ file will include the file , which should contain all system dependent definitions (like or ) not contained in the program. The syntax of is syntax; please read the documentation if you have questions. You should set the environment variable used by (and ) to the directory where resides.

The function getname( ) will accept forward and backward slashes as path separators if you compile under emx. However, options can be introduced with and , therefore paths starting with a forward slash must be enclosed in double quotes (not under UNIX).

⟨ Write limbo 13 ⟩ ≡ fprintf (out ,

  ␣

  ␣                 ␣  ␣

  ␣

, one side ? : , title);

if (∗include file)

fprintf (out ,

    ␣

, include file);

for (i = optind ; i < argc − 1; i^{++})

{strcpy (buffer , argv [i]); modify filename(buffer );

fprintf (out , ␣ , getname(buffer )); }

fputc( , out );

This code is used in section 7.

§14  c2cweb (Version 1.5)  INPUT HANDLING 9

14. Input Handling.

#define  500

⟨ Prototypes 11 ⟩ +≡ void handle input (void);

15.

This is a wild hack. Perhaps in a future version I will improve it.

⟨ Global variables 8 ⟩ +≡ char buffer [ + 1];

16.

The main routine. Characters which will be treated in a special way by and TEX are handled within a great switch.

#define xisspace(c) (isspace(c) ∧ ((unsigned char) c < ^{∘}200 ))

void handle input (void)

{char ∗buf p; char ch;

⟨ Control flags 17 ⟩; line number = 0; while (get line( )) {buf p = buffer ;

do {ch = ∗buf p;

⟨ Special cases 18 ⟩;

switch (ch) {case ␣ :

if (leading blanks ) {blank count^{++}; goto end ; } break;

case : {int i = tab length − (column % tab length);

column += i − 1; /∗ we’ll say later column^{++} ∗/

if (leading blanks ) {blank count += i; goto end ; }

while (i^{−})

10  INPUT HANDLING  c2cweb (Version 1.5) §16

fputc( ␣ , out ); goto end ; } break; case :

⟨ Cases for 20 ⟩; break;

case : ⟨ Cases for 25 ⟩; break;

case : ⟨ Cases for 26 ⟩; break;

case : ⟨ Cases for 29 ⟩; break;

case : ⟨ Cases for 30 ⟩; break;

case : ⟨ Cases for 21 ⟩; break;

case : ⟨ Cases for 22 ⟩; break;

case : ⟨ Cases for 23 ⟩; break;

case : ⟨ Cases for 24 ⟩; break;

default:

⟨ Cases for default 31 ⟩; break;

}

fputc(ch, out ); end :

buf p^{++}; column^{++}; } while (ch ≠ );

} }

17.

⟨ Control flags 17 ⟩ ≡ int any input = ; /∗ set after the first non blank character in a new section ∗/ int brace count = 0; int blank count = 0; int in comment = ; int in C = ; int in string = ; int short comment = ; int leading blanks = ;

int double linefeed =  ;  /∗ set if last character was a linefeed ∗/
int linefeed comment =  ;  /∗ set if a comment follows a linefeed immediately ∗/
int comment slash =  ;  /∗ set if last character was a slash ∗/
int comment star =  ;  /∗ set if last character was a star ∗/

int escape state = ;

/∗ needed to check whether in string or at the end of a preprocessor line ∗/

int before TeX text =  ;  /∗ the state after leaving a function block ∗/
int function blocks =  ;  /∗ set if function block algorithm is on ∗/

This code is used in section 16.

18.

Here comes a bunch of if -statements.

⟨ Special cases 18 ⟩ ≡ ⟨ Check conditions while at start of a line 19 ⟩;

if (double linefeed ∧ ch ≡ )

linefeed comment = ;

if (double linefeed ∧ (ch ≡ ␣ ∨ ch ≡ ))

leading blanks = ;

if (ch ≠  )  /∗ multiple linefeed ? ∗/

double linefeed = ;

if (! xisspace(ch)) /∗ whitespaces ? ∗/ {any input = ;

if (before TeX text ∧ function blocks )

{before TeX text = ;

if (function blocks ≡ )

function blocks = ; /∗ start at the second occurrence ∗/ else {fputs ( , out ); /∗ start a new text section ∗/

if (leading blanks )

{leading blanks = ;

while (blank count^{−}) fputc( ␣ , out ); blank count = 0; } }

}

if (in comment ∧ leading blanks )

{leading blanks = ; while (blank count^{−})

fputc( ␣ , out ); blank count = 0; }

}

if (! (ch ≡  ∨ xisspace(ch)))  /∗ whitespace or possible start of comment ? ∗/

{if (! (in comment ∨ in C ∨ comment slash)) /∗ outside of code ? ∗/ {in C = ;

fputs (  , out );  /∗ start of a new code section ∗/

if (leading blanks )

{leading blanks = ;

while (blank count^{−}) fputc( ␣ , out ); blank count = 0; }

}

if (! (in comment ∨ comment slash) ∧ leading blanks )

{leading blanks = ;

while (blank count^{−})

fputc( ␣ , out ); blank count = 0; }

}

if (comment slash ∧! (ch ≡  ∨ ch ≡ ))  /∗ start of a comment ? ∗/

{comment slash = ; if (! in comment )

linefeed comment = ;

fputc( , out ); }

if (comment star ∧ ch ≠ ) /∗ end of a comment ? ∗/ {comment star = ;

fputc( , out ); }

if (escape state ∧! (ch ≡  ∨ ch ≡  ∨ ch ≡  ))

/∗ end of string or end of preprocessor line or backslash itself ? ∗/

escape state = ;

This code is used in section 16.

19.

⟨ Check conditions while at start of a line 19 ⟩ ≡ if (buf p ≡ buffer ) {if (! (in comment ∨ in string ))

{if (! strncmp(buf p, , 6)) {in C = ; before TeX text = ; function blocks = ; /∗ switch on the algorithm ∗/ brace count = 0; if (any input )

fputs (

, out ); /∗ start a new section ∗/

any input = ; ∗(buf p^{−}) = ; /∗ the rest of the line will be ignored ∗/ goto end ; } else if (! strncmp(buf p, , 5)) {in C = ; before TeX text = ;

function blocks =  ;  /∗ switch off the algorithm ∗/

if (any input )

fputs (

, out );

any input = ; ∗(buf p^{−}) = ; goto end ; } else if (! strncmp(buf p, , 5)) {brace count^{++}; /∗ a dummy opening brace ∗/ fputs ( , out );

ch =  ;  /∗ an end of line is simulated ∗/

goto end ; } else if (! strncmp(buf p, , 5)) {brace count^{−}; /∗ a dummy closing brace ∗/ fputs ( , out );

if (! brace count ∧ function blocks ) /∗ end of function block reached ? ∗/ {in C = ; before TeX text = ;

break; }

ch = ; goto end ; } else if (! strncmp(buf p, , 6)) {fputs ( , out ); /∗ a dummy function body ∗/ ch = ; goto end ; }

} }

This code is used in section 18.

20.

⟨ Cases for 20 ⟩ ≡

if (in comment )

fputc( , out ); else if (in string )

break; else if (function blocks ) {brace count^{++}; in C = ; }

This code is used in section 16.

21.

⟨ Cases for 21 ⟩ ≡ if (in comment ) {fputs ( , out ); goto end ; } else /∗ needs to output ∗/

fputc( , out );

This code is used in section 16.

22.

⟨ Cases for 22 ⟩ ≡ if (! in comment )

{if (∗(buf p + 1) ≡  ∧ ∗(buf p + 2) ≡  )
escape state =  ;  /∗ this catches  ∗/

}

This code is used in section 16.

23.

⟨ Cases for 23 ⟩ ≡ if (! in comment ) /∗ start or end of a string ? ∗/ {if (escape state)

escape state = ; else

in string = − in string ; }

This code is used in section 16.

24.

⟨ Cases for 24 ⟩ ≡ if (in comment ) {fputs ( , out ); goto end ; } else

escape state = − escape state;

/∗ continuation of preprocessor line or an escape character ∗/

This code is used in section 16.

25.

⟨ Cases for 25 ⟩ ≡

if (in comment )

fputc( , out ); else if (in string )

break; else if (function blocks ) {brace count^{−}; if (! brace count ) /∗ end of function block reached ? ∗/ {in C = ;

before TeX text = ; break; }

}

This code is used in section 16.

26.

⟨ Cases for 26 ⟩ ≡ if (comment star ) {⟨ Cases for 27 ⟩; } else if (comment slash) {⟨ Cases for 28 ⟩; } else {comment slash = ;

goto end ; }

This code is used in section 16.

27.

⟨ Cases for 27 ⟩ ≡ comment star = ; leading blanks = ; if (! short comment )

{in comment =  ;  /∗ end of comment ∗/

if (! in C ) {linefeed comment = ;

if (verbatim)

fputs ( , out );

if (∗(buf p + 1) ≡  )  /∗ end of line ? ∗/

fputs ( , out );

goto end ; } if (in C ∧ verbatim) {if (linefeed comment )

{linefeed comment = ;

fputs ( , out );

if (∗(buf p + 1) ≡ ∧! user linefeed )

fputs ( , out ); goto end ; } else

fputc( , out );

}

linefeed comment = ;

if (in C ∨ verbatim)

fputc( , out ); else

goto end ; } else

fputc( , out );

This code is used in section 26.

28.

⟨ Cases for 28 ⟩ ≡ comment slash = ;

if (! short comment ) {in comment = ;

short comment =  ;  /∗ start of a short comment ∗/

if (! in C ∧ verbatim) {fputs ( , out ); if (leading blanks ) {leading blanks = ;

while (blank count^{−}) fputc( ␣ , out ); blank count = 0; } fputs ( , out ); goto end ; }

if (in C ∧ verbatim) {if (leading blanks ∨ linefeed comment )

{linefeed comment = ;

if (! user linefeed )

fputs ( , out ); fputs ( , out );

/∗ this cryptic command starts a comment line without indentation ∗/

if (leading blanks )

{leading blanks = ;

while (blank count^{−}) fputc( ␣ , out ); blank count = 0; } fputs ( , out ); } else

fputs ( , out );

goto end ; }

if (in C ∨ verbatim)

fputc( , out ); else

goto end ; } else

fputc( , out );

This code is used in section 26.

29.

⟨ Cases for 29 ⟩ ≡ if (comment slash) {comment slash = ;

if (in comment ∧! short comment ) /∗ uuh, ooh, for people who ‘comment out’ code with comments instead of using and for example—this non-ANSI behaviour would cause bad formatted code and is therefore not supported; the program exits ∗/

{fprintf (stderr , ␣␣␣␣ ␣ ␣ ␣ ␣ ␣ ␣ , line number ); exit (−1); }

if (! short comment )

{in comment =  ;  /∗ start of comment ∗/

if (! in C ∧ verbatim) {fputs ( , out ); if (leading blanks ) {leading blanks = ; while (blank count^{−})

fputc( ␣ , out ); blank count = 0; } fputs ( , out );

goto end ; }

if (in C ∧ verbatim) {if (leading blanks ∨ linefeed comment )

{linefeed comment = ; if (! user linefeed )

fputs ( , out ); fputs ( , out ); if (leading blanks ) {leading blanks = ;

while (blank count^{−})

fputc( ␣ , out ); blank count = 0; } fputs ( , out ); } else

fputs ( , out );

goto end ; }

if (in C ∨ verbatim)

fputc( , out ); else {fputs ( ␣␣ , out );

goto end ; }

} else

fputc( , out ); } else {comment star = ;

goto end ; }

This code is used in section 16.

30.

⟨ Cases for 30 ⟩ ≡ blank count = 0; if (! in comment ∧ in C ) {if (double linefeed ≡ )

{double linefeed = ;

if (escape state)

{escape state = ; /∗ continuation of a preprocessor line ∗/ leading blanks = ;

if (in string )

fputc( , out ); else

fputs ( , out ); goto end ; }

if (! leading blanks ∧ user linefeed )

fputs ( , out ); } else if (double linefeed ≡ ) {double linefeed = ;

/∗ blank lines in the input will be output as little white space between code lines ∗/

fputs (at nmb, out ); }

}

leading blanks = ;

if (short comment ) {short comment = ; in comment = ; double linefeed = ;

if (verbatim) {if (linefeed comment ∧ in C )

fputs ( , out ); else

fputc( , out ); }

if (! in C )

fputs ( , out ); else if (linefeed comment ∧ verbatim)

fputs ( , out );

linefeed comment = ; }

if (in comment ∧ in C ∧ verbatim ∧ linefeed comment ) {fputs ( , out ); /∗ continuation of a comment line without indentation ∗/ goto end ; }

if (in comment ∧ verbatim)

/∗ Both and TEX need an input at the beginning of a line to prevent leading blanks be

swallowed while in verbatim mode; this will be the macro which causes a linebreak ∗/ {fputs ( , out ); goto end ; }

This code is used in section 16.

31.

All other special characters will be substituted with proper sequences TEX can understand.

⟨ Cases for default 31 ⟩ ≡ if (in comment ) {switch (ch)

{case : fputs ( , out ); break;

case : fputs ( , out ); break;

case : fputs ( , out ); break;

case : fputs ( , out ); break;

case : fputs ( , out ); break;

case : fputs ( , out ); break;

case : fputs ( , out ); break;

case : fputs ( , out ); break;

case : fputs ( , out ); break;

case : fputs ( , out ); break;

case : fputs ( , out ); break;

default:

fputc(ch, out ); break;

} goto end ; }

This code is used in section 16.

32.

Because the index macros defined in  don’t append a dot, we have to redefine  .

⟨ Write index section 32 ⟩ ≡ fprintf (out ,

);

This code is used in section 7.

33.

⟨ Prototypes 11 ⟩ +≡ void usage(void);

34.

void usage(void) {fprintf (stderr ,

␣      ␣          ␣              ␣ ␣
␣␣        ␣
␣␣␣␣  ␣         ␣ ␣␣␣   ␣
␣␣␣␣  ␣␣␣␣␣␣␣␣␣␣␣␣   ␣     ␣
␣␣␣␣  ␣       ␣␣␣ ␣   ␣      ␣         ␣     ␣       ␣
␣␣␣␣  ␣        ␣␣ ␣   ␣    ␣    ␣  ␣ ␣      ␣
␣␣␣␣  ␣         ␣ ␣   ␣         ␣       ␣        ␣
␣␣␣␣  ␣␣␣␣␣␣␣␣␣␣␣␣        ␣
␣␣␣␣  ␣␣␣␣␣␣␣␣␣␣␣␣         ␣

);

exit (−1); }

35.

⟨ Prototypes 11 ⟩ +≡ void modify filename(char ∗);

36.

If a response file is expanded, trailing blanks can occur which will be ignored here. The same happens if a filename with trailing blanks is enclosed in quotes.

void modify filename(name)

char ∗name; {char ∗p; if ((p = strrchr (name, )) ≠ Λ) {p^{++}; if (∗p ∧ ∗p ≠ ␣ )

p^{++}; if (∗p ∧ ∗p ≠ ␣ )

p^{++}; if (∗p ≠ )

∗p = ; else

∗p = ; p^{++}; ∗p = ; } else

strcat (name, ); }

37.

⟨ Global variables 8 ⟩ +≡ int line number = 0; int column;

38.

⟨ Prototypes 11 ⟩ +≡ char ∗get line(void);

39.

get line( ) gets the next line and removes all trailing blanks or tabs.

char ∗get line(void) {char ∗p; int i = ;

if ((p = fgets (buffer , + 1, in)) ≠ Λ) {while (i^{−})

{if (∗(p^{++}) ≡ )

break; }

p^{−}; p^{−}; while ((∗p ≡ ␣ ∨ ∗p ≡ ) ∧ p ≥ buffer )

p^{−}; ∗(p + 1) = ; ∗(p + 2) = ;

line number^{++}; column = 0; } return (p); }

40.

⟨ Global variables 8 ⟩ +≡ char tempbuf [2 ∗ + 1];

41.

⟨ Prototypes 11 ⟩ +≡ char ∗protect underlines (char ∗);

42.

This function is needed for the names of named sections, i.e. file names.

char ∗protect underlines (p)

char ∗p; {char ∗q;

q = tempbuf ;

do

{if (∗p ≡ )

∗(q^{++}) = ;

∗(q^{++}) = ∗p; } while (∗(p^{++}));

return tempbuf ;

}

43.

⟨ Prototypes 11 ⟩ +≡ #ifndef

char ∗ getname(char ∗); #endif

44.

For Linux and other UNIX-systems the function getname( ) must be defined.

#ifndef char ∗ getname(char ∗path) {char ∗p;

p = strrchr (path, );

return p ≡ Λ ? path : (p + 1); }

#endif

24  HINTS AND TRICKS  c2cweb (Version 1.5) §45

45. Hints and Tricks.

Some words are reserved by you would like to use. Here is a small list of them (see the manual for a complete one):

, , , …

To make a word unreserved write a line

ident x

into where ident is the reserved word.

Some words you would expect knows actually are not in its memory:

,  ,  , …

To make a word ident1 reserved you should write

ident1 ident2

into . Now ident1 will behave as ident2 ; for example

causes  to treat  as it treats  .

Bear always in mind that has been developed for use with UNIX and not for DOS or OS/2. Weird non-ANSI constructions like

void FAR ∗ FARFUNC Cdecl memcpy …

will cause some, hmmm, troubles if you use the original program. Until now it’s also a bit difficult to program for Windows^{TM} or the Presentation Manager^{TM}, because you have to include every structure and constant you use in your program manually, which can be a tedious work.

Do not use the same name for a structure and an instance of it. This means that you must avoid things like this:

struct foo foo;

would be confused totally. The same applies to all identifiers which will be used as reserved and as unreserved words at the same time (This usually will not affect identical names of variables and functions. But in this case the reader of your program will get confused).

Most of the C constants are written in upper case, and writes them in typewriter type. But some constants like or are mixed or lower case, and will use italic type instead of. Look at again to see a workaround how to get a correct output (Note: underline characters are converted to ‘x’ in the TEX control string).

Nested comments are not supported; the program aborts with an error message.

If you have unbalanced braces due to  …  constructions, you can keep  and
your editor happy if you write a  or  command where needed; otherwise memory of
can overflow.  replaces these commands with the equal  constructions (only defined in this

package’s modified version!).

Another trick with preprocessor conditionals:

#ifdef
int func1 { … }

#endif

Without the #endif instruction would be written into the next section.

§45  c2cweb (Version 1.5)  HINTS AND TRICKS 25

The command proved to be useful in cases like this:

#if

void func1 (int a)

#else

void func1 (a) int a;

#endif { … }

It is essentially the same as

but will not start a new section (Thus it is not necessary to insert a before the actual function).

26  INDEX  c2cweb (Version 1.5) §46

46. Index.

: 4, 8, 9, 43, 44. getname( ): 4, 6, 7, 13, \underline{43}, \underline{44}. response( ): 4. wildcard ( ): 4. any input : \underline{17}, 18, 19. argc: \underline{4}, 6, 7, 9, 13. argv : \underline{4}, 6, 7, 9, 13. at nmb: \underline{8}, 30. atoi ( ): 9. banner : \underline{1}, 4. before TeX text : \underline{17}, 18, 19, 25. blank count : 16, \underline{17}, 18, 28, 29, 30. brace count : \underline{17}, 19, 20, 25. buf p: \underline{16}, 19, 22, 27. buffer : \underline{4}, 7, \underline{12}, 13, \underline{15}, 16, 19, 39. : \underline{14}, 15, 39. c: \underline{9}. ch: \underline{16}, 18, 19, 31. column: 16, \underline{37}, 39. comment slash: \underline{17}, 18, 26, 28, 29. comment star : \underline{17}, 18, 26, 27, 29. : 13. : 4, \underline{8}, 9, 12. : \underline{4}, 30. double linefeed : \underline{17}, 18, 30. end : \underline{16}, 19, 21, 24, 26, 27, 28, 29, 30, 31. : 9. escape state: \underline{17}, 18, 22, 23, 24, 30. exit ( ): 12, 29, 34. : \underline{4}, 8, 17, 18, 19, 23, 25, 27, 28, 29, 30. fclose( ): 4, 6. fgets ( ): 39. : 4, 8, 9, \underline{10}, 12, 40. filename: \underline{12}. fopen( ): 12. fprintf ( ): 6, 7, 9, 12, 13, 29, 32, 34. fputc( ): 13, 16, 18, 20, 21, 25, 27, 28, 29, 30, 31. fputs ( ): 18, 19, 21, 24, 27, 28, 29, 30, 31. function blocks : \underline{17}, 18, 19, 20, 25. get line( ): 16, \underline{38}, \underline{39}. getopt ( ): 5, 9. handle input ( ): 6, 7, \underline{14}, \underline{16}. i: \underline{4}, \underline{9}, \underline{16}, \underline{39}. in: 4, 6, \underline{10}, 12, 39. in C : \underline{17}, 18, 19, 20, 25, 27, 28, 29, 30. in comment : \underline{17}, 18, 19, 20, 21, 22, 23, 24,

25, 27, 28, 29, 30, 31. in string : \underline{17}, 19, 20, 23, 25, 30. include file: \underline{8}, 9, 13. isspace( ): 16. leading blanks : 16, \underline{17}, 18, 27, 28, 29, 30. line number : 16, 29, \underline{37}, 39. linefeed comment : \underline{17}, 18, 27, 28, 29, 30. main( ): \underline{4}. modify filename( ): 7, 10, 12, 13, \underline{35}, \underline{36}. name: \underline{36}. one side: \underline{8}, 9, 13. open files ( ): 6, 7, \underline{11}, \underline{12}. optarg : 8, 9. optchar : \underline{8}, 9. optind : 4, 6, 7, 9, 13. optswchar : 8, 9. out : 4, 6, 7, \underline{10}, 12, 13, 16, 18, 19, 20, 21, 24,

25, 27, 28, 29, 30, 31, 32. outdir : 7, \underline{8}, 9, 12. p: \underline{4}, \underline{36}, \underline{39}, \underline{42}, \underline{44}. path: \underline{44}. : \underline{8}, 9. pathsepchar : \underline{8}, 9. printf ( ): 4, 6, 7. protect underlines ( ): 6, 7, \underline{41}, \underline{42}. q: \underline{4}, \underline{42}. short comment : \underline{17}, 27, 28, 29, 30. stderr : 9, 12, 29, 34. strcat ( ): 12, 36. strchr ( ): 9. strcpy ( ): 7, 9, 12, 13. strlen( ): 9, 12. strncmp( ): 19. strrchr ( ): 6, 7, 36, 44. tab length: \underline{8}, 9, 16. tempbuf : \underline{40}, 42. title: \underline{8}, 9, 13. : \underline{8}, 9. : \underline{4}, 9, 17, 18, 19, 20, 22, 23, 24, 25,

26, 28, 29, 30. usage( ): 9, \underline{33}, \underline{34}.

user linefeed : \underline{8}, 9, 27, 28, 29, 30.
verbatim: \underline{8}, 9, 27, 28, 29, 30.
: \underline{4}, 18, 19.
xisspace( ): \underline{16}, 18.

c2cweb (Version 1.5) NAMES OF THE SECTIONS 27

⟨ Cases for 29 ⟩ Used in section 16. ⟨ Cases for 27 ⟩ Used in section 26. ⟨ Cases for 26 ⟩ Used in section 16. ⟨ Cases for 28 ⟩ Used in section 26. ⟨ Cases for 21 ⟩ Used in section 16. ⟨ Cases for 23 ⟩ Used in section 16. ⟨ Cases for 22 ⟩ Used in section 16. ⟨ Cases for 24 ⟩ Used in section 16. ⟨ Cases for 30 ⟩ Used in section 16. ⟨ Cases for 20 ⟩ Used in section 16. ⟨ Cases for 25 ⟩ Used in section 16. ⟨ Cases for default 31 ⟩ Used in section 16.

⟨ Check conditions while at start of a line 19 ⟩ Used in section 18.

⟨ Control flags 17 ⟩ Used in section 16.

⟨ Get command switches 9 ⟩ Used in section 4.

⟨ Global variables 8, 10, 15, 37, 40 ⟩ Used in section 4. ⟨ Include files 5 ⟩ Used in section 4.

⟨ Processing all files except the last one 6 ⟩ Used in section 4. ⟨ Processing the last file 7 ⟩ Used in section 4.

⟨ Prototypes 11, 14, 33, 35, 38, 41, 43 ⟩ Used in section 4. ⟨ Special cases 18 ⟩ Used in section 16.

⟨ Write index section 32 ⟩ Used in section 7.

⟨ Write limbo 13 ⟩ Used in section 7.

The c2cweb program

(Version 1.5)

Section Page

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 The program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2

The input switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 4 The output header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 8 Input Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 9

Hints and Tricks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 24 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 26

Copyright \begin{matrix}c \\ ◯ \end{matrix} 1996 by Werner Lemberg

Permission is granted to make and distribute verbatim copies of this document provided that the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this document under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.