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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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:%d:%d: %s: ", input_name
? input_name
: "stdin", line_number
, char_number
, t
);
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 mcy_error(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 mcy_warning(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
= 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");
151 memset(res
, 0x55, size
);
156 void *xrealloc(void *p
, size_t size
)
161 assert(size
< 102400);
162 res
= realloc(p
, size
);
165 error("Virtual memory exhausted.\n");
170 char *xstrdup(const char *str
)
175 s
= xmalloc(strlen(str
)+1);
176 return strcpy(s
, str
);
179 int unistrlen(const WCHAR
*s
)
182 for(n
= 0; *s
; n
++, s
++)
187 WCHAR
*unistrcpy(WCHAR
*dst
, const WCHAR
*src
)
196 WCHAR
*xunistrdup(const WCHAR
* str
)
201 s
= xmalloc((unistrlen(str
)+1) * sizeof(WCHAR
));
202 return unistrcpy(s
, str
);
205 int unistricmp(const WCHAR
*s1
, const WCHAR
*s2
)
209 static const char warn
[] = "Don't know the uppercase equivalent of non acsii characters;"
210 "comparison might yield wrong results";
213 if((*s1
& 0xffff) > 0x7f || (*s2
& 0xffff) > 0x7f)
223 i
= toupper(*s1
++) - toupper(*s2
++);
228 if((*s1
& 0xffff) > 0x7f || (*s2
& 0xffff) > 0x7f)
235 return toupper(*s1
) - toupper(*s2
);
238 int unistrcmp(const WCHAR
*s1
, const WCHAR
*s2
)