home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol150 / 211confg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1984-04-29  |  10.9 KB  |  328 lines

  1. /************************************************************************/
  2. /*                confg.c                 */
  3. /*    configuration program for Citadel bulletin board system.    */
  4. /************************************************************************/
  5. #include "b:210ctdl.h"
  6. /************************************************************************/
  7. /*                History                 */
  8. /*                                    */
  9. /* 82Nov20 CrT    Created.                        */
  10. /************************************************************************/
  11.  
  12. /************************************************************************/
  13. /*                Contents                */
  14. /*                                    */
  15. /*    init()            system startup initialization        */
  16. /*    main()                                */
  17. /*    wrapup()        finishes and writes ctdlTabl.sys    */
  18. /************************************************************************/
  19.  
  20. /************************************************************************/
  21. /*    init() -- master system initialization                */
  22. /************************************************************************/
  23. init()
  24. {
  25.     char     getCh(), toUpper();
  26.     unsigned codend(), endExt(), externs(), topOfMem();
  27.     char     c, *msgFile;
  28.  
  29.     echo        = BOTH;     /* echo input to console too    */
  30.     usingWCprotocol    = FALSE;
  31.  
  32.     printf("code ends ....at  %u\n", codend()  );
  33.     printf("externs start at  %u\n", externs() );
  34.     printf("externs end   at  %u\n", endext()  );
  35.     printf("free RAM ends at  %u\n", topofmem());
  36.  
  37.     exitToCpm    = FALSE;        /* not time to quit yet!    */
  38.     sizeLTentry = sizeOf(logTab[0]);    /* just had to try that feature */
  39.     outFlag    = OUTOK;        /* not p(ausing)        */
  40.  
  41.     pullMessage = FALSE;        /* not pulling a message    */
  42.     pulledMLoc    = ERROR;        /* haven't pulled one either    */
  43.     pulledMId    = ERROR;
  44.  
  45.     debug    = FALSE;
  46.     loggedIn    = FALSE;
  47.     haveCarrier = FALSE;
  48.     termWidth    = 79;
  49.     termUpper    = FALSE;
  50.     termTab    = FALSE;
  51.  
  52.     noChat    = FALSE;
  53.  
  54.     /* shave-and-a-haircut/two bits pause pattern for ringing sysop: */
  55.     shave[0]    = 40;
  56.     shave[1]    = 20;
  57.     shave[2]    = 20;
  58.     shave[3]    = 40;
  59.     shave[4]    = 80;
  60.     shave[5]    = 40;
  61.     shave[6]    =250;
  62.  
  63.     /* initialize input character-translation table:    */
  64.     for (c=0;      by XMODEM (fixed length 128 byte records                                                                           with CRLF at;            /* pass printing chars        */
  65.     }
  66.     filter[SPECIAL]    = SPECIAL;
  67.     filter[CNTRLp]    = CNTRLp;
  68.     filter[DEL        ]    = BACKSPACE;
  69.     filter[BACKSPACE]    = BACKSPACE;
  70. /*  filter[CNTRLI   ]    = CNTRLI   ;    */
  71.     filter[XOFF     ]    = 'P'       ;
  72.     filter['\r'     ]    = NEWLINE  ;
  73.     filter[CNTRLO   ]    = 'N'       ;
  74.  
  75.     /* check for CPM 2.x */
  76.     if (!call(5, 0, 0, 12)) {
  77.     printf(" Not CPM 2.x!! Citadel's random-access won't work!\n");
  78.     exit();
  79.     }
  80.  
  81.     setSpace(homeDisk, homeUser);
  82.  
  83.     /* open message file */
  84.     msgFile    = "a:ctdlmsg.sys";
  85.     *msgFile   += msgDisk;
  86.     if ((msgfl = open(msgFile, 2)) == ERROR) {
  87.     printf(" %s not found, creating new file. \n", msgFile);
  88.     printf(" (Be sure to initialize it!)\n");
  89.     if ((msgfl = creat("ctdlmsg.sys")) == ERROR) {
  90.         printf("?can't create ctdlmsg.sys!!\n");
  91.         exit();
  92.     }
  93.     close(msgfl);    /* can't create in mode 2! */
  94.     msgfl = open("ctdlmsg.sys", 2);
  95.     }
  96.     rsrec(msgfl);    /* initialize for random io */
  97.  
  98.     /* open room file */
  99.     if ((roomfl = open("ctdlroom.sys", 2)) == ERROR) {
  100.     printf(" ctdlroom.sys not found, creating new file. \n");
  101.     printf(" (Be sure to initialize it!)\n");
  102.     if ((roomfl = creat("ctdlroom.sys")) == ERROR) {
  103.         printf("?can't create ctdlroom.sys!!\n");
  104.         exit();
  105.     }
  106.     close(roomfl);     /* can't create in mode 2! */
  107.     roomfl = open("ctdlroom.sys", 2);
  108.     }
  109.     rsrec(roomfl);    /* initialize for random io */
  110.  
  111.     /* open userlog file */
  112.     if ((logfl = open("ctdllog.sys", 2)) == ERROR) {
  113.     printf(" ctdlLog.sys not found, creating new file. \n");
  114.     printf(" (Be sure to initialize it!)\n");
  115.     if ((logfl = creat("ctdlLog.sys")) == ERROR) {
  116.         printf("?can't create ctdlLog.sys!!\n");
  117.         exit();
  118.     }
  119.     close(logfl);    /* can't create in mode 2! */
  120.     logfl = open("ctdlLog.sys", 2);
  121.     }
  122.     rsrec(logfl);    /* initialize for random io */
  123.  
  124.     printf("\n Erase and initialize log, message and/or room files?");
  125.     if (toUpper(getCh()) == 'Y') {
  126.     /* each of these has an additional go/no-go interrogation: */
  127.     zapMsgFile();
  128.     zapRoomFile();
  129.     zapLogFile();
  130.     }
  131.  
  132. }
  133.  
  134. /************************************************************************/
  135. /*    main() for confg.c                        */
  136. /************************************************************************/
  137. main() {
  138.     char *fBuf;
  139.     char *line;
  140.     char *cmd, *var, *string;
  141. /*  char fBuf[BUFSIZ];                */
  142. /*  char line[128];                */
  143. /*  char cmd[128], var[128], string[128];    */
  144.     int  arg, arg2, args;
  145.     union {
  146.     int  *pi;
  147.     char *pc;
  148.     } nextCode;     /* where to deposit next code */
  149.  
  150.     /* icky-tricky to conserve RAM: */
  151.     fBuf    = msgBuf;
  152.     line    = fBuf + BUFSIZ;
  153.     cmd     = line + 128;
  154.     var     = cmd  + 128;
  155.     string    = var  + 128;
  156.  
  157.  
  158.     if (fOpen("ctdlcnfg.sys", fBuf) == ERROR) {
  159.     printf("?Can't find ctdlCnfg.sys!\n");
  160.     exit();
  161.     }
  162.     nextCode.pc = &codeBuf[0];
  163.     while (fgets(line, fBuf)) {
  164.     if (args = sscanf(line, "%s %s %x ", cmd, var, &arg)) {
  165.         if          (strCmp(cmd, "#define" ) == SAMESTRING  &&  args==3) {
  166.         printf("#define '%s' as %x\n", var, arg);
  167.                if (strCmp(var, "MDATA"       )    == SAMESTRING) {
  168.             mData    = arg;
  169.         } else if (strCmp(var, "MEGAHZ"    )    == SAMESTRING) {
  170.             megaHz    = arg;
  171.         } else if (strCmp(var, "CRYPTSEED" )    == SAMESTRING) {
  172.             cryptSeed    = arg;
  173.         } else if (strCmp(var, "RCPM"       )    == SAMESTRING) {
  174.             rcpm    = arg;
  175.         } else if (strCmp(var, "CLOCK"       )    == SAMESTRING) {
  176.             clock    = arg;
  177.         } else if (strCmp(var, "MESSAGEK"  )    == SAMESTRING) {
  178.             maxMSector    = arg*8;
  179.         } else if (strCmp(var, "MSGDISK"   )    == SAMESTRING) {
  180.             msgDisk    = arg;
  181.         } else if (strCmp(var, "HOMEDISK"  )    == SAMESTRING) {
  182.             homeDisk    = arg;
  183.         } else if (strCmp(var, "HOMEUSER"  )    == SAMESTRING) {
  184.             homeUser    = arg;
  185.         } else if (strCmp(var, "LOGINOK"   )    == SAMESTRING) {
  186.             unlogLoginOk= arg;
  187.         } else if (strCmp(var, "ENTEROK"   )    == SAMESTRING) {
  188.             unlogEnterOk= arg;
  189.         } else if (strCmp(var, "READOK"    )    == SAMESTRING) {
  190.             unlogReadOk = arg;
  191.         } else if (strCmp(var, "ROOMOK"    )    == SAMESTRING) {
  192.             nonAideRoomOk=arg;
  193.         } else {
  194.             printf("? -- no variable '%s' known! -- ignored.\n", var);
  195.         }
  196.  
  197.         } else if (strCmp(cmd, "#start"  ) == SAMESTRING) {
  198.         printf("#start procedure '%s'\n", var);
  199.         if      (strCmp(var, "HANGUP"    ) == SAMESTRING) {
  200.             pHangUp    = nextCode.pc;
  201.         } else if (strCmp(var, "INITPORT"  ) == SAMESTRING) {
  202.             pInitPort    = nextCode.pc;
  203.         } else if (strCmp(var, "CARRDETECT") == SAMESTRING) {
  204.             pCarrDetect = nextCode.pc;
  205.         } else if (strCmp(var, "MIREADY"   ) == SAMESTRING) {
  206.             pMIReady    = nextCode.pc;
  207.         } else if (strCmp(var, "MOREADY"   ) == SAMESTRING) {
  208.             pMOReady    = nextCode.pc;
  209.         } else if (strCmp(var, "INITDATE"  ) == SAMESTRING) {
  210.             pInitDate    = nextCode.pc;
  211.         } else if (strCmp(var, "GETDAY"    ) == SAMESTRING) {
  212.             pGetDay    = nextCode.pc;
  213.         } else if (strCmp(var, "GETMONTH"  ) == SAMESTRING) {
  214.             pGetMonth    = nextCode.pc;
  215.         } else if (strCmp(var, "GETYEAR"   ) == SAMESTRING) {
  216.             pGetYear    = nextCode.pc;
  217.         } else printf("?--no procedure '%s' known!\n", var);
  218.  
  219.         } else if (strCmp(cmd, "#code"   ) == SAMESTRING) {
  220.         printf("#code '%s'\n", var);
  221.         if      (strCmp(var, "LOAD"       ) == SAMESTRING) {
  222.             *nextCode.pc++    = LOAD;
  223.             *nextCode.pi++    = arg;
  224.         } else if (strCmp(var, "ANDI"       ) == SAMESTRING) {
  225.             *nextCode.pc++    = ANDI;
  226.             *nextCode.pc++    = arg;
  227.         } else if (strCmp(var, "ORI"       ) == SAMESTRING) {
  228.             *nextCode.pc++    = ORI;
  229.             *nextCode.pc++    =arg;
  230.         } else if (strCmp(var, "XORI"       ) == SAMESTRING) {
  231.             *nextCode.pc++    = XORI;
  232.             *nextCode.pc++    = arg;
  233.         } else if (strCmp(var, "STORE"       ) == SAMESTRING) {
  234.             *nextCode.pc++    = STORE;
  235.             *nextCode.pi++    = arg;
  236.         } else if (strCmp(var, "LOADI"       ) == SAMESTRING) {
  237.             *nextCode.pc++    = LOADI;
  238.             *nextCode.pc++    = arg;
  239.         } else if (strCmp(var, "RET"       ) == SAMESTRING) {
  240.             *nextCode.pc++    = RET;
  241.         } else if (strCmp(var, "INP"       ) == SAMESTRING) {
  242.             *nextCode.pc++    = INP;
  243.             *nextCode.pc++    = arg;
  244.         } else if (strCmp(var, "OUTP"       ) == SAMESTRING) {
  245.             *nextCode.pc++    = OUTP;
  246.             *nextCode.pc++    = arg;
  247.         } else if (strCmp(var, "PAUSEI"    ) == SAMESTRING) {
  248.             *nextCode.pc++    = PAUSEI;
  249.             *nextCode.pc++    = arg;
  250.         } else if (strCmp(var, "ARRAY[]="  ) == SAMESTRING) {
  251.             *nextCode.pc++    = STOREX;
  252.             *nextCode.pc++    = arg;
  253.         } else if (strCmp(var, "ARRAY[]"   ) == SAMESTRING) {
  254.             *nextCode.pc++    = LOADX;
  255.             *nextCode.pc++    = arg;
  256.         } else if (strCmp(var, "OPR#"       ) == SAMESTRING) {
  257.             *nextCode.pc++    = OPRNUMBER;
  258.  
  259.             /* reparse to pick up string: */
  260.             sscanf(line, "%s %s \"%s\" %d %d",
  261.             cmd, var, string, &arg, &arg2
  262.             );
  263.             /* copy string into code buffer: */
  264.             strCpy(nextCode.pc, string);
  265.             while (*nextCode.pc++);    /* step over string    */
  266.             *nextCode.pc++    = arg;    /* lower limit        */
  267.             *nextCode.pc++    = arg2; /* upper limit        */
  268.  
  269.         } else if (strCmp(var, "OUTSTRING" ) == SAMESTRING) {
  270.             *nextCode.pc++    = OUTSTRING;
  271.  
  272.             /* reparse to pick up string: */
  273.             sscanf(line, "%s %s \"%s\"", cmd, var, string);
  274.             /* copy string into code buffer: */
  275.             strCpy(nextCode.pc, string);
  276.             while (*nextCode.pc++);    /* step over string    */
  277.             nextCode.pc--;
  278.             *nextCode.pc++    = '\r'; /* add a CR        */
  279.             *nextCode.pc++    = '\0'; /* tie off with null    */
  280.         } else printf("?--no code '%s'!\n", var);
  281.  
  282.         } else if (strCmp(cmd, "#nodeTitle") == SAMESTRING) {
  283.             /* reparse by ";" terminator: */
  284.             sscanf(line, "%s \"%s\"", cmd, string);
  285.             /* copy string into code buffer: */
  286.             strCpy(nextCode.pc, string);
  287.             nodeTitle    = nextCode.pc;
  288.             while (*nextCode.pc++);    /* step over string    */
  289.         } else if (strCmp(cmd, "#nodeName" ) == SAMESTRING) {
  290.             /* reparse by ";" terminator: */
  291.             sscanf(line, "%s \"%s\"", cmd, string);
  292.             /* copy string into code buffer: */
  293.             strCpy(nextCode.pc, string);
  294.             nodeName    = nextCode.pc;
  295.             while (*nextCode.pc++);    /* step over string    */
  296.         } else if (strCmp(cmd, "#nodeId"   ) == SAMESTRING) {
  297.             /* reparse by ";" terminator: */
  298.             sscanf(line, "%s \"%s\"", cmd, string);
  299.             /* copy string into code buffer: */
  300.             strCpy(nextCode.pc, string);
  301.             nodeId    = nextCode.pc;
  302.             while (*nextCode.pc++);    /* step over string    */
  303.         } else if (strCmp(cmd, "#alldone") == SAMESTRING) {
  304.         break;
  305.         } else if (cmd[0] == '#') printf("? -- no '%s' command!\n", cmd);
  306.     }
  307.     }
  308.     if (nextCode.pc < &codeBuf[MAXCODE]) {
  309.        init();
  310.        wrapup();
  311.     } else {
  312.     printf("\7codeBuf[] overflow! Recompile with larger MAXCODE "    );
  313.     printf("or reduce ctdlCnfg.sys\7"                );
  314.     }
  315. }
  316.  
  317. /************************************************************************/
  318. /*    wrapup() finishes up and writes ctdlTabl.sys out, finally    */
  319. /************************************************************************/
  320. wrapup() {
  321.     printf("\ncreating ctdlTabl.sys table\n");
  322.     msgInit();
  323.     indexRooms();
  324.     logInit();
  325.     printf("writeSysTab =%d\n", writeSysTab());
  326. }
  327.  
  328.