1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
/* {\hrulefill} *
{\ % beginning of TeX mode
\input fonts.tex % define fonts
\input title.tex % title and authors
% end of TeX mode}
* {\hrulefill} */
/* {\hrulefill\ pas\_bold.c\ \hrulefill} */
/*{\ In PASCAL, several key words are usually printed in bold face.
Our {\bf src2tex} and {\bf src2latex} print those key words
in bold typewriter fonts if the input file is written in PASCAL. \hfill}*/
#include <stdio.h>
#include "src2tex.h"
extern int *dec_buf_ptr(int *);
extern int *inc_buf_ptr(int *);
/* {\hrulefill\ table of key words of PASCAL\ \hrulefill} */
/* {\rm If input source file is written in PASCAL, then
the following words are printed in bold face.\hfill}*/
char *PAS_Table[] =
{"absolute", "and", "array",
"begin",
"case", "const",
"define", "div", "downto", "do",
"else", "end", "external",
"file", "forward", "for", "function",
"goto",
"if", "inline", "in",
"label", "let",
"mod",
"nil", "not",
"of", "or", "out",
"packed", "procedure", "program",
"record", "repeat", "return",
"set", "shl", "shr", "string",
"then", "to", "type",
"until",
"var",
"while", "with",
"xor",
""};
/* {\hrulefill\ compare two words\ \hrulefill} */
/* {\rm This function compares two strings
\smallskip
\qquad{\tt buf\_ptr}={\sl string1},\ {\tt tbl\_ptr}={\sl string2}
\smallskip
\noindent
and returns
\smallskip
$\qquad\displaystyle{\tt flag}\cases{
=0 &if {\sl string1=string2}\cr
\not=0 &otherwise\ .\cr}$
\smallskip
\noindent
However, compare\_word() is slightly different from strcmp().
\hfill}*/
int compare_word(buf_ptr, tbl_ptr)
int *buf_ptr;
char *tbl_ptr;
{
char c;
int *ptr, flag = 0;
/* {\ if the previous character is either an
alphabet or a number, then returns -1 \hfill} */
ptr = dec_buf_ptr(buf_ptr);
c = *ptr;
if ((c >= '0') && (c <= '9'))
return (-1);
if ((c >= 'A') && (c <= 'Z'))
return (-1);
if ((c >= 'a') && (c <= 'z'))
return (-1);
if (c == '_')
return (-1);
/* flag $\not=0$ if two strings are different {\hfill} */
/* flag = 0 otherwise {\hfill} */
ptr = buf_ptr;
while (*tbl_ptr != '\0')
{
c = *ptr;
/* upper case -> lower case {\hfill} */
if ((c >= 'A') && (c <= 'Z'))
c += 0x20;
flag = c - *tbl_ptr;
if (flag != 0)
break;
ptr = inc_buf_ptr(ptr);
++tbl_ptr;
}
/* {\ if the next character is either an
alphabet or a number, then returns -1 \hfill} */
c = *ptr;
if ((c >= '0') && (c <= '9'))
return (-1);
if ((c >= 'A') && (c <= 'Z'))
return (-1);
if ((c >= 'a') && (c <= 'z'))
return (-1);
if (c == '_')
return (-1);
return flag;
}
/* {\hrulefill\ get bold face flag\ \hrulefill} */
/* {\rm This function compares a string
\smallskip
\qquad{\tt buf\_ptr}={\sl string}
\smallskip
\noindent
with key words stored in {\tt PAS\_Table[]}.
If there exists a key word which is equal to given {\sl string},
then it returns the length of {\sl string}.\hfill}*/
int get_bf_flag(buf_ptr)
int *buf_ptr;
{
char **table, *ptr;
int i = 0;
for (table = PAS_Table; **table != '\0'; ++table)
{
if (compare_word(buf_ptr, *table) == 0)
{
#ifdef DEBUGGING
printf("compare_word(): ");
printf("a reserved word \"%s\" is found in PAS_table\n", *table);
#endif
/* strlen(*table) {\hfill} */
for (i= 0, ptr = *table; *ptr != '\0'; ++i, ++ptr);
break;
}
}
return i;
}
|