/* * ChkTeX, header file for main program. * Copyright (C) 1995-96 Jens T. Berger Thielemann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Contact the author at: * Jens Berger * Spektrumvn. 4 * N-0666 Oslo * Norway * E-mail: * * */ #ifndef CHKTEX_H #define CHKTEX_H 1 #if defined(HAVE_CONFIG_H) || defined(CONFIG_H_NAME) # ifndef CONFIG_H_NAME # define CONFIG_H_NAME "config.h" # endif # ifndef HAVE_CONFIG_H # define HAVE_CONFIG_H 1 # endif # include CONFIG_H_NAME #endif /* For TeX Live */ #ifdef KPATHSEA #include #endif #include #include #include #ifdef HAVE_STDARG_H # include #else #error Sorry, ChkTeX needs an _ANSI_ compiler w/stdarg.h installed to compile. #endif #ifndef HAVE_VPRINTF #error Sorry, ChkTeX needs an _ANSI_ compiler w/vprintf() to compile. #endif #include #include #include #ifdef HAVE_UNISTD_H # include #endif #ifdef HAVE_LIMITS_H # include #endif #ifdef HAVE_STRINGS_H # include #endif #ifdef HAVE_INTTYPES_H # include #endif #ifdef HAVE_STDINT_H # include #endif #include "types.h" #ifndef LONG_MAX # define LONG_MAX (0x7fffffff) #endif #ifndef CHAR_BIT # define CHAR_BIT (8) #endif #include "FindErrs.h" #if defined(HAVE_FILENO) && defined(HAVE_ISATTY) # include #endif /* * Define aliases for preprocessor statements */ #if defined(__unix__) || defined(__unix) || defined(unix) #undef __unix__ #define __unix__ 1 #elif defined(__APPLE__) && defined(__MACH__) /* OS X should be considered a UNIX */ #undef __unix__ #define __unix__ 1 #elif defined(MSDOS) || defined(__MSDOS__) || defined(__msdos__) #undef __MSDOS__ #define __MSDOS__ 1 #endif /* -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- */ /* * NOTE: All macros below should return FALSE (0) if the input * character is 0. * * The next macro should return TRUE if LaTeX (and you?) considers * the character `c' as a space, which should be detected when * we're checking whether commands are terminated by spaces. * * Note: If you wish to change this macro, you'll have to update * the main loop in FindErrs.c as well. */ #define LATEX_SPACE(c) (c > 0 && c <= ' ') /* -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- -=><=- */ #define betw(a,b,c) ((a < b) && (b < c)) #define within(a,b,c) ((a <= b) && (b <= c)) #ifndef min # define min(a,b) ((a)<=(b)?(a):(b)) #endif #ifndef max # define max(a,b) ((a)>(b)?(a):(b)) #endif #ifndef abs # define abs(a) (a>=0?a:(-a)) #endif #define LOOP(name, body) {{body} _end__##name:;} #define LAST(name) goto _end__##name #define NUMBRACKETS 6 #define NEWBUF(name,len) \ static char _ ## name [len + (WALLBYTES<<1)] = {0}; \ char *name = &_ ## name[WALLBYTES] #define INTFAULTMSG "INTERNAL FAULT OCCURED! PLEASE SUBMIT A BUG REPORT!\n" #define INTERNFAULT INTFAULTMSG #define BITDEF1(a) BIT_ ## a #define BITDEF2(a) FLG_ ## a = (1<'.")\ MSG(pmNoTermData, etErr, TRUE, 0,\ "Could not access the termcap data base.")\ MSG(pmNoTermDefd, etErr, TRUE, 0,\ "Terminal type `%s' is not defined.")\ MSG(pmNoRegExp, etWarn, TRUE, 0,\ "Regular expressions not compiled in. Please recompile.")\ MSG(pmNoCommon, etErr, TRUE, 0,\ "`%s' can't be a member of both `%s' and `%s'.") \ MSG(pmNoOpenDir, etWarn, TRUE, 0, \ "Could not open the directory `%s'.") \ MSG(pmNoDebugFlag, etWarn, TRUE, 0, \ "This version of doesn't support the -d flag. Please recompile.")\ MSG(pmNoRegexMem, etErr, TRUE, 0,\ "Unable to allocate regular expressions - no memory?\n")\ MSG(pmRegexCompileFailed, etWarn, TRUE, 0,\ "Compilation of regular expression %s failed with error %s.\n")\ MSG(pmRegexMatchingError, etErr, TRUE, 0,\ "PCRE matching error %d.\n") \ MSG(pmSuppTooHigh, etWarn, TRUE, 0,\ "Warning %d is numbered too high (max %d) and won't be suppressed.\n") \ MSG(pmLongLines, etWarn, TRUE, 0,\ "ChkTeX does not handle lines over %d bytes correctly. Some errors and line numbers may be wrong in this file.") \ MSG(pmTabExpands, etWarn, TRUE, 0,\ "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.") \ MSG(pmCmdSpaceStyle, etWarn, TRUE, 0,\ "Illegal CmdSpaceStyle `%s' using `Ignore'.") #undef MSG #define MSG(num, type, inuse, ctxt, text) num, enum PrgErrNum { PRGMSGS pmMaxFault }; #undef MSG extern struct ErrMsg PrgMsgs[pmMaxFault + 1]; struct ErrInfo { char *Data; char *LineBuf; char *File; unsigned long Line, Column, ErrLen; enum { efNone = 0x00, efNoItal = 0x01, efItal = 0x02, efNoMath = 0x04, efMath = 0x08 } Flags; }; extern char *ReadBuffer; extern char *CmdBuffer; extern char *TmpBuffer; extern const char BrOrder[NUMBRACKETS + 1]; extern unsigned long Brackets[NUMBRACKETS]; extern FILE *OutputFile, *InputFile; /* We include semicolons on all but the last so that we can include a * semicolon where it's called. This helps with indentation at the * calling location. It also means that DEF must never have a * semicolon. The reason for the care is that isolated semicolons * have been known to break some compilers. */ /* See also RESOURCE_INFO where the same trick doesn't work, and we * cannot include semicolons at the calling site, regardless of * indentation concerns. */ #define OPTION_DEFAULTS \ DEF(int, GlobalRC, TRUE); \ DEF(int, WipeVerb, TRUE); \ DEF(int, BackupOut, TRUE); \ DEF(int, Quiet, FALSE); \ DEF(int, LicenseOnly, FALSE); \ DEF(int, UsingStdIn, FALSE); \ DEF(int, InputFiles, TRUE); \ DEF(int, HeadErrOut, TRUE); \ DEF(const char *, OutputName, ""); \ DEF(const char *, PseudoInName, NULL); \ DEF(char *, OutputFormat, VerbNormal); \ DEF(char *, PipeOutputFormat, NULL); \ DEF(const char *, Delimit, ":"); \ DEF(long, DebugLevel, 0); \ DEF(int, NoLineSupp, FALSE) #define STATE_VARS \ DEF(enum ItState, ItState, itOff); /* Are we doing italics? */ \ DEF(int, AtLetter, FALSE); /* Whether `@' is a letter or not. */ \ DEF(int, InHeader, TRUE); /* Whether we're in the header */ \ DEF(int, VerbMode, FALSE); /* Whether we're in complete ignore-mode */ \ DEF(const char *, VerbStr, ""); /* String we'll terminate verbmode upon */ \ DEF(unsigned long, ErrPrint, 0); /* # errors printed */ \ DEF(unsigned long, WarnPrint, 0); /* # warnings printed */ \ DEF(unsigned long, UserSupp, 0); /* # user suppressed warnings */ \ DEF(unsigned long, LineSupp, 0); /* # warnings suppressed on a single line */ #define DEF(type, name, value) extern type name OPTION_DEFAULTS; STATE_VARS; #undef DEF extern struct Stack CharStack, InputStack, EnvStack, ConTeXtStack; extern struct Stack FileSuppStack, UserFileSuppStack; extern struct Stack MathModeStack; enum Quote { quLogic, quTrad }; extern enum Quote Quote; extern int StdInTTY, StdOutTTY, UsingStdIn; enum CmdSpace { csIgnore = 0, csInterWord = 0x1, csInterSentence = 0x2, csBoth = 0x3, /* both bits set */ }; extern enum CmdSpace CmdSpace; int main(int argc, char **argv); void PrintPrgErr(enum PrgErrNum, ...); void ErrPrintf(const char *fmt, ...); extern char *PrgName; #endif /* CHKTEX_H */