summaryrefslogtreecommitdiff
path: root/src/preproc/perr.c
blob: 99861117ed1e8e8ff4d88ee303ba4f5a29428ce9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 * The functions in this file print error messages.
 */
#include "../preproc/preproc.h"
#include "../preproc/pproto.h"
extern char *progname;

/*
 * Prototypes for static functions.
 */
static void rm_files (void);


/*
 * File list.
 */
struct finfo_lst {
   char *name;                  /* file name */
   FILE *file;                  /* file */
   struct finfo_lst *next;      /* next entry in list */
   };

static struct finfo_lst *file_lst = NULL;

/*
 * errt1 - error message in one string, location indicated by a token.
 */
void errt1(t, s)
struct token *t;
char *s;
   {
   errfl1(t->fname, t->line, s);
   }

/*
 * errfl1 - error message in one string, location given by file and line.
 */
void errfl1(f, l, s)
char *f;
int l;
char *s;
   {
   fflush(stdout);
   fprintf(stderr, "%s: File %s; Line %d: %s\n", progname, f, l, s);
   rm_files();
   exit(EXIT_FAILURE);
   }

/*
 * err1 - error message in one string, no location given
 */
void err1(s)
char *s;
   {
   fflush(stdout);
   fprintf(stderr, "%s: %s\n", progname, s);
   rm_files();
   exit(EXIT_FAILURE);
   }

/*
 * errt2 - error message in two strings, location indicated by a token.
 */
void errt2(t, s1, s2)
struct token *t;
char *s1;
char *s2;
   {
   errfl2(t->fname, t->line, s1, s2);
   }

/*
 * errfl2 - error message in two strings, location given by file and line.
 */
void errfl2(f, l, s1, s2)
char *f;
int l;
char *s1;
char *s2;
   {
   fflush(stdout);
   fprintf(stderr, "%s: File %s; Line %d: %s%s\n", progname, f, l, s1, s2);
   rm_files();
   exit(EXIT_FAILURE);
   }

/*
 * err2 - error message in two strings, no location given
 */
void err2(s1, s2)
char *s1;
char *s2;
   {
   fflush(stdout);
   fprintf(stderr, "%s: %s%s\n", progname, s1, s2);
   rm_files();
   exit(EXIT_FAILURE);
   }

/*
 * errt3 - error message in three strings, location indicated by a token.
 */
void errt3(t, s1, s2, s3)
struct token *t;
char *s1;
char *s2;
char *s3;
   {
   errfl3(t->fname, t->line, s1, s2, s3);
   }

/*
 * errfl3 - error message in three strings, location given by file and line.
 */
void errfl3(f, l, s1, s2, s3)
char *f;
int l;
char *s1;
char *s2;
char *s3;
   {
   fflush(stdout);
   fprintf(stderr, "%s: File %s; Line %d: %s%s%s\n", progname, f, l,
       s1, s2, s3);
   rm_files();
   exit(EXIT_FAILURE);
   }

/*
 * addrmlst - add a file name to the list of files to be removed if
 *   an error occurs.
 */
void addrmlst(fname, f)
char *fname;
FILE *f;
   {
   struct finfo_lst *id;

   id = NewStruct ( finfo_lst );
   id->name = fname;
   id->file = f;
   id->next = file_lst;
   file_lst = id;
   }

/*
 * rm_files - remove files that must be cleaned up in the event of an
 *   error.
 */
static void rm_files()
   {
   while (file_lst != NULL) {
      fclose ( file_lst->file );
      remove(file_lst->name);
      file_lst = file_lst->next;
      }
   }