diff options
author | Guy Harris <guy@alum.mit.edu> | 1998-10-13 07:03:37 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 1998-10-13 07:03:37 +0000 |
commit | d0b809aa7421d0b6c265084a51cbf9fdc9159b8b (patch) | |
tree | 1bcdb1dc35bf75e65d5d8a1587d105e74a4cfc1e | |
parent | d9850d803f8a4c155bd919f5ca7a991bd8e0e8c9 (diff) |
Squelch a number of "-Wall" errors by:
1) renaming "snprintf.h" to "snprintf-imp.h" (it contains stuff
used by the "snprintf()" *implementation*, but not stuff it
*exports*);
2) creating a new "snprintf.h" to declare "vsnprintf()" and
"snprintf()";
3) removing an unused variable;
4) fixing a call to "add_item_to_tree()" to handle the
possibility of "ntohl()" returning a "long" rather than an
"int".
svn path=/trunk/; revision=47
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | Makefile.in | 3 | ||||
-rw-r--r-- | capture.c | 8 | ||||
-rw-r--r-- | file.c | 7 | ||||
-rw-r--r-- | filter.c | 5 | ||||
-rw-r--r-- | packet-ospf.c | 4 | ||||
-rw-r--r-- | snprintf-imp.h | 232 | ||||
-rw-r--r-- | snprintf.c | 1 | ||||
-rw-r--r-- | snprintf.h | 233 | ||||
-rw-r--r-- | util.c | 11 |
10 files changed, 269 insertions, 238 deletions
diff --git a/Makefile.am b/Makefile.am index 9f4e6a3a12..bda65d5e71 100644 --- a/Makefile.am +++ b/Makefile.am @@ -63,7 +63,8 @@ ethereal_SOURCES = \ EXTRA_ethereal_SOURCES = \ snprintf.c \ - snprintf.h + snprintf.h \ + snprintf-imp.h ethereal_DEPENDENCIES = @SNPRINTF_O@ ethereal_LDADD = @SNPRINTF_O@ diff --git a/Makefile.in b/Makefile.in index 385ef0446e..1aa2622386 100644 --- a/Makefile.in +++ b/Makefile.in @@ -135,7 +135,8 @@ ethereal_SOURCES = \ EXTRA_ethereal_SOURCES = \ snprintf.c \ - snprintf.h + snprintf.h \ + snprintf-imp.h ethereal_DEPENDENCIES = @SNPRINTF_O@ ethereal_LDADD = @SNPRINTF_O@ @@ -1,7 +1,7 @@ /* capture.c * Routines for packet capture windows * - * $Id: capture.c,v 1.6 1998/10/12 01:40:43 gerald Exp $ + * $Id: capture.c,v 1.7 1998/10/13 07:03:31 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -36,11 +36,17 @@ #include <pcap.h> #include <string.h> +#include <unistd.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <net/if.h> #ifdef NEED_SNPRINTF_H +# ifdef HAVE_STDARG_H +# include <stdarg.h> +# else +# include <varargs.h> +# endif # include "snprintf.h" #endif @@ -1,7 +1,7 @@ /* file.c * File I/O routines * - * $Id: file.c,v 1.9 1998/10/13 02:10:54 gerald Exp $ + * $Id: file.c,v 1.10 1998/10/13 07:03:32 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -37,6 +37,11 @@ #include <errno.h> #ifdef NEED_SNPRINTF_H +# ifdef HAVE_STDARG_H +# include <stdarg.h> +# else +# include <varargs.h> +# endif # include "snprintf.h" #endif @@ -1,7 +1,7 @@ /* filter.c * Routines for managing filter sets * - * $Id: filter.c,v 1.6 1998/10/13 02:10:55 gerald Exp $ + * $Id: filter.c,v 1.7 1998/10/13 07:03:33 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -429,8 +429,7 @@ filter_prefs_save(GtkWidget *w) { void filter_prefs_cancel(GtkWidget *w) { - filter_def *filt; - + /* Let the list cb know we're about to destroy the widget tree, so it */ /* doesn't operate on widgets that don't exist. */ gtk_object_set_data(GTK_OBJECT(w), E_FILT_CM_KEY, (gpointer)TRUE); diff --git a/packet-ospf.c b/packet-ospf.c index 73469fd021..2e45507a75 100644 --- a/packet-ospf.c +++ b/packet-ospf.c @@ -2,7 +2,7 @@ * Routines for OSPF packet disassembly * (c) Copyright Hannes R. Boehm <hannes@boehm.org> * - * $Id: packet-ospf.c,v 1.5 1998/10/10 03:32:13 gerald Exp $ + * $Id: packet-ospf.c,v 1.6 1998/10/13 07:03:34 guy Exp $ * * At this time, this module is able to analyze OSPF * packets as specified in RFC2328. MOSPF (RFC1584) and other @@ -570,7 +570,7 @@ dissect_ospf_lsa(const u_char *pd, int offset, frame_data *fd, GtkTree *tree, in add_item_to_tree(ospf_lsa_tree, offset + 5, 3,"Metric: %d", asext_metric); add_item_to_tree(ospf_lsa_tree, offset + 8, 4,"Forwarding Address: %s", ip_to_str((guint8 *) &(asext_lsa.gateway))); - add_item_to_tree(ospf_lsa_tree, offset + 12, 4,"External Route Tag: %d", ntohl(asext_lsa.external_tag)); + add_item_to_tree(ospf_lsa_tree, offset + 12, 4,"External Route Tag: %ld", (long)ntohl(asext_lsa.external_tag)); break; default: diff --git a/snprintf-imp.h b/snprintf-imp.h new file mode 100644 index 0000000000..245739541e --- /dev/null +++ b/snprintf-imp.h @@ -0,0 +1,232 @@ +/* + Unix snprintf implementation. + Version 1.2 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + It can be redistribute also under the terms of GNU Library General + Public Lincense. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + Revision History: + + 1.2: + * put under LGPL. + 1.1: + * added changes from Miles Bader + * corrected a bug with %f + * added support for %#g + * added more comments :-) + 1.0: + * supporting must ANSI syntaxic_sugars(see below) + 0.0: + * suppot %s %c %d + + it understands: + Integer: + %lu %lu %u + %hd %ld %d decimal + %ho %lo %o octal + %hx %lx %x %X hexa + Floating points: + %g %G %e %E %f double + Strings: + %s %c string + %% % + + Formating conversion flags: + - justify left + + Justify right or put a plus if number + # prefix 0x, 0X for hexa and 0 for octal + * precision/witdth is specify as an (int) in the arguments + ' ' leave a blank for number with no sign + l the later should be a long + h the later should be a short + +format: + snprintf(holder, sizeof_holder, format, ...) + +Return values: + (sizeof_holder - 1) + + + THANKS(for the patches and ideas): + Miles Bader + Cyrille Rustom + Jacek Slabocewiz + Mike Parker(mouse) + +Alain Magloire: alainm@rcsm.ee.mcgill.ca +*/ + +#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__ +#include <stdarg.h> +#else +#include <varargs.h> +#endif + +#include <stdlib.h> /* for atoi() */ +#include <ctype.h> + + +/* + * For the FLOATING POINT FORMAT : + * the challenge was finding a way to + * manipulate the Real numbers without having + * to resort to mathematical function(it + * would require to link with -lm) and not + * going down to the bit pattern(not portable) + * + * so a number, a real is: + + real = integral + fraction + + integral = ... + a(2)*10^2 + a(1)*10^1 + a(0)*10^0 + fraction = b(1)*10^-1 + b(2)*10^-2 + ... + + where: + 0 <= a(i) => 9 + 0 <= b(i) => 9 + + from then it was simple math + */ + +/* + * size of the buffer for the integral part + * and the fraction part + */ +#define MAX_INT 99 + 1 /* 1 for the null */ +#define MAX_FRACT 29 + 1 + +/* + * numtoa() uses PRIVATE buffers to store the results, + * So this function is not reentrant + */ +#define itoa(n) numtoa(n, 10, 0, (char **)0) +#define otoa(n) numtoa(n, 8, 0, (char **)0) +#define htoa(n) numtoa(n, 16, 0, (char **)0) +#define dtoa(n, p, f) numtoa(n, 10, p, f) + +#define SWAP_INT(a,b) {int t; t = (a); (a) = (b); (b) = t;} + +/* this struct holds everything we need */ +struct DATA { + int length; + char *holder; + int counter; +#ifdef __STDC__ + const char *pf; +#else + char *pf; +#endif +/* FLAGS */ + int width, precision; + int justify; char pad; + int square, space, star_w, star_p, a_long ; +}; + +#define PRIVATE static +#define PUBLIC +/* signature of the functions */ +#ifdef __STDC__ +/* the floating point stuff */ + PRIVATE double pow_10(int); + PRIVATE int log_10(double); + PRIVATE double integral(double, double *); + PRIVATE char * numtoa(double, int, int, char **); + +/* for the format */ + PRIVATE void conv_flag(char *, struct DATA *); + PRIVATE void floating(struct DATA *, double); + PRIVATE void exponent(struct DATA *, double); + PRIVATE void decimal(struct DATA *, double); + PRIVATE void octal(struct DATA *, double); + PRIVATE void hexa(struct DATA *, double); + PRIVATE void strings(struct DATA *, char *); + +#else +/* the floating point stuff */ + PRIVATE double pow_10(); + PRIVATE int log_10(); + PRIVATE double integral(); + PRIVATE char * numtoa(); + +/* for the format */ + PRIVATE void conv_flag(); + PRIVATE void floating(); + PRIVATE void exponent(); + PRIVATE void decimal(); + PRIVATE void octal(); + PRIVATE void hexa(); + PRIVATE void strings(); +#endif + +/* those are defines specific to snprintf to hopefully + * make the code clearer :-) + */ +#define RIGHT 1 +#define LEFT 0 +#define NOT_FOUND -1 +#define FOUND 1 +#define MAX_FIELD 15 + +/* the conversion flags */ +#define isflag(c) ((c) == '#' || (c) == ' ' || \ + (c) == '*' || (c) == '+' || \ + (c) == '-' || (c) == '.' || \ + isdigit(c)) + +/* round off to the precision */ +#define ROUND(d, p) \ + (d < 0.) ? \ + d - pow_10(-(p)->precision) * 0.5 : \ + d + pow_10(-(p)->precision) * 0.5 + +/* set default precision */ +#define DEF_PREC(p) \ + if ((p)->precision == NOT_FOUND) \ + (p)->precision = 6 + +/* put a char */ +#define PUT_CHAR(c, p) \ + if ((p)->counter < (p)->length) { \ + *(p)->holder++ = (c); \ + (p)->counter++; \ + } + +#define PUT_PLUS(d, p) \ + if ((d) > 0. && (p)->justify == RIGHT) \ + PUT_CHAR('+', p) + +#define PUT_SPACE(d, p) \ + if ((p)->space == FOUND && (d) > 0.) \ + PUT_CHAR(' ', p) + +/* pad right */ +#define PAD_RIGHT(p) \ + if ((p)->width > 0 && (p)->justify != LEFT) \ + for (; (p)->width > 0; (p)->width--) \ + PUT_CHAR((p)->pad, p) + +/* pad left */ +#define PAD_LEFT(p) \ + if ((p)->width > 0 && (p)->justify == LEFT) \ + for (; (p)->width > 0; (p)->width--) \ + PUT_CHAR((p)->pad, p) + +/* if width and prec. in the args */ +#define STAR_ARGS(p) \ + if ((p)->star_w == FOUND) \ + (p)->width = va_arg(args, int); \ + if ((p)->star_p == FOUND) \ + (p)->precision = va_arg(args, int) diff --git a/snprintf.c b/snprintf.c index f131ca4dfb..64ade9d517 100644 --- a/snprintf.c +++ b/snprintf.c @@ -44,6 +44,7 @@ # include <config.h> #endif +#include "snprintf-imp.h" #include "snprintf.h" /* diff --git a/snprintf.h b/snprintf.h index 245739541e..62f57789b0 100644 --- a/snprintf.h +++ b/snprintf.h @@ -1,232 +1,9 @@ -/* - Unix snprintf implementation. - Version 1.2 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - It can be redistribute also under the terms of GNU Library General - Public Lincense. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - Revision History: - - 1.2: - * put under LGPL. - 1.1: - * added changes from Miles Bader - * corrected a bug with %f - * added support for %#g - * added more comments :-) - 1.0: - * supporting must ANSI syntaxic_sugars(see below) - 0.0: - * suppot %s %c %d - - it understands: - Integer: - %lu %lu %u - %hd %ld %d decimal - %ho %lo %o octal - %hx %lx %x %X hexa - Floating points: - %g %G %e %E %f double - Strings: - %s %c string - %% % - - Formating conversion flags: - - justify left - + Justify right or put a plus if number - # prefix 0x, 0X for hexa and 0 for octal - * precision/witdth is specify as an (int) in the arguments - ' ' leave a blank for number with no sign - l the later should be a long - h the later should be a short - -format: - snprintf(holder, sizeof_holder, format, ...) - -Return values: - (sizeof_holder - 1) - - - THANKS(for the patches and ideas): - Miles Bader - Cyrille Rustom - Jacek Slabocewiz - Mike Parker(mouse) - -Alain Magloire: alainm@rcsm.ee.mcgill.ca -*/ +extern int vsnprintf(char *string, size_t length, const char * format, + va_list args); #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif - -#include <stdlib.h> /* for atoi() */ -#include <ctype.h> - - -/* - * For the FLOATING POINT FORMAT : - * the challenge was finding a way to - * manipulate the Real numbers without having - * to resort to mathematical function(it - * would require to link with -lm) and not - * going down to the bit pattern(not portable) - * - * so a number, a real is: - - real = integral + fraction - - integral = ... + a(2)*10^2 + a(1)*10^1 + a(0)*10^0 - fraction = b(1)*10^-1 + b(2)*10^-2 + ... - - where: - 0 <= a(i) => 9 - 0 <= b(i) => 9 - - from then it was simple math - */ - -/* - * size of the buffer for the integral part - * and the fraction part - */ -#define MAX_INT 99 + 1 /* 1 for the null */ -#define MAX_FRACT 29 + 1 - -/* - * numtoa() uses PRIVATE buffers to store the results, - * So this function is not reentrant - */ -#define itoa(n) numtoa(n, 10, 0, (char **)0) -#define otoa(n) numtoa(n, 8, 0, (char **)0) -#define htoa(n) numtoa(n, 16, 0, (char **)0) -#define dtoa(n, p, f) numtoa(n, 10, p, f) - -#define SWAP_INT(a,b) {int t; t = (a); (a) = (b); (b) = t;} - -/* this struct holds everything we need */ -struct DATA { - int length; - char *holder; - int counter; -#ifdef __STDC__ - const char *pf; +extern int snprintf(char *string, size_t length, const char * format, ...); #else - char *pf; +extern int snprintf(char *string, size_t length, const char * format, + int va_alist); #endif -/* FLAGS */ - int width, precision; - int justify; char pad; - int square, space, star_w, star_p, a_long ; -}; - -#define PRIVATE static -#define PUBLIC -/* signature of the functions */ -#ifdef __STDC__ -/* the floating point stuff */ - PRIVATE double pow_10(int); - PRIVATE int log_10(double); - PRIVATE double integral(double, double *); - PRIVATE char * numtoa(double, int, int, char **); - -/* for the format */ - PRIVATE void conv_flag(char *, struct DATA *); - PRIVATE void floating(struct DATA *, double); - PRIVATE void exponent(struct DATA *, double); - PRIVATE void decimal(struct DATA *, double); - PRIVATE void octal(struct DATA *, double); - PRIVATE void hexa(struct DATA *, double); - PRIVATE void strings(struct DATA *, char *); - -#else -/* the floating point stuff */ - PRIVATE double pow_10(); - PRIVATE int log_10(); - PRIVATE double integral(); - PRIVATE char * numtoa(); - -/* for the format */ - PRIVATE void conv_flag(); - PRIVATE void floating(); - PRIVATE void exponent(); - PRIVATE void decimal(); - PRIVATE void octal(); - PRIVATE void hexa(); - PRIVATE void strings(); -#endif - -/* those are defines specific to snprintf to hopefully - * make the code clearer :-) - */ -#define RIGHT 1 -#define LEFT 0 -#define NOT_FOUND -1 -#define FOUND 1 -#define MAX_FIELD 15 - -/* the conversion flags */ -#define isflag(c) ((c) == '#' || (c) == ' ' || \ - (c) == '*' || (c) == '+' || \ - (c) == '-' || (c) == '.' || \ - isdigit(c)) - -/* round off to the precision */ -#define ROUND(d, p) \ - (d < 0.) ? \ - d - pow_10(-(p)->precision) * 0.5 : \ - d + pow_10(-(p)->precision) * 0.5 - -/* set default precision */ -#define DEF_PREC(p) \ - if ((p)->precision == NOT_FOUND) \ - (p)->precision = 6 - -/* put a char */ -#define PUT_CHAR(c, p) \ - if ((p)->counter < (p)->length) { \ - *(p)->holder++ = (c); \ - (p)->counter++; \ - } - -#define PUT_PLUS(d, p) \ - if ((d) > 0. && (p)->justify == RIGHT) \ - PUT_CHAR('+', p) - -#define PUT_SPACE(d, p) \ - if ((p)->space == FOUND && (d) > 0.) \ - PUT_CHAR(' ', p) - -/* pad right */ -#define PAD_RIGHT(p) \ - if ((p)->width > 0 && (p)->justify != LEFT) \ - for (; (p)->width > 0; (p)->width--) \ - PUT_CHAR((p)->pad, p) - -/* pad left */ -#define PAD_LEFT(p) \ - if ((p)->width > 0 && (p)->justify == LEFT) \ - for (; (p)->width > 0; (p)->width--) \ - PUT_CHAR((p)->pad, p) - -/* if width and prec. in the args */ -#define STAR_ARGS(p) \ - if ((p)->star_w == FOUND) \ - (p)->width = va_arg(args, int); \ - if ((p)->star_p == FOUND) \ - (p)->precision = va_arg(args, int) @@ -1,7 +1,7 @@ /* util.c * Utility routines * - * $Id: util.c,v 1.4 1998/10/12 01:40:57 gerald Exp $ + * $Id: util.c,v 1.5 1998/10/13 07:03:37 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -34,6 +34,15 @@ #include <stdarg.h> #include <strings.h> +#ifdef NEED_SNPRINTF_H +# ifdef HAVE_STDARG_H +# include <stdarg.h> +# else +# include <varargs.h> +# endif +# include "snprintf.h" +#endif + #include "util.h" #include "image/icon-excl.xpm" |