4 * Copyright 1998,2000 Bertho A. Stultiens
21 #define SUPPRESS_YACC_ERROR_MESSAGE
23 static void generic_msg(const char *s
, const char *t
, va_list ap
)
25 fprintf(stderr
, "%s %s: %d, %d: ", t
, input_name
? input_name
: "stdin", line_number
, char_number
);
26 vfprintf(stderr
, s
, ap
);
27 fprintf(stderr
, "\n");
31 * The yyerror routine should not exit because we use the error-token
32 * to determine the syntactic error in the source. However, YACC
33 * uses the same routine to print an error just before the error
35 * The extra routine 'xyyerror' is used to exit after giving a real
38 int yyerror(const char *s
, ...)
40 #ifndef SUPPRESS_YACC_ERROR_MESSAGE
43 generic_msg(s
, "Yacc error", ap
);
49 int xyyerror(const char *s
, ...)
53 generic_msg(s
, "Error", ap
);
59 int yywarning(const char *s
, ...)
63 generic_msg(s
, "Warning", ap
);
68 void internal_error(const char *file
, int line
, const char *s
, ...)
72 fprintf(stderr
, "Internal error (please report) %s %d: ", file
, line
);
73 vfprintf(stderr
, s
, ap
);
74 fprintf(stderr
, "\n");
79 void error(const char *s
, ...)
83 fprintf(stderr
, "Error: ");
84 vfprintf(stderr
, s
, ap
);
85 fprintf(stderr
, "\n");
90 void warning(const char *s
, ...)
94 fprintf(stderr
, "Warning: ");
95 vfprintf(stderr
, s
, ap
);
96 fprintf(stderr
, "\n");
100 char *dup_basename(const char *name
, const char *ext
)
103 int extlen
= strlen(ext
);
110 slash
= strrchr(name
, '/');
114 namelen
= strlen(name
);
116 /* +4 for later extension and +1 for '\0' */
117 base
= (char *)xmalloc(namelen
+4 +1);
119 if(!strcasecmp(name
+ namelen
-extlen
, ext
))
121 base
[namelen
- extlen
] = '\0';
126 void *xmalloc(size_t size
)
131 assert(size
< 102400);
135 error("Virtual memory exhausted.\n");
139 * This is *paramount* because we depend on it
140 * just about everywhere in the rest of the code.
142 memset(res
, 0, size
);
147 void *xrealloc(void *p
, size_t size
)
152 assert(size
< 102400);
153 res
= realloc(p
, size
);
156 error("Virtual memory exhausted.\n");
161 char *xstrdup(const char *str
)
166 s
= (char *)xmalloc(strlen(str
)+1);
167 return strcpy(s
, str
);
170 int unistrlen(const WCHAR
*s
)
173 for(n
= 0; *s
; n
++, s
++)
178 WCHAR
*unistrcpy(WCHAR
*dst
, const WCHAR
*src
)
187 WCHAR
*xunistrdup(const WCHAR
* str
)
192 s
= (WCHAR
*)xmalloc((unistrlen(str
)+1) * sizeof(WCHAR
));
193 return unistrcpy(s
, str
);
196 int unistricmp(const WCHAR
*s1
, const WCHAR
*s2
)
200 static char warn
[] = "Don't know the uppercase equivalent of non acsii characters;"
201 "comparison might yield wrong results";
204 if((*s1
& 0xffff) > 0x7f || (*s2
& 0xffff) > 0x7f)
214 i
= toupper(*s1
++) - toupper(*s2
++);
219 if((*s1
& 0xffff) > 0x7f || (*s2
& 0xffff) > 0x7f)
226 return toupper(*s1
) - toupper(*s2
);
229 int unistrcmp(const WCHAR
*s1
, const WCHAR
*s2
)