home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 331.lha / select / select.vlt < prev    next >
Encoding:
Text File  |  1990-01-07  |  8.9 KB  |  221 lines

  1. /* select.vlt - Warren Block  05-Jan-90.  Based on:                           */
  2. /* Dial_Select.vlt - display a list of numbers to dial for mouse selection    */
  3. /*                 - written by Glenn M. Lewis - Caltech - 12/12/89           */
  4. /*                 - based upon an ARexx script in Amazing Computing V4.12    */
  5. /*                                                                            */
  6. /* Do what you want with this code.                                           */
  7. /* I shall not be held responsible for any use or misuse of this code.        */
  8. /* Since parts of this code were derived from the Amazing Computing article,  */
  9. /* here is the gratuitous notice:                                             */
  10. /*                                                                            */
  11. /* copyright 1989 Richard Lee Stockton and Gramma Software.                   */
  12. /* This code is freely distributable as long as this copyright                */
  13. /* notice remains, unchanged, at the start of the code.  Thank you.           */
  14. /*                                                                            */
  15. /* You are welcome.                                                           */
  16. /*                  -- Glenn                                                  */
  17. /*                                                                            */
  18. /* Completely reworked by Warren Block, Dec 1989 and Jan 1990:                */
  19. /*   * Multiple columns!  And the code is bright enough to figure this out    */
  20. /*     automatically!  It's nifty!  It's magic!  It's...well, it's free.      */
  21. /*   * Automatically adjusts to size of VLT window--no hard-coded sizes       */
  22. /*   * Accepts BBS names, numbers, baud rates, and scripts in TFL-like format */
  23. /*   * Improved phone file parsing                                            */
  24. /*   * Lots of drastically changed code (for the better, hopefully)           */
  25. /*   * Added "Redial Last" as the last gadget                                 */
  26. /*   * Changed hard-coded values to easily-changed configuration constants    */
  27. /*   * Added support for opening the window on a custom screen or Workbench   */
  28.  
  29. /* Make sure necessary ARP library is loaded */
  30. if ~show('l', "rexxarplib.library") THEN
  31.   call addlib("rexxarplib.library", 0, -30, 0)
  32.  
  33. address VLT
  34.  
  35. dialcmd   = 'ATDT'         /* Standard Hayes-type tone dial command.  */
  36. redialcmd = 'AT*RD9'       /* Redial command for my Codex 2233 modem. */
  37. shellname = 'NewCLI'       /* This could be NewShell or whatever.     */
  38. numfile   = 'S:VLT.Phone'  /* Phone numbers file.                     */
  39. csi       = '1B'x || '['
  40.  
  41. vltwidth  = ScreenCols("VLT")    /* Find size of VLT screen. */
  42. vltheight = ScreenRows("VLT")
  43. screenname = "VLT"
  44. if vltwidth == -1 then do        /* If width was -1, it was */
  45.   vltwidth  = ScreenCols()       /* a Workbench window.     */
  46.   vltheight = ScreenRows()
  47.   screenname = ""
  48. end
  49.  
  50. /*
  51. q = Setenv(SystemPassWord,"AMIGA")      /* Need for async script startup */
  52. */
  53.  
  54. call loadnumbers(numfile)
  55.  
  56. longest = 19                /* TFL format--19 chars for name */
  57.  
  58. /* Decide on number of columns for window.  Try adding more entries to */
  59. /* to numfile to see this stuff at work.  It auto-sizes the window to  */
  60. /* fit as well as possible into the right side of the current VLT window. */
  61. columns = vltheight % (14*(files.0+1))
  62. if 14*(files.0+2) > vltheight then
  63.   if 14*(files.0+1) // vltheight ~= 0 then columns = columns + 1
  64. gadspercolumn = (files.0+1) % columns
  65. if (files.0+1)//columns ~= 0 then gadspercolumn = gadspercolumn + 1
  66. gadspercolumn = min((vltheight - 14) % 14, gadspercolumn)
  67.  
  68. w.title    = "Phone Numbers"
  69. w.width    = min(15*(columns+1)+longest*8*columns, vltwidth)
  70. w.height   = min(16+14*gadspercolumn, vltheight)
  71. w.topedge  = (vltheight-w.height)/2
  72. w.leftedge = (640-w.width)*.9
  73. w.idcmp    = 'CLOSEWINDOW+GADGETUP'
  74. w.flags    = 'WINDOWCLOSE+WINDOWDRAG+BACKFILL+ACTIVATE'
  75.  
  76. /* Setup FAVorites Host */
  77. /* First, write a 2-line temporary file to t: which the 'newcli' */
  78. /* or 'newshell' commands can use as a startup script.           */
  79.  
  80. call open(f,"t:host.scp","W")
  81. if screenname == "VLT" then
  82.   call writeln(f, "rx 'Call CreateHost(FAVHOST,FAVPORT,VLT)'")
  83. else
  84.   call writeln(f, "rx 'Call CreateHost(FAVHOST,FAVPORT,)'")
  85. call writeln(f, "EndCLI")
  86. call close(f)
  87. if screenname == "VLT" then
  88.   address command shellname '"CON:555/175/85/20//" FROM "t:host.scp"'
  89. else
  90.   address command shellname '"CON:500/175/85/20//" FROM "t:host.scp"'
  91.  
  92. /* Delay until the HOST had opened its port. */
  93.  
  94. do 500 while ~SHOW('Ports','FAVHOST') /* Wait up to 10 seconds for port */
  95.   call delay(5)                       /* Wait 1/10 of a second */
  96. end
  97.  
  98. if ~show('Ports', 'FAVHOST') THEN DO  /* Host failed to open, quit. */
  99.   say "Couldn't open port FAVHOST."
  100.   exit 10
  101. end
  102.  
  103. /* Open the HOST window */
  104. call OpenWindow(FAVHOST, w.leftedge, w.topedge, w.width, w.height, w.idcmp, w.flags, w.title)
  105.  
  106. /* Add the gadgets to the HOST window.  One gadget per filename.         */
  107. /* WB: added multiple columns.  This is uuugglly, but works pretty well. */
  108. do i=0 to files.0
  109.   call AddGadget(FAVHOST, 12+(168 * (i % gadspercolumn)),14+14*(i//gadspercolumn), i, files.i.name, files.i.name)
  110. end
  111.  
  112. /* Open our port.  This is where we RECEIVE the signals from the host port */
  113. /* In this application, FAVHOST sends messages, FAVPORT receives them. */
  114.  
  115. call OpenPort(FAVPORT)
  116.  
  117. /* MAIN LOOP */
  118.  
  119. do forever
  120.   call WaitPkt(FAVPORT)        /* Wait for messages at FAVPORT */
  121.   p = GetPkt(FAVPORT)
  122.   IF p ~== NULL() THEN        /* Don't process an empty packet */
  123.     do
  124.       thisarg = strip(GetArg(p))  /* Get the argument info from the packet */
  125.       call reply(p,0)      /* Always reply() as soon as possible */
  126.  
  127.       if thisarg == 'CLOSEWINDOW' then
  128.         do
  129.           call closewindow(FAVHOST)
  130.           address command 'delete t:host.scp'
  131.           exit 0
  132.         end
  133.  
  134.       do i=0 to files.0
  135.         if thisarg == strip(files.i.name) then break
  136.       end
  137.       if i<files.0+1 then
  138.         do
  139.           call closewindow(FAVHOST)
  140.           address command 'delete t:host.scp'
  141.  
  142.           /* Clear the screen */
  143.           'emit "' || csi || 'H' || csi || 'J'
  144.  
  145.           /* I don't even want to know why I have to do this... */
  146.           if files.i.baud < 2400 then
  147.             'bau ' || files.i.baud
  148.           else
  149.             'baud ' || files.i.baud
  150.  
  151.           call delay(20)
  152.  
  153.           if thisarg == "Redial Last" then
  154.             do
  155.               'emit "Redialing Last Number *X0D*N"'
  156.               "rawsend " redialcmd
  157.               "send ''*X0D"
  158.             end
  159.           else
  160.             do
  161.               'send "Dialing:' thisarg '(' || files.i.baud 'baud) *X0D*N"'
  162.               call delay(50)
  163.               'send "' || dialcmd files.i.number '*X0D"'
  164.               /* code to execute scripts: currently doesn't work */
  165.               /* due to problems with VLT's scripting commands.  */
  166.               /*
  167.               if length(files.i.script)>0 & exists(files.i.script) then
  168.                 do
  169.                   'emit "*R*NStarting script..."'
  170.                   call delay(20)
  171.                   outstr = '"' || csi || '?91hAMIGA~@' || files.i.script || csi || '?91l' || '"'
  172.                   "emit" outstr
  173.                   'emit "*R*N"'
  174.                 end
  175.               */
  176.             end
  177.           exit 0
  178.         end
  179.     end
  180. end
  181.  
  182. /* WB: The file format used is the same as that used by The Final    */
  183. /* List.  I think so, anyway, since I used to use GT.Term a lot and  */
  184. /* this format is the same.  Lines beginning with a vertical bar are */
  185. /* ignored, so you can add comments.  Here is a sample record:       */
  186. /*                                                                   */
  187. /* |    BBS Name     |  Phone Number   |Baud| Script                 */
  188. /* Wonkity World     1 (605) 342-1632  2400 REXX:DialWonkity.scp     */
  189. /*                                                                   */
  190. /* Don't use tabs.                                                   */
  191. /* This file should be saved as "VLT.Phone" in the S: directory.     */
  192. /* If you already have a "GT.Phone" file (or something in the same   */
  193. /* format), you should be able to just rename it.  Entries following */
  194. /* the baud rate on the same line are ignored, but may be used later */
  195. /* for scripts and such.                                             */
  196.  
  197. loadnumbers:
  198.   parse arg filename
  199.  
  200.   if ~Open('input', filename, 'Read') then do
  201.     "message ''Can not open file:" filename "for input."
  202.     exit 0
  203.   end
  204.   i = 0
  205.   do while ~eof('input')
  206.     line = Readln('input')
  207.     if length(compress(line))<2 | substr(line,1,1) == '|' then iterate
  208.     parse var line 1 files.i.name +18 files.i.number +18 files.i.baud +5 files.i.script .
  209.     files.i.name   = center(strip(files.i.name),19,' ')
  210.     files.i.number = strip(files.i.number)
  211.     files.i.baud   = strip(files.i.baud)
  212.     files.i.script = compress(files.i.script, ' ' || '0A'x)
  213.     i = i + 1
  214.   end
  215.   call Close('input')
  216.   files.i.name   = center('Redial Last',19,' ')
  217.   files.i.number = ''
  218.   files.i.baud   = '2400'
  219.   files.0 = i
  220. return
  221.