home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d548 / multiinstall.lha / MultiInstall / MultiInstall.lzh / MultiInstall.c next >
C/C++ Source or Header  |  1991-08-18  |  25KB  |  1,256 lines

  1. #include <functions.h>
  2. #include <ctype.h>
  3. #include <exec/types.h>
  4. #include <exec/memory.h>
  5. #include <libraries/dos.h>
  6. #include <libraries/dosextens.h>
  7. #include <intuition/intuition.h>
  8. #include <graphics/gfx.h>
  9. #include <graphics/text.h>
  10. #include <workbench/workbench.h>
  11. #include <workbench/startup.h>
  12.  
  13. #define FAULT 1
  14. #define ON 1
  15. #define NO_FAULT 0
  16. #define NO_WINDW 1
  17. #define NO_GRAFX 2
  18. #define NO_INTUI 3
  19.  
  20. #define MAKEDIR_S 0
  21. #define DELETE_S  1
  22. #define DODOS_S   2
  23. #define RENAME_S  3
  24. #define STORE_S   4
  25. #define WRITE_S   5
  26. #define COPY_S    6
  27. #define FLUSH_S   7
  28. #define PURGE_S   8
  29. #define CLEAR_S   9
  30. #define PRINT_S  10
  31. #define ASK_S    11
  32. #define WAIT_S   12
  33. #define IF_S     13
  34. #define ELSE_S   14
  35. #define END_S    15
  36. #define QUIT_S   16
  37. #define AS_S     17
  38. #define EXISTS_S 18
  39. #define MAXCOM 19
  40.  
  41. #define NO_FLAG     1
  42. #define YES_FLAG    2
  43. #define TRUE_FLAG   4
  44. #define FALSE_FLAG  8
  45. #define OK_FLAG    16
  46. #define FAULT_FLAG 32
  47. #define MAXPRED 6
  48.  
  49. #define SYMBOL 1
  50. #define STRING 2
  51. #define PREDICATE 3
  52.  
  53. #define NOT_FOUND -1
  54.  
  55. struct StoredFile
  56. {
  57. struct StoredFile *sf_NextFile;
  58. int sf_Size;
  59. char sf_Name[80];
  60. };
  61.  
  62.  
  63. struct IntuitionBase *IntuitionBase;
  64. struct GfxBase *GfxBase;
  65. struct Window *MyWindow;
  66. struct RastPort *rp;
  67.  
  68. char PrintOutBuffer[80];
  69.  
  70. struct TextAttr MyAttr =
  71. {
  72.  (STRPTR)"topaz.font",
  73.  8,
  74.  NULL,
  75.  NULL
  76. };
  77.  
  78.  
  79. SHORT TextVectors8[] =
  80. {
  81.  0,0, 69,0, 69,10, 0, 10, 0, 0, 69,0, 70,1, 70,11, 1,11
  82. };
  83.  
  84. struct Border TextBorder8 = { -1,-1, 1,0,JAM2, 9, &TextVectors8[0], NULL };
  85.  
  86. struct IntuiText NOText =
  87. { 1, 0, JAM2, 2, 1, &MyAttr, (UBYTE *)"   NO   ", NULL };
  88.  
  89. struct IntuiText CONTINUEText =
  90. { 1, 0, JAM2, 2, 1, &MyAttr, (UBYTE *)"CONTINUE", NULL };
  91.  
  92. struct IntuiText YESText =
  93. { 1, 0, JAM2, 2, 1, &MyAttr, (UBYTE *)"  YES   ", NULL };
  94.  
  95. struct IntuiText OutText =
  96. { 1, 0, JAM2, 0, 0, &MyAttr, (UBYTE *)PrintOutBuffer, NULL };
  97.  
  98.  
  99. struct Gadget CONTGadg =
  100. {
  101.  NULL,
  102.  -80, -15,
  103.  68,9,
  104.  GADGHCOMP | GRELRIGHT | GRELBOTTOM,
  105.  GADGIMMEDIATE | RELVERIFY,
  106.  BOOLGADGET,
  107.  (APTR)&TextBorder8,
  108.  NULL,
  109.  &CONTINUEText,
  110.  NULL,
  111.  NULL,
  112.  1,
  113.  NULL
  114. };
  115.  
  116. struct Gadget NOGadg =
  117. {
  118.  NULL,
  119.  -80, -15,
  120.  68,9,
  121.  GADGHCOMP | GRELRIGHT | GRELBOTTOM,
  122.  GADGIMMEDIATE | RELVERIFY,
  123.  BOOLGADGET,
  124.  (APTR)&TextBorder8,
  125.  NULL,
  126.  &NOText,
  127.  NULL,
  128.  NULL,
  129.  1,
  130.  NULL
  131. };
  132.  
  133. struct Gadget YESGadg =
  134. {
  135.  &NOGadg,
  136.  12, -15,
  137.  68,9,
  138.  GADGHCOMP | GRELBOTTOM,
  139.  GADGIMMEDIATE | RELVERIFY,
  140.  BOOLGADGET,
  141.  (APTR)&TextBorder8,
  142.  NULL,
  143.  &YESText,
  144.  NULL,
  145.  NULL,
  146.  2,
  147.  NULL
  148. };
  149.  
  150. struct NewWindow WindowData =
  151. {
  152.  0,0,
  153.  512,128,
  154.  0,1,
  155.  GADGETUP,
  156.  WINDOWDRAG | WINDOWDEPTH | ACTIVATE,
  157.  NULL,
  158.  NULL,
  159.  (UBYTE*)"MultiInstall Version 1.00 by Stefan G. Boldorf in 1991",
  160.  NULL, NULL,
  161.  NULL, NULL,
  162.  NULL, NULL,
  163.  WBENCHSCREEN,
  164. };
  165.  
  166. struct StoredFile *FirstFile = NULL;
  167. long IF_Level =0, STATE_Flags = 4;
  168. long LineCount, PrintCount, PrintChars, MaxLines, PrintLine;
  169. long WinWidth, WinHeight;
  170. char *LastPos, *Curr;
  171.  
  172.  
  173. char Command_List[19][8] =
  174. {
  175.  "MAKEDIR", "DELETE", "DODOS", "RENAME",       /* Normal DOS functions   */
  176.  "STORE", "WRITE", "COPY", "FLUSH",            /* File functions         */
  177.  "PURGE", "CLEAR",
  178.  "PRINT", "ASK", "WAIT",                       /* IO functions           */
  179.  "IF", "ELSE", "END", "QUIT", "AS",            /* Structural functions   */
  180.  "EXISTS"                                      /* Predicate function     */
  181. };
  182.  
  183.  
  184. char Predicate_List[6][6] =
  185. {
  186.  "NO", "YES", "TRUE", "FALSE", "OK", "FAULT"
  187. };
  188.  
  189.  
  190. char InfoList[10][56] =
  191. {
  192.  "This is MultiInstall Version 1.00 by Stefan G. Boldorf",
  193.  "                                                      ",
  194.  "                            Date of creation 8.8. 1991",
  195.  "                                                      ",
  196.  "MultiInstall is a simple Utility  for installing large",
  197.  "program  packages. It is driven  via an ASCII file and",
  198.  "can be started  from  either  Workbench or  CLI/SHELL.",
  199.  "                                                      ",
  200.  "This  utility is in the  Public  Domain, see the .doc",
  201.  "file for the copying agreement and instructions.      "
  202. };
  203.  
  204.  
  205. /* --------------------------- Environment Stuff ----------------------- */
  206.  
  207.  
  208.  
  209. void
  210. CloseInstWindow( how)
  211. int how;
  212. {
  213.  switch (how)
  214.    {
  215.     case NO_FAULT: CloseWindow( MyWindow);
  216.     case NO_WINDW: CloseLibrary( GfxBase);
  217.     case NO_GRAFX: CloseLibrary( IntuitionBase);
  218.     case NO_INTUI: break;
  219.    }
  220. }
  221.  
  222.  
  223.  
  224. int
  225. OpenInstWindow()
  226. {
  227.  int fault;
  228.  
  229.  fault =0;
  230.  if ( !fault)
  231.    {
  232.     fault = (IntuitionBase = (struct IntuitionBase *)
  233.              OpenLibrary("intuition.library", 0L))? NO_FAULT: NO_INTUI;
  234.    }
  235.  if ( !fault)
  236.    {
  237.     fault = (GfxBase = (struct GfxBase *)
  238.              OpenLibrary("graphics.library", 0L))? NO_FAULT: NO_GRAFX;
  239.    }
  240.  if ( !fault)
  241.    {
  242.     fault = (MyWindow = (struct Window *)
  243.              OpenWindow( &WindowData))? NO_FAULT: NO_WINDW;
  244.    }
  245.  if ( !fault)
  246.    {
  247.     rp = MyWindow->RPort;
  248.     PrintCount =0;
  249.     WinWidth   = 508 - MyWindow->BorderLeft - MyWindow->BorderRight;
  250.     PrintChars = WinWidth >>3;
  251.     WinHeight = MyWindow->Height -MyWindow->BorderTop
  252.                 -MyWindow->BorderBottom -20;
  253.     MaxLines = WinHeight / 9;
  254.     PrintLine =0;
  255.    }
  256.  else
  257.    {
  258.     CloseInstWindow( fault);
  259.    }
  260.  return( fault);
  261. }
  262.  
  263.  
  264.  
  265. void
  266. ClearPrint()
  267. {
  268.  SetAPen( rp, 0L);
  269.  RectFill( rp, (long)(MyWindow->BorderLeft), (long)(MyWindow->BorderTop),
  270.                (long)(512 - (int)(MyWindow->BorderRight)),
  271.                (long)(128 - (int)(MyWindow->BorderBottom)));
  272.  SetAPen( rp, 1L);
  273.  PrintCount = (long)(MyWindow->BorderTop) +1;
  274.  PrintLine =0;
  275. }
  276.  
  277.  
  278.  
  279. void
  280. PrintOut( TheText)
  281. char *TheText;
  282. {
  283.  if ( PrintLine >= MaxLines)
  284.    {
  285.     ClipBlit( rp, MyWindow->BorderLeft, MyWindow->BorderTop +9,
  286.               rp, MyWindow->BorderLeft, MyWindow->BorderTop,
  287.                   WinWidth, WinHeight, 0xc0);
  288.     PrintLine = MaxLines -1;
  289.     PrintCount = (int)(MyWindow->BorderTop) +1 +9*MaxLines;
  290.    }
  291.  strncpy( PrintOutBuffer, TheText, PrintChars);
  292.  PrintOutBuffer[PrintChars] =0;
  293.  SetAPen( rp, 0);
  294.  RectFill( rp, (int)(MyWindow->BorderLeft), PrintCount,
  295.                 512 - (int)(MyWindow->BorderRight), PrintCount +8);
  296.  PrintIText( rp, &OutText, (int)(MyWindow->BorderLeft), PrintCount);
  297.  PrintCount += 9;
  298.  PrintLine++;
  299. }
  300.  
  301.  
  302.  
  303. void
  304. ClearGadget( Gad, Win)
  305. struct Gadget *Gad;
  306. struct Window *Win;
  307. {
  308.  struct RastPort *wrp;
  309.  int x, y;
  310.  
  311.  wrp = Win->RPort;
  312.  SetAPen( wrp, 0);
  313.  SetDrMd( wrp, JAM2);
  314.  x = (Gad->Flags & GRELRIGHT) ? Win->Width  +Gad->LeftEdge: Gad->LeftEdge;
  315.  y = (Gad->Flags & GRELBOTTOM)? Win->Height +Gad->TopEdge : Gad->TopEdge;
  316.  RectFill( wrp, x -2, y -2, x +Gad->Width +1, y +Gad->Height +1);
  317.  SetAPen( wrp, 1);
  318. }
  319.  
  320.  
  321.  
  322. void
  323. WaitForUser( TheText)
  324. char *TheText;
  325. {
  326.  struct IntuiMessage *MyMess;
  327.  struct Gadget *MyLoc;
  328.  int MyClass, MyID;
  329.  
  330.  PrintOut( TheText);
  331.  ModifyIDCMP( MyWindow, GADGETUP);
  332.  AddGadget( MyWindow, &CONTGadg, -1);
  333.  RefreshGadgets( &CONTGadg, MyWindow, NULL);
  334.  MyID = 0;
  335.  while ( MyID != 1)
  336.    {
  337.     Wait( 1<<MyWindow->UserPort->mp_SigBit);
  338.     while( MyMess = (struct IntuiMessage *)GetMsg( MyWindow->UserPort))
  339.       {
  340.        MyClass = MyMess->Class;
  341.        MyLoc = (struct Gadget *)MyMess->IAddress;
  342.        ReplyMsg( MyMess);
  343.       }
  344.     if ( MyClass == GADGETUP)
  345.       {
  346.        MyID = MyLoc->GadgetID;
  347.       }
  348.    }
  349.  ClearGadget( &CONTGadg, MyWindow);
  350.  RemoveGadget( MyWindow, &CONTGadg);
  351.  ModifyIDCMP( MyWindow, NULL);
  352. }
  353.  
  354.  
  355.  
  356. void
  357. ErrorOut( ETxt)
  358. char *ETxt;
  359. {
  360.  char ErTxt[80];
  361.  
  362.  if (LineCount) sprintf( ErTxt, "Error in line %d: %s", LineCount, ETxt);
  363.  WaitForUser( ErTxt);
  364. }
  365.  
  366.  
  367.  
  368. void
  369. AskAbout( TheText)
  370. char *TheText;
  371. {
  372.  struct IntuiMessage *MyMess;
  373.  struct Gadget *MyLoc;
  374.  int MyClass, MyID;
  375.  
  376.  PrintOut( TheText);
  377.  ModifyIDCMP( MyWindow, GADGETUP);
  378.  AddGList( MyWindow, &YESGadg, -1, 2, NULL);
  379.  RefreshGList( &YESGadg, MyWindow, NULL, 2);
  380.  MyID = 0;
  381.  while ( MyID == 0)
  382.    {
  383.     Wait( 1<< MyWindow->UserPort->mp_SigBit);
  384.     while( MyMess = (struct IntuiMessage *)GetMsg( MyWindow->UserPort))
  385.       {
  386.        MyClass = MyMess->Class;
  387.        MyLoc = (struct Gadget *)MyMess->IAddress;
  388.        ReplyMsg( MyMess);
  389.       }
  390.     if ( MyClass == GADGETUP)
  391.       {
  392.        MyID = MyLoc->GadgetID;
  393.       }
  394.    }
  395.  ClearGadget( &YESGadg, MyWindow);
  396.  ClearGadget( &NOGadg, MyWindow);
  397.  RemoveGList( MyWindow, &YESGadg, 2);
  398.  ModifyIDCMP( MyWindow, NULL);
  399.  STATE_Flags = (MyID ==1)? (STATE_Flags & ~YES_FLAG)|NO_FLAG:
  400.                            (STATE_Flags & ~NO_FLAG)|YES_FLAG;
  401. }
  402.  
  403.  
  404.  
  405. void
  406. PrintInfo()
  407. {
  408.  int t;
  409.  
  410.  ClearPrint();
  411.  for( t=0; t < 9; t++)
  412.    {
  413.     PrintOut( InfoList[t]);
  414.    }
  415.  WaitForUser( InfoList[9]);
  416. }
  417.  
  418.  
  419.  
  420. /* ------------------------------ DOS Stuff ---------------------------- */
  421.  
  422.  
  423.  
  424. int
  425. FileSize( Name)
  426. char *Name;
  427. {
  428.  struct FileInfoBlock MyInfo;
  429.  struct FileLock *MyFile;
  430.  int back;
  431.  
  432.  back =0;
  433.  if ( MyFile = (struct FileLock *) Lock( Name, ACCESS_READ))
  434.    {
  435.     if ( Examine( MyFile, &MyInfo))
  436.       {
  437.        back = MyInfo.fib_Size;
  438.       }
  439.     UnLock( MyFile);
  440.    }
  441.  return( back);
  442. }
  443.  
  444.  
  445.  
  446. int
  447. ReadFile( Name, Loc, Size)
  448. char *Name;
  449. char *Loc;
  450. int Size;
  451. {
  452.  struct FileHandle *fh;
  453.  int back;
  454.  
  455.  back = FALSE;
  456.  fh = NULL;
  457.  if ( fh = Open( Name, MODE_OLDFILE))
  458.    {
  459.     back = Read( fh, Loc, Size) == Size;
  460.     Close( fh);
  461.    }
  462.  return( back);
  463. }
  464.  
  465.  
  466.  
  467. int
  468. WriteFile( Name, Loc, Size)
  469. char *Name;
  470. char *Loc;
  471. int Size;
  472. {
  473.  struct FileHandle *fh;
  474.  int back;
  475.  
  476.  back = FALSE;
  477.  fh = NULL;
  478.  if ( fh = Open( Name, MODE_NEWFILE))
  479.    {
  480.     back = Write( fh, Loc, Size) == Size;
  481.     Close( fh);
  482.    }
  483.  return( back);
  484. }
  485.  
  486.  
  487.  
  488. /* --------------------------- List Handling ----------------------- */
  489.  
  490.  
  491.  
  492. int
  493. StoreFile( Name, ID)
  494. char *Name;
  495. char *ID;
  496. {
  497.  struct StoredFile *help, *CurF;
  498.  int DataSize, back;
  499.  char *DataBuffer;
  500.  
  501.  back = FALSE;
  502.  CurF = NULL;
  503.  if ((DataSize = FileSize( Name)) > 0)
  504.    {
  505.     if (CurF = (struct StoredFile *)
  506.                 AllocMem( sizeof( struct StoredFile) +DataSize,
  507.                                   MEMF_PUBLIC|MEMF_CLEAR))
  508.       {
  509.        CurF->sf_Size = DataSize;
  510.        CurF->sf_NextFile = NULL;
  511.        strncpy( &CurF->sf_Name[0], ID, PrintChars);
  512.        CurF->sf_Name[PrintChars] =0;
  513.        DataBuffer = (char *)(CurF) + sizeof( struct StoredFile);
  514.        if ( ReadFile( Name, DataBuffer, DataSize))
  515.          {
  516.           back = TRUE;
  517.           if ( FirstFile == NULL)
  518.             {
  519.              FirstFile = CurF;
  520.             }
  521.           else
  522.             {
  523.              help = FirstFile;
  524.              while( help->sf_NextFile)
  525.                {
  526.                 help = help->sf_NextFile;
  527.                }
  528.              help->sf_NextFile = CurF;
  529.             }
  530.          }
  531.        else
  532.          {
  533.           ErrorOut("File is corrupt");
  534.           FreeMem( (char *)CurF, DataSize + sizeof( struct StoredFile));
  535.          }
  536.       }
  537.     else
  538.       {
  539.        ErrorOut("Not enough memory");
  540.       }
  541.    }
  542.  else
  543.    {
  544.     ErrorOut("File not found");
  545.    }
  546.  return( back);
  547. }
  548.  
  549.  
  550.  
  551. struct StoredFile
  552. *FindFile( ID)
  553. char *ID;
  554. {
  555.  struct StoredFile *Back;
  556.  int searching;
  557.  
  558.  if (Back = FirstFile)
  559.    {
  560.     searching = TRUE;
  561.     while (Back && searching)
  562.       {
  563.        if ( strcmp( ID, Back->sf_Name) == NULL)
  564.          {
  565.           searching = FALSE;
  566.          }
  567.        else
  568.          {
  569.           Back = Back->sf_NextFile;
  570.          }
  571.       }
  572.    }
  573.  return( Back);
  574. }
  575.  
  576.  
  577.  
  578. int
  579. RemoveFile( ID)
  580. char *ID;
  581. {
  582.  struct StoredFile *CurF, *Pred;
  583.  int searching, back = FALSE;
  584.  
  585.  if (CurF = FindFile( ID))
  586.    {
  587.     if (CurF == FirstFile)
  588.       {
  589.        FirstFile = CurF->sf_NextFile;
  590.       }
  591.     else
  592.       {
  593.        Pred = FirstFile;
  594.        while ( Pred->sf_NextFile != CurF)
  595.          {
  596.           Pred = Pred->sf_NextFile;
  597.          }
  598.        Pred->sf_NextFile = CurF->sf_NextFile;
  599.       }
  600.     FreeMem( CurF, CurF->sf_Size + sizeof( struct StoredFile));
  601.     back = TRUE;
  602.    }
  603.  else
  604.    {
  605.     ErrorOut("File is not stored");
  606.    }
  607.  return( back);
  608. }
  609.  
  610.  
  611.  
  612. int
  613. SaveFile( ID, Name)
  614. char *ID;
  615. char *Name;
  616. {
  617.  struct StoredFile *CurF;
  618.  int back;
  619.  char *DataBuffer;
  620.  
  621.  back =FALSE;
  622.  if (CurF = FindFile( ID))
  623.    {
  624.     DataBuffer = (char *)(CurF) + sizeof( struct StoredFile);
  625.     if (!(back = WriteFile( Name, DataBuffer, CurF->sf_Size)))
  626.       {
  627.        ErrorOut("Could not write file");
  628.       }
  629.    }
  630.  else
  631.    {
  632.     ErrorOut("File not stored");
  633.    }
  634.  return( back);
  635. }
  636.  
  637.  
  638.  
  639. int
  640. RemoveAllFiles()
  641. {
  642.  struct StoredFile *help;
  643.  
  644.  while ( FirstFile != NULL)
  645.    {
  646.     help = FirstFile->sf_NextFile;
  647.     FreeMem( FirstFile, FirstFile->sf_Size + sizeof( struct StoredFile));
  648.     FirstFile = help;
  649.    }
  650.  return( TRUE);
  651. }
  652.  
  653.  
  654.  
  655. int
  656. CopyFile( InName, OutName)
  657. char *InName;
  658. char *OutName;
  659. {
  660.  int DataSize, back;
  661.  char *DataBuffer;
  662.  
  663.  back = FALSE;
  664.  if ((DataSize = FileSize( InName)) > 0)
  665.    {
  666.     if (DataBuffer = (char *) AllocMem( DataSize, MEMF_PUBLIC|MEMF_CLEAR))
  667.       {
  668.        if ( ReadFile( InName, DataBuffer, DataSize))
  669.          {
  670.           if ( WriteFile( OutName, DataBuffer, DataSize))
  671.             {
  672.              back = TRUE;
  673.             }
  674.           else
  675.             {
  676.              ErrorOut("Could not write file");
  677.             }
  678.          }
  679.        else
  680.          {
  681.           ErrorOut("Could not read file");
  682.          }
  683.        FreeMem( DataBuffer, DataSize);
  684.       }
  685.     else
  686.       {
  687.        ErrorOut("Could not allocate memory");
  688.       }
  689.    }
  690.  return( back);
  691. }
  692.  
  693.  
  694.  
  695. int
  696. ExistsFile( Name)
  697. char *Name;
  698. {
  699.  if ( FileSize( Name))
  700.    {
  701.     STATE_Flags |= OK_FLAG;
  702.     STATE_Flags &= ~FAULT_FLAG;
  703.    }
  704.  else
  705.    {
  706.     STATE_Flags &= ~OK_FLAG;
  707.     STATE_Flags |= FAULT_FLAG;
  708.    }
  709.  return( TRUE);
  710. }
  711.  
  712.  
  713.  
  714. /* --------------------------- Search Fuctions ----------------------- */
  715.  
  716.  
  717.  
  718. int
  719. NextCommand()
  720. {
  721.  int searching, t;
  722.  
  723.  t=0;
  724.  searching = TRUE;
  725.  while (( t < MAXCOM)&&(searching))
  726.    {
  727.     if ( strncmp( Curr, Command_List[t], strlen( Command_List[t])) == 0)
  728.       {
  729.        searching = FALSE;
  730.        Curr += strlen( Command_List[t]);
  731.       }
  732.     else
  733.       {
  734.        t++;
  735.       }
  736.    }
  737.  if ( searching) t = NOT_FOUND;
  738.  return( t);
  739. }
  740.  
  741.  
  742.  
  743. int
  744. NextPredicate()
  745. {
  746.  int searching, t;
  747.  
  748.  t=0;
  749.  searching = TRUE;
  750.  while (( t < MAXPRED)&&(searching))
  751.    {
  752.     if ( strncmp( Curr, Predicate_List[t], strlen( Predicate_List[t])) == 0)
  753.       {
  754.        searching = FALSE;
  755.        Curr += strlen( Predicate_List[t]);
  756.       }
  757.     else
  758.       {
  759.        t++;
  760.       }
  761.    }
  762.  if ( searching) t = NOT_FOUND;
  763.  return( t);
  764. }
  765.  
  766.  
  767.  
  768. int
  769. NextString( Buffer)
  770. char *Buffer;
  771. {
  772.  int searching, t;
  773.  
  774.  t =0;
  775.  if ( *Curr == 34)
  776.    {
  777.     Curr++;
  778.     while ((*Curr != 34)&&(Curr < LastPos))
  779.       {
  780.        if ( *Curr == 92) Curr++;
  781.        if ( t < 78)Buffer[t] = *Curr;
  782.        if ( *Curr == 10) LineCount++;
  783.        t++;
  784.        Curr++;
  785.       }
  786.     Curr++;
  787.    }
  788.  if ( t > 78) t = 0;
  789.  Buffer[t] =0;
  790.  return( t);
  791. }
  792.  
  793.  
  794.  
  795. int
  796. NextItem()
  797. {
  798.  int searching, type;
  799.  
  800.  searching = TRUE;
  801.  type =0;
  802.  while (searching)
  803.    {
  804.     if ( *Curr == 59)
  805.       {
  806.        while ((*Curr != 10)&&( Curr < LastPos))
  807.          {
  808.           Curr++;
  809.          }
  810.        Curr++;
  811.        LineCount++;
  812.       }
  813.     if (isalpha((int)(*Curr)))
  814.       {
  815.        type = SYMBOL;
  816.        searching = FALSE;
  817.       }
  818.     if (*Curr == 34)
  819.       {
  820.        type = STRING;
  821.        searching = FALSE;
  822.       }
  823.     if ( Curr >= LastPos)
  824.       {
  825.        searching = FALSE;
  826.       }
  827.     if ((searching) &&( Curr < LastPos))
  828.       {
  829.        if ( *Curr == 10) LineCount++;
  830.        Curr++;
  831.       }
  832.    }
  833.  return( type);
  834. }
  835.  
  836.  
  837.  
  838. /* --------------------------- Execute Fuctions ----------------------- */
  839.  
  840.  
  841.  
  842. int
  843. Exec_Simple( Com)
  844. int Com;
  845. {
  846.  struct FileLock *MyLock;
  847.  struct FileHandle *nfh;
  848.  char *Help;
  849.  int len, Correct, DosError;
  850.  char SBuffer[80];
  851.  
  852.  Correct = FALSE;
  853.  if ( NextItem() == STRING)
  854.    {
  855.     if (len = NextString( SBuffer))
  856.       {
  857.        switch (Com)
  858.          {
  859.           case MAKEDIR_S:  if (MyLock = CreateDir( SBuffer))
  860.                              {
  861.                               UnLock( MyLock);
  862.                               Correct = TRUE;
  863.                              }
  864.                            else
  865.                              {
  866.                               ErrorOut("Unable to create directory");
  867.                              }
  868.                            break;
  869.           case DELETE_S:   Correct = DeleteFile( SBuffer);
  870.                            break;
  871.           case DODOS_S:    if (nfh = Open("RAM:mil.tmp", MODE_NEWFILE))
  872.                              {
  873.                               Correct = Execute( SBuffer, nfh, nfh);
  874.                               Close(nfh);
  875.                               DeleteFile("RAM:mil.tmp");
  876.                              }
  877.                            if (DosError = IoErr())
  878.                              {
  879.                               sprintf( SBuffer, "DOS Error No %d", DosError);
  880.                               ErrorOut( SBuffer);
  881.                               Correct = FALSE;
  882.                              }
  883.                            break;
  884.           case FLUSH_S:    Correct = RemoveFile( SBuffer);
  885.                            break;
  886.           case PRINT_S:    PrintOut( SBuffer);
  887.                            Correct = TRUE;
  888.                            break;
  889.           case ASK_S:      AskAbout( SBuffer);
  890.                            Correct = TRUE;
  891.                            break;
  892.           case WAIT_S:     WaitForUser( SBuffer);
  893.                            Correct = TRUE;
  894.                            break;
  895.           case EXISTS_S:   Correct = ExistsFile( SBuffer);
  896.                            break;
  897.          }
  898.       }
  899.     else
  900.       {
  901.        ErrorOut( "Valid string expected!");
  902.        Correct = FALSE;
  903.       }
  904.    }
  905.  else
  906.    {
  907.     ErrorOut( "String value expected!");
  908.     Correct = FALSE;
  909.    }
  910.  return( Correct);
  911. }
  912.  
  913.  
  914.  
  915. int
  916. Exec_Double( Com)
  917. int Com;
  918. {
  919.  int t, searching, Correct, len_A, len_B;
  920.  char *Help;
  921.  char Buffer_A[80], Buffer_B[80];
  922.  
  923.  Correct = FALSE;
  924.  if ( NextItem() == STRING)
  925.    {
  926.     if (len_A = NextString( Buffer_A))
  927.       {
  928.        if ( NextItem() == SYMBOL)
  929.          {
  930.           if (NextCommand() == AS_S)
  931.             {
  932.              if ( NextItem() == STRING)
  933.                {
  934.                 if (len_B = NextString( Buffer_B))
  935.                   {
  936.                    switch( Com)
  937.                      {
  938.                       case RENAME_S: Correct = Rename( Buffer_A, Buffer_B);
  939.                                      break;
  940.                       case STORE_S:  Correct = StoreFile( Buffer_A, Buffer_B);
  941.                                      break;
  942.                       case WRITE_S:  Correct = SaveFile( Buffer_A, Buffer_B);
  943.                                      break;
  944.                       case COPY_S:   Correct = CopyFile( Buffer_A, Buffer_B);
  945.                                      break;
  946.                      }
  947.                   }
  948.                }
  949.             }
  950.          }
  951.       }
  952.    }
  953.  return( Correct);
  954. }
  955.  
  956.  
  957.  
  958. int
  959. Exec_IF()
  960. {
  961.  int found, type, Curr_IF_Level;
  962.  int back = FALSE;
  963.  char DBuf[80];
  964.  
  965.  Curr_IF_Level = IF_Level;
  966.  if ( NextItem( ) == SYMBOL)
  967.    {
  968.     if ((found = NextPredicate())< MAXPRED)
  969.       {
  970.        if (!(STATE_Flags & (1<<found)))
  971.          {
  972.           found = FALSE;
  973.           while ((! found)&&(Curr < LastPos))
  974.             {
  975.              if ((type = NextItem()) == SYMBOL)
  976.                {
  977.                 type = NextCommand();
  978.                 if ( type != NOT_FOUND)
  979.                   {
  980.                    if (((type == END_S)||(type == ELSE_S))
  981.                        &&(Curr_IF_Level == IF_Level))
  982.                      {
  983.                       found = TRUE;
  984.                       back = TRUE;
  985.                      }
  986.                    else
  987.                      {
  988.                       if ( type == END_S) Curr_IF_Level--;
  989.                      }
  990.                    if ( type == IF_S)
  991.                      {
  992.                       Curr_IF_Level++;
  993.                       if ( NextItem() == SYMBOL)
  994.                         {
  995.                          if (NextPredicate() == NOT_FOUND)
  996.                            {
  997.                             ErrorOut("No predicate after IF");
  998.                             found = TRUE;
  999.                            }
  1000.                         }
  1001.                       else
  1002.                         {
  1003.                          ErrorOut("No predicate symbol after IF");
  1004.                          found = TRUE;
  1005.                         }
  1006.                      }
  1007.                   }
  1008.                 else
  1009.                   {
  1010.                    ErrorOut("Predicate outside IF");
  1011.                    found = TRUE;
  1012.                   }
  1013.                }
  1014.              else
  1015.                {
  1016.                 if (type == STRING) NextString( DBuf);
  1017.                }
  1018.             }
  1019.          }
  1020.        else
  1021.          {
  1022.           back = TRUE;
  1023.          }
  1024.        IF_Level++;
  1025.       }
  1026.     else
  1027.       {
  1028.        ErrorOut("Expected a predictate");
  1029.       }
  1030.    }
  1031.  else
  1032.    {
  1033.     ErrorOut("Expected a predictate symbol");
  1034.    }
  1035.  return( back);
  1036. }
  1037.  
  1038.  
  1039.  
  1040. int
  1041. Exec_SkipElse()
  1042. {
  1043.  int found, type, CurrIFLevel, Com, back = FALSE;
  1044.  char DBuf[80];
  1045.  
  1046.  found = FALSE;
  1047.  CurrIFLevel = IF_Level;
  1048.  while ((! found)&&(Curr < LastPos))
  1049.    {
  1050.     if ((type = NextItem()) == SYMBOL)
  1051.       {
  1052.        Com = NextCommand();
  1053.        if ((Com == END_S)&&(CurrIFLevel == IF_Level))
  1054.          {
  1055.           found = TRUE;
  1056.           back = TRUE;
  1057.          }
  1058.        else
  1059.          {
  1060.           if (Com == END_S) CurrIFLevel--;
  1061.          }
  1062.        if (Com == IF_S)
  1063.          {
  1064.           CurrIFLevel++;
  1065.           if ( NextItem() == SYMBOL)
  1066.             {
  1067.              if (NextPredicate() == NOT_FOUND)
  1068.                {
  1069.                 ErrorOut("No predicate after IF");
  1070.                 found = TRUE;
  1071.                }
  1072.             }
  1073.           else
  1074.             {
  1075.              ErrorOut("No predicate symbol after IF");
  1076.              found = TRUE;
  1077.             }
  1078.          }
  1079.       }
  1080.     else
  1081.       {
  1082.        if (type == STRING) NextString( DBuf);
  1083.       }
  1084.    }
  1085.  return( back);
  1086. }
  1087.  
  1088.  
  1089.  
  1090. void
  1091. Exec_Script( Start)
  1092. char *Start;
  1093. {
  1094.  int Correct, done, CommandNr;
  1095.  
  1096.  Correct = TRUE;
  1097.  done = FALSE;
  1098.  Curr = Start;
  1099.  LineCount =1;
  1100.  while (( Curr < LastPos)&&(Correct)&&(!done))
  1101.    {
  1102.     if (NextItem() == SYMBOL)
  1103.       {
  1104.        CommandNr = NextCommand();
  1105.        switch( CommandNr)
  1106.          {
  1107.           case ASK_S:
  1108.           case WAIT_S:
  1109.           case DODOS_S:
  1110.           case FLUSH_S:
  1111.           case PRINT_S:
  1112.           case DELETE_S:
  1113.           case EXISTS_S:
  1114.           case MAKEDIR_S: Correct = Exec_Simple( CommandNr);
  1115.                           break;
  1116.           case STORE_S:
  1117.           case WRITE_S:
  1118.           case COPY_S:
  1119.           case RENAME_S: Correct = Exec_Double( CommandNr);
  1120.                          break;
  1121.           case PURGE_S:  Correct = RemoveAllFiles();
  1122.                          break;
  1123.           case CLEAR_S:  ClearPrint();
  1124.                          Correct = TRUE;
  1125.                          break;
  1126.           case IF_S:     Correct = Exec_IF();
  1127.                          break;
  1128.           case END_S:    IF_Level--;
  1129.                          if ( IF_Level < 0)
  1130.                            {
  1131.                             Correct = FALSE;
  1132.                            }
  1133.                          else
  1134.                            {
  1135.                             Correct = TRUE;
  1136.                            }
  1137.                          break;
  1138.           case ELSE_S:   Correct = Exec_SkipElse();
  1139.                          break;
  1140.           case AS_S:     ErrorOut("Unexpected AS found");
  1141.                          Correct = FALSE;
  1142.           case QUIT_S:   done = TRUE;
  1143.                          Correct = TRUE;
  1144.                          break;
  1145.           default:       ErrorOut("Unexpected Symbol found!");
  1146.                          Correct = FALSE;
  1147.                          break;
  1148.          }
  1149.       }
  1150.     else
  1151.       {
  1152.        if ( Curr < LastPos)
  1153.          {
  1154.           ErrorOut("Line has to start with a command!");
  1155.          }
  1156.        else
  1157.          {
  1158.           WaitForUser("Reached last script line, click [CONTINUE] to leave!");
  1159.          }
  1160.        Correct = FALSE;
  1161.       }
  1162.    }
  1163. }
  1164.  
  1165.  
  1166.  
  1167. /* --------------------------- Open Routine ----------------------- */
  1168.  
  1169.  
  1170.  
  1171. void
  1172. HandleScript( Name)
  1173. char *Name;
  1174. {
  1175.  int The_Size;
  1176.  char *StartPos;
  1177.  
  1178.  LineCount =0;
  1179.  if (The_Size = FileSize( Name))
  1180.    {
  1181.     if ( StartPos = (char *)AllocMem( The_Size, MEMF_PUBLIC|MEMF_CLEAR))
  1182.       {
  1183.        if (ReadFile( Name, StartPos, The_Size))
  1184.          {
  1185.           LastPos = StartPos +The_Size;
  1186.           LineCount =1;
  1187.           Exec_Script( StartPos);
  1188.           RemoveAllFiles();
  1189.          }
  1190.        else
  1191.          {
  1192.           ErrorOut("Mangled script file");
  1193.          }
  1194.        FreeMem( StartPos, The_Size);
  1195.       }
  1196.     else
  1197.       {
  1198.        ErrorOut("Not enought memory");
  1199.       }
  1200.    }
  1201.  else
  1202.    {
  1203.     ErrorOut("File empty or not there");
  1204.    }
  1205. }
  1206.  
  1207.  
  1208.  
  1209. /* --------------------------- Main Routine ----------------------- */
  1210.  
  1211.  
  1212.  
  1213. main( argc, argv)
  1214. int argc;
  1215. char **argv;
  1216. {
  1217.  struct WBStartup *WBMess;
  1218.  char *ScriptFile;
  1219.  
  1220.  if (! OpenInstWindow())
  1221.    {
  1222.     ClearPrint();
  1223.     ScriptFile = NULL;
  1224.     if ( argc == 0)
  1225.       {
  1226.        WBMess = (struct WBStartup *) argv;
  1227.        if ( WBMess->sm_NumArgs == 2)
  1228.          {
  1229.           ScriptFile = WBMess->sm_ArgList[1].wa_Name;
  1230.          }
  1231.       }
  1232.     else
  1233.       {
  1234.        if ( argc > 1)
  1235.          {
  1236.           ScriptFile = argv[1];
  1237.          }
  1238.       }
  1239.     if ( ScriptFile)
  1240.       {
  1241.        HandleScript( ScriptFile);
  1242.       }
  1243.     else
  1244.       {
  1245.        PrintInfo();
  1246.       }
  1247.     CloseInstWindow( NO_FAULT);
  1248.    }
  1249.  exit( 0);
  1250. }
  1251.  
  1252.  
  1253.  
  1254. /* ------------------------------ THE END ------------------------------ */
  1255.  
  1256.