4 * Copyright 1998,2000 Bertho A. Stultiens
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
35 #define SUPPRESS_YACC_ERROR_MESSAGE
37 static void generic_msg(const char *s, const char *t, va_list ap)
39 fprintf(stderr, "%s %s: %d, %d: ", t, input_name ? input_name : "stdin", line_number, char_number);
40 vfprintf(stderr, s, ap);
41 fprintf(stderr, "\n");
45 * The yyerror routine should not exit because we use the error-token
46 * to determine the syntactic error in the source. However, YACC
47 * uses the same routine to print an error just before the error
49 * The extra routine 'xyyerror' is used to exit after giving a real
52 int yyerror(const char *s, ...)
54 #ifndef SUPPRESS_YACC_ERROR_MESSAGE
57 generic_msg(s, "Yacc error", ap);
63 int xyyerror(const char *s, ...)
67 generic_msg(s, "Error", ap);
73 int yywarning(const char *s, ...)
77 generic_msg(s, "Warning", ap);
82 void internal_error(const char *file, int line, const char *s, ...)
86 fprintf(stderr, "Internal error (please report) %s %d: ", file, line);
87 vfprintf(stderr, s, ap);
88 fprintf(stderr, "\n");
93 void error(const char *s, ...)
97 fprintf(stderr, "Error: ");
98 vfprintf(stderr, s, ap);
99 fprintf(stderr, "\n");
104 void warning(const char *s, ...)
108 fprintf(stderr, "Warning: ");
109 vfprintf(stderr, s, ap);
110 fprintf(stderr, "\n");
114 char *dup_basename(const char *name, const char *ext)
117 int extlen = strlen(ext);
124 slash = strrchr(name, '/');
128 namelen = strlen(name);
130 /* +4 for later extension and +1 for '\0' */
131 base = (char *)xmalloc(namelen +4 +1);
133 if(!strcasecmp(name + namelen-extlen, ext))
135 base[namelen - extlen] = '\0';
140 void *xmalloc(size_t size)
145 assert(size < 102400);
149 error("Virtual memory exhausted.\n");
153 * This is *paramount* because we depend on it
154 * just about everywhere in the rest of the code.
156 memset(res, 0, size);
161 void *xrealloc(void *p, size_t size)
166 assert(size < 102400);
167 res = realloc(p, size);
170 error("Virtual memory exhausted.\n");
175 char *xstrdup(const char *str)
180 s = (char *)xmalloc(strlen(str)+1);
181 return strcpy(s, str);
184 int unistrlen(const WCHAR *s)
187 for(n = 0; *s; n++, s++)
192 WCHAR *unistrcpy(WCHAR *dst, const WCHAR *src)
201 WCHAR *xunistrdup(const WCHAR * str)
206 s = (WCHAR *)xmalloc((unistrlen(str)+1) * sizeof(WCHAR));
207 return unistrcpy(s, str);
210 int unistricmp(const WCHAR *s1, const WCHAR *s2)
214 static char warn[] = "Don't know the uppercase equivalent of non acsii characters;"
215 "comparison might yield wrong results";
218 if((*s1 & 0xffff) > 0x7f || (*s2 & 0xffff) > 0x7f)
228 i = toupper(*s1++) - toupper(*s2++);
233 if((*s1 & 0xffff) > 0x7f || (*s2 & 0xffff) > 0x7f)
240 return toupper(*s1) - toupper(*s2);
243 int unistrcmp(const WCHAR *s1, const WCHAR *s2)