cline.c

changeset 30
d642fdb6745e
parent 28
72a98cbcb9f1
child 31
27c3c1c6b768
equal deleted inserted replaced
29:fa625066ae52 30:d642fdb6745e
73 return 1; 73 return 1;
74 } 74 }
75 75
76 /* Get arguments */ 76 /* Get arguments */
77 char* directory = "./"; 77 char* directory = "./";
78 char* suffix = " "; 78 char* includeSuffix = NULL;
79 char* excludeSuffix = NULL;
79 int checked = 0; 80 int checked = 0;
80 81
81 for (int t = 1 ; t < argc ; t++) { 82 for (int t = 1 ; t < argc ; t++) {
82 83
83 int argflags = checkArgument(argv[t], "hsSrRmvVbeE"); 84 int argflags = checkArgument(argv[t], "hsSrRmvVbeE");
84 85 int paropt = 0;
85 /* s, S */ 86
86 if ((argflags & 6) > 0) { 87 /* s */
87 if (registerArgument(&checked, 6)) { 88 if ((argflags & 2) > 0) {
88 return exit_with_help(settings, 1); 89 if (!checkParamOpt(&paropt) || registerArgument(&checked, 2)) {
89 } 90 return exit_with_help(settings, 1);
90 settings->includeSuffixes = (argflags & 2) > 0; 91 }
91 t++; 92 t++;
92 if (t >= argc) { 93 if (t >= argc) {
93 return exit_with_help(settings, 1); 94 return exit_with_help(settings, 1);
94 } 95 }
95 suffix = argv[t]; 96 includeSuffix = argv[t];
97 }
98 /* S */
99 if ((argflags & 4) > 0) {
100 if (!checkParamOpt(&paropt) || registerArgument(&checked, 4)) {
101 return exit_with_help(settings, 1);
102 }
103 t++;
104 if (t >= argc) {
105 return exit_with_help(settings, 1);
106 }
107 excludeSuffix = argv[t];
96 } 108 }
97 /* h */ 109 /* h */
98 if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { 110 if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) {
99 return exit_with_help(settings, 0); 111 return exit_with_help(settings, 0);
100 } 112 }
123 } 135 }
124 settings->verbose = false; 136 settings->verbose = false;
125 } 137 }
126 /* b */ 138 /* b */
127 if ((argflags & 256) > 0) { 139 if ((argflags & 256) > 0) {
128 if (registerArgument(&checked, 256)) { 140 if (!checkParamOpt(&paropt) || registerArgument(&checked, 256)) {
129 return exit_with_help(settings, 1); 141 return exit_with_help(settings, 1);
130 } 142 }
131 t++; 143 t++;
132 if (t >= argc) { 144 if (t >= argc) {
133 return exit_with_help(settings, 1); 145 return exit_with_help(settings, 1);
144 return exit_with_help(settings, 1); 156 return exit_with_help(settings, 1);
145 } 157 }
146 } 158 }
147 /* e */ 159 /* e */
148 if ((argflags & 512) > 0) { 160 if ((argflags & 512) > 0) {
149 if (t + 2 >= argc) { 161 if (!checkParamOpt(&paropt) || t + 2 >= argc) {
150 return exit_with_help(settings, 1); 162 return exit_with_help(settings, 1);
151 } 163 }
152 t++; add_string(settings->regex->pattern_list, argv[t]); 164 t++; add_string(settings->regex->pattern_list, argv[t]);
153 t++; add_string(settings->regex->pattern_list, argv[t]); 165 t++; add_string(settings->regex->pattern_list, argv[t]);
154 } 166 }
155 /* E */ 167 /* E */
156 if ((argflags & 1024) > 0) { 168 if ((argflags & 1024) > 0) {
157 t++; 169 t++;
158 if (t >= argc) { 170 if (!checkParamOpt(&paropt) || t >= argc) {
159 return exit_with_help(settings, 1); 171 return exit_with_help(settings, 1);
160 } 172 }
161 add_string(settings->regex->pattern_list, argv[t]); 173 add_string(settings->regex->pattern_list, argv[t]);
162 add_string(settings->regex->pattern_list, "$"); 174 add_string(settings->regex->pattern_list, "$");
163 } 175 }
174 if (!settings->verbose) { 186 if (!settings->verbose) {
175 close_stdout(); 187 close_stdout();
176 } 188 }
177 189
178 /* Find tokens */ 190 /* Find tokens */
179 char* finder = strtok(suffix, ","); 191 parseCSL(includeSuffix, settings->includeSuffixes);
180 while (finder != NULL) { 192 parseCSL(excludeSuffix, settings->excludeSuffixes);
181 add_string(settings->suffixList, finder);
182 finder = strtok(NULL, ",");
183 }
184 193
185 /* Scan directory */ 194 /* Scan directory */
186 if (regex_compile_all(settings->regex)) { 195 if (regex_compile_all(settings->regex)) {
187 int lines = scanDirectory((scanner_t){directory, 0}, settings); 196 int lines = scanDirectory((scanner_t){directory, 0}, settings);
188 destroy_settings_t(settings); 197 destroy_settings_t(settings);

mercurial