Moved main() to a separate file

This commit is contained in:
Pierre Pronchery 2014-05-10 01:39:51 +02:00
parent c663fdbadc
commit ee78592c50
6 changed files with 98 additions and 33 deletions

View File

@ -25,10 +25,12 @@ dist:
$(PACKAGE)-$(VERSION)/src/linux.c \
$(PACKAGE)-$(VERSION)/src/netbsd.c \
$(PACKAGE)-$(VERSION)/src/strace.c \
$(PACKAGE)-$(VERSION)/src/main.c \
$(PACKAGE)-$(VERSION)/src/Makefile \
$(PACKAGE)-$(VERSION)/src/freebsd.h \
$(PACKAGE)-$(VERSION)/src/linux.h \
$(PACKAGE)-$(VERSION)/src/netbsd.h \
$(PACKAGE)-$(VERSION)/src/strace.h \
$(PACKAGE)-$(VERSION)/src/project.conf \
$(PACKAGE)-$(VERSION)/Makefile \
$(PACKAGE)-$(VERSION)/COPYING \

View File

@ -16,7 +16,7 @@ INSTALL = install
all: $(TARGETS)
strace_OBJS = freebsd.o linux.o netbsd.o strace.o
strace_OBJS = freebsd.o linux.o netbsd.o strace.o main.o
strace_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
strace_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
@ -32,9 +32,12 @@ linux.o: linux.c linux.h
netbsd.o: netbsd.c netbsd.h
$(CC) $(strace_CFLAGS) -c netbsd.c
strace.o: strace.c freebsd.h linux.h netbsd.h
strace.o: strace.c freebsd.h linux.h netbsd.h strace.h
$(CC) $(strace_CFLAGS) -c strace.c
main.o: main.c strace.h
$(CC) $(strace_CFLAGS) -c main.c
clean:
$(RM) -- $(strace_OBJS)

54
src/main.c Normal file
View File

@ -0,0 +1,54 @@
/* $Id$ */
/* Copyright (c) 2014 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Devel strace */
/* 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/>. */
#include <unistd.h>
#include <stdio.h>
#include "strace.h"
/* strace */
/* private */
/* prototypes */
static int _usage(void);
/* functions */
/* usage */
static int _usage(void)
{
fputs("Usage: strace program [argument...]\n", stderr);
return 1;
}
/* public */
/* functions */
/* main */
int main(int argc, char * argv[])
{
int o;
while((o = getopt(argc, argv, "")) != -1)
switch(o)
{
default:
return _usage();
}
if(argc - optind < 1)
return _usage();
return (strace(&argv[optind]) == 0) ? 0 : 2;
}

View File

@ -1,18 +1,21 @@
targets=strace
cflags_force=-W
cflags=-Wall -g -O2 -pedantic
dist=Makefile,freebsd.h,linux.h,netbsd.h
dist=Makefile,freebsd.h,linux.h,netbsd.h,strace.h
[strace]
type=binary
sources=freebsd.c,linux.c,netbsd.c,strace.c
sources=freebsd.c,linux.c,netbsd.c,strace.c,main.c
install=$(BINDIR)
[linux.c]
depends=linux.h
[main.c]
depends=strace.h
[netbsd.c]
depends=netbsd.h
[strace.c]
depends=freebsd.h,linux.h,netbsd.h
depends=freebsd.h,linux.h,netbsd.h,strace.h

View File

@ -29,8 +29,6 @@
/* strace */
/* private */
/* prototypes */
static int _strace(char * argv[]);
static int _strace_error(char const * message, int ret);
static int _strace_parent(pid_t pid);
@ -41,9 +39,10 @@ static void _strace_regs_print(struct reg * regs);
#endif
/* public */
/* functions */
/* strace */
static int _strace(char * argv[])
int strace(char * argv[])
{
pid_t pid;
@ -63,6 +62,8 @@ static int _strace(char * argv[])
}
/* private */
/* functions */
/* strace_error */
static int _strace_error(char const * message, int ret)
{
@ -172,28 +173,3 @@ static void _strace_regs_print(struct reg * regs)
# endif
}
#endif
/* usage */
static int _usage(void)
{
fputs("Usage: strace program [argument...]\n", stderr);
return 1;
}
/* main */
int main(int argc, char * argv[])
{
int o;
while((o = getopt(argc, argv, "")) != -1)
switch(o)
{
default:
return _usage();
}
if(argc - optind < 1)
return _usage();
return (_strace(&argv[optind]) == 0) ? 0 : 2;
}

27
src/strace.h Normal file
View File

@ -0,0 +1,27 @@
/* $Id$ */
/* Copyright (c) 2014 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Devel strace */
/* 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 STRACE_STRACE_H
# define STRACE_STRACE_H
/* strace */
/* public */
/* prototypes */
int strace(char * argv[]);
#endif /* !STRACE_STRACE_H */