Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/agcore/sums.syn @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 { | |
2 /* | |
3 * AnaGram, A System for Syntax Directed Programming | |
4 * Copyright 1993-2002 Parsifal Software. All Rights Reserved. | |
5 * Copyright 2006 David A. Holland. All Rights Reserved. | |
6 * See the file COPYING for license and usage terms. | |
7 * | |
8 * sums.syn - read checksum and build information | |
9 */ | |
10 | |
11 #include "port.h" | |
12 | |
13 #include "agstack.h" | |
14 #include "agstring.h" | |
15 #include "build.h" | |
16 #include "checksum.h" | |
17 #include "sums-defs.h" | |
18 | |
19 //#define INCLUDE_LOGGING | |
20 #include "log.h" | |
21 } | |
22 | |
23 [ | |
24 //pointer input | |
25 event driven | |
26 parser name = parseSumData | |
27 parser file name = "#.cpp" | |
28 line numbers path = "sumparse.syn" | |
29 ] | |
30 | |
31 eof = 0 | |
32 digit = '0-9' | |
33 ascii = 32..126 | |
34 | |
35 (void) inserted data $ | |
36 -> checksum data, build date, build os, eof | |
37 | |
38 (void) build date | |
39 -> "Build date:", text, '\n' = build_date = stringbuf; | |
40 | |
41 (void) build os | |
42 -> "Build OS:", text, '\n' = build_os = stringbuf; | |
43 | |
44 (void) checksum data | |
45 -> "Checksum data:\n", sum entry?... | |
46 | |
47 (void) sum entry | |
48 -> summable:w, '=', length:l, ',', sum:s, offset:o, '\n' = addsum(w,l,s,o); | |
49 | |
50 (summable) summable | |
51 -> "ag1" = SUM_AG1; | |
52 -> "ag" = SUM_AG; | |
53 -> "agcl" = SUM_AGCL; | |
54 | |
55 (unsigned long) length | |
56 -> integer:i = i; | |
57 | |
58 (unsigned long) sum | |
59 -> integer:i = i; | |
60 | |
61 (unsigned long) offset | |
62 -> = 0; | |
63 -> '@', integer:i = i; | |
64 | |
65 (unsigned long) integer | |
66 -> digit:d = d - '0'; | |
67 -> integer:i, digit:d = 10*i + d - '0'; | |
68 | |
69 (void) text | |
70 -> ascii:c = startstring(c); | |
71 -> text, ascii:c = addstring(c); | |
72 | |
73 { | |
74 #define SYNTAX_ERROR {\ | |
75 char buf[500];\ | |
76 sprintf(buf,"%s, line %d, column %d\n", \ | |
77 (PCB).error_message, (PCB).line, (PCB).column);\ | |
78 LOGV(buf);\ | |
79 } | |
80 | |
81 /* note - cannot compute skiplen at runtime */ | |
82 static char sumInfo[512] = "Checksum data:\n"; | |
83 static const size_t skiplen = 15; /* length of "Checksum data:\n" */ | |
84 | |
85 static AgStack<sumentry> sums; | |
86 | |
87 static char stringbuf[128]; | |
88 static size_t stringbufpos; | |
89 | |
90 AgString build_date, build_os; | |
91 | |
92 static void addstring(int ch) { | |
93 if (stringbufpos < sizeof(stringbuf)-1) { | |
94 stringbuf[stringbufpos++] = ch; | |
95 stringbuf[stringbufpos] = 0; | |
96 } | |
97 } | |
98 | |
99 static void startstring(int ch) { | |
100 stringbufpos = 0; | |
101 addstring(ch); | |
102 } | |
103 | |
104 static void addsum(summable what, unsigned long len, unsigned long sum, | |
105 unsigned long offset) { | |
106 sumentry se; | |
107 se.what = what; | |
108 se.offset = offset; | |
109 se.correct.length = len; | |
110 se.correct.sum = sum; | |
111 se.observed.length = 0; | |
112 se.observed.sum = 0; | |
113 sums.push(se); | |
114 } | |
115 | |
116 const char *checksums_ok(void) { | |
117 LOGSECTION("checksums_ok"); | |
118 | |
119 char *p = sumInfo; | |
120 size_t i; | |
121 | |
122 init_parseSumData(); | |
123 | |
124 for (i=0; i<sizeof(sumInfo); i++) { | |
125 unsigned char c = (unsigned char)p[i]; | |
126 if (i >= skiplen) { | |
127 c ^= PADBYTE; | |
128 } | |
129 //LOGV(c) | |
130 PCB.input_code = c; | |
131 if (PCB.exit_flag == AG_RUNNING_CODE) parseSumData(); | |
132 if (c == 0) break; | |
133 } | |
134 | |
135 if (PCB.exit_flag != AG_SUCCESS_CODE) { | |
136 LOGV(PCB.exit_flag); | |
137 return "Parse error in checksum data"; | |
138 } | |
139 | |
140 if (sums.size() == 0) { | |
141 LOGS("no sums"); | |
142 return "Checksum data empty"; | |
143 } | |
144 | |
145 for (i=0; i<sums.size(); i++) { | |
146 observeSum(&sums[i]); | |
147 } | |
148 | |
149 for (i=0; i<sums.size(); i++) { | |
150 LOGV(sums[i].what) LCV(sums[i].offset); | |
151 LOGV(sums[i].correct.length) LCV(sums[i].correct.sum); | |
152 LOGV(sums[i].observed.length) LCV(sums[i].observed.sum); | |
153 | |
154 if (sums[i].observed != sums[i].correct) { | |
155 switch (sums[i].what) { | |
156 case SUM_AG1: return "Bad checksum for ag1 shared library"; | |
157 case SUM_AG: return "Bad checksum for ag executable"; | |
158 case SUM_AGCL: return "Bad checksum for agcl executable"; | |
159 } | |
160 // this shouldn't happen | |
161 return "Bad checksum for unknown object (?)"; | |
162 } | |
163 } | |
164 | |
165 // ok | |
166 return NULL; | |
167 } | |
168 } |