w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

ChkTeX.h
Go to the documentation of this file.
1 /*
2  * ChkTeX, header file for main program.
3  * Copyright (C) 1995-96 Jens T. Berger Thielemann
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * Contact the author at:
20  * Jens Berger
21  * Spektrumvn. 4
22  * N-0666 Oslo
23  * Norway
24  * E-mail: <jensthi@ifi.uio.no>
25  *
26  *
27  */
28 
29 #ifndef CHKTEX_H
30 #define CHKTEX_H 1
31 #if defined(HAVE_CONFIG_H) || defined(CONFIG_H_NAME)
32 # ifndef CONFIG_H_NAME
33 # define CONFIG_H_NAME "config.h"
34 # endif
35 # ifndef HAVE_CONFIG_H
36 # define HAVE_CONFIG_H 1
37 # endif
38 # include CONFIG_H_NAME
39 #endif
40 
41 /* For TeX Live */
42 #ifdef KPATHSEA
43 #include <kpathsea/config.h>
44 #endif
45 
46 #include <ctype.h>
47 #include <math.h>
48 #include <stdio.h>
49 
50 #ifdef HAVE_STDARG_H
51 # include <stdarg.h>
52 #else
53 #error Sorry, ChkTeX needs an _ANSI_ compiler w/stdarg.h installed to compile.
54 #endif
55 
56 #ifndef HAVE_VPRINTF
57 #error Sorry, ChkTeX needs an _ANSI_ compiler w/vprintf() to compile.
58 #endif
59 
60 #include <stddef.h>
61 #include <stdlib.h>
62 #include <string.h>
63 
64 #ifdef HAVE_UNISTD_H
65 # include <unistd.h>
66 #endif
67 
68 #ifdef HAVE_LIMITS_H
69 # include <limits.h>
70 #endif
71 
72 #ifdef HAVE_STRINGS_H
73 # include <strings.h>
74 #endif
75 
76 #ifdef HAVE_INTTYPES_H
77 # include <inttypes.h>
78 #endif
79 
80 #ifdef HAVE_STDINT_H
81 # include <stdint.h>
82 #endif
83 
84 #include "types.h"
85 
86 #ifndef LONG_MAX
87 # define LONG_MAX (0x7fffffff)
88 #endif
89 
90 #ifndef CHAR_BIT
91 # define CHAR_BIT (8)
92 #endif
93 
94 #include "FindErrs.h"
95 
96 #if defined(HAVE_FILENO) && defined(HAVE_ISATTY)
97 # include <stdio.h>
98 #endif
99 
100 /*
101  * Define aliases for preprocessor statements
102  */
103 
104 #if defined(__unix__) || defined(__unix) || defined(unix)
105 #undef __unix__
106 #define __unix__ 1
107 #elif defined(__APPLE__) && defined(__MACH__)
108 /* OS X should be considered a UNIX */
109 #undef __unix__
110 #define __unix__ 1
111 #elif defined(MSDOS) || defined(__MSDOS__) || defined(__msdos__)
112 #undef __MSDOS__
113 #define __MSDOS__ 1
114 #endif
115 
116 /* -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- */
117 
118 /*
119  * NOTE: All macros below should return FALSE (0) if the input
120  * character is 0.
121  *
122  * The next macro should return TRUE if LaTeX (and you?) considers
123  * the character `c' as a space, which should be detected when
124  * we're checking whether commands are terminated by spaces.
125  *
126  * Note: If you wish to change this macro, you'll have to update
127  * the main loop in FindErrs.c as well.
128  */
129 
130 #define LATEX_SPACE(c) (c > 0 && c <= ' ')
131 
132 /* -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- */
133 
134 
135 
136 
137 
138 
139 #define betw(a,b,c) ((a < b) && (b < c))
140 #define within(a,b,c) ((a <= b) && (b <= c))
141 
142 #ifndef min
143 # define min(a,b) ((a)<=(b)?(a):(b))
144 #endif
145 
146 #ifndef max
147 # define max(a,b) ((a)>(b)?(a):(b))
148 #endif
149 
150 #ifndef abs
151 # define abs(a) (a>=0?a:(-a))
152 #endif
153 
154 #define LOOP(name, body) {{body} _end__##name:;}
155 #define LAST(name) goto _end__##name
156 
157 #define NUMBRACKETS 6
158 
159 #define NEWBUF(name,len) \
160 static char _ ## name [len + (WALLBYTES<<1)] = {0}; \
161 char *name = &_ ## name[WALLBYTES]
162 
163 #define INTFAULTMSG "INTERNAL FAULT OCCURED! PLEASE SUBMIT A BUG REPORT!\n"
164 
165 #define INTERNFAULT INTFAULTMSG
166 
167 #define BITDEF1(a) BIT_ ## a
168 #define BITDEF2(a) FLG_ ## a = (1<<BIT_ ## a)
169 
170 /*
171  * Debugging info
172  */
173 
174 #define DEBUGBITS(a) enum a { \
175  BIT(DbgMsgs), /* Dump messages */ \
176  BIT(DbgListInfo), /* Dump list info */ \
177  BIT(DbgListCont), /* Dump list contents */ \
178  BIT(DbgOtherInfo), /* Dump misc. other info */ \
179  BIT(DbgRunTime) /* Dump runtime info */ \
180 };
181 
182 #undef BIT
183 #define BIT BITDEF1
185 #undef BIT
186 #define BIT BITDEF2
188 #ifdef STRIP_DEBUG
189 # define DEBUG(a)
190 #else
191 # define DEBUG(a) if(DebugLevel & FLG_DbgRunTime) ErrPrintf a
192 #endif
193 #define PRGMSGS \
194  MSG(pmMinFault, etWarn, TRUE, 0, INTERNFAULT)\
195  MSG(pmNoFileMatch, etWarn, TRUE, 0,\
196  "No files matched the pattern `%s'.")\
197  MSG(pmNoTeXOpen, etWarn, TRUE, 0,\
198  "Unable to open the TeX file `%s'.")\
199  MSG(pmRename, etMsg, TRUE, 0,\
200  "Renaming `%s' as `%s'.")\
201  MSG(pmRenameErr, etErr, TRUE, 0,\
202  "Could not rename `%s' to `%s'.")\
203  MSG(pmOutOpen, etErr, TRUE, 0,\
204  "Unable to open output file.")\
205  MSG(pmOutTwice, etErr, TRUE, 0,\
206  "You can specify output file only once.")\
207  MSG(pmStrDupErr, etErr, TRUE, 0,\
208  "Unable to duplicate strings - no memory?")\
209  MSG(pmWordListErr, etErr, TRUE, 0,\
210  "Unable to create wordlist - no memory?")\
211  MSG(pmNoStackMem, etErr, TRUE, 0,\
212  "Unable to create stack - no memory?\n")\
213  MSG(pmWarnNumErr, etErr, TRUE, 0,\
214  "Illegal warning number used.")\
215  MSG(pmVerbLevErr, etErr, TRUE, 0,\
216  "Illegal verbosity level.")\
217  MSG(pmNotPSDigit, etWarn, TRUE, 0,\
218  "`%c' is not a %s digit - ignored!")\
219  MSG(pmEscCode, etWarn, TRUE, 0,\
220  "Unknown escape code `%c%c' - ignored!")\
221  MSG(pmKeyWord, etErr, TRUE, 0,\
222  "Unsupported control word (`%s') encountered in file `%s'.")\
223  MSG(pmFaultFmt, etErr, TRUE, 0,\
224  "\"%s\", line %d: Faulty format - unexpected %s found.")\
225  MSG(pmRsrcOpen, etWarn, TRUE, 0,\
226  "Could not open `%s', may cause unwanted behaviour.")\
227  MSG(pmSlowAbbr, etMsg, FALSE, 0,\
228  "The abbreviation `%s' requires slow abbreviation searching.")\
229  MSG(pmEmptyToken, etWarn, TRUE, 0,\
230  "Empty token isolated in `%s' - probably faulty format")\
231  MSG(pmAssert, etErr, TRUE, 0,\
232  "Assertion failed. Please report bug.")\
233  MSG(pmNoRsrc, etWarn, TRUE, 0,\
234  "Could not find global resource file.")\
235  MSG(pmQuoteStyle, etWarn, TRUE, 0,\
236  "Illegal quotestyle `%s'.")\
237  MSG(pmWrongWipeTemp, etWarn, TRUE, 0,\
238  "Wrong template for wiping arguments, \"%s\"")\
239  MSG(pmSpecifyTerm, etErr, TRUE, 0,\
240  "Specify a terminal type with `setenv TERM <yourtype>'.")\
241  MSG(pmNoTermData, etErr, TRUE, 0,\
242  "Could not access the termcap data base.")\
243  MSG(pmNoTermDefd, etErr, TRUE, 0,\
244  "Terminal type `%s' is not defined.")\
245  MSG(pmNoRegExp, etWarn, TRUE, 0,\
246  "Regular expressions not compiled in. Please recompile.")\
247  MSG(pmNoCommon, etErr, TRUE, 0,\
248  "`%s' can't be a member of both `%s' and `%s'.") \
249  MSG(pmNoOpenDir, etWarn, TRUE, 0, \
250  "Could not open the directory `%s'.") \
251  MSG(pmNoDebugFlag, etWarn, TRUE, 0, \
252  "This version of doesn't support the -d flag. Please recompile.")\
253  MSG(pmNoRegexMem, etErr, TRUE, 0,\
254  "Unable to allocate regular expressions - no memory?\n")\
255  MSG(pmRegexCompileFailed, etWarn, TRUE, 0,\
256  "Compilation of regular expression %s failed with error %s.\n")\
257  MSG(pmRegexMatchingError, etErr, TRUE, 0,\
258  "PCRE matching error %d.\n") \
259  MSG(pmSuppTooHigh, etWarn, TRUE, 0,\
260  "Warning %d is numbered too high (max %d) and won't be suppressed.\n") \
261 MSG(pmLongLines, etWarn, TRUE, 0,\
262  "ChkTeX does not handle lines over %d bytes correctly. Some errors and line numbers may be wrong in this file.") \
263 MSG(pmTabExpands, etWarn, TRUE, 0,\
264  "ChkTeX could not fully expand tabs because the resulting line would be more than %d bytes. Some errors and line numbers may be wrong in this file.")
265 
266 #undef MSG
267 #define MSG(num, type, inuse, ctxt, text) num,
269 {
271 };
272 #undef MSG
273 
274 extern struct ErrMsg PrgMsgs[pmMaxFault + 1];
275 
276 struct ErrInfo
277 {
278  char *Data;
279  char *LineBuf;
280  char *File;
281  unsigned long Line, Column, ErrLen;
282  enum
283  {
284  efNone = 0x00,
285  efNoItal = 0x01,
286  efItal = 0x02,
287  efNoMath = 0x04,
288  efMath = 0x08
289  } Flags;
290 };
291 
292 extern char *ReadBuffer;
293 extern char *CmdBuffer;
294 extern char *TmpBuffer;
295 
296 extern const char BrOrder[NUMBRACKETS + 1];
297 
298 extern unsigned long Brackets[NUMBRACKETS];
299 
300 
302 
303 /* We include semicolons on all but the last so that we can include a
304  * semicolon where it's called. This helps with indentation at the
305  * calling location. It also means that DEF must never have a
306  * semicolon. The reason for the care is that isolated semicolons
307  * have been known to break some compilers. */
308 /* See also RESOURCE_INFO where the same trick doesn't work, and we
309  * cannot include semicolons at the calling site, regardless of
310  * indentation concerns. */
311 #define OPTION_DEFAULTS \
312  DEF(int, GlobalRC, TRUE); \
313  DEF(int, WipeVerb, TRUE); \
314  DEF(int, BackupOut, TRUE); \
315  DEF(int, Quiet, FALSE); \
316  DEF(int, LicenseOnly, FALSE); \
317  DEF(int, UsingStdIn, FALSE); \
318  DEF(int, InputFiles, TRUE); \
319  DEF(int, HeadErrOut, TRUE); \
320  DEF(const char *, OutputName, ""); \
321  DEF(const char *, PseudoInName, NULL); \
322  DEF(char *, OutputFormat, VerbNormal); \
323  DEF(char *, PipeOutputFormat, NULL); \
324  DEF(const char *, Delimit, ":"); \
325  DEF(long, DebugLevel, 0); \
326  DEF(int, NoLineSupp, FALSE)
327 
328 #define STATE_VARS \
329  DEF(enum ItState, ItState, itOff); /* Are we doing italics? */ \
330  DEF(int, AtLetter, FALSE); /* Whether `@' is a letter or not. */ \
331  DEF(int, InHeader, TRUE); /* Whether we're in the header */ \
332  DEF(int, VerbMode, FALSE); /* Whether we're in complete ignore-mode */ \
333  DEF(long, MathMode, 0); /* Whether we're in math mode or not */ \
334  DEF(const char *, VerbStr, ""); /* String we'll terminate verbmode upon */ \
335  DEF(unsigned long, ErrPrint, 0); /* # errors printed */ \
336  DEF(unsigned long, WarnPrint, 0); /* # warnings printed */ \
337  DEF(unsigned long, UserSupp, 0); /* # user suppressed warnings */ \
338  DEF(unsigned long, LineSupp, 0); /* # warnings suppressed on a single line */ \
339  DEF(uint64_t, FileSuppressions, 0); /* # warnings suppressed in a file */ \
340  DEF(uint64_t, UserFileSuppressions, 0) /* # User warnings suppressed in a file */
341 
342 #define DEF(type, name, value) extern type name
344 STATE_VARS;
345 #undef DEF
346 extern struct Stack CharStack, InputStack, EnvStack;
347 
348 enum Quote
349 {
351  quTrad
352 };
353 
354 extern enum Quote Quote;
356 
357 int main(int argc, char **argv);
358 void PrintPrgErr(enum PrgErrNum, ...);
359 void ErrPrintf(const char *fmt, ...);
360 
361 extern char *PrgName;
362 
363 #endif /* CHKTEX_H */
struct Stack InputStack
Definition: ChkTeX.c:51
struct Stack CharStack
Definition: ChkTeX.c:49
Debug_BIT
Definition: ChkTeX.h:184
struct Stack CharStack InputStack EnvStack
Definition: ChkTeX.c:54
#define PRGMSGS
Definition: ChkTeX.h:193
void ErrPrintf(const char *fmt,...)
int main(int argc, char **argv)
Definition: cjpeg.c:461
int UsingStdIn
Definition: ChkTeX.h:355
FILE * OutputFile
Definition: ChkTeX.c:203
const char BrOrder[6+1]
Definition: ChkTeX.c:61
#define STATE_VARS
Definition: ChkTeX.h:328
char * CmdBuffer
Definition: FindErrs.c:161
Quote
Definition: ChkTeX.h:349
@ quTrad
Definition: ChkTeX.h:351
@ quLogic
Definition: ChkTeX.h:350
char * TmpBuffer
Definition: ChkTeX.c:74
struct ErrMsg PrgMsgs[pmMaxFault+1]
Definition: ChkTeX.c:45
char * ReadBuffer
Definition: ChkTeX.c:75
#define OPTION_DEFAULTS
Definition: ChkTeX.h:311
int StdInTTY
Definition: ChkTeX.c:207
#define NUMBRACKETS
Definition: ChkTeX.h:157
char * PrgName
Definition: ChkTeX.c:205
int StdOutTTY
Definition: ChkTeX.h:355
void PrintPrgErr(enum PrgErrNum,...)
Definition: ChkTeX.c:1048
PrgErrNum
Definition: ChkTeX.h:269
@ pmMaxFault
Definition: ChkTeX.h:270
unsigned long Brackets[6]
Definition: ChkTeX.c:63
Debug_FLG
Definition: ChkTeX.h:187
#define DEBUGBITS(a)
Definition: ChkTeX.h:174
FILE * InputFile
Definition: ChkTeX.h:301
unsigned long ErrLen
Definition: ChkTeX.h:281
@ efNoMath
Definition: ChkTeX.h:287
@ efNoItal
Definition: ChkTeX.h:285
@ efNone
Definition: ChkTeX.h:284
@ efItal
Definition: ChkTeX.h:286
@ efMath
Definition: ChkTeX.h:288
char * LineBuf
Definition: ChkTeX.h:279
unsigned long Column
Definition: ChkTeX.h:281
char * File
Definition: ChkTeX.h:280
char * Data
Definition: ChkTeX.h:278
unsigned long Line
Definition: ChkTeX.h:281
enum ErrInfo::@90 Flags
Definition: Utility.h:71
#define FILE
Definition: t1stdio.h:34
char fmt[256]
Definition: tex4ht.c:3925
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269