home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / comm / fido / spot / rexx / temptool.spot < prev    next >
Text File  |  1993-09-02  |  9KB  |  254 lines

  1. /***************************************************************************/
  2. /* TempTool.spot (C) Phil O'Malley 1993, Fidonet: 2:250/107.96             */
  3. /*                                                                         */
  4. /* $VER: TempTool v1,1 [02.9.93]                                           */
  5. /***************************************************************************/
  6. /*                                                                         */
  7. /* Usage: Call the script as a separate program immediately before your    */
  8. /*        text editor, ie. from an execution script, specifing the path    */
  9. /*        of the temp file on the CLI.                                     */
  10. /*                                                                         */
  11. /*          eg. rx TempTool.spot dh0:T/Spot.temp                           */
  12. /*                                                                         */
  13. /*        Installation of the script requires conciderable alteration of   */
  14. /*        your Spot reply headers and additions to your userlists. Please  */
  15. /*        see the accompanying documentation (TempTool.doc).               */
  16. /*                                                                         */
  17. /***************************************************************************/
  18. /*                                                                         */
  19. /* Other: TempTool.spot is freely distributable provided its documentation */
  20. /*        file accompanies it, and both remain unaltered. The copyright is */
  21. /*        retained by P.A.O'Malley (2:250/107.96@fidonet), and thus the    */
  22. /*        distribution is *not* public domain.                             */
  23. /*                                                                         */
  24. /***************************************************************************/
  25.  
  26. options results
  27.  
  28. version = 'TempTool v1.1'
  29.  
  30. /* Firstly grab the filename to peruse */ 
  31.  
  32. parse arg temp_file
  33.  
  34. if temp_file = '' then do
  35.   say 'Usage: rx TempTool.spot <filename>'
  36.   exit
  37. end
  38.  
  39. if exists(temp_file) = 0 then do
  40.   say 'Error: File '''temp_file''' not found!'
  41.   exit
  42. end
  43.  
  44. /***************************************************************************/
  45. /* Check for, and install if necessary, any libraries that are needed.     */
  46. /***************************************************************************/
  47.  
  48. /* For the statef() function */
  49.  
  50. if ~show(l, "rexxsupport.library") then do
  51.   if ~addlib("rexxsupport.library", 0, -30) then do
  52.     say "Error: Can''t find 'rexxsupport.library' in libs:"
  53.     exit
  54.   end
  55. end
  56.  
  57. /***************************************************************************/
  58. /* Define global variables                                                 */
  59. /***************************************************************************/
  60.  
  61. /* Logical assigns */
  62.  
  63. true    = 1
  64. false   = 0
  65. newline = '0a'x
  66.  
  67. /* Intra-script marker assigns. Notice that the intro markers are not really
  68.    necessary to make the script work, but they do ensure a roughly constant
  69.    execution speed on a 68000, particularly with long messages. */
  70.  
  71. marker_intro_start = '!intro_start'||newline
  72. marker_intro_end   = '!intro_end'||newline
  73.  
  74. marker_name_start  = '!#'
  75. marker_name_end    = '#!'
  76.  
  77. /* Intra-script path assigns */
  78.  
  79. userlist.1 = 'spot:userlist_fidonet'
  80. userlist.2 = 'spot:userlist_amiganet'
  81.  
  82. /***************************************************************************/
  83. /* Grab the data from the temp file and alter it...                        */
  84. /***************************************************************************/
  85.  
  86. /* Grab the data from the tempory file */
  87.  
  88. call open(file,temp_file,'r')
  89. temp_data = readch(file,filelength(temp_file))
  90. call close(file)
  91.  
  92. /* Call the AlterIntro procedure */
  93.  
  94. temp_data = alterintro(temp_data,marker_intro_start,marker_intro_end,marker_name_start,marker_name_end)
  95.  
  96. /***************************************************************************/
  97. /* Save the altered data back to the original file name and quit...        */
  98. /***************************************************************************/
  99.  
  100. call open(file,temp_file,'w')
  101. writech(file,temp_data)
  102. call close(file)
  103.  
  104. exit
  105.  
  106. /***************************************************************************/
  107. /* AlterIntro procedure.                                                   */
  108. /***************************************************************************/
  109.  
  110. alterintro: procedure expose userlist. newline true false
  111.  
  112.   parse arg temp.0,intro_start_marker,intro_end_marker,name_start_marker,name_end_marker
  113.  
  114.   /* Grab the position of the intro markers. */ 
  115.  
  116.   intro_start = index(temp.0,intro_start_marker,1)
  117.   intro_end   = index(temp.0,intro_end_marker,1)
  118.  
  119.   /* If either are bust then the following will recognise it and pop the
  120.      procedure. */
  121.  
  122.   if (intro_end-intro_start) ~> 0 then return temp.0
  123.  
  124.   /* Strip the intro markers, leaving a copy of what was held within in the
  125.      variable intro.0. */ 
  126.  
  127.   intro.1 = left(temp.0,(intro_end-1))
  128.   intro.0 = right(intro.1,(length(intro.1)-(intro_start+(length(intro_start_marker)-1))))
  129.  
  130.   /* Now that we have just the reply header in one easy to access variable,
  131.      we can now look for any name markers. */
  132.  
  133.   name_start = index(intro.0,name_start_marker,1)
  134.   name_end   = index(intro.0,name_end_marker,1)
  135.  
  136.   /* And execute this loop until no more are found. */
  137.  
  138.   do until (name_end-name_start) ~> 0
  139.   
  140.     /* Now purge the name from the markers and hold it in name.0 */
  141.  
  142.     name.1 = right(intro.0,(length(intro.0)-name_start-(length(name_end_marker)-1)))
  143.     name.0 = left(name.1,(name_end-name_start-length(name_end_marker)))
  144.  
  145.     /* Because there might be multiple userlists to scan through to find a
  146.        match, I've put the scanning routines into their own procedure which
  147.        returns either the contents of the first userlist which matched the
  148.        parameters, or a junk variable. */
  149.  
  150.     userlist = chooseuserlist()
  151.  
  152.     /* And now locate the position of the entry concerned. */
  153.  
  154.     read_posn = index(userlist,name.0,1)
  155.  
  156.     /* If a valid userlist was returned then the following loop is entered
  157.        into, otherwise it is skipped. */
  158.  
  159.     if read_posn ~= 0 then do
  160.  
  161.       /* Grab the exact position of the userlist entry. */
  162.  
  163.       entry_start = read_posn
  164.       entry_end   = index(userlist,newline,read_posn)
  165.  
  166.       /* And now the position of the comment annotation */
  167.  
  168.       comment_start = index(userlist,";",read_posn)
  169.  
  170.       /* If this entry has no comment, then the following loop will not be
  171.          entered into. */
  172.  
  173.       if (comment_start ~= 0) then do
  174.         if (comment_start ~> entry_end) then do
  175.  
  176.           /* This "-2" business is because Spot annotes its comments with a
  177.              "; " string, hence I'm chopping it off. */
  178.  
  179.           entry.1 = right(userlist,((length(userlist)-(comment_start-1))-2))
  180.           entry.0 = left(entry.1,((entry_end-comment_start)-2))
  181.  
  182.           name.0 = entry.0
  183.  
  184.         end
  185.       end 
  186.     end
  187.  
  188.     /* And now reconstruct the reply header. Intro.1 and intro.2 are just
  189.        what is to the left and right of the markers. */
  190.  
  191.     intro.1 = left(intro.0,(name_start)-1)
  192.     intro.2 = right(intro.0,(length(intro.0)-name_end-(length(name_end_marker)-1)))
  193.  
  194.     /* Hence, putting name.0 in between will either insert the nickname (if
  195.        present) or, if not, the original. */
  196.  
  197.     intro.0 = intro.1||name.0||intro.2
  198.  
  199.     /* And prepare for the loop back. */ 
  200.  
  201.     name_start = index(intro.0,name_start_marker,1)
  202.     name_end   = index(intro.0,name_end_marker,1)
  203.  
  204.   end
  205.   
  206.   /* temp.1 is what was originally before the intro_start_marker, and temp.2
  207.      what was after the intro_end_marker. */
  208.  
  209.   temp.1 = left(temp.0,(intro_start-1))
  210.   temp.2 = right(temp.0,(length(temp.0)-(intro_end+length(intro_end_marker)-1)))
  211.  
  212. return temp.1||intro.0||temp.2
  213.  
  214. /***************************************************************************/
  215. /* ChooseUserlist() procedure, spawned from AlterIntro().                    */
  216. /***************************************************************************/
  217.  
  218. ChooseUserlist: procedure expose userlist. name.0 false
  219.  
  220.   /* Stack the current userlist marker */
  221.  
  222.   current_userlist = 1
  223.  
  224.   /* Now, look through all the userlists */
  225.  
  226.   do until exists(userlist.current_userlist) = false
  227.  
  228.     call open(file,userlist.current_userlist)
  229.     userlist_data = readch(file,filelength(userlist.current_userlist))
  230.     call close(file)
  231.     
  232.     if index(userlist_data,name.0,1) ~= false then do
  233.       return userlist_data
  234.     end
  235.  
  236.     current_userlist = current_userlist + 1
  237.  
  238.   end
  239.  
  240. return "Non available fitting parameters."
  241.  
  242. /***************************************************************************/
  243. /* Miscellaneous procedures...                                             */
  244. /***************************************************************************/
  245.  
  246. /* Return the length of a file */
  247.  
  248. filelength: procedure
  249.  
  250.   parse arg file
  251.   parse value statef(file) with type size blk bits day min tick com
  252.  
  253. return size
  254.