4 * Copyright 1998 Bertho A. Stultiens
5 * Copyright 2002 Ove Kaaven
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
36 #define CURRENT_LOCATION { input_name ? input_name : "stdin", line_number, parser_text }
38 static const int want_near_indication
= 0;
40 static void make_print(char *str
)
50 static void generic_msg(const loc_info_t
*loc_info
, const char *s
, const char *t
, va_list ap
)
52 fprintf(stderr
, "%s:%d: %s: ", loc_info
->input_name
, loc_info
->line_number
, t
);
53 vfprintf(stderr
, s
, ap
);
55 if (want_near_indication
)
58 if(loc_info
->near_text
)
60 cpy
= xstrdup(loc_info
->near_text
);
62 fprintf(stderr
, " near '%s'", cpy
);
69 /* yyerror: yacc assumes this is not newline terminated. */
70 void parser_error(const char *s
, ...)
72 loc_info_t cur_location
= CURRENT_LOCATION
;
75 generic_msg(&cur_location
, s
, "Error", ap
);
76 fprintf(stderr
, "\n");
81 void error_loc(const char *s
, ...)
83 loc_info_t cur_loc
= CURRENT_LOCATION
;
86 generic_msg(&cur_loc
, s
, "Error", ap
);
91 void error_loc_info(const loc_info_t
*loc_info
, const char *s
, ...)
95 generic_msg(loc_info
, s
, "Error", ap
);
100 int parser_warning(const char *s
, ...)
102 loc_info_t cur_loc
= CURRENT_LOCATION
;
105 generic_msg(&cur_loc
, s
, "Warning", ap
);
110 void error(const char *s
, ...)
114 fprintf(stderr
, "error: ");
115 vfprintf(stderr
, s
, ap
);
120 void warning(const char *s
, ...)
124 fprintf(stderr
, "warning: ");
125 vfprintf(stderr
, s
, ap
);
129 void warning_loc_info(const loc_info_t
*loc_info
, const char *s
, ...)
133 generic_msg(loc_info
, s
, "Warning", ap
);
137 void chat(const char *s
, ...)
139 if(debuglevel
& DEBUGLEVEL_CHAT
)
143 fprintf(stderr
, "chat: ");
144 vfprintf(stderr
, s
, ap
);
149 char *dup_basename(const char *name
, const char *ext
)
152 int extlen
= strlen(ext
);
159 slash
= strrchr(name
, '/');
161 slash
= strrchr(name
, '\\');
166 namelen
= strlen(name
);
168 /* +4 for later extension and +1 for '\0' */
169 base
= xmalloc(namelen
+4 +1);
171 if(!strcasecmp(name
+ namelen
-extlen
, ext
))
173 base
[namelen
- extlen
] = '\0';
178 size_t widl_getline(char **linep
, size_t *lenp
, FILE *fp
)
190 while (fgets(&line
[n
], len
- n
, fp
))
192 n
+= strlen(&line
[n
]);
193 if (line
[n
- 1] == '\n')
195 else if (n
== len
- 1)
198 line
= xrealloc(line
, len
);
207 void *xmalloc(size_t size
)
215 error("Virtual memory exhausted.\n");
217 memset(res
, 0x55, size
);
222 void *xrealloc(void *p
, size_t size
)
227 res
= realloc(p
, size
);
230 error("Virtual memory exhausted.\n");
235 char *xstrdup(const char *str
)
240 s
= xmalloc(strlen(str
)+1);
241 return strcpy(s
, str
);