Drastically reduce the warnings in utilbox
This commit is contained in:
parent
3f43762bf8
commit
a3491d5fe8
2
Makefile
2
Makefile
|
@ -71,9 +71,9 @@ dist:
|
||||||
$(PACKAGE)-$(VERSION)/src/common.c \
|
$(PACKAGE)-$(VERSION)/src/common.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/project.conf \
|
$(PACKAGE)-$(VERSION)/src/project.conf \
|
||||||
$(PACKAGE)-$(VERSION)/tools/utilbox.c \
|
$(PACKAGE)-$(VERSION)/tools/utilbox.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/tools/utils.c \
|
||||||
$(PACKAGE)-$(VERSION)/tools/Makefile \
|
$(PACKAGE)-$(VERSION)/tools/Makefile \
|
||||||
$(PACKAGE)-$(VERSION)/tools/utils.sh \
|
$(PACKAGE)-$(VERSION)/tools/utils.sh \
|
||||||
$(PACKAGE)-$(VERSION)/tools/utils.c \
|
|
||||||
$(PACKAGE)-$(VERSION)/tools/project.conf \
|
$(PACKAGE)-$(VERSION)/tools/project.conf \
|
||||||
$(PACKAGE)-$(VERSION)/Makefile \
|
$(PACKAGE)-$(VERSION)/Makefile \
|
||||||
$(PACKAGE)-$(VERSION)/COPYING \
|
$(PACKAGE)-$(VERSION)/COPYING \
|
||||||
|
|
|
@ -15,16 +15,19 @@ INSTALL = install
|
||||||
|
|
||||||
all: $(TARGETS)
|
all: $(TARGETS)
|
||||||
|
|
||||||
utilbox_OBJS = utilbox.o
|
utilbox_OBJS = utilbox.o utils.o
|
||||||
utilbox_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
utilbox_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||||
utilbox_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
utilbox_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||||
|
|
||||||
utilbox: $(utilbox_OBJS) utils.c
|
utilbox: $(utilbox_OBJS)
|
||||||
$(CC) -o utilbox $(utilbox_OBJS) $(utilbox_LDFLAGS)
|
$(CC) -o utilbox $(utilbox_OBJS) $(utilbox_LDFLAGS)
|
||||||
|
|
||||||
utilbox.o: utilbox.c
|
utilbox.o: utilbox.c
|
||||||
$(CC) $(utilbox_CFLAGS) -c utilbox.c
|
$(CC) $(utilbox_CFLAGS) -c utilbox.c
|
||||||
|
|
||||||
|
utils.o: utils.c
|
||||||
|
$(CC) $(utilbox_CFLAGS) -c utils.c
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) $(utilbox_OBJS)
|
$(RM) $(utilbox_OBJS)
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
targets=utilbox
|
targets=utilbox
|
||||||
cflags_force=-W
|
cflags_force=-W
|
||||||
cflags=-Wall -g -O2 -pedantic
|
cflags=-Wall -g -O2 -pedantic
|
||||||
dist=Makefile,utils.sh,utils.c
|
dist=Makefile,utils.sh
|
||||||
|
|
||||||
[utilbox]
|
[utilbox]
|
||||||
type=binary
|
type=binary
|
||||||
sources=utilbox.c
|
sources=utilbox.c,utils.c
|
||||||
depends=utils.c
|
|
||||||
|
|
|
@ -20,22 +20,11 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
|
#include "utilbox.h"
|
||||||
|
|
||||||
|
|
||||||
/* utilbox */
|
/* utilbox */
|
||||||
/* private */
|
/* private */
|
||||||
/* types */
|
|
||||||
typedef struct _Call
|
|
||||||
{
|
|
||||||
char const * name;
|
|
||||||
int (*call)(int argc, char * argv[]);
|
|
||||||
} Call;
|
|
||||||
|
|
||||||
|
|
||||||
/* variables */
|
|
||||||
#include "utils.c"
|
|
||||||
|
|
||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
static int _error(char const * message, int ret);
|
static int _error(char const * message, int ret);
|
||||||
static int _list(Call * calls);
|
static int _list(Call * calls);
|
||||||
|
@ -86,25 +75,25 @@ int main(int argc, char * argv[])
|
||||||
if((p = strdup(argv[0])) == NULL)
|
if((p = strdup(argv[0])) == NULL)
|
||||||
return _error(NULL, 2);
|
return _error(NULL, 2);
|
||||||
q = basename(p);
|
q = basename(p);
|
||||||
for(i = 0; _calls[i].name != NULL; i++)
|
for(i = 0; calls[i].name != NULL; i++)
|
||||||
if(strcmp(_calls[i].name, q) == 0)
|
if(strcmp(calls[i].name, q) == 0)
|
||||||
{
|
{
|
||||||
free(p);
|
free(p);
|
||||||
return _calls[i].call(argc, argv);
|
return calls[i].call(argc, argv);
|
||||||
}
|
}
|
||||||
free(p);
|
free(p);
|
||||||
while((o = getopt(argc, argv, "l")) != -1)
|
while((o = getopt(argc, argv, "l")) != -1)
|
||||||
switch(o)
|
switch(o)
|
||||||
{
|
{
|
||||||
case 'l':
|
case 'l':
|
||||||
return _list(_calls);
|
return _list(calls);
|
||||||
default:
|
default:
|
||||||
return _usage();
|
return _usage();
|
||||||
}
|
}
|
||||||
if(optind == argc)
|
if(optind == argc)
|
||||||
return _usage();
|
return _usage();
|
||||||
for(i = 0; _calls[i].name != NULL; i++)
|
for(i = 0; calls[i].name != NULL; i++)
|
||||||
if(strcmp(_calls[i].name, argv[optind]) == 0)
|
if(strcmp(calls[i].name, argv[optind]) == 0)
|
||||||
return _calls[i].call(argc - optind, &argv[optind]);
|
return calls[i].call(argc - optind, &argv[optind]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
34
tools/utilbox.h
Normal file
34
tools/utilbox.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
|
||||||
|
/* 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 <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#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 */
|
|
@ -15,6 +15,9 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "utilbox.h"
|
||||||
|
|
||||||
|
|
||||||
/* basename.c */
|
/* basename.c */
|
||||||
#define main _basename_main
|
#define main _basename_main
|
||||||
#define _usage _basename_usage
|
#define _usage _basename_usage
|
||||||
|
@ -706,7 +709,7 @@
|
||||||
#undef _who
|
#undef _who
|
||||||
|
|
||||||
|
|
||||||
static Call _calls[] =
|
Call calls[] =
|
||||||
{
|
{
|
||||||
|
|
||||||
{ "basename", _basename_main },
|
{ "basename", _basename_main },
|
||||||
|
|
|
@ -60,6 +60,9 @@ cat > "utils.c" << EOF
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "utilbox.h"
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
for i in ../src/*.c; do
|
for i in ../src/*.c; do
|
||||||
BASENAME=`basename $i`
|
BASENAME=`basename $i`
|
||||||
|
@ -73,7 +76,7 @@ done >> "utils.c"
|
||||||
cat >> "utils.c" << EOF
|
cat >> "utils.c" << EOF
|
||||||
|
|
||||||
|
|
||||||
static Call _calls[] =
|
Call calls[] =
|
||||||
{
|
{
|
||||||
$CALLS
|
$CALLS
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user