Merge from the vendor branch and resolve conflicts.

This commit is contained in:
Doug Rabson 2008-05-08 11:01:46 +00:00
parent 5f06c5bb28
commit 5768032947
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=178846
7 changed files with 54 additions and 46 deletions

View File

@ -34,7 +34,7 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
RCSID("$Id: com_err.c,v 1.18 2002/03/10 23:07:01 assar Exp $"); RCSID("$Id: com_err.c 14930 2005-04-24 19:43:06Z lha $");
#endif #endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -51,15 +51,14 @@ error_message (long code)
const char *p = com_right(_et_list, code); const char *p = com_right(_et_list, code);
if (p == NULL) { if (p == NULL) {
if (code < 0) if (code < 0)
sprintf(msg, "Unknown error %ld", code); snprintf(msg, sizeof(msg), "Unknown error %ld", code);
else else
p = strerror(code); p = strerror(code);
} }
if (p != NULL && *p != '\0') { if (p != NULL && *p != '\0') {
strncpy(msg, p, sizeof(msg) - 1); strlcpy(msg, p, sizeof(msg));
msg[sizeof(msg) - 1] = 0;
} else } else
sprintf(msg, "Unknown error %ld", code); snprintf(msg, sizeof(msg), "Unknown error %ld", code);
return msg; return msg;
} }

View File

@ -32,7 +32,7 @@
*/ */
/* $FreeBSD$ */ /* $FreeBSD$ */
/* $Id: com_err.h,v 1.9 2001/05/11 20:03:36 assar Exp $ */ /* $Id: com_err.h 15566 2005-07-07 14:58:07Z lha $ */
/* MIT compatible com_err library */ /* MIT compatible com_err library */
@ -43,11 +43,12 @@
#include <stdarg.h> #include <stdarg.h>
#include <com_right.h> #include <com_right.h>
#include <stdarg.h>
typedef void (*errf) __P((const char *, long, const char *, va_list)); typedef void (*errf) __P((const char *, long, const char *, va_list));
const char * error_message __P((long)); const char * error_message (long);
int init_error_table __P((const char**, long, int)); int init_error_table (const char**, long, int);
void com_err_va __P((const char *, long, const char *, va_list)) void com_err_va __P((const char *, long, const char *, va_list))
__printflike(3, 0); __printflike(3, 0);
@ -55,11 +56,11 @@ void com_err_va __P((const char *, long, const char *, va_list))
void com_err __P((const char *, long, const char *, ...)) void com_err __P((const char *, long, const char *, ...))
__printflike(3, 4); __printflike(3, 4);
errf set_com_err_hook __P((errf)); errf set_com_err_hook (errf);
errf reset_com_err_hook __P((void)); errf reset_com_err_hook (void);
const char *error_table_name __P((int num)); const char *error_table_name (int num);
void add_to_error_table __P((struct et_list *new_table)); void add_to_error_table (struct et_list *new_table);
#endif /* __COM_ERR_H__ */ #endif /* __COM_ERR_H__ */

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
/* $Id: com_right.h,v 1.11 2000/07/31 01:11:08 assar Exp $ */ /* $Id: com_right.h 14551 2005-02-03 08:45:13Z lha $ */
/* $FreeBSD$ */ /* $FreeBSD$ */
#ifndef __COM_RIGHT_H__ #ifndef __COM_RIGHT_H__
@ -51,8 +51,8 @@ struct et_list {
}; };
extern struct et_list *_et_list; extern struct et_list *_et_list;
const char *com_right __P((struct et_list *list, long code)); const char *com_right (struct et_list *list, long code);
void initialize_error_table_r __P((struct et_list **, const char **, int, long)); void initialize_error_table_r (struct et_list **, const char **, int, long);
void free_error_table __P((struct et_list *)); void free_error_table (struct et_list *);
#endif /* __COM_RIGHT_H__ */ #endif /* __COM_RIGHT_H__ */

View File

@ -37,7 +37,7 @@
#include <getarg.h> #include <getarg.h>
#if 0 #if 0
RCSID("$Id: compile_et.c,v 1.16 2002/08/20 12:44:51 joda Exp $"); RCSID("$Id: compile_et.c 15426 2005-06-16 19:21:42Z lha $");
#endif #endif
#include <err.h> #include <err.h>
@ -48,7 +48,7 @@ extern FILE *yyin;
extern void yyparse(void); extern void yyparse(void);
long base; long base_id;
int number; int number;
char *prefix; char *prefix;
char *id_str; char *id_str;
@ -158,13 +158,13 @@ generate_h(void)
fprintf(h_file, "typedef enum %s_error_number{\n", name); fprintf(h_file, "typedef enum %s_error_number{\n", name);
for(ec = codes; ec; ec = ec->next) { for(ec = codes; ec; ec = ec->next) {
fprintf(h_file, "\t%s = %ld%s\n", ec->name, base + ec->number, fprintf(h_file, "\t%s = %ld%s\n", ec->name, base_id + ec->number,
(ec->next != NULL) ? "," : ""); (ec->next != NULL) ? "," : "");
} }
fprintf(h_file, "} %s_error_number;\n", name); fprintf(h_file, "} %s_error_number;\n", name);
fprintf(h_file, "\n"); fprintf(h_file, "\n");
fprintf(h_file, "#define ERROR_TABLE_BASE_%s %ld\n", name, base); fprintf(h_file, "#define ERROR_TABLE_BASE_%s %ld\n", name, base_id);
fprintf(h_file, "\n"); fprintf(h_file, "\n");
fprintf(h_file, "#endif /* %s */\n", fn); fprintf(h_file, "#endif /* %s */\n", fn);
@ -196,17 +196,17 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
char *p; char *p;
int optind = 0; int optidx = 0;
setprogname(argv[0]); setprogname(argv[0]);
if(getarg(args, num_args, argc, argv, &optind)) if(getarg(args, num_args, argc, argv, &optidx))
usage(1); usage(1);
if(help_flag) if(help_flag)
usage(0); usage(0);
if(optind == argc) if(optidx == argc)
usage(1); usage(1);
filename = argv[optind]; filename = argv[optidx];
yyin = fopen(filename, "r"); yyin = fopen(filename, "r");
if(yyin == NULL) if(yyin == NULL)
err(1, "%s", filename); err(1, "%s", filename);
@ -217,8 +217,7 @@ main(int argc, char **argv)
p++; p++;
else else
p = filename; p = filename;
strncpy(Basename, p, sizeof(Basename)); strlcpy(Basename, p, sizeof(Basename));
Basename[sizeof(Basename) - 1] = '\0';
Basename[strcspn(Basename, ".")] = '\0'; Basename[strcspn(Basename, ".")] = '\0';

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
/* $Id: compile_et.h,v 1.6 2000/07/01 20:21:48 assar Exp $ */ /* $Id: compile_et.h 15426 2005-06-16 19:21:42Z lha $ */
/* $FreeBSD$ */ /* $FreeBSD$ */
#ifndef __COMPILE_ET_H__ #ifndef __COMPILE_ET_H__
@ -41,13 +41,14 @@
#include <config.h> #include <config.h>
#endif #endif
#include <err.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <ctype.h> #include <ctype.h>
extern long base; extern long base_id;
extern int number; extern int number;
extern char *prefix; extern char *prefix;
extern char name[128]; extern char name[128];

View File

@ -46,7 +46,7 @@
#include "lex.h" #include "lex.h"
#if 0 #if 0
RCSID("$Id: lex.l,v 1.6 2000/06/22 00:42:52 assar Exp $"); RCSID("$Id: lex.l 15143 2005-05-16 08:52:54Z lha $");
#endif #endif
static unsigned lineno = 1; static unsigned lineno = 1;
@ -92,7 +92,7 @@ getstring(void)
int i = 0; int i = 0;
int c; int c;
int quote = 0; int quote = 0;
while((c = input()) != EOF){ while(i < sizeof(x) - 1 && (c = input()) != EOF){
if(quote) { if(quote) {
x[i++] = c; x[i++] = c;
quote = 0; quote = 0;
@ -113,6 +113,8 @@ getstring(void)
} }
x[i] = '\0'; x[i] = '\0';
yylval.string = strdup(x); yylval.string = strdup(x);
if (yylval.string == NULL)
err(1, "malloc");
return STRING; return STRING;
} }

View File

@ -36,7 +36,7 @@
#include "compile_et.h" #include "compile_et.h"
#include "lex.h" #include "lex.h"
#if 0 #if 0
RCSID("$Id: parse.y,v 1.11 2000/06/22 00:42:52 assar Exp $"); RCSID("$Id: parse.y 15426 2005-06-16 19:21:42Z lha $");
#endif #endif
void yyerror (char *s); void yyerror (char *s);
@ -79,16 +79,14 @@ id : ID STRING
et : ET STRING et : ET STRING
{ {
base = name2number($2); base_id = name2number($2);
strncpy(name, $2, sizeof(name)); strlcpy(name, $2, sizeof(name));
name[sizeof(name) - 1] = '\0';
free($2); free($2);
} }
| ET STRING STRING | ET STRING STRING
{ {
base = name2number($2); base_id = name2number($2);
strncpy(name, $3, sizeof(name)); strlcpy(name, $3, sizeof(name));
name[sizeof(name) - 1] = '\0';
free($2); free($2);
free($3); free($3);
} }
@ -104,24 +102,32 @@ statement : INDEX NUMBER
} }
| PREFIX STRING | PREFIX STRING
{ {
prefix = realloc(prefix, strlen($2) + 2); free(prefix);
strcpy(prefix, $2); asprintf (&prefix, "%s_", $2);
strcat(prefix, "_"); if (prefix == NULL)
errx(1, "malloc");
free($2); free($2);
} }
| PREFIX | PREFIX
{ {
prefix = realloc(prefix, 1); prefix = realloc(prefix, 1);
if (prefix == NULL)
errx(1, "malloc");
*prefix = '\0'; *prefix = '\0';
} }
| EC STRING ',' STRING | EC STRING ',' STRING
{ {
struct error_code *ec = malloc(sizeof(*ec)); struct error_code *ec = malloc(sizeof(*ec));
if (ec == NULL)
errx(1, "malloc");
ec->next = NULL; ec->next = NULL;
ec->number = number; ec->number = number;
if(prefix && *prefix != '\0') { if(prefix && *prefix != '\0') {
asprintf (&ec->name, "%s%s", prefix, $2); asprintf (&ec->name, "%s%s", prefix, $2);
if (ec->name == NULL)
errx(1, "malloc");
free($2); free($2);
} else } else
ec->name = $2; ec->name = $2;
@ -141,7 +147,7 @@ static long
name2number(const char *str) name2number(const char *str)
{ {
const char *p; const char *p;
long base = 0; long num = 0;
const char *x = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" const char *x = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz0123456789_"; "abcdefghijklmnopqrstuvwxyz0123456789_";
if(strlen(str) > 4) { if(strlen(str) > 4) {
@ -154,12 +160,12 @@ name2number(const char *str)
yyerror("invalid character in table name"); yyerror("invalid character in table name");
return 0; return 0;
} }
base = (base << 6) + (q - x) + 1; num = (num << 6) + (q - x) + 1;
} }
base <<= 8; num <<= 8;
if(base > 0x7fffffff) if(num > 0x7fffffff)
base = -(0xffffffff - base + 1); num = -(0xffffffff - num + 1);
return base; return num;
} }
void void