home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / MISC / HSRC_117.ZIP / CONFIG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-12  |  11.1 KB  |  455 lines

  1. /* XBBS Message Base Reader -- This module parses the control file */
  2.  
  3. #include "msgg.h"
  4. #include "twindow.h"
  5. #include "keys.h"
  6. #include "headedit.h"
  7.  
  8.  
  9.  
  10. void pascal read_control (char *file,char *application) {
  11.  
  12.     struct nodeidx huge *nidxx=NULL;
  13.     int pf;
  14.     static char s[256];
  15.     char *p;
  16.     char *pp;
  17.     struct ffblk f;
  18.     char nonodelist=0;
  19.     char nomouse=0;
  20.     long x;
  21.  
  22.     for(x=0;x<10;x++) fkey[(word)x]=NULL;
  23.  
  24.     if(!strchr(file,'\\') && !strchr(file,':') && !strchr(file,'/')) {
  25.         p=searchpath(file);
  26.         file=p;
  27.     }
  28.  
  29.     if(!(pf=_open(file,O_RDONLY | O_DENYNONE | O_TEXT))==-1) {
  30.         error_message(" Can't open ctl file ");
  31.         pause();
  32.         exit(3);
  33.     }
  34.     fputs("\nParsing config file...",stderr);
  35.  
  36.     if(*application && application) {
  37.         while (!eof(pf)) {
  38.             getone(s,pf);
  39.             if (!*s) continue;
  40.             p=strtok(s," ");
  41.             strupr(p);
  42.             pp=strtok(0,"\n");
  43.             if (pp==NULL) pp="";
  44.             strip(pp,98);
  45.             stripcr(p);
  46.             if(!stricmp(p,"APPLICATION")) {
  47.                 if(!stricmp(pp,application)) break;
  48.             }
  49.         }
  50.     }
  51.     if(eof(pf)) {
  52.         error_message(" APPLICATION statement not matched or empty file ");
  53.         pause();
  54.         exit(3);
  55.     }
  56.  
  57.     while (!eof(pf)) {
  58.         getone(s,pf);
  59.         if (!*s) continue;
  60.         p=strtok(s," ");
  61.         pp=strtok(0,"\n");
  62.         if (pp==NULL) pp="";
  63.         strip(pp,98);
  64.         stripcr(p);
  65.  
  66. #ifdef DEBUG
  67.  
  68.         printf("\n`%s' -> `%s'",p,pp);
  69.  
  70. #endif
  71.  
  72.         if(!stricmp(p,"SPAWNVIEW")) {
  73.             strip(pp,79);
  74.             if(spawnview) free(spawnview);
  75.             spawnview=strdup(pp);
  76.         }
  77.         else if(!stricmp(p,"FLSEARCH")) {
  78.             strip(pp,79);
  79.             if(flsearch)free(flsearch);
  80.             flsearch=strdup(pp);
  81.         }
  82.         else if(!stricmp(p,"ENDAPP")) break;
  83.         else if (!stricmp(p,"ADDRESS") && noaddress<(char)(max(maxy,25)-2)) {
  84.             strip(pp,27);
  85.             pp=strtok(pp,":");
  86.             address[noaddress]=(struct _address *)malloc(sizeof(struct _address));
  87.             if (address[noaddress]==NULL) {
  88.                 fputs("\nOOM for addresses\n",stdout);
  89.             }
  90.             else {
  91.                 address[noaddress]->zone=(word)atol(pp);
  92.                 address[noaddress]->net=(word)atol(strtok(0,"/"));
  93.                 address[noaddress]->node=(word)atol(strtok(0,"."));
  94.                 address[noaddress]->point=(word)atol(strtok(0,"@"));
  95.                 p=strtok(0,"\n");
  96.                 strncpy(address[noaddress]->domain,p,37);
  97.                 address[noaddress]->domain[36]=0;
  98.                 noaddress++;
  99.             }
  100.         }
  101.         else if(!stricmp(p,"FKEY")) {
  102.  
  103.             int temp;
  104.  
  105.             temp=atoi(strtok(pp," "));
  106.             pp=strtok(0,"\n");
  107.             lstrip(pp);
  108.             if(pp!=NULL && *pp && temp>0 && temp<11) {
  109.                 if(fkey[temp-1])free(fkey[temp-1]);
  110.                 fkey[temp-1]=(char *)malloc(strlen(pp)+1);
  111.                 if(!fkey[temp-1]) continue;
  112.                 strcpy(fkey[temp-1],pp);
  113.             }
  114.         }
  115.         else if(!stricmp(p,"VMODE")) {
  116.             videomethod=atoi(pp);
  117.         }
  118.         else if(!stricmp(p,"HEIGHT")) {
  119.             maxy=atoi(pp);
  120.         }
  121.         else if(!stricmp(p,"WIDTH")) {
  122.             maxx=atoi(pp);
  123.         }
  124.         else if(!stricmp(p,"NOMOUSE")) {
  125.             nomouse=1;
  126.         }
  127.         if (!stricmp(p,"NOHILITE")) {
  128.             hilite=1;
  129.         }
  130.         else if (!stricmp(p,"TEMPLATE")) {
  131.             strip(pp,79);
  132.             if(template)free(template);
  133.             template=strdup(pp);
  134.         }
  135.         else if (!stricmp(p,"TEXTEDITOR")) {
  136.             if(texteditor) free(texteditor);
  137.             texteditor=strdup(pp);
  138.         }
  139.         else if (!stricmp(p,"USEDEFAULT")) {
  140.             usedefault=1;
  141.         }
  142.         else if (!stricmp(p,"MAKEINFO")) {
  143.             makeinfo=1;
  144.         }
  145.         else if (!stricmp(p,"NO*PT")) {
  146.             nopt=1;
  147.         }
  148.         else if (!stricmp(p,"NOINTL")) {
  149.             nointl=1;
  150.         }
  151.         else if (!stricmp(p,"NOCHECK")) {
  152.             autocheck=0;
  153.         }
  154.         else if (!stricmp(p,"COMPRESS")) {
  155.             packsize=(word)atol(pp);
  156.             if(packsize<1024)packsize=1024;
  157.         }
  158.         else if(!stricmp(p,"NOTRACK")) {
  159.             notrack=1;
  160.         }
  161.         else if(!stricmp(p,"NETBOARD")) {
  162.             netboard=(word)atol(pp);
  163.             if(netboard>4095)netboard=0;
  164.         }
  165.         else if(!stricmp(p,"ALTBOARD")) {
  166.             altboard=(word)atol(pp);
  167.             if(altboard>4095)altboard=0;
  168.         }
  169.         else if(!stricmp(p,"TOTALAREAS")) {
  170.             totalareas=(word)atol(pp);
  171.             printf("\nTracking LMRs for %u areas",totalareas);
  172.         }
  173.         else if(!stricmp(p,"USERNUMBER")) {
  174.             userno=(word)atol(pp);
  175.         }
  176.         else if (!stricmp(p,"START")) {
  177.             areano=(word)atol(pp);
  178.             if (areano<1 || areano>4095) areano=0;
  179.         }
  180.         else if (!stricmp(p,"WRAP")) {
  181.             if(wrapcall) free(wrapcall);
  182.             wrapcall=strdup(pp);
  183.         }
  184.         else if (!stricmp(p,"LINES")) {
  185.             maxlines=(word)atol(pp);
  186.             if (maxlines<257) maxlines=257;
  187.         }
  188.         else if (!stricmp(p,"BEFOREQUOTE")) {
  189.             strip(pp,79);
  190.             if(before_quote) free(before_quote);
  191.             before_quote=strdup(pp);
  192.         }
  193.         else if (!stricmp(p,"AFTERBEFORE")) {
  194.             strip(pp,79);
  195.             if(after_before) free(after_before);
  196.             after_before=strdup(pp);
  197.         }
  198.         else if (!stricmp(p,"AFTERQUOTE")) {
  199.             strip(pp,79);
  200.             if(after_quote) free(after_quote);
  201.             after_quote=strdup(pp);
  202.         }
  203.         else if (!stricmp(p,"NONODELIST")) {
  204.             nonodelist=1;
  205.         }
  206.         else if (!stricmp(p,"EDITOR")) {
  207.             if(editor)free(editor);
  208.             editor=strdup(pp);
  209.         }
  210.         else if (!stricmp(p,"ANSIEDITOR")) {
  211.             if(ansieditor)free(ansieditor);
  212.             ansieditor=strdup(pp);
  213.         }
  214.         else if (!stricmp(p,"NODELIST")) {
  215.             strip(pp,78);
  216.             if(nodepath)free(nodepath);
  217.             nodepath=strdup(pp);
  218.         }
  219.         else if (!stricmp(p,"PAGELENGTH")) {
  220.             pagelength=(char)atoi(pp);
  221.         }
  222.         else if (!stricmp(p,"TOPMARGIN")) {
  223.             topmargin=(char)atoi(pp);
  224.         }
  225.         else if (!stricmp(p,"BOTTOMMARGIN")) {
  226.             bottommargin=(char)atoi(pp);
  227.         }
  228.         else if (!stricmp(p,"LEFTMARGIN")) {
  229.             leftmargin=(char)atoi(pp);
  230.         }
  231.         else if (!stricmp(p,"TEXTWIDTH")) {
  232.             textwidth=(char)atoi(pp);
  233.         }
  234.         else if (!stricmp(p,"BEFOREHEADER")) {
  235.             strip(pp,11);
  236.             while ((p=strchr(pp,'~'))) *p='\x1b';
  237.             while ((p=strchr(pp,'`'))) *p='\n';
  238.             strcpy(beforeheader,pp);
  239.         }
  240.         else if (!stricmp(p,"AFTERTEXT")) {
  241.             strip(pp,47);
  242.             while ((p=strchr(pp,'~'))) *p='\x1b';
  243.             while ((p=strchr(pp,'`'))) *p='\n';
  244.             strcpy(aftertext,pp);
  245.         }
  246.         else if (!stricmp(p,"AFTERHEADER")) {
  247.             strip(pp,11);
  248.             while ((p=strchr(pp,'~'))) *p='\x1b';
  249.             while ((p=strchr(pp,'`'))) *p='\n';
  250.             strcpy(afterheader,pp);
  251.         }
  252.         else if (!stricmp(p,"AFTERPRINTING")) {
  253.             strip(pp,11);
  254.             while ((p=strchr(pp,'~'))) *p='\x1b';
  255.             while ((p=strchr(pp,'`'))) *p='\n';
  256.             strcpy(afterprinting,pp);
  257.         }
  258.         else if (!stricmp(p,"ALIAS") && noalias<(char)(max(maxy,25)-2)) {
  259.             strip(pp,35);
  260.             if(noalias) for(x=0;x<noalias;x++) {
  261.                 if(!stricmp(pp,alias[(word)x])) goto BreakOut;
  262.             }
  263.             alias[noalias]=(char *)malloc(36);
  264.             if (alias[noalias]==NULL) {
  265.                 fputs("\nOOM for aliases\n",stdout);
  266.             }
  267.             else {
  268.                 strcpy(alias[noalias],pp);
  269.                 noalias++;
  270.             }
  271. BreakOut:
  272. ;
  273.         }
  274.         else if (!stricmp(p,"ATTRIBUTES")) defaultattr=(word)atol(pp);
  275.         else if (!stricmp(p,"EXPORTNAME")) {
  276.             strip(pp,65);
  277.             strcpy(filenamer,pp);
  278.         }
  279.         else if (!stricmp(p,"PATH") && nodirs<(char)(max(maxy,25)-2)) {
  280.             strip(pp,78);
  281.             if(nodirs) for(x=0;x<nodirs;x++) {
  282.                 if(!stricmp(pp,dirs[(word)x])) goto BreakOut2;
  283.             }
  284.             dirs[nodirs]=(char *)malloc(79);
  285.             if(dirs[nodirs]==NULL) {
  286.                 fputs("\nOOM for paths\n",stdout);
  287.             }
  288.             else {
  289.                 if(!*pp) dirs[nodirs]=0;
  290.                 strcpy(dirs[nodirs],pp);
  291.                 nodirs++;
  292.             }
  293. BreakOut2:
  294. ;
  295.         }
  296.         else if (!stricmp(p,"USEEMS")) {
  297.             LIMEMS=1;
  298.         }
  299.         else if (!stricmp(p,"SWAP")) {
  300.             swap=1;
  301.         }
  302.         else if (!stricmp(p,"SWAPDRIVE")) {
  303.             useswapdisk=toupper(*pp);
  304.         }
  305.         else if (!stricmp(p,"SWAPFILE")) {
  306.             strip(pp,63);
  307.             strcpy(swapname,pp);
  308.         }
  309.         if (!stricmp(p,"TEXTCOLOR")) readtextcolor=(char)atoi(pp);
  310.         else if (!stricmp(p,"TEXTBACK")) readtextback=(char)atoi(pp);
  311.         else if (!stricmp(p,"STATCOLOR")) readstatcolor=(char)atoi(pp);
  312.         else if (!stricmp(p,"STATBACK")) readstatback=(char)atoi(pp);
  313.         else if (!stricmp(p,"HEADCOLOR")) readheadcolor=(char)atoi(pp);
  314.         else if (!stricmp(p,"HEADBACK")) readheadback=(char)atoi(pp);
  315.         else if (!stricmp(p,"ORIGFORE")) orig_fore=(char)atoi(pp);
  316.         else if (!stricmp(p,"ORIGBACK")) orig_back=(char)atoi(pp);
  317.         else if (!stricmp(p,"TEARFORE")) tear_fore=(char)atoi(pp);
  318.         else if (!stricmp(p,"TEARBACK")) tear_back=(char)atoi(pp);
  319.         else if (!stricmp(p,"QUOTEFORE")) quote_fore=(char)atoi(pp);
  320.         else if (!stricmp(p,"QUOTEBACK")) quote_back=(char)atoi(pp);
  321.         else if (!stricmp(p,"KLUDGEFORE")) kludge_fore=(char)atoi(pp);
  322.         else if (!stricmp(p,"KLUDGEBACK")) kludge_back=(char)atoi(pp);
  323.         else if(!stricmp(p,"BELL")) nobell=0;
  324.  
  325.         if (!stricmp(p,"ORIGIN")) {
  326.             strip(pp,58);
  327.             strcpy(origin,pp);
  328.         }
  329.         else if (!stricmp(p,"OUTBOUND")) {
  330.             strip(pp,80);
  331.             strcpy(outbound,pp);
  332.         }
  333.         else if (!stricmp(p,"INBOUND")) {
  334.             strip(pp,80);
  335.             strcpy(inbound,pp);
  336.         }
  337.         else if(!stricmp(p,"MSGAREAS")) {
  338.             strcpy(msgareas,pp);
  339.         }
  340.         else if(!stricmp(p,"DOMAIL")) {
  341.             domail=(char)atoi(pp);
  342.         }
  343.         else if(!stricmp(p,"SKIPDELETED")) {
  344.             skipdeleted=(char)atoi(pp);
  345.         }
  346.     }
  347.     _close(pf);
  348.  
  349.     if(!nomouse) {
  350.         x=(long)getvect(0x33);  /* Check for mouse driver */
  351.         if(x!=0L) {
  352.             _AX=0;  /* Initialize mouse */
  353.             geninterrupt(0x33);
  354.         }
  355.         usemouse=(unsigned char)_AX;
  356.         if(usemouse) {    /* Make sure mouse cursor stays hidden */
  357.             _AX=2;
  358.             geninterrupt(0x33);
  359.         }
  360.     }
  361.  
  362.     if (totalareas) {
  363.         lastread=(word *)malloc(totalareas * sizeof(word));
  364.         if (lastread==NULL) {
  365.             fputs("\nOut of memory for LMRs\n",stdout);
  366.             exit(254);
  367.         }
  368.         for(x=0;x<totalareas;x++) lastread[(word)x]=0;
  369.     }
  370.     if (areano) {
  371.         if(nodirs) strcpy(path,dirs[0]);
  372.         if(totalareas)load_lastread();
  373.         nomess=check_area(areano);
  374.         if (!nomess) messno=0;
  375.         else messno=1;
  376.         if (areano<(totalareas+1) && nomess) messno=lastread[areano-1];
  377.         if ((messno>nomess && nomess) || (messno==0 && nomess)) messno=1;
  378.         if (messno) get_mess(0);
  379.     }
  380.  
  381.     if (nonodelist) goto BigFinish;
  382.     sprintf(s,"%sQNL_IDX.BBS",nodepath);
  383.     if (!findfirst(s,&f,0)) {
  384. TryNodeAgain:
  385.         nidxsize=f.ff_fsize/(long)sizeof(struct nodeidx);
  386.         nidx=(struct nodeidx huge *) farmalloc(nidxsize * (long)sizeof(struct nodeidx));
  387.         if (nidx==NULL) {
  388.             if(nidxsize<512L) {
  389.                 printf("\nScrew it, can't load nodelist.\n");
  390.                 nonodelist=0;
  391.                 nidxsize=0L;
  392.                 goto BigFinish;
  393.             }
  394.             nidxsize/=2L;
  395.             f.ff_fsize=nidxsize*(long)sizeof(struct nodeidx);
  396.             printf("\nInsufficient memory for whole nodelist index...trying %ld nodes...",nidxsize);
  397.             goto TryNodeAgain;
  398.         }
  399.         if((pf=_open(s,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
  400.             error_message(" Can't open nodelist ");
  401.             if (nidx!=NULL) farfree ((void far *)nidx);
  402.             nidx=NULL;
  403.             nonodelist=0;
  404.             nidxsize=0L;
  405.             goto BigFinish;
  406.         }
  407.         fputs("\nReading nodelist...",stdout);
  408.         nidxx=nidx;
  409.         while (f.ff_fsize) {
  410.  
  411.             int x;
  412.  
  413.             x=32767/sizeof(struct nodeidx);
  414.             x*=sizeof(struct nodeidx);
  415.             if(f.ff_fsize>(long)x) {
  416.                 f.ff_fsize-=(long)x;
  417.             }
  418.             else {
  419.                 x=(int)f.ff_fsize;
  420.                 f.ff_fsize=0;
  421.             }
  422.             if (_read(pf,(void *)nidxx,x)<1 || eof(pf)==-1) {
  423.                 perror("Error");
  424.                 if (nidx) free ((void *)nidx);
  425.                 break;
  426.             }
  427.             nidxx=&nidx[(long)x/(long)sizeof(struct nodeidx)];
  428.         }
  429.         _close(pf);
  430.     }
  431. BigFinish:
  432.     if(nodirs>1) nodirs=max(23,maxy-2);
  433. }
  434.  
  435.  
  436.  
  437. void pascal strip (char *s,int blank) {
  438.  
  439.        lstrip(s);
  440.        stripcr(s);
  441.        s[blank]=0;
  442. }
  443.  
  444.  
  445.  
  446.  
  447. void pascal getone (char *s, int fp) {
  448.  
  449.    do {
  450.        if (!fgetsx(s,256,fp)) *s=0;
  451.    } while (!eof(fp) && *s==';');
  452.    if (eof(fp)) *s=0;
  453. }
  454.  
  455.