home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 427.lha / VLTautodialer_v.7BETA / autodial.vlt < prev    next >
Text File  |  1990-10-07  |  8KB  |  253 lines

  1. /* Autodialer for VLT */
  2. /* Beta v .7. Don't say I didn't warn you.... */
  3. /* This program is copyright 1990, Dan Sugalski. */
  4. /* The archive it appears in may be freely redistributed */
  5. /* provided that it remains intact */
  6. address vlt
  7.  
  8. if ~show(l,"rexxsupport.library")
  9.     then call addlib('rexxsupport.library',0,-30,0)
  10. if ~show(l,'rexxarplib.library')
  11.     then call addlib('rexxarplib.library',0,-30,0)
  12.  
  13. if ~open(phone,'S:VLTPhone',r)
  14.     then do
  15.     message "{Can't open phone file!}"
  16.     exit 1
  17.     end
  18. do i=1 while ~eof(phone)
  19.     line = readln(phone)
  20.     parse var line phone.name.i phone.number.i phone.macro.i phone.parity.i phone.strip.i
  21.     end
  22.  
  23. call close(phone)
  24.  
  25. screen = 'VLT'
  26. height=ScreenRows(VLT)                              /* get screen size for VLT */
  27. width =ScreenCols(VLT)                              /* screen.                 */
  28.  
  29. if height = -1 then do                              /* a -1 means that the screen   */
  30.     height = ScreenRows()                           /* we tried to get data for     */
  31.     width  = ScreenCols()                           /* doesn't exist. So we get     */
  32.     screen = ''                                     /* workbench values             */
  33.  
  34.     rx '{call createhost(DIALPORT, DIALPORT2)}'     /* open port on workbench       */
  35.     end
  36. else
  37.     rx '{call createhost(DIALPORT, DIALPORT2, VLT)}'    /* open port on VLT screen  */
  38.  
  39. call openport(dialport2)                            /* open our port    */
  40.  
  41. do j=1 to 10 while ~showlist(P,dialport)            /* wait for opening of host */
  42.     call delay(10)
  43.     end
  44.  
  45. if ~showlist(p,dialport)                            /* if no host, abort with a */
  46.     then do                                         /* message.                 */
  47.     message '{ERROR in CreateHost!}'
  48.     exit 1
  49.     end
  50.  
  51. do until phone.name.i ~= ""                 /* strip out trailing blanks        */
  52.     i = i-1
  53.     end
  54.  
  55. do j=1 to i                                             /* here we make all the names   */
  56.     if length(phone.name.j) < 15                        /* fiftee n characters long. We  */
  57.         then phone.name.j = center(phone.name.j, 15)    /* either center and pad with   */
  58.         else phone.name.j = left(phone.name.j, 15)      /* spaces or we truncate.       */
  59.     end
  60.  
  61. min = 1                     /* initial settings */
  62. max = 10
  63. if max > i then max = i
  64.  
  65.  
  66.             /* we open the window and show the first page of gadgets. */
  67. call openwindow(dialport, 10, 10, 300, 180, "CLOSEWINDOW+GADGETUP", "WINDOWCLOSE+WINDOWDRAG+WINDOWDEPTH", "VLT Autodialer")
  68. call dogadgets(min, max, i)
  69.  
  70.  
  71.         /* This loop upcoming is our major port watcher. It gets the messages   */
  72.         /* from user gadget picks and processes them.                           */
  73.  
  74.  
  75. do dummy1 = 1
  76.     do dummy2 = 1
  77.         token = getpkt(dialport2)
  78.         if token = '0000 0000'x then leave
  79.         myarg = getarg(token)
  80.         call reply(token)
  81.         select
  82.             when myarg = 'DOWN' then do             /* Change pages */
  83.                 call cleargadgets(min, max)
  84.                 max = max + 10
  85.                 if max > i then max = i
  86.                 min = max - 9
  87.                 call dogadgets(min, max, i)
  88.                 end
  89.             when myarg = 'UP' then do               /* Change Pages */
  90.                 call cleargadgets(min, max)
  91.                 min = min - 10
  92.                 if min < 1 then min = 1
  93.                 max = min + 9
  94.                 call dogadgets(min, max, i)
  95.                 end
  96.             otherwise leave dummy1
  97.             end
  98.         end
  99.     call waitpkt(dialport2)
  100. end
  101.  
  102. if myarg = 'CLOSEWINDOW' then do         /* If closewindow, must be an abort */
  103.     call closewindow(dialport)
  104.     exit 0
  105.     end
  106.  
  107.                 /* At this point we must have been given a  */
  108.                 /* phone number gadget. So we get the info  */
  109.                 /* and process it properly.                 */
  110.  
  111. call closewindow(dialport, continue)
  112.  
  113. if phone.parity.myarg ~= '' then do
  114.     parity phone.parity.myarg       /* set parity to specified */
  115.     end
  116. else do
  117.     parity '8N1'                    /* no parity specified, default to 8N1 */
  118.     end
  119.  
  120. if upper(phone.strip.myarg) = 'Y' then do
  121.     str on
  122.     end                             /* strip bit 8 on   */
  123. else do
  124.     str off                         /* strip bit eight off  */
  125.     end
  126.  
  127.  
  128. do until getpkt(dialport2)= '0000 0000'x end
  129. VLTString = 'schedule (cancel autodialer; autodialer: trap add  {CONNECT} [rx (address DIALPORT2 CONN)]; '
  130. VLTString = VLTString || 'trap add  {BUSY} [rx (Address DIALPORT2 RD)]; '
  131. VLTString = VLTString || 'trap add  {NO DIALTONE} [rx (address DIALPORT2 ND)]; '
  132. VLTString = VLTString || 'trap add  {NO CARRIER} [rx (address DIALPORT2 NC)]; '
  133. VLTString = VLTString || 'trap add  {OK} [rx (address DIALPORT2 CLOSEWINDOW)]; '
  134. VLTString = VLTString || 'trap add  {ERROR} [rx (address DIALPORT2 RD)];'
  135. VLTString = VLTString || ' pause)'
  136. Delayer = 'schedule (cancel delayer; delayer: wait 1:00; rx (address DIALPORT2 TO))'
  137.  
  138. call openwindow(DIALPORT, 220, 75, 200, 40, "CLOSEWINDOW", "WINDOWCLOSE+WINDOWDRAG", "Close to Cancel")
  139. call move(DIALPORT, 4, 30)
  140. call setApen(dialport, 1)
  141. call Text(DIALPORT, "Click on Close to cancel")
  142. call move(DIALPORT, 4, 20)
  143. call Text(DIALPORT, "Dialing "||strip(phone.name.myarg))
  144. VLTString
  145. Delayer
  146.  
  147. send '{atdt' strip(phone.number.myarg) '}'
  148.  
  149. do dummy1 = 1
  150.     do dummy2 = 1
  151.         token = getpkt(dialport2)
  152.         if token = '0000 0000'x then leave dummy2
  153.         myarg2 = getarg(token)
  154.         call reply(token)
  155.         select
  156.  
  157.             when myarg2 = 'CONN' then do
  158.                 'beep'
  159.                 if phone.macro.myarg ~= ''
  160.                     then do
  161.                     sendstring = "address rexx; call " strip(phone.macro.myarg)||"()"
  162.                     address vlt
  163.                     rx "'"sendstring"'"
  164.                     end
  165.                 'cancel autodialer'
  166.                 'cancel delayer'
  167.                 leave dummy1
  168.                 end
  169.  
  170.             when myarg2 = 'RD' then do
  171.                 call delay(100)
  172.                 send '{atdt' strip(phone.number.myarg) '}'
  173.                 'cancel delayer'
  174.                 leave dummy2
  175.                 end
  176.  
  177.             when myarg2 = 'ND' then do
  178.                 message '{No dialtone!}'
  179.                 'cancel autodialer'
  180.                 'cancel delayer'
  181.                 leave dummy1
  182.                 end
  183.  
  184.             when myarg2 = 'NC' then do
  185.                 message '{No carrier from host!}'
  186.                 'cancel autodialer'
  187.                 'cancel delayer'
  188.                 leave dummy1
  189.                 end
  190.  
  191.             when myarg2 = 'CLOSEWINDOW' then do
  192.                 message '{User abort requested}'
  193.                 'cancel autodialer'
  194.                 'cancel delayer'
  195.                 'hangup'
  196.                 leave dummy1
  197.                 end
  198.  
  199.             when myarg2 = 'TO' then do
  200.                 message '{timeout. Aborting dial attempt.}'
  201.                 'cancel autodialer'
  202.                 leave dummy1
  203.                 end
  204.  
  205.             otherwise nop
  206.  
  207.             end
  208.         end
  209.     call waitpkt(dialport2)
  210.     end
  211. call exit(dialport)
  212. exit 0
  213.  
  214.  
  215.  
  216.  
  217. /* given the starting and ending phone entry numbers, this function
  218.    puts up gadgets for them, as well as up and/or down gadgets,
  219.    if necceesary.                                                   */
  220.  
  221. dogadgets:
  222.     arg start, end, realmax
  223.     if start > 1 then  call addgadget(dialport, 200, 40, up, "PgUp", up)
  224.     if end < realmax then call addgadget(dialport,200, 120, down, "PgDn", down)
  225.     do dotemp = start to end
  226.         call addgadget(dialport, 12, 11+(15*(dotemp-start)), dotemp, phone.name.dotemp, dotemp)
  227.         end
  228.     return 1
  229.  
  230.  
  231. /* this function takes the starting and ending phone entries
  232.    and clears out the gadgets for them, as well as removing
  233.    the up and down gadgets, if they appear.                  */
  234.  
  235. cleargadgets:
  236.     arg start, end
  237.     call setAPen(dialport, 0)
  238.     if start > 1 then do
  239.         call removegadget(dialport, up)
  240.         call rectfill(dialport, 198, 39, 250, 56)
  241.         end
  242.     if end < i then do
  243.         call removegadget(dialport, down)
  244.         call rectfill(dialport, 198, 119, 250, 136)
  245.         end
  246.     do dotemp = start to end
  247.         call removegadget(dialport, dotemp)
  248.         call rectfill(dialport, 10, 10+(15*(dotemp-start)), 145, 11+11+(15*(dotemp-start)))
  249.         end
  250.     call setapen(dialport, 1)
  251.     return 1
  252.  
  253.