home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / fido / pup_v2b.zip / PUPMAIN.C < prev    next >
C/C++ Source or Header  |  1987-12-28  |  5KB  |  183 lines

  1. #include <puppy.h>
  2. #include <ascii.h>
  3. #include <driver.h>        /* MSDOS */
  4.  
  5. struct _pup pup;        /* main system file */
  6. struct _clr caller;        /* current caller logged in */
  7.  
  8. struct _msg *msg;    /* msg base index */
  9.  
  10. FLAG test;        /* 1 == test mode, (no modem) */
  11. FLAG localin;        /* 1 == simultaneous keyboards */
  12. BYTE lmtstate;        /* 0 - 2, caller time limit warning state */
  13. int limit;        /* time limit in force, or 0 for no limit */
  14. int klimit;        /* download limit in force */
  15.  
  16. /* Local system shit */
  17.  
  18. FLAG abort;        /* True if ^C typed. */
  19. FLAG doscode;        /* DOS error code */
  20. char column;        /* column number, */
  21. char line;
  22. char months[13][4] = {    /* table of month names */
  23.     "Eh?","Jan","Feb","Mar","Apr","May","Jun","Jul",
  24.     "Aug","Sep","Oct","Nov","Dec"
  25. };
  26.  
  27. /* XMODEM protocol module */
  28.  
  29. int totl_files;        /* how many failed, */
  30. int totl_errors;    /* error count, soft errors incl */
  31. int totl_blocks;    /* number blocks sent, */
  32. char crcmode;        /* 1 if CRC mode, */
  33. char filemode;        /* transfer type; XMODEM, MODEM7, TELINK */
  34.  
  35. /* Modem variables */
  36.  
  37. WORD linkrate;        /* baud rate to/from modem */
  38. WORD datarate;        /* baud rate to/from caller */
  39. FLAG cd_flag;        /* true == ignore CD line */
  40.  
  41. extern WORD cd_bit;    /* MSDOS driver: bit to test for Carrier Detect, */
  42. extern WORD iodev;    /* MSDOS driver: serial channel number */    
  43.  
  44. /* Local text buffer */
  45.  
  46. char *text;        /* work buffer */
  47. unsigned textsize;    /* and its size */
  48.  
  49. extern long sizmem();    /* MSDOS */
  50. extern char *getmem();    /* MSDOS */
  51.  
  52. /*************************************************************
  53.  
  54.     These are DUMMIES so I can leave out the
  55.     FidoNet code until it is working. 
  56.  
  57. **************************************************************/
  58.  
  59. get_pkt() {}        /* dummy */
  60. put_pkt() {}        /* dummy */
  61.  
  62.  
  63.  
  64. main(argc,argv)
  65. int argc;
  66. char **argv;
  67. {
  68. int i,n;
  69. FLAG evtmsg;        /* 1 == we announced upcoming event */
  70. FLAG rdymsg;        /* 1 == we announced "waiting ... " */
  71. FLAG mdmmsg;        /* 1 == we initialized the modem */
  72.  
  73.     printf("Pup bulletin board, version 2a, 23 Dec 87\r\n");
  74.     printf("Tom Jennings, 164 Shipley\r\n");
  75.     printf("San Francisco CA 94107 USA\r\n");
  76.     printf("(k) all rights reversed\r\n");
  77.     test= 0;                /* not test mode */
  78.  
  79.     i= open("puppy.sys",0);            /* load the system file */
  80.     if (i == -1) {
  81.         printf("Can't find PUPPY.SYS\r\n");
  82.         exit(1);
  83.     }
  84.     read(i,&pup,sizeof(struct _pup));    /* read it in, */
  85.     close(i);
  86.  
  87.     iodev= pup.iodev;            /* MSDOS stuff the drivers */
  88.     cd_bit= pup.cd_bit;            /* MSDOS with setup info */
  89.     allmem();                /* MSDOS get all available memory */
  90.     textsize= sizmem();            /* MSDOS how much mem we have */
  91.     text= getmem(textsize);            /* MSDOS get it all, */
  92.  
  93.     i= pup.messages * sizeof(struct _msg);
  94.     if (i > textsize) {            /* allocate room for msg index */
  95.         printf("You have too many messages!\r\n");
  96.         exit(1);
  97.     }
  98.     msg= (struct _msg *) text;        /* ptr to message file index */
  99.     textsize -= i;                /* account for it, */
  100.     text += i;                /* advance the pointer */
  101.  
  102.     if (pup.msgsize > textsize) {        /* room for message entry */
  103.         printf("Message-size is too big!\r\n");
  104.         exit(1);
  105.     }
  106.  
  107. /* 
  108.     *************** The Big Loop. **************
  109. */
  110.     set_clk();                /* install clock */
  111.     init();                    /* start up hardware, */
  112.  
  113.     evtmsg= 0;                /* no event warning yet */
  114.     rdymsg= 0;                /* no ready message yet */
  115.     mdmmsg= 0;                /* no modem init */
  116.  
  117.     while (doscode == 0) {            /* exit-to-DOS code */
  118.  
  119.         switch (keyhit()) {        /* poll the keyboard */
  120.             case '?':
  121.                 printf("\"L\"    Login to Pup\r\n");
  122.                 printf("\"I\"    Init the modem\r\n");
  123.                 printf("^C     Return to DOS\r\n");
  124.                 rdymsg= 0;
  125.                 break;
  126.                 
  127.             case ETX: doscode= 1; break;
  128.             case 'i': case 'I':     /* Init modem */
  129.                 mdmmsg= 0;
  130.                 rdymsg= 0;
  131.                 break;
  132.  
  133.             case 'l': case 'L':    /* Local Login */
  134.                 test= 1;    /* do test mode */
  135.                 puppy();    /* take the pup for a WOC */
  136.                 test= 0;
  137.                 rdymsg= 0;
  138.                 break;
  139.         }
  140.         if (doscode) break;
  141.  
  142.         i= til_sched('?',0,0);        /* ask the scheduler whats up */
  143.         if (i != -1) {            /* if an event NOW */
  144.             if (pup.sched[i].tag == 'X') {
  145.                 doscode= pup.sched[i].len;
  146.                 markevt(i);    /* flag it as run */
  147.                 printf("Pup says: \"Event #%d X ERRORLEVEL %d\"\r\n",i,doscode);
  148.                 break;        /* terminate Big Loop */
  149.             }
  150.             printf("Pup says: \"FidoNet %c\"\r\n",pup.sched[i].tag);
  151.             evtmsg= 0;        /* need messages */
  152.             rdymsg= 0;
  153.             mdmmsg= 0;
  154.             continue;        /* check for more events, etc */
  155.         }
  156.         i= til_sched('?',10,0);        /* ask the scheduler whats up */
  157.         if (i != -1) {            /* if an event within 10 minutes */
  158.             if (! evtmsg) printf("Pup says: \"Event within 10 minutes\"\r\n");
  159.             evtmsg= 1;
  160.             continue;        /* no modem/caller stuff */
  161.         }
  162.         if (! mdmmsg) {
  163.             mdmmsg= 1;
  164.             rdymsg= 0;
  165.             init_modem(pup.mdmstr);    /* wake up the modem */
  166.         }
  167.         if (! rdymsg) printf("Pup says: \"Waiting for something to do (?=help)\"\r\n");
  168.         rdymsg= 1;
  169.  
  170. /* OK, no events etc. If the phone rings, answer it. If TSYNC is received 
  171. during the signon process, it drops into Incoming Mail. */
  172.  
  173.         if (answer() > 0) {        /* if an incoming call, */
  174.             puppy();
  175.             rdymsg= 0;
  176.         }
  177.     }
  178.  
  179.     reset_clk();                /* turn off clock, */
  180.     if (! test) uninit();            /* always ints off, etc */
  181.     exit(doscode);                /* back to DOS */
  182. }
  183.