4 * Copyright 1998 Bertho A. Stultiens
20 #define WANT_NEAR_INDICATION
23 #ifdef WANT_NEAR_INDICATION
24 void make_print(char *str
)
35 int yyerror(const char *s
, ...)
39 fprintf(stderr
, "Error %s: %d, %d: ", input_name
? input_name
: "stdin", line_number
, char_number
);
40 vfprintf(stderr
, s
, ap
);
41 #ifdef WANT_NEAR_INDICATION
43 char *cpy
= xstrdup(yytext
);
45 fprintf(stderr
, " near '%s'\n", cpy
);
49 fprintf(stderr
, "\n");
56 int yywarning(const char *s
, ...)
60 fprintf(stderr
, "Warning %s: %d, %d: ", input_name
? input_name
: "stdin", line_number
, char_number
);
61 vfprintf(stderr
, s
, ap
);
62 #ifdef WANT_NEAR_INDICATION
64 char *cpy
= xstrdup(yytext
);
66 fprintf(stderr
, " near '%s'\n", cpy
);
70 fprintf(stderr
, "\n");
76 void internal_error(const char *file
, int line
, const char *s
, ...)
80 fprintf(stderr
, "Internal error (please report) %s %d: ", file
, line
);
81 vfprintf(stderr
, s
, ap
);
82 fprintf(stderr
, "\n");
87 void error(const char *s
, ...)
91 fprintf(stderr
, "Error: ");
92 vfprintf(stderr
, s
, ap
);
93 fprintf(stderr
, "\n");
98 void warning(const char *s
, ...)
102 fprintf(stderr
, "Warning: ");
103 vfprintf(stderr
, s
, ap
);
104 fprintf(stderr
, "\n");
108 void chat(const char *s
, ...)
110 if(debuglevel
& DEBUGLEVEL_CHAT
)
114 fprintf(stderr
, "FYI: ");
115 vfprintf(stderr
, s
, ap
);
116 fprintf(stderr
, "\n");
121 char *dup_basename(const char *name
, const char *ext
)
124 int extlen
= strlen(ext
);
131 slash
= strrchr(name
, '/');
135 namelen
= strlen(name
);
137 /* +4 for later extension and +1 for '\0' */
138 base
= (char *)xmalloc(namelen
+4 +1);
140 if(!stricmp(name
+ namelen
-extlen
, ext
))
142 base
[namelen
- extlen
] = '\0';
147 void *xmalloc(size_t size
)
152 assert(size
< 102400);
156 error("Virtual memory exhausted.\n");
158 memset(res
, 0, size
);
163 void *xrealloc(void *p
, size_t size
)
168 assert(size
< 102400);
169 res
= realloc(p
, size
);
172 error("Virtual memory exhausted.\n");
177 char *xstrdup(const char *str
)
179 char *s
= (char *)xmalloc(strlen(str
)+1);
180 return strcpy(s
, str
);
183 int string_compare(const string_t
*s1
, const string_t
*s2
)
185 if(s1
->type
== str_char
&& s2
->type
== str_char
)
187 return stricmp(s1
->str
.cstr
, s2
->str
.cstr
);
191 internal_error(__FILE__
, __LINE__
, "Cannot yet compare unicode strings");
196 int wstrlen(const short *s
)
204 short *wstrcpy(short *dst
, const short *src
)
212 int wstricmp(const short *s1
, const short *s2
)
214 char *cs1
= dupwstr2cstr(s1
);
215 char *cs2
= dupwstr2cstr(s2
);
216 int retval
= stricmp(cs1
, cs2
);
219 warning("Comparing unicode strings without case -> converting to ascii");
223 short *dupcstr2wstr(const char *str
)
225 int len
= strlen(str
) + 1;
226 short *ws
= (short *)xmalloc(len
*2);
230 /* FIXME: codepage translation */
232 *wptr
++ = (short)(*str
++ & 0xff);
237 char *dupwstr2cstr(const short *str
)
239 int len
= wstrlen(str
) + 1;
240 char *cs
= (char *)xmalloc(len
);
244 /* FIXME: codepage translation */
246 *cptr
++ = (char)*str
++;
252 int stricmp(const char *s1
, const char *s2
)
254 while(*s1
&& *s2
&& !(toupper(*s1
) - toupper(*s2
)))