mirror of
https://github.com/ascii-boxes/boxes.git
synced 2025-06-18 15:56:39 +02:00
Applied Joe Zbiciak's patches to remove all snprintf()s and variants
Added concat_strings() function and changed yyerror() in the process
This commit is contained in:
parent
2535f9f8f5
commit
b84e9ed503
81
src/tools.c
81
src/tools.c
@ -4,7 +4,7 @@
|
|||||||
* Date created: June 20, 1999 (Sunday, 16:51h)
|
* Date created: June 20, 1999 (Sunday, 16:51h)
|
||||||
* Author: Copyright (C) 1999 Thomas Jensen
|
* Author: Copyright (C) 1999 Thomas Jensen
|
||||||
* tsjensen@stud.informatik.uni-erlangen.de
|
* tsjensen@stud.informatik.uni-erlangen.de
|
||||||
* Version: $Id: tools.c,v 1.3 1999/08/13 23:54:24 tsjensen Exp tsjensen $
|
* Version: $Id: tools.c,v 1.4 1999/08/21 16:09:33 tsjensen Exp tsjensen $
|
||||||
* Language: ANSI C
|
* Language: ANSI C
|
||||||
* World Wide Web: http://home.pages.de/~jensen/boxes/
|
* World Wide Web: http://home.pages.de/~jensen/boxes/
|
||||||
* Purpose: Provide tool functions for error reporting and some
|
* Purpose: Provide tool functions for error reporting and some
|
||||||
@ -26,6 +26,9 @@
|
|||||||
* Revision History:
|
* Revision History:
|
||||||
*
|
*
|
||||||
* $Log: tools.c,v $
|
* $Log: tools.c,v $
|
||||||
|
* Revision 1.4 1999/08/21 16:09:33 tsjensen
|
||||||
|
* Removed newline check from empty_line() function
|
||||||
|
*
|
||||||
* Revision 1.3 1999/08/13 23:54:24 tsjensen
|
* Revision 1.3 1999/08/13 23:54:24 tsjensen
|
||||||
* Bugfix: cut&paste error in in strisyes() and strisno(). Thanks Warren Seltzer
|
* Bugfix: cut&paste error in in strisyes() and strisno(). Thanks Warren Seltzer
|
||||||
*
|
*
|
||||||
@ -52,7 +55,7 @@
|
|||||||
|
|
||||||
|
|
||||||
static const char rcsid_tools_c[] =
|
static const char rcsid_tools_c[] =
|
||||||
"$Id: tools.c,v 1.3 1999/08/13 23:54:24 tsjensen Exp tsjensen $";
|
"$Id: tools.c,v 1.4 1999/08/21 16:09:33 tsjensen Exp tsjensen $";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -64,14 +67,14 @@ int yyerror (const char *fmt, ...)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
char buf[1024];
|
|
||||||
|
|
||||||
va_start (ap, fmt);
|
va_start (ap, fmt);
|
||||||
snprintf (buf, 1024-1, "%s: %s: line %d: ", PROJECT,
|
|
||||||
|
fprintf (stderr, "%s: %s: line %d: ", PROJECT,
|
||||||
yyfilename? yyfilename: "(null)", yylineno);
|
yyfilename? yyfilename: "(null)", yylineno);
|
||||||
vsnprintf (buf+strlen(buf), 1024-strlen(buf)-1, fmt, ap);
|
vfprintf (stderr, fmt, ap);
|
||||||
strcat (buf, "\n");
|
fputc ('\n', stderr);
|
||||||
fprintf (stderr, buf);
|
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -157,6 +160,70 @@ int strisno (const char *s)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void concat_strings (char *dst, int max_len, int count, ...)
|
||||||
|
/*
|
||||||
|
* Concatenate a variable number of strings into a fixed-length buffer.
|
||||||
|
*
|
||||||
|
* dst Destination array
|
||||||
|
* max_len Maximum resulting string length (including terminating NULL).
|
||||||
|
* count Number of source strings.
|
||||||
|
*
|
||||||
|
* The concatenation process terminates when either the destination
|
||||||
|
* buffer is full or all 'count' strings are processed. Null string
|
||||||
|
* pointers are treated as empty strings.
|
||||||
|
*
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
va_list va;
|
||||||
|
const char *src;
|
||||||
|
|
||||||
|
va_start (va, count);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sanity check.
|
||||||
|
*/
|
||||||
|
if (max_len < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (max_len == 1 || count < 1) {
|
||||||
|
*dst = '\0';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Loop over all input strings.
|
||||||
|
*/
|
||||||
|
while (count-->0 && max_len > 1) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Grab an input string pointer. If it's NULL, skip it (eg. treat
|
||||||
|
* it as empty.
|
||||||
|
*/
|
||||||
|
src = va_arg (va, const char *);
|
||||||
|
|
||||||
|
if (src == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Concatenate 'src' onto 'dst', as long as we have room.
|
||||||
|
*/
|
||||||
|
while (*src && max_len > 1) {
|
||||||
|
*dst++ = *src++;
|
||||||
|
max_len--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
va_end (va);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Terminate the string with an ASCII NUL.
|
||||||
|
*/
|
||||||
|
*dst = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int empty_line (const line_t *line)
|
int empty_line (const line_t *line)
|
||||||
/*
|
/*
|
||||||
* Return true if line is empty.
|
* Return true if line is empty.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user