From 9dec87454c875c4a3b32a6c5aad630a5ba8b5140 Mon Sep 17 00:00:00 2001 From: Mike Dvorkin Date: Sat, 10 Jul 2010 13:11:21 -0700 Subject: [PATCH] Added Makefile; make & make clean both work --- Makefile | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/pit.c | 28 +++++++++++++++++++++++++ src/pit.h | 10 +++++++++ src/project.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/project.h | 8 ++++++++ src/table.c | 9 ++++---- src/table.h | 5 +++++ src/task.c | 10 +++++++++ src/task.h | 4 ++++ 9 files changed, 184 insertions(+), 4 deletions(-) create mode 100644 Makefile create mode 100644 src/pit.c create mode 100644 src/pit.h create mode 100644 src/project.c create mode 100644 src/project.h create mode 100644 src/table.h create mode 100644 src/task.c create mode 100644 src/task.h diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..beccccf --- /dev/null +++ b/Makefile @@ -0,0 +1,57 @@ +#!/usr/bin/make +# + +# The toplevel directory of the source tree. +SRCDIR = ./src + +# The directory into which object code files should be written. +OBJDIR = ./obj + +# The directory into which executable file should be written. +BINDIR = ./bin + +# C Compiler and options for use in building executable. +CC = gcc -g -Os -Wall + +SRC = \ + $(SRCDIR)/pit.c \ + $(SRCDIR)/project.c \ + $(SRCDIR)/table.c \ + $(SRCDIR)/task.c + +OBJ = \ + $(OBJDIR)/pit.o \ + $(OBJDIR)/project.o \ + $(OBJDIR)/table.o \ + $(OBJDIR)/task.o + +APP = pit + +all: $(OBJDIR) $(APP) + +$(OBJDIR): + -mkdir $(OBJDIR) + -mkdir $(BINDIR) + +$(APP): $(OBJ) + $(CC) -o $(BINDIR)/$(APP) $(OBJ) + +$(OBJDIR)/pit.o: $(SRCDIR)/pit.c $(SRCDIR)/pit.h + $(CC) -o $(OBJDIR)/pit.o -c $(SRCDIR)/pit.c + +$(OBJDIR)/project.o: $(SRCDIR)/project.c $(SRCDIR)/project.h + $(CC) -o $(OBJDIR)/project.o -c $(SRCDIR)/project.c + +$(OBJDIR)/table.o: $(SRCDIR)/table.c $(SRCDIR)/table.h + $(CC) -o $(OBJDIR)/table.o -c $(SRCDIR)/table.c + +$(OBJDIR)/task.o: $(SRCDIR)/task.c $(SRCDIR)/task.h + $(CC) -o $(OBJDIR)/task.o -c $(SRCDIR)/task.c + + +clean: + rm -f $(OBJDIR)/*.o + rm -f $(BINDIR)/$(APP) + rmdir $(OBJDIR) + rmdir $(BINDIR) + diff --git a/src/pit.c b/src/pit.c new file mode 100644 index 0000000..5e016c6 --- /dev/null +++ b/src/pit.c @@ -0,0 +1,28 @@ +#include "pit.h" +#include +#include +#include + +static int usage() { + printf("usage...\n"); + return 1; +} + +int main(int argc, char *argv[]) { + int i; + char *commands[] = { "project", "task", "note", "log" }; + + printf("argc: %d\n", argc); + for(i = 0; i < argc; i++) { + printf("argv[%d]: [%s]\n", i, argv[i]); + } + + if (argc > 1) { + if (strstr(commands[0], argv[1]) == commands[0]) { + return pit_project(&argv[1]); + } else if (strstr(commands[1], argv[1]) == commands[1]) { + return pit_task(&argv[1]); + } + } + return usage(); +} \ No newline at end of file diff --git a/src/pit.h b/src/pit.h new file mode 100644 index 0000000..5281253 --- /dev/null +++ b/src/pit.h @@ -0,0 +1,10 @@ +#if !defined(__PIT_H__) +#define __PIT_H__ + +typedef unsigned long ulong; +typedef unsigned char uchar; + +int pit_project(char *argv[]); +int pit_task(char *argv[]); + +#endif diff --git a/src/project.c b/src/project.c new file mode 100644 index 0000000..c91e23b --- /dev/null +++ b/src/project.c @@ -0,0 +1,57 @@ +#include "pit.h" +#include "project.h" +#include +#include +#include + +int pit_project(char *argv[]) { + char **arg = &argv[1]; + char *error = NULL; + + if (!*arg) { + printf("list projects\n"); + } else if (!strcmp(*arg, "-c")) { + if (!*++arg) { + error = "missing project name"; + } else { + create_project(*arg, *(arg + 1)); + } + } else if (!strcmp(*arg, "-d") || !strcmp(*arg, "-s")) { + if (!*++arg) { + error = "missing project number"; + } else { + unsigned long number = atoi(*arg); + if (!number) { + error = "invalid project number"; + } else { + if (!strcmp(*--arg, "-d")) { + delete_project(number); + } else { + show_project(number); + } + } + } + } + + if (error) { + printf("%s\n", error); + } + + return error == NULL; +} + +static int create_project(char *name, char *status) { + printf("creating project [%s], status [%s]\n", name, status); + return 1; +} + +static int show_project(unsigned long number) { + printf("showing project %lu\n", number); + return 1; +} + +static int delete_project(unsigned long number) { + printf("deleting project %lu\n", number); + return 1; +} + diff --git a/src/project.h b/src/project.h new file mode 100644 index 0000000..6a76be5 --- /dev/null +++ b/src/project.h @@ -0,0 +1,8 @@ +#if !defined(__PROJECT_H__) +#define __PROJECT_H__ + +static int create_project(char *name, char *status); +static int show_project(unsigned long number); +static int delete_project(unsigned long number); + +#endif diff --git a/src/table.c b/src/table.c index ecc9ea4..80362e0 100755 --- a/src/table.c +++ b/src/table.c @@ -1,11 +1,10 @@ +#include "pit.h" +#include "table.h" #include #include #include #include -typedef unsigned long ulong; -typedef unsigned char uchar; - #define TABLE_INCREMENT 50 #define TABLE_HAS_ID 1 #define TABLE_HAS_CREATED_AT 2 @@ -211,6 +210,7 @@ PTable table_free(PTable pt) { } +#if defined(TEST) int main() { PTable pt; typedef struct { @@ -255,4 +255,5 @@ int main() { table_free(pt); printf("OK\n"); return 0; -} \ No newline at end of file +} +#endif diff --git a/src/table.h b/src/table.h new file mode 100644 index 0000000..790919b --- /dev/null +++ b/src/table.h @@ -0,0 +1,5 @@ +#if !defined(__TABLE_H__) +#define __TABLE_H__ + + +#endif \ No newline at end of file diff --git a/src/task.c b/src/task.c new file mode 100644 index 0000000..334052f --- /dev/null +++ b/src/task.c @@ -0,0 +1,10 @@ +#include "pit.h" +#include "task.h" +#include +#include +#include + +int pit_task(char *argv[]) { + printf("pit_task\n"); + return 1; +} diff --git a/src/task.h b/src/task.h new file mode 100644 index 0000000..d07c18f --- /dev/null +++ b/src/task.h @@ -0,0 +1,4 @@ +#if !defined(__TASK_H__) +#define __TASK_H__ + +#endif