Change Details
ubb-patgen/ubb-patgen.c |
14 | 14 | #include <stdlib.h> |
15 | 15 | #include <stdio.h> |
16 | 16 | #include <unistd.h> |
| 17 | #include <ctype.h> |
17 | 18 | #include <string.h> |
18 | 19 | #include <math.h> |
19 | 20 | #include <time.h> |
... | ... | |
194 | 195 | } |
195 | 196 | |
196 | 197 | |
| 198 | static const char *load_pattern(const char *s) |
| 199 | { |
| 200 | static char buf[20000]; /* more than enough :) */ |
| 201 | FILE *file; |
| 202 | char *p = buf; |
| 203 | int comment = 0; |
| 204 | int c; |
| 205 | |
| 206 | if (!strcmp(s, "-")) { |
| 207 | file = stdin; |
| 208 | } else { |
| 209 | file = fopen(s, "r"); |
| 210 | if (!file) |
| 211 | return s; |
| 212 | } |
| 213 | while ((c = fgetc(file)) != EOF) { |
| 214 | if (comment) { |
| 215 | comment = c != '\n'; |
| 216 | continue; |
| 217 | } |
| 218 | if (c == '#') { |
| 219 | comment = 1; |
| 220 | continue; |
| 221 | } |
| 222 | if (isspace(c)) |
| 223 | continue; |
| 224 | if (buf+sizeof(buf)-1 == p) { |
| 225 | fprintf(stderr, "%s: file is too big\n", s); |
| 226 | exit(1); |
| 227 | } |
| 228 | *p++ = c; |
| 229 | } |
| 230 | if (file != stdin) |
| 231 | fclose(file); |
| 232 | *p = 0; |
| 233 | return buf; |
| 234 | } |
| 235 | |
| 236 | |
197 | 237 | /* ----- DMA control ------------------------------------------------------- */ |
198 | 238 | |
199 | 239 | |
... | ... | |
449 | 489 | "usage: %s\n" |
450 | 490 | " %s [-q] -f freq_hz\n" |
451 | 491 | " %s [-q] [-f freq_hz] -c [active_s]\n" |
452 | | " %s [-q] [-f freq_hz] [-C] pattern\n\n" |
| 492 | " %s [-q] [-f freq_hz] [-C] file|pattern\n\n" |
453 | 493 | " -c output bus clock on CLK without sending a pattern\n" |
454 | 494 | " -C temporarily output bus clock on CLK (for debugging)\n" |
455 | 495 | " -f freq_hz set bus clock to the specified frequency (default: 1 MHz)\n" |
... | ... | |
457 | 497 | " differences.\n\n" |
458 | 498 | " active_s keep running that many seconds after setting the clock\n" |
459 | 499 | " (default: exit immediately but leave the clock on)\n" |
| 500 | " file file containing the pattern\n" |
460 | 501 | " pattern send the specified pattern on DAT0 through DAT3\n\n" |
461 | 502 | "Frequency: the frequency in Hz, optionally followed by \"M\" or \"k\",\n" |
462 | 503 | " optionally followed by \"Hz\", optionally followed by \"+\" or \"-\".\n" |
... | ... | |
538 | 579 | usage(*argv); |
539 | 580 | } |
540 | 581 | |
| 582 | if (pattern) |
| 583 | pattern = load_pattern(pattern); |
| 584 | |
541 | 585 | ubb_open(UBB_ALL); |
542 | 586 | |
543 | 587 | PDFUNS = UBB_CMD; |
Download the corresponding diff file