-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.c
149 lines (138 loc) · 4.02 KB
/
ui.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifndef _COLOR_H_
#define _COLOR_H_
#define NONE "\e[0m" //normal
#define BLACK "\e[0;30m" //dark
#define L_BLACK "\e[1;30m" //bright dark
#define RED "\e[0;31m" //deep red
#define L_RED "\e[1;31m" //bright red
#define GREEN "\e[0;32m" //deep green
#define L_GREEN "\e[1;32m" //bright green
#define BROWN "\e[0;33m" //deep yellow
#define YELLOW "\e[1;33m" //bright yellow
#define BLUE "\e[0;34m" //deep blue
#define L_BLUE "\e[1;34m" //bright blue
#define PURPLE "\e[0;35m" //deep pink
#define L_PURPLE "\e[1;35m" //bright pink
#define CYAN "\e[0;36m" //deep green
#define L_CYAN "\e[1;36m" //bright green
#define GRAY "\e[0;37m" //gray
#define WHITE "\e[1;37m" //white
#define BOLD "\e[1m" //bold white
#define UNDERLINE "\e[4m" //underline white
#define BLINK "\e[5m" //blink white
#define REVERSE "\e[7m" //reverse
#define HIDE "\e[8m" //hide
#define CLEAR "\e[2J" //clear
#define CLRLINE "\r\e[K" //clear line
#endif
#ifndef DATAMNG
#define DATAMNG
#include "datamng.h"
#endif
#ifndef TSTAT
#define TSTAT
#include "tstat.h"
#endif
#ifndef TOPT
#include "topts.h"
#define TOPT
#endif
int start(tlist *list,int argc,char *argv[]){
char s[500], *cp;
cp = s;
if(argc==1){
printf("Name unknown.\n");
exit(1);
}
while(--argc){
argv++;
for(;*cp=*(*argv);cp++,(*argv)++);
*cp++=' ';
}
*--cp='\0';
tele *new = add(list,s,Started);
datach(new,"%s");
ptele(new,"Started %n\tid:%i,%sHh:%smm:%sss\tmode:%m\n");
return 0;
}
int end(tlist *list,int argc,char *argv[]){
int ifid=0;
int ifname=0;
char **others;
tele *ele;
Opts *optlist = opts(2,"i|id:",&ifid,"n|name:",&ifname);
argc = optloads(optlist,&others,argc,argv);
if(ifid&&ifname){
printf("Argument error: id and name options cannot occurs at the same time.\n");
exit(2);
}else if(!(ifid||ifname)){
printf("Please specify your activity locate method:\n"
"\t-i for locating by id.\n"
"\t-n for locating by name\n");
exit(2);
}
if(ifid){
ele = findbyid(list,atoi(others[0]));
datach(ele,"%e%m",Ended);
}else if(ifname){
char name[500];
char *cp = name;
while(--argc){
(*others)++;
for(;*cp=*(*others);cp++,(*others)++);
*cp++=' ';
}
*--cp='\0';
if(!findbyname(list, name)){
fprintf(stderr,"End failed. Not activity named \"%s\".\n",others[0]);
return -1;
}
int nextid = findbyname(list,others[0])->id;
for(iterlist *iter=newiter(list);
ele=liter(iter);){
if(ele->id==nextid&&ele->spndnextid!=-1)
nextid = ele->spndnextid;
else if(ele->id==nextid&&ele->spndnextid==-1){
datach(ele,"%e%m",Ended);
break;
}
}
}
if(!ele)
return -1;
ptele(ele,"%n\t%i\t%eHh:%emm:%ess,%m\n");
return 0;
}
int listall(tlist *list,int argc,char *argv[]){
char *fmt,**others;
fmt=NULL;
int iftotal=0;
Opts *optlist = opts(2,"f|forms:s",&fmt,"t|total:",&iftotal);
optloads(optlist,&others,argc,argv);
pall(list,srecon(fmt),iftotal);
return 0;
}
int statistic(tlist *list,int argc,char *argv[]){
iterlist *iter = newiter(list);
pttitle("%n\t%i\tperiod\n");
for(tele *ele;ele=liter(iter);){
if(ele->spndnextid==-1){
ptele(ele,"%n\t%i\t");
printf("%s\n",sgethprd(getprd(list,ele->name)));
}
}
return 0;
}
int help(){
printf(
"Usage:\n"
"\t"BOLD"start <name>"NONE" \tto start a activity.\n"
"\t"BOLD"end -i <id>"NONE" or "BOLD"end -n <name>"NONE" \tto end an activity.\n"
"\t"BOLD"list"NONE" \tto list all activities.\n"
"\t"BOLD"statistic"NONE" \t to statistic all activities.\n"
);
return 0;
}