ConfigTrailer:
PROC[name: Name]
RETURNS[] = {
cedarCoreConfig: BOOLEAN ¬ data.cedarCoreConfig;
IF main
THEN {
Line[];
IO.PutRope[stream, "\tfirstControl = XR𡤏irstControl();"]};
PopScope[];
IF cedarCoreConfig
THEN {
Line[];
IO.PutRope[stream, "\tXR←StartCedarModule(firstControl);"];
Line[];
IO.PutRope[stream, "\t}"];
Line[];
IO.PutRope[stream, "\tfirsttime = 0;"];
};
Line[];
IO.PutRope[stream, "}"];
IF main
THEN {
Line[2];
IO.PutRope[stream, IF data.extern THEN "extern" ELSE "static"];
IF cedarCoreConfig THEN IO.PutRope[stream, " void XR←install←"]
ELSE IO.PutRope[stream, " void XR←run←"];
IO.UnsafePutBlock[stream, HashToBlock[name]];
IF cedarCoreConfig
THEN
{
IO.PutRope[stream, "() { XR←run←"];
IO.UnsafePutBlock[stream, HashToBlock[name]];
IO.PutRope[stream, "(); }"]
}
ELSE IO.PutRope[stream, "() { XR←StartCedarModule(firstControl); }"];
};
IF main
THEN {
Line[2];
IO.PutRope[stream, IF data.extern THEN "extern" ELSE "static"];
IO.PutRope[stream, " void XR←unload←"];
IO.UnsafePutBlock[stream, HashToBlock[name]];
IO.PutRope[stream, "() { XR←Unload(firstControl); }"]};
main ¬ FALSE;
IF data.buildPackagedWorld
THEN {
generate the XR←InstallAndRunPackage boilerplate:
#include <string.h>
char XR←packageVersion[] = "<Today's Date>";
static char *argvec[25];
static char **defaultArgv = &argvec[0];
static int firstTime = 1;
static int defaultArgc = 0;
void XR←GetPackageDefaultArgs(argc←ptr, argv←ptr)
int *argc←ptr; char ***argv←ptr; {
extern char defaultArgs[];
char *nextArg;
if( (argc←ptr == 0) || (argv←ptr == 0) ) return;
if(!firstTime) {
*argv←ptr = defaultArgv;
*argc←ptr = defaultArgc;
return;}
for (;;) {
if (firstTime) {
nextArg = strtok(defaultArgs, " ");
firstTime = 0;}
else nextArg = strtok(0, " ");
if (nextArg == 0) break;
defaultArgv[defaultArgc] = nextArg;
defaultArgc++;};
*argv←ptr = defaultArgv;
*argc←ptr = defaultArgc;}
void XR←SetupPackage() { return;}
void XR←InstallAndRunPackage() {
XR←install←<packagename>();
XR𡤌ommitInstallation();
XR←run←<packagename>();
}
Put: PROC [r: Rope.ROPE] = {IO.PutRope[stream, r]};
Line[2];
Put["#include <string.h>\n"];
Put["char XR←packageVersion[] = \""];
Put[Convert.RopeFromTime[BasicTime.Now[]]]; Put["\";\n"];
Put["static char *argvec[25];\n"];
Put["static char **defaultArgv = &argvec[0];\n"];
Put["static int firstTime = 1;\n"];
Put["static int defaultArgc = 0;\n"];
Put["void XR←GetPackageDefaultArgs(argc←ptr, argv←ptr)\n"];
Put["\tint *argc←ptr; char ***argv←ptr; {\n"];
Put["\textern char defaultArgs[];\n"];
Put["\tchar *nextArg;\n"];
Put["\tif( (argc←ptr == 0) || (argv←ptr == 0) ) return;\n"];
Put["\tif(!firstTime) {\n"];
Put["\t\t*argv←ptr = defaultArgv;\n"];
Put["\t\t*argc←ptr = defaultArgc;\n"];
Put["\t\treturn;}\n"];
Put["\tfor (;;) {\n"];
Put["\t\tif (firstTime) {\n"];
Put["\t\t\tnextArg = strtok(defaultArgs, \" \");\n"];
Put["\t\t\tfirstTime = 0;}\n"];
Put["\t\telse nextArg = strtok(0, \" \");\n"];
Put["\t\tif (nextArg == 0) break;\n"];
Put["\t\tdefaultArgv[defaultArgc] = nextArg;\n"];
Put["\t\tdefaultArgc++;}\n"];
Put["\t*argv←ptr = defaultArgv;\n"];
Put["\t*argc←ptr = defaultArgc;\n}\n"];
Put["void XR←SetupPackage() { return;}\n"];
Put["void XR←InstallAndRunPackage() {\n"];
Put["\tXR←install←"]; IO.UnsafePutBlock[stream, HashToBlock[name]]; Put["();\n"];
Put["\tXR𡤌ommitInstallation();\n"];
Put["\tXR←run←"]; IO.UnsafePutBlock[stream, HashToBlock[name]]; Put["();\n}\n"];
};
};
OuterHeader:
PROC[name: Name]
RETURNS[] = {
IO.PutRope[stream, "/* "];
IO.UnsafePutBlock[stream, HashToBlock[name]];
IO.PutF1[stream, ".c produced by Cinder of %g", IO.time[Loader.BCDBuildTime[]]];
IO.PutRope[stream, " */"];
Line[2];
IO.PutRope[stream, "#include <cedar/InstallationSupport.h>"];
IO.PutRope[stream, "/* formerly from <cedar/InstallationSupport.h>: */"]; Line[];
These must match the definitions exported by InstallationSupport*.df
IO.PutRope[stream, "typedef unsigned XR←InterfacePtr;"]; Line[];
IO.PutRope[stream, "typedef unsigned XR←GlobalFramePtr;"]; Line[];
IO.PutRope[stream, "extern XR←InterfacePtr XR←ImportInterface ();"]; Line[];
IO.PutRope[stream, "extern XR←InterfacePtr XR𡤎xportInterface ();"]; Line[];
IO.PutRope[stream, "extern void XR𡤎xportProc ();"]; Line[];
IO.PutRope[stream, "extern void XR←PushScope ();"]; Line[];
IO.PutRope[stream, "extern void XR←HideNames ();"]; Line[];
IO.PutRope[stream, "extern void XR←PopScope ();"]; Line[];
IO.PutRope[stream, "extern void XR←PushRename ();"]; Line[];
IO.PutRope[stream, "extern void XR←PopRename ();"]; Line[];
IO.PutRope[stream, "extern void XR𡤏orgetName ();"]; Line[];
IO.PutRope[stream, "extern void XR←ProhibitDuplicateExports ();"]; Line[];
IO.PutRope[stream, "extern void XR←PermitDuplicateExports ();"]; Line[];
IO.PutRope[stream, "extern void XRontrol ();"]; Line[];
IO.PutRope[stream, "extern XR←GlobalFramePtr XR𡤏irstControl();"]; Line[];
IO.PutRope[stream, "void XR←Start ();"]; Line[];
IO.PutRope[stream, "static char versionStamp[] = \"@"];
IO.PutF[stream, "(#)mob←version [%g,%g] %g\";",
IO.card[OSMiscOps.StampToTime[data.objectStamp][0]],
IO.card[OSMiscOps.StampToTime[data.objectStamp][1]],
IO.rope[data.sourceName]];
Line[];
IO.PutRope[stream, "static char configBuildTime[] = \"@"];
IO.PutRope[stream, "(#)configBuildTime "];
IO.PutRope[stream, Convert.RopeFromTime[BasicTime.Now[]]];
IO.PutRope[stream, "\";"];
Line[];
IO.PutF1[stream, "char XR𡤌onfigBuildTime←%g[] = \"",
IO.rope[data.rootName]];
IO.PutRope[stream, Convert.RopeFromUnpackedTime[BasicTime.UnpackZ[BasicTime.Now[]]]];
IO.PutRope[stream, "\";"];
Line[];
};
}.