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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
37 static const int want_near_indication
= 0;
39 static void make_print(char *str
)
49 static void generic_msg(const char *s
, const char *t
, const char *n
, va_list ap
)
51 fprintf(stderr
, "%s:%d: %s: ", input_name
? input_name
: "stdin", line_number
, t
);
52 vfprintf(stderr
, s
, ap
);
54 if (want_near_indication
)
61 fprintf(stderr
, " near '%s'", cpy
);
68 /* yyerror: yacc assumes this is not newline terminated. */
69 int parser_error(const char *s
, ...)
73 generic_msg(s
, "Error", parser_text
, ap
);
74 fprintf(stderr
, "\n");
80 void error_loc(const char *s
, ...)
84 generic_msg(s
, "Error", parser_text
, ap
);
89 int parser_warning(const char *s
, ...)
93 generic_msg(s
, "Warning", parser_text
, ap
);
98 void error(const char *s
, ...)
102 fprintf(stderr
, "error: ");
103 vfprintf(stderr
, s
, ap
);
108 void warning(const char *s
, ...)
112 fprintf(stderr
, "warning: ");
113 vfprintf(stderr
, s
, ap
);
117 void chat(const char *s
, ...)
119 if(debuglevel
& DEBUGLEVEL_CHAT
)
123 fprintf(stderr
, "chat: ");
124 vfprintf(stderr
, s
, ap
);
129 char *dup_basename(const char *name
, const char *ext
)
132 int extlen
= strlen(ext
);
139 slash
= strrchr(name
, '/');
143 namelen
= strlen(name
);
145 /* +4 for later extension and +1 for '\0' */
146 base
= xmalloc(namelen
+4 +1);
148 if(!strcasecmp(name
+ namelen
-extlen
, ext
))
150 base
[namelen
- extlen
] = '\0';
155 size_t widl_getline(char **linep
, size_t *lenp
, FILE *fp
)
167 while (fgets(&line
[n
], len
- n
, fp
))
169 n
+= strlen(&line
[n
]);
170 if (line
[n
- 1] == '\n')
172 else if (n
== len
- 1)
175 line
= xrealloc(line
, len
);
184 void *xmalloc(size_t size
)
192 error("Virtual memory exhausted.\n");
194 memset(res
, 0x55, size
);
199 void *xrealloc(void *p
, size_t size
)
204 res
= realloc(p
, size
);
207 error("Virtual memory exhausted.\n");
212 char *xstrdup(const char *str
)
217 s
= xmalloc(strlen(str
)+1);
218 return strcpy(s
, str
);