home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 337.lha / Helper_v.07 / Helper.mod < prev    next >
Encoding:
Text File  |  1990-01-26  |  21.2 KB  |  612 lines

  1. MODULE Helper;
  2.  
  3. (*======================================================================*)
  4. (*                        Helper version v0.07                          *)
  5. (*======================================================================*)
  6. (*           Copyright © 1989 Mike Cargal, All Rights Reserved          *)
  7. (*======================================================================*)
  8. (*      Version: 0.07           Author : Mike Cargal                    *)
  9. (*      Date   : 20-Jun-89      Changes: Original                       *)
  10. (*======================================================================*)
  11. (*      Link with RTA                                                   *)
  12. (*======================================================================*)
  13.  
  14.  
  15. FROM SYSTEM         IMPORT ADR, STRPTR, LONGWORD, BYTE, ADDRESS, TSIZE,
  16.                            SHIFT, SHORT;
  17. FROM RunTime        IMPORT WBMsg;
  18. FROM EasyIDCMP      IMPORT ProcTable, ProcessEvents;
  19. FROM EasyMenus      IMPORT AddMenu, AddItem, DisposeStrip, AddSub,
  20.                            StartStrip, currentStrip, stripFailed,
  21.                            nextSubWidth;
  22. FROM Intuition      IMPORT WindowPtr, IntuiMessage, GadgetPtr,
  23.                            ActivateWindow, SetMenuStrip, IDCMPFlags,
  24.                            ClearMenuStrip, ITEMNUM, IDCMPFlagSet,
  25.                            ModifyIDCMP, Screen, ScreenPtr,
  26.                            RememberPtr, AllocRemember, FreeRemember;
  27. FROM DOS            IMPORT Lock, UnLock, SharedLock, Write, Output,
  28.                            CurrentDir, FileLock, ParentDir, DupLock,
  29.                            InfoData, InfoDataPtr, Input;
  30. FROM DOSProcess     IMPORT Process, ProcessPtr, StandardPacket,
  31.                            StandardPacketPtr, ActionDiskInfo;
  32. FROM ArpPortUtils   IMPORT CreatePort, DeletePort;
  33. FROM ArpLoader      IMPORT PCBFlags, PCBFlagSet, PCBPtr, PCB, ASyncRun,
  34.                            NewShell, nshInteractiveShell,
  35.                            nshInteractiveCLI, SpawnShell;
  36. FROM ArpPackets     IMPORT SendPacket;
  37. FROM ArpProcess     IMPORT FindCLI;
  38. FROM ArpMisc        IMPORT CloseWindowSafely;
  39. FROM Interrupts     IMPORT Forbid, Permit;
  40. FROM Libraries      IMPORT OpenLibrary, CloseLibrary;
  41. FROM Workbench      IMPORT DiskObject, DiskObjectPtr, StrArrayPtr,
  42.                            WBStartupPtr, WBStartup, WBArg;
  43. FROM Icon           IMPORT GetDiskObject, FindToolType, IconBase, IconName,
  44.                            FreeDiskObject;
  45. FROM Memory         IMPORT AllocMem, FreeMem, MemReqSet, MemReqs;
  46. FROM Strings        IMPORT AppendSubStr, AssignStr, LengthStr,
  47.                            Equal, CompareCAPStr, LocateChar;
  48. FROM Tasks          IMPORT FindTask, CurrentTask;
  49. FROM Devices        IMPORT OpenDevice, CloseDevice;
  50. FROM IO             IMPORT IOStdReq, IOStdReqPtr, DoIO, IOFlagSet;
  51. FROM IOUtils        IMPORT CreateStdIO, DeleteStdIO;
  52. FROM Ports          IMPORT MsgPortPtr, MsgPort;
  53. FROM InputEvents    IMPORT InputEvent, IEQualifiers, IEQualifierSet,
  54.                            IEClass, InputEventPtr;
  55. FROM InputDevice    IMPORT INDWriteEvent, InputDeviceName;
  56. FROM CmdLineUtils   IMPORT argc, argv;
  57. FROM Conversions    IMPORT ConvNumToStr, ConvStrToNum, Hex;
  58. FROM DoRawTbl       IMPORT RawEnt, RawTbl, RawTblPtr, BuildRawTbl;
  59. FROM Gads           IMPORT Gad, ChangeGads, InitGads, GadPtr,
  60.                            OpenHelperWindow, CloseHelperWindow,
  61.                            GetFile, HandleCloseWindow, DefConfig,
  62.                            LoadGads, SaveGads, SaveDefaults, Version;
  63. FROM IconifyUtils   IMPORT StartIconify, Iconify, DisposeIconify;
  64. (*FROM TermOut        IMPORT WriteString; *)
  65.                    (* IMPORT Debug; *)
  66.  
  67. (*$O-,$R-*) 
  68. CONST
  69.   IconifyGadID = 100; 
  70. VAR
  71.   Gads         : GadPtr;
  72.   MyInputEvent : InputEvent;
  73.   ParentProcess,
  74.   MyProcess    : ProcessPtr;
  75.   CmdBuff      : ARRAY [0..255] OF CHAR;
  76.   MyStdIO      : IOStdReqPtr;
  77.   MyRawTbl     : RawTblPtr;
  78.   MyPort       : MsgPortPtr;
  79.   CLIWindow,
  80.   wp           : WindowPtr;
  81.   MyDiskObj    : DiskObjectPtr;
  82.   FromWB       : BOOLEAN;
  83.   CLINum       : INTEGER;
  84.   MemRemem     : RememberPtr;
  85.   Remembering  : BOOLEAN;
  86.   ITopEdge,
  87.   ILeftEdge,
  88.   IWidth,
  89.   IHeight      : INTEGER;
  90.   IconGad      : GadgetPtr;
  91.   Iconified    : BOOLEAN;  
  92.  
  93. (*******************************************************************)
  94.  
  95. PROCEDURE CLIWActive(wp : WindowPtr) : BOOLEAN;
  96.  
  97.   (*-------------------------------------------------------------\
  98.    |                                                             |
  99.    |  This is a recursive routine which traverses to linked-     |
  100.    |    list of windows for this Screen and returns TRUE or      |
  101.    |    FALSE based up whether or not our CLI window is still    |
  102.    |    open.                                                    |
  103.    |                                                             |
  104.    \-------------------------------------------------------------*)
  105.  
  106. VAR
  107.   Result : BOOLEAN;
  108.  
  109. BEGIN
  110.  
  111.   IF wp = CLIWindow THEN
  112.     RETURN(TRUE)
  113.   ELSE
  114.     IF wp^.NextWindow = NIL THEN
  115.       RETURN(FALSE)
  116.     ELSE
  117.       RETURN(CLIWActive(wp^.NextWindow))
  118.     END;
  119.   END;
  120.     
  121. END CLIWActive;
  122.  
  123. (*******************************************************************)
  124.  
  125. PROCEDURE WriteCommand(Cmd : ARRAY OF CHAR);
  126.  
  127.   (*-------------------------------------------------------------\
  128.    |                                                             |
  129.    |  Create input events for each character of the command      |
  130.    |    and Write input device events for each of these to       |
  131.    |    simulate them being typed on keyboard.                   |
  132.    |                                                             |
  133.    \-------------------------------------------------------------*)
  134.       
  135. VAR
  136.   i     : CARDINAL;
  137.   dummy : LONGINT;
  138.  
  139. BEGIN
  140.   
  141.   dummy := 0;
  142.   FOR i := 0 TO LengthStr(Cmd)-1 DO  
  143.     MyInputEvent.ieCode      := MyRawTbl^[CARDINAL(Cmd[i])].Cd;
  144.     MyInputEvent.ieQualifier := MyRawTbl^[CARDINAL(Cmd[i])].Qual;
  145.     IF dummy = 0 THEN  
  146.       dummy := DoIO(MyStdIO);
  147.     END;
  148.   END;
  149.     
  150. END WriteCommand;
  151.  
  152. (*******************************************************************)
  153.  
  154. PROCEDURE HandleGadgetUp(VAR im : IntuiMessage;
  155.                              gp : GadgetPtr)       : INTEGER;
  156.  
  157.   (*-------------------------------------------------------------\
  158.    |                                                             |
  159.    |  Set our process current directory to the current           |
  160.    |    directory of the CLI from which we were started (and     |
  161.    |    are consequently attached to).                           |
  162.    |                                                             |
  163.    |  Build command string associated with selected Helper       |
  164.    |    button (appending file name from file requester if       |
  165.    |    necessary).                                              |
  166.    |                                                             |
  167.    |  Write Command to input device.                             |
  168.    |                                                             |
  169.    \-------------------------------------------------------------*)
  170.  
  171. VAR
  172.   FileName : STRPTR;
  173.   i        : CARDINAL;
  174.  
  175. BEGIN
  176.  
  177.   IF FromWB THEN
  178.     IF NOT CLIWActive(wp^.WScreen^.FirstWindow) THEN 
  179.       RETURN(1)
  180.     END;
  181.   END;
  182.  
  183.   IF gp^.GadgetID = IconifyGadID THEN
  184.     Iconify(wp,Iconified,wp^.Width,ITopEdge,ILeftEdge,IWidth,IHeight);
  185.     ActivateWindow(CLIWindow);  
  186.     RETURN(0);
  187.   END;
  188.   
  189.   UnLock(CurrentDir(DupLock(ParentProcess^.prCurrentDir)));
  190.   i := gp^.GadgetID;  
  191.   AssignStr(CmdBuff,Gads^[i].Command);
  192.   IF Gads^[i].AppendFile THEN
  193.     FileName := GetFile(ADR(Gads^[i].Command),ADR(""));
  194.     IF LocateChar(FileName^," ",0) # -1 THEN 
  195.       AppendSubStr(CmdBuff,"\x22");
  196.     END;  
  197.     AppendSubStr(CmdBuff,FileName^);
  198.     IF LocateChar(FileName^," ",0) # -1 THEN
  199.       AppendSubStr(CmdBuff,"\x22");
  200.     END;  
  201.   END;
  202.   AppendSubStr(CmdBuff,"\x0d");
  203.   ActivateWindow(CLIWindow);
  204.   WriteCommand(CmdBuff);
  205.   RETURN(0);
  206.  
  207. END HandleGadgetUp;
  208.  
  209. (*******************************************************************)
  210.  
  211. PROCEDURE HandleIntuiTicks(VAR im : IntuiMessage) : INTEGER;
  212.  
  213.   (*-------------------------------------------------------------\
  214.    |                                                             |
  215.    | This procedure will execute approximately 10 times each     |
  216.    |   second as long as the Helper window is active.            |
  217.    |   Of course, the Helper window is rarely active since       |
  218.    |   Helper automatically reactivates the CLI window.          |
  219.    |   However, by using this code, anything which activates     |
  220.    |   the Helper window will cause Helper (if run from WB)      |
  221.    |   to check to see if its CLI window is still open, and      |
  222.    |   exit if the CLI window has been closed (Since there is    |
  223.    |   nothing for Helper to do if it has no CLI).               |
  224.    |                                                             |
  225.    \-------------------------------------------------------------*)
  226.    
  227. BEGIN 
  228.  
  229.   IF CLIWActive(wp^.WScreen^.FirstWindow) THEN
  230.     RETURN(0)
  231.   END;
  232.   RETURN(1);
  233.   
  234. END HandleIntuiTicks;
  235.  
  236. (*******************************************************************)
  237.  
  238. PROCEDURE HandleMenuPick(VAR im : IntuiMessage;
  239.                              item : CARDINAL  ) : INTEGER;
  240.  
  241.   (*-------------------------------------------------------------\
  242.    |                                                             |
  243.    |  Handle menu requests:                                      |
  244.    |     Menuitem 0 - Load configuration.                        |
  245.    |              1 - Change configuration.                      |
  246.    |              2 - Save configuration file.                   |
  247.    |              3 - Save default configuration file.           |
  248.    |              4 - exit helper by returning non 0 to          |
  249.    |                    EasyIDCMP.                               |
  250.    |                                                             |
  251.    \-------------------------------------------------------------*)
  252.  
  253. BEGIN
  254.   CASE ITEMNUM(item) OF 
  255.     0 : LoadGads(wp)
  256.   | 1 : ChangeGads(wp)
  257.   | 2 : SaveGads(wp)
  258.   | 3 : SaveDefaults(wp)
  259.   | 4 : (* Do Nothing *)
  260.   | 5 : RETURN(1);
  261.   ELSE  (* Do Nothing *)
  262.   END;
  263.   RETURN(0);
  264.     
  265. END HandleMenuPick;
  266.  
  267. (*******************************************************************)
  268.  
  269. PROCEDURE AddMenus();
  270.  
  271.   (*-------------------------------------------------------------\
  272.    |                                                             |
  273.    |  Build menu structures and attach to Helper window if       |
  274.    |    successful.                                              |
  275.    |                                                             |
  276.    \-------------------------------------------------------------*)
  277.  
  278. BEGIN
  279.  
  280.   StartStrip;
  281.  
  282.   AddMenu("Project",145);;
  283.     AddItem("Load",         "L");
  284.     AddItem("Change",       "C");
  285.     AddItem("Save",         "S");
  286.     AddItem("Save Defaults","D");
  287.     AddItem("About...",      0C);
  288.       nextSubWidth := 210;
  289.       AddSub("                          ",0C);
  290.       AddSub("      Helper v0.06        ",0C);
  291.       AddSub("                          ",0C);
  292.       AddSub("    © 1989 Mike Cargal    ",0C);
  293.       AddSub("                          ",0C);
  294.       AddSub(" Developed using M2Sprint ",0C);
  295.       AddSub("      for the Amiga       ",0C);
  296.       AddSub(" M2S Inc., Dallas, Texas  ",0C);
  297.       AddSub("                          ",0C);
  298.     AddItem("Quit",         "Q");
  299.  
  300.   IF NOT stripFailed THEN 
  301.     SetMenuStrip(wp,currentStrip);
  302.   END;
  303.       
  304. END AddMenus;
  305.  
  306. (*******************************************************************)
  307.  
  308. PROCEDURE Getwp(CLIProcess : ProcessPtr) : WindowPtr;
  309.  
  310.   (*-------------------------------------------------------------\
  311.    |                                                             |
  312.    |  Get pointer to CLI window.  By sending packet to Console   |
  313.    |    handler for the parent task, we can get back the         |
  314.    |    address of the window it opened for us.  Since Helper    |
  315.    |    should have been started from the CLI, this will be      |
  316.    |    the window opened by the CLI's console handler.  If      |
  317.    |    Helper was not started from CLI, this packet should      |
  318.    |    fail so we'll return NILL and Helper will not continue.  |
  319.    |                                                             |
  320.    \-------------------------------------------------------------*)
  321.  
  322. VAR
  323.   wp               : WindowPtr;
  324.   MyStandardPacket : StandardPacket;
  325.   MyInfoDataPtr    : InfoDataPtr;
  326.   MyArgs           : ARRAY [0..6] OF ADDRESS;
  327.     
  328. BEGIN
  329.   
  330.  
  331.   MyInfoDataPtr := AllocMem(TSIZE(InfoData),MemReqSet{MemClear});
  332.   MyArgs[0] := SHIFT(MyInfoDataPtr,-2); (* PTR to BPTR *)
  333.   IF BOOLEAN(SendPacket(ActionDiskInfo,
  334.                         ADR(MyArgs),
  335.                         MsgPortPtr(CLIProcess^.prConsoleTask))) THEN
  336.     wp := WindowPtr(MyInfoDataPtr^.idVolumeNode) 
  337.   ELSE
  338.     wp := NIL;
  339.   END;            
  340.   FreeMem(MyInfoDataPtr,TSIZE(InfoData));
  341.   RETURN(wp);
  342.  
  343. END Getwp;
  344.  
  345. (*******************************************************************)
  346.  
  347. PROCEDURE OpenInputDevice() : BOOLEAN;
  348.  
  349.   (*-------------------------------------------------------------\
  350.    |                                                             |
  351.    | Open up Input Device to send input events to simulate       |
  352.    |   keyboard input.                                           |
  353.    |                                                             |
  354.    \-------------------------------------------------------------*)
  355.  
  356. BEGIN
  357.   MyPort := CreatePort(NIL,0);
  358.   MyStdIO := CreateStdIO(MyPort);
  359.   WITH MyStdIO^ DO
  360.     ioCommand := INDWriteEvent;
  361.     ioLength  := TSIZE(InputEvent);
  362.     ioData    := ADR(MyInputEvent);
  363.   END;
  364.   WITH MyInputEvent DO 
  365.     ieNextEvent         := NIL;
  366.     ieClass             := IEClassRawKey;
  367.     ieSubClass          := BYTE(0);
  368.     ieQualifier         := IEQualifierSet{};
  369.     ieEventAddress      := NIL;
  370.     ieTimeStamp.tvSecs  := 0;
  371.     ieTimeStamp.tvMicro := 0;
  372.   END;
  373.   IF OpenDevice(ADR(InputDeviceName),0,MyStdIO,LONGBITSET{}) = 0 THEN 
  374.     RETURN(TRUE);
  375.   END; 
  376.   RETURN(FALSE);
  377.     
  378. END OpenInputDevice;
  379.  
  380. (*******************************************************************)
  381.  
  382. PROCEDURE StartCLI();
  383.  
  384. VAR
  385.   MyNewShell   : NewShell;
  386.   WindowSpec,
  387.   StartUp,
  388.   Shell,
  389.   ConfigFile   : STRPTR;
  390.   MyWBStartupPtr : WBStartupPtr;
  391.   
  392. BEGIN
  393.  
  394.   StartUp    := NIL;
  395.   Shell      := NIL;
  396.   WindowSpec := NIL;
  397.   MyDiskObj  := NIL;
  398.   
  399.   IconBase := OpenLibrary(ADR(IconName),0);
  400.   IF IconBase # NIL THEN 
  401.     MyWBStartupPtr := WBStartupPtr(WBMsg);
  402.     UnLock(CurrentDir(DupLock(MyWBStartupPtr^.smArgList^.waLock)));  
  403.     MyDiskObj := GetDiskObject(MyWBStartupPtr^.smArgList^.waName);
  404.     IF MyDiskObj # NIL THEN 
  405.       WindowSpec := FindToolType(MyDiskObj^.doToolTypes,
  406.                                  ADR("WINDOW"));
  407.       StartUp    := FindToolType(MyDiskObj^.doToolTypes,
  408.                                  ADR("STARTUP"));
  409.       ConfigFile := FindToolType(MyDiskObj^.doToolTypes,
  410.                                  ADR("CONFIG"));
  411.       Shell      := FindToolType(MyDiskObj^.doToolTypes,
  412.                                  ADR("SHELL"));                           
  413.       IF ConfigFile # NIL THEN
  414.         DefConfig := ConfigFile;
  415.       END;
  416.     END;
  417.   CloseLibrary(IconBase);                                       
  418.   END;
  419.   
  420.   IF WindowSpec = NIL THEN 
  421.     WindowSpec := ADR("NewCON:0/20/640/200/Helper Shell");
  422.   END;
  423.   
  424.   WITH MyNewShell DO
  425.     nshStackSize := 4000;
  426.     nshPri       := BYTE(0);
  427.     IF CompareCAPStr(Shell^,"YES") = Equal THEN
  428.       nshControl   := nshInteractiveShell;
  429.     ELSE
  430.       nshControl   := nshInteractiveCLI;
  431.     END;
  432.     nshLogMsg    := ADR("Welcome to Helper\n\x1b[33m© 1989 Mike Cargal\x1b[31m\n");
  433.     nshInput     := NIL;
  434.     nshOutput    := NIL;
  435.     nshReserved[0] := 0;
  436.     nshReserved[1] := 0;
  437.     nshReserved[2] := 0;
  438.     nshReserved[3] := 0;
  439.     nshReserved[4] := 0;
  440.     nshReserved[5] := 0;
  441.   END;
  442.   
  443.   CLINum := SHORT(SpawnShell(WindowSpec,StartUp,ADR(MyNewShell)));
  444.   IF CLINum > 0 THEN
  445.     Forbid;
  446.     ParentProcess := FindCLI(CLINum);
  447.     Permit;
  448.   ELSE
  449.     ParentProcess := NIL;  
  450.   END;                                 
  451.   
  452. END StartCLI;
  453.  
  454.  
  455. (*******************************************************************)
  456.  
  457. PROCEDURE DoHelper();
  458.  
  459.   (*-------------------------------------------------------------\
  460.    |                                                             |
  461.    |  If all looks well, then open Helper window, etc. and BEGIN |
  462.    |    to wait for IDCMP events to let us know what to do       |
  463.    |                                                             |
  464.    \-------------------------------------------------------------*)
  465.  
  466. VAR
  467.   MyProcTable   : ProcTable;
  468.   dummy         : INTEGER;
  469.   MyIDCMP       : IDCMPFlagSet;
  470.  
  471. BEGIN
  472.  
  473.   IF ParentProcess # NIL THEN 
  474.     CLIWindow := Getwp(ParentProcess);
  475.     IF CLIWindow # NIL THEN 
  476.     Gads := InitGads();
  477.       IF OpenInputDevice() THEN
  478.         wp := OpenHelperWindow();
  479.         IF FromWB THEN 
  480.           MyIDCMP := wp^.IDCMPFlags;
  481.           INCL(MyIDCMP,IntuiTicks);
  482.           ModifyIDCMP(wp,MyIDCMP);
  483.         END;
  484.         IF wp # NIL THEN
  485.           IF StartIconify(wp,IconifyGadID,IconGad) THEN END;
  486.           Iconified := FALSE;
  487.           MyRawTbl := BuildRawTbl();
  488.           IF MyRawTbl # NIL THEN 
  489.             AddMenus;
  490.             WITH MyProcTable DO
  491.               WaitForEvent := TRUE;
  492.               CloseWindow  := HandleCloseWindow;
  493.               GadgetUp     := HandleGadgetUp;
  494.               MenuPick     := HandleMenuPick;
  495.               IntuiTicks   := HandleIntuiTicks;
  496.             END;   
  497.             dummy := ProcessEvents(wp,MyProcTable);
  498.             ClearMenuStrip(wp);
  499.             DisposeStrip(currentStrip);
  500.             DisposeIconify(wp,IconGad);
  501.             CloseHelperWindow(wp);
  502.           END;  
  503.         END;
  504.         CloseDevice(MyStdIO);
  505.         DeleteStdIO(MyStdIO);
  506.         DeletePort(MyPort);
  507.       END;  
  508.     END;
  509.   END;  
  510.  
  511. END DoHelper;
  512.  
  513.  
  514. (*******************************************************************)
  515.  
  516. PROCEDURE FirstTime();
  517.  
  518.   (*-------------------------------------------------------------\
  519.    |                                                             |
  520.    |  If first time in (i.e. no arguments (this needs to be      | 
  521.    |    improved)), start up another Helper asynchronously       |
  522.    |    passing the address of this process's Process structure  |
  523.    |    so I can keep the current directories in synch.          |
  524.    |                                                             |
  525.    |  NOTE: currently this address acts as an argument so that   |
  526.    |    I can tell the difference between helper running itself  |
  527.    |    and Helper being run initially from the CLI.  This is    |
  528.    |    not very clean and I'm still looking for a better way    |
  529.    |    to do this.                                              |
  530.    |                                                             |
  531.    \-------------------------------------------------------------*)
  532.  
  533. VAR
  534.   MyPCB        : PCB;
  535.   result       : LONGINT;
  536.  
  537. BEGIN
  538.   WITH MyPCB DO
  539.     pcbStackSize  := 4000;
  540.     pcbPri        := BYTE(0);
  541.     pcbControl    := PCBFlagSet{};
  542.     pcbTrapCode   := PROC(NIL);
  543.     pcbInput      := NIL; 
  544.     pcbOutput     := NIL; 
  545.     pcbLoadedCode := NIL;
  546.     pcbLastGasp   := NIL;
  547.     pcbWBProcess  := NIL;
  548.   END; 
  549.   IF ConvNumToStr(CmdBuff,LONGWORD(MyProcess),Hex,FALSE,8,"0") THEN 
  550.     AppendSubStr(CmdBuff,"\x0d");
  551.     result := ASyncRun(argv[0](*"Helper"*),ADR(CmdBuff),ADR(MyPCB));
  552.     IF result < LONGINT(0) THEN
  553.       result := Write(Output(),ADR("Helper failed to start process\n"),31);
  554.     END;
  555.   END;
  556.  
  557. END FirstTime;
  558.  
  559. (*******************************************************************)
  560.  
  561. PROCEDURE SecondTime();
  562.  
  563.   (*-------------------------------------------------------------\
  564.    |                                                             |
  565.    |  If we had an argument then it should have been the address |
  566.    |    of the parent Process.  If not then somethings not       |
  567.    |    quite right so we'll get out of here.                    |
  568.    |                                                             |
  569.    |  If all looks well, then open Helper window, etc. and BEGIN |
  570.    |    to wait for IDCMP events to let us know what to do       |
  571.    |                                                             |
  572.    \-------------------------------------------------------------*)
  573.  
  574. BEGIN
  575.   IF ConvStrToNum(argv[1]^,LONGWORD(ParentProcess),Hex,FALSE) THEN     
  576.     DoHelper
  577.   END;  
  578. END SecondTime;
  579.  
  580. (*******************************************************************)
  581.  
  582. BEGIN
  583.  
  584.   (*-------------------------------------------------------------\
  585.    |                                                             |
  586.    |  First time in MyProcess will be the ParentProcess we will  |
  587.    |   pass to the second invocation of Helper.  Second time     |
  588.    |   it will be the Process structure for the started process. |
  589.    |                                                             |
  590.    |  We can tell (theoretically) whether this is the first      |
  591.    |   or second time by the presence of any arguments.          |
  592.    |                                                             |
  593.    \-------------------------------------------------------------*)
  594.  
  595.   MyProcess := ProcessPtr(FindTask(CurrentTask));
  596.   IF WBMsg # NIL THEN
  597.     FromWB := TRUE;
  598.     StartCLI;
  599.     DoHelper;
  600.     IF MyDiskObj # NIL THEN 
  601.       FreeDiskObject(MyDiskObj);                                                            
  602.     END;
  603.   ELSE 
  604.     IF argc = 1 THEN
  605.       FirstTime   
  606.     ELSE 
  607.       SecondTime
  608.     END;  
  609.   END;
  610.  
  611. END Helper.
  612.