HuntnGather – Diff between revs 1 and 2
?pathlinks?
Rev 1 | Rev 2 | |||
---|---|---|---|---|
Line 3... | Line 3... | |||
3 | /////////////////////////////////////////////////////////////////////////// |
3 | /////////////////////////////////////////////////////////////////////////// |
|
Line 4... | Line 4... | |||
4 | |
4 | |
|
5 | #include <stdio.h> |
5 | #include <stdio.h> |
|
6 | #include <stdlib.h> |
6 | #include <stdlib.h> |
|
- | 7 | #include <string.h> |
||
7 | #include <string.h> |
8 | #include <dirent.h> |
|
8 | #include <signal.h> |
9 | #include <signal.h> |
|
Line -... | Line 10... | |||
- | 10 | #include <ctype.h> |
||
- | 11 | |
||
- | 12 | #include <sys/types.h> |
||
9 | #include <ctype.h> |
13 | #include <sys/stat.h> |
|
10 | |
14 | |
|
Line 11... | Line 15... | |||
11 | #include <proto/dos.h> |
15 | #include <proto/dos.h> |
|
12 | #include <proto/exec.h> |
16 | #include <proto/exec.h> |
|
Line 21... | Line 25... | |||
21 | |
25 | |
|
22 | #if !defined FALSE |
26 | #if !defined FALSE |
|
23 | #define FALSE 0; |
27 | #define FALSE 0; |
|
Line -... | Line 28... | |||
- | 28 | #endif |
||
- | 29 | |
||
24 | #endif |
30 | #define DEFAULT_DATABASE_FILE "S:gather.db" |
|
25 | |
31 | |
|
26 | /*************************************************************************/ |
32 | /*************************************************************************/ |
|
27 | /* Version string used for querrying the program version. */ |
33 | /* Version string used for querrying the program version. */ |
|
28 | /*************************************************************************/ |
34 | /*************************************************************************/ |
|
Line 29... | Line 35... | |||
29 | TEXT version_string[] = |
35 | TEXT version_string[] = |
|
Line 30... | Line 36... | |||
30 | "\0$VER: Hunt 1.2 "__DATE__" by Wizardry and Steamworks"; |
36 | "\0$VER: Hunt 1.3 "__DATE__" by Wizardry and Steamworks"; |
|
31 | |
37 | |
|
32 | int run = TRUE; |
38 | int run = TRUE; |
|
33 | |
39 | |
|
Line 34... | Line 40... | |||
34 | void SignalHandler(int sig) { |
40 | void SignalHandler(int sig) { |
|
35 | // Toggle the run flag to stop execution. |
- | ||
36 | run = FALSE; |
- | ||
37 | } |
- | ||
38 | |
- | ||
39 | /* |
- | ||
40 | * |
- | ||
41 | * Counts the lines in a database file "dbFile". |
- | ||
42 | */ |
- | ||
43 | int CountDatabaseLines(char *dbFile) { |
- | ||
44 | FILE *fp; |
- | ||
45 | int lines; |
- | ||
46 | char c; |
- | ||
47 | |
- | ||
48 | if((fp = fopen(dbFile, "r")) == NULL) { |
- | ||
49 | fprintf(stderr, "Unable to open gather database for reading.\n"); |
- | ||
50 | fclose(fp); |
- | ||
51 | return 0; |
- | ||
52 | } |
- | ||
53 | |
- | ||
54 | lines = 0; |
- | ||
55 | while(fscanf(fp, "%c", &c) == 1) { |
- | ||
56 | switch(c) { |
- | ||
57 | case '\n': |
- | ||
58 | ++lines; |
- | ||
59 | break; |
- | ||
60 | } |
- | ||
61 | } |
- | ||
62 | |
- | ||
63 | fclose(fp); |
- | ||
64 | |
- | ||
65 | return lines; |
41 | // Toggle the run flag to stop execution. |
|
66 | } |
42 | run = FALSE; |
|
67 | |
43 | } |
|
68 | |
44 | |
|
69 | /* |
45 | /* |
|
Line 86... | Line 62... | |||
86 | |
62 | |
|
87 | /* |
63 | /* |
|
88 | * |
64 | * |
|
89 | * Search the database for a matching string. |
65 | * Search the database for a matching string. |
|
90 | */ |
66 | */ |
|
91 | void SearchDatabase(char *dbFile, char* string, int lines) { |
67 | void SearchDatabase(char *dbFile, char* string) { |
|
92 | FILE *fp; |
68 | FILE *fp; |
|
93 | char *name; |
69 | char *name; |
|
94 | char *path; |
70 | char *path; |
|
95 | char c; |
71 | char c; |
|
Line 111... | Line 87... | |||
111 | total = 0; |
87 | total = 0; |
|
112 | while(run && fscanf(fp, "%c", &c) == 1) { |
88 | while(run && fscanf(fp, "%c", &c) == 1) { |
|
113 | #if defined ___AmigaOS___ |
89 | #if defined ___AmigaOS___ |
|
114 | // Check if CTRL+C was pressed and abort the program. |
90 | // Check if CTRL+C was pressed and abort the program. |
|
115 | if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { |
91 | if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { |
|
- | 92 | run = FALSE; |
||
116 | break; |
93 | break; |
|
117 | } |
94 | } |
|
118 | #endif |
95 | #endif |
|
Line 119... | Line 96... | |||
119 | |
96 | |
|
Line 165... | Line 142... | |||
165 | } |
142 | } |
|
Line 166... | Line 143... | |||
166 | |
143 | |
|
167 | fclose(fp); |
144 | fclose(fp); |
|
Line -... | Line 145... | |||
- | 145 | } |
||
- | 146 | |
||
- | 147 | /* |
||
- | 148 | * |
||
168 | } |
149 | * Search the database for the matching string. |
|
169 | |
- | ||
170 | void Hunt(char *dbFile, char *needle) { |
- | ||
171 | int lines; |
- | ||
172 | |
- | ||
173 | lines = CountDatabaseLines(dbFile); |
150 | */ |
|
174 | |
151 | void Hunt(char *dbFile, char *needle) { |
|
175 | // Search the database for the matching string. |
152 | // Search the database for the matching string. |
|
Line 176... | Line 153... | |||
176 | SearchDatabase(dbFile, needle, lines); |
153 | SearchDatabase(dbFile, needle); |
|
177 | } |
154 | } |
|
- | 155 | |
||
- | 156 | int main(int argc, char **argv) { |
||
Line 178... | Line 157... | |||
178 | |
157 | int option; |
|
179 | int main(int argc, char **argv) { |
158 | char *dbFile; |
|
Line -... | Line 159... | |||
- | 159 | struct stat path; |
||
180 | int option; |
160 | |
|
181 | |
161 | // Bind handler to SIGINT. |
|
- | 162 | signal(SIGINT, SignalHandler); |
||
- | 163 | |
||
- | 164 | dbFile = DEFAULT_DATABASE_FILE; |
||
182 | // Bind handler to SIGINT. |
165 | while((option = getopt(argc, argv, "hd:")) != -1) { |
|
183 | signal(SIGINT, SignalHandler); |
166 | switch(option) { |
|
184 | |
167 | case 'd': |
|
185 | while((option = getopt(argc, argv, "h")) != -1) { |
168 | dbFile = optarg; |
|
186 | switch(option) { |
169 | break; |
|
187 | case 'h': |
170 | case 'h': |
|
188 | fprintf(stdout, "SYNTAX: %s STRING", argv[0]); |
171 | fprintf(stdout, "SYNTAX: %s [-d DATABASE] STRING\n", argv[0]); |
|
189 | break; |
172 | break; |
|
190 | case '?': |
173 | case '?': |
|
Line 191... | Line 174... | |||
191 | fprintf(stderr, "Invalid option %c.\n", optopt); |
174 | fprintf(stderr, "Invalid option %c.\n", optopt); |
|
192 | fprintf(stdout, "SYNTAX: %s STRING\n", argv[0]); |
175 | fprintf(stdout, "SYNTAX: %s [-d DATABASE] STRING\n", argv[0]); |
|
- | 176 | return 1; |
||
- | 177 | } |
||
- | 178 | } |
||
- | 179 | |
||
- | 180 | if(optind > argc) { |
||
- | 181 | fprintf(stdout, "SYNTAX: %s [-d DATABASE] STRING\n", argv[0]); |
||
193 | return 1; |
182 | return 1; |
|
194 | } |
183 | } |
|
Line 195... | Line 184... | |||
195 | } |
184 | |