home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 427.lha / VLT_select_v2.3 / select.vlt < prev    next >
Text File  |  1990-10-07  |  8KB  |  301 lines

  1. /* select.vlt--by Warren Block.  A dialing macro for VLT, based on: */
  2.  
  3. /* Dial_Select.vlt - display a list of numbers to dial for mouse selection    */
  4. /*                 - written by Glenn M. Lewis - Caltech - 12/12/89           */
  5. /*                 - based upon an ARexx script in Amazing Computing V4.12    */
  6. /*                                                                            */
  7. /* Do what you want with this code.                                           */
  8. /* I shall not be held responsible for any use or misuse of this code.        */
  9. /* Since parts of this code were derived from the Amazing Computing article,  */
  10. /* here is the gratuitous notice:                                             */
  11. /*                                                                            */
  12. /* copyright 1989 Richard Lee Stockton and Gramma Software.                   */
  13. /* This code is freely distributable as long as this copyright                */
  14. /* notice remains, unchanged, at the start of the code.  Thank you.           */
  15. /*                                                                            */
  16. /* You are welcome.                                                           */
  17. /*                  -- Glenn                                                  */
  18.  
  19. title='Select V2.3'
  20.  
  21. if ~show('L','rexxarplib.library') then do
  22.   call addlib('rexxsupport.library',0,-30,0)
  23.   call addlib('rexxarplib.library',0,-30,0)
  24. end
  25.  
  26. if show('Ports','SELECTHOST') then exit
  27.  
  28. address VLT
  29.  
  30. predial=0
  31. numfile='S:VLT.Phone'
  32. dialfile='t:undialed'
  33. dialstr='<<< Dial >>>'
  34. password='AMIGA'
  35. gadht=14
  36. maxdialcnt=8
  37. pausetime=2
  38. quitfont ='Topaz'
  39. call setenv(systempassword,password)
  40. cmdstart ='1b'x||"[?91h"||password||"~@"
  41. cmdend   ='1b'x||"[?91l"
  42. shellname='NewCLI'
  43. dialcount=0
  44. dialstr. =''
  45.  
  46. if ~exists('C:FastFonts') then
  47.   fontprog='FF'
  48. else
  49.   fontprog='FastFonts'
  50. fontprog=fontprog '> NIL:'
  51.  
  52. 'extract "FUNCTIONKEY"'
  53. oldF1=VLT.FUNCTIONKEY.1
  54. "function 1 [~rx 'address SELECTPORT CANCEL']"
  55.  
  56. vltwidth=screencols('VLT')
  57. if vltwidth == -1 then do
  58.   screenname=''
  59.   vltwidth=screencols()
  60.   vltheight=screenrows()
  61. end
  62. else do
  63.   vltheight=screenrows('VLT')
  64.   screenname='VLT'
  65. end
  66. dialx=vltwidth*.06
  67. dialy=vltheight*.25
  68. call LoadNumbers(numfile)
  69.  
  70. rx '{call createhost(SELECTHOST,SELECTPORT'||','||screenname||')}'
  71. do 500 while ~show('Ports','SELECTHOST')
  72.   call delay(5)
  73. end
  74. if ~show('Ports','SELECTHOST') then do
  75.   'message "Couldn''t open SELECTHOST port."'
  76.   signal CleanExit
  77. end
  78.  
  79. maxpercolumn=(vltheight%gadht)-1
  80. columns=max((gadht*(files.count+2))%vltheight,1)
  81. if gadht*(files.count+2) > vltheight then
  82.   if gadht*(files.count+1)//vltheight ~= 0 then columns=columns+1
  83. gadspercolumn=(files.count+1)%columns
  84. if (files.count+1)//columns ~= 0 then gadspercolumn=gadspercolumn+1
  85. gadspercolumn=min((vltheight-gadht)%gadht,gadspercolumn)
  86. w.wid =min(15*(columns+1)+(namelen+1)*8*columns,vltwidth)
  87. w.hght=min(16+14*gadspercolumn,vltheight)
  88. w.top =(vltheight-w.hght)/2
  89. w.left=(vltwidth-w.wid)*.94
  90. call openwindow(SELECTHOST,w.left,w.top,w.wid,w.hght,,
  91. 'CLOSEWINDOW+GADGETUP','WINDOWCLOSE+WINDOWDRAG+BACKFILL+ACTIVATE',title)
  92. do i=0 to files.count
  93.   call addgadget(SELECTHOST,12+(168*(i%gadspercolumn)),,
  94.   14+14*(i//gadspercolumn),i,gadget.i,gadget.i)
  95. end
  96. call openport(SELECTPORT)
  97.  
  98. if exists(dialfile) then call ReadUndialed
  99.  
  100. do forever
  101.   call waitpkt(SELECTPORT)
  102.   p=getpkt(SELECTPORT)
  103.   if p ~== NULL() then do
  104.     name=strip(getarg(p))
  105.     call reply(p,0)
  106.     select
  107.       when name == 'CLOSEWINDOW' | name == 'CANCEL' then do
  108.         call postmsg()
  109.         call closewindow(SELECTHOST)
  110.         if exists(dialfile) then
  111.           call DeleteDial
  112.         call SetFont(quitfont)
  113.         signal CleanExit
  114.       end
  115.       when name == dialstr then do
  116.         if dialcount>0 then
  117.           signal StartDialing
  118.         else do
  119.           call closewindow(SELECTHOST)
  120.           signal CleanExit
  121.         end
  122.       end
  123.       otherwise do
  124.         if exists(dialfile) then do
  125.           call DeleteDial
  126.           call postmsg(dialx,dialy,copies('\ ',maxdialcnt),screenname)
  127.           dialcount=0
  128.           dialstr. =''
  129.         end
  130.         call AddName
  131.       end
  132.     end
  133.   end
  134. end
  135. exit
  136.  
  137. DeleteDial:
  138. address command 'delete' dialfile
  139. return
  140.  
  141. SetFont:
  142. parse arg newfont
  143. address command fontprog newfont||'.font'
  144. return
  145.  
  146. ReadUndialed:
  147. call open('input',dialfile,'Read')
  148. dialcount=0
  149. do until eof('input')
  150.   in=readln('input')
  151.   if length(in)>0 then do
  152.     dialstr.dialcount=in
  153.     dialcount=dialcount+1
  154.   end
  155. end
  156. tempstr=''
  157. do i=0 to maxdialcnt-1
  158.   if dialstr.i ~= '' then tempstr=tempstr||i+1||': '
  159.   tempstr=tempstr||dialstr.i
  160.   if i<maxdialcnt-1 then tempstr=tempstr||'\'
  161. end
  162. if dialcount>0 then
  163.   call postmsg(dialx,dialy,tempstr,screenname)
  164. call close('input')
  165. return
  166.  
  167. AddName:
  168. if dialcount<maxdialcnt then do
  169.   dialstr.dialcount=name
  170.   tempstr=''
  171.   do i=0 to maxdialcnt-1
  172.     if dialstr.i ~= '' then tempstr=tempstr||i+1||': '
  173.     tempstr=tempstr||dialstr.i
  174.     if i<maxdialcnt-1 then tempstr=tempstr||'\'
  175.   end
  176.   call postmsg(dialx,dialy,tempstr,screenname)
  177.   dialcount=dialcount+1
  178. end
  179. return
  180.  
  181. StartDialing:
  182. dialnum=0
  183. call closewindow(SELECTHOST,'CONTINUE')
  184. call postmsg()
  185. call postmsg(dialx,dialy,copies(' ',namelen+19),
  186. ||'\'||center('Press F1 To Cancel',namelen+18),screenname)
  187. do forever
  188.   'trap add install "CONNECT" (rx [address SELECTPORT CONNECT])'
  189.   'trap add install "BUSY"    (rx [address SELECTPORT BUSY])'
  190.   'trap add install "NO"      (rx [address SELECTPORT NO])'
  191.   'schedule (Timer: delay 35; rx [address SELECTPORT TIMEOUT])'
  192.   name=dialstr.dialnum
  193.   'clear'
  194.   'baud' files.name.pbaud
  195.   call postmsg(dialx,dialy,center('Dialing' files.name.name ,
  196.   '('||files.name.pbaud 'baud)',namelen+18),screenname)
  197.   'send "*R"'
  198.   if predial ~= 0 then call delay(predial)
  199.   'send raw "'||'ATDT' files.name.phone||'"'
  200.   'send "*R"'
  201.   call waitpkt(SELECTPORT)
  202.   'cancel "Timer"'
  203.   'trap remove all'
  204.   p=getpkt(SELECTPORT)
  205.   answer=strip(getarg(p))
  206.   call reply(p,0)
  207.   select
  208.     when answer == 'CONNECT' then do
  209.       call postmsg()
  210.       'clear'
  211.       if files.name.pfont ~= '' then
  212.         call SetFont(files.name.pfont)
  213.       if length(files.name.scp)>0 & exists(files.name.scp) then do
  214.         str=cmdstart||files.name.scp||cmdend
  215.         'emit raw "'||str||'"'
  216.       end
  217.       do i=dialnum to dialcount-1
  218.         q=i+1
  219.         dialstr.i=dialstr.q
  220.       end
  221.       dialcount=dialcount-1
  222.       call DeleteDial
  223.       if dialcount>0 then do
  224.         call open('output',dialfile,'Write')
  225.         do i=0 to dialcount-1
  226.           call writeln('output',dialstr.i)
  227.         end
  228.         call close('output')
  229.       end
  230.       call closewindow(SELECTHOST)
  231.       signal CleanExit
  232.     end
  233.     when answer == 'CANCEL' then do
  234.       signal StopIt
  235.     end
  236.     otherwise do
  237.       'send "*R"'
  238.       call postmsg(dialx,dialy,center('Pausing...',namelen+18),screenname)
  239.       'schedule (Timer: delay ' pausetime '; rx [address SELECTPORT TIMEOUT])'
  240.       call waitpkt(SELECTPORT)
  241.       p=getpkt(SELECTPORT)
  242.       answer=strip(getarg(p))
  243.       call reply(p,0)
  244.       if answer == 'CANCEL' then signal StopIt
  245.       dialnum=dialnum+1
  246.       if dialnum>(dialcount-1) then dialnum=0
  247.     end
  248.   end
  249. end
  250. exit
  251.  
  252. StopIt:
  253. 'send "*R"'
  254. call postmsg()
  255. 'message "'||center('--- Dialer Stopped ---',namelen+18)||'"'
  256. 'clear'
  257. call open('output',dialfile,'Write')
  258. do i=0 to dialcount-1
  259.   call writeln('output',dialstr.i)
  260. end
  261. call close('output')
  262. call closewindow(SELECTHOST)
  263. call SetFont(quitfont)
  264.  
  265. CleanExit:
  266. "function 1 ["||oldF1||"]"
  267. exit 0
  268.  
  269. LoadNumbers:
  270.   parse arg filename
  271.   if ~open('input', filename, 'Read') then do
  272.     'message "Error opening' filename 'for input."'
  273.     signal CleanExit
  274.   end
  275.   template=Readln('input')
  276.   parse var template '|' namelen '|' numblen '|' baudlen '|' fontlen '|'
  277.   namelen=length(namelen)+1
  278.   numblen=length(numblen)+1
  279.   baudlen=length(baudlen)+1
  280.   fontlen=length(fontlen)+1
  281.   i=0
  282.   gadget. =''
  283.   do while ~eof('input')
  284.     line=Readln('input')
  285.     if length(compress(line))<2 | substr(line,1,1) == '|' then iterate
  286.     parse var line 1 bbsname +namelen number +numblen baud +baudlen font +fontlen script .
  287.     name=strip(bbsname)
  288.     files.name.name =name
  289.     files.name.phone=strip(number)
  290.     files.name.pbaud=strip(baud)
  291.     files.name.pfont=strip(font)
  292.     files.name.scp  =strip(script)
  293.     gadget.i=center(name,namelen+1,' ')
  294.     i=i+1
  295.   end
  296.   call close('input')
  297.   files.dialstr.name=center(dialstr,namelen+1,' ')
  298.   gadget.i=files.dialstr.name
  299.   files.count=i
  300. return
  301.