home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Editor / DVD!FX17.LHA / FrexxEd / Rexx / FrexxEdStart.rx < prev    next >
Encoding:
Text File  |  1995-03-20  |  3.4 KB  |  131 lines

  1. /*****************************************************************************
  2.  * $VER: FrexxFrontEd v2.3 (20.2.95) - by Daniel Stenberg & Michiel Willems
  3.  *
  4.  * Arexx script for FrexxEd as replacement for Ed used with Ced
  5.  *
  6.  * Altered by Nicolas Dade to be more general. last changed (18.2.95)
  7.  *
  8.  * NEW FEATURES:
  9.  * (5.2.95)
  10.  *  o correctly handles relative paths in Filename.
  11.  *  o handles multiple filenames.
  12.  *  o cleaned up STICKY code.
  13.  * (18.2.95)
  14.  *  o STICKY can appear anywhere in the arguments
  15.  * BUGS:
  16.  *  o opening more than one new file at once does not work!
  17.  * (20.2.95)
  18.  *  o [Daniel/Kjell] Added the iconfy-stuff!
  19.  *
  20.  *
  21.  * USAGE/DESCRIPTION:
  22.  *
  23.  * Arguments: rx FrexxEdStart.rx {Filenames} [STICKY]
  24.  * Example  : rx FrexxEdStart S:Startup-Sequence S:User-Startup
  25.  *
  26.  ****************************************************************************/
  27.  
  28. OPTIONS RESULTS
  29.  
  30. IF ~SHOW('L', "rexxsupport.library") THEN DO
  31.   IF ~ADDLIB('rexxsupport.library', 0, -30, 0)
  32.   THEN DO
  33.     SAY "couldn't open rexxsupport.library!"
  34.     EXIT 10
  35.   END
  36. END
  37.  
  38. PARSE ARG CMDLINE
  39.  
  40. IF CMDLINE = "" THEN
  41.   NOARGS = 1
  42. ELSE
  43.   NOARGS = 0
  44.  
  45. NUMARGS = 0
  46. STICKY = 0
  47. DO UNTIL CMDLINE = ""
  48.   CMDLINE = STRIP(CMDLINE)
  49.   IF LEFT(CMDLINE,1) = '"' THEN DO
  50.     NUMARGS = NUMARGS + 1
  51.     PARSE VAR CMDLINE '"' NAME.NUMARGS '"' CMDLINE
  52.   END
  53.   ELSE DO
  54.     NUMARGS = NUMARGS + 1
  55.     PARSE VAR CMDLINE NAME.NUMARGS CMDLINE
  56.   END
  57.   IF NAME.NUMARGS="" THEN 
  58.     NUMARGS = NUMARGS - 1 /* ignore empty arguments */
  59.   IF UPPER(NAME.NUMARGS) = "STICKY" & STICKY = 0 THEN DO /* if sticky appears twice then the second time it refers to a file */
  60.     STICKY = 1
  61.     NUMARGS = NUMARGS - 1
  62.   END
  63. END
  64.  
  65. /* if we are going to be sticky then setup a port for us to use */
  66. OURPORT="ED_FREXXED.no port"
  67. IF STICKY THEN DO
  68.   i = 1
  69.   cont = 0
  70.   DO while i<100 /* no more than 100 simultaneous startups! */
  71.     IF ~SHOW("P", "ED_FREXXED."i) THEN DO
  72.         OURPORT = "ED_FREXXED."i
  73.         cont = OPENPORT(OURPORT)
  74.         IF cont THEN i = 100 /* we might not get the port if someone else creates it between the SHOW() and the OPENPORT() */
  75.     END
  76.     i = i + 1
  77.   END
  78.   IF ~cont THEN DO
  79.     SAY "We found no free port to use!"
  80.     EXIT(5)
  81.   END
  82. END
  83.  
  84. /* process each filename */
  85. DO n=0 TO NUMARGS
  86.   FILE = NAME.n
  87.  
  88. /* if FILE does not contain an absolute path then prepend the current dir to it */
  89.   IF FILE~="" & POS(":",FILE)=0 THEN DO
  90.     CDIR = PRAGMA("D")
  91.     IF RIGHT(CDIR,1)~=":" THEN CDIR=CDIR"/"
  92.     FILE = CDIR||FILE
  93.   END
  94.  
  95.   PortName = 'FREXXED.1'
  96.  
  97.   IF ~SHOW(P, PortName) THEN DO
  98.     ADDRESS COMMAND "RUN <NIL: >NIL: Fred"
  99.     ADDRESS COMMAND "WaitForPort " || PortName
  100.   END
  101.   ADDRESS VALUE PortName
  102.   'int ID = Open (ARexxRead("FILE"));
  103.    if(ID && atoi(ARexxRead("STICKY"))) {
  104.      ReadInfo("_notifyport");
  105.      if(GetErrNo())
  106.        ExecuteFile("KillNotify.FPL");
  107.      SetInfo(ID, "_notifyport", ARexxRead("OURPORT"));
  108.      SetInfo(ID, "_iconify_when_quit", ReadInfo("iconify"));
  109.    }
  110.    else {
  111.      ARexxSet("STICKY", "0");
  112.    }
  113.    Deiconify();
  114.    WindowToFront();
  115.    '
  116. END
  117.  
  118. /* if STICKY then wait for NUMARGS kill notifications to show up in OURPORT */
  119. IF STICKY THEN DO
  120.   DO n=1 TO NUMARGS
  121.     DO WHILE ~WAITPKT(OURPORT) /* wait for NUMARGS messages that tell 
  122.                                   us that the NUMARGS previously opened
  123.                                   buffer are killed */
  124.     END
  125.     packet = GETPKT(OURPORT) /* get package, but ignore contents! */
  126.     CALL REPLY(packet,0)   /* return OK! */
  127.   END
  128. END
  129.  
  130. /*************************************/
  131.