home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / UTILS / DLGDS4 / CPPSRC2.CPP < prev    next >
C/C++ Source or Header  |  1993-08-06  |  19KB  |  715 lines

  1. /*Substitutions and fills in file, cppskel.dat
  2.  
  3.   Area Fills
  4.   @ZZ0    Form the dialog in constructor
  5.   @ZZ1    Defined Control Names in Object Def.
  6.   @ZZ2    Data struct def
  7.   @ZZ3    Variable names in 'read'
  8.   @ZZ4    Variable names in 'write'
  9.   @ZZ5    Ancestor constructor call
  10.   @ZZ6    Uses_ stuff
  11.   @ZZ7    include of tcolortx.h, tinplong.h
  12.   @ZZ8    Links
  13.  
  14.   Substitutions
  15.   @XX1    Dialog's Symbol   (as  TMyDialog)
  16.   @XX2    Dialog's ancestor (usually TDialog)
  17.   @XX3    Dialog's registration TStreamRec (as RMyDialog)
  18.   @XX4    Filename (upper case)
  19.   @XX5    Filename (lower case)
  20. */
  21.  
  22. #define Uses_TStringCollection
  23. #include <tv.h>
  24. #include <stdlib.h>
  25. #include <dos.h>
  26. #include <dir.h>
  27. #include <fcntl.h>
  28. #include <string.h>
  29. #include <iostream.h>
  30. #include <fstream.h>
  31. #include <stdio.h>
  32. #include "readscpt.h"
  33.  
  34. ofstream outf;
  35. ifstream data;
  36. #define BIG 300
  37. char s[BIG], upperName[MAXFILE], lowerName[MAXFILE];
  38. Boolean needcontrol1 = False;
  39.  
  40. char* quoted(const char* s)
  41. //returns a double quoted string or "0" for empty string
  42. {
  43.  static char q[300] = {"\""};   //the first quote in place
  44.  if (*s == '\0' || !s) return "0";
  45.  strcpy(&q[1], s);
  46.  short l = strlen(q);
  47.  q[l] = '\"';
  48.  q[l+1] = '\0';
  49.  return q;
  50. }
  51.  
  52. void aField(ViewObj *P, char* fieldtype)
  53. {
  54.  outf << "  " << fieldtype << " " << P->FieldName << ";   //" << P->Obj <<endl;
  55. }
  56. void aVar(ViewObj *P)
  57. {
  58.  if (strcmp(P->VarName, "control") != 0)
  59.    outf << "    " << P->Obj << " *" << P->VarName << ";\n";
  60. }
  61.  
  62. //the following extend the ViewObj struct's to also write the code
  63. struct DialogWriteObj : DialogObj {
  64.      virtual void writeCode();
  65.      };
  66.  
  67. struct ButtonWriteObj : ButtonObj {
  68.      virtual void writeCode();
  69.      virtual void writeVars() {aVar(this);};
  70.      };
  71.  
  72. struct InputLongWriteObj : InputLongObj {
  73.      virtual void writeCode();
  74.      virtual void writeFields() {aField(this, "long");} ;
  75.      virtual void writeVars() {aVar(this);};
  76.      };
  77. struct LabelWriteObj : LabelObj {
  78.      virtual void writeCode();
  79.      };
  80. struct HistoryWriteObj : HistoryObj {
  81.      virtual void writeCode();
  82.      };
  83. struct InputLineWriteObj : InputLineObj {
  84.      virtual void writeCode();
  85.      virtual void writeFields();
  86.      virtual void writeVars() {aVar(this);};
  87.      };
  88. struct ClusterWriteObj : ClusterObj {
  89.      virtual void writeCode();
  90.      virtual void writeFields() {aField(this, "ushort");} ;
  91.      virtual void writeVars() {aVar(this);};
  92.      };
  93. struct ListBoxWriteObj : ListBoxObj {
  94.      virtual void writeCode();
  95.      virtual void writeFields() {aField(this, "TListBoxRec");} ;
  96.      virtual void writeVars() {aVar(this);};
  97.      };
  98. struct ScrollBarWriteObj : ScrollBarObj {
  99.      virtual void writeCode();
  100.      virtual void writeVars();
  101.      };
  102. struct MemoWriteObj : MemoObj {
  103.      virtual void writeCode();
  104.      virtual void writeFields();
  105.      virtual void writeVars() {aVar(this);};
  106.      };
  107. struct StaticTextWriteObj : StaticTextObj {
  108.      virtual void writeCode();
  109.      virtual void writeVars() {aVar(this);};
  110.      };
  111. struct ColoredTextWriteObj : ColoredTextObj {
  112.      virtual void writeCode();
  113.      virtual void writeVars() {aVar(this);};
  114.      };
  115.  
  116.  
  117.  
  118. //now that we know the final extensions of ViewObj, we can write the
  119. //getKind function
  120. ViewObj *getKind(recType Kind)
  121. { ViewObj *P;
  122.   switch (Kind) {
  123.       case Dlg : P = new DialogWriteObj(); break;
  124.       case Button : P = new ButtonWriteObj(); break;
  125.       case InputL : P = new InputLineWriteObj(); break;
  126.       case Labl : P = new LabelWriteObj();  break;
  127.       case Histry : P = new HistoryWriteObj(); break;
  128.       case ILong : P = new InputLongWriteObj(); break;
  129.       case CheckB: P = new ClusterWriteObj(); break;
  130.       case RadioB: P = new ClusterWriteObj(); break;
  131.       case MultiCB: P = new MultiCheckBoxObj(); break;
  132.       case ListB: P = new ListBoxWriteObj(); break;
  133.       case ScrollB :  P = new ScrollBarWriteObj(); break;
  134.       case Memo: P = new MemoWriteObj(); break;
  135.       case SText: P = new StaticTextWriteObj(); break;
  136.       case CText : P = new ColoredTextWriteObj(); break;
  137.       default : P = 0; break;
  138.       }
  139. return P;
  140. }
  141.  
  142. char * getWinFlagWords(ushort w, char *s)
  143. //given the set bits return names in 'or' form
  144. {
  145.  static char *flagArray[4] =  {
  146.         "wfMove", "wfGrow", "wfClose", "wfZoom"};
  147.  s[0] = '\0';
  148.  for (int i = 0; i <= 15; i++) {
  149.    if ((w & 1) == 1 && flagArray[i][0] != '\0')
  150.      strcat(strcat(s, flagArray[i]), " | ");
  151.    w >>= 1;
  152.    }
  153.  int l = strlen(s);
  154.  if (l > 4)
  155.     s[l-3] = '\0';   //remove last " | "
  156.  return s;
  157. }
  158.  
  159. char * getEventWords(ushort w, char *s)
  160. //given the set bits return names in 'or' form
  161. {
  162.  static char *flagArray[10] =  {
  163.         "evMouseDown", "evMouseUp", "evMouseMove", "evMouseAuto",
  164.         "evKeyDown", "", "", "", "evCommand", "evBroadcast"};
  165.  s[0] = '\0';
  166.  for (int i = 0; i <= 15; i++) {
  167.    if ((w & 1) == 1 && flagArray[i][0] != '\0')
  168.      strcat(strcat(s, flagArray[i]), " | ");
  169.    w >>= 1;
  170.    }
  171.  int l = strlen(s);
  172.  if (l > 4)
  173.     s[l-3] = '\0';   //remove last " | "
  174.  return s;
  175. }
  176.  
  177. char * getOptionWords(ushort w, char *s)
  178. //given the set bits return names in 'or' form
  179. {
  180.  static char *flagArray[16] =  {
  181.         "ofSelectable", "ofTopSelect", "ofFirstClick", "ofFramed",
  182.         "ofPreProcess", "ofPostProcess", "ofBuffered", "ofTileable",
  183.         "ofCenterX", "ofCenterY", "ofValidate", "0x800", "0x1000",
  184.         "0x2000", "0x4000", "ofShoehorn"};
  185.  s[0] = '\0';
  186.  for (int i = 0; i <= 15; i++) {
  187.    if ((w & 1) == 1 && flagArray[i][0] != '\0')
  188.      strcat(strcat(s, flagArray[i]), " | ");
  189.    w >>= 1;
  190.    }
  191.  int l = strlen(s);
  192.  if (l > 4)
  193.     s[l-3] = '\0';   //remove last " | "
  194.  return s;
  195. }
  196.  
  197. short bitCount(ushort w) //numbers of set bits in the word
  198. {
  199.  short count = 0;
  200.  for (int i = 0; i <= 15; i++)  {
  201.     if ((w & 1) == 1)
  202.        count++;
  203.     w >>= 1;
  204.     }
  205. return count;
  206. }
  207.  
  208. void doBitOutput(const char* var, const char* pre, ushort actual,
  209.                        ushort defaul, char* (func)(ushort w, char* s))
  210. //output something like "foo->options |= ofSelectable or ofFramed;"
  211. //and/or "foo-> options &= ofTopSelect;"
  212. //actual is the bits set and defaul are the default settings
  213. //it's known that actual and defaul are not equal on entry
  214. {
  215.  char s[100];
  216.  ushort NOTs, ORs, diff ;
  217.  diff = actual ^ defaul;  //the bits that are different
  218.  if (bitCount(diff) > 5) { //this is too complex--output hex number
  219.    outf << var << pre << " = 0x" << hex << actual << dec <<";\n";
  220.    return;
  221.    }
  222.  NOTs = diff & defaul;  //the bits not in defaul
  223.  ORs = diff & actual;    //the extra bits in actual
  224.  s[0] = '\0';
  225.  if (NOTs != 0) {
  226.    outf << " " << var <<pre;
  227.    if (bitCount(NOTs) == 1)
  228.      outf << " &= ~" << func(NOTs, s) << ";\n";
  229.    else
  230.      outf << " &= ~(" << func(NOTs, s) << ");\n";
  231.    }
  232.  s[0] = '\0';
  233.  if (ORs != 0)
  234.    outf << " " << var << pre << " |= " << func(ORs, s) << ";\n";
  235. }
  236.  
  237. void doTRect(ViewObj *P)
  238. {
  239. outf << "(TRect(" << P->X1 << ", " << P->Y1 << ", "
  240.      << P->X2 << ", " << P->Y2 << ")";
  241. }
  242.  
  243. void insertControl(const char *Name)
  244. {
  245.  outf <<  " insert(" << Name << ");\n\n";
  246. }
  247.  
  248. void doOpEvent(ViewObj *P)
  249. {if (P->DefEvMsk != P->EvMsk)
  250.    doBitOutput(P->VarName, "->eventMask", P->EvMsk, P->DefEvMsk, getEventWords);
  251.  
  252. if (P->DefOptns != P->Optns)
  253.    doBitOutput(P->VarName, "->options", P->Optns, P->DefOptns, getOptionWords);
  254.  
  255. }
  256.  
  257. void writeHelpCtx(char * VarName, char* H, ushort Ctx)
  258. {
  259. if (*H != '\0') {
  260.   if (strcmp(H, "hcNoContext")) {
  261.     outf << " " << VarName << "->helpCtx = " << H << ";\n";
  262.     }
  263.   }
  264. else if (Ctx != 0) {
  265.     outf << " " << VarName << "->helpCtx = " << Ctx << ";\n";
  266.     }
  267. }
  268.  
  269. void start(ViewObj *P)
  270. {
  271.   outf << " " << P->VarName << " = new " << P->Obj;
  272.   doTRect(P);
  273. }
  274.  
  275. void finish(ViewObj *P)
  276. {
  277.  writeHelpCtx(P->VarName, P->HelpCtxSym, P->HCtx);
  278.  doOpEvent(P);
  279.  insertControl(P->VarName);
  280. }
  281.  
  282. void flagsOut(ushort flags)
  283. {
  284.  if (flags == 0) outf << "bfNormal";
  285.  else {
  286.     short plus = 0;
  287.     if ((flags & 1) != 0) {
  288.         plus = 1; outf << "bfDefault"; }
  289.     if ((flags & 2) != 0) {
  290.         if (plus) outf << "|";
  291.         plus = 1;
  292.         outf << "bfLeftJust";}
  293.     if ((flags & 4) != 0) {
  294.         if (plus) outf << "|";
  295.         plus = 1;
  296.         outf << "bfBroadcast"; }
  297.     if ((flags & 8) != 0)  {
  298.         if (plus) outf << "|";
  299.         outf << "bfGrabFocus"; }
  300.     }
  301. }
  302.  
  303. void ButtonWriteObj::writeCode()
  304. {
  305.  start(this);
  306.  outf << ", " << quoted(ButtonText) << ", ";
  307.  if (*CommandName != '\0')
  308.     outf << CommandName;
  309.  else outf << CommandValue;
  310.  outf << ", ";
  311.  flagsOut(Flags);
  312.  outf << ");\n";
  313.  finish(this);
  314. }
  315.  
  316. void LabelWriteObj::writeCode()
  317. {
  318.  outf << "   insert(new " << Obj;
  319.  doTRect(this);
  320.  outf << ", " << quoted(LabelText) << ", " << LinkName << "));\n\n";
  321. }
  322.  
  323. void HistoryWriteObj::writeCode()
  324. {
  325.  outf << "   insert(new " << Obj;
  326.  doTRect(this);
  327.  outf << ", (TInputLine*)" << HistoryLink << ", " << HistoryID << "));\n\n";
  328. }
  329.  
  330. void InputLongWriteObj::writeCode()
  331. {
  332.   start(this);
  333.   outf << ", " << (LongStrLeng+1) << ", " << LLim << ", " << ULim <<  ", "
  334.        << ILOptions << ", " << quoted(LongLabelText) << ");\n";
  335.   finish(this);
  336. }
  337.  
  338. void InputLineWriteObj::writeCode()
  339. {
  340.   start(this);
  341.   outf << ", " << (StringLeng+1) << ");\n";    //Note: add 1
  342.   finish(this);
  343. }
  344. void InputLineWriteObj::writeFields()
  345. {
  346.   outf << "  char " << FieldName << "[" << (StringLeng+1)  //Note: add 1 !
  347.        << "];   //" << Obj << endl;
  348. }
  349.  
  350. void doText(char *s)
  351. {    //split up a long string into several lines. String cannot exceed 254
  352.  if (!*s) {
  353.    outf << 0;
  354.    return;
  355.    }
  356.  if (strlen(s) > 254) s[254] = '\0';   //truncate if too big
  357.  outf << '\"';
  358.  short count = 47;
  359.  while (*s)  {
  360.     if (s[0] == '\\' && s[1] == 'n' && s[2]) {
  361.        outf << s[0] << s[1] << "\"\n     \"";
  362.        count = 5;
  363.        s++;    //extra increment to pass 'n'
  364.        }
  365.     else {
  366.        outf << *s;
  367.        count++;
  368.        }
  369.     s++;
  370.     if (count > 75 && *s) {
  371.        outf << "\"\n     \"";
  372.        count = 5;
  373.        }
  374.     }
  375.  outf << '\"';
  376. }
  377.  
  378. void StaticTextWriteObj::writeCode()
  379. {
  380.   start(this);
  381.   outf << ", ";
  382.   doText(Text);
  383.   outf << ");\n";
  384.   finish(this);
  385. }
  386.  
  387. void ColoredTextWriteObj::writeCode()
  388. {
  389.   start(this);
  390.   outf << ", ";
  391.   doText(Text);
  392.   outf << ", 0x" << hex << Attrib << dec << ");\n";
  393.   finish(this);
  394. }
  395.  
  396. void ScrollBarWriteObj::writeCode()
  397. {
  398.   start(this);
  399.   outf << ");\n";
  400.   finish(this);
  401. }
  402.  
  403. void ScrollBarWriteObj::writeVars()
  404. {
  405.  if (strcmp(VarName, "control1") != 0) //control1 is used by TMemo
  406.    aVar(this);
  407.  else needcontrol1 = True;
  408. }
  409.  
  410. void ListBoxWriteObj::writeCode()
  411. {
  412.   start(this);
  413.   outf << ", " << Columns << ", ";
  414.   if (*ScrollBar != '\0')
  415.     outf << "(TScrollBar*)" << ScrollBar << ");\n";
  416.   else outf << "0);\n";
  417.   finish(this);
  418. }
  419.  
  420. void MemoWriteObj::writeCode()
  421. {
  422.   start(this);
  423.   outf << ", " ;
  424.   if (*HScroll != '\0')
  425.     outf << "(TScrollBar*)" << HScroll << ", ";
  426.   else outf << "0, ";
  427.   if (*VScroll != '\0')
  428.     outf << "(TScrollBar*)" << VScroll << ", 0, ";
  429.   else outf << "0, 0, ";
  430.   outf << BufSize << ");\n";
  431.   finish(this);
  432. }
  433. void MemoWriteObj::writeFields()
  434. {
  435.   outf << "  ushort " << FieldName << ";   //" << Obj << " text length\n";
  436.   outf << "  char " << TextFieldName << "[" << BufSize << "];   //"
  437.        << Obj << " text\n";
  438. }
  439.  
  440. void ClusterWriteObj::writeCode()
  441. {
  442.   start(this);
  443.   for (int i=0; i < Items; i++)
  444.     outf << ",\n  new TSItem(\"" << (char *)LabelColl->at(i) << "\"";
  445.   outf << ", 0";
  446.   for (i = 0; i <= Items; i++)
  447.     outf << ")";
  448.   outf << ";\n";
  449.   finish(this);
  450. }
  451.  
  452. void DoControls(void *p, void*)
  453. {ViewObj *P = (ViewObj*)p;
  454.  P->writeCode();
  455. }
  456.  
  457. void DialogWriteObj::writeCode()
  458. {
  459.   outf << " TView *control";
  460.   if (needcontrol1) outf << ", *control1;\n";
  461.   else outf << ";\n";
  462.  
  463.   if (DefEvMsk != EvMsk)
  464.      doBitOutput("", "eventMask", EvMsk, DefEvMsk, getEventWords);
  465.  
  466.   if (DefOptns != Optns)
  467.      doBitOutput("", "options", Optns, DefOptns, getOptionWords);
  468.  
  469.   if (WinFlags != 5)    //5 is the default
  470.      doBitOutput("", "flags", WinFlags, 5, getWinFlagWords);
  471.   writeHelpCtx("this", HelpCtxSym, HCtx);                //!! needs work !!
  472.   outf << endl;
  473.  
  474.   ScriptColl->forEach(DoControls, 0);
  475. }
  476.  
  477. char* SkelDatName(char *exe, char* rtn)
  478. //find where to locate cppskel.dat.  Use drive, directory of this exe file
  479. {
  480.  char drive[MAXDRIVE];
  481.  char dir[MAXDIR];
  482.  char name[MAXFILE];
  483.  char ext[MAXEXT];
  484.  fnsplit(exe, drive, dir, name, ext);
  485.  fnmerge(rtn, drive, dir, "CPPSKEL", ".DAT");
  486.  return rtn;
  487. }
  488.  
  489. void subst(char *p) //make a substitution for @XXn
  490. {
  491. char tail[BIG];
  492. short n = *(p+3) - '0';    //get the @XX #
  493. *p = '\0';                 //terminate s at the '@'
  494. strcpy(tail, p+4);         //keep the rest of the line
  495. switch (n) {
  496.   case 1 :                //this would be @XX1
  497.        strcat(s, Dialog->Obj);
  498.        strncat(s, tail, BIG-strlen(s));
  499.        break;
  500.   case 2 :
  501.        strcat(s, "TDialog");
  502.        strncat(s, tail, BIG-strlen(s));
  503.        break;
  504.   case 3 :
  505.        strcat(s, "R");            //subst 'R' for 'T'
  506.        strcat(s, Dialog->Obj+1);  //less the 'T'
  507.        strncat(s, tail, BIG-strlen(s));
  508.        break;
  509.   case 4 :
  510.        strcat(s, upperName);
  511.        strncat(s, tail, BIG-strlen(s));
  512.        break;
  513.   case 5 :
  514.        strcat(s, lowerName);
  515.        strncat(s, tail, BIG-strlen(s));
  516.        break;
  517.   }
  518. }
  519.  
  520. void doWriteItems(void *p, void* first)
  521. {
  522.  ViewObj *P = (ViewObj*)p;
  523.  if (*P->VarName != '\0' && strcmp(P->VarName, "control") != 0
  524.                  && strcmp(P->VarName, "control1") != 0) {
  525.     if (*(int*)first)  {
  526.        outf << " os";
  527.        *(int*)first = False;
  528.        }
  529.     outf << " << " << P->VarName;
  530.     }
  531. }
  532.  
  533. void doTheWriteItems()
  534. {//code to Write pointers in 'Write'
  535.  int first = True;
  536.  ScriptColl->forEach(doWriteItems, &first);
  537.  if (!first) outf << ";\n";  //if !first, there is at least one item
  538. }
  539.  
  540. void doReadItems(void *p, void* first)
  541. {
  542.  ViewObj *P = (ViewObj*)p;
  543.  if (*P->VarName != '\0' && strcmp(P->VarName, "control") != 0
  544.                  && strcmp(P->VarName, "control1") != 0) {
  545.     if (*(int*)first)  {
  546.        outf << " is";
  547.        *(int*)first = False;
  548.        }
  549.     outf << " >> " << P->VarName;
  550.     }
  551. }
  552.  
  553. void doTheReadItems()
  554. {//code to read pointers in 'read'
  555.  int first = True;
  556.  ScriptColl->forEach(doReadItems, &first);
  557.  if (!first) outf << ";\n";  //if !first, there is at least one item
  558. }
  559.  
  560. void doFields(void *p, void* first)
  561. {     // fieldnames for the data transfer struct
  562.  ViewObj *P = (ViewObj*)p;
  563.  if (*(int*)first && *P->FieldName != '\0') {
  564.     outf << "struct " << Dialog->FieldName << "  {\n";
  565.     *(int*)first = False;
  566.     }
  567.  P->writeFields();
  568. }
  569.  
  570. void doTheDataStruct()
  571. {//code to build the data transfer struct
  572.  if (present[ListB])   //if we have listbox, define TListBoxRec
  573.     outf <<
  574.       "#if !defined(__TListBoxRec)\n"
  575.       "#define __TListBoxRec\n"
  576.       "struct TListBoxRec\n"
  577.       "{\n"
  578.       "    TCollection* collection;\n"
  579.       "    short focused;\n"
  580.       "};\n"
  581.       "#endif\n\n";
  582.  
  583.  int first = True;
  584.  ScriptColl->forEach(doFields, &first);
  585.  if (!first) outf << "  };\n\n";  //if !first, there is at least one field
  586. }
  587.  
  588. void doVars(void *p, void*)
  589. {ViewObj *P = (ViewObj*)p;
  590.  P->writeVars();
  591. }
  592.  
  593. void doTheVars()
  594.  //define variables whose names are not "control"
  595. {
  596.  ScriptColl->forEach(doVars, 0);
  597.  outf << endl;
  598. }
  599.  
  600. void ancestorConstructor()
  601. {
  602.  outf << "       TDialog";
  603.  doTRect(Dialog);
  604.  outf << ", " << quoted(((DialogWriteObj*)(Dialog))->Title) << "),\n";
  605. }
  606.  
  607. void doUsesStuff()
  608. {
  609.  static char* uses[] = {"TDialog", "TButton", "TStaticText", "TColoredText",
  610.     "TInputLine", "TLabel", "THistory", "TInputLong", "TCheckBoxes",
  611.     "TRadioButtons", "TMultiCheckBoxes", "TListBox", "TMemo", "TScrollBar"};
  612.  
  613.  short ts = 0;
  614.  for (recType i = Button; i <= ScrollB; ((int)i)++)
  615.     if (present[i]) {
  616.        outf << "#define Uses_" << uses[i] << endl;
  617.        ts |= (i == CheckB || i == RadioB || i == MultiCB);
  618.        }
  619.  if (ts)
  620.     outf << "#define Uses_TSItem\n";
  621. }
  622.  
  623. void doLinks(void *p, void*)
  624. {char *P = (char*)p;
  625.  outf << "__link(R" << (char*)((P)+1) << ")\n";  //subst 'R' for 'T'
  626. }
  627.  
  628. void doIncludes()
  629. {
  630.   if (present[CText])
  631.     outf << "#include \"tcolortx.h\"\n";
  632.   if (present[ILong])
  633.     outf << "#include \"tinplong.h\"\n";
  634. }
  635.  
  636. //-------------------------------------------------------------------
  637. // The following exit procedure is required in order to view error
  638. // messages before Turbo Vision wipes out the screen
  639. //-------------------------------------------------------------------
  640. int exit_flag = 1;
  641.  
  642. void exitfunc(void)
  643. {
  644.   if( exit_flag )
  645.   {
  646.      cout << "\nStrike Enter key to continue" << endl;
  647.      char c;
  648.      cin.get(c);
  649.   }
  650. }
  651.  
  652. #pragma exit exitfunc  100
  653.  
  654. int main(int argc, char** argv)
  655. // argv[1] is script file
  656. // argv[2] is .src name
  657. // argv[3] is error filename
  658.  
  659. {
  660.  if (argc < 3) {
  661.    cout << "Usage:  cppsrc2 <script filename> <source filename> [error filename]";
  662.    exit(1);
  663.    }
  664.  if (argc >= 4) {
  665.    freopen(argv[3], "w", stdout);
  666.    exit_flag = 0;   // won't need hold up on exit
  667.    }
  668.  
  669.  checkMemory();
  670.  
  671.  data.open(SkelDatName(argv[0], s), ios::in);
  672.  if (!data.good()) {
  673.    cout << "Can't open cppskel.dat" << endl;
  674.    exit(1);
  675.    }
  676.  
  677.  readScriptFile(argv[1]);  //argv(1) is temporary script file
  678.  
  679.  outf.open(argv[2], ios::out);
  680.  if (!outf.good()) {
  681.    cout << "Can't open source file" << endl;
  682.    exit(1);
  683.    }
  684.  fnsplit(argv[2], 0, 0, upperName, 0);
  685.  strupr(upperName);            //for use later
  686.  strcpy(lowerName, upperName);
  687.  strlwr(lowerName);
  688.  
  689.  while (!data.eof()) {
  690.     data.getline(s, BIG);
  691.     if (strcmp(s, "@ZZ0") == 0) Dialog->writeCode();
  692.     else if (strcmp(s, "@ZZ1") == 0) doTheVars();
  693.     else if (strcmp(s, "@ZZ2") == 0) doTheDataStruct();
  694.     else if (strcmp(s, "@ZZ3") == 0) doTheReadItems();
  695.     else if (strcmp(s, "@ZZ4") == 0) doTheWriteItems();
  696.     else if (strcmp(s, "@ZZ5") == 0) ancestorConstructor();
  697.     else if (strcmp(s, "@ZZ6") == 0) doUsesStuff();
  698.     else if (strcmp(s, "@ZZ7") == 0) doIncludes();
  699.     else if (strcmp(s, "@ZZ8") == 0) classCollection->forEach(doLinks, 0);
  700.     else  {
  701.        char *p = strstr(s, "@XX");
  702.        while (p) {
  703.          subst(p);
  704.          p = strstr(s, "@XX");
  705.          }
  706.        outf << s << endl;
  707.        }
  708.     }
  709.  
  710.  outf.close();
  711.  data.close();
  712.  cout << "completed" << endl;
  713.  return 0;
  714. }
  715.