From 35976a0ab0cfd8245f1e2fbdce6ba1530605998e Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Wed, 6 Dec 2000 08:47:11 +0000 Subject: [PATCH] Remove a bunch of macro definitions we don't use. Run lclint on t_com_err test case; tune options; more annotations. Use instead of duplicated definitions in generated files. Rebuild Perl versions of awk scripts for generating files. Dump K&R C support, assume C89/C++. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@12880 dc483132-0cff-0310-8789-dd5450dbe970 --- src/util/et/ChangeLog | 23 ++++++++++++ src/util/et/com_err.c | 17 ++------- src/util/et/com_err.h | 65 ++++++++++++--------------------- src/util/et/error_message.c | 10 +++--- src/util/et/error_table.h | 13 ++----- src/util/et/et_c.awk | 41 ++++++--------------- src/util/et/et_c.perl | 71 ++++++++++++------------------------- src/util/et/et_h.perl | 12 ++++--- src/util/et/t_com_err.c | 37 +++++++++---------- 9 files changed, 116 insertions(+), 173 deletions(-) diff --git a/src/util/et/ChangeLog b/src/util/et/ChangeLog index 6a8aad120..7dd0d4d35 100644 --- a/src/util/et/ChangeLog +++ b/src/util/et/ChangeLog @@ -1,5 +1,27 @@ 2000-12-05 Ken Raeburn + * et_c.awk: Don't generate macros we won't use. Assume ANSI C + prototypes. Include com_err.h in output file, rather than + duplicating declarations. + + * com_err.c: Assume ANSI C; drop conditional-prototype macros and + varargs.h support. + + * com_err.h: Get rid of old 68k-Mac pragmas. + (GSS_DLLIMP, KRB5_EXPORTVAR, HAVE_STDARG_H, ET_P, NEAR, + ET_STDARG_P, ET_VARARGS): Don't define. + (struct et_list, _et_list): Declare, with annotations. + * error_table.h (struct et_list, _et_list): Don't declare here. + + * error_message.c (_et_list): Annotate. + (error_message, add_error_table, remove_error_table): Check + 'table' field of et_list for null pointer. + + * t_com_err.c: Include string.h. + (try_one): Check strcmp value against zero explicitly. + (main): Annotate arguments as unused. Cast add_error_table and + remove_error_table return values to void. + * Makefile.in (clean-unix): Clean up lclint files too. (cleant-lclint): New target. (et1.c, et2.c, et1.h, et2.h, test1.c, test1.h, test2.h, test2.c): @@ -13,6 +35,7 @@ (rebuild, rebuild-c, rebuild-h): New targets: Rebuild perl versions of awk scripts. (clean-files): Get more generated files from test cases. + * et_c.perl, et_h.perl: Rebuilt. 2000-11-14 Ken Raeburn diff --git a/src/util/et/com_err.c b/src/util/et/com_err.c index 19a30a0b0..47f02047a 100644 --- a/src/util/et/com_err.c +++ b/src/util/et/com_err.c @@ -35,9 +35,8 @@ static void MacMessageBox(char *errbuf); static /*@null@*/ et_old_error_hook_func com_err_hook = 0; -static void default_com_err_proc -ET_P((const char FAR *whoami, errcode_t code, - const char FAR *fmt, va_list ap)); +static void default_com_err_proc (const char FAR *whoami, errcode_t code, + const char FAR *fmt, va_list ap); static void default_com_err_proc(whoami, code, fmt, ap) const char FAR *whoami; @@ -112,25 +111,13 @@ KRB5_DLLIMP void KRB5_CALLCONV com_err_va(whoami, code, fmt, ap) } -#ifndef ET_VARARGS KRB5_DLLIMP void KRB5_CALLCONV_C com_err(const char FAR *whoami, errcode_t code, const char FAR *fmt, ...) -#else -KRB5_DLLIMP void KRB5_CALLCONV_C com_err(whoami, code, fmt, va_alist) - const char FAR *whoami; - errcode_t code; - const char FAR *fmt; - va_dcl -#endif { va_list ap; -#ifdef ET_VARARGS - va_start(ap); -#else va_start(ap, fmt); -#endif com_err_va(whoami, code, fmt, ap); va_end(ap); } diff --git a/src/util/et/com_err.h b/src/util/et/com_err.h index 268ccf5ee..1ec2be1b6 100644 --- a/src/util/et/com_err.h +++ b/src/util/et/com_err.h @@ -14,49 +14,23 @@ #if defined(_MSDOS) || defined(_WIN32) || defined(macintosh) #include -#if defined(macintosh) && defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__) -#pragma import on -#endif #endif #ifndef KRB5_CALLCONV #define KRB5_CALLCONV #define KRB5_CALLCONV_C #define KRB5_DLLIMP -#define GSS_DLLIMP -#define KRB5_EXPORTVAR #endif #ifndef FAR #define FAR -#define NEAR -#endif - -#if defined(__STDC__) || defined(__cplusplus) || defined(_MSDOS) || defined(_WIN32) || defined(macintosh) - -/* End-user programs may need this -- oh well */ -#ifndef HAVE_STDARG_H -#define HAVE_STDARG_H 1 #endif -#define ET_P(x) x - -#else -#define ET_P(x) () -#endif /* __STDC__ */ - -#ifdef HAVE_STDARG_H #include -#define ET_STDARG_P(x) x -#else -#include -#define ET_STDARG_P(x) () -#define ET_VARARGS -#endif typedef long errcode_t; -typedef void (*et_old_error_hook_func) ET_P((const char FAR *, errcode_t, - const char FAR *, va_list ap)); +typedef void (*et_old_error_hook_func) (const char FAR *, errcode_t, + const char FAR *, va_list ap); struct error_table { /*@shared@*/ char const FAR * const FAR * msgs; @@ -64,22 +38,35 @@ struct error_table { unsigned int n_msgs; }; +/* These are for INTERNAL USE ONLY! Don't rely on them, we're trying + to eliminate them. They're currently used for some internal stuff + in generated files. */ +struct et_list { + /*@dependent@*//*@null@*/ struct et_list *next; + /*@dependent@*//*@null@*/ const struct error_table FAR *table; +}; +#if !defined(_MSDOS) && !defined(_WIN32) && !defined(macintosh) +/*@null@*//*@dependent@*/ extern struct et_list * _et_list; +#endif +/* end INTERNAL stuff */ + #ifdef __cplusplus extern "C" { #endif +/* Public interfaces */ KRB5_DLLIMP extern void KRB5_CALLCONV_C com_err - ET_STDARG_P((const char FAR *, errcode_t, const char FAR *, ...)); + (const char FAR *, errcode_t, const char FAR *, ...); KRB5_DLLIMP extern void KRB5_CALLCONV com_err_va - ET_P((const char FAR *whoami, errcode_t code, const char FAR *fmt, - va_list ap)); + (const char FAR *whoami, errcode_t code, const char FAR *fmt, + va_list ap); KRB5_DLLIMP extern /*@observer@*//*@dependent@*/ const char FAR * KRB5_CALLCONV error_message - ET_P((errcode_t)) + (errcode_t) /*@modifies internalState@*/; KRB5_DLLIMP extern errcode_t KRB5_CALLCONV add_error_table - ET_P((const struct error_table FAR *)); + (/*@dependent@*/ const struct error_table FAR *); KRB5_DLLIMP extern errcode_t KRB5_CALLCONV remove_error_table - ET_P((const struct error_table FAR *)); + (const struct error_table FAR *); #if !defined(_MSDOS) && !defined(_WIN32) && !defined(macintosh) /* @@ -88,19 +75,13 @@ KRB5_DLLIMP extern errcode_t KRB5_CALLCONV remove_error_table * applications under non-Unix environments. */ -extern et_old_error_hook_func set_com_err_hook - ET_P((et_old_error_hook_func)); -extern et_old_error_hook_func reset_com_err_hook - ET_P((void)); +extern et_old_error_hook_func set_com_err_hook (et_old_error_hook_func); +extern et_old_error_hook_func reset_com_err_hook (void); #endif #ifdef __cplusplus } #endif -#if defined(macintosh) && defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__) -#pragma import reset -#endif - #define __COM_ERR_H #endif /* ! defined(__COM_ERR_H) */ diff --git a/src/util/et/error_message.c b/src/util/et/error_message.c index 615530684..0c9ce1869 100644 --- a/src/util/et/error_message.c +++ b/src/util/et/error_message.c @@ -49,10 +49,10 @@ extern const int sys_nerr; static char buffer[ET_EBUFSIZ]; #if (defined(_MSDOS) || defined(_WIN32) || defined(macintosh)) -static struct et_list * _et_list = (struct et_list *) NULL; +/*@null@*/ static struct et_list * _et_list = (struct et_list *) NULL; #else /* Old interface compatibility */ -struct et_list * _et_list = (struct et_list *) NULL; +/*@null@*/ struct et_list * _et_list = (struct et_list *) NULL; #endif /*@null@*//*@only@*/static struct dynamic_et_list * et_list_dynamic; @@ -117,6 +117,8 @@ error_message(long code) dprintf (("scanning static list for %x\n", table_num)); for (et = _et_list; et != NULL; et = et->next) { + if (et->table == NULL) + continue; dprintf (("\t%x = %s\n", et->table->base & ERRCODE_MAX, et->table->msgs[0])); if ((et->table->base & ERRCODE_MAX) == table_num) { @@ -240,7 +242,7 @@ add_error_table(et) wouldn't check the dynamically maintained list before adding an entry to the static list. */ for (el = _et_list; el != NULL; el = el->next) - if (el->table->base == et->base) + if (el->table != NULL && el->table->base == et->base) return EEXIST; for (del = et_list_dynamic; del != NULL; del = del->next) if (del->table->base == et->base) @@ -286,7 +288,7 @@ remove_error_table(et) break; } for (el = &_et_list; *el; el = &(*el)->next) - if ((*el)->table->base == et->base) { + if ((*el)->table != NULL && (*el)->table->base == et->base) { struct et_list *old = *el; *el = old->next; old->next = NULL; diff --git a/src/util/et/error_table.h b/src/util/et/error_table.h index 3f48a8c2c..18bf67680 100644 --- a/src/util/et/error_table.h +++ b/src/util/et/error_table.h @@ -15,28 +15,19 @@ #define ET_EBUFSIZ 64 #endif -struct et_list { - /*@dependent@*//*@null@*/ struct et_list *next; - /*@dependent@*/ const struct error_table FAR *table; -}; - struct dynamic_et_list { /*@only@*//*@null@*/ struct dynamic_et_list *next; /*@dependent@*/ const struct error_table FAR *table; }; -#if !defined(_MSDOS) && !defined(_WIN32) && !defined(macintosh) -/*@null@*//*@dependent@*/ extern struct et_list * _et_list; -#endif - #define ERRCODE_RANGE 8 /* # of bits to shift table number */ #define BITS_PER_CHAR 6 /* # bits to shift per character in name */ #define ERRCODE_MAX 0xFFFFFFFFUL /* Mask for maximum error table */ -extern /*@observer@*/ const char FAR *error_table_name ET_P((unsigned long)) +extern /*@observer@*/ const char FAR *error_table_name (unsigned long) /*@modifies internalState@*/; extern const char FAR *error_table_name_r (unsigned long, - /*@out@*/ /*@returned@*/ char FAR *outbuf) + /*@out@*/ /*@returned@*/ char FAR *outbuf) /*@modifies outbuf@*/; #define _ET_H diff --git a/src/util/et/et_c.awk b/src/util/et/et_c.awk index 9c6a6cfa8..65396d443 100644 --- a/src/util/et/et_c.awk +++ b/src/util/et/et_c.awk @@ -110,31 +110,21 @@ c2n["_"]=63 print " */" > outfile print "#if defined(_MSDOS) || defined(_WIN32)" > outfile - print "#include \"win-mac.h\"" > outfile + print "# include \"win-mac.h\"" > outfile print "#else" > outfile - print "# ifndef KRB5_CALLCONV" > outfile - print "# define KRB5_CALLCONV" > outfile - print "# define KRB5_CALLCONV_C" > outfile - print "# define KRB5_DLLIMP" > outfile - print "# define KRB5_EXPORTVAR" > outfile print "# define FAR" > outfile - print "# define NEAR" > outfile - print "# endif" > outfile print "#endif" > outfile print "" > outfile - - print "#if defined(__STDC__) || defined(_MSDOS) || defined(_WIN32)" > outfile - print "#define P(x) x" > outfile - print "#define NOARGS void" > outfile - print "#else" > outfile - print "#define P(x) ()" > outfile - print "#define NOARGS" > outfile - print "#define const" > outfile - print "#endif" > outfile + print "extern void initialize_" table_name "_error_table (void);" > outfile print "" > outfile - print "extern void initialize_" table_name "_error_table (NOARGS);" > outfile + print "/* Lclint doesn't handle null annotations on arrays" > outfile + print " properly, so we need this typedef in each" > outfile + print " generated .c file. */" > outfile + print "/*@-redef@*/" > outfile + print "typedef /*@null@*/ const char FAR *ncptr;" > outfile + print "/*@=redef@*/" > outfile print "" > outfile - print "static const char FAR * const text[] = {" > outfile + print "static ncptr const text[] = {" > outfile table_item_count = 0 } @@ -197,11 +187,7 @@ END { print " 0" > outfile print "};" > outfile print "" > outfile - print "struct error_table {" > outfile - print " char const FAR * const FAR * msgs;" > outfile - print " long base;" > outfile - print " int n_msgs;" > outfile - print "};" > outfile + print "#include " > outfile print "" > outfile if (tab_base_high == 0) { print "const struct error_table et_" table_name "_error_table = { text, " \ @@ -214,13 +200,8 @@ END { } print "" > outfile print "#if !defined(_MSDOS) && !defined(_WIN32) && !defined(macintosh)" > outfile - print "struct et_list {" > outfile - print " struct et_list *next;" > outfile - print " const struct error_table * table;" > outfile - print "};" > outfile - print "extern struct et_list *_et_list;" > outfile print "static struct et_list link = { 0, 0 };" > outfile - print "void initialize_" table_name "_error_table (NOARGS) {" > outfile + print "void initialize_" table_name "_error_table (void) {" > outfile print " if (!link.table) {" > outfile print " link.next = _et_list;" > outfile print " link.table = &et_" table_name "_error_table;" > outfile diff --git a/src/util/et/et_c.perl b/src/util/et/et_c.perl index 6af71791f..8d7062b7a 100644 --- a/src/util/et/et_c.perl +++ b/src/util/et/et_c.perl @@ -1,5 +1,5 @@ -#!/afs/athena/contrib/perl5/p -eval 'exec /afs/athena/contrib/perl5/arch/sun4x_55/bin/perl -S $0 ${1+"$@"}' +#!/usr/athena/bin/perl +eval 'exec /usr/athena/bin/perl -S $0 ${1+"$@"}' if $running_under_some_shell; # this emulates #! processing on NIH machines. # (remove #! line above if indigestible) @@ -79,8 +79,8 @@ $c2n{'9'} = 62; $c2n{'_'} = 63; line: while (<>) { - chop; # strip record separator - @Fld = split(' ', $_, 9999); + chomp; # strip record separator + @Fld = split($FS, $_, 9999); if (/^#/) { next line; } @@ -139,48 +139,37 @@ line: while (<>) { &Pick('>', $outfile) && (print $fh '#if defined(_MSDOS) || defined(_WIN32)'); &Pick('>', $outfile) && - (print $fh "#include \"win-mac.h\""); + (print $fh "# include \"win-mac.h\""); &Pick('>', $outfile) && (print $fh '#else'); - &Pick('>', $outfile) && - (print $fh '# ifndef KRB5_CALLCONV'); - &Pick('>', $outfile) && - (print $fh '# define KRB5_CALLCONV'); - &Pick('>', $outfile) && - (print $fh '# define KRB5_CALLCONV_C'); - &Pick('>', $outfile) && - (print $fh '# define KRB5_DLLIMP'); - &Pick('>', $outfile) && - (print $fh '# define KRB5_EXPORTVAR'); &Pick('>', $outfile) && (print $fh '# define FAR'); - &Pick('>', $outfile) && - (print $fh '# define NEAR'); - &Pick('>', $outfile) && - (print $fh '# endif'); &Pick('>', $outfile) && (print $fh '#endif'); &Pick('>', $outfile) && (print $fh ''); - &Pick('>', $outfile) && - (print $fh + (print $fh 'extern void initialize_' . $table_name . - '#if defined(__STDC__) || defined(_MSDOS) || defined(_WIN32)'); + '_error_table (void);'); + &Pick('>', $outfile) && + (print $fh ''); &Pick('>', $outfile) && - (print $fh '#define P(x) x'); + (print $fh "/* Lclint doesn't handle null annotations on arrays"); &Pick('>', $outfile) && - (print $fh '#else'); + (print $fh ' properly, so we need this typedef in each'); &Pick('>', $outfile) && - (print $fh '#define P(x) ()'); + (print $fh ' generated .c file. */'); &Pick('>', $outfile) && - (print $fh '#define const'); + (print $fh '/*@-redef@*/'); &Pick('>', $outfile) && - (print $fh '#endif'); + (print $fh 'typedef /*@null@*/ const char FAR *ncptr;'); + &Pick('>', $outfile) && + (print $fh '/*@=redef@*/'); &Pick('>', $outfile) && (print $fh ''); &Pick('>', $outfile) && - (print $fh 'static const char FAR * const text[] = {'); + (print $fh 'static ncptr const text[] = {'); $table_item_count = 0; } @@ -249,15 +238,7 @@ line: while (<>) { &Pick('>', $outfile) && (print $fh ''); &Pick('>', $outfile) && - (print $fh 'struct error_table {'); -&Pick('>', $outfile) && - (print $fh ' char const FAR * const FAR * msgs;'); -&Pick('>', $outfile) && - (print $fh ' long base;'); -&Pick('>', $outfile) && - (print $fh ' int n_msgs;'); -&Pick('>', $outfile) && - (print $fh '};'); + (print $fh '#include '); &Pick('>', $outfile) && (print $fh ''); if ($tab_base_high == 0) { @@ -279,21 +260,13 @@ else { &Pick('>', $outfile) && (print $fh ''); &Pick('>', $outfile) && - (print $fh '#if defined(unix) || defined(_AIX)'); -&Pick('>', $outfile) && - (print $fh 'struct et_list {'); -&Pick('>', $outfile) && - (print $fh ' struct et_list *next;'); -&Pick('>', $outfile) && - (print $fh ' const struct error_table * table;'); -&Pick('>', $outfile) && - (print $fh '};'); -&Pick('>', $outfile) && - (print $fh 'extern struct et_list *_et_list;'); + (print $fh + + '#if !defined(_MSDOS) && !defined(_WIN32) && !defined(macintosh)'); &Pick('>', $outfile) && (print $fh 'static struct et_list link = { 0, 0 };'); &Pick('>', $outfile) && - (print $fh 'void initialize_' . $table_name . '_error_table (NOARGS) {'); + (print $fh 'void initialize_' . $table_name . '_error_table (void) {'); &Pick('>', $outfile) && (print $fh ' if (!link.table) {'); &Pick('>', $outfile) && diff --git a/src/util/et/et_h.perl b/src/util/et/et_h.perl index b477faf5d..0b2ee1f23 100644 --- a/src/util/et/et_h.perl +++ b/src/util/et/et_h.perl @@ -1,5 +1,5 @@ -#!/afs/athena/contrib/perl5/p -eval 'exec /afs/athena/contrib/perl5/arch/sun4x_55/bin/perl -S $0 ${1+"$@"}' +#!/usr/athena/bin/perl +eval 'exec /usr/athena/bin/perl -S $0 ${1+"$@"}' if $running_under_some_shell; # this emulates #! processing on NIH machines. # (remove #! line above if indigestible) @@ -192,11 +192,15 @@ else { &Pick('>', $outfile) && (print $fh ''); &Pick('>', $outfile) && - (print $fh '#if defined(unix) || defined(_AIX)'); + (print $fh + + '#if !defined(_MSDOS) && !defined(_WIN32) && !defined(macintosh)'); &Pick('>', $outfile) && (print $fh '/* for compatibility with older versions... */'); &Pick('>', $outfile) && - (print $fh 'extern void initialize_' . $table_name . '_error_table ();'); + (print $fh 'extern void initialize_' . $table_name . + + '_error_table () /*@modifies internalState@*/;'); &Pick('>', $outfile) && (print $fh '#define init_' . $table_name . '_err_tbl initialize_' . diff --git a/src/util/et/t_com_err.c b/src/util/et/t_com_err.c index d3ed26057..f86c31797 100644 --- a/src/util/et/t_com_err.c +++ b/src/util/et/t_com_err.c @@ -1,4 +1,5 @@ #include +#include #include "com_err.h" #include "et1.h" #include "et2.h" @@ -14,7 +15,7 @@ try_one (errcode_t code, int known, int table, int msgno) char buffy[1024]; sprintf (buffy, "error table %d message %d", table, msgno); - if (!strcmp (buffy, msg)) { + if (0 == strcmp (buffy, msg)) { if (!known) { known_err++; } @@ -58,49 +59,49 @@ try_em_1 (int t1_known, int t2_known, int lineno) } #define try_em(A,B) try_em_1(A,B,__LINE__) -int main (int argc, char *argv[]) +int main (/*@unused@*/ int argc, /*@unused@*/ char *argv[]) { try_em (0, 0); - add_error_table (&et_et1_error_table); + (void) add_error_table (&et_et1_error_table); try_em (1, 0); - add_error_table (&et_et2_error_table); + (void) add_error_table (&et_et2_error_table); try_em (1, 1); - remove_error_table (&et_et1_error_table); + (void) remove_error_table (&et_et1_error_table); try_em (0, 1); - remove_error_table (&et_et1_error_table); + (void) remove_error_table (&et_et1_error_table); try_em (0, 1); - remove_error_table (&et_et2_error_table); + (void) remove_error_table (&et_et2_error_table); try_em (0, 0); initialize_et1_error_table (); try_em (1, 0); - add_error_table (&et_et1_error_table); + (void) add_error_table (&et_et1_error_table); try_em (1, 0); - remove_error_table (&et_et1_error_table); + (void) remove_error_table (&et_et1_error_table); try_em (0, 0); initialize_et1_error_table (); try_em (1, 0); - add_error_table (&et_et1_error_table); + (void) add_error_table (&et_et1_error_table); try_em (1, 0); - add_error_table (&et_et2_error_table); + (void) add_error_table (&et_et2_error_table); try_em (1, 1); - remove_error_table (&et_et1_error_table); + (void) remove_error_table (&et_et1_error_table); try_em (0, 1); - remove_error_table (&et_et2_error_table); + (void) remove_error_table (&et_et2_error_table); try_em (0, 0); - remove_error_table (&et_et2_error_table); + (void) remove_error_table (&et_et2_error_table); try_em (0, 0); - add_error_table (&et_et2_error_table); + (void) add_error_table (&et_et2_error_table); try_em (0, 1); initialize_et2_error_table (); try_em (0, 1); - add_error_table (&et_et1_error_table); + (void) add_error_table (&et_et1_error_table); try_em (1, 1); - remove_error_table (&et_et1_error_table); + (void) remove_error_table (&et_et1_error_table); try_em (0, 1); - remove_error_table (&et_et2_error_table); + (void) remove_error_table (&et_et2_error_table); try_em (0, 0); return fail; -- 2.26.2