mirror of
https://github.com/michaeldv/pit.git
synced 2025-12-10 00:15:35 +00:00
Added Makefile; make & make clean both work
This commit is contained in:
57
Makefile
Normal file
57
Makefile
Normal file
@@ -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)
|
||||||
|
|
||||||
28
src/pit.c
Normal file
28
src/pit.c
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#include "pit.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
10
src/pit.h
Normal file
10
src/pit.h
Normal file
@@ -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
|
||||||
57
src/project.c
Normal file
57
src/project.c
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#include "pit.h"
|
||||||
|
#include "project.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
8
src/project.h
Normal file
8
src/project.h
Normal file
@@ -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
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
|
#include "pit.h"
|
||||||
|
#include "table.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
typedef unsigned long ulong;
|
|
||||||
typedef unsigned char uchar;
|
|
||||||
|
|
||||||
#define TABLE_INCREMENT 50
|
#define TABLE_INCREMENT 50
|
||||||
#define TABLE_HAS_ID 1
|
#define TABLE_HAS_ID 1
|
||||||
#define TABLE_HAS_CREATED_AT 2
|
#define TABLE_HAS_CREATED_AT 2
|
||||||
@@ -211,6 +210,7 @@ PTable table_free(PTable pt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(TEST)
|
||||||
int main() {
|
int main() {
|
||||||
PTable pt;
|
PTable pt;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -255,4 +255,5 @@ int main() {
|
|||||||
table_free(pt);
|
table_free(pt);
|
||||||
printf("OK\n");
|
printf("OK\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
5
src/table.h
Normal file
5
src/table.h
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#if !defined(__TABLE_H__)
|
||||||
|
#define __TABLE_H__
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
10
src/task.c
Normal file
10
src/task.c
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#include "pit.h"
|
||||||
|
#include "task.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int pit_task(char *argv[]) {
|
||||||
|
printf("pit_task\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
4
src/task.h
Normal file
4
src/task.h
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#if !defined(__TASK_H__)
|
||||||
|
#define __TASK_H__
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user