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.c
Go to the documentation of this file.
1 /*
2  * ChkTeX, finds typographic errors in (La)TeX files.
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 
30 #include "ChkTeX.h"
31 #ifdef KPATHSEA
32 #include <kpathsea/getopt.h>
33 #else
34 #include <getopt.h>
35 #endif
36 #include "OpSys.h"
37 #include "Utility.h"
38 #include "FindErrs.h"
39 #include "Resource.h"
40 #include <string.h>
41 
42 #undef MSG
43 #define MSG(num, type, inuse, ctxt, text) {(enum ErrNum)num, type, inuse, ctxt, text},
44 
45 struct ErrMsg PrgMsgs[pmMaxFault + 1] = {
47 };
48 
49 struct Stack CharStack = {
50  0L
52 
53 {
54 0L}, EnvStack =
55 
56 {
57 0L};
58 
59 /************************************************************************/
60 
61 const char BrOrder[NUMBRACKETS + 1] = "()[]{}";
62 
63 unsigned long Brackets[NUMBRACKETS];
64 
65 /************************************************************************/
66 
67 
68 /*
69  * Have to do things this way, to ease some checking throughout the
70  * program.
71  */
72 
73 
76 
77 static const char *Banner =
78  "ChkTeX v" PACKAGE_VERSION " - Copyright 1995-96 Jens T. Berger Thielemann.\n"
79 #ifdef __OS2__
80  "OS/2 port generated with emx compiler, by Wolfgang Fritsch, <fritsch@hmi.de>\n"
81 #elif defined(__MSDOS__)
82  "MS-DOS port by Bj\\o rn Ove Thue, <bjort@ifi.uio.no>\n"
83 #endif
84 #if HAVE_PCRE
85  "Compiled with PCRE regex support."
86 #else
87 #if HAVE_POSIX_ERE
88  "Compiled with POSIX extended regex support."
89 #else
90  "Compiled with no regex support."
91 #endif
92 #endif
93  "\n";
94 
95 static const char *BigBanner =
96  "ChkTeX comes with ABSOLUTELY NO WARRANTY; details on this and\n"
97  "distribution conditions in the GNU General Public License file.\n"
98  "Type \"ChkTeX -h\" for help, \"ChkTeX -i\" for distribution info.\n"
99  "Author: Jens Berger.\n"
100  "Bug reports: https://savannah.nongnu.org/bugs/?group=chktex\n"
101  " or darthandrus@gmail.com\n"
102  "Press " STDIN_BREAK " to terminate stdin input.\n";
103 
104 static const char *Distrib =
105  "\n"
106  "This program is free software; you can redistribute it and/or modify\n"
107  "it under the terms of the GNU General Public License as published by\n"
108  "the Free Software Foundation; either version 2 of the License, or\n"
109  "(at your option) any later version.\n"
110  "\n"
111  "This program is distributed in the hope that it will be useful,\n"
112  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
113  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
114  "GNU General Public License for more details.\n"
115  "\n"
116  "You should have received a copy of the GNU General Public License\n"
117  "along with this program; if not, write to the Free Software\n"
118  "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n";
119 
120 static const char *OnText = "On";
121 
122 static const char *OffText = "Off";
123 
124 static const char *HowHelp =
125  "-h or --help gives usage information. See also ChkTeX.{ps,dvi}.\n";
126 
127 static const char *HelpText =
128  "\n"
129  "\n"
130  " Usage of ChkTeX v" PACKAGE_VERSION "\n"
131  " ~~~~~~~~~~~~~~~~~~~~~~\n"
132  "\n"
133  " Template\n"
134  " ~~~~~~~~\n"
135  "chktex [-hiqrW] [-v[0-...]] [-l <rcfile>] [-[wemn] <[1-42]|all>]\n"
136  " [-d[0-...]] [-p <name>] [-o <outfile>] [-[btxgI][0|1]]\n"
137  " file1 file2 ...\n"
138  "\n"
139  "----------------------------------------------------------------------\n"
140  " Description of options:\n"
141  " ~~~~~~~~~~~~~~~~~~~~~~~\n"
142  "Misc. options\n"
143  "~~~~~~~~~~~~~\n"
144  " -h --help : This text.\n"
145  " -i --license : Show distribution information\n"
146  " -l --localrc : Read local .chktexrc formatted file.\n"
147  " -d --debug : Debug information. Give it a number.\n"
148  " -r --reset : Reset settings to default.\n"
149  "\n"
150  "Muting warning messages:\n"
151  "~~~~~~~~~~~~~~~~~~~~~~~~\n"
152  " -w --warnon : Makes msg # given a warning and turns it on.\n"
153  " -e --erroron : Makes msg # given an error and turns it on.\n"
154  " -m --msgon : Makes msg # given a message and turns it on.\n"
155  " -n --nowarn : Mutes msg # given.\n"
156  " -L --nolinesupp: Disables per-line suppressions.\n"
157  "\n"
158  "Output control flags:\n"
159  "~~~~~~~~~~~~~~~~~~~~~\n"
160  " -v --verbosity : How errors are displayed.\n"
161  " Default 1, 0=Less, 2=Fancy, 3=lacheck.\n"
162  " -V --pipeverb : How errors are displayed when stdout != tty.\n"
163  " Defaults to the same as -v.\n"
164  " -s --splitchar : String used to split fields when doing -v0\n"
165  " -o --output : Redirect error report to a file.\n"
166  " -q --quiet : Shuts up about version information.\n"
167  " -p --pseudoname: Input file-name when reporting.\n"
168  " -f --format : Format to use for output\n"
169  "\n"
170  "Boolean switches (1 -> enables / 0 -> disables):\n"
171  "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
172  " -b --backup : Backup output file.\n"
173  " -x --wipeverb : Ignore contents of `\\verb' commands.\n"
174  " -g --globalrc : Read global .chktexrc file.\n"
175  " -I --inputfiles: Execute \\input statements.\n"
176  " -H --headererr : Show errors found in front of \\begin{document}\n"
177  "\n"
178  "Miscellaneous switches:\n"
179  "~~~~~~~~~~~~~~~~~~~~~~~\n"
180  " -W --version : Version information\n"
181  "\n"
182  "----------------------------------------------------------------------\n"
183  "If no LaTeX files are specified on the command line, we will read from\n"
184  "stdin. For explanation of warning/error messages, please consult the\n"
185  "main documentation ChkTeX.dvi, ChkTeX.ps or ChkTeX.pdf.\n";
186 
187 
188 
189 
190 /*
191  * Options we will set.
192  *
193  */
194 
195 enum Quote Quote;
196 
197 char VerbNormal[] = "%k %n in %f line %l: %m\n" "%r%s%t\n" "%u\n";
198 
199 #define DEF(type, name, value) type name = value
202 #undef DEF
204 
205 char *PrgName;
206 
208 
209 /*
210  * End of config params.
211  */
212 
213 static int ParseArgs(int argc, char **argv);
214 static void ShowIntStatus(void);
215 static int OpenOut(void);
216 static int ShiftArg(char **Argument);
217 
218 
219 /*
220  * Duplicates all arguments, and appends an asterix to each of them.
221  */
222 
223 static void AddStars(struct WordList *wl)
224 {
225  unsigned long Count, CmdLen;
226  char *Data;
227 
228  FORWL(Count, *wl)
229  {
230  Data = wl->Stack.Data[Count];
231  CmdLen = strlen(Data);
232  if (Data[CmdLen - 1] != '*')
233  {
235  strcat(TmpBuffer, "*");
236  InsertWord(TmpBuffer, wl);
237  }
238  }
239 }
240 
241 /*
242  * Sets up all the lists.
243  *
244  */
245 
246 static void SetupLists(void)
247 {
248  unsigned long i;
249 
252 
254 
255  ListRep(&WipeArg, ':', 0);
256  ListRep(&NoCharNext, ':', 0);
257 
258 #define ThisItem ((char *) AbbrevCase.Stack.Data[i])
259 
260  FORWL(i, AbbrevCase)
261  {
262  if (isalpha((unsigned char)ThisItem[0]))
263  {
264  ThisItem[0] = toupper((unsigned char)ThisItem[0]);
266  ThisItem[0] = tolower((unsigned char)ThisItem[0]);
267  }
269  }
270 }
271 
272 #define NOCOMMON(a,b) NoCommon(&a,#a,&b,#b)
273 
274 /*
275  * Checks that two lists don't have any common element.
276  */
277 
278 static void
279 NoCommon(struct WordList *a, const char *aName,
280  struct WordList *b, const char *bName)
281 {
282  unsigned long i;
283 
284  FORWL(i, *a)
285  {
286  if (HasWord((char *) a->Stack.Data[i], b))
287  PrintPrgErr(pmNoCommon, a->Stack.Data[i], aName, bName);
288  }
289 }
290 
291 /*
292  * Expands the tabs in a string to regular intervals sized
293  * TSize.
294  */
295 
296 static void ExpandTabs(char *From, char *To, long TSize, long MaxDiff)
297 {
298  char *Next;
299  char *Orig;
300  unsigned long Diff;
301  static short HasExpandedTooLong = 0;
302 
303  Next = From;
304  Orig = To;
305 
306  while ((Next = strchr(From, '\t')))
307  {
308  if ((Diff = Next - From))
309  {
310  strncpy(To, From, Diff);
311  To += Diff;
312  Diff = TSize - ((To - Orig) % TSize);
313  }
314  else
315  Diff = TSize;
316 
317  /* Make sure we don't expand this buffer out of the memory we
318  * have allocated for it. */
319  if ( Diff > MaxDiff+1 )
320  {
321  Diff = MaxDiff+1;
322  if ( !HasExpandedTooLong )
323  {
325  }
326  HasExpandedTooLong = 1;
327  }
328  MaxDiff -= (Diff-1);
329 
330  memset(To, ' ', Diff);
331  To += Diff;
332 
333  From = ++Next;
334  }
335  strcpy(To, From);
336 }
337 
338 
339 int main(int argc, char **argv)
340 {
341  int retval = EXIT_FAILURE, ret, CurArg;
342  unsigned long Count;
343  int StdInUse = FALSE;
344  long Tab = 8;
345 
346 #ifdef __LOCALIZED
347 
348  InitStrings();
349 #endif
350 
351  OutputFile = stdout;
352 #ifdef KPATHSEA
353  kpse_set_program_name(argv[0], "chktex");
355 #ifdef WIN32
357 #endif
358 #else
359  PrgName = argv[0];
360 #endif
361 
362 #undef KEY
363 #undef LCASE
364 #undef LIST
365 #undef LNEMPTY
366 #define KEY(a, def)
367 #define LCASE(a)
368 #define LIST(a)
369 #define LNEMPTY(a) InsertWord("", &a);
370 
372 
373  while (SetupVars())
375 
376  if (CmdLine.Stack.Used)
377  {
379  CmdLine.Stack.Used = 1L;
380  }
381 
382  if ((CurArg = ParseArgs((unsigned long) argc, argv)))
383  {
384  retval = EXIT_SUCCESS;
385  if (CmdLine.Stack.Used)
386  {
388  CmdLine.Stack.Used = 1L;
389  }
390 
391  if (!Quiet || LicenseOnly)
392  fprintf(stderr, "%s", Banner);
393 
394  if (CurArg == argc)
395  UsingStdIn = TRUE;
396 
397 #if defined(HAVE_FILENO) && defined(HAVE_ISATTY)
398 
399  StdInTTY = isatty(fileno(stdin));
401 #else
402 
403  StdInTTY = StdOutTTY = TRUE;
404 #endif
405 
406  SetupTerm();
407 
408  if ((UsingStdIn && StdInTTY && !Quiet) || LicenseOnly)
409  {
410  fprintf(stderr, "%s", BigBanner);
411  }
412 
413  if (!StdOutTTY && PipeOutputFormat)
415 
416  if (LicenseOnly)
417  {
418  fprintf(stderr, "%s", Distrib);
419  }
420  else
421  {
422  SetupLists();
423  if (QuoteStyle)
424  {
425  if (!strcasecmp(QuoteStyle, "LOGICAL"))
426  Quote = quLogic;
427  else if (!strcasecmp(QuoteStyle, "TRADITIONAL"))
428  Quote = quTrad;
429  else
430  {
432  Quote = quTrad;
433  }
434  }
435 
436  if (DebugLevel)
437  ShowIntStatus();
438 
442 
443  if (TabSize && isdigit((unsigned char)*TabSize))
444  Tab = strtol(TabSize, NULL, 10);
445 
446  if (OpenOut())
447  {
448  for (;;)
449  {
450  for (Count = 0; Count < NUMBRACKETS; Count++)
451  Brackets[Count] = 0L;
452 
453 #define DEF(type, name, value) name = value
454  STATE_VARS;
455 #undef DEF
456  if (UsingStdIn)
457  {
458  if (StdInUse)
459  break;
460  else
461  {
462  StdInUse = TRUE;
463  PushFile("stdin", stdin, &InputStack);
464  }
465  }
466  else
467  {
468  if (CurArg <= argc)
469  {
470  const char *filename = NULL;
471  if (CurArg < argc)
472  filename = argv[CurArg++];
473 
475  break;
476  }
477  }
478 
479  if (StkTop(&InputStack) && OutputFile)
480  {
481  while (!ferror(OutputFile)
482  && StkTop(&InputStack)
484  && FGetsStk(ReadBuffer, BUFSIZ - 1,
485  &InputStack))
486  {
487 
488  /* Make all spaces ordinary spaces */
489 
490  strrep(ReadBuffer, '\n', ' ');
491  strrep(ReadBuffer, '\r', ' ');
494 
495  strcat(ReadBuffer, " ");
497  if ( ret != EXIT_SUCCESS ) {
498  retval = ret;
499  }
500  }
501 
503  }
504  }
505  }
506  }
507  }
508  return retval;
509 }
510 
511 /*
512  * Opens the output file handle & possibly renames
513  */
514 
515 static int OpenOut(void)
516 {
517  int Success = TRUE;
518 
519  if (*OutputName)
520  {
521  if (BackupOut && fexists(OutputName))
522  {
525 
526  if (fexists(TmpBuffer))
527  remove(TmpBuffer);
528 
529  if (!rename(OutputName, TmpBuffer))
531  else
532  {
534  Success = FALSE;
535  }
536 
537  }
538 
539  if (Success)
540  {
541 #ifdef KPATHSEA
542  if (!(OutputFile = fopen(OutputName, "wb")))
543 #else
544  if (!(OutputFile = fopen(OutputName, "w")))
545 #endif
546  {
548  Success = FALSE;
549  }
550  }
551  }
552  else
553  OutputFile = stdout;
554 
555  return (Success);
556 }
557 
558 #ifndef STRIP_DEBUG
559 static void ShowWL(const char *Name, const struct WordList *wl)
560 {
561  unsigned long i, j, percent;
562 
563  fprintf(stderr, "Name: %12s", Name);
564 
566  {
567  fprintf(stderr, ", MaxLen: %3ld, Entries: %3ld, ",
568  wl->MaxLen, wl->Stack.Used);
569 
570  if (wl->Hash.Index && wl->Stack.Used)
571  {
572  for (i = j = 0; i < HASH_SIZE; i++)
573  {
574  if (wl->Hash.Index[i])
575  j++;
576  }
577  percent = (j * 10000) / wl->Stack.Used;
578 
579 
580  fprintf(stderr, "Hash usage: %3ld.%02ld%%",
581  percent / 100, percent % 100);
582  }
583  else
584  fprintf(stderr, "No hash table.");
585  }
586 
587  fputc('\n', stderr);
588 
590  {
591  FORWL(i, *wl) fprintf(stderr, "\t%s\n", (char *) wl->Stack.Data[i]);
592  }
593 }
594 #endif
595 
596 #define BOOLDISP(var) ((var)? OnText : OffText)
597 #define SHOWSTAT(text, arg) fprintf(stderr, "\t" text ": %s\n", arg)
598 #define BOOLSTAT(name, var) SHOWSTAT(name, BOOLDISP(var))
599 #define SHOWSTR(text, arg) fprintf(stderr, "%s:\n\t%s\n", text, arg);
600 
601 
602 /*
603  * Prints some of the internal flags; mainly for debugging purposes
604  */
605 
606 static void ShowIntStatus(void)
607 {
608 #ifndef STRIP_DEBUG
609  unsigned long Cnt;
610  const char *String;
611  const char *iuStr = "";
612 
613  if (DebugLevel & FLG_DbgMsgs)
614  {
615  fprintf(stderr, "There are %d warnings/error messages available:\n",
616  emMaxFault - emMinFault - 1);
617 
618  for (Cnt = emMinFault + 1; Cnt < emMaxFault; Cnt++)
619  {
620  switch (LaTeXMsgs[Cnt].Type)
621  {
622  case etWarn:
623  String = "Warning";
624  break;
625  case etErr:
626  String = "Error";
627  break;
628  case etMsg:
629  String = "Message";
630  break;
631  default:
632  String = "";
633  break;
634  }
635 
636  switch (LaTeXMsgs[Cnt].InUse)
637  {
638  case iuOK:
639  iuStr = "In use";
640  break;
641  case iuNotUser:
642  iuStr = "User muted";
643  break;
644  case iuNotSys:
645  iuStr = "System muted";
646  break;
647  }
648 
649  fprintf(stderr, "Number: %2ld, Type: %s, Status: %s\n"
650  "\tText: %s\n\n",
651  Cnt, String, iuStr, LaTeXMsgs[Cnt].Message);
652  }
653  }
654 
655 #undef KEY
656 #undef LCASE
657 #undef LNEMPTY
658 #undef LIST
659 
660 #define LNEMPTY LIST
661 #define LIST(a) ShowWL(#a, &a);
662 #define LCASE(a) LIST(a); LIST(a ## Case);
663 #define KEY(a,def) SHOWSTR(#a, a);
664 
665 
667  {
669  }
670 
672  {
673  SHOWSTR("Outputformat", OutputFormat);
674 
675  fprintf(stderr, "Current flags include:\n");
676 
677  BOOLSTAT("Read global resource", GlobalRC);
678  BOOLSTAT("Wipe verbose commands", WipeVerb);
679  BOOLSTAT("Backup outfile", BackupOut);
680  BOOLSTAT("Quiet mode", Quiet);
681  BOOLSTAT("Show license", LicenseOnly);
682  BOOLSTAT("Use stdin", UsingStdIn);
683  BOOLSTAT("\\input files", InputFiles);
684  BOOLSTAT("Output header errors", HeadErrOut);
685  BOOLSTAT("No line suppressions", NoLineSupp);
686  }
687 #endif
688 }
689 
690 /*
691  * Resets all stacks.
692  *
693  */
694 
695 #undef KEY
696 #undef LCASE
697 #undef LNEMPTY
698 #undef LIST
699 
700 #define LNEMPTY LIST
701 #define LIST(a) ClearWord(&a);
702 #define LCASE(a) LIST(a); LIST(a ## Case);
703 #define KEY(a,def) a = def;
704 
705 static void ResetStacks(void)
706 {
708 }
709 
710 /*
711  * Resets all flags (not wordlists) to their default values. Sets
712  * Outputfile to stdout.
713  *
714  */
715 
716 static void ResetSettings(void)
717 {
718 
719 #define DEF(type, name, value) name = value
721 #undef DEF
722  if (OutputFile != stdout)
723  {
725  OutputFile = stdout;
726  }
727 }
728 
729 /*
730  * Reads a numerical argument from the argument. Supports concatenation
731  * of arguments (main purpose)
732  */
733 
734 static int ParseNumArg(long *Dest, /* Where to put the value */
735  long Default, /* Value to put in if no in argue */
736  char **Argument) /* optarg or similar */
737 {
738  if (Argument && *Argument && isdigit((unsigned char)**Argument))
739  *Dest = strtol(*Argument, Argument, 10);
740  else
741  *Dest = Default;
742 
743  return (ShiftArg(Argument));
744 }
745 
746 /*
747  * Same as above; however, will toggle the boolean if user doesn't
748  * supply value
749  */
750 
751 static int ParseBoolArg(int *Dest, /* Boolean value */
752  char **Argument) /* optarg or similar */
753 {
754  long D = *Dest ? 1L : 0L;
755  int Retval;
756 
757  Retval = ParseNumArg(&D, *Dest ? 0L : 1L, Argument);
758 
759  *Dest = D ? TRUE : FALSE;
760 
761  return (Retval);
762 }
763 
764 /*
765  * Returns the first character in the string passed, updates the
766  * string pointer, if the string is non-empty.
767  *
768  * 0 if the string is empty.
769  */
770 
771 static int ShiftArg(char **Argument) /* optarg or similar */
772 {
773  if (Argument && *Argument && **Argument)
774  return (*((char *) (*Argument)++));
775  else
776  return 0;
777 }
778 
779 /*
780  * Parses an argv similar array.
781  */
782 
783 static int ParseArgs(int argc, char **argv)
784 {
785  /* Needed for option parsing. */
786 
787  static const struct option long_options[] = {
788  {"help", no_argument, 0L, 'h'},
789  {"localrc", required_argument, 0L, 'l'},
790  {"output", required_argument, 0L, 'o'},
791  {"warnon", required_argument, 0L, 'w'},
792  {"erroron", required_argument, 0L, 'e'},
793  {"msgon", required_argument, 0L, 'm'},
794  {"nowarn", required_argument, 0L, 'n'},
795  {"nolinesupp", no_argument, 0L, 'L'},
796  {"verbosity", optional_argument, 0L, 'v'},
797  {"pipeverb", optional_argument, 0L, 'V'},
798  {"debug", required_argument, 0L, 'd'},
799  {"reset", no_argument, 0L, 'r'},
800  {"quiet", no_argument, 0L, 'q'},
801  {"license", no_argument, 0L, 'i'},
802  {"splitchar", required_argument, 0L, 's'},
803  {"format", required_argument, 0L, 'f'},
804  {"pseudoname", required_argument, 0L, 'p'},
805 
806  {"inputfiles", optional_argument, 0L, 'I'},
807  {"backup", optional_argument, 0L, 'b'},
808  {"globalrc", optional_argument, 0L, 'g'},
809  {"wipeverb", optional_argument, 0L, 'x'},
810  {"tictoc", optional_argument, 0L, 't'},
811  {"headererr", optional_argument, 0L, 'H'},
812  {"version", no_argument, 0L, 'W'},
813 
814  {0L, 0L, 0L, 0L}
815  };
816 
817  int option_index = 0L, c, i, nextc, ErrType;
818 
819  int Retval = FALSE, InUse;
820  int Success, Foo;
821  long Err, Verb = 1, PipeVerb = 1;
822 
823  enum
824  {
825  aeNoErr = 0,
826  aeArg, /* missing/bad required argument */
827  aeOpt, /* unknown option returned */
828  aeHelp, /* just a call for help */
829  aeMem /* no memory */
830  } ArgErr = aeNoErr;
831 
832  optind = 0;
833 
834  while (!ArgErr &&
835  ((c = getopt_long((int) argc, argv,
836  "b::d:e:f:g::hH::I::il:m:n:Lo:p:qrs:t::v::V::w:Wx::",
837  long_options, &option_index)) != EOF))
838  {
839  while (c)
840  {
841  nextc = 0;
842  switch (c)
843  {
844  case 's':
845  if (!(Delimit = strdup(optarg)))
846  {
848  ArgErr = aeMem;
849  }
850 
851  break;
852  case 'p':
853  if (!(PseudoInName = strdup(optarg)))
854  {
856  ArgErr = aeMem;
857  }
858 
859  break;
860 
861  case 'd':
862 #ifdef STRIP_DEBUG
863 
865 #else
866 
867  nextc = ParseNumArg(&DebugLevel, 0xffff, &optarg);
868 #endif
869 
870  break;
871  case 'i':
872  LicenseOnly = TRUE;
873 
874  nextc = ShiftArg(&optarg);
875  break;
876  case 'L':
877  NoLineSupp = TRUE;
878 
879  nextc = ShiftArg(&optarg);
880  break;
881  case 'q':
882  Quiet = TRUE;
883 
884  nextc = ShiftArg(&optarg);
885  break;
886 
887  LOOP(warntype,
888  case 'w': ErrType = etWarn; InUse = iuOK; LAST(warntype);
889  case 'e': ErrType = etErr; InUse = iuOK; LAST(warntype);
890  case 'm': ErrType = etMsg; InUse = iuOK; LAST(warntype);
891  case 'n': ErrType = etMsg; InUse = iuNotUser; LAST(warntype);
892  )
893  if (isdigit((unsigned char)*optarg))
894  {
895  nextc = ParseNumArg(&Err, -1, &optarg);
896  if (betw(emMinFault, Err, emMaxFault))
897  {
898  LaTeXMsgs[Err].Type = ErrType;
899  LaTeXMsgs[Err].InUse = InUse;
900  }
901  else
902  {
903  ArgErr = aeOpt;
905  }
906  }
907  else if (!strcasecmp(optarg, "all"))
908  {
909  for (i = emMinFault + 1; i < emMaxFault; i++)
910  {
911  LaTeXMsgs[i].Type = ErrType;
912  LaTeXMsgs[i].InUse = InUse;
913  }
914  }
915  else
916  {
917  ArgErr = aeOpt;
919  }
920 
921  break;
922 
923  case 'g':
925  if (!GlobalRC)
926  {
927  ResetStacks();
928  }
929  break;
930 
931  case 'r':
932  ResetSettings();
933  nextc = ShiftArg(&optarg);
934  break;
935 
936  case 'l':
937  if (optarg)
938  ReadRC(optarg);
939  break;
940 
941  case 'f':
942  if (!(OutputFormat = strdup(optarg)))
943  {
945  ArgErr = aeMem;
946  }
947  break;
948 
949  case 'v':
950  nextc = ParseNumArg(&Verb, 2, &optarg);
951 
952  if (Verb < (long) OutFormat.Stack.Used)
954  else
955  {
957  ArgErr = aeArg;
958  }
959  break;
960  case 'V':
961  nextc = ParseNumArg(&PipeVerb, 1, &optarg);
962 
963  if (PipeVerb < (long) OutFormat.Stack.Used)
965  else
966  {
968  ArgErr = aeArg;
969  }
970  break;
971 
972  case 'o':
973  if (optarg)
974  {
975  if (*OutputName)
976  {
978  ArgErr = aeOpt;
979  }
980  else
981  {
982  if (!(OutputName = strdup(optarg)))
983  {
985  ArgErr = aeMem;
986  }
987  }
988  }
989 
990  break;
991 
992  case 't':
993  nextc = ParseBoolArg(&Foo, &optarg);
994  break;
995  case 'x':
997  break;
998  case 'b':
1000  break;
1001  case 'I':
1003  break;
1004  case 'H':
1006  break;
1007  case 'W':
1008  printf("%s", Banner);
1009  exit(EXIT_SUCCESS);
1010  case '?':
1011  default:
1012  fputs(Banner, stderr);
1013  fputs(HowHelp, stderr);
1014  exit(EXIT_FAILURE);
1015  break;
1016  case 'h':
1017  ArgErr = aeHelp;
1018  break;
1019  }
1020  c = nextc;
1021  }
1022  }
1023 
1024  if ((argc > optind) && !strcmp(argv[optind], "?"))
1025  ArgErr = aeHelp;
1026 
1027  if (ArgErr)
1028  {
1029  fputs(Banner, stderr);
1030  fputs(BigBanner, stderr);
1031  fputs(HelpText, stderr);
1032  Success = FALSE;
1033  }
1034  else
1035  Success = TRUE;
1036 
1037  if (Success)
1038  Retval = optind;
1039 
1040  return (Retval);
1041 }
1042 
1043 /*
1044  * Outputs a program error.
1045  */
1046 
1047 
1048 void PrintPrgErr(enum PrgErrNum Error, ...)
1049 {
1050  const char *Type;
1051  va_list MsgArgs;
1052 
1054  {
1055  switch (PrgMsgs[Error].Type)
1056  {
1057  case etWarn:
1058  Type = "WARNING";
1059  break;
1060  case etMsg:
1061  Type = "NOTE";
1062  break;
1063  default:
1064  case etErr:
1065  Type = "ERROR";
1066  break;
1067  }
1068  fprintf(stderr, "%s: %s -- ", PrgName, Type);
1069 
1070  va_start(MsgArgs, Error);
1071  vfprintf(stderr, PrgMsgs[Error].Message, MsgArgs);
1072  va_end(MsgArgs);
1073  fputc('\n', stderr);
1074 
1075  if (PrgMsgs[Error].Type == etErr)
1076  exit(EXIT_FAILURE);
1077  }
1078 }
1079 
1080 void ErrPrintf(const char *fmt, ...)
1081 {
1082  va_list MsgArgs;
1083 
1084  va_start(MsgArgs, fmt);
1085  vfprintf(stderr, fmt, MsgArgs);
1086  va_end(MsgArgs);
1087 }
long __cdecl strtol(char const *_String, char **_EndPtr, int _Radix)
struct Stack InputStack
Definition: ChkTeX.c:51
static void SetupLists(void)
Definition: ChkTeX.c:246
int WipeVerb
Definition: ChkTeX.c:200
static void ShowIntStatus(void)
Definition: ChkTeX.c:606
void ErrPrintf(char *fmt,...)
Definition: ChkTeX.c:1080
static char * HowHelp
Definition: ChkTeX.c:124
#define NOCOMMON(a, b)
Definition: ChkTeX.c:272
#define ThisItem
int HeadErrOut
Definition: ChkTeX.c:200
int main(int argc, char **argv)
Definition: ChkTeX.c:339
static char * BigBanner
Definition: ChkTeX.c:95
int UsingStdIn
Definition: ChkTeX.c:200
static int ShiftArg(char **Argument)
Definition: ChkTeX.c:771
static void ResetStacks(void)
Definition: ChkTeX.c:705
long DebugLevel
Definition: ChkTeX.c:200
FILE * OutputFile
Definition: ChkTeX.c:203
int Quiet
Definition: ChkTeX.c:200
int InputFiles
Definition: ChkTeX.c:200
char VerbNormal[]
Definition: ChkTeX.c:197
int GlobalRC
Definition: ChkTeX.c:200
static void AddStars(struct WordList *wl)
Definition: ChkTeX.c:223
char * TmpBuffer
Definition: ChkTeX.c:74
struct ErrMsg PrgMsgs[pmMaxFault+1]
Definition: ChkTeX.c:45
char * ReadBuffer
Definition: ChkTeX.c:75
enum Quote Quote
Definition: ChkTeX.c:195
struct Stack CharStack
Definition: ChkTeX.c:49
static char * OffText
Definition: ChkTeX.c:122
int BackupOut
Definition: ChkTeX.c:200
static void ShowWL(char *Name, struct WordList *wl)
Definition: ChkTeX.c:559
int LicenseOnly
Definition: ChkTeX.c:200
static char * HelpText
Definition: ChkTeX.c:127
static void ResetSettings(void)
Definition: ChkTeX.c:716
#define SHOWSTR(text, arg)
Definition: ChkTeX.c:599
static void NoCommon(struct WordList *a, char *aName, struct WordList *b, char *bName)
Definition: ChkTeX.c:279
static char * Banner
Definition: ChkTeX.c:77
#define BOOLSTAT(name, var)
Definition: ChkTeX.c:598
char * OutputName
Definition: ChkTeX.c:200
char * PipeOutputFormat
Definition: ChkTeX.c:200
char BrOrder[6+1]
Definition: ChkTeX.c:61
int StdInTTY
Definition: ChkTeX.c:207
char * PrgName
Definition: ChkTeX.c:205
int StdOutTTY
Definition: ChkTeX.c:207
char * PseudoInName
Definition: ChkTeX.c:200
static void ExpandTabs(char *From, char *To, long TSize, long MaxDiff)
Definition: ChkTeX.c:296
static int ParseNumArg(long *Dest, long Default, char **Argument)
Definition: ChkTeX.c:734
static int ParseArgs(int argc, char **argv)
Definition: ChkTeX.c:783
char * Delimit
Definition: ChkTeX.c:200
unsigned long Brackets[6]
Definition: ChkTeX.c:63
struct Stack EnvStack
Definition: ChkTeX.c:54
static char * Distrib
Definition: ChkTeX.c:104
void PrintPrgErr(enum PrgErrNum Error,...)
Definition: ChkTeX.c:1048
int NoLineSupp
Definition: ChkTeX.c:200
static int ParseBoolArg(int *Dest, char **Argument)
Definition: ChkTeX.c:751
static char * OnText
Definition: ChkTeX.c:120
static int OpenOut(void)
Definition: ChkTeX.c:515
#define LAST(name)
Definition: ChkTeX.h:155
#define PRGMSGS
Definition: ChkTeX.h:193
#define INTERNFAULT
Definition: ChkTeX.h:165
#define STATE_VARS
Definition: ChkTeX.h:328
Quote
Definition: ChkTeX.h:349
@ quTrad
Definition: ChkTeX.h:351
@ quLogic
Definition: ChkTeX.h:350
#define OPTION_DEFAULTS
Definition: ChkTeX.h:311
#define NUMBRACKETS
Definition: ChkTeX.h:157
PrgErrNum
Definition: ChkTeX.h:269
@ pmQuoteStyle
Definition: ChkTeX.h:270
@ pmWarnNumErr
Definition: ChkTeX.h:270
@ pmNoDebugFlag
Definition: ChkTeX.h:270
@ pmOutTwice
Definition: ChkTeX.h:270
@ pmVerbLevErr
Definition: ChkTeX.h:270
@ pmNoCommon
Definition: ChkTeX.h:270
@ pmMinFault
Definition: ChkTeX.h:270
@ pmStrDupErr
Definition: ChkTeX.h:270
@ pmTabExpands
Definition: ChkTeX.h:270
@ pmOutOpen
Definition: ChkTeX.h:270
@ pmRename
Definition: ChkTeX.h:270
@ pmRenameErr
Definition: ChkTeX.h:270
@ pmMaxFault
Definition: ChkTeX.h:270
#define NEWBUF(name, len)
Definition: ChkTeX.h:159
#define betw(a, b, c)
Definition: ChkTeX.h:139
@ FLG_DbgMsgs
Definition: ChkTeX.h:187
@ FLG_DbgListCont
Definition: ChkTeX.h:187
@ FLG_DbgOtherInfo
Definition: ChkTeX.h:187
@ FLG_DbgListInfo
Definition: ChkTeX.h:187
#define LOOP(name, body)
Definition: ChkTeX.h:154
void PrintStatus(unsigned long Lines)
Definition: FindErrs.c:1777
struct ErrMsg LaTeXMsgs[emMaxFault+1]
Definition: FindErrs.c:63
int FindErr(const char *_RealBuf, const unsigned long _Line)
Definition: FindErrs.c:1302
ErrNum
Definition: FindErrs.h:137
@ emMaxFault
Definition: FindErrs.h:138
@ emMinFault
Definition: FindErrs.h:138
void SetupTerm(void)
Definition: OpSys.c:280
int SetupVars(void)
Definition: OpSys.c:160
void AddAppendix(char *Name, const char *App)
Definition: OpSys.c:351
char ConfigFile[BUFSIZ]
Definition: OpSys.c:118
#define BAKAPPENDIX
Definition: OpSys.h:182
#define STDIN_BREAK
Definition: OpSys.h:139
int ReadRC(const char *Filename)
Definition: Resource.c:111
struct WordList NonItalic
Definition: Resource.c:39
struct WordList CenterDots
Definition: Resource.c:39
struct WordList Italic
Definition: Resource.c:39
struct WordList UserWarnCase
Definition: Resource.c:39
const char * TabSize
Definition: Resource.c:39
struct WordList LowDots
Definition: Resource.c:39
struct WordList VerbEnvir
Definition: Resource.c:39
struct WordList WipeArg
Definition: Resource.c:39
struct WordList CmdLine
Definition: Resource.c:39
const char * QuoteStyle
Definition: Resource.c:39
struct WordList AbbrevCase
Definition: Resource.c:39
struct WordList OutFormat
Definition: Resource.c:39
struct WordList MathEnvir
Definition: Resource.c:39
struct WordList NoCharNext
Definition: Resource.c:39
struct WordList Abbrev
Definition: Resource.c:39
struct WordList ItalCmd
Definition: Resource.c:39
#define RESOURCE_INFO
Definition: Resource.h:43
void MakeLower(struct WordList *wl)
Definition: Utility.c:574
int PushFileName(const char *Name, struct Stack *stack)
Definition: Utility.c:681
void ListRep(struct WordList *wl, const char From, const char To)
Definition: Utility.c:585
char * FGetsStk(char *Dest, unsigned long len, struct Stack *stack)
Definition: Utility.c:725
void * StkTop(struct Stack *Stack)
Definition: Utility.c:671
void strrep(char *String, const char From, const char To)
Definition: Utility.c:131
unsigned long CurStkLine(struct Stack *stack)
Definition: Utility.c:797
char * HasWord(const char *Word, struct WordList *WL)
Definition: Utility.c:564
FILE * CurStkFile(struct Stack *stack)
Definition: Utility.c:787
int PushFile(const char *Name, FILE *fh, struct Stack *stack)
Definition: Utility.c:701
int InsertWord(const char *Word, struct WordList *WL)
Definition: Utility.c:512
int fexists(const char *Filename)
Definition: Utility.c:80
#define strdup
Definition: Utility.h:167
#define FORWL(ind, list)
Definition: Utility.h:49
static double percent(cairo_time_t a, cairo_time_t b)
static struct option long_options[]
Definition: cjklatex.c:87
Definition: error.hpp:20
#define b
Definition: jpegint.h:372
@ FALSE
Definition: dd.h:101
@ TRUE
Definition: dd.h:102
#define fopen
Definition: xxstdio.h:21
char * strncpy()
int strcmp()
Definition: coll.cpp:143
int printf()
char * strcpy()
i32 Count[10]
Definition: dvibook.c:121
#define c(n)
Definition: gpos-common.c:150
#define a(n)
Definition: gpos-common.c:148
#define strchr
Definition: gsftopk.c:59
const unsigned D
Definition: image.cpp:30
#define EXIT_SUCCESS
Definition: cdjpeg.h:175
#define EXIT_FAILURE
Definition: cdjpeg.h:169
char String
Definition: tttypes.h:35
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
void exit()
#define EOF
Definition: afmparse.c:59
enum OutputFormat_ OutputFormat
#define PACKAGE_VERSION
Definition: config.h:105
int optind
Definition: getopt.c:39
char * optarg
Definition: getopt.c:42
#define no_argument
Definition: getopt.h:110
#define required_argument
Definition: getopt.h:111
int getopt_long()
#define optional_argument
Definition: getopt.h:112
#define strcasecmp
Definition: c-auto.h:150
#define fclose
Definition: debug.h:100
#define kpse_program_name
Definition: types.h:322
#define fileno
Definition: win32lib.h:72
#define isatty
Definition: win32lib.h:80
static int ret
Definition: convert.c:72
#define fputs
Definition: mendex.h:67
#define fprintf
Definition: mendex.h:64
int setmode()
int remove()
int option_index
Definition: getopt.c:147
#define isdigit(c)
Definition: snprintf.c:177
#define _O_BINARY
Definition: lfs.c:127
#define Default
Definition: nup.c:35
#define ArgErr(s, o, r)
Definition: objects.h:63
char * filename[256]
Definition: pbmtopk.c:46
logical rename
Definition: pmxab.c:724
int Err
Definition: pnmtotiffcmyk.c:84
#define HASH_SIZE
Definition: libppm3.c:19
type_C toupper(type_C)
bstring c int memset(void *s, int c, int length)
#define tolower(ch)
Definition: utype.h:137
#define isalpha(ch)
Definition: utype.h:82
long Diff
Definition: spottopgm.c:28
enum ErrMsg::@91 Type
@ etErr
Definition: FindErrs.h:158
enum ErrMsg::@92 InUse
struct HashEntry ** Index
Definition: Utility.h:67
Definition: Utility.h:71
void ** Data
Definition: Utility.h:72
unsigned long Used
Definition: Utility.h:73
A string of characters.
Definition: t1part.c:49
struct Hash Hash
Definition: Utility.h:81
struct Stack Stack
Definition: Utility.h:80
unsigned long MaxLen
Definition: Utility.h:78
Definition: getopt.h:95
#define FILE
Definition: t1stdio.h:34
#define ferror(f)
Definition: t1stdio.h:110
int j
Definition: t4ht.c:1589
*job_name strlen((char *) job_name) - 4)
char fmt[256]
Definition: tex4ht.c:3925
@ L
Definition: ubidiimp.h:45
#define BUFSIZ
Definition: ps.c:61
#define va_start(pvar)
Definition: varargs.h:30
#define va_end(pvar)
Definition: varargs.h:38
char * va_list
Definition: varargs.h:22
static const char * bName
Definition: wrtjava.cpp:91
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269
static int nextc(parser_state *p)
Definition: y.tab.c:10227