From a3491d5fe8dd0870be3b08e830c44525e5180b04 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Tue, 13 Oct 2009 10:19:32 +0000 Subject: [PATCH] Drastically reduce the warnings in utilbox --- Makefile | 2 +- tools/Makefile | 7 +++++-- tools/project.conf | 5 ++--- tools/utilbox.c | 27 ++++++++------------------- tools/utilbox.h | 34 ++++++++++++++++++++++++++++++++++ tools/utils.c | 5 ++++- tools/utils.sh | 5 ++++- 7 files changed, 58 insertions(+), 27 deletions(-) create mode 100644 tools/utilbox.h diff --git a/Makefile b/Makefile index d396342..524db11 100644 --- a/Makefile +++ b/Makefile @@ -71,9 +71,9 @@ dist: $(PACKAGE)-$(VERSION)/src/common.c \ $(PACKAGE)-$(VERSION)/src/project.conf \ $(PACKAGE)-$(VERSION)/tools/utilbox.c \ + $(PACKAGE)-$(VERSION)/tools/utils.c \ $(PACKAGE)-$(VERSION)/tools/Makefile \ $(PACKAGE)-$(VERSION)/tools/utils.sh \ - $(PACKAGE)-$(VERSION)/tools/utils.c \ $(PACKAGE)-$(VERSION)/tools/project.conf \ $(PACKAGE)-$(VERSION)/Makefile \ $(PACKAGE)-$(VERSION)/COPYING \ diff --git a/tools/Makefile b/tools/Makefile index 4e2a002..1be655f 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -15,16 +15,19 @@ INSTALL = install all: $(TARGETS) -utilbox_OBJS = utilbox.o +utilbox_OBJS = utilbox.o utils.o utilbox_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) utilbox_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) -utilbox: $(utilbox_OBJS) utils.c +utilbox: $(utilbox_OBJS) $(CC) -o utilbox $(utilbox_OBJS) $(utilbox_LDFLAGS) utilbox.o: utilbox.c $(CC) $(utilbox_CFLAGS) -c utilbox.c +utils.o: utils.c + $(CC) $(utilbox_CFLAGS) -c utils.c + clean: $(RM) $(utilbox_OBJS) diff --git a/tools/project.conf b/tools/project.conf index e852efa..c02cf6d 100644 --- a/tools/project.conf +++ b/tools/project.conf @@ -1,9 +1,8 @@ targets=utilbox cflags_force=-W cflags=-Wall -g -O2 -pedantic -dist=Makefile,utils.sh,utils.c +dist=Makefile,utils.sh [utilbox] type=binary -sources=utilbox.c -depends=utils.c +sources=utilbox.c,utils.c diff --git a/tools/utilbox.c b/tools/utilbox.c index 0964069..3cd2995 100644 --- a/tools/utilbox.c +++ b/tools/utilbox.c @@ -20,22 +20,11 @@ #include #include #include +#include "utilbox.h" /* utilbox */ /* private */ -/* types */ -typedef struct _Call -{ - char const * name; - int (*call)(int argc, char * argv[]); -} Call; - - -/* variables */ -#include "utils.c" - - /* prototypes */ static int _error(char const * message, int ret); static int _list(Call * calls); @@ -86,25 +75,25 @@ int main(int argc, char * argv[]) if((p = strdup(argv[0])) == NULL) return _error(NULL, 2); q = basename(p); - for(i = 0; _calls[i].name != NULL; i++) - if(strcmp(_calls[i].name, q) == 0) + for(i = 0; calls[i].name != NULL; i++) + if(strcmp(calls[i].name, q) == 0) { free(p); - return _calls[i].call(argc, argv); + return calls[i].call(argc, argv); } free(p); while((o = getopt(argc, argv, "l")) != -1) switch(o) { case 'l': - return _list(_calls); + return _list(calls); default: return _usage(); } if(optind == argc) return _usage(); - for(i = 0; _calls[i].name != NULL; i++) - if(strcmp(_calls[i].name, argv[optind]) == 0) - return _calls[i].call(argc - optind, &argv[optind]); + for(i = 0; calls[i].name != NULL; i++) + if(strcmp(calls[i].name, argv[optind]) == 0) + return calls[i].call(argc - optind, &argv[optind]); return 0; } diff --git a/tools/utilbox.h b/tools/utilbox.h new file mode 100644 index 0000000..be8f72a --- /dev/null +++ b/tools/utilbox.h @@ -0,0 +1,34 @@ +/* $Id$ */ +/* Copyright (c) 2009 Pierre Pronchery */ +/* This file is part of DeforaOS Unix utils */ +/* 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, version 3 of the License. + * + * 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, see . */ + + + +#ifndef UTILS_UTILBOX_H +# define UTILS_UTILBOX_H + + +/* utilbox */ +/* types */ +typedef struct _Call +{ + char const * name; + int (*call)(int argc, char * argv[]); +} Call; + + +/* variables */ +extern Call calls[]; + +#endif /* UTILS_UTILBOX_H */ diff --git a/tools/utils.c b/tools/utils.c index 9ef4661..ac5f2fe 100644 --- a/tools/utils.c +++ b/tools/utils.c @@ -15,6 +15,9 @@ +#include "utilbox.h" + + /* basename.c */ #define main _basename_main #define _usage _basename_usage @@ -706,7 +709,7 @@ #undef _who -static Call _calls[] = +Call calls[] = { { "basename", _basename_main }, diff --git a/tools/utils.sh b/tools/utils.sh index f7cc301..7139c2a 100644 --- a/tools/utils.sh +++ b/tools/utils.sh @@ -60,6 +60,9 @@ cat > "utils.c" << EOF * along with this program. If not, see . */ + +#include "utilbox.h" + EOF for i in ../src/*.c; do BASENAME=`basename $i` @@ -73,7 +76,7 @@ done >> "utils.c" cat >> "utils.c" << EOF -static Call _calls[] = +Call calls[] = { $CALLS { NULL, NULL }