HuntnGather – Diff between revs 10 and 11

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 10 Rev 11
Line 22... Line 22...
22 #if defined ___AmigaOS___ 22 #if defined ___AmigaOS___
23 /*************************************************************************/ 23 /*************************************************************************/
24 /* Version string used for querrying the program version. */ 24 /* Version string used for querrying the program version. */
25 /*************************************************************************/ 25 /*************************************************************************/
26 TEXT version_string[] = 26 TEXT version_string[] =
27 "\0$VER: Hunt 1.6 "__DATE__" by Wizardry and Steamworks"; 27 "\0$VER: Hunt 1.7 "__DATE__" by Wizardry and Steamworks";
28 #endif 28 #endif
Line 29... Line 29...
29   29  
30 #if !defined TRUE 30 #if !defined TRUE
31 #define TRUE 1; 31 #define TRUE 1;
Line 32... Line 32...
32 #endif 32 #endif
33   33  
34 #if !defined FALSE 34 #if !defined FALSE
Line -... Line 35...
-   35 #define FALSE 0;
-   36 #endif
35 #define FALSE 0; 37  
Line 36... Line 38...
36 #endif 38 #define NAME_BUF 32
Line 37... Line 39...
37   39 #define PATH_BUF 128
Line 49... Line 51...
49 */ 51 */
50 char *strupr(char *str) { 52 char *strupr(char *str) {
51 char *up; 53 char *up;
52 int i; 54 int i;
Line 53... Line 55...
53   55  
54 up = (char *) malloc((strlen(str) + 1) * sizeof(char)); 56 up = malloc((strlen(str) + 1) * sizeof(char));
Line 55... Line 57...
55 sprintf(up, "%s", str); 57 sprintf(up, "%s", str);
56   58  
57 i = strlen(up); 59 i = strlen(up);
Line 119... Line 121...
119 * Search the database for a matching string. 121 * Search the database for a matching string.
120 */ 122 */
121 void SearchDatabase(char *dbFile, char* need) { 123 void SearchDatabase(char *dbFile, char* need) {
122 FILE *fp; 124 FILE *fp;
123 char *name; 125 char *name;
-   126 int name_size;
124 char *path; 127 char *path;
-   128 int path_size;
125 char c; 129 char c;
126 int i; 130 int i;
127 int side; 131 int side;
128 int match; 132 int match;
129 int total; 133 int total;
Line 131... Line 135...
131 if((fp = fopen(dbFile, "r")) == NULL) { 135 if((fp = fopen(dbFile, "r")) == NULL) {
132 fprintf(stderr, "Unable to open gather database for reading.\n"); 136 fprintf(stderr, "Unable to open gather database for reading.\n");
133 return; 137 return;
134 } 138 }
Line -... Line 139...
-   139  
135   140 name_size = NAME_BUF;
-   141 name = malloc(name_size * sizeof(char));
136 name = (char *) malloc(sizeof(char)); 142 path_size = PATH_BUF;
Line 137... Line 143...
137 path = (char *) malloc(sizeof(char)); 143 path = malloc(path_size * sizeof(char));
138   144  
139 i = 0; 145 i = 0;
140 side = 0; 146 side = 0;
Line 157... Line 163...
157 fprintf(stdout, "%s\n", path); 163 fprintf(stdout, "%s\n", path);
158 match = FALSE; 164 match = FALSE;
159 } 165 }
160 if(name != NULL) { 166 if(name != NULL) {
161 free(name); 167 free(name);
-   168 name_size = NAME_BUF;
162 name = (char *) malloc(sizeof(char)); 169 name = malloc(name_size * sizeof(char));
163 } 170 }
164 --side; 171 --side;
165 i = 0; 172 i = 0;
166 break; 173 break;
167 case '\t': 174 case '\t':
Line 169... Line 176...
169 if(compare(name, need)) { 176 if(compare(name, need)) {
170 match = TRUE; 177 match = TRUE;
171 } 178 }
172 if(path != NULL) { 179 if(path != NULL) {
173 free(path); 180 free(path);
-   181 path_size = PATH_BUF;
174 path = (char *) malloc(sizeof(char)); 182 path = malloc(path_size * sizeof(char));
175 } 183 }
176 ++side; 184 ++side;
177 i = 0; 185 i = 0;
178 break; 186 break;
179 default: 187 default:
180 switch(side) { 188 switch(side) {
181 case 0: 189 case 0:
-   190 if(strlen(name) == name_size) {
-   191 name_size = 1.5 * name_size;
-   192 name = realloc(name, name_size * sizeof(char));
-   193 }
182 name = (char *) realloc(name, (i + 1 + 1) * sizeof(char)); 194 //name = realloc(name, (i + 1 + 1) * sizeof(char));
183 name[i] = c; 195 name[i] = c;
184 name[i + 1] = '\0'; 196 name[i + 1] = '\0';
185 break; 197 break;
186 case 1: 198 case 1:
-   199 if(strlen(path) == path_size) {
-   200 path_size = 1.5 * path_size;
-   201 path = realloc(path, path_size * sizeof(char));
-   202 }
187 path = (char *) realloc(path, (i + 1 + 1) * sizeof(char)); 203 //path = realloc(path, (i + 1 + 1) * sizeof(char));
188 path[i] = c; 204 path[i] = c;
189 path[i + 1] = '\0'; 205 path[i + 1] = '\0';
190 break; 206 break;
191 default: 207 default:
192 fprintf(stderr, "Database corrupted.\n"); 208 fprintf(stderr, "Database corrupted.\n");
Line 210... Line 226...
210 void Hunt(char *dbFile, char *need) { 226 void Hunt(char *dbFile, char *need) {
211 // Search the database for the matching string. 227 // Search the database for the matching string.
212 SearchDatabase(dbFile, need); 228 SearchDatabase(dbFile, need);
213 } 229 }
Line -... Line 230...
-   230  
-   231 void usage(char *name) {
-   232 fprintf(stdout, "Hunt & Gather - %s, a file index search tool. \n", name);
-   233 fprintf(stdout, " \n");
-   234 fprintf(stdout, "SYNTAX: %s [-d DATABASE] PATTERN \n", name);
-   235 fprintf(stdout, " \n");
-   236 fprintf(stdout, " -d DATABASE A path to a database generated by the \n");
-   237 fprintf(stdout, " Gather tool that should be searched. \n");
-   238 fprintf(stdout, " \n");
-   239 fprintf(stdout, "PATTERN is an AmigaOS DOS pattern to match file names. \n");
-   240 fprintf(stdout, " \n");
-   241 fprintf(stdout, "(c) 2021 Wizardry and Steamworks, MIT. \n");
-   242 }
214   243  
215 int main(int argc, char **argv) { 244 int main(int argc, char **argv) {
216 int option; 245 int option;
217 char *dbFile; 246 char *dbFile;
Line 225... Line 254...
225 switch(option) { 254 switch(option) {
226 case 'd': 255 case 'd':
227 dbFile = optarg; 256 dbFile = optarg;
228 break; 257 break;
229 case 'h': 258 case 'h':
230 fprintf(stdout, "SYNTAX: %s [-d DATABASE] PATTERN\n", argv[0]); 259 usage(argv[0]);
231 return 0; 260 return 0;
232 case '?': 261 case '?':
233 fprintf(stderr, "Invalid option %c.\n", optopt); 262 fprintf(stderr, "Invalid option %c.\n", optopt);;
234 fprintf(stdout, "SYNTAX: %s [-d DATABASE] PATTERN\n", argv[0]); -  
235 return 1; 263 return 1;
236 } 264 }
237 } 265 }
Line 238... Line 266...
238   266  
239 if(optind >= argc) { 267 if(optind >= argc) {
240 fprintf(stdout, "SYNTAX: %s [-d DATABASE] PATTERN\n", argv[0]); 268 usage(argv[0]);
241 return 1; 269 return 1;
Line 242... Line 270...
242 } 270 }
243   271