/* $NetBSD: rpc_util.c,v 1.18 2015/09/20 16:57:13 kamil Exp $ */
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user or with the express written consent of
* Sun Microsystems, Inc.
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
/*
* Reinitialize the world
*/
void
reinitialize(void)
{
memset(curline, 0, MAXLINESIZE);
where = curline;
linenum = 0;
defined = NULL;
}
/*
* string equality
*/
int
streq(const char *a, const char *b)
{
return (strcmp(a, b) == 0);
}
/*
* find a value in a list
*/
definition *
findval(list *lst, const char *val, int (*cmp)(definition *, const char *))
{
for (; lst != NULL; lst = lst->next) {
if ((*cmp) (lst->val, val)) {
return (lst->val);
}
}
return (NULL);
}
/*
* store a value in a list
*/
void
storeval(list **lstp, definition *val)
{
list **l;
list *lst;
void
pvname(const char *pname, const char *vnum)
{
f_print(fout, "%s_%s", locase(pname), vnum);
}
/*
* print a useful (?) error message, and then die
*/
__printflike(1, 2) void
error(const char *msg, ...)
{
va_list ap;
printwhere();
fprintf(stderr, "%s:%d: ", infilename, linenum);
va_start(ap, msg);
vfprintf(stderr, msg, ap);
va_end(ap);
fprintf(stderr, "\n");
errx(EXIT_FAILURE, "Cannot recover from this error");
}
/*
* Something went wrong, unlink any files that we may have created and then
* die.
*/
void
crash(void)
{
int i;
if (!docleanup)
return;
for (i = 0; i < nfiles; i++) {
(void) unlink(outfiles[i]);
}
}
/*
* error, token encountered was not the expected one
*/
void
expected1(tok_kind exp1)
{
error("Expected '%s'", toktostr(exp1));
}
/*
* error, token encountered was not one of two expected ones
*/
void
expected2(tok_kind exp1, tok_kind exp2)
{
error("Expected '%s' or '%s'",
toktostr(exp1),
toktostr(exp2));
}
/*
* error, token encountered was not one of 3 expected ones
*/
void
expected3(tok_kind exp1, tok_kind exp2, tok_kind exp3)
{
error("Expected '%s', '%s', or '%s'",
toktostr(exp1),
toktostr(exp2),
toktostr(exp3));
}
void
tabify(FILE *f, int tab)
{
while (tab--) {
(void) fputc('\t', f);
}
}