70 "\n %s -rs .c\n"; |
70 "\n %s -rs .c\n"; |
71 |
71 |
72 printf(helpText, prgName, prgName, prgName, prgName); |
72 printf(helpText, prgName, prgName, prgName, prgName); |
73 } |
73 } |
74 |
74 |
|
75 int exit_with_help(char* prgName, settings_t* settings, int code) { |
|
76 printHelpText(prgName); |
|
77 destroy_settings_t(settings); |
|
78 return code; |
|
79 } |
|
80 |
75 int main(int argc, char** argv) { |
81 int main(int argc, char** argv) { |
76 |
82 |
77 // Settings |
83 // Settings |
78 settings_t *settings = new_settings_t(); |
84 settings_t *settings = new_settings_t(); |
79 if (settings == NULL) { |
85 if (settings == NULL) { |
92 |
98 |
93 // Get arguments |
99 // Get arguments |
94 char* directory = "./"; |
100 char* directory = "./"; |
95 char* suffix = " "; |
101 char* suffix = " "; |
96 bool showHelp = false; |
102 bool showHelp = false; |
97 char checked = 0; |
103 int checked = 0; |
98 |
104 |
99 for (int t = 1 ; t < argc ; t++) { |
105 for (int t = 1 ; t < argc ; t++) { |
100 |
106 |
101 int argflags = checkArgument(argv[t], "hsSrRm"); |
107 int argflags = checkArgument(argv[t], "hsSrRm"); |
102 |
108 |
103 // s |
109 // s |
104 if ((argflags & 2) > 0) { |
110 if ((argflags & 2) > 0) { |
105 if ((checked & 1) > 0) { |
111 if (registerArgument(&checked, 6)) { |
106 printHelpText(prgName); |
112 return exit_with_help(prgName, settings, 1); |
107 destroy_settings_t(settings); |
|
108 return 1; |
|
109 } |
113 } |
110 settings->includeSuffixes = true; |
114 settings->includeSuffixes = true; |
111 t++; |
115 t++; |
112 if (t >= argc) { |
116 if (t >= argc) { |
113 printHelpText(prgName); |
117 return exit_with_help(prgName, settings, 1); |
114 destroy_settings_t(settings); |
|
115 return 1; |
|
116 } |
118 } |
117 suffix = argv[t]; |
119 suffix = argv[t]; |
118 checked |= 1; |
|
119 } |
120 } |
120 // S |
121 // S |
121 if ((argflags & 4) > 0) { |
122 if ((argflags & 4) > 0) { |
122 if ((checked & 1) > 0) { |
123 if (registerArgument(&checked, 6)) { |
123 printHelpText(prgName); |
124 return exit_with_help(prgName, settings, 1); |
124 destroy_settings_t(settings); |
|
125 return 1; |
|
126 } |
125 } |
127 settings->includeSuffixes = false; |
126 settings->includeSuffixes = false; |
128 t++; |
127 t++; |
129 if (t >= argc) { |
128 if (t >= argc) { |
130 printHelpText(prgName); |
129 return exit_with_help(prgName, settings, 1); |
131 destroy_settings_t(settings); |
|
132 return 1; |
|
133 } |
130 } |
134 suffix = argv[t]; |
131 suffix = argv[t]; |
135 checked |= 1; |
|
136 } |
132 } |
137 // h |
133 // h |
138 if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { |
134 if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { |
139 if ((checked & 2) > 0) { |
135 if (registerArgument(&checked, 1)) { |
140 printHelpText(prgName); |
136 return exit_with_help(prgName, settings, 1); |
141 destroy_settings_t(settings); |
137 } |
142 return 1; |
|
143 } |
|
144 checked |= 2; |
|
145 showHelp = true; |
138 showHelp = true; |
146 } |
139 } |
147 // r, R |
140 // r, R |
148 if ((argflags & 24) > 0) { |
141 if ((argflags & 24) > 0) { |
149 if ((checked & 4) > 0) { |
142 if (registerArgument(&checked, 24)) { |
150 printHelpText(prgName); |
143 return exit_with_help(prgName, settings, 1); |
151 destroy_settings_t(settings); |
144 } |
152 return 1; |
|
153 } |
|
154 checked |= 4; |
|
155 settings->recursive = true; |
145 settings->recursive = true; |
156 } |
146 } |
|
147 // m |
157 if ((argflags & 32) > 0) { |
148 if ((argflags & 32) > 0) { |
158 if ((checked & 32) > 0) { |
149 if (registerArgument(&checked, 32)) { |
159 printHelpText(prgName); |
150 return exit_with_help(prgName, settings, 1); |
160 destroy_settings_t(settings); |
151 } |
161 return 1; |
|
162 } |
|
163 checked |= 32; |
|
164 settings->matchesOnly = true; |
152 settings->matchesOnly = true; |
165 } |
153 } |
166 // Path |
154 // Path |
167 if (argflags == 0) { |
155 if (argflags == 0) { |
168 if ((checked & 8) > 0) { |
156 if (registerArgument(&checked, 1024)) { |
169 printHelpText(prgName); |
157 return exit_with_help(prgName, settings, 1); |
170 destroy_settings_t(settings); |
158 } |
171 return 1; |
|
172 } |
|
173 checked |= 8; |
|
174 directory = argv[t]; |
159 directory = argv[t]; |
175 } |
160 } |
176 } |
161 } |
177 |
162 |
178 // Show help and quit |
163 // Show help and quit |
179 if (showHelp) { |
164 if (showHelp) { |
180 printHelpText(prgName); |
165 return exit_with_help(prgName, settings, 0); |
181 destroy_settings_t(settings); |
|
182 return 0; |
|
183 } |
166 } |
184 |
167 |
185 // Find tokens |
168 // Find tokens |
186 char* finder = strtok(suffix, ","); |
169 char* finder = strtok(suffix, ","); |
187 while (finder != NULL) { |
170 while (finder != NULL) { |