FreeCalypso > hg > fc-sim-sniff
comparison sw/sniff-dec/main.c @ 41:118a12e9483b
simtrace3-sniff-dec started
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 31 Aug 2023 08:46:23 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
40:510bef2b2000 | 41:118a12e9483b |
---|---|
1 /* | |
2 * simtrace3-sniff-dec main module: reading the log file. | |
3 */ | |
4 | |
5 #include <ctype.h> | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <strings.h> | |
10 | |
11 char *log_filename; | |
12 char linebuf[128]; | |
13 int lineno; | |
14 unsigned fpga_word; | |
15 | |
16 static void | |
17 process_line() | |
18 { | |
19 char *cp; | |
20 | |
21 cp = index(linebuf, '\n'); | |
22 if (!cp) { | |
23 fprintf(stderr, "%s line %d: too long or missing newline\n", | |
24 log_filename, lineno); | |
25 exit(1); | |
26 } | |
27 if (linebuf[0] != '[') | |
28 return; | |
29 cp = linebuf + 1; | |
30 while (isdigit(*cp) || *cp == ':' || *cp == '.') | |
31 cp++; | |
32 if (*cp++ != ']') { | |
33 invalid: fprintf(stderr, "%s line %d: failed to parse\n", | |
34 log_filename, lineno); | |
35 exit(1); | |
36 } | |
37 if (!isspace(*cp)) | |
38 goto invalid; | |
39 *cp++ = '\0'; | |
40 if (strlen(linebuf) > 17) | |
41 goto invalid; | |
42 while (isspace(*cp)) | |
43 cp++; | |
44 if (!isxdigit(cp[0]) || !isxdigit(cp[1]) || !isxdigit(cp[2]) || | |
45 !isxdigit(cp[3]) || !isspace(cp[4])) | |
46 goto invalid; | |
47 fpga_word = strtoul(cp, 0, 16); | |
48 process_fpga_word(); | |
49 } | |
50 | |
51 main(argc, argv) | |
52 char **argv; | |
53 { | |
54 FILE *inf; | |
55 | |
56 if (argc != 2) { | |
57 fprintf(stderr, "usage: %s logfile\n", argv[0]); | |
58 exit(1); | |
59 } | |
60 log_filename = argv[1]; | |
61 inf = fopen(log_filename, "r"); | |
62 if (!inf) { | |
63 perror(log_filename); | |
64 exit(1); | |
65 } | |
66 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) | |
67 process_line(); | |
68 exit(0); | |
69 } |