summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/c-pascal/cap_comm.tex
blob: 3f407580b352a96a68b6471de1cac941dc1fff02 (plain)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%     CAP  ---  Macros for typesetting programs in C and Pascal     %
%       Micha\l{} Gulczy\'nski, Szczecin, Feb 1997 / Feb 1998       %
%                     mgulcz@we.tuniv.szczecin.pl                   %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  version 1.2
%    This file contains common definitions used in the CAP package.
%    It does not contain any useful macros itself.
%


%
%      macro that compares two strings
%
\def\@Identical#1#2{%
  MG\fi
  \edef\@FirstString{#1}%
  \edef\@SecondString{#2}%
  \ifx \@FirstString \@SecondString
}
%
%      font declarations
%
{% a tiny trick that lets TeX check if the user has PL fonts...
 \catcode`\p = 12
 \catcode`\l = 12
 \catcode`\r = 12
 \xdef\xxx{plr10}
}
\if\@Identical{\xxx}{\fontname\tenrm}
  \font\tenttsl = plsltt10
  \font\tenttit = plitt10
\else
  \font\tenttsl = cmsltt10
  \font\tenttit = cmitt10
\fi
\let\IdentifierFont = \it
\let\TextFont = \sl
\let\KeywordFont = \bf
\let\CommentFont = \tenttit
\let\DirectiveFont = \tenttsl
\let\SymbolFont = \tt
\let\SpecialFont = \tt    % some characters: { } < > _ \ and | are very
                          % special -- they exist only in tt fonts
%
%      registers and constants used in the program
%
\newif\if@TempBool            % temporary boolean
\newread\@InFile              % file read by \Insert macros
\newcount\@CharCode           % code of current character
\newcount\@PrevChar           % code of previous charater
\newcount\@WhereAmI           % one of the following values:
\chardef\@NothingSpecial = 0
\chardef\@Text = 1
\chardef\@Directive = 2       % used only in C
\chardef\@ShortComment = 3    % C: //... ;    Pascal: (* ... *)
\chardef\@LongComment = 4     % C: /* ... */; Pascal: { ... }
%
%      I need a "not eof" function
%
\def\neof#1{%
  MG\fi
  \ifeof#1
    \@TempBoolfalse
  \else
    \@TempBooltrue
  \fi
  \if@TempBool
}
%
%      macro for changing catcodes of some special characters
%
\def\@TurnSpecialCharsOff{%
  \catcode`\/=12
  \catcode`\~=12
  \catcode`\#=12
  \catcode`\$=12
  \catcode`\%=12
  \catcode`\^=12
  \catcode`\&=12
  \catcode`\_=12
  \catcode`\\=12
  \catcode`\{=12
  \catcode`\}=12
  \catcode`\ =12
  \catcode`\^^M=12
}
%
%      macro that initiates all the variables
%
\def\@PrepareCPas{%
  \begingroup
  \parindent=0pt
  \rightskip=0pt plus 1fil
  \@TurnSpecialCharsOff
  \def\@Word{}%
  \@WhereAmI = \@NothingSpecial
  \@PrevChar = 32
  \SymbolFont
}
%
%      macro that outputs the char specified as the argument;
%      characters < > _  \ { | } are written with \SpecialFont
%
\def\@WriteChar#1{%
  \def\@Check##1{%
    \ifnum `#1=`##1
      {\SpecialFont #1}%
      \@TempBooltrue
    \fi
  }%
  \@TempBoolfalse
  \@Check{<}%
  \@Check{>}%
  \@Check{_}%
  \@Check{\\}%
  \@Check{\{}%
  \@Check{\}}%
  \@Check{|}%
  \if@TempBool
  \else
    \ifnum `#1=13
      \par\leavevmode
    \else
      \ifnum `#1=32
        \hskip 1ex
      \else
        #1%
      \fi
    \fi
  \fi
}
%
%      checks if word #1 is a keyword and writes it out;
%      #2 is a list of keywords separated with spaces
%
\def\@WriteWord#1#2{%
  \if\@OnListOfKeywords{ #1 }{#2}%
    {\KeywordFont #1}%
  \else
    {\IdentifierFont #1}%
  \fi
}
%
%      checks if string #2 contains string #1
%
\def\@OnListOfKeywords#1#2{%
  MG\fi
  \edef\@ExpandedArgument{{#1}}%
  \expandafter\@@OnListOfKeywords\@ExpandedArgument{#2}\relax
}
\def\@@OnListOfKeywords#1#2{%
  \def\@CheckList##1#1##2\@EndOfList{%
    \if\@Identical{##2}{}%
      \@TempBoolfalse
    \else
      \@TempBooltrue
    \fi
  }%
  \expandafter\@CheckList#2#1\@EndOfList\relax
  \if@TempBool
}
%
%      checks if the specified character is a digit or a letter
%
\def\@DigitLetter#1{%
  MG\fi
  \@TempBoolfalse
  \ifnum `\` < #1\relax   %   small letter?
    \ifnum `\{ > #1\relax
      \@TempBooltrue
    \fi
  \fi
  \ifnum `\@ < #1\relax   %   capital letter?
    \ifnum `\[ > #1\relax
      \@TempBooltrue
    \fi
  \fi
  \ifnum `\/ < #1\relax   %   digit?
    \ifnum `\: > #1\relax
      \@TempBooltrue
    \fi
  \fi
  \if@TempBool
}

\endinput