home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / comm / mail / thor / thor.lha / rexx / CEDDownload.thor < prev    next >
Text File  |  1994-08-06  |  3KB  |  137 lines

  1. /* CEDDownload.thor · by Troels Walsted Hansen
  2. ** $VER: CEDDownload.thor v1.2 (23.02.94)
  3. **
  4. ** An ARexx script that creates a download event for the file
  5. ** under the cursor in CED.
  6. **
  7. ** Get-file-name code is a slightly modified version of
  8. ** something I found in insert_adr.ced by Dirk Federlein.  :^)
  9. */
  10.  
  11. /* user varibles. edit to your hearts content */
  12.  
  13. bbsname = "REQUEST"     /* Change REQUEST to a BBS name if you like.. */
  14.  
  15. /* this is where the action begins.. */
  16.  
  17. options results
  18. address 'rexx_ced'
  19.  
  20. /* needs Thor, CED and rexxsupport.library */
  21.  
  22. if(substr(address(),1,4) ~= "THOR") then do
  23.     parse arg portname
  24.     if~(show(p, portname)) then do
  25.         if ~(show(p, "THOR.01")) then do
  26.             say "No THOR port found!"
  27.             exit
  28.         end
  29.         else portname = "THOR.01"
  30.     end
  31. end
  32. else portname = address()
  33.  
  34. if ~show('ports','rexx_ced') then do
  35.     say "Sorry, CED's ARexx port was not found. Aborting script.."
  36.     exit
  37. end
  38.  
  39. if ~show(l, 'rexxsupport.library') then do
  40.     if ~addlib('rexxsupport.library', 0, -30) then do
  41.         say "Please install rexxsupport.library in your libs: directory"
  42.         exit
  43.     end
  44. end
  45.  
  46. /* get filename */
  47.  
  48. tabchar = '09'X
  49. cr    = '0A'X
  50. /*    Get contents of current line: */
  51. status 55
  52. line = result
  53.  
  54. /*    Get tab size: */
  55. status 8
  56. tabadjust = result - 1
  57.  
  58. /*    Get cursor x position (relative to beginning of line = 1): */
  59. status 46
  60. cur = result + 1
  61.  
  62. i = index(line,tabchar)
  63. DO while i > 0 & i <= cur - tabadjust
  64.     cur = cur - tabadjust
  65.     i = index(line,tabchar,i+1)
  66. END
  67.  
  68. /* If the current character is non-alphabetic, then start one character
  69. ** over to the left.  This allows the cursor to be immediately after
  70. ** the key word (say on a space or bracket.)
  71. */
  72.  
  73. char = substr(line,cur,1)
  74. if (~(datatype(char,'A') | char = '.' | char = '-' | char = '_' | char = '+') & cur > 1) then
  75.     cur = cur - 1
  76.  
  77. /*    Find leftmost and rightmost alphabetic character adjacent to current: */
  78.  
  79. right = cur - 1
  80. left = cur + 1
  81. char = 'A'
  82. DO while (datatype(char,'A') | char = '.' | char = '-' | char = '_' | char = '+') & (left > 0)
  83.      left = left - 1
  84.     if left > 0 then
  85.         char = substr(line,left,1)
  86. END
  87. char = 'A'
  88. DO while (datatype(char,'A') | (char = '.' | char = '-' | char = '_' | char = '+'))
  89.     right = right + 1
  90.     char = substr(line,right,1)
  91. END
  92.  
  93. if right-left <= 1 then
  94. DO
  95.     address(portname)
  96.     THORTOFRONT
  97.     REQUESTSTRING TITLE '"Enter name of file to download:"' BT '"_Ok|_Cancel"' MAXCHARS 40
  98.     filetodl = result
  99.     if(rc ~= 0) then do
  100.         REQUESTNOTIFY TEXT '"Need a filename to create a download event."' BT '"_Ok"'
  101.         address 'rexx_ced'
  102.         CEDTOFRONT
  103.         exit
  104.         end
  105. END
  106. else
  107. DO
  108.     filetodl = substr(line,left+1,right-left-1)
  109. END
  110.  
  111. /* create upload event */
  112.  
  113. address(portname)
  114.  
  115. if(BBSname = "REQUEST") then do
  116.     THORTOFRONT
  117.     REQUESTLIST BBSLIST
  118.     BBSName = result
  119.  
  120.     if(rc ~= 0) then do
  121.         REQUESTNOTIFY TEXT '"Need a bbsname to create a download event."' BT '"_Ok"'
  122.         address 'rexx_ced'
  123.         CEDTOFRONT
  124.         exit
  125.         end
  126. end
  127.  
  128. ADDEVENT BBS '"'bbsname'"' DOWNLOAD FILENAME '"'filetodl'"'
  129. if(rc ~= 0) then REQUESTNOTIFY TEXT '"Didn''t succeed in creating a download event for the file"' BT '"_Ok"'
  130.  
  131. /* bye.. */
  132.  
  133. address 'rexx_ced'
  134. CEDTOFRONT
  135.  
  136. exit
  137.