Permalink
Browse files

More stuff

  • Loading branch information...
1 parent 9ee90f5 commit 249876059f86621ac093b91b8f6b0e1c4ec87ad7 @txus committed Mar 24, 2011
Showing with 147 additions and 43 deletions.
  1. +1 −0 .gitignore
  2. +15 −15 Makefile
  3. +1 −1 libtool
  4. +13 −13 src/Makefile
  5. +103 −0 src/main.c
  6. +14 −14 tests/Makefile
  7. BIN tests/check_micetrap
View
@@ -6,3 +6,4 @@ src/micetrap
config.log
config.status
.deps/*
+tests/check_micetrap
View
@@ -69,18 +69,18 @@ DIST_ARCHIVES = $(distdir).tar.gz
GZIP_ENV = --best
distuninstallcheck_listfiles = find . -type f -print
distcleancheck_listfiles = find . -type f -print
-ACLOCAL = ${SHELL} /Users/txus/Code/micetrap/missing --run aclocal-1.10
-AMTAR = ${SHELL} /Users/txus/Code/micetrap/missing --run tar
+ACLOCAL = ${SHELL} /Users/txus/Code/micetrap-rewrite/missing --run aclocal-1.10
+AMTAR = ${SHELL} /Users/txus/Code/micetrap-rewrite/missing --run tar
AR = ar
-AUTOCONF = ${SHELL} /Users/txus/Code/micetrap/missing --run autoconf
-AUTOHEADER = ${SHELL} /Users/txus/Code/micetrap/missing --run autoheader
-AUTOMAKE = ${SHELL} /Users/txus/Code/micetrap/missing --run automake-1.10
+AUTOCONF = ${SHELL} /Users/txus/Code/micetrap-rewrite/missing --run autoconf
+AUTOHEADER = ${SHELL} /Users/txus/Code/micetrap-rewrite/missing --run autoheader
+AUTOMAKE = ${SHELL} /Users/txus/Code/micetrap-rewrite/missing --run automake-1.10
AWK = awk
CC = gcc
CCDEPMODE = depmode=gcc3
CFLAGS = -g -O2
-CHECK_CFLAGS = -I/usr/local/include
-CHECK_LIBS = -L/usr/local/lib -lcheck
+CHECK_CFLAGS = -I/usr/local/Cellar/check/0.9.8/include
+CHECK_LIBS = -L/usr/local/Cellar/check/0.9.8/lib -lcheck
CPP = gcc -E
CPPFLAGS =
CYGPATH_W = echo
@@ -108,7 +108,7 @@ LIBTOOL = $(SHELL) $(top_builddir)/libtool
LIPO = lipo
LN_S = ln -s
LTLIBOBJS =
-MAKEINFO = ${SHELL} /Users/txus/Code/micetrap/missing --run makeinfo
+MAKEINFO = ${SHELL} /Users/txus/Code/micetrap-rewrite/missing --run makeinfo
MKDIR_P = ./install-sh -c -d
NM = /usr/bin/nm
NMEDIT = nmedit
@@ -131,10 +131,10 @@ SET_MAKE =
SHELL = /bin/sh
STRIP = strip
VERSION = 0.0.1
-abs_builddir = /Users/txus/Code/micetrap
-abs_srcdir = /Users/txus/Code/micetrap
-abs_top_builddir = /Users/txus/Code/micetrap
-abs_top_srcdir = /Users/txus/Code/micetrap
+abs_builddir = /Users/txus/Code/micetrap-rewrite
+abs_srcdir = /Users/txus/Code/micetrap-rewrite
+abs_top_builddir = /Users/txus/Code/micetrap-rewrite
+abs_top_srcdir = /Users/txus/Code/micetrap-rewrite
ac_ct_CC = gcc
ac_ct_DUMPBIN =
am__include = include
@@ -162,7 +162,7 @@ host_vendor = apple
htmldir = ${docdir}
includedir = ${prefix}/include
infodir = ${datarootdir}/info
-install_sh = $(SHELL) /Users/txus/Code/micetrap/install-sh
+install_sh = $(SHELL) /Users/txus/Code/micetrap-rewrite/install-sh
libdir = ${exec_prefix}/lib
libexecdir = ${exec_prefix}/libexec
localedir = ${datarootdir}/locale
@@ -612,13 +612,13 @@ uninstall-am:
uninstall uninstall-am
#
-# INCLUDES = -I/usr/local/include
+# INCLUDES = -I/usr/local/Cellar/check/0.9.8/include
#
# TESTS = check_micetrap
#
# noinst_PROGRAMS = $(TESTS)
# check_micetrap_SOURCES = check_micetrap.c
-# check_micetrap_LDADD = -L/usr/local/lib -lcheck check_hello.o
+# check_micetrap_LDADD = -L/usr/local/Cellar/check/0.9.8/lib -lcheck check_hello.o
# CLEANFILES = check_micetrap.log
#
# check_%.o : $(srcdir)/%.c
View
@@ -2,7 +2,7 @@
# libtool - Provide generalized library-building support services.
# Generated automatically by config.status (micetrap) 0.0.1
-# Libtool was configured on host txus-macbook:
+# Libtool was configured on host txus-desktop.local:
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
#
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
View
@@ -64,18 +64,18 @@ DIST_SOURCES = $(micetrap_SOURCES)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
-ACLOCAL = ${SHELL} /Users/txus/Code/micetrap/missing --run aclocal-1.10
-AMTAR = ${SHELL} /Users/txus/Code/micetrap/missing --run tar
+ACLOCAL = ${SHELL} /Users/txus/Code/micetrap-rewrite/missing --run aclocal-1.10
+AMTAR = ${SHELL} /Users/txus/Code/micetrap-rewrite/missing --run tar
AR = ar
-AUTOCONF = ${SHELL} /Users/txus/Code/micetrap/missing --run autoconf
-AUTOHEADER = ${SHELL} /Users/txus/Code/micetrap/missing --run autoheader
-AUTOMAKE = ${SHELL} /Users/txus/Code/micetrap/missing --run automake-1.10
+AUTOCONF = ${SHELL} /Users/txus/Code/micetrap-rewrite/missing --run autoconf
+AUTOHEADER = ${SHELL} /Users/txus/Code/micetrap-rewrite/missing --run autoheader
+AUTOMAKE = ${SHELL} /Users/txus/Code/micetrap-rewrite/missing --run automake-1.10
AWK = awk
CC = gcc
CCDEPMODE = depmode=gcc3
CFLAGS = -g -O2
-CHECK_CFLAGS = -I/usr/local/include
-CHECK_LIBS = -L/usr/local/lib -lcheck
+CHECK_CFLAGS = -I/usr/local/Cellar/check/0.9.8/include
+CHECK_LIBS = -L/usr/local/Cellar/check/0.9.8/lib -lcheck
CPP = gcc -E
CPPFLAGS =
CYGPATH_W = echo
@@ -103,7 +103,7 @@ LIBTOOL = $(SHELL) $(top_builddir)/libtool
LIPO = lipo
LN_S = ln -s
LTLIBOBJS =
-MAKEINFO = ${SHELL} /Users/txus/Code/micetrap/missing --run makeinfo
+MAKEINFO = ${SHELL} /Users/txus/Code/micetrap-rewrite/missing --run makeinfo
MKDIR_P = .././install-sh -c -d
NM = /usr/bin/nm
NMEDIT = nmedit
@@ -126,10 +126,10 @@ SET_MAKE =
SHELL = /bin/sh
STRIP = strip
VERSION = 0.0.1
-abs_builddir = /Users/txus/Code/micetrap/src
-abs_srcdir = /Users/txus/Code/micetrap/src
-abs_top_builddir = /Users/txus/Code/micetrap
-abs_top_srcdir = /Users/txus/Code/micetrap
+abs_builddir = /Users/txus/Code/micetrap-rewrite/src
+abs_srcdir = /Users/txus/Code/micetrap-rewrite/src
+abs_top_builddir = /Users/txus/Code/micetrap-rewrite
+abs_top_srcdir = /Users/txus/Code/micetrap-rewrite
ac_ct_CC = gcc
ac_ct_DUMPBIN =
am__include = include
@@ -157,7 +157,7 @@ host_vendor = apple
htmldir = ${docdir}
includedir = ${prefix}/include
infodir = ${datarootdir}/info
-install_sh = $(SHELL) /Users/txus/Code/micetrap/install-sh
+install_sh = $(SHELL) /Users/txus/Code/micetrap-rewrite/install-sh
libdir = ${exec_prefix}/lib
libexecdir = ${exec_prefix}/libexec
localedir = ${datarootdir}/locale
View
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <getopt.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
@@ -12,12 +13,114 @@
#define BUFSIZE 1024
+const char* program_name = "micetrap";
+const char* program_version = "0.0.1";
+
void error(char *msg) {
perror(msg);
exit(1);
}
+void show_banner() {
+ printf("Usage:\n\t\t[sudo] %s <service> [options]", program_name);
+ printf("\n\t\t\t-p --port\t[PORT]\t\tA specific port to use\n");
+}
+
+void show_version() {
+ printf("%s-%s", program_name, program_version);
+}
+
+void
+populate_service_and_port_from_options(char *service, int *port, int argc, char* argv[])
+{
+
+ int next_option;
+
+ const char* const short_options = "hpv:";
+ const struct option long_options[] =
+ {
+ { "help", 0, NULL, 'h' },
+ { "version", 0, NULL, 'v' },
+ { "port", 1, NULL, 'p' },
+ { "service", 1, NULL, 's' },
+ { NULL, 0, NULL, 0 },
+ };
+
+ char* service_name = NULL;
+ unsigned int port_number = NULL;
+
+ if (argc == 1)
+ {
+ show_banner();
+ exit(EXIT_SUCCESS);
+ }
+
+ while(1)
+ {
+
+ next_option = getopt_long (argc, argv, short_options, long_options, NULL);
+
+ if (next_option == -1)
+ {
+ break;
+ }
+
+ switch(next_option)
+ {
+ case 'h' :
+ show_banner();
+ exit(EXIT_SUCCESS);
+
+ case 'v' :
+ show_version();
+ exit(EXIT_SUCCESS);
+
+ case 'p' :
+ printf("Given a port argument: %s\n", optarg);
+ port_number = (int)optarg;
+ break;
+
+ case 's' :
+ printf("Given a service argument: %s\n", optarg);
+ service_name = (char*)optarg;
+ break;
+
+ case -1 :
+ break;
+
+ default :
+ abort();
+ }
+
+ }
+
+ if (optind < argc)
+ {
+ printf("Unrecognized options:\n");
+ while (optind < argc)
+ printf("\t\t%s\n", argv[optind++]);
+ }
+
+ if (service_name == NULL)
+ {
+ printf("You must provide a valid service name.");
+ exit(-1);
+ }
+
+ service = service_name;
+ port = port_number;
+ printf("After Service: %s\nPort: %i", service, port);
+}
+
int main(int argc, char **argv) {
+
+ char* service = NULL;
+ unsigned int port = NULL;
+
+ populate_service_and_port_from_options(&service, &port, argc, argv);
+
+ printf("Service: %s\nPort: %i", service, port);
+
int parentfd; /* parent socket */
int childfd; /* child socket */
int portno; /* port to listen on */
View
@@ -65,18 +65,18 @@ DIST_SOURCES = $(check_micetrap_SOURCES)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
-ACLOCAL = ${SHELL} /Users/txus/Code/micetrap/missing --run aclocal-1.10
-AMTAR = ${SHELL} /Users/txus/Code/micetrap/missing --run tar
+ACLOCAL = ${SHELL} /Users/txus/Code/micetrap-rewrite/missing --run aclocal-1.10
+AMTAR = ${SHELL} /Users/txus/Code/micetrap-rewrite/missing --run tar
AR = ar
-AUTOCONF = ${SHELL} /Users/txus/Code/micetrap/missing --run autoconf
-AUTOHEADER = ${SHELL} /Users/txus/Code/micetrap/missing --run autoheader
-AUTOMAKE = ${SHELL} /Users/txus/Code/micetrap/missing --run automake-1.10
+AUTOCONF = ${SHELL} /Users/txus/Code/micetrap-rewrite/missing --run autoconf
+AUTOHEADER = ${SHELL} /Users/txus/Code/micetrap-rewrite/missing --run autoheader
+AUTOMAKE = ${SHELL} /Users/txus/Code/micetrap-rewrite/missing --run automake-1.10
AWK = awk
CC = gcc
CCDEPMODE = depmode=gcc3
CFLAGS = -g -O2
-CHECK_CFLAGS = -I/usr/local/include
-CHECK_LIBS = -L/usr/local/lib -lcheck
+CHECK_CFLAGS = -I/usr/local/Cellar/check/0.9.8/include
+CHECK_LIBS = -L/usr/local/Cellar/check/0.9.8/lib -lcheck
CPP = gcc -E
CPPFLAGS =
CYGPATH_W = echo
@@ -104,7 +104,7 @@ LIBTOOL = $(SHELL) $(top_builddir)/libtool
LIPO = lipo
LN_S = ln -s
LTLIBOBJS =
-MAKEINFO = ${SHELL} /Users/txus/Code/micetrap/missing --run makeinfo
+MAKEINFO = ${SHELL} /Users/txus/Code/micetrap-rewrite/missing --run makeinfo
MKDIR_P = .././install-sh -c -d
NM = /usr/bin/nm
NMEDIT = nmedit
@@ -127,10 +127,10 @@ SET_MAKE =
SHELL = /bin/sh
STRIP = strip
VERSION = 0.0.1
-abs_builddir = /Users/txus/Code/micetrap/tests
-abs_srcdir = /Users/txus/Code/micetrap/tests
-abs_top_builddir = /Users/txus/Code/micetrap
-abs_top_srcdir = /Users/txus/Code/micetrap
+abs_builddir = /Users/txus/Code/micetrap-rewrite/tests
+abs_srcdir = /Users/txus/Code/micetrap-rewrite/tests
+abs_top_builddir = /Users/txus/Code/micetrap-rewrite
+abs_top_srcdir = /Users/txus/Code/micetrap-rewrite
ac_ct_CC = gcc
ac_ct_DUMPBIN =
am__include = include
@@ -158,7 +158,7 @@ host_vendor = apple
htmldir = ${docdir}
includedir = ${prefix}/include
infodir = ${datarootdir}/info
-install_sh = $(SHELL) /Users/txus/Code/micetrap/install-sh
+install_sh = $(SHELL) /Users/txus/Code/micetrap-rewrite/install-sh
libdir = ${exec_prefix}/lib
libexecdir = ${exec_prefix}/libexec
localedir = ${datarootdir}/locale
@@ -526,7 +526,7 @@ uninstall-am:
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags uninstall uninstall-am
-# check_micetrap_LDADD = $(top_builddir)/src/libmicetrap.la -L/usr/local/lib -lcheck
+# check_micetrap_LDADD = $(top_builddir)/src/libmicetrap.la -L/usr/local/Cellar/check/0.9.8/lib -lcheck
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
View
Binary file not shown.

0 comments on commit 2498760

Please sign in to comment.