HuntnGather – Diff between revs 15 and 19

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 15 Rev 19
Line 17... Line 17...
17   17  
18 #if !defined ___HAVE_GETOPT___ 18 #if !defined ___HAVE_GETOPT___
19 #include "getopt.h" 19 #include "getopt.h"
Line -... Line 20...
-   20 #endif
-   21  
20 #endif 22 #define PROGRAM_VERSION "1.7.2"
21   23  
22 #if defined ___AmigaOS___ 24 #if defined ___AmigaOS___
23 /*************************************************************************/ 25 /*************************************************************************/
24 /* Version string used for querrying the program version. */ 26 /* Version string used for querrying the program version. */
25 /*************************************************************************/ 27 /*************************************************************************/
26 TEXT version_string[] = 28 TEXT version_string[] =
Line 27... Line 29...
27 "\0$VER: Hunt 1.7 "__DATE__" by Wizardry and Steamworks"; 29 "\0$VER: Hunt " PROGRAM_VERSION " "__DATE__" by Wizardry and Steamworks";
28 #endif 30 #endif
29   31  
Line 52... Line 54...
52 int compare(char *name, char *need) { 54 int compare(char *name, char *need) {
53 #if defined ___AmigaOS___ 55 #if defined ___AmigaOS___
54 ULONG size; 56 ULONG size;
55 int success; 57 int success;
56 UBYTE *pattern; 58 UBYTE *pattern;
-   59 char *upe = name;
-   60 char *upn = need;
Line 57... Line 61...
57   61  
58 #if !defined ___NOCASE_FS___ 62 #if defined ___NOCASE_FS___
59 strupr(need); 63 upe = strupr(upe);
60 strupr(name); 64 upn = strupr(upn);
Line -... Line 65...
-   65 #endif
61 #endif 66  
Line 62... Line 67...
62   67 // "must be at least 2 times as large plus 2 bytes"
Line 63... Line 68...
63 size = strlen(need) * 3; 68 size = strlen(upn) * 2 + 2;
-   69  
-   70 success = FALSE;
-   71  
Line -... Line 72...
-   72 if(pattern = AllocVec(size, MEMF_ANY|MEMF_CLEAR)) {
64   73 switch(ParsePatternNoCase(upn, pattern, (LONG)size)) {
65 success = FALSE; 74 case 1: // the pattern contains wildcards
66   -  
67 if(pattern = AllocVec(size, MEMF_ANY|MEMF_CLEAR)) { -  
Line 68... Line 75...
68   75 success = MatchPatternNoCase(pattern, upe);
69 if(ParsePatternNoCase(need, pattern, (LONG)size) > 0) { 76  
Line 70... Line 77...
70 success = MatchPatternNoCase(pattern, name); 77 break;
71   78 case 0: // no wildcards so fall back to exact name match
Line 72... Line 79...
72 FreeVec(pattern); 79 success = (strstr(upe, upn) != NULL);
73   80  
74 return success; 81 break;
-   82 }
-   83  
Line 75... Line 84...
75 } 84 FreeVec(pattern);
Line 76... Line 85...
76   85 }
77 FreeVec(pattern); 86  
78 } 87 return success;
79   88 #else
Line 80... Line 89...
80 return success; 89 int success;
Line 81... Line -...
81 #else -  
82 int success; -  
83   90 char *upe = name;
84 success = FALSE; 91 char *upn = need;
85   92  
Line 117... Line 124...
117 fprintf(stderr, "Unable to open gather database for reading.\n"); 124 fprintf(stderr, "Unable to open gather database for reading.\n");
118 return; 125 return;
119 } 126 }
Line 120... Line 127...
120   127  
121 name_size = NAME_BUF; 128 name_size = NAME_BUF;
122 name = malloc(name_size * sizeof(char)); 129 name = malloc(name_size * sizeof(*name));
123 path_size = PATH_BUF; 130 path_size = PATH_BUF;
Line 124... Line 131...
124 path = malloc(path_size * sizeof(char)); 131 path = malloc(path_size * sizeof(*path));
125   132  
126 i = 0; 133 i = 0;
127 side = 0; 134 side = 0;
Line 145... Line 152...
145 match = FALSE; 152 match = FALSE;
146 } 153 }
147 if(name != NULL) { 154 if(name != NULL) {
148 free(name); 155 free(name);
149 name_size = NAME_BUF; 156 name_size = NAME_BUF;
150 name = malloc(name_size * sizeof(char)); 157 name = malloc(name_size * sizeof(*name));
151 } 158 }
152 --side; 159 --side;
153 i = 0; 160 i = 0;
154 break; 161 break;
155 case '\t': 162 case '\t':
Line 158... Line 165...
158 match = TRUE; 165 match = TRUE;
159 } 166 }
160 if(path != NULL) { 167 if(path != NULL) {
161 free(path); 168 free(path);
162 path_size = PATH_BUF; 169 path_size = PATH_BUF;
163 path = malloc(path_size * sizeof(char)); 170 path = malloc(path_size * sizeof(*name));
164 } 171 }
165 ++side; 172 ++side;
166 i = 0; 173 i = 0;
167 break; 174 break;
168 default: 175 default:
169 switch(side) { 176 switch(side) {
170 case 0: 177 case 0:
171 if(strlen(name) == name_size) { 178 if(strlen(name) == name_size) {
172 name_size = 1.5 * name_size; 179 name_size = 1.5 * name_size;
173 name = realloc(name, name_size * sizeof(char)); 180 name = realloc(name, name_size * sizeof(*name));
174 } 181 }
175 //name = realloc(name, (i + 1 + 1) * sizeof(char)); 182 //name = realloc(name, (i + 1 + 1) * sizeof(*name));
176 name[i] = c; 183 name[i] = c;
177 name[i + 1] = '\0'; 184 name[i + 1] = '\0';
178 break; 185 break;
179 case 1: 186 case 1:
180 if(strlen(path) == path_size) { 187 if(strlen(path) == path_size) {
181 path_size = 1.5 * path_size; 188 path_size = 1.5 * path_size;
182 path = realloc(path, path_size * sizeof(char)); 189 path = realloc(path, path_size * sizeof(*path));
183 } 190 }
184 //path = realloc(path, (i + 1 + 1) * sizeof(char)); 191 //path = realloc(path, (i + 1 + 1) * sizeof(*path));
185 path[i] = c; 192 path[i] = c;
186 path[i + 1] = '\0'; 193 path[i + 1] = '\0';
187 break; 194 break;
188 default: 195 default:
189 fprintf(stderr, "Database corrupted.\n"); 196 fprintf(stderr, "Database corrupted.\n");
Line 209... Line 216...
209 SearchDatabase(dbFile, need); 216 SearchDatabase(dbFile, need);
210 } 217 }
Line 211... Line 218...
211   218  
212 void usage(char *name) { 219 void usage(char *name) {
-   220 fprintf(stdout, "Hunt & Gather - %s, a file index search tool. \n", name);
213 fprintf(stdout, "Hunt & Gather - %s, a file index search tool. \n", name); 221 fprintf(stdout, "Version: %s \n", PROGRAM_VERSION);
214 fprintf(stdout, " \n"); 222 fprintf(stdout, " \n");
215 fprintf(stdout, "SYNTAX: %s [-d DATABASE] PATTERN \n", name); 223 fprintf(stdout, "SYNTAX: %s [-d DATABASE] PATTERN \n", name);
216 fprintf(stdout, " \n"); 224 fprintf(stdout, " \n");
217 fprintf(stdout, " -d DATABASE A path to a database generated by the \n"); 225 fprintf(stdout, " -d DATABASE A path to a database generated by the \n");