1 /* $NetBSD: util.c,v 1.1.1.1 1997/09/26 17:54:09 phil Exp $ */ 2 3 /* 4 * Copyright 1997 Piermont Information Systems Inc. 5 * All rights reserved. 6 * 7 * Written by Philip A. Nelson for Piermont Information Systems Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software develooped for the NetBSD Project by 20 * Piermont Information Systems Inc. 21 * 4. The name of Piermont Information Systems Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS'' 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE 29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 35 * THE POSSIBILITY OF SUCH DAMAGE. 36 * 37 */ 38 39 /* util.c - utility routines. */ 40 41 #include <stdio.h> 42 #include <stdlib.h> 43 #include <string.h> 44 #include <stdarg.h> 45 #include "defs.h" 46 47 /* Error routine */ 48 void 49 yyerror(const char *fmt, ...) 50 { 51 va_list args; 52 53 va_start (args, fmt); 54 printf ("%s:%d: ", src_name, line_no); 55 vfprintf (stdout, fmt, args); 56 printf ("\n"); 57 va_end (args); 58 had_errors = TRUE; 59 } 60 61 62 /* Buffer routines */ 63 static char *mc_buff = NULL; 64 static int mc_size = 0; 65 static int mc_loc = 0; 66 67 void buff_add_ch (char ch) 68 { 69 char *t; 70 71 if (mc_loc >= mc_size-1) { 72 if (mc_size == 0) 73 mc_size = 80; 74 else 75 mc_size *= 2; 76 t = (char *) malloc (mc_size); 77 if (t == NULL) { 78 (void) fprintf (stderr, "%s:%d: Malloc error\n", 79 src_name, line_no); 80 exit (1); 81 } 82 if (mc_buff != NULL) { 83 strcpy (t, mc_buff); 84 free (mc_buff); 85 } 86 mc_buff = t; 87 } 88 mc_buff[mc_loc++] = ch; 89 mc_buff[mc_loc] = '\0'; 90 } 91 92 /* get a copy of the string ! */ 93 94 char * 95 buff_copy (void) 96 { 97 char *res = strdup (mc_buff); 98 mc_loc = 0; 99 mc_buff[0] = '\0'; 100 return res; 101 } 102