#include <stdio.h>
#include "asn-incl.h"
#include "asn1module.h"
#include "mem.h"
#include "print.h"
#include "rules.h"
#include "type-info.h"
#include "util.h"
#include "cond.h"
#include "gen-type.h"
#include "gen-enc.h"
#include "gen-dec.h"
#include "gen-vals.h"
#include "gen-free.h"
#include "gen-print.h"
#include "gen-any.h"
#include "gen-code.h"
static void PrintCSrcComment PROTO ((FILE *src, Module *m));
static void PrintCSrcIncludes PROTO ((FILE *src, Module *m, ModuleList *mods));
static void PrintCHdrComment PROTO ((FILE *hdr, Module *m));
void
PrintCCode PARAMS ((src, hdr, mods, m, r, longJmpVal, printTypes, printValues, printEncoders, printDecoders, printPrinters, printFree),
FILE *src _AND_
FILE *hdr _AND_
ModuleList *mods _AND_
Module *m _AND_
CRules *r _AND_
long int longJmpVal _AND_
int printTypes _AND_
int printValues _AND_
int printEncoders _AND_
int printDecoders _AND_
int printPrinters _AND_
int printFree)
{
TypeDef *td;
ValueDef *vd;
PrintCSrcComment (src, m);
PrintCSrcIncludes (src, m, mods);
PrintCHdrComment (hdr, m);
PrintConditionalIncludeOpen (hdr, m->cHdrFileName);
fprintf (hdr,"\n\n");
fprintf (src,"\n\n");
if (printValues)
{
FOR_EACH_LIST_ELMT (vd, m->valueDefs)
{
PrintCValueDef (src, r, vd);
}
}
PrintCAnyCode (src, hdr, r, mods, m);
FOR_EACH_LIST_ELMT (td, m->typeDefs)
{
if (printTypes)
PrintCTypeDef (hdr, r, m, td);
if (printEncoders &&
((td->anyRefs != NULL) || td->cTypeDefInfo->isPdu))
PrintCBerEncoder (src, hdr, r, m, td);
if (printDecoders &&
((td->anyRefs != NULL) || td->cTypeDefInfo->isPdu))
PrintCBerDecoder (src, hdr, r, m, td, &longJmpVal);
if (printEncoders)
PrintCBerContentEncoder (src, hdr, r, m, td);
if (printDecoders)
PrintCBerContentDecoder (src, hdr, r, m, td, &longJmpVal);
if (printPrinters)
PrintCPrinter (src, hdr, r, mods, m, td);
if (printFree)
PrintCFree (src, hdr, r, mods, m, td);
switch (td->type->basicType->choiceId)
{
case BASICTYPE_SEQUENCEOF:
case BASICTYPE_SETOF:
case BASICTYPE_CHOICE:
case BASICTYPE_SET:
case BASICTYPE_SEQUENCE:
fprintf (src, "\n\n\n");
case BASICTYPE_IMPORTTYPEREF:
case BASICTYPE_LOCALTYPEREF:
case BASICTYPE_BOOLEAN:
case BASICTYPE_REAL:
case BASICTYPE_OCTETSTRING:
case BASICTYPE_NULL:
case BASICTYPE_OID:
case BASICTYPE_INTEGER:
case BASICTYPE_BITSTRING:
case BASICTYPE_ENUMERATED:
case BASICTYPE_ANYDEFINEDBY:
case BASICTYPE_ANY:
fprintf (hdr, "\n\n\n");
break;
}
}
if (printValues)
{
FOR_EACH_LIST_ELMT (vd, m->valueDefs)
{
PrintCValueExtern (hdr, r, vd);
}
}
PrintConditionalIncludeClose (hdr, m->cHdrFileName);
}
static void
PrintCSrcComment PARAMS ((src, m),
FILE *src _AND_
Module *m)
{
long int t;
t = time (0);
fprintf (src, "/*\n");
fprintf (src, " * %s\n *\n", m->cSrcFileName);
fprintf (src, " * \"%s\" ASN.1 module encode/decode/print/free C src.\n *\n", m->modId->name);
fprintf (src, " * This file was generated by snacc on %s *\n", ctime (&t));
fprintf (src, " * UBC snacc written by Mike Sample\n *\n");
fprintf (src, " * NOTE: This is a machine generated file - editing not recommended\n");
fprintf (src, " */\n\n\n");
}
static void
PrintCSrcIncludes PARAMS ((src, m, mods),
FILE *src _AND_
Module *m _AND_
ModuleList *mods)
{
void *tmp;
Module *impMod;
fprintf (src, "\n#include \"asn-incl.h\"\n");
tmp = (void*)CURR_LIST_NODE (mods);
FOR_EACH_LIST_ELMT (impMod, mods)
{
fprintf (src, "#include \"%s\"\n", impMod->cHdrFileName);
}
SET_CURR_LIST_NODE (mods, tmp);
}
static void
PrintCHdrComment PARAMS ((f, m),
FILE *f _AND_
Module *m)
{
long int t;
t = time (0);
fprintf (f, "/*\n");
fprintf (f, " * %s\n *\n", m->cHdrFileName);
fprintf (f, " * \"%s\" ASN.1 module C type definitions and prototypes\n *\n", m->modId->name);
fprintf (f, " * This .h file was generated by snacc on %s *\n", ctime (&t));
fprintf (f, " * UBC snacc written compiler by Mike Sample\n *\n");
fprintf (f, " * NOTE: This is a machine generated file--editing not recommended\n");
fprintf (f, " */\n\n\n");
}