home *** CD-ROM | disk | FTP | other *** search
/ Computerworld Gratis 30 Hours of Connection / Image(2).iso / infovia / win31 / genlearn.sc_ / genlearn.sc
Text File  |  1995-08-10  |  7KB  |  283 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.         (define,junk,(receive,1000))                    <* Empty Recv Buffer *>
  46.         (delete,junk)
  47.  
  48.         <* Wait for response *>
  49.         (status,{Last Error:}(value,dmsg)(lf)
  50.             {Dialing...}(lf)
  51.             {Timeout in %d seconds}
  52.             ,(/,(phone,timeout),1000))
  53.         (define,response,(receive,(phone,timeout),CONNECT,BUSY,ERROR,
  54.             {NO CARRIER},{NO DIALTONE},{NO ANSWER}))
  55.  
  56.         (loop,{ <* Case *>
  57.             (has,response,CONNECT,{
  58.                 (define,again,done)
  59.                 (lbreak)
  60.             })
  61.             (has,response,BUSY,{
  62.                 (status,{BUSY})
  63.                 (define,query,(message,{The number you dialed is Busy. Would you like to try again?},YESNO,q,1,y,n))
  64.                 (define,again,(value,query))
  65.                 (define,dmsg,{BUSY})
  66.                 (lbreak)
  67.             })
  68.             (has,response,ERROR,{
  69.                 (status,{Modem Error})
  70.                 (message,{Modem Error, Connection Failed},OK,e)
  71.                 (lbreak)
  72.             })
  73.             (has,response,{NO CARRIER},{
  74.                 (status,{NO CARRIER})
  75.                 (define,query,(message,{Unable to connect to remote modem. Would you like to try again?},YESNO,q,1,y,n))
  76.                 (define,again,(value,query))
  77.                 (define,dmsg,{NO CARRIER})
  78.                 (lbreak)
  79.             })
  80.             (has,response,{NO DIALTONE},{
  81.                 (status,{NO DIALTONE})
  82.                 (define,query,(message,{No Dialtone. Would you like to try again?},YESNO,q,1,y,n))
  83.                 (define,again,(value,query))
  84.                 (define,dmsg,{NO DIALTONE})
  85.                 (lbreak)
  86.             })
  87.             (has,response,{NO ANSWER},{
  88.                 (status,{NO ANSWER})
  89.                 (define,query,(message,{No Answer. Would you like to try again?},YESNO,q,1,y,n))
  90.                 (define,again,(value,query))
  91.                 (define,dmsg,{NO ANSWER})
  92.                 (lbreak)
  93.             })
  94.             <* Unknown response / TIMEOUT *>
  95.             (send,(cr))
  96.             (status,{TIMEOUT})
  97.             (define,query,(message,{TIMEOUT. Would you like to try again?},YESNO,q,1,y,n))
  98.             (pause,5000)
  99.             (trac,iz2)
  100.             (define,again,(value,query))
  101.             (define,dmsg,{TIMEOUT})
  102.         },1) <* End Case *>
  103.  
  104.         <* Check for loop again *>
  105.         (==,(value,again),y,,{
  106.             (lbreak)
  107.         })
  108.     },-1)
  109.     (==,(value,again),done,,{
  110.         (sexit)
  111.     })
  112.  
  113.     (delete,again,query,response,pnum)
  114.  
  115.     (status,{Waiting for Physical Connection...}(lf)
  116.         {Timeout in %d seconds},(/,(phone,timeout),1000))
  117.     (poll,physical,open,(phone,timeout),{
  118.         (status,{Physical connection established})
  119.         (pause,1000)
  120.     },{
  121.         (wdial_message,{Physical layer not opened. Connection Failed!},OK,e)
  122.         (sexit)
  123.     })
  124. })
  125.  
  126. <********************************************>
  127. <* Wait for callback (for DEFENDER systems) *>
  128. <********************************************>
  129. (define,callback,{
  130.     (status,{Waiting for provider to hangup...}(lf)
  131.         {Timeout in %d seconds},(/,(phone,timeout),1000))
  132.     (poll,physical,closed,(phone,timeout),,{
  133.         (wdial_message,{The provider never hung up. Connection Failed!},OK,e)
  134.         (sexit)
  135.     })
  136.  
  137.     (status,{Waiting for callback...}(lf)
  138.         {Timeout in %d seconds},24000)
  139.     (define,tmp,(receive,2400000,RING))        <* Wait for RING *>
  140.     (has,tmp,RING,,{
  141.         (wdial_message,{The provider never called back. Connection Failed!},OK,e)
  142.         (sexit)
  143.     })
  144.  
  145.     (status,{Answering phone})
  146.     (send,ATA(cr))                                                    <* Answer Modem *>
  147.  
  148.     (status,{Waiting for Physical Connection...}(lf)
  149.         {Timeout in %d seconds},(/,(phone,timeout),1000))
  150.     (poll,physical,open,(phone,timeout),{
  151.         (status,{Physical connection established})
  152.         (pause,1000)
  153.     },{
  154.         (wdial_message,{Physical layer not opened. Connection Failed!},OK,e)
  155.         (sexit)
  156.     })
  157. })
  158.  
  159. (define, abort,{
  160.     (status,{Not connected})
  161.     (message, {The other side hung up. Connection Failed!})
  162.     (exit)                                                    <* exit script if no carrier        *>
  163. })
  164.  
  165. (define, did_they_hang_up?,{
  166.     (poll, physical, open, , , {
  167.         (abort)
  168.     })
  169. })
  170.  
  171. <*********************>
  172. <* Ask user for help *>
  173. <*********************>
  174. (define, response_not_recognized, {
  175.     (status,{Waiting for user input})
  176.     (define, user_data,
  177.          (prompt,(value,input_data)
  178.              {
  179. }                                 {Response not recognized!
  180. }                                 {You must either:
  181. }                                 {            o Run the `teach' mode script again
  182. }                                 {
  183. }                                 {            o Enter a response to continue connecting.
  184. }                                 {
  185. }                                 {Type 'EXIT' to abort.}
  186.     ))
  187.     (has, (value, user_data), EXIT,
  188.             { (sexit) },
  189.             { (send, (value, user_data) (cr)) })
  190. })
  191.  
  192. (define,hangup,{
  193.     (escape,cleardtr)
  194.     (poll,physical,close,2000,,{
  195.         (send,+++)
  196.         (pause,2000)
  197.         (send,ATH0(cr))
  198.         (pause,2000)
  199.     })
  200. })
  201.  
  202. <*******************************************************>
  203. <* Exit gracefully, ERROR                                         *>
  204. <*******************************************************>
  205. (define,sexit,{
  206.     (status,{Not connected})
  207.     (exit)
  208. })
  209.  
  210. <*******************************************************>
  211. <* Negotiate layers etc.                                                             *>
  212. <*******************************************************>
  213. (define,topacket,{
  214.     <* Change to packet mode *>
  215.     (changemode,packet)
  216.  
  217.     (==,(frametype),SLIP,,{
  218.         <* PPP Mode *>
  219.  
  220.         <* Open LCP Layer *>
  221.         (status,{Waiting for Link Control...}(lf)
  222.             {Timeout in %d seconds},(/,(phone,timeout),1000))
  223.         (define,stoptime,(+,(trac,xcm),(phone,timeout)))
  224.         (loop, {
  225.             (did_they_hang_up?)
  226.             (poll,lcp,open,1000,{
  227.                 (lbreak)
  228.             })
  229.             (compare,(trac,xcm),(value,stoptime),{
  230.                 (changemode,raw)
  231.                 (hangup)
  232.                 (message,{Link control not established. Connection Failed!},OK,e)
  233.                 (sexit)
  234.             })
  235.         },-1)
  236.  
  237.         <* Open IPCP Layer *>
  238.         (status,{Waiting for Network Control...}(lf)
  239.             {Timeout in %d seconds},(/,(phone,timeout),1000))
  240.         (define,stoptime,(+,(trac,xcm),(phone,timeout)))
  241.         (loop, {
  242.             (did_they_hang_up?)
  243.             (poll,ipcp,open,1000,{
  244.                 (lbreak)
  245.             })
  246.             (compare,(trac,xcm),(value,stoptime),{
  247.                 (changemode,raw)
  248.                 (hangup)
  249.                 (message,{Network control not established. Connection Failed!},OK,e)
  250.                 (sexit)
  251.             })
  252.         },-1)
  253.     })
  254.  
  255.     (status,{Connected})
  256. })
  257.  
  258. <********************************************************>
  259. <* Check if script can run over this SLANG interpretter *>
  260. <********************************************************>
  261. <* (define,checkver,{
  262.     <* Version OK *>
  263. })*>
  264.  
  265. <* Return user's password or ask for it *>
  266. (define,pword,{
  267.     (==,(password),,{
  268.         (password,(prompt, {Please enter your password:}, *))
  269.     })
  270.     (password)
  271. })
  272.  
  273. <* Return user's userid or ask for it *>
  274. (define,uname,{
  275.     (==,(username),,{
  276.         (username,(prompt, {Please enter your username:}))
  277.     })
  278.     (username)
  279. })
  280.  
  281. <***    END Genlearn Common Macros    ***>
  282. <*----------------------------------*>
  283.