1 #ifndef INCLUDE_CMDLINE
2 #define INCLUDE_CMDLINE
6 #include "./patch_sta.h"
8 #define IS_NUMBER(tmp, char) \
9 while (*tmp != '\0') { \
10 if (!isdigit(*tmp)) { \
11 printf("[ERROR]: -%c should followed "\
12 "by a number\n", char);\
18 static inline int int_toobig(int num
)
25 int check_option(char *p
)
30 /* FIXME -- WCN: I am lazy ... */
31 if (*(p
+1) != 'a' && *(p
+1) != 'c' && *(p
+1) != 'C' && *(p
+1) != 'm' &&
32 *(p
+1) != 'M' && *(p
+1) != 'x' && *(p
+1) != 'h' && *(p
+1) != 'n' &&
33 *(p
+1) != 'l' && *(p
+1) != 'L' && *(p
+1) != 's' && *(p
+1) != 'r' &&
34 *(p
+1) != 'N' && *(p
+1) != 'O' && *(p
+1) != 'w' && *(p
+1) != 'e' &&
35 *(p
+1) != 'I' && *(p
+1) != 't' && *(p
+1) != 'i')
41 int get_command_option(int argc
, char **argv
, int index
, char *aopt
)
53 if (strlen(p
) > 2 || (-1 == check_option(p
))) {
54 printf("[ERROR]: %s Invalidata option!\n", p
);
58 /* First option should be input file or -h */
63 fprintf(stderr
,"[ERROR]: First option "\
64 "should be input file or -h.\n");
69 if (aopt
[(int)(*(p
+1))] == 1) {
70 printf("[ERROR]: -%c is repeat!\n", *(p
+1));
78 if ((argc
-1) == index
|| (*(argv
[index
+1]) == '-'))
79 if ((opt
!= 'a') && (opt
!= 'h') && (opt
!= 'n') &&
80 (opt
!= 'L') && (opt
!= 'w') && (opt
!= 'e') &&
81 (opt
!= 'I') && (opt
!= 'i')) {
82 printf("[ERROR]: Option -%c lost value!\n", opt
);
88 int parse_command_line(int argc
, char **argv
)
95 program_name
= argv
[0];
98 printf("[ERROR]: Please give me the input file's name\n");
103 memset(aopt
, 0, 256);
110 opt
= get_command_option(argc
, argv
, index
, aopt
);
141 p_comtop
= strtod(argv
[index
], NULL
);
142 if (int_toobig((int)p_comtop
)) {
143 printf("TOPX is too big.\n"
144 "Should be less than %u\n", INT_MAX
);
160 p_tail
= strtod(argv
[index
], NULL
);
161 if (int_toobig((int)p_tail
)) {
162 printf("Tail limit is too big.\n"
163 "Should be less than %u\n", INT_MAX
);
170 p_nation
= argv
[index
];
171 if ((*p_nation
) == '-')
177 p_person
= argv
[index
];
178 if ((*p_person
) == '-')
186 p_pertop
= strtod(argv
[index
], NULL
);
187 if (int_toobig((int)p_pertop
)) {
188 printf("TOPX is too big.\n"
189 "Should be less than %u\n", INT_MAX
);
196 p_html
= argv
[index
];
197 if ((*p_html
) == '-')
203 p_cnty
= argv
[index
];
204 if ((*p_cnty
) == '-')
209 g_nat_interest
= SELECT
;
210 p_nat_interest
= argv
[index
];
211 if ((*p_nat_interest
) == '-')
230 p_other
= argv
[index
];
231 if ((*p_other
) == '-')
233 if (strcmp(p_other
, "report") == 0) {
234 other
= OTHER_REPORT
;
236 } else if (strcmp(p_other
, "review") == 0) {
237 other
= OTHER_REVIEW
;
239 } else if (strcmp(p_other
, "test") == 0) {
242 } else if (strcmp(p_other
, "ack") == 0) {
245 } else if (strcmp(p_other
, "sof") == 0) {
255 if ((g_interest
== SELECT
|| g_nat_interest
== SELECT
) && g_line
== SELECT
)
258 for (i
= 0; i
< 256; i
++)