Home | History | Annotate | Line # | Download | only in error
error.h revision 1.15
      1 /*	$NetBSD: error.h,v 1.15 2009/08/13 06:59:37 dholland Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1980, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. Neither the name of the University nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  *
     31  *	@(#)error.h	8.1 (Berkeley) 6/6/93
     32  */
     33 
     34 #include <stdbool.h>
     35 
     36 typedef int boolean;
     37 
     38 /*
     39  * Descriptors for the various languages we know about.
     40  * If you touch these, also touch lang_table
     41  */
     42 #define INUNKNOWN	0
     43 #define INCPP		1
     44 #define INCC		2
     45 #define INAS		3
     46 #define INLD		4
     47 #define INLINT		5
     48 #define INF77		6
     49 #define INPI		7
     50 #define INPC		8
     51 #define INFRANZ		9
     52 #define INLISP		10
     53 #define INVAXIMA	11
     54 #define INRATFOR	12
     55 #define INLEX		13
     56 #define INYACC		14
     57 #define INAPL		15
     58 #define INMAKE		16
     59 #define INRI		17
     60 #define INTROFF		18
     61 #define INMOD2		19
     62 
     63 /*
     64  * We analyze each line in the error message file, and
     65  * attempt to categorize it by type, as well as language.
     66  * Here are the type descriptors.
     67  */
     68 typedef int Errorclass;
     69 
     70 #define C_FIRST		  0	/* first error category */
     71 #define C_UNKNOWN	0	/* must be zero */
     72 #define C_IGNORE	1	/* ignore the message; used for pi */
     73 #define C_SYNC		2	/* synchronization errors */
     74 #define C_DISCARD	3	/* touches dangerous files, so discard */
     75 #define C_NONSPEC	4	/* not specific to any file */
     76 #define C_THISFILE	5	/* specific to this file, but at no line */
     77 #define C_NULLED	6	/* refers to special func; so null */
     78 #define C_TRUE		7	/* fits into true error format */
     79 #define C_DUPL		8	/* sub class only; duplicated error message */
     80 #define C_LAST		  9	/* last error category */
     81 
     82 #define SORTABLE(x)	(!(NOTSORTABLE(x)))
     83 #define NOTSORTABLE(x)	(x <= C_NONSPEC)
     84 
     85 /*
     86  * Resources to count and print out the error categories
     87  */
     88 extern const char *class_table[];
     89 extern int class_count[];
     90 
     91 #define nunknown	class_count[C_UNKNOWN]
     92 #define nignore		class_count[C_IGNORE]
     93 #define nsyncerrors	class_count[C_SYNC]
     94 #define ndiscard	class_count[C_DISCARD]
     95 #define nnonspec	class_count[C_NONSPEC]
     96 #define nthisfile	class_count[C_THISFILE]
     97 #define nnulled		class_count[C_NULLED]
     98 #define ntrue		class_count[C_TRUE]
     99 #define ndupl		class_count[C_DUPL]
    100 
    101 /* places to put the error complaints */
    102 
    103 #define TOTHEFILE	1	/* touch the file */
    104 #define TOSTDOUT	2	/* just print them out (ho-hum) */
    105 
    106 extern FILE *errorfile;	/* where error file comes from */
    107 extern FILE *queryfile;	/* where the query responses from the user come from*/
    108 
    109 extern char *processname;
    110 extern char *scriptname;
    111 
    112 extern const char *suffixlist;
    113 
    114 extern boolean query;
    115 extern boolean terse;
    116 int inquire(const char *, ...);	/* inquire for yes/no */
    117 
    118 /*
    119  * codes for inquire() to return
    120  */
    121 #define Q_error	-1			/* an error occurred */
    122 #define Q_NO	1			/* 'N' */
    123 #define Q_no	2			/* 'n' */
    124 #define Q_YES	3			/* 'Y' */
    125 #define Q_yes	4			/* 'y' */
    126 
    127 /*
    128  * Describes attributes about a language
    129  */
    130 struct lang_desc {
    131 	const char *lang_name;
    132 	const char *lang_incomment;	/* one of the following defines */
    133 	const char *lang_outcomment;	/* one of the following defines */
    134 };
    135 extern struct lang_desc lang_table[];
    136 
    137 #define CINCOMMENT	"/*###"
    138 #define COUTCOMMENT	"%%%*/\n"
    139 #define FINCOMMENT	"C###"
    140 #define FOUTCOMMENT	"%%%\n"
    141 #define NEWLINE		"%%%\n"
    142 #define PIINCOMMENT	"(*###"
    143 #define PIOUTCOMMENT	"%%%*)\n"
    144 #define LISPINCOMMENT	";###"
    145 #define ASINCOMMENT	"####"
    146 #define RIINCOMMENT	CINCOMMENT
    147 #define RIOUTCOMMENT	COUTCOMMENT
    148 #define TROFFINCOMMENT	".\\\"###"
    149 #define TROFFOUTCOMMENT	NEWLINE
    150 #define MOD2INCOMMENT	"(*###"
    151 #define MOD2OUTCOMMENT	"%%%*)\n"
    152 
    153 /*
    154  * Defines and resources for determing if a given line
    155  * is to be discarded because it refers to a file not to
    156  * be touched, or if the function reference is to a
    157  * function the user doesn't want recorded.
    158  */
    159 
    160 #define ERRORNAME	"/.errorrc"
    161 extern int nignored;
    162 extern char **names_ignored;
    163 
    164 /*
    165  * Structure definition for a full error
    166  */
    167 typedef struct edesc Edesc;
    168 typedef Edesc *Eptr;
    169 
    170 struct edesc {
    171 	Eptr error_next;		/* linked together */
    172 	int error_lgtext;		/* how many on the right hand side */
    173 	char **error_text;		/* the right hand side proper */
    174 	Errorclass error_e_class;	/* error category of this error */
    175 	Errorclass error_s_class;	/* sub descriptor of error_e_class */
    176 	int error_language;		/* the language for this error */
    177 	int error_position;		/* oridinal position */
    178 	int error_line;			/* discovered line number */
    179 	int error_no;			/* sequence number on input */
    180 };
    181 
    182 /*
    183  * Resources for the true errors
    184  */
    185 extern int nerrors;
    186 extern Eptr er_head;
    187 
    188 extern int cur_wordc;
    189 extern char **cur_wordv;
    190 
    191 
    192 /*
    193  * Resources for each of the files mentioned
    194  */
    195 extern int nfiles;
    196 extern Eptr **files;			/* array of pointers into errors */
    197 extern boolean *touchedfiles;		/* which files we touched */
    198 
    199 /*
    200  * The language the compilation is in, as intuited from
    201  * the flavor of error messages analyzed.
    202  */
    203 extern int language;
    204 extern char *currentfilename;
    205 
    206 /*
    207  * Macros for initializing arrays of string constants.
    208  * This is a fairly gross set of preprocessor hacks; the idea is
    209  * that instead of
    210  *     static char *foo[4] = { "alpha", "beta", "gamma", "delta" };
    211  * you do
    212  *     DECL_STRINGS_4(static, foo, "alpha", "beta", "gamma", "delta");
    213  *
    214  * and it comes out as
    215  *     static char foo_0[] = "delta";
    216  *     static char foo_1[] = "gamma";
    217  *     static char foo_2[] = "beta";
    218  *     static char foo_3[] = "alpha";
    219  *     static char *foo[4] = { foo_3, foo_2, foo_1, foo_0 };
    220  *
    221  * none of which is const.
    222  *
    223  * Unfortunately, the string arrays this program slings around freely
    224  * can't be all const (because it munges some of them) and can't be
    225  * all non-const without something like this to initialize the ones
    226  * that need to contain string constants. Unfortunately you can't
    227  * mix (const char *const *) and (char **) in C, only in C++.
    228  */
    229 
    230 #define DECL_STR(sym, num, str) static char sym##_##num[] = str
    231 
    232 #define DECL_S1(sym, s, ...) __VA_ARGS__ DECL_STR(sym, 0, s)
    233 #define DECL_S2(sym, s, ...) DECL_STR(sym, 1, s); DECL_S1(sym, __VA_ARGS__)
    234 #define DECL_S3(sym, s, ...) DECL_STR(sym, 2, s); DECL_S2(sym, __VA_ARGS__)
    235 #define DECL_S4(sym, s, ...) DECL_STR(sym, 3, s); DECL_S3(sym, __VA_ARGS__)
    236 #define DECL_S5(sym, s, ...) DECL_STR(sym, 4, s); DECL_S4(sym, __VA_ARGS__)
    237 #define DECL_S6(sym, s, ...) DECL_STR(sym, 5, s); DECL_S5(sym, __VA_ARGS__)
    238 
    239 #define USE_S1(sym) sym##_0
    240 #define USE_S2(sym) sym##_1, USE_S1(sym)
    241 #define USE_S3(sym) sym##_2, USE_S2(sym)
    242 #define USE_S4(sym) sym##_3, USE_S3(sym)
    243 #define USE_S5(sym) sym##_4, USE_S4(sym)
    244 #define USE_S6(sym) sym##_5, USE_S5(sym)
    245 
    246 #define DECL_STRS(num, class, sym, ...) \
    247 	DECL_S##num(sym, __VA_ARGS__); \
    248 	class char *sym[num] = { USE_S##num(sym) }
    249 
    250 #define DECL_STRINGS_1(class, sym, ...) DECL_STRS(1, class, sym, __VA_ARGS__)
    251 #define DECL_STRINGS_2(class, sym, ...) DECL_STRS(2, class, sym, __VA_ARGS__)
    252 #define DECL_STRINGS_3(class, sym, ...) DECL_STRS(3, class, sym, __VA_ARGS__)
    253 #define DECL_STRINGS_4(class, sym, ...) DECL_STRS(4, class, sym, __VA_ARGS__)
    254 #define DECL_STRINGS_5(class, sym, ...) DECL_STRS(5, class, sym, __VA_ARGS__)
    255 #define DECL_STRINGS_6(class, sym, ...) DECL_STRS(6, class, sym, __VA_ARGS__)
    256 
    257 
    258 /*
    259  *	Functional forwards
    260  */
    261 void arrayify(int *, Eptr **, Eptr);
    262 void *Calloc(size_t, size_t);
    263 void clob_last(char *,  char);
    264 Errorclass discardit(Eptr);
    265 void eaterrors(int *, Eptr **);
    266 void erroradd(int, char **, Errorclass, Errorclass);
    267 void filenames(int, Eptr **);
    268 void findfiles(int, Eptr *, int *, Eptr ***);
    269 char firstchar(const char *);
    270 void getignored(const char *);
    271 char lastchar(const char *);
    272 char next_lastchar(const char *);
    273 void onintr(int);
    274 bool persperdexplode(char *, char **, char **);
    275 Errorclass pi(void);
    276 int position(const char *, char);
    277 void printerrors(bool, int, Eptr []);
    278 const char *plural(int);
    279 char *Strdup(const char *);
    280 char *substitute(char *, char, char);
    281 bool touchfiles(int, Eptr **, int *, char ***);
    282 const char *verbform(int);
    283 void wordvbuild(char *, int*, char ***);
    284 int wordvcmp(char **, int, char **);
    285 void wordvprint(FILE *, int, char **);
    286 char **wordvsplice(int, int, char **);
    287