home *** CD-ROM | disk | FTP | other *** search
/ The AGA Experience 2 / agavol2.iso / software / utilities / comms / html-heaven / arexx / html-ttx.rexx < prev    next >
OS/2 REXX Batch file  |  1996-01-08  |  9KB  |  177 lines

  1. /* HTML-Helper Arexx script for TTX (TurboText)
  2.  * Ver      : 1.2 (7 January 1996)
  3.  * Copyright: Cletus Baker (InterNet: cletus@gonix.com)
  4.  * Function : Pass on the HTML commands from HTML-Helper to TTX.
  5.  *            This version adds support for AutoView, which SAVEs
  6.  *            the document and reloads it into the browser of choice
  7.  *            for semi-WYSIWYG viewing with each command entered.
  8.  *            Original created by Paul Kolenbrander with thanks to
  9.  *            Dan Barrett. Heavily expanded, improved and modified
  10.  *            by Cletus Baker. (Who also made the TTX-attach script)
  11.  * Input    : HTMLCMD - The HTML command to be inserted; output from
  12.  *            HTML-Heaven.
  13.  *          : AV - The AutoView status; output from HTML-Heaven
  14.  *
  15.  *
  16.  *      There are several conditions understood by this script.  They
  17.  *      include whether or not a block is selected, whether or not a
  18.  *      command contains quotation marks, and whether or not a command
  19.  *      is a split command containing an open and a close element.
  20.  *      This script is intended to be intuitive and behaves under each
  21.  *      possible condition as follows:
  22.  *
  23.  *   1) Block is selected, command is split; command contains no
  24.  *      quotation marks:
  25.  *         The command will be broken and the open and close will be
  26.  *         pasted on either side of the selected block.  The cursor
  27.  *         is placed at the end of the close, ready for continued body
  28.  *         text entry.
  29.  *
  30.  *   2) Block is selected, command is *not* split; command contains no
  31.  *      quotation marks:
  32.  *         The command is pasted at the end of the selected block.  The
  33.  *         cursor is placed at the end of the command, ready for
  34.  *         continued body text entry.
  35.  *
  36.  *   3) Block is selected, command is split; command *does* contain
  37.  *      quotation marks:
  38.  *         The command will be broken and the open and close will be
  39.  *         pasted on either side of the selected block.  In this case,
  40.  *         the cursor is placed between the first set of quotation
  41.  *         marks found within the open portion of the command, ready
  42.  *         for entry of the quoted name or value.
  43.  *
  44.  *   4) Block is selected, command is *not* split; command *does*
  45.  *      contain quotation marks:
  46.  *         The command is pasted at the end of the selected block.  The
  47.  *         cursor is placed between the first set of quotation marks
  48.  *         found in the command, ready for entry of the quoted name or
  49.  *         value.
  50.  *
  51.  *   5) Block is *not* selected, command is split; *whether or not* the
  52.  *      command contains quotation marks:
  53.  *         The command is inserted at the current location of the cursor.
  54.  *         The cursor is then positioned between the open and close
  55.  *         elements of the command, ready for entry of the text which
  56.  *         is subject to the command.  Where the split command also
  57.  *         contains quotation marks, don't forget to supply any text
  58.  *         required there as well.
  59.  *
  60.  *   6) Block is *not* selected, command is *not* split; command
  61.  *      contains no quotation marks:
  62.  *         The command is inserted at the current location of the cursor.
  63.  *         The cursor is then positioned at the end of the freshly
  64.  *         pasted command, ready for continued body text entry.
  65.  *
  66.  *   7) Block is *not* selected, command is *not* split; command
  67.  *      *does* contain quotation marks:
  68.  *         the command is inserted at the current location of the cursor.
  69.  *         The cursor is then positioned between the first set of
  70.  *         quotation marks found in the command, ready for entry of the
  71.  *         quoted name or value.
  72.  */
  73.  
  74. OPTIONS RESULTS                            /* Enable return codes.      */
  75. PARSE ARG AV HTMLCMD                       /* Snag our HTMLCMD and AV   */
  76. HTMLCMD = SUBSTR(HTMLCMD,2, LENGTH(HTMLCMD)-1) /* strip leading space   */
  77. If HTMLCMD == "" then do                   /* If no command, go directly*/
  78.   Call AutoView()                          /*   to the AutoView routine,*/
  79.   EXIT                                     /*   then EXIT the program.  */
  80.   end
  81.  
  82. qq  = '"'||'"'                             /* This should avoid a bunch */
  83. qqq = '"'||'"'||'"'                        /*   of quoting gymnastics.  */
  84.  
  85. offset = index(HTMLCMD,qqq) - 1            /* Does HTMLCMD contain any  */
  86.                                            /*   triple quotes (implying */
  87.                                            /*   dbl quotes at its end)? */
  88. HTMLCMD = STRIP((TRANSLATE(HTMLCMD,'','\')), B,'"')
  89.                                            /* Strip quotes at each end. */
  90.  
  91. ADDRESS 'TURBOTEXT' 'ActivateLastDoc'      /* Get the active window     */
  92. ADDRESS VALUE RESULT                       /* ...and address its port.  */
  93.  
  94. GetPrefs AutoEraseBlocks                   /* Get status of block auto- */
  95. AEBstatus = RESULT                         /* erasure for later reset.  */
  96.  
  97. SetPrefs AutoEraseBlocks OFF               /* Render this pref harmless.*/
  98.  
  99. GetBlkInfo                                 /* Is a block selected?      */
  100. PARSE UPPER VAR RESULT blk vert lblk cblk  /* Get the particulars...    */
  101.  
  102. if POS('><',HTMLCMD) ~= 0 then do          /* Is it a split command?    */
  103.                                            /* If yes, then....          */
  104.    if blk = "ON" then do                   /* If block is selected we:  */
  105.       MarkBlk                              /* UNmark the marked block.  */
  106.                                            /* Isolate open and close.   */
  107.       CMD2 = right(HTMLCMD,(LENGTH(HTMLCMD)-(LASTPOS('<',HTMLCMD))+1))
  108.       CMD1 = substr(HTMLCMD,1,(LENGTH(HTMLCMD)-LENGTH(CMD2)))
  109.       Text CMD2                            /* Insert close @ cursor.    */
  110.       SetBookmark 0                        /* Mark our place here.      */
  111.       Move lblk cblk                       /* move to start of block.   */
  112.       Text CMD1                            /* Insert the open here.     */
  113.       quotepos = index(CMD1,qq)            /* Check open for dbl quotes.*/
  114.                                            /* If quotes, place cursor...*/
  115.       if quotepos > 0 then MoveLeft (length(CMD1)-quotepos)
  116.       else do
  117.          MoveBookmark 0                    /* Otherwise return to mark  */
  118.          MoveRight (LENGTH(CMD1))          /*   and adjust cursor right */
  119.          end                               /*   equal to length of CMD1.*/
  120.       ClearBookmark 0                      /* Pick up after yourself.   */
  121.       end
  122.  
  123.    else do                                 /* If no block is selected...*/
  124.       Text HTMLCMD                         /* Insert all @ current pos. */
  125.                                            /* ...and move cursor to ctr.*/
  126.       MoveLeft (LENGTH(HTMLCMD)+1-LASTPOS('<',HTMLCMD))
  127.       end
  128.    end
  129. else do                                    /* If not a split command... */
  130.    if blk = "ON" then MarkBlk              /* UNmark any marked block.  */
  131.                                            /* If triple quotes found we */
  132.                                            /*   restore dblquotes @ end.*/
  133.    if offset >= 0 then HTMLCMD = insert(qq,HTMLCMD,(offset))
  134.    Text HTMLCMD                            /* Insert command @ cursor.  */
  135.    quotepos = index(HTMLCMD,qq)            /* Find location of quotes & */
  136.                                            /*   place cursor between.   */
  137.    if quotepos > 0 then MoveLeft (length(HTMLCMD)-quotepos)
  138.    end                                     /* No quotes?  Then stay put.*/
  139.  
  140. SetPrefs AutoEraseBlocks AEBstatus         /* Reset AutoEraseBlocks     */
  141. Call AutoView()                            /* Perform AutoView routine  */
  142.  
  143. EXIT
  144.  
  145. AutoView:
  146.   If AV = 'SAVE' then do                   /* Check for AutoView = ON   */
  147.      GetFilePath
  148.      FileName = RESULT                     /* Do we have a filename?    */
  149.      If FileName = "" then do              /* If not, open a requester  */
  150.        SaveFileAs                          /*   for a new filename...   */
  151.        GetFilePath                         /*   (and then don't forget  */
  152.        FileName = RESULT                   /*   (to tell me what it is).*/
  153.        end
  154.      else SaveFile                         /*   otherwise save.         */
  155.                                            /* Now reload doc in browser.*/
  156.  
  157.      IF OPEN('tempname', 'T:TempRexxFile', 'READ') ~= 1 THEN DO  
  158.         OPEN('tempname','T:TempRexxFile','WRITE')
  159.         WRITELN('tempname',FileName)
  160.         CLOSE('tempname')
  161.         ADDRESS COMMAND 'rx S:HTMLVIEW.rexx '||FileName
  162.      END
  163.      ELSE DO
  164.         OLDFILE = READLN('tempname')
  165.         IF UPPER(OLDFILE) = UPPER(FileName) THEN DO
  166.             ADDRESS COMMAND 'rx S:HTMLVIEW.rexx'
  167.         END
  168.         ELSE DO
  169.            OPEN('tempname','T:TempRexxFile','WRITE')
  170.            WRITELN('tempname',FileName)
  171.            CLOSE('tempname')
  172.            ADDRESS COMMAND 'rx S:HTMLVIEW.rexx '||FileName
  173.         END
  174.      END
  175.    end
  176. return
  177.