-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathhtml_03.c
More file actions
408 lines (363 loc) · 8.25 KB
/
Copy pathhtml_03.c
File metadata and controls
408 lines (363 loc) · 8.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include "gf2.h"
int desc_page_count = 0;
int desc_page_ndx = 0;
FILE* desc_page_file[ 1024 ];
FILE* cur_page_file;
void html_open()
{
cur_page_file = fopen( "index.html", "w+" );
desc_page_file[0] = cur_page_file;
desc_page_ndx = 0;
desc_page_count = 0;
fprintf( cur_page_file, "<html>" );
fprintf( cur_page_file, "<body style=\"white-space: nowrap;\">" );
}
void html_close()
{
fprintf( cur_page_file, "</body>" );
fprintf( cur_page_file, "</html>" );
fclose( desc_page_file[0] );
}
void html_page_push( const char *format , ... )
{
char filename[256];
desc_page_ndx++;
desc_page_count++;
sprintf( filename, "%08x.html", desc_page_count );
fprintf( cur_page_file, "<a href='%s'>", filename );
va_list arglist;
va_start( arglist, format );
vfprintf( cur_page_file, format, arglist );
va_end( arglist );
fprintf( cur_page_file, "</a>" );
cur_page_file = fopen( filename, "w+" );
desc_page_file[ desc_page_ndx ] = cur_page_file;
fprintf( cur_page_file, "<html>" );
fprintf( cur_page_file, "<body style=\"white-space: nowrap;\">" );
}
void html_page_push_silent()
{
char filename[256];
desc_page_ndx++;
desc_page_count++;
sprintf( filename, "%08x.html", desc_page_count );
cur_page_file = fopen( filename, "w+" );
desc_page_file[ desc_page_ndx ] = cur_page_file;
}
void html_page_pop()
{
fprintf( cur_page_file, "</body>" );
fprintf( cur_page_file, "</html>" );
fclose( cur_page_file );
desc_page_ndx--;
cur_page_file = desc_page_file[ desc_page_ndx ];
}
void html_println( const char *format , ... )
{
va_list arglist;
va_start( arglist, format );
vfprintf( cur_page_file, format, arglist );
va_end( arglist );
fprintf( cur_page_file, "<br>" );
}
void html_print( const char *format , ... )
{
va_list arglist;
va_start( arglist, format );
vfprintf( cur_page_file, format, arglist );
va_end( arglist );
}
void html_br()
{
fprintf( cur_page_file, "<br>" );
}
void html_hr()
{
fprintf( cur_page_file, "<hr>" );
}
void html_references_push()
{
fprintf( cur_page_file, "See also:<ul>" );
}
void html_reference( const char* link )
{
fprintf( cur_page_file, "<li><a href='%s'>%s</a></li>", link, link );
}
void html_ul_push( const char* title )
{
fprintf( cur_page_file, "%s<ul>", title );
}
void html_li_push()
{
fprintf( cur_page_file, "<li>" );
}
void html_li( const char *format , ... )
{
va_list arglist;
va_start( arglist, format );
fprintf( cur_page_file, "<li>" );
vfprintf( cur_page_file, format, arglist );
fprintf( cur_page_file, "</li>" );
va_end( arglist );
}
void html_li_pop()
{
fprintf( cur_page_file, "</li>" );
}
void html_ul_pop()
{
fprintf( cur_page_file, "</ul>" );
}
void html_references_pop()
{
fprintf( cur_page_file, "</ul>" );
}
void html_print_p_bin( int bit_size, uint32_t* x )
{
fprintf( cur_page_file, "b");
int word_count = p_gf2_wc(bit_size);
int top_word_ndx = word_count-1;
do
{
uint32_t top_word = x[ top_word_ndx ];
for (int i=31;i>=0;i--)
{
fprintf( cur_page_file, "%c",top_word&(1<<i)?'1':'0');
}
top_word_ndx--;
}
while (top_word_ndx >= 0);
}
void html_print_p_bin_skiplz( int bit_size, uint32_t* x )
{
fprintf( cur_page_file, "b");
int word_count = p_gf2_wc(bit_size);
int top_word_ndx = word_count-1;
int found_top_bit = 0;
do
{
uint32_t top_word = x[ top_word_ndx ];
for (int i=31;i>=0;i--)
{
if (found_top_bit)
{
fprintf( cur_page_file, "%c",top_word&(1<<i)?'1':'0');
}
else
{
if ( top_word&(1<<i) )
{
found_top_bit = 1;
fprintf( cur_page_file, "1" );
}
}
}
top_word_ndx--;
}
while (top_word_ndx >= 0);
if (!found_top_bit)
{
fprintf( cur_page_file, "0" );
}
}
void html_print_p_hex( int bit_size, uint32_t* x )
{
fprintf( cur_page_file, "0x");
int word_count = p_gf2_wc(bit_size);
int top_word_ndx = word_count-1;
do
{
uint32_t top_word = x[ top_word_ndx ];
fprintf( cur_page_file, "%08x",top_word);
top_word_ndx--;
}
while (top_word_ndx >= 0);
}
void html_print_p_hex_skiplz( int bit_size, uint32_t* x )
{
fprintf( cur_page_file, "0x");
int word_count = p_gf2_wc(bit_size);
int top_word_ndx = word_count-1;
int found_word = 0;
do
{
uint32_t top_word = x[ top_word_ndx ];
if (top_word)
{
fprintf( cur_page_file, "%x",top_word);
found_word = 1;
}
top_word_ndx--;
}
while (top_word_ndx >= 0);
if (!found_word)
{
fprintf( cur_page_file, "0" );
}
}
void html_print_p_poly( int bit_size, uint32_t* x )
{
int word_count = p_gf2_wc(bit_size);
int top_word_ndx = word_count-1;
int has_prev = 0;
do
{
uint32_t top_word = x[ top_word_ndx ];
for (int i=31;i>=0;i--)
{
if ( top_word & (1<<i) )
{
if (( top_word_ndx == 0 ) && (i==0))
{
fprintf( cur_page_file, "%s1",has_prev?" + ":"");
}
else if (( top_word_ndx == 0 ) && (i==1))
{
fprintf( cur_page_file, "%sx",has_prev?" + ":"");
}
else
{
fprintf( cur_page_file, "%sx<sup>%d</sup>",has_prev?" + ":"",(top_word_ndx*32)+i);
}
has_prev = 1;
}
}
top_word_ndx--;
}
while (top_word_ndx >= 0);
if (!has_prev)
{
fprintf( cur_page_file, "0");
}
}
void html_print_p_poly_input( int bit_size, uint32_t* x )
{
int word_count = p_gf2_wc(bit_size);
int top_word_ndx = word_count-1;
int has_prev = 0;
do
{
uint32_t top_word = x[ top_word_ndx ];
for (int i=31;i>=0;i--)
{
if ( top_word & (1<<i) )
{
if (( top_word_ndx == 0 ) && (i==0))
{
fprintf( cur_page_file, "%s1",has_prev?" + ":"");
}
else if (( top_word_ndx == 0 ) && (i==1))
{
fprintf( cur_page_file, "%sx",has_prev?" + ":"");
}
else
{
fprintf( cur_page_file, "%sx^%d",has_prev?" + ":"",(top_word_ndx*32)+i);
}
has_prev = 1;
}
}
top_word_ndx--;
}
while (top_word_ndx >= 0);
if (!has_prev)
{
fprintf( cur_page_file, "0");
}
}
void html_print_p( const char* name, int bit_size, uint32_t* x )
{
html_print( "<tt>" );
html_print( "%s = ", name);
html_print_p_bin_skiplz( bit_size, x );
html_br();
html_print( "%s = ", name);
html_print_p_hex_skiplz( bit_size, x );
html_br();
html_print( "%s = ", name);
html_print_p_poly( bit_size, x );
html_br();
html_print( "%s = ", name);
html_print_p_poly_input( bit_size, x );
html_br();
html_print( "</tt>" );
}
void html_print_p_factors( char* name, int bit_size, int factor_count, uint32_t* factors )
{
html_print("<tt>");
html_print("%s = ", name);
for (int i=0;i<factor_count;i++)
{
if (p_gf2_eqz(bit_size,factors+(p_gf2_wc(bit_size)*i)))
{
continue;
}
html_print("(b");
html_print_p_bin_skiplz(bit_size,factors+(p_gf2_wc(bit_size)*i));
html_print(")");
}
html_br();
html_print("%s = ", name);
for (int i=0;i<factor_count;i++)
{
if (p_gf2_eqz(bit_size,factors+(p_gf2_wc(bit_size)*i)))
{
continue;
}
html_print("(0x");
html_print_p_hex_skiplz(bit_size,factors+(p_gf2_wc(bit_size)*i));
html_print(")");
}
html_br();
html_print("%s = ", name);
for (int i=0;i<factor_count;i++)
{
if (p_gf2_eqz(bit_size,factors+(p_gf2_wc(bit_size)*i)))
{
continue;
}
html_print("(");
html_print_p_poly(bit_size,factors+(p_gf2_wc(bit_size)*i));
html_print(")");
}
html_br();
html_print("</tt>");
}
void html_indent_push()
{
html_print("<div style=\"margin-left:4em;\">");
}
void html_indent_pop()
{
html_print("</div>");
}
void html_code_begin()
{
html_print("<tt><pre>");
}
void html_code_end()
{
html_print("</pre></tt>");
}
void
html_print_bin_w( int bit_size, uint32_t* x, int width )
{
for (int i=width-1;i>=0;i--)
{
fprintf(cur_page_file,"%c",p_gf2_bt( bit_size, x, i )?'1':'0');
}
}
void
html_print_bin_w_aug( int bit_size, uint32_t* x, int width )
{
for (int i=width-1;i>=0;i--)
{
fprintf(cur_page_file,"%c",p_gf2_bt( bit_size, x, i )?'1':'0');
if ( i == (width/2) ) {
fprintf(cur_page_file," ");
}
}
}