home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April A / Pcwk4a98.iso / Wtestowe / OnNet16 / GENLEARN.SCR < prev    next >
Text File  |  1997-02-13  |  8KB  |  301 lines

  1. <* language=slang *>
  2.  
  3.  
  4. <************************************************>
  5. <* Connect to provider, with redial/retry logic *>
  6. <************************************************>
  7. (define,connect,{
  8.     (poll,physical,open,1,{                                    <* Hangup *>
  9.         (send,(modem,hangup)(cr))
  10.         (define,junk,(receive,2000,OK))
  11.         (delete,junk)
  12.     })
  13.  
  14.     (slang_init_modem)                                            <* Init the modem *>
  15.  
  16.     (define,pnum,(phone,number))
  17.     (==,(value,pnum),,{
  18.         (define,pnum,(prompt,{Please enter the phone number to dial:}))
  19.     })
  20.     (replace,pnum,(char,41))                                <* Get rid of parentheses *>
  21.     (replace,pnum,(char,40))
  22.     (replace,pnum,{-})                                            <* Get rid of dashes *>
  23.  
  24.     (define,dmsg,{NONE})
  25.     (loop,{
  26.         (trac,iz2)
  27.         (status,{Last Error:}(value,dmsg)(lf)
  28.             {Dialing...})
  29.         (define,again,n)                                            <* Clear loop again flag *>
  30.  
  31.         <* Dial *>
  32.         (send,
  33.             (modem,dial)
  34.             (==,(phone,prefix),,,{
  35.                 (phone,prefix)
  36.                 (loop,{(modem,pause)},2)
  37.             })
  38.             (value,pnum)
  39.             (==,(phone,ext),,,{
  40.                 (loop,{(modem,pause)},2)
  41.                 (phone,ext)
  42.             })
  43.             (cr)
  44.         )       
  45.         
  46.         <* Removed the following code following *>
  47.         <* "Empty Recv Buffer" for Cinci Bell Problem *>
  48.         <* with 3COM Impact RS232-ISDN *>
  49.         <* modem. *>           
  50.                   
  51.         <* This loop slowed things up to *>
  52.         <* the point that a script generated *>
  53.         <* from genlearn (teach mode) would still *>
  54.         <* be waiting for the connect message *>
  55.         <* from the modem, never even looking *>
  56.         <* at carrier.                         *>
  57.         <* cmn at request of Mike Holland on *>
  58.         <* 6/13/96 Thursday.                *>
  59.         
  60.  
  61.         <* Empty Recv Buffer *>    
  62.         <* (define,junk,(receive,1000)) *>                
  63.         <* (delete,junk) *>
  64.  
  65.         <* Wait for response *>
  66.         (status,{Last Error:}(value,dmsg)(lf)
  67.             {Dialing...}(lf)
  68.             {Timeout in %d seconds}
  69.             ,(/,(phone,timeout),1000))
  70.         (define,response,(receive,(phone,timeout),CONNECT,BUSY,ERROR,
  71.             {NO CARRIER},{NO DIALTONE},{NO ANSWER}))
  72.  
  73.         (loop,{ <* Case *>
  74.             (has,response,CONNECT,{
  75.                 (define,again,done)
  76.                 (lbreak)
  77.             })
  78.             (has,response,BUSY,{
  79.                 (status,{BUSY})
  80.                 (define,query,(message,{The number you dialed is Busy. Would you like to try again?},YESNO,q,1,y,n))
  81.                 (define,again,(value,query))
  82.                 (define,dmsg,{BUSY})
  83.                 (lbreak)
  84.             })
  85.             (has,response,ERROR,{
  86.                 (status,{Modem Error})
  87.                 (message,{Modem Error, Connection Failed},OK,e)
  88.                 (lbreak)
  89.             })
  90.             (has,response,{NO CARRIER},{
  91.                 (status,{NO CARRIER})
  92.                 (define,query,(message,{Unable to connect to remote modem. Would you like to try again?},YESNO,q,1,y,n))
  93.                 (define,again,(value,query))
  94.                 (define,dmsg,{NO CARRIER})
  95.                 (lbreak)
  96.             })
  97.             (has,response,{NO DIALTONE},{
  98.                 (status,{NO DIALTONE})
  99.                 (define,query,(message,{No Dialtone. Would you like to try again?},YESNO,q,1,y,n))
  100.                 (define,again,(value,query))
  101.                 (define,dmsg,{NO DIALTONE})
  102.                 (lbreak)
  103.             })
  104.             (has,response,{NO ANSWER},{
  105.                 (status,{NO ANSWER})
  106.                 (define,query,(message,{No Answer. Would you like to try again?},YESNO,q,1,y,n))
  107.                 (define,again,(value,query))
  108.                 (define,dmsg,{NO ANSWER})
  109.                 (lbreak)
  110.             })
  111.             <* Unknown response / TIMEOUT *>
  112.             (send,(cr))
  113.             (status,{TIMEOUT})
  114.             (define,query,(message,{TIMEOUT. Would you like to try again?},YESNO,q,1,y,n))
  115.             (pause,5000)
  116.             (trac,iz2)
  117.             (define,again,(value,query))
  118.             (define,dmsg,{TIMEOUT})
  119.         },1) <* End Case *>
  120.  
  121.         <* Check for loop again *>
  122.         (==,(value,again),y,,{
  123.             (lbreak)
  124.         })
  125.     },-1)
  126.     (==,(value,again),done,,{
  127.         (sexit)
  128.     })
  129.  
  130.     (delete,again,query,response,pnum)
  131.  
  132.     (status,{Waiting for Physical Connection...}(lf)
  133.         {Timeout in %d seconds},(/,(phone,timeout),1000))
  134.     (poll,physical,open,(phone,timeout),{
  135.         (status,{Physical connection established})
  136.         (pause,1000)
  137.     },{
  138.         (wdial_message,{Physical layer not opened. Connection Failed!},OK,e)
  139.         (sexit)
  140.     })
  141. })
  142.  
  143. <********************************************>
  144. <* Wait for callback (for DEFENDER systems) *>
  145. <********************************************>
  146. (define,callback,{
  147.     (status,{Waiting for provider to hangup...}(lf)
  148.         {Timeout in %d seconds},(/,(phone,timeout),1000))
  149.     (poll,physical,closed,(phone,timeout),,{
  150.         (wdial_message,{The provider never hung up. Connection Failed!},OK,e)
  151.         (sexit)
  152.     })
  153.  
  154.     (status,{Waiting for callback...}(lf)
  155.         {Timeout in %d seconds},24000)
  156.     (define,tmp,(receive,2400000,RING))        <* Wait for RING *>
  157.     (has,tmp,RING,,{
  158.         (wdial_message,{The provider never called back. Connection Failed!},OK,e)
  159.         (sexit)
  160.     })
  161.  
  162.     (status,{Answering phone})
  163.     (send,ATA(cr))                                                    <* Answer Modem *>
  164.  
  165.     (status,{Waiting for Physical Connection...}(lf)
  166.         {Timeout in %d seconds},(/,(phone,timeout),1000))
  167.     (poll,physical,open,(phone,timeout),{
  168.         (status,{Physical connection established})
  169.         (pause,1000)
  170.     },{
  171.         (wdial_message,{Physical layer not opened. Connection Failed!},OK,e)
  172.         (sexit)
  173.     })
  174. })
  175.  
  176. (define, abort,{
  177.     (status,{Not connected})
  178.     (message, {The other side hung up. Connection Failed!})
  179.     (exit)                                                    <* exit script if no carrier        *>
  180. })
  181.  
  182. (define, did_they_hang_up?,{
  183.     (poll, physical, open, , , {
  184.         (abort)
  185.     })
  186. })
  187.  
  188. <*********************>
  189. <* Ask user for help *>
  190. <*********************>
  191. (define, response_not_recognized, {
  192.     (status,{Waiting for user input})
  193.     (define, user_data,
  194.          (prompt,(value,input_data)
  195.              {
  196. }                                 {Response not recognized!
  197. }                                 {You must either:
  198. }                                 {            o Run the `teach' mode script again
  199. }                                 {
  200. }                                 {            o Enter a response to continue connecting.
  201. }                                 {
  202. }                                 {Type 'EXIT' to abort.}
  203.     ))
  204.     (has, (value, user_data), EXIT,
  205.             { (sexit) },
  206.             { (send, (value, user_data) (cr)) })
  207. })
  208.  
  209. (define,hangup,{
  210.     (changemode, raw)
  211.     (escape,cleardtr)
  212.     (poll,physical,close,2000,,{
  213.         (send,+++)
  214.         (pause,2000)
  215.         (send,ATH0(cr))
  216.         (pause,2000)
  217.     })
  218. })
  219.  
  220. <*******************************************************>
  221. <* Exit gracefully, ERROR                                         *>
  222. <*******************************************************>
  223. (define,sexit,{
  224.     (status,{Not connected})
  225.     (exit)
  226. })
  227.  
  228. <*******************************************************>
  229. <* Negotiate layers etc.                                                             *>
  230. <*******************************************************>
  231. (define,topacket,{
  232.     <* Change to packet mode *>
  233.     (changemode,packet)
  234.  
  235.     (==,(frametype),SLIP,,{
  236.         <* PPP Mode *>
  237.  
  238.         <* Open LCP Layer *>
  239.         (status,{Waiting for Link Control...}(lf)
  240.             {Timeout in %d seconds},(/,(phone,timeout),1000))
  241.         (define,stoptime,(+,(trac,xcm),(phone,timeout)))
  242.         (loop, {
  243.             (did_they_hang_up?)
  244.             (poll,lcp,open,1000,{
  245.                 (lbreak)
  246.             })
  247.             (compare,(trac,xcm),(value,stoptime),{
  248.                 (changemode,raw)
  249.                 (hangup)
  250.                 (message,{Link control not established. Connection Failed!},OK,e)
  251.                 (sexit)
  252.             })
  253.         },-1)
  254.  
  255.         <* Open IPCP Layer *>
  256.         (status,{Waiting for Network Control...}(lf)
  257.             {Timeout in %d seconds},(/,(phone,timeout),1000))
  258.         (define,stoptime,(+,(trac,xcm),(phone,timeout)))
  259.         (loop, {
  260.             (did_they_hang_up?)
  261.             (poll,ipcp,open,1000,{
  262.                 (lbreak)
  263.             })
  264.             (compare,(trac,xcm),(value,stoptime),{
  265.                 (changemode,raw)
  266.                 (hangup)
  267.                 (message,{Network control not established. Connection Failed!},OK,e)
  268.                 (sexit)
  269.             })
  270.         },-1)
  271.     })
  272.  
  273.     (status,{Connected})
  274. })
  275.  
  276. <********************************************************>
  277. <* Check if script can run over this SLANG interpretter *>
  278. <********************************************************>
  279. <* (define,checkver,{
  280.     <* Version OK *>
  281. })*>
  282.  
  283. <* Return user's password or ask for it *>
  284. (define,pword,{
  285.     (==,(password),,{
  286.         (password,(prompt, {Please enter your password:}, *))
  287.     })
  288.     (password)
  289. })
  290.  
  291. <* Return user's userid or ask for it *>
  292. (define,uname,{
  293.     (==,(username),,{
  294.         (username,(prompt, {Please enter your username:}))
  295.     })
  296.     (username)
  297. })
  298.  
  299. <***    END Genlearn Common Macros    ***>
  300. <*----------------------------------*>
  301.