static void PrintCppFile(FILE *f, ParserState *parse) { /* things we always need */ if (gl_header) { fprintf(f, "%s", gl_header); } if (parse->topcomment) { PrintComment(f, parse->topcomment); } if (parse->needsStdlib) { fprintf(f, "#include <stdlib.h>\n"); } fprintf(f, "#include <propeller.h>\n"); fprintf(f, "#include \"%s.h\"\n", parse->basename); fprintf(f, "\n"); PrintMacros(f, parse); /* declare static functions and variables */ if (gl_ccode && !gl_nospin) { int n; n = PrintPrivateFunctionDecls(f, parse); if (n > 0) fprintf(f, "\n"); } /* print data block, if applicable */ if (parse->datblock) { if (gl_gas_dat) { fprintf(f, "extern "); PrintDatArray(f, parse, ";\n", false); PrintDataBlockForGas(f, parse, 1); } else { if (gl_ccode) { fprintf(f, "static "); PrintDatArray(f, parse, " = {\n", false); } else { PrintDatArray(f, parse, " = {\n", true); } PrintDataBlock(f, parse, TEXT_OUTPUT); fprintf(f, "};\n"); } } /* functions */ PrintFunctionBodies(f, parse); /* any closing comments */ if (parse->botcomment) { PrintComment(f, parse->botcomment); } }
/************************************************************************** * * CreateFiles * * SYNOPSIS * int CreateFiles (LST_LIST *clist, char *filename) * * PURPOSE * Follow specified rule and create files. * * INPUT * * * EFFECTS * * * RETURN VALUE * * * BUGS * * * HISTORY * * * SEE ALSO * */ int CreateFiles (ConfigType *cf, char *filename) { LST_LIST *macrolist; LST_LIST *stacklist; StackType *stack; MakeMacro *macro; NameType *name; Statement *st; FILE *fp = NULL; int firstflag; int error = FALSE; int stacksize = 0; if (!filename) { filename = MAKEFILE; } macrolist = GetMakeMacros (filename); if (!macrolist) { return FALSE; } stacklist = LST_CreateList (NULL); if (!stacklist) { SetGlobalErr (ERR_OUT_OF_MEMORY); GEprintf ("OOM: couldn't allocate stack list"); return FALSE; } if (DebugSwitch) { PrintMacros (macrolist); } st = (Statement*)LST_Head (&cf->Statements); while (!LST_EndOfList (st)) { switch (st->Command) { case CMD_OPEN: if (fp) { fclose (fp); } fp = fopen (st->Arg1, "w"); if (!fp) { SetGlobalErr (ERR_GENERIC); GEprintf1 ("Couldn't open file '%s' for writing", st->Arg1); return FALSE; } break; case CMD_PRINT: if (!fp) { printf ("ERROR:'_Print' command issued with no file opened\n"); error = TRUE; break; } PrintEscString (LST_NodeName(st), fp); break; case CMD_NAMES: macro = (MakeMacro*)LST_FindName (macrolist, LST_NodeName(st)); if (!macro) { SetGlobalErr (ERR_GENERIC); GEprintf2 ("'%s' macro not found in file '%s'", LST_NodeName(st), filename); return FALSE; } if (!fp) { printf ("ERROR:'_Names' command issued with no file opened\n"); error = TRUE; break; } firstflag = TRUE; name = (NameType*)LST_Head (¯o->Names); while (!LST_EndOfList (name)) { if (firstflag && st->Arg1) { firstflag = FALSE; if (!ApplyRule (name, st->Arg1, fp)) { error = TRUE; } } else if (st->Arg2) { if (!ApplyRule (name, st->Arg2, fp)) { error = TRUE; } } while (!LST_EndOfList (name)) { if (name->Macro) { stack = (StackType*)LST_CreateNode (sizeof (StackType), NULL); if (!stack) { SetGlobalErr (ERR_OUT_OF_MEMORY); GEprintf ("OOM: couldn't allocate stack entry"); return FALSE; } stack->Father = name; LST_AddTail (stacklist, stack); stacksize++; name = (NameType*)LST_Head (&name->Macro->Names); } else if (name->Delim) { name = (NameType*)LST_Next (name); break; } else { name = (NameType*)LST_Next (name); while (stacksize && LST_EndOfList (name)) { stack = (StackType*)LST_RemTail (stacklist); if (stack) { name = (NameType*)LST_Next (stack->Father); LST_DeleteNode (stack); stacksize--; } } } } } if (st->Arg3) { PrintEscString (st->Arg3, fp); } break; case CMD_CLOSE: if (fp) { fclose (fp); fp = NULL; } break; } st = (Statement*)LST_Next (st); } return (error ? FALSE : TRUE); } /* CreateFiles */