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