| 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: <[email protected]> |
| 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 |
| 184 |
DEBUGBITS(Debug_BIT) |
| 185 |
#undef BIT |
| 186 |
#define BIT BITDEF2 |
| 187 |
DEBUGBITS(Debug_FLG) |
| 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' using `Traditional'.")\ |
| 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 |
MSG(pmCmdSpaceStyle, etWarn, TRUE, 0,\ |
| 266 |
"Illegal CmdSpaceStyle `%s' using `Ignore'.") |
| 267 |
|
| 268 |
#undef MSG |
| 269 |
#define MSG(num, type, inuse, ctxt, text) num, |
| 270 |
enum PrgErrNum |
| 271 |
{ |
| 272 |
PRGMSGS pmMaxFault |
| 273 |
}; |
| 274 |
#undef MSG |
| 275 |
|
| 276 |
extern struct ErrMsg PrgMsgs[pmMaxFault + 1]; |
| 277 |
|
| 278 |
struct ErrInfo |
| 279 |
{ |
| 280 |
char *Data; |
| 281 |
char *LineBuf; |
| 282 |
char *File; |
| 283 |
unsigned long Line, Column, ErrLen; |
| 284 |
enum |
| 285 |
{ |
| 286 |
efNone = 0x00, |
| 287 |
efNoItal = 0x01, |
| 288 |
efItal = 0x02, |
| 289 |
efNoMath = 0x04, |
| 290 |
efMath = 0x08 |
| 291 |
} Flags; |
| 292 |
}; |
| 293 |
|
| 294 |
extern char *ReadBuffer; |
| 295 |
extern char *CmdBuffer; |
| 296 |
extern char *TmpBuffer; |
| 297 |
|
| 298 |
extern const char BrOrder[NUMBRACKETS + 1]; |
| 299 |
|
| 300 |
extern unsigned long Brackets[NUMBRACKETS]; |
| 301 |
|
| 302 |
|
| 303 |
extern FILE *OutputFile, *InputFile; |
| 304 |
|
| 305 |
/* We include semicolons on all but the last so that we can include a |
| 306 |
* semicolon where it's called. This helps with indentation at the |
| 307 |
* calling location. It also means that DEF must never have a |
| 308 |
* semicolon. The reason for the care is that isolated semicolons |
| 309 |
* have been known to break some compilers. */ |
| 310 |
/* See also RESOURCE_INFO where the same trick doesn't work, and we |
| 311 |
* cannot include semicolons at the calling site, regardless of |
| 312 |
* indentation concerns. */ |
| 313 |
#define OPTION_DEFAULTS \ |
| 314 |
DEF(int, GlobalRC, TRUE); \ |
| 315 |
DEF(int, WipeVerb, TRUE); \ |
| 316 |
DEF(int, BackupOut, TRUE); \ |
| 317 |
DEF(int, Quiet, FALSE); \ |
| 318 |
DEF(int, LicenseOnly, FALSE); \ |
| 319 |
DEF(int, UsingStdIn, FALSE); \ |
| 320 |
DEF(int, InputFiles, TRUE); \ |
| 321 |
DEF(int, HeadErrOut, TRUE); \ |
| 322 |
DEF(const char *, OutputName, ""); \ |
| 323 |
DEF(const char *, PseudoInName, NULL); \ |
| 324 |
DEF(char *, OutputFormat, VerbNormal); \ |
| 325 |
DEF(char *, PipeOutputFormat, NULL); \ |
| 326 |
DEF(const char *, Delimit, ":"); \ |
| 327 |
DEF(long, DebugLevel, 0); \ |
| 328 |
DEF(int, NoLineSupp, FALSE) |
| 329 |
|
| 330 |
#define STATE_VARS \ |
| 331 |
DEF(enum ItState, ItState, itOff); /* Are we doing italics? */ \ |
| 332 |
DEF(int, AtLetter, FALSE); /* Whether `@' is a letter or not. */ \ |
| 333 |
DEF(int, InHeader, TRUE); /* Whether we're in the header */ \ |
| 334 |
DEF(int, VerbMode, FALSE); /* Whether we're in complete ignore-mode */ \ |
| 335 |
DEF(const char *, VerbStr, ""); /* String we'll terminate verbmode upon */ \ |
| 336 |
DEF(unsigned long, ErrPrint, 0); /* # errors printed */ \ |
| 337 |
DEF(unsigned long, WarnPrint, 0); /* # warnings printed */ \ |
| 338 |
DEF(unsigned long, UserSupp, 0); /* # user suppressed warnings */ \ |
| 339 |
DEF(unsigned long, LineSupp, 0); /* # warnings suppressed on a single line */ |
| 340 |
|
| 341 |
#define DEF(type, name, value) extern type name |
| 342 |
OPTION_DEFAULTS; |
| 343 |
STATE_VARS; |
| 344 |
#undef DEF |
| 345 |
extern struct Stack CharStack, InputStack, EnvStack, ConTeXtStack; |
| 346 |
extern struct Stack FileSuppStack, UserFileSuppStack; |
| 347 |
extern struct Stack MathModeStack; |
| 348 |
|
| 349 |
enum Quote |
| 350 |
{ |
| 351 |
quLogic, |
| 352 |
quTrad |
| 353 |
}; |
| 354 |
|
| 355 |
extern enum Quote Quote; |
| 356 |
extern int StdInTTY, StdOutTTY, UsingStdIn; |
| 357 |
|
| 358 |
enum CmdSpace |
| 359 |
{ |
| 360 |
csIgnore = 0, |
| 361 |
csInterWord = 0x1, |
| 362 |
csInterSentence = 0x2, |
| 363 |
csBoth = 0x3, /* both bits set */ |
| 364 |
}; |
| 365 |
extern enum CmdSpace CmdSpace; |
| 366 |
|
| 367 |
int main(int argc, char **argv); |
| 368 |
void PrintPrgErr(enum PrgErrNum, ...); |
| 369 |
void ErrPrintf(const char *fmt, ...); |
| 370 |
|
| 371 |
extern char *PrgName; |
| 372 |
|
| 373 |
#endif /* CHKTEX_H */ |