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