home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / bss / pup.arc / PUPMAIN.C < prev    next >
C/C++ Source or Header  |  1987-12-11  |  5KB  |  178 lines

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