home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / modemcap / mdial.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-31  |  1.3 KB  |  64 lines

  1. #include "modemcap.h"
  2. #include <setjmp.h>
  3. #include <signal.h>
  4. #include <dial.h>
  5.  
  6. static    jmp_buf    env;        /* long jump buffer if timeout in read    */
  7. extern    int    merrno;
  8.  
  9. static    timeout ()
  10. {
  11.     longjmp  (env, 1);
  12. }
  13.  
  14. mdial (telno, fd)
  15. char    *telno;
  16. int    fd;
  17. {
  18.     char    buf[64];    /* telephone buffer if AS is false */
  19.     char    command[80];    /* dial command buffer */
  20.     int    i, j;        /* index and length of telephone number */
  21.     char    c;        /* single character for connection verification */
  22.  
  23.     if (! DI)
  24.         return (merrno = A_PROB); /* can't dial phone anyhow */
  25.  
  26.     if (! AS)        /* never used any other kind of modem */
  27.         return (merrno = A_PROB);
  28.     else            /* normal ascii character phone numbers    */
  29.         strcpy (buf, telno);
  30.  
  31.     sprintf (command, "%s%s%s%s%s", CS, DS, buf, DE, CE);
  32.     if (setjmp (env) != 0) {    
  33.         signal (SIGALRM, SIG_DFL);
  34.         return (merrno = D_HUNG);
  35.     }
  36.     signal (SIGALRM, timeout);
  37.     alarm (10);
  38.     write (fd, command, strlen (command));
  39.  
  40.     if (CO) {    /* verify connection */
  41.         if (setjmp (env) != 0) {    
  42.             signal (SIGALRM, SIG_DFL);
  43.             return (merrno = A_PROB);
  44.         }
  45.         signal (SIGALRM, timeout);
  46.         if (TT)
  47.             alarm (30);
  48.         else
  49.             alarm (30 + strlen (telno) / 2);
  50.  
  51.         for (i = 0;CO[i] != 0;) {
  52.             if (read (fd, &c, 1) != 1)
  53.                 continue;
  54.             
  55.             if (CO[i] == c)
  56.                 i++;
  57.             else
  58.                 i = 0;
  59.         }
  60.         return (0);
  61.     }
  62.     return (0);
  63. }
  64.