2019-06-24 01:46:53 +03:00
|
|
|
/* $NetBSD: util.c,v 1.6 2019/06/23 22:46:53 christos Exp $ */
|
1997-09-26 21:54:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1997 Piermont Information Systems Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Philip A. Nelson for Piermont Information Systems Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2012-03-06 20:55:18 +04:00
|
|
|
* 3. The name of Piermont Information Systems Inc. may not be used to endorse
|
1997-09-26 21:54:09 +04:00
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* util.c - utility routines. */
|
|
|
|
|
2004-06-21 02:20:14 +04:00
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include "nbtool_config.h"
|
|
|
|
#endif
|
|
|
|
|
2003-06-23 17:05:47 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
2003-07-17 12:33:03 +04:00
|
|
|
#if defined(__RCSID) && !defined(lint)
|
2019-06-24 01:46:53 +03:00
|
|
|
__RCSID("$NetBSD: util.c,v 1.6 2019/06/23 22:46:53 christos Exp $");
|
2003-06-23 17:05:47 +04:00
|
|
|
#endif
|
|
|
|
|
1997-09-26 21:54:09 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
/* Error routine */
|
|
|
|
void
|
|
|
|
yyerror(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
2012-03-06 20:55:18 +04:00
|
|
|
va_start(args, fmt);
|
|
|
|
printf("%s:%d: ", src_name, line_no);
|
|
|
|
vfprintf(stdout, fmt, args);
|
|
|
|
printf("\n");
|
|
|
|
va_end(args);
|
1997-09-26 21:54:09 +04:00
|
|
|
had_errors = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Buffer routines */
|
|
|
|
static char *mc_buff = NULL;
|
|
|
|
static int mc_size = 0;
|
|
|
|
static int mc_loc = 0;
|
|
|
|
|
2012-03-06 20:55:18 +04:00
|
|
|
void
|
|
|
|
buff_add_ch(char ch)
|
1997-09-26 21:54:09 +04:00
|
|
|
{
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
if (mc_loc >= mc_size-1) {
|
|
|
|
if (mc_size == 0)
|
|
|
|
mc_size = 80;
|
|
|
|
else
|
|
|
|
mc_size *= 2;
|
2019-06-24 01:46:53 +03:00
|
|
|
t = malloc(mc_size);
|
1997-09-26 21:54:09 +04:00
|
|
|
if (t == NULL) {
|
2012-03-06 20:55:18 +04:00
|
|
|
(void)fprintf(stderr, "%s:%d: Malloc error\n",
|
1997-09-26 21:54:09 +04:00
|
|
|
src_name, line_no);
|
2012-03-06 20:55:18 +04:00
|
|
|
exit(1);
|
1997-09-26 21:54:09 +04:00
|
|
|
}
|
|
|
|
if (mc_buff != NULL) {
|
2012-03-06 20:55:18 +04:00
|
|
|
strcpy(t, mc_buff);
|
|
|
|
free(mc_buff);
|
1997-09-26 21:54:09 +04:00
|
|
|
}
|
|
|
|
mc_buff = t;
|
|
|
|
}
|
|
|
|
mc_buff[mc_loc++] = ch;
|
|
|
|
mc_buff[mc_loc] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get a copy of the string ! */
|
|
|
|
char *
|
2012-03-06 20:55:18 +04:00
|
|
|
buff_copy(void)
|
1997-09-26 21:54:09 +04:00
|
|
|
{
|
2012-03-06 20:55:18 +04:00
|
|
|
char *res = strdup(mc_buff);
|
|
|
|
|
1997-09-26 21:54:09 +04:00
|
|
|
mc_loc = 0;
|
|
|
|
mc_buff[0] = '\0';
|
2012-03-06 20:55:18 +04:00
|
|
|
return res;
|
1997-09-26 21:54:09 +04:00
|
|
|
}
|