home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR9
/
WIZTOO.ZIP
/
CODEGEN.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-22
|
7KB
|
180 lines
// Module: CODEGEN.CPP
// September 20, 1993
// Fairfield, Iowa
// Aerosoft (R) Broadcast Channel Wizard Version 1.0
// Copyright (c) Aerosoft 1993 All rights reserved.
// This software source code is FREEWARE. You may be use the
// source code or redistribute the source code free of charge.
// However, you cannot sell this source code or any alteration of
// the source code.
// This module implements four functions that each perform code generation
// for one of the four files:
// CHNNLDEF.H, BRDCASTR.H, BRDCASTR.CPP, APP.CPP
// See file BCWIZ.MAN for an explanation of these files.
#include <stdio.h>
#include <process.h>
#include "CODEGEN.H"
void GenCHNNLDEF_H(ChannelSpecs &oChannelSpecs)
{
FILE *fid;
if ((fid=fopen(CHNNLDEF_H_FILE, "wt"))==NULL)
{
printf("*** Execution error: Unable to open %s.\n", CHNNLDEF_H_FILE);
exit(0);
}
fprintf(fid, "#ifndef _chnnldef_h_\n");
fprintf(fid, "#define _chnnldef_h_\n\n");
fprintf(fid, "// Module: CHNNLDEF.H\n\n");
ChannelSpec *opSpec = oChannelSpecs.oChannelSpec;
for (int i=0; i<oChannelSpecs.iNumSpecs; i++,opSpec++)
{
fprintf(fid, "class %s {\n", opSpec->cpFuncName);
fprintf(fid, "public:\n");
fprintf(fid, "virtual void Receive%s %s=0;\n", opSpec->cpFuncName,
opSpec->cpProtoList);
fprintf(fid, "};\n\n");
}
fprintf(fid, "#endif\n");
fclose(fid);
}
void GenBRDCASTR_CPP(ChannelSpecs &oChannelSpecs)
{
FILE *fid;
if ((fid=fopen(BRDCASTR_CPP_FILE, "wt"))==NULL)
{
printf("*** Execution error: Unable to open %s.\n", BRDCASTR_CPP_FILE);
exit(0);
}
fprintf(fid, "// Module: BRDCASTR.CPP\n\n");
fprintf(fid, "#include <stdio.h>\n");
fprintf(fid, "#include \"%s\"\n", BRDCASTR_H_FILE);
fprintf(fid, "#include \"%s\"\n\n", CHNNLDEF_H_FILE);
fprintf(fid, " Broadcaster oBroadcaster;\n\n");
ChannelSpec *opSpec = oChannelSpecs.oChannelSpec;
for (int i=0; i<oChannelSpecs.iNumSpecs; i++,opSpec++)
{
fprintf(fid, "int Broadcaster::Connect (%s *op) {\n",
opSpec->cpFuncName);
fprintf(fid, " return o%sChannel.Add(op); }\n",
opSpec->cpFuncName);
fprintf(fid, "int Broadcaster::Disconnect (%s *op) {\n",
opSpec->cpFuncName);
fprintf(fid, " return o%sChannel.Delete(op); }\n",
opSpec->cpFuncName);
fprintf(fid, "void Broadcaster::Broadcast%s %s {\n",
opSpec->cpFuncName, opSpec->cpProtoList);
fprintf(fid, " for (void *op = o%sChannel.First();\n", opSpec->cpFuncName);
fprintf(fid, " op != NULL;\n");
fprintf(fid, " op = o%sChannel.Next())\n", opSpec->cpFuncName);
fprintf(fid, " {\n");
fprintf(fid, " ((%s *)op)->Receive%s%s;\n",
opSpec->cpFuncName, opSpec->cpFuncName, opSpec->cpArgList);
fprintf(fid, " }\n}\n");
}
fclose(fid);
}
void GenBRDCASTR_H(ChannelSpecs &oChannelSpecs)
{
FILE *fid;
if ((fid=fopen(BRDCASTR_H_FILE, "wt"))==NULL)
{
printf("*** Execution error: Unable to open %s.\n", BRDCASTR_H_FILE);
exit(0);
}
fprintf(fid, "#ifndef _brdcastr_h_\n");
fprintf(fid, "#define _brdcastr_h_\n\n");
fprintf(fid, "// Module: BRDCASTR.H\n\n");
fprintf(fid, "#include \"%s\"\n", CHANNEL_H_FILE);
fprintf(fid, "#include \"%s\"\n\n", CHNNLDEF_H_FILE);
fprintf(fid, "class Broadcaster {\n");
ChannelSpec *opSpec = oChannelSpecs.oChannelSpec;
for (int i=0; i<oChannelSpecs.iNumSpecs; i++,opSpec++)
{
fprintf(fid, " Channel o%sChannel;\n", opSpec->cpFuncName);
}
fprintf(fid, "public:\n");
opSpec = oChannelSpecs.oChannelSpec;
for (i=0; i<oChannelSpecs.iNumSpecs; i++,opSpec++)
{
fprintf(fid, " int Connect (%s *op);\n", opSpec->cpFuncName);
fprintf(fid, " int Disconnect (%s *op);\n", opSpec->cpFuncName);
fprintf(fid, " int ChannelStatus (%s *)\n", opSpec->cpFuncName);
fprintf(fid, " {return o%sChannel.Status();}\n", opSpec->cpFuncName);
fprintf(fid, " void Broadcast%s %s;\n",
opSpec->cpFuncName, opSpec->cpProtoList);
}
fprintf(fid, "};\n\n");
fprintf(fid, " extern Broadcaster oBroadcaster;\n\n");
fprintf(fid, "#endif\n");
fclose(fid);
}
void GenAPP_CPP(ChannelSpecs &oChannelSpecs)
{
FILE *fid;
if ((fid=fopen(APP_CPP_FILE, "wt"))==NULL)
{
printf("*** Execution error: Unable to open %s.\n", APP_CPP_FILE);
exit(0);
}
fprintf(fid, "// Module: APP.CPP\n\n");
fprintf(fid, "// Cut and paste the contents of this module to create\n");
fprintf(fid, "// application code. There are two sections: Producer\n");
fprintf(fid, "// calls and Consumer methods.\n\n");
fprintf(fid, "#include \"%s\"\n\n", CHNNLDEF_H_FILE);
fprintf(fid, "// Producer calls --\n\n");
ChannelSpec *opSpec = oChannelSpecs.oChannelSpec;
for (int i=0; i<oChannelSpecs.iNumSpecs; i++,opSpec++)
{
fprintf(fid, " oBroadcast.Broadcast%s%s;\n",
opSpec->cpFuncName, opSpec->cpArgList);
}
fprintf(fid, "\n// Consumer methods --\n\n");
opSpec = oChannelSpecs.oChannelSpec;
for (i=0; i<oChannelSpecs.iNumSpecs; i++,opSpec++)
{
fprintf(fid, "class Consumer%d : public %s {\n",
i+1, opSpec->cpFuncName);
fprintf(fid, "public:\n");
fprintf(fid, " void Receive%s %s;\n",
opSpec->cpFuncName, opSpec->cpProtoList);
fprintf(fid, "};\n");
fprintf(fid, "void Consumer%d::Receive%s %s {}\n\n",
i+1, opSpec->cpFuncName, opSpec->cpProtoList);
}
fclose(fid);
}