home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Editor / FREDV19A.LHA / FrexxEd / Rexx / FrexxEdStart.rx < prev    next >
Encoding:
Text File  |  1995-06-07  |  5.6 KB  |  174 lines

  1. /*****************************************************************************
  2.  * $VER: FrexxFrontEd v2.5 (6.6.95)
  3.  *
  4.  * Arexx script for FrexxEd as replacement for Ed used with Ced
  5.  * Also used by "freds" and "bin/startfred".
  6.  *
  7.  * Orginally by Daniel Stenberg & Michiel Willems.
  8.  * Altered by Nicolas Dade (nicolas-dade@uiuc.edu) to be more general.
  9.  * Altered by Mogens Isager to be even more general :-).
  10.  * Altered by Nicolas Dade again to fold Mogens' changes into my private version.
  11.  *
  12.  * NEW FEATURES:
  13.  * (5.2.95) [Nicolas]
  14.  *  o correctly handles relative paths in Filename.
  15.  *  o handles multiple filenames.
  16.  *  o cleaned up STICKY code.
  17.  * (18.2.95) [Nicolas]
  18.  *  o STICKY can appear anywhere in the arguments.
  19.  * (20.2.95) [Daniel/Kjell]
  20.  *  o Added the iconfy-stuff!
  21.  * (23.2.95) [Nicolas]
  22.  *  o it's ok to open more than one new file at once.
  23.  *  o starting with no arguments makes Fred pop up a requester.
  24.  *  o eliminated NOARGS code because NOARGS was never used.
  25.  *  o moved "run Fred" out of loop.
  26.  *  o moved "Deiconify(); WindowToFront();" out of loop.
  27.  * (4.6.95) [Mogens]
  28.  *  o Made some changes to handle no args or just STICKY.
  29.  * (6.6.95) [Nicolas]
  30.  *  o folded some of Mogen's changes into my code
  31.  *  o changed fpl/KillNotify.FPL to be smarter about multiple files and re-iconifying.
  32.  *    This meant adding the global info _iconify_when_quit_countdown that counts the total number of buffers that were opened while iconified.
  33.  *  o ARexxRead()s replaced by having arexx place the variable directly in the FPL code.
  34.  *  o In order to keep the user from deiconifying while we open the files, the command(s) to FrexxEd are built up in arexx, and then sent as one long command.
  35.  *
  36.  * USAGE/DESCRIPTION:
  37.  *
  38.  * Arguments: rx FrexxEdStart.rx {Filenames} [STICKY]
  39.  * Example  : rx FrexxEdStart S:Startup-Sequence S:User-Startup
  40.  *
  41.  * Note that the shell script Freds calls FrexxEdStart for us, so the above
  42.  * example could also have been written as
  43.  *   freds S:Startup-Sequence S:User-Startup
  44.  *
  45.  ****************************************************************************/
  46.  
  47. OPTIONS RESULTS
  48.  
  49. IF ~SHOW('L', "rexxsupport.library") THEN DO
  50.   IF ~ADDLIB('rexxsupport.library', 0, -30, 0)
  51.   THEN DO
  52.     SAY "couldn't open rexxsupport.library!"
  53.     EXIT 10
  54.   END
  55. END
  56.  
  57. /* get Fred running, even if we have no filenames to pass to Fred */
  58. PortName = 'FREXXED.1'
  59. IF ~SHOW(P, PortName) THEN DO
  60.   ADDRESS COMMAND "Run <nil: >nil: Fred"
  61.   ADDRESS COMMAND "WaitForPort "PortName
  62. END
  63.  
  64. /* parse the command line. inits NunArgs, Name.nnn and Sticky */
  65. PARSE ARG CmdLine
  66.  
  67. NumArgs = 0
  68. Sticky = 0
  69. DO UNTIL CmdLine = ""
  70.   CmdLine = STRIP(CmdLine)
  71.   IF LEFT(CmdLine,1) = '"' THEN DO
  72.     NumArgs = NumArgs + 1
  73.     PARSE VAR CmdLine '"' Name.NumArgs '"' CmdLine
  74.   END
  75.   ELSE DO
  76.     NumArgs = NumArgs + 1
  77.     PARSE VAR CmdLine Name.NumArgs CmdLine
  78.   END
  79.   IF Name.NumArgs="" THEN
  80.     NumArgs = NumArgs - 1 /* ignore empty arguments */
  81.   IF UPPER(Name.NumArgs) = "STICKY" & ~Sticky THEN DO /* if sticky appears twice then the second time it refers to a file */
  82.     Sticky = 1
  83.     NumArgs = NumArgs - 1 /* sticky will not be counted in NumArgs */
  84.   END
  85. END
  86.  
  87. /* if Sticky then setup a port for us to use */
  88. OurPort="ED_FREXXED.no port"
  89. IF Sticky THEN DO
  90.   i = 1
  91.   cont = 0
  92.   DO while i<100 /* no more than 100 simultaneous startups! */
  93.     IF ~SHOW("P", "ED_FREXXED."i) THEN DO
  94.     OurPort = "ED_FREXXED."i
  95.     cont = OPENPORT(OurPort)
  96.     IF cont THEN i = 100 /* we might not get the port if someone else creates it between the SHOW() and the OPENPORT() */
  97.     END
  98.     i = i + 1
  99.   END
  100.   IF ~cont THEN DO
  101.     SAY "We found no free port to use!"
  102.     EXIT(5)
  103.   END
  104. END
  105.  
  106. /* Because of problems with the user tweaking the window while the files are being opened, I accumulate all the fpl code in FPLCode and then execute it all at once at the end */
  107. FPLCode = 'int ID, oldID;'
  108.  
  109. /* if files where specified, load each file into FrexxEd */
  110. IF NumArgs > 0 THEN DO
  111.  
  112.   /* make sure KillNotify.FPL has been loaded, and add our NumArgs to the iconify countdown */
  113.   IF Sticky THEN DO
  114.     FPLCode = FplCode||'ID = GetBufferID();
  115.      ReadInfo("_iconify_when_quit_countdown", ID);
  116.      if (GetErrNo()) {
  117.        ExecuteFile("KillNotify.FPL");
  118.      }
  119.      if (ReadInfo("iconify", ID)) {
  120.        SetInfo(ID, "_iconify_when_quit_countdown", 'NumArgs' + ReadInfo("_iconify_when_quit_countdown", ID));
  121.      }'
  122.   END
  123.  
  124.   DO n=1 TO NumArgs
  125.     File = Name.n
  126.  
  127.     /* if File does not contain an absolute path then prepend the current dir to it */
  128.     IF File~="" & POS(":",File)=0 THEN DO
  129.       CDir = PRAGMA("D")
  130.       IF RIGHT(CDir,1)~=":" THEN CDir=CDir"/"
  131.       File = CDir||File
  132.     END
  133.  
  134.     FPLCode = FPLCode||'ID = New();
  135.      if (ID) {
  136.        oldID = CurrentBuffer(ID);
  137.        Activate(ID, -1, oldID);
  138.        Open("'File'");
  139.        if ('Sticky') {
  140.      SetInfo(ID, "_notifyport", "'OurPort'");
  141.      SetInfo(ID, "_iconify_when_quit", ReadInfo("iconify"));
  142.        }
  143.      }
  144.      else {
  145.        ARexxSet("Sticky", "0");
  146.      }'
  147.   END
  148. END
  149.  
  150. ELSE DO /* NumArgs = 0 */
  151.   /* have Fred open a file requester---the user can choose as many files as they like */
  152.   /* note that Sticky doesn't work with filerequested files */
  153.   FPLCode = FPLCode||'ID = Open("");'
  154. END
  155.  
  156. /* force the Fred window into view */
  157. FPLCode = FPLCode||'Deiconify(); WindowToFront();'
  158.  
  159. /* send all the accumulated code to FrexxEd */
  160. ADDRESS VALUE PortName
  161. FPLCode
  162. ADDRESS
  163.  
  164. /* if Sticky then wait for NumArgs kill notifications to show up in OurPort */
  165. IF Sticky THEN DO
  166.   DO n=1 TO NumArgs
  167.     DO WHILE ~WAITPKT(OurPort) /* wait for a packet */
  168.     END
  169.     packet = GETPKT(OurPort) /* get packet, but ignore contents! */
  170.   END
  171. END
  172.  
  173. /*************************************/
  174.