From ee78592c50f49f669f0aa0c05ad27bfcfc68834e Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sat, 10 May 2014 01:39:51 +0200 Subject: [PATCH] Moved main() to a separate file --- Makefile | 2 ++ src/Makefile | 7 +++++-- src/main.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ src/project.conf | 9 +++++--- src/strace.c | 32 ++++------------------------ src/strace.h | 27 ++++++++++++++++++++++++ 6 files changed, 98 insertions(+), 33 deletions(-) create mode 100644 src/main.c create mode 100644 src/strace.h diff --git a/Makefile b/Makefile index 66febf2..3095db8 100644 --- a/Makefile +++ b/Makefile @@ -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 \ diff --git a/src/Makefile b/src/Makefile index 7ceb0d6..ba7aa42 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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) diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..e3aecf4 --- /dev/null +++ b/src/main.c @@ -0,0 +1,54 @@ +/* $Id$ */ +/* Copyright (c) 2014 Pierre Pronchery */ +/* 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 . */ + + + +#include +#include +#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; +} diff --git a/src/project.conf b/src/project.conf index 374b6d6..937c12d 100644 --- a/src/project.conf +++ b/src/project.conf @@ -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 diff --git a/src/strace.c b/src/strace.c index 01eaeb8..2f7aced 100644 --- a/src/strace.c +++ b/src/strace.c @@ -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; -} diff --git a/src/strace.h b/src/strace.h new file mode 100644 index 0000000..2b59d1d --- /dev/null +++ b/src/strace.h @@ -0,0 +1,27 @@ +/* $Id$ */ +/* Copyright (c) 2014 Pierre Pronchery */ +/* 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 . */ + + + +#ifndef STRACE_STRACE_H +# define STRACE_STRACE_H + + +/* strace */ +/* public */ +/* prototypes */ +int strace(char * argv[]); + +#endif /* !STRACE_STRACE_H */