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 / MODEMS / MODEM / MDMFND13.LBR / MDMFND13.CQ / MDMFND13.C
Text File  |  2000-06-30  |  4KB  |  189 lines

  1. /* program to auto search phone numbers for 300/1200 carrier 
  2.  * note--this program is for tek-80 members only, not for
  3.  * outside distribution. no encouragement of illegal/unethical
  4.  * activity is to be implied by this program. it is for
  5.  * entertainment use only!
  6.  * 
  7.  * written by Tom Burnett   05/16/84      ver 1.3
  8.  */
  9. #include "qstdio.h"
  10. main(argc,argv)
  11. int argc;
  12. char *argv[];
  13. {
  14.     int x,y;
  15.     int pre, start, finish, count;
  16.     char s[20];
  17.     char t[10];
  18.     fprintf(stderr,"\n\n\nModem Finder     ver 1.3  Tom Burnett 05/16/84\n\n\n");
  19.     if (argc < 4) {
  20.         fprintf(stderr,"usage A>finder [pre start end] [modemstr] [>outfile]<cr>\n");
  21.         exit(1);
  22.         }
  23.     strcpy(t, "ATE0");
  24.     for (y = 0; t[y] != '\0'; ++y) {
  25.         mdmout(t[y]);
  26.             }
  27.         mdmout(13);
  28.     delay();
  29.      if (argc == 5) {
  30.         strcpy(s, argv[4]);
  31.         for(x = 0; s[x] != '\0'; ++x) {
  32.         mdmout(s[x]);
  33.             }
  34.         mdmout(13);
  35.         delay();
  36.         }
  37.     pre = atoi(argv[1]);
  38.     start = atoi(argv[2]);
  39.     finish = atoi(argv[3]);
  40.     if (start > 9999 || finish > 9999) {
  41.         fprintf(stderr,"\n\ninvalid starting and/or ending number!!\n");
  42.         fprintf(stderr,"\n\naborting.....\n\n\n");
  43.         exit(1);
  44.         }
  45.     fprintf(stderr,"starting numbers are....begin %s-%s\n",argv[1],argv[2]);
  46.     fprintf(stderr,"                        end   %s-%s\n",argv[1],argv[3]);
  47.     fprintf(stderr,"\n\n\n");
  48.     count = start;
  49.     while (count != (finish + 1)) {
  50.     dial(pre,count);
  51.     delay();
  52.     ++count;
  53.         }
  54. }
  55. /* function to dial number on hayes smartmodem */
  56. dial(pre,num)
  57. int pre;
  58. int num;
  59. {
  60.     char s[20];
  61.     char s1[10];
  62.     char s2[10];
  63.     int i,x,y;
  64.     x = 13;
  65.     strcpy(s, "ATDP ");
  66.     itob(pre, s1, 10);
  67.     strcat(s, s1);
  68.     itob(num, s2, 10);
  69.         if (strlen(s2) == 1) strcat(s, "000");
  70.         if (strlen(s2) == 2) strcat(s, "00");
  71.         if (strlen(s2) == 3) strcat(s, "0");
  72.      strcat(s, s2);
  73.     fprintf(stderr,"now trying...%s%c",s,x);
  74.     for (i = 0; s[i] != '\0'; ++i) {
  75.     mdmout(s[i]);
  76.         }
  77.     mdmout(13);
  78.     y = chkcar();
  79.     if (y) {
  80.         printf("carrier found on --> %s <--\n",s);
  81.         fprintf(stderr,"carrier found on --> %s <--\n",s);
  82.         hngup();
  83.         }
  84. }
  85. /* function to output char to modem--note lobo max-80 specific */
  86. /* uses port a */
  87. mdmout(c)
  88. char c;
  89. {
  90.     unsigned dat;
  91.     int x;
  92.     dat = 0xF7E4;
  93. loop:    x = peek(dat + 1);
  94.     if ((x & 0x04) == '\0') {
  95.     goto loop;
  96.         }
  97.     poke(dat, c);
  98. }
  99. /* function to check for carrier detect after call returns 1 if yes */
  100. chkcar()
  101. {
  102.     char a;
  103.     int x,y;
  104.     x = 0;
  105.     y = 0;
  106.     delay();
  107. loop:    a = mdmstb();
  108.     if (a == 'N') return(0);
  109.     if (a == 'C') return(1);
  110.     if (checkq()) {
  111.             fprintf(stderr,"\n\naborting......\n\n\n");
  112.             exit(0);
  113.             }
  114.     ++x;
  115.     if (x > 32000) {
  116.         x = 0;
  117.         ++y;
  118.         if (y > 60) {
  119.             printf("modem hung.....attempting to hang up..\n\n");
  120.             fprintf(stderr,"modem hung..attempting to hang up..\n\n");
  121.             return(0);
  122.             }
  123.         }
  124.     goto loop;
  125. }
  126. /* function to check status of uart returns char with no loop */
  127. /* ie \0 if no char ready, char if one is available           */
  128. mdmstb()
  129. {
  130.     unsigned dat;
  131.     dat = 0xF7E4;
  132.     return(peek(dat));
  133. }
  134. /* function to delay approx 2 secs */
  135. /* also checks for q or Q          */
  136. delay()
  137. {
  138.     int x,y;
  139.     if (checkq()) {
  140.         fprintf(stderr,"\n\naborting.......\n\n\n");
  141.         exit(0);
  142.         }
  143.     for (x = 0; x != -1; ++x) ;
  144. }
  145. /* function to hang up smartmodem after car det */
  146. hngup()
  147. {
  148.     int i,j,x,y;
  149.     char z[10];
  150.     char s[10];
  151.     strcpy(s, "ATH");
  152.     strcpy(z, "+++");
  153. loop:    delay();
  154.     delay();
  155.     delay();
  156.     for (x = 0; z[x] != '\0'; ++x) {
  157.         mdmout(z[x]);
  158.             }
  159.     delay();
  160.     for (y = 0; s[y] != '\0'; ++y) {
  161.         mdmout(s[y]);
  162.         }
  163.     mdmout(13);
  164.     i = 0;
  165.     for (;;) {
  166.     j = mdmstb();
  167.     if (j == 'O') {
  168.             fprintf(stderr,"disconnect successful\n");
  169.             break;
  170.             }
  171.         ++i;
  172.         if (i > 10000) {
  173.         fprintf(stderr,"no disconnect..will try again\n");
  174.         goto loop;
  175.         }
  176.     }
  177.     delay();
  178. }
  179. /* function to check for q or Q to abort -- returns 1 if true */
  180. checkq()
  181. {
  182.     int x;
  183.     x = getkey();
  184.     if (x == 'q' || x == 'Q') {
  185.         return(1);
  186.         }
  187.     else return(0);
  188. }
  189.