4 * Copyright 1998 Bertho A. Stultiens
5 * Copyright 2002 Ove Kaaven
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
37 /* #define WANT_NEAR_INDICATION */
39 #ifdef WANT_NEAR_INDICATION
40 void make_print(char *str
)
51 static void generic_msg(const char *s
, const char *t
, const char *n
, va_list ap
)
53 fprintf(stderr
, "%s:%d: %s: ", input_name
? input_name
: "stdin", line_number
, t
);
54 vfprintf(stderr
, s
, ap
);
55 #ifdef WANT_NEAR_INDICATION
62 fprintf(stderr
, " near '%s'", cpy
);
67 fprintf(stderr
, "\n");
71 int yyerror(const char *s
, ...)
75 generic_msg(s
, "Error", yytext
, ap
);
81 int yywarning(const char *s
, ...)
85 generic_msg(s
, "Warning", yytext
, ap
);
90 void internal_error(const char *file
, int line
, const char *s
, ...)
94 fprintf(stderr
, "Internal error (please report) %s %d: ", file
, line
);
95 vfprintf(stderr
, s
, ap
);
100 void error(const char *s
, ...)
104 fprintf(stderr
, "error: ");
105 vfprintf(stderr
, s
, ap
);
110 void warning(const char *s
, ...)
114 fprintf(stderr
, "warning: ");
115 vfprintf(stderr
, s
, ap
);
119 void chat(const char *s
, ...)
121 if(debuglevel
& DEBUGLEVEL_CHAT
)
125 fprintf(stderr
, "chat: ");
126 vfprintf(stderr
, s
, ap
);
131 char *dup_basename(const char *name
, const char *ext
)
134 int extlen
= strlen(ext
);
141 slash
= strrchr(name
, '/');
145 namelen
= strlen(name
);
147 /* +4 for later extension and +1 for '\0' */
148 base
= (char *)xmalloc(namelen
+4 +1);
150 if(!strcasecmp(name
+ namelen
-extlen
, ext
))
152 base
[namelen
- extlen
] = '\0';
157 void *xmalloc(size_t size
)
165 error("Virtual memory exhausted.\n");
169 * This is *paramount* because we depend on it
170 * just about everywhere in the rest of the code.
172 memset(res
, 0, size
);
177 void *xrealloc(void *p
, size_t size
)
182 res
= realloc(p
, size
);
185 error("Virtual memory exhausted.\n");
190 char *xstrdup(const char *str
)
195 s
= (char *)xmalloc(strlen(str
)+1);
196 return strcpy(s
, str
);