1725ffd732b6a4933082e7cc3f91071b4bc005b7
4 * Copyright 1998,2000 Bertho A. Stultiens
22 #define SUPPRESS_YACC_ERROR_MESSAGE
24 static void generic_msg(const char *s
, const char *t
, va_list ap
)
26 fprintf(stderr
, "%s %s: %d, %d: ", t
, input_name
? input_name
: "stdin", line_number
, char_number
);
27 vfprintf(stderr
, s
, ap
);
28 fprintf(stderr
, "\n");
32 * The yyerror routine should not exit because we use the error-token
33 * to determine the syntactic error in the source. However, YACC
34 * uses the same routine to print an error just before the error
36 * The extra routine 'xyyerror' is used to exit after giving a real
39 int yyerror(const char *s
, ...)
41 #ifndef SUPPRESS_YACC_ERROR_MESSAGE
44 generic_msg(s
, "Yacc error", ap
);
50 int xyyerror(const char *s
, ...)
54 generic_msg(s
, "Error", ap
);
60 int yywarning(const char *s
, ...)
64 generic_msg(s
, "Warning", ap
);
69 void internal_error(const char *file
, int line
, const char *s
, ...)
73 fprintf(stderr
, "Internal error (please report) %s %d: ", file
, line
);
74 vfprintf(stderr
, s
, ap
);
75 fprintf(stderr
, "\n");
80 void error(const char *s
, ...)
84 fprintf(stderr
, "Error: ");
85 vfprintf(stderr
, s
, ap
);
86 fprintf(stderr
, "\n");
91 void warning(const char *s
, ...)
95 fprintf(stderr
, "Warning: ");
96 vfprintf(stderr
, s
, ap
);
97 fprintf(stderr
, "\n");
101 char *dup_basename(const char *name
, const char *ext
)
104 int extlen
= strlen(ext
);
111 slash
= strrchr(name
, '/');
115 namelen
= strlen(name
);
117 /* +4 for later extension and +1 for '\0' */
118 base
= (char *)xmalloc(namelen
+4 +1);
120 if(!stricmp(name
+ namelen
-extlen
, ext
))
122 base
[namelen
- extlen
] = '\0';
127 void *xmalloc(size_t size
)
132 assert(size
< 102400);
136 error("Virtual memory exhausted.\n");
140 * This is *paramount* because we depend on it
141 * just about everywhere in the rest of the code.
143 memset(res
, 0, size
);
148 void *xrealloc(void *p
, size_t size
)
153 assert(size
< 102400);
154 res
= realloc(p
, size
);
157 error("Virtual memory exhausted.\n");
162 char *xstrdup(const char *str
)
167 s
= (char *)xmalloc(strlen(str
)+1);
168 return strcpy(s
, str
);
171 int unistrlen(const WCHAR
*s
)
174 for(n
= 0; *s
; n
++, s
++)
179 WCHAR
*unistrcpy(WCHAR
*dst
, const WCHAR
*src
)
188 WCHAR
*xunistrdup(const WCHAR
* str
)
193 s
= (WCHAR
*)xmalloc((unistrlen(str
)+1) * sizeof(WCHAR
));
194 return unistrcpy(s
, str
);
197 int unistricmp(const WCHAR
*s1
, const WCHAR
*s2
)
201 static char warn
[] = "Don't know the uppercase equivalent of non acsii characters;"
202 "comparison might yield wrong results";
205 if((*s1
& 0xffff) > 0x7f || (*s2
& 0xffff) > 0x7f)
215 i
= toupper(*s1
++) - toupper(*s2
++);
220 if((*s1
& 0xffff) > 0x7f || (*s2
& 0xffff) > 0x7f)
227 return toupper(*s1
) - toupper(*s2
);
230 int unistrcmp(const WCHAR
*s1
, const WCHAR
*s2
)