home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / HEATH / HMSRC20.LBR / HM4.CZ / HM4.C
Text File  |  2000-06-30  |  7KB  |  274 lines

  1. /************************** START OF MODULE 4 *******************************/
  2.  
  3. #define  C80
  4. #include "hmodem80.h"
  5.  
  6. dial()
  7. {
  8.    static char *number;      /* buffer for number to be sent to modem */
  9.    static char *result;      /* buffer for responses from modem */
  10.    static char *instr;       /* buffer for numbers entered at keyboard */
  11.    static int connect;
  12.    static int status, i, j, k, n, nocnt, action, c;
  13.    static char *p;
  14.  
  15.    if (allocerror(number = alloc(128)))
  16.       return;
  17.    if (allocerror(result = alloc(128)))
  18.       return;
  19.    if (allocerror(instr = alloc(128)))
  20.       return;
  21.    status = shownos();
  22.    putlabel("Dialing Menu:  Enter letters and/or numbers, separated by commas");
  23.    QuitFlag = connect = FALSE;
  24.    Dialing = TRUE;
  25.    printf("\nPlease enter number(s) to dial:  ");
  26.    if (j=getline(instr,80)) {
  27.       putlabel("Automatic Redial:  Press ESC to stop");
  28.       for (i=0,nocnt=1; instr[i]; i++)
  29.          if  (instr[i] == ',') {
  30.             instr[i] = 0;
  31.             nocnt++;
  32.          }
  33.       i = nocnt;
  34.       while (TRUE) {
  35.          p = instr;
  36.          nocnt = i;
  37.          while (nocnt--) {
  38.             n = -1;
  39.             strcpy(number,Modem.dialcmd);
  40.             if (*p == '+') {
  41.                strcat(number,Sprint);
  42.                p++;
  43.             }
  44.             else if (*p == '-') {
  45.                strcat(number,Mci);
  46.                p++;
  47.             }
  48.             if ((status == OK) && (j=strlen(p))==1) {
  49.                if (isalpha(n = *p)) {
  50.                   n = toupper(n) - 'A';
  51.                   setace(n);
  52.                   strcat(number,Book[n].number);    
  53.                   strcat(number,Modem.dialsuffix);
  54.                   mstrout(number,FALSE);
  55.                   printf("\nDialing %s...",Book[n].name);
  56.                }
  57.                else {
  58.                   printf("\nInvalid Number\n");
  59.                   goto abort;
  60.                }
  61.             }     
  62.             else {
  63.                strcat(number,p);
  64.                strcat(number,Modem.dialsuffix);
  65.                mstrout(number,FALSE);
  66.                printf("\nDialing %s...",p);
  67.             }
  68.             while (readline(10) != TIMEOUT);    /*flush modem input*/
  69.             do {
  70.                action = readstr(result,Modem.timeout);
  71.                if (action == TIMEOUT)
  72.                   goto abort;
  73.                printf("%s\n",result);
  74.             } while (!(c=isin(result,Modem.connect))
  75.                   && !isin(result,Modem.busy1)
  76.                   && !isin(result,Modem.busy2)
  77.                   && !isin(result,Modem.busy3)
  78.                   && !isin(result,Modem.busy4));
  79.  
  80.             if (c) {                   /* got connect string */
  81.                printf("\007\nOn Line to %s\n",n >= 0 ? Book[n].name : p);
  82.                if (n >= 0)
  83.                   FDx = !Book[n].echo;
  84.                connect = TRUE;
  85.                goto done;
  86.             }
  87.             mcharout(CR);
  88.             while (readline(10) != TIMEOUT);    /* wait for modem */
  89.             p += j+1;
  90.          }
  91.          if (kbwait(Modem.pause))
  92.             goto abort;
  93.       }
  94.    }
  95.  
  96. abort:
  97.    printf("Call Aborted.\n");
  98.    mcharout(CR);
  99.    readstr(result,1);      /*gobble last result*/
  100.    resetace();
  101.  
  102. done:
  103.    flush();
  104.    if (Book != -1)
  105.       free(Book);
  106.    free(instr);
  107.    free(result);
  108.    free(number);
  109.    Dialing = FALSE;
  110.    return connect;
  111. }
  112.  
  113. shownos()
  114. {
  115.    static int i, j, status;
  116.  
  117.    cls();
  118.    if ((status=loadnos()) == OK) {
  119.       printf("\033p         NAME                NUMBER          B   P D S E\033q");
  120.       for (i=0,j=1; i<20; i++,j++) {
  121.          locate(i+1,0);
  122.          printf("%c - %s",i+'A',Book[i].name);
  123.          locate(i+1,41-strlen(Book[i].number));
  124.          printf(Book[i].number);
  125.          locate(i+1,44);
  126.          printf("%4d %c %d %d %c\n",Baudtable[Book[i].pbaudindex],Book[i].pparity,
  127.             Book[i].pdatabits,Book[i].pstopbits,Book[i].echo?'H':'F');
  128.       }
  129.    }
  130.    return status;
  131. }
  132.  
  133. loadnos()
  134. {
  135.    static unsigned amount, loc;
  136.    static int fd, i, result;
  137.  
  138.    fd = 0;
  139.    result = NERROR;
  140.    amount = 128 * roundup(20 * sizeof(struct phonebook));
  141.    Book = alloc(amount);
  142.    if (!allocerror(Book)) {
  143.       strcpy(Pathname,Phonefile);
  144.       addrive(Pathname,Invokdrive);
  145.       if (!openerror((fd = fopen(Pathname,"rb")))) {
  146.          read(fd, Book, amount);
  147.          result = OK;
  148.          fclose(fd);
  149.       }
  150.    }
  151.    return result;
  152. }      
  153.  
  154. readstr(p,t)
  155. char *p;
  156. int t;
  157. {
  158.    static int c;
  159.  
  160.    t *= 10;                /* convert to tenths */
  161.    flush();
  162.    while (((c=readline(t)) != CR) && (c != TIMEOUT)) {
  163.       if (c != LF)
  164.          *p++ = c;
  165.    }
  166.    *p = 0;
  167.    return c;
  168. }
  169.  
  170. isin(received,expected)
  171. char *received, *expected;
  172. {  
  173.    return (index(received,expected) != -1);
  174. }
  175.  
  176. diskstuff()
  177. {
  178.    static int c;
  179.  
  180.    for (;;) {
  181.       cls();
  182.       printf("\t\tA - Change disk in default drive\n");
  183.       printf("\t\tB - Change default drive (currently %c:)\n",Currdrive);
  184.       printf("\t\tC - Delete file on default drive\n");
  185.       printf("\t\tZ - Exit\n");
  186.       printf("\n\tPlease enter choice:  ");
  187.       putlabel("Disk Operations Menu");
  188.       flush();
  189.       c = toupper(getchar());
  190.       switch (c) {
  191.  
  192.          case 'A':
  193.             printf("\nChange disk in %c: then press any key...",Currdrive);
  194.             flush();
  195.             getchar();
  196.             reset(Currdrive);
  197.             break;
  198.  
  199.          case 'B':
  200.             printf("\nPlease enter the new default drive:  ");
  201.             flush();
  202.             reset(getchar());
  203.             break;
  204.  
  205.          case 'C':
  206.             directory();
  207.             printf("\nDelete what file?  ");
  208.             if (!getline(Pathname,16))
  209.                break;
  210.             printf("\nAre you sure? (Y/N) <N>  ");
  211.             flush();
  212.             c = toupper(getchar());
  213.             if (c == 'Y')
  214.                unlink(Pathname);
  215.             break;
  216.       
  217.           default:
  218.             cls();
  219.             return;
  220.             break;
  221.       }
  222.    }
  223. }
  224.  
  225. #define     UPARROW     'x'
  226. #define     DNARROW     'r'
  227.  
  228. help()
  229. {
  230.    static int fd, function, c, i;
  231.    static int pagend[10], k, kbdata;
  232.  
  233.    strcpy(Pathname,"HMODEM.HLP");
  234.    addrive(Pathname,Invokdrive);
  235.    fd = fopen(Pathname,"rb");
  236.    if (openerror(fd,Pathname))
  237.       return;
  238.    cls();
  239.    putlabel("Help Screens:  Use Up-Arrow, Down-Arrow, ESC to exit");
  240.    c = k = pagend[0] = 0;
  241.  
  242. newpage:
  243.    for (i=0; i<22 && (c=getc(fd)) != CTRLZ; ) {
  244.       putchar(c);
  245.       if (c == CR)
  246.          ++i;
  247.    }
  248. again:
  249.    kbdata = getchar();
  250.    if ((function = getfunction(kbdata)) == UPARROW) {
  251.       if (k > 0)
  252.          k--;
  253.       seek(fd,pagend[k],0);
  254.       cls();
  255.       goto newpage;
  256.    }
  257.    else if (function == DNARROW) {
  258.       if (k < 3) {
  259.          pagend[++k] = ftell(fd);
  260.          goto newpage;
  261.       }
  262.       else
  263.          goto again;
  264.    }
  265.    else if (kbdata == ESC) {
  266.       fclose(fd);
  267.       cls();
  268.       return;
  269.    }
  270.    goto again;
  271. }
  272.  
  273. /************************* end of module 4 **********************************/
  274.