mirror of
https://github.com/michaeldv/pit.git
synced 2025-12-09 16:05:35 +00:00
Added Makefile; make & make clean both work
This commit is contained in:
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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
#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