-
Notifications
You must be signed in to change notification settings - Fork 0
/
args.h
57 lines (52 loc) · 1.38 KB
/
args.h
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
#include "lib/macros.h"
#include <stdio.h>
struct OPTION{
const char*url,*title,*color,*file;
bool help,reset,url_read,title_read,color_read;
};
void printOptions(OPTION*op){
printf("url:%s\ntitle:%s\ncolor:%s\nfile:%s\n",
op->url,
op->title,
op->color,
op->file);
printf("help:%d\nreset:%d\n-u:%d\n-t:%d\n-c:%d\n",
op->help,op->reset,op->url_read,op->title_read,op->color_read);
}
void optput(OPTION*op,const char*key,const char*val){
if(streq(key,"-u"))op->url=val;
else if(streq(key,"-t"))op->title=val;
else if(streq(key,"-c"))op->color=val;
else if(streq(key,"-f"))op->file=val;
}
void optflag(OPTION*op,const char*key){
if(streq(key,"-h")||streq(key,"--help"))op->help=true;
else if(streq(key,"-reset"))op->reset=true;
else if(streq(key,"-u"))op->url_read=true;
else if(streq(key,"-t"))op->title_read=true;
else if(streq(key,"-c"))op->color_read=true;
}
void showHelp(){
printf("Usage: screenxtv [options]\n");
printf(" -u [url]\n");
printf(" -c [color]\n");
printf(" -t [title]\n");
printf(" -reset\n");
printf(" -f config_file\n");
}
OPTION parseArgs(char**argv){
char*prev=NULL;
OPTION op={NULL,NULL,NULL,NULL,false,false};
for(;*argv;argv++){
char*s=*argv;
if(s[0]=='-'){
if(prev)optflag(&op,prev);
prev=s;
}else{
if(prev)optput(&op,prev,s);
prev=NULL;
}
}
if(prev)optflag(&op,prev);
return op;
}