make compile
[heimdal.git] / lib / asn1 / gen_decode.c
blobcf7f0b05dc06f47fe781563d99a0a85dc584e5ce
1 /*
2 * Copyright (c) 1997 - 2006 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 #include "gen_locl.h"
35 #include "lex.h"
37 RCSID("$Id$");
39 static void
40 decode_primitive (const char *typename, const char *name, const char *forwstr)
42 #if 0
43 fprintf (codefile,
44 "e = decode_%s(p, len, %s, &l);\n"
45 "%s;\n",
46 typename,
47 name,
48 forwstr);
49 #else
50 fprintf (codefile,
51 "e = der_get_%s(p, len, %s, &l);\n"
52 "if(e) %s;\np += l; len -= l; ret += l;\n",
53 typename,
54 name,
55 forwstr);
56 #endif
59 static int
60 is_primitive_type(int type)
62 switch(type) {
63 case TInteger:
64 case TBoolean:
65 case TOctetString:
66 case TBitString:
67 case TEnumerated:
68 case TGeneralizedTime:
69 case TGeneralString:
70 case TOID:
71 case TUTCTime:
72 case TUTF8String:
73 case TPrintableString:
74 case TIA5String:
75 case TBMPString:
76 case TUniversalString:
77 case TVisibleString:
78 case TNull:
79 return 1;
80 default:
81 return 0;
85 static void
86 find_tag (const Type *t,
87 Der_class *cl, Der_type *ty, unsigned *tag)
89 switch (t->type) {
90 case TBitString:
91 *cl = ASN1_C_UNIV;
92 *ty = PRIM;
93 *tag = UT_BitString;
94 break;
95 case TBoolean:
96 *cl = ASN1_C_UNIV;
97 *ty = PRIM;
98 *tag = UT_Boolean;
99 break;
100 case TChoice:
101 errx(1, "Cannot have recursive CHOICE");
102 case TEnumerated:
103 *cl = ASN1_C_UNIV;
104 *ty = PRIM;
105 *tag = UT_Enumerated;
106 break;
107 case TGeneralString:
108 *cl = ASN1_C_UNIV;
109 *ty = PRIM;
110 *tag = UT_GeneralString;
111 break;
112 case TGeneralizedTime:
113 *cl = ASN1_C_UNIV;
114 *ty = PRIM;
115 *tag = UT_GeneralizedTime;
116 break;
117 case TIA5String:
118 *cl = ASN1_C_UNIV;
119 *ty = PRIM;
120 *tag = UT_IA5String;
121 break;
122 case TInteger:
123 *cl = ASN1_C_UNIV;
124 *ty = PRIM;
125 *tag = UT_Integer;
126 break;
127 case TNull:
128 *cl = ASN1_C_UNIV;
129 *ty = PRIM;
130 *tag = UT_Null;
131 break;
132 case TOID:
133 *cl = ASN1_C_UNIV;
134 *ty = PRIM;
135 *tag = UT_OID;
136 break;
137 case TOctetString:
138 *cl = ASN1_C_UNIV;
139 *ty = PRIM;
140 *tag = UT_OctetString;
141 break;
142 case TPrintableString:
143 *cl = ASN1_C_UNIV;
144 *ty = PRIM;
145 *tag = UT_PrintableString;
146 break;
147 case TSequence:
148 case TSequenceOf:
149 *cl = ASN1_C_UNIV;
150 *ty = CONS;
151 *tag = UT_Sequence;
152 break;
153 case TSet:
154 case TSetOf:
155 *cl = ASN1_C_UNIV;
156 *ty = CONS;
157 *tag = UT_Set;
158 break;
159 case TTag:
160 *cl = t->tag.tagclass;
161 *ty = is_primitive_type(t->subtype->type) ? PRIM : CONS;
162 *tag = t->tag.tagvalue;
163 break;
164 case TType:
165 if ((t->symbol->stype == Stype && t->symbol->type == NULL)
166 || t->symbol->stype == SUndefined) {
167 error_message("%s is imported or still undefined, "
168 " can't generate tag checking data in CHOICE "
169 "without this information",
170 t->symbol->name);
171 exit(1);
173 find_tag(t->symbol->type, cl, ty, tag);
174 return;
175 case TUTCTime:
176 *cl = ASN1_C_UNIV;
177 *ty = PRIM;
178 *tag = UT_UTCTime;
179 break;
180 case TUTF8String:
181 *cl = ASN1_C_UNIV;
182 *ty = PRIM;
183 *tag = UT_UTF8String;
184 break;
185 case TBMPString:
186 *cl = ASN1_C_UNIV;
187 *ty = PRIM;
188 *tag = UT_BMPString;
189 break;
190 case TUniversalString:
191 *cl = ASN1_C_UNIV;
192 *ty = PRIM;
193 *tag = UT_UniversalString;
194 break;
195 case TVisibleString:
196 *cl = ASN1_C_UNIV;
197 *ty = PRIM;
198 *tag = UT_VisibleString;
199 break;
200 default:
201 abort();
205 static void
206 range_check(const char *name,
207 const char *length,
208 const char *forwstr,
209 struct range *r)
211 if (r->min == r->max + 2 || r->min < r->max)
212 fprintf (codefile,
213 "if ((%s)->%s > %d) {\n"
214 "e = ASN1_MAX_CONSTRAINT; %s;\n"
215 "}\n",
216 name, length, r->max, forwstr);
217 if (r->min - 1 == r->max || r->min < r->max)
218 fprintf (codefile,
219 "if ((%s)->%s < %d) {\n"
220 "e = ASN1_MIN_CONSTRAINT; %s;\n"
221 "}\n",
222 name, length, r->min, forwstr);
223 if (r->max == r->min)
224 fprintf (codefile,
225 "if ((%s)->%s != %d) {\n"
226 "e = ASN1_EXACT_CONSTRAINT; %s;\n"
227 "}\n",
228 name, length, r->min, forwstr);
231 static int
232 decode_type (const char *name, const Type *t, int optional,
233 const char *forwstr, const char *tmpstr, const char *dertype)
235 switch (t->type) {
236 case TType: {
237 if (optional)
238 fprintf(codefile,
239 "%s = calloc(1, sizeof(*%s));\n"
240 "if (%s == NULL) %s;\n",
241 name, name, name, forwstr);
242 fprintf (codefile,
243 "e = decode_%s(p, len, %s, &l);\n",
244 t->symbol->gen_name, name);
245 if (optional) {
246 fprintf (codefile,
247 "if(e) {\n"
248 "free(%s);\n"
249 "%s = NULL;\n"
250 "} else {\n"
251 "p += l; len -= l; ret += l;\n"
252 "}\n",
253 name, name);
254 } else {
255 fprintf (codefile,
256 "if(e) %s;\n",
257 forwstr);
258 fprintf (codefile,
259 "p += l; len -= l; ret += l;\n");
261 break;
263 case TInteger:
264 if(t->members) {
265 fprintf(codefile,
266 "{\n"
267 "int enumint;\n");
268 decode_primitive ("integer", "&enumint", forwstr);
269 fprintf(codefile,
270 "*%s = enumint;\n"
271 "}\n",
272 name);
273 } else if (t->range == NULL) {
274 decode_primitive ("heim_integer", name, forwstr);
275 } else if (t->range->min == INT_MIN && t->range->max == INT_MAX) {
276 decode_primitive ("integer", name, forwstr);
277 } else if (t->range->min == 0 && t->range->max == UINT_MAX) {
278 decode_primitive ("unsigned", name, forwstr);
279 } else if (t->range->min == 0 && t->range->max == INT_MAX) {
280 decode_primitive ("unsigned", name, forwstr);
281 } else
282 errx(1, "%s: unsupported range %d -> %d",
283 name, t->range->min, t->range->max);
284 break;
285 case TBoolean:
286 decode_primitive ("boolean", name, forwstr);
287 break;
288 case TEnumerated:
289 decode_primitive ("enumerated", name, forwstr);
290 break;
291 case TOctetString:
292 if (dertype) {
293 fprintf(codefile,
294 "if (%s == CONS) {\n",
295 dertype);
296 decode_primitive("octet_string_ber", name, forwstr);
297 fprintf(codefile,
298 "} else {\n");
300 decode_primitive ("octet_string", name, forwstr);
301 if (dertype)
302 fprintf(codefile, "}\n");
303 if (t->range)
304 range_check(name, "length", forwstr, t->range);
305 break;
306 case TBitString: {
307 Member *m;
308 int pos = 0;
310 if (ASN1_TAILQ_EMPTY(t->members)) {
311 decode_primitive ("bit_string", name, forwstr);
312 break;
314 fprintf(codefile,
315 "if (len < 1) return ASN1_OVERRUN;\n"
316 "p++; len--; ret++;\n");
317 fprintf(codefile,
318 "do {\n"
319 "if (len < 1) break;\n");
320 ASN1_TAILQ_FOREACH(m, t->members, members) {
321 while (m->val / 8 > pos / 8) {
322 fprintf (codefile,
323 "p++; len--; ret++;\n"
324 "if (len < 1) break;\n");
325 pos += 8;
327 fprintf (codefile,
328 "(%s)->%s = (*p >> %d) & 1;\n",
329 name, m->gen_name, 7 - m->val % 8);
331 fprintf(codefile,
332 "} while(0);\n");
333 fprintf (codefile,
334 "p += len; ret += len;\n");
335 break;
337 case TSequence: {
338 Member *m;
340 if (t->members == NULL)
341 break;
343 ASN1_TAILQ_FOREACH(m, t->members, members) {
344 char *s;
346 if (m->ellipsis)
347 continue;
349 asprintf (&s, "%s(%s)->%s", m->optional ? "" : "&",
350 name, m->gen_name);
351 if (s == NULL)
352 errx(1, "malloc");
353 decode_type (s, m->type, m->optional, forwstr, m->gen_name, NULL);
354 free (s);
357 break;
359 case TSet: {
360 Member *m;
361 unsigned int memno;
363 if(t->members == NULL)
364 break;
366 fprintf(codefile, "{\n");
367 fprintf(codefile, "unsigned int members = 0;\n");
368 fprintf(codefile, "while(len > 0) {\n");
369 fprintf(codefile,
370 "Der_class class;\n"
371 "Der_type type;\n"
372 "int tag;\n"
373 "e = der_get_tag (p, len, &class, &type, &tag, NULL);\n"
374 "if(e) %s;\n", forwstr);
375 fprintf(codefile, "switch (MAKE_TAG(class, type, tag)) {\n");
376 memno = 0;
377 ASN1_TAILQ_FOREACH(m, t->members, members) {
378 char *s;
380 assert(m->type->type == TTag);
382 fprintf(codefile, "case MAKE_TAG(%s, %s, %s):\n",
383 classname(m->type->tag.tagclass),
384 is_primitive_type(m->type->subtype->type) ? "PRIM" : "CONS",
385 valuename(m->type->tag.tagclass, m->type->tag.tagvalue));
387 asprintf (&s, "%s(%s)->%s", m->optional ? "" : "&", name, m->gen_name);
388 if (s == NULL)
389 errx(1, "malloc");
390 if(m->optional)
391 fprintf(codefile,
392 "%s = calloc(1, sizeof(*%s));\n"
393 "if (%s == NULL) { e = ENOMEM; %s; }\n",
394 s, s, s, forwstr);
395 decode_type (s, m->type, 0, forwstr, m->gen_name, NULL);
396 free (s);
398 fprintf(codefile, "members |= (1 << %d);\n", memno);
399 memno++;
400 fprintf(codefile, "break;\n");
402 fprintf(codefile,
403 "default:\n"
404 "return ASN1_MISPLACED_FIELD;\n"
405 "break;\n");
406 fprintf(codefile, "}\n");
407 fprintf(codefile, "}\n");
408 memno = 0;
409 ASN1_TAILQ_FOREACH(m, t->members, members) {
410 char *s;
412 asprintf (&s, "%s->%s", name, m->gen_name);
413 if (s == NULL)
414 errx(1, "malloc");
415 fprintf(codefile, "if((members & (1 << %d)) == 0)\n", memno);
416 if(m->optional)
417 fprintf(codefile, "%s = NULL;\n", s);
418 else if(m->defval)
419 gen_assign_defval(s, m->defval);
420 else
421 fprintf(codefile, "return ASN1_MISSING_FIELD;\n");
422 free(s);
423 memno++;
425 fprintf(codefile, "}\n");
426 break;
428 case TSetOf:
429 case TSequenceOf: {
430 char *n;
431 char *sname;
433 fprintf (codefile,
434 "{\n"
435 "size_t %s_origlen = len;\n"
436 "size_t %s_oldret = ret;\n"
437 "size_t %s_olen = 0;\n"
438 "void *%s_tmp;\n"
439 "ret = 0;\n"
440 "(%s)->len = 0;\n"
441 "(%s)->val = NULL;\n",
442 tmpstr,
443 tmpstr,
444 tmpstr,
445 tmpstr,
446 name,
447 name);
449 fprintf (codefile,
450 "while(ret < %s_origlen) {\n"
451 "size_t %s_nlen = %s_olen + sizeof(*((%s)->val));\n"
452 "if (%s_olen > %s_nlen) { e = ASN1_OVERFLOW; %s; }\n"
453 "%s_olen = %s_nlen;\n"
454 "%s_tmp = realloc((%s)->val, %s_olen);\n"
455 "if (%s_tmp == NULL) { e = ENOMEM; %s; }\n"
456 "(%s)->val = %s_tmp;\n",
457 tmpstr,
458 tmpstr, tmpstr, name,
459 tmpstr, tmpstr, forwstr,
460 tmpstr, tmpstr,
461 tmpstr, name, tmpstr,
462 tmpstr, forwstr,
463 name, tmpstr);
465 asprintf (&n, "&(%s)->val[(%s)->len]", name, name);
466 if (n == NULL)
467 errx(1, "malloc");
468 asprintf (&sname, "%s_s_of", tmpstr);
469 if (sname == NULL)
470 errx(1, "malloc");
471 decode_type (n, t->subtype, 0, forwstr, sname, NULL);
472 fprintf (codefile,
473 "(%s)->len++;\n"
474 "len = %s_origlen - ret;\n"
475 "}\n"
476 "ret += %s_oldret;\n"
477 "}\n",
478 name,
479 tmpstr, tmpstr);
480 if (t->range)
481 range_check(name, "len", forwstr, t->range);
482 free (n);
483 free (sname);
484 break;
486 case TGeneralizedTime:
487 decode_primitive ("generalized_time", name, forwstr);
488 break;
489 case TGeneralString:
490 decode_primitive ("general_string", name, forwstr);
491 break;
492 case TTag:{
493 char *tname, *typestring;
494 char *ide = NULL;
496 asprintf(&typestring, "%s_type", tmpstr);
498 fprintf(codefile,
499 "{\n"
500 "size_t %s_datalen, %s_oldlen;\n"
501 "Der_type %s;\n",
502 tmpstr, tmpstr, typestring);
503 if(support_ber)
504 fprintf(codefile,
505 "int is_indefinite;\n");
507 fprintf(codefile, "e = der_match_tag_and_length(p, len, %s, &%s, %s, "
508 "&%s_datalen, &l);\n",
509 classname(t->tag.tagclass),
510 typestring,
511 valuename(t->tag.tagclass, t->tag.tagvalue),
512 tmpstr);
514 /* XXX hardcode for now */
515 if (support_ber && t->subtype->type == TOctetString) {
516 ide = typestring;
517 } else {
518 fprintf(codefile,
519 "if (e == 0 && %s != %s) { e = ASN1_BAD_ID; }\n",
520 typestring,
521 is_primitive_type(t->subtype->type) ? "PRIM" : "CONS");
524 if(optional) {
525 fprintf(codefile,
526 "if(e) {\n"
527 "%s = NULL;\n"
528 "} else {\n"
529 "%s = calloc(1, sizeof(*%s));\n"
530 "if (%s == NULL) { e = ENOMEM; %s; }\n",
531 name, name, name, name, forwstr);
532 } else {
533 fprintf(codefile, "if(e) %s;\n", forwstr);
535 fprintf (codefile,
536 "p += l; len -= l; ret += l;\n"
537 "%s_oldlen = len;\n",
538 tmpstr);
539 if(support_ber)
540 fprintf (codefile,
541 "if((is_indefinite = _heim_fix_dce(%s_datalen, &len)) < 0)\n"
542 "{ e = ASN1_BAD_FORMAT; %s; }\n"
543 "if (is_indefinite) { if (len < 2) { e = ASN1_OVERRUN; %s; } len -= 2; }",
544 tmpstr, forwstr, forwstr);
545 else
546 fprintf(codefile,
547 "if (%s_datalen > len) { e = ASN1_OVERRUN; %s; }\n"
548 "len = %s_datalen;\n", tmpstr, forwstr, tmpstr);
549 asprintf (&tname, "%s_Tag", tmpstr);
550 if (tname == NULL)
551 errx(1, "malloc");
552 decode_type (name, t->subtype, 0, forwstr, tname, ide);
553 if(support_ber)
554 fprintf(codefile,
555 "if(is_indefinite){\n"
556 "len += 2;\n"
557 "e = der_match_tag_and_length(p, len, "
558 "(Der_class)0, &%s, UT_EndOfContent, "
559 "&%s_datalen, &l);\n"
560 "if(e) %s;\n"
561 "p += l; len -= l; ret += l;\n"
562 "if (%s != (Der_type)0) { e = ASN1_BAD_ID; %s; }\n"
563 "} else \n",
564 typestring,
565 tmpstr,
566 forwstr,
567 typestring, forwstr);
568 fprintf(codefile,
569 "len = %s_oldlen - %s_datalen;\n",
570 tmpstr, tmpstr);
571 if(optional)
572 fprintf(codefile,
573 "}\n");
574 fprintf(codefile,
575 "}\n");
576 free(tname);
577 free(typestring);
578 break;
580 case TChoice: {
581 Member *m, *have_ellipsis = NULL;
582 const char *els = "";
584 if (t->members == NULL)
585 break;
587 ASN1_TAILQ_FOREACH(m, t->members, members) {
588 const Type *tt = m->type;
589 char *s;
590 Der_class cl;
591 Der_type ty;
592 unsigned tag;
594 if (m->ellipsis) {
595 have_ellipsis = m;
596 continue;
599 find_tag(tt, &cl, &ty, &tag);
601 fprintf(codefile,
602 "%sif (der_match_tag(p, len, %s, %s, %s, NULL) == 0) {\n",
603 els,
604 classname(cl),
605 ty ? "CONS" : "PRIM",
606 valuename(cl, tag));
607 asprintf (&s, "%s(%s)->u.%s", m->optional ? "" : "&",
608 name, m->gen_name);
609 if (s == NULL)
610 errx(1, "malloc");
611 decode_type (s, m->type, m->optional, forwstr, m->gen_name, NULL);
612 fprintf(codefile,
613 "(%s)->element = %s;\n",
614 name, m->label);
615 free(s);
616 fprintf(codefile,
617 "}\n");
618 els = "else ";
620 if (have_ellipsis) {
621 fprintf(codefile,
622 "else {\n"
623 "(%s)->u.%s.data = calloc(1, len);\n"
624 "if ((%s)->u.%s.data == NULL) {\n"
625 "e = ENOMEM; %s;\n"
626 "}\n"
627 "(%s)->u.%s.length = len;\n"
628 "memcpy((%s)->u.%s.data, p, len);\n"
629 "(%s)->element = %s;\n"
630 "p += len;\n"
631 "ret += len;\n"
632 "len -= len;\n"
633 "}\n",
634 name, have_ellipsis->gen_name,
635 name, have_ellipsis->gen_name,
636 forwstr,
637 name, have_ellipsis->gen_name,
638 name, have_ellipsis->gen_name,
639 name, have_ellipsis->label);
640 } else {
641 fprintf(codefile,
642 "else {\n"
643 "e = ASN1_PARSE_ERROR;\n"
644 "%s;\n"
645 "}\n",
646 forwstr);
648 break;
650 case TUTCTime:
651 decode_primitive ("utctime", name, forwstr);
652 break;
653 case TUTF8String:
654 decode_primitive ("utf8string", name, forwstr);
655 break;
656 case TPrintableString:
657 decode_primitive ("printable_string", name, forwstr);
658 break;
659 case TIA5String:
660 decode_primitive ("ia5_string", name, forwstr);
661 break;
662 case TBMPString:
663 decode_primitive ("bmp_string", name, forwstr);
664 break;
665 case TUniversalString:
666 decode_primitive ("universal_string", name, forwstr);
667 break;
668 case TVisibleString:
669 decode_primitive ("visible_string", name, forwstr);
670 break;
671 case TNull:
672 fprintf (codefile, "/* NULL */\n");
673 break;
674 case TOID:
675 decode_primitive ("oid", name, forwstr);
676 break;
677 default :
678 abort ();
680 return 0;
683 void
684 generate_type_decode (const Symbol *s)
686 int preserve = preserve_type(s->name) ? TRUE : FALSE;
688 fprintf (headerfile,
689 "int "
690 "decode_%s(const unsigned char *, size_t, %s *, size_t *);\n",
691 s->gen_name, s->gen_name);
693 fprintf (codefile, "int\n"
694 "decode_%s(const unsigned char *p,"
695 " size_t len, %s *data, size_t *size)\n"
696 "{\n",
697 s->gen_name, s->gen_name);
699 switch (s->type->type) {
700 case TInteger:
701 case TBoolean:
702 case TOctetString:
703 case TOID:
704 case TGeneralizedTime:
705 case TGeneralString:
706 case TUTF8String:
707 case TPrintableString:
708 case TIA5String:
709 case TBMPString:
710 case TUniversalString:
711 case TVisibleString:
712 case TUTCTime:
713 case TNull:
714 case TEnumerated:
715 case TBitString:
716 case TSequence:
717 case TSequenceOf:
718 case TSet:
719 case TSetOf:
720 case TTag:
721 case TType:
722 case TChoice:
723 fprintf (codefile,
724 "size_t ret = 0;\n"
725 "size_t l;\n"
726 "int e;\n");
727 if (preserve)
728 fprintf (codefile, "const unsigned char *begin = p;\n");
730 fprintf (codefile, "\n");
731 fprintf (codefile, "memset(data, 0, sizeof(*data));\n"); /* hack to avoid `unused variable' */
733 decode_type ("data", s->type, 0, "goto fail", "Top", NULL);
734 if (preserve)
735 fprintf (codefile,
736 "data->_save.data = calloc(1, ret);\n"
737 "if (data->_save.data == NULL) { \n"
738 "e = ENOMEM; goto fail; \n"
739 "}\n"
740 "data->_save.length = ret;\n"
741 "memcpy(data->_save.data, begin, ret);\n");
742 fprintf (codefile,
743 "if(size) *size = ret;\n"
744 "return 0;\n");
745 fprintf (codefile,
746 "fail:\n"
747 "free_%s(data);\n"
748 "return e;\n",
749 s->gen_name);
750 break;
751 default:
752 abort ();
754 fprintf (codefile, "}\n\n");