HuntnGather – Diff between revs 29 and 33
?pathlinks?
Rev 29 | Rev 33 | |||
---|---|---|---|---|
Line 13... | Line 13... | |||
13 | #endif |
13 | #endif |
|
Line 14... | Line 14... | |||
14 | |
14 | |
|
Line 15... | Line 15... | |||
15 | #include <sys/types.h> |
15 | #include <sys/types.h> |
|
- | 16 | |
||
16 | |
17 | #if defined ___AmigaOS___ |
|
17 | #if defined ___AmigaOS___ |
18 | |
|
18 | #include <proto/dos.h> |
19 | #include <proto/dos.h> |
|
19 | #include <proto/exec.h> |
20 | #include <proto/exec.h> |
|
Line 20... | Line 21... | |||
20 | #include <proto/utility.h> |
21 | #include <proto/utility.h> |
|
21 | #endif |
22 | #endif |
|
22 | |
23 | |
|
Line 23... | Line 24... | |||
23 | #if defined ___AsyncIO___ |
24 | #if defined ___AsyncIO___ |
|
24 | #include <asyncio.h> |
25 | #include <asyncio.h> |
|
25 | #endif |
26 | #endif |
|
Line -... | Line 27... | |||
- | 27 | |
||
- | 28 | #if !defined ___HAVE_GETOPT___ |
||
26 | |
29 | #include "/shared/getopt.h" |
|
Line 27... | Line 30... | |||
27 | #if !defined ___HAVE_GETOPT___ |
30 | #endif |
|
28 | #include "getopt.h" |
31 | |
|
29 | #endif |
32 | #include "/shared/utilities.h" |
|
30 | |
33 | |
|
31 | #define PROGRAM_VERSION "1.7.4" |
34 | #define PROGRAM_VERSION "1.7.4" |
|
32 | |
35 | |
|
33 | #if defined ___AmigaOS___ |
36 | #if defined ___AmigaOS___ |
|
Line 34... | Line 37... | |||
34 | /*************************************************************************/ |
37 | /*************************************************************************/ |
|
35 | /* Version string used for querrying the program version. */ |
- | ||
36 | /*************************************************************************/ |
- | ||
37 | TEXT version_string[] = |
- | ||
38 | "\0$VER: Hunt " PROGRAM_VERSION " "__DATE__" by Wizardry and Steamworks"; |
- | ||
39 | #endif |
- | ||
40 | |
- | ||
41 | #if !defined TRUE |
- | ||
42 | #define TRUE 1; |
- | ||
43 | #endif |
- | ||
44 | |
- | ||
45 | #if !defined FALSE |
- | ||
46 | #define FALSE 0; |
- | ||
47 | #endif |
38 | /* Version string used for querrying the program version. */ |
|
Line 48... | Line 39... | |||
48 | |
39 | /*************************************************************************/ |
|
49 | #define ASYNC_BUF 8192 |
40 | TEXT version_string[] = |
|
50 | #define NAME_BUF 32 |
41 | "\0$VER: Hunt " PROGRAM_VERSION " "__DATE__" by Wizardry and Steamworks"; |
|
51 | #define PATH_BUF 128 |
- | ||
52 | #define DEFAULT_DATABASE_FILE "S:gather.db" |
- | ||
53 | |
- | ||
54 | int run = TRUE; |
- | ||
55 | |
- | ||
56 | void SignalHandler(int sig) { |
- | ||
57 | // Toggle the run flag to stop execution. |
- | ||
58 | run = FALSE; |
- | ||
59 | } |
- | ||
60 | |
- | ||
61 | /* |
- | ||
62 | * |
- | ||
63 | * Returns largest of strings. |
- | ||
64 | */ |
- | ||
65 | #if defined ___AmigaOS___ |
- | ||
66 | LONG StringLenMax(char *a, char *b) { |
- | ||
67 | LONG p = strlen(a); |
42 | #endif |
|
Line 68... | Line 43... | |||
68 | LONG q = strlen(b); |
43 | |
|
69 | #else |
44 | int PROGRAM_RUN = TRUE; |
|
70 | int StrlenMax(char *a, char *b) { |
45 | int PROGRAM_VERBOSE = FALSE; |
|
Line 118... | Line 93... | |||
118 | char *n = b; |
93 | char *n = b; |
|
Line 119... | Line 94... | |||
119 | |
94 | |
|
Line 120... | Line 95... | |||
120 | success = FALSE; |
95 | success = FALSE; |
|
121 | |
96 | |
|
122 | #if defined ___NOCASE_FS___ |
97 | #if defined ___NOCASE_FS___ |
|
123 | e = strupr(e); |
98 | e = StrUpr(e); |
|
Line 124... | Line 99... | |||
124 | n = strupr(n); |
99 | n = StrUpr(n); |
|
125 | #endif |
100 | #endif |
|
Line 156... | Line 131... | |||
156 | #if defined ___AsyncIO___ |
131 | #if defined ___AsyncIO___ |
|
157 | if((fp = OpenAsync(dbFile, MODE_READ, ASYNC_BUF)) == NULL) { |
132 | if((fp = OpenAsync(dbFile, MODE_READ, ASYNC_BUF)) == NULL) { |
|
158 | #else |
133 | #else |
|
159 | if((fp = fopen(dbFile, "r")) == NULL) { |
134 | if((fp = fopen(dbFile, "r")) == NULL) { |
|
160 | #endif |
135 | #endif |
|
161 | fprintf(stderr, "Unable to open '%s' for reading.\n", dbFile); |
136 | fprintf(stderr, "Could not open '%s' for reading.\n", dbFile); |
|
162 | return; |
137 | return; |
|
163 | } |
138 | } |
|
Line 164... | Line 139... | |||
164 | |
139 | |
|
165 | name_size = NAME_BUF; |
140 | name_size = NAME_BUF; |
|
Line 171... | Line 146... | |||
171 | side = 0; |
146 | side = 0; |
|
172 | match = FALSE; |
147 | match = FALSE; |
|
173 | total = 0; |
148 | total = 0; |
|
Line 174... | Line 149... | |||
174 | |
149 | |
|
175 | #if defined ___AsyncIO___ |
150 | #if defined ___AsyncIO___ |
|
176 | while(run && (c = ReadCharAsync(fp)) != -1) { |
151 | while(PROGRAM_RUN && (c = ReadCharAsync(fp)) != -1) { |
|
177 | #else |
152 | #else |
|
178 | while(run && fscanf(fp, "%c", &c) == 1) { |
153 | while(PROGRAM_RUN && fscanf(fp, "%c", &c) == 1) { |
|
179 | #endif |
154 | #endif |
|
180 | #if defined ___AmigaOS___ |
155 | #if defined ___AmigaOS___ |
|
181 | // Check if CTRL+C was pressed and abort the program. |
156 | // Check if CTRL+C was pressed and abort the program. |
|
182 | if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { |
157 | if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { |
|
183 | run = FALSE; |
158 | PROGRAM_RUN = FALSE; |
|
184 | continue; |
159 | continue; |
|
185 | } |
160 | } |
|
Line 186... | Line 161... | |||
186 | #endif |
161 | #endif |
|
Line 272... | Line 247... | |||
272 | fprintf(stdout, " \n"); |
247 | fprintf(stdout, " \n"); |
|
273 | fprintf(stdout, "(c) 2021 Wizardry and Steamworks, MIT. \n"); |
248 | fprintf(stdout, "(c) 2021 Wizardry and Steamworks, MIT. \n"); |
|
274 | } |
249 | } |
|
Line 275... | Line 250... | |||
275 | |
250 | |
|
276 | int main(int argc, char **argv) { |
- | ||
277 | #if defined ___AmigaOS___ |
- | ||
278 | struct FileInfoBlock *FIB; |
- | ||
279 | BPTR lock; |
- | ||
280 | #else |
- | ||
281 | struct stat dirStat; |
- | ||
282 | #endif |
251 | int main(int argc, char **argv) { |
|
283 | int option; |
252 | int option; |
|
Line 284... | Line 253... | |||
284 | char *dbFile; |
253 | char *dbFile; |
|
285 | |
254 | |
|
Line 306... | Line 275... | |||
306 | if(optind >= argc) { |
275 | if(optind >= argc) { |
|
307 | usage(argv[0]); |
276 | usage(argv[0]); |
|
308 | return 1; |
277 | return 1; |
|
309 | } |
278 | } |
|
Line 310... | Line 279... | |||
310 | |
279 | |
|
- | 280 | switch(GetFsType(dbFile)) { |
||
311 | #if defined ___AmigaOS___ |
281 | case UNKNOWN: |
|
312 | if((lock = Lock(dbFile, ACCESS_READ)) == NULL) { |
282 | case DIRECTORY: |
|
313 | fprintf(stderr, "Path '%s' is not accessible.\n", dbFile); |
283 | fprintf(stderr, "'%s' is not a file.\n", dbFile); |
|
314 | return 1; |
- | ||
315 | } |
- | ||
316 | |
284 | return 1; |
|
317 | if((FIB = AllocDosObject(DOS_FIB, NULL)) == NULL) { |
- | ||
318 | fprintf(stderr, "Path '%s' file information block not accessible.\n", dbFile); |
285 | case REGULAR: |
|
319 | UnLock(lock); |
286 | Hunt(dbFile, argv[optind]); |
|
320 | return 1; |
287 | break; |
|
Line 321... | Line -... | |||
321 | } |
- | ||
322 | |
- | ||
323 | if(Examine(lock, FIB) == FALSE) { |
- | ||
324 | fprintf(stderr, "Path '%s' information unexaminable.\n", dbFile); |
- | ||
325 | FreeDosObject(DOS_FIB, FIB); |
- | ||
326 | UnLock(lock); |
- | ||
327 | return 1; |
- | ||
328 | } |
- | ||
329 | |
- | ||
330 | if(FIB->fib_DirEntryType > 0) { |
- | ||
331 | #else |
- | ||
332 | stat(dbFile, &dirStat); |
- | ||
333 | if(!S_ISREG(dirStat.st_mode)) { |
- | ||
334 | #endif |
- | ||
335 | fprintf(stderr, "'%s' is not a file.\n", dbFile); |
- | ||
336 | return 1; |
- | ||
337 | } |
- | ||
338 | |
- | ||
339 | #if defined ___AmigaOS___ |
- | ||
340 | FreeDosObject(DOS_FIB, FIB); |
- | ||
341 | UnLock(lock); |
- | ||
342 | #endif |
- | ||
343 | |
- | ||
344 | Hunt(dbFile, argv[optind]); |
288 | } |
|
345 | |
289 | |