listing code now in function
[cdoot:cdoot.git] / cdoot.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "cdootlib.h"
4
5 void printUsage();
6
7 int main(int argc, const char *argv[]){
8         setupSQLite();  
9         ++argv;
10         --argc;
11         for(; argc-->0; ++argv){
12                 if(strcmp(*argv, "-l") == 0)
13                         listAll(1);
14                 else if(strcmp(*argv, "-a") == 0){
15                         ++argv;
16                         --argc;
17                         char *project = *argv;  
18                         ++argv;
19                         --argc;
20                         char *summary = *argv;
21                         ++argv;
22                         --argc;
23                         int priority = atoi(*argv);
24                         addTodo(project, summary, priority);
25                 }else if(strcmp(*argv, "-h") == 0)
26                         printUsage();
27                 else if(strcmp(*argv, "-r") == 0){
28                         int *ids = listAll(0);
29                         ++argv;
30                         --argc;
31                         removeTodo(ids[atoi(*argv)]);
32                 }else if(strcmp(*argv, "-cp") == 0){
33                         int *ids = listAll(0);
34                         ++argv;
35                         --argc;
36                         int id = atoi(*argv);
37                         ++argv;
38                         --argc;
39                         int pri = atoi(*argv);
40                         changePriority(ids[id], pri);
41                 }else if(strcmp(*argv, "-cd") == 0){
42                         int *ids = listAll(0);
43                         ++argv;
44                         --argc;
45                         int id = atoi(*argv);
46                         ++argv;
47                         --argc;
48                         int inc = 0;
49                         int incbool = 0;
50                         if(*argv[0] != '+')
51                                 inc = atoi(*argv);
52                         else{
53                                 inc = atoi(*&argv[0]);
54                                 incbool = 1;
55                         }
56                         changeCompleted(ids[id], inc, incbool);
57                 }else if(strcmp(*argv, "-cdu") == 0){
58                         int *ids = listAll(0);
59                         ++argv;
60                         --argc;
61                         int id = atoi(*argv);
62                         ++argv;
63                         --argc;
64                         char *date = *argv;
65                         changeDate(ids[id],date);
66                 }else if(strcmp(*argv, "-e") == 0){
67                         ++argv;
68                         --argc;
69                         if(strcmp(*argv, "ods") == 0){
70                                 ++argv;
71                                 --argc;
72                                 char *fn = *argv;
73                                 exportToODS(fn);
74                         }
75                 }else if(strcmp(*argv, "-fp") == 0){
76                         ++argv;
77                         --argc;
78                         filterPriority(atoi(*argv));
79                 }else if(strcmp(*argv, "-fpo") == 0){
80                         ++argv;
81                         --argc;
82                         filterProject(*argv);
83                 }else
84                         printUsage();
85         }
86         killSQLite();
87         return 0;
88 }
89
90 void printUsage(){
91         printf("CDoot -- a program to manage project/todos in a simple way\n");
92         printf("Usage: cdoot <options>\n");
93         printf("Options:\n");
94         printf("  -l                                   List all todos\n");
95         printf("  -a   <project> <summary> <priority>  Add a todo\n");
96         printf("  -r   <id>                            Remove a todo (<id>)\n");
97         printf("  -cp  <id> <priority>                 Change a todo's (<id>) priority (<priority>)\n");
98         printf("  -cd  <id> <percent>                  Change how completed (<percent>) a todo (<id>) is. You can also add + to \n                                      increase instead of set\n");
99         printf("  -fp  <priority>                      Show only todos matching <priority>\n");
100         printf("  -fpo <project>                       Show only todos where project is like <project>\n"); 
101         printf("  -h                                   View this message\n");
102 }