HuntnGather – Diff between revs 39 and 41
?pathlinks?
Rev 39 | Rev 41 | |||
---|---|---|---|---|
Line 128... | Line 128... | |||
128 | return DIRECTORY; |
128 | return DIRECTORY; |
|
129 | } |
129 | } |
|
Line 130... | Line 130... | |||
130 | |
130 | |
|
131 | /* |
131 | /* |
|
- | 132 | * |
||
- | 133 | * Get the size of a file. |
||
- | 134 | */ |
||
- | 135 | int GetFileSize(char *dbFile) { |
||
- | 136 | #if defined ___AsyncIO___ |
||
- | 137 | struct AsyncFile *fp; |
||
- | 138 | #else |
||
- | 139 | FILE *fp; |
||
- | 140 | #endif |
||
- | 141 | int size; |
||
- | 142 | |
||
- | 143 | #if defined ___AsyncIO___ |
||
- | 144 | if((fp = OpenAsync(dbFile, MODE_READ, ASYNC_BUF)) == NULL) { |
||
- | 145 | #else |
||
- | 146 | if((fp = fopen(dbFile, "r")) == NULL) { |
||
- | 147 | #endif |
||
- | 148 | fprintf(stderr, "Could not open file '%s' for reading.\n", dbFile); |
||
- | 149 | return -1; |
||
- | 150 | } |
||
- | 151 | |
||
- | 152 | #if defined ___AsyncIO___ |
||
- | 153 | SeekAsync(fp, 0, MODE_END); |
||
- | 154 | size = SeekAsync(fp, 0, MODE_CURRENT); |
||
- | 155 | #else |
||
- | 156 | fseek(fp, 0L, SEEK_END); |
||
- | 157 | size = ftell(fp); |
||
- | 158 | #endif |
||
- | 159 | |
||
- | 160 | #if defined ___AsyncIO___ |
||
- | 161 | CloseAsync(fp); |
||
- | 162 | #else |
||
- | 163 | fclose(fp); |
||
- | 164 | #endif |
||
- | 165 | |
||
- | 166 | return size; |
||
- | 167 | } |
||
- | 168 | |
||
- | 169 | /* |
||
132 | * |
170 | * |
|
133 | * Counts the lines of a file. |
171 | * Counts the lines of a file. |
|
134 | */ |
172 | */ |
|
135 | int CountFileLines(char *dbFile) { |
173 | int CountFileLines(char *dbFile) { |
|
136 | #if defined ___AsyncIO___ |
174 | #if defined ___AsyncIO___ |
|
137 | struct AsyncFile *fp; |
- | ||
138 | LONG c; |
175 | struct AsyncFile *fp; |
|
139 | #else |
176 | #else |
|
140 | FILE *fp; |
- | ||
141 | char c; |
177 | FILE *fp; |
|
142 | #endif |
178 | #endif |
|
- | 179 | int lines; |
||
Line 143... | Line 180... | |||
143 | int lines; |
180 | dbLine *line = NULL; |
|
144 | |
181 | |
|
145 | #if defined ___AsyncIO___ |
182 | #if defined ___AsyncIO___ |
|
146 | if((fp = OpenAsync(dbFile, MODE_READ, ASYNC_BUF)) == NULL) { |
183 | if((fp = OpenAsync(dbFile, MODE_READ, ASYNC_BUF)) == NULL) { |
|
147 | #else |
184 | #else |
|
148 | if((fp = fopen(dbFile, "r")) == NULL) { |
185 | if((fp = fopen(dbFile, "r")) == NULL) { |
|
149 | #endif |
186 | #endif |
|
150 | fprintf(stderr, "Could not open file '%s' for reading.\n", dbFile); |
187 | fprintf(stderr, "Could not open file '%s' for reading.\n", dbFile); |
|
Line 151... | Line -... | |||
151 | return -1; |
- | ||
152 | } |
188 | return -1; |
|
153 | |
189 | } |
|
154 | lines = 0; |
190 | |
|
Line 155... | Line 191... | |||
155 | if(PROGRAM_VERBOSE) { |
191 | if(PROGRAM_VERBOSE) { |
|
156 | fprintf(stdout, "Counting lines in '%s'...\r", dbFile); |
192 | fprintf(stdout, "Counting lines in '%s'...\r", dbFile); |
|
157 | } |
- | ||
158 | |
- | ||
159 | #if defined ___AsyncIO___ |
- | ||
160 | while(PROGRAM_RUN && (c = ReadCharAsync(fp)) != -1) { |
193 | } |
|
161 | #else |
194 | |
|
162 | while(PROGRAM_RUN && fscanf(fp, "%c", &c) == 1) { |
195 | lines = 0; |
|
163 | #endif |
196 | while(PROGRAM_RUN && (line = ReadLine(fp)) != NULL) { |
|
164 | #if defined ___AmigaOS___ |
197 | #if defined ___AmigaOS___ |
|
165 | // Check if CTRL+C was pressed and abort the program. |
198 | // Check if CTRL+C was pressed and abort the program. |
|
166 | if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { |
199 | if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { |
|
167 | PROGRAM_RUN = FALSE; |
- | ||
168 | continue; |
200 | PROGRAM_RUN = FALSE; |
|
169 | } |
201 | continue; |
|
170 | #endif |
202 | } |
|
171 | switch(c) { |
203 | #endif |
|
172 | case '\n': |
204 | |
|
173 | ++lines; |
- | ||
174 | |
- | ||
175 | if(PROGRAM_VERBOSE) { |
205 | ++lines; |
|
- | 206 | |
||
- | 207 | if(PROGRAM_VERBOSE) { |
||
- | 208 | fprintf(stdout, "Counting lines in '%s': %d.\r", dbFile, lines); |
||
- | 209 | } |
||
- | 210 | |
||
- | 211 | free(line->string); |
||
- | 212 | free(line); |
||
- | 213 | line = NULL; |
||
- | 214 | } |
||
- | 215 | |
||
176 | fprintf(stdout, "Counting lines in '%s': %d.\r", dbFile, lines); |
216 | if(line != NULL) { |
|
Line 177... | Line 217... | |||
177 | } |
217 | free(line->string); |
|
178 | break; |
218 | free(line); |
|
179 | } |
219 | line = NULL; |