home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / MXMS_160.LZH / INIT.C < prev    next >
C/C++ Source or Header  |  1991-06-25  |  30KB  |  982 lines

  1. /****************************************************************************/
  2. /*    Init.c      MaxMail initialization stuff                              */
  3. /*                                                                          */
  4. /****************************************************************************/
  5.  
  6. #include "MaxMail.h"
  7.  
  8. char dummy[81];
  9. char adrive[_MAX_DRIVE];
  10.  
  11. extern int  fido_init;
  12. extern int Command;
  13. extern char  _far *msgbuffer;
  14.  
  15. /* Initialize MaxMail */
  16.  
  17. void init()
  18. {
  19.  
  20.    int x;
  21.    struct find_t fbuf;
  22.  
  23.    startsecs = clock();
  24.    parmread = FALSE;
  25.    get_currents();           /* Get the current directory,drive and save */
  26.  
  27.    LogMode = 0;        /* Turn off logging by default */
  28.  
  29.    NewHelpFil[0] = 0;        /* Turn off newusers help file */
  30.    HelpFile[0] = 0;        /* Turn off std help file */
  31.    LogFile[0] = 0;        /* Turn Off logfile by default */
  32.    SignOff[0] = 0;
  33.    MsgHdrFile[0] = 0;
  34.    statline[0] = 0;
  35.    BullFile[0] = 0;
  36.    BBSid[0] = 0;
  37.    QWKWelcome[0] = 0;
  38.    QWKnews[0] = 0;
  39.    QWKbye[0] = 0;
  40.    QWKDir[0] = 0;
  41.    NewFiles[0] = 0;
  42.    Command = FALSE;
  43.    strcpy(BBSphone,"555-1212");
  44.    tdir[0] = 0;        /* Temporary directory for Packing program */
  45.    PACKER_1 = NULL;
  46.    PROTO_1  = NULL;
  47.    ZIPREP = NULL;
  48.    LHAREP = NULL;
  49.    ARCREP = NULL;
  50.    ExtendOk = TRUE;
  51.    ReDirect = FALSE;
  52.    MaxDaily = 0;
  53.    StripTags = TRUE;
  54.  
  55.    SkipCount = 0;
  56.    ForceCount = 0;
  57.  
  58. /* Establish Default color attributes */
  59.  
  60.    TextAttr[STD_TEXT] = 6;           /* Cyan on black */
  61.    TextAttr[HILITE_TEXT] = 3;        /* Yellow on black */
  62.    TextAttr[MENU_KEY] = 2;        /* Green on black */
  63.    TextAttr[TIME_LEFT] = 87;        /* White on Magenta */
  64.    TextAttr[PROMPT_TEXT] = 4;        /* Blue on black */
  65.    TextAttr[ATTN_TEXT] = 1;        /* Red on black */
  66.    TextAttr[VIEW_TEXT] = 71;        /* White on Blue */
  67.  
  68.    load_cfgfile(MCfgFile);
  69.  
  70.    if (tdir[0]) {        /* Was a temp dir specified? */
  71.       x = strlen(tdir) - 1;        /* Bump to tail end of string */
  72.       if (tdir[x] == '\\')
  73.          tdir[x] = 0;        /* Remove it! We will add it when necessary */
  74.    }
  75.  
  76.    if (Task && LogFile[0]) {        /* Redo logfile name with task # */
  77.       _splitpath(LogFile,adrive,dummy,temp,temp1);
  78.       temp[6] = 0;        /* Trim out 2 chars */
  79.       sprintf(LogFile,"%s%s%s%02x%s",adrive,dummy,temp,Task,temp1);
  80.    }
  81.  
  82.    if (!parmread) {
  83.       if(read_prm(PrmFile) < 0)
  84.          aborterror(FILEOPEN,"Error opening PRM file!\r\n");
  85.  
  86.       if(switch_dir(PRM(sys_path)))        /* Change to Maximus home dir */
  87.          deinit(2);
  88.    }
  89.  
  90. /* Now test the temp subdirectory and see if it's legal */
  91.    if (tdir[0]) {
  92.       if (switch_dir(tdir)) {        /* Uh oh! */
  93.          logit("Invalid temp dir specified",'!');
  94.          tdir[0] = 0;        /* Terminate it! */
  95.       }
  96.       switch_dir(PRM(sys_path));        /* Return to Maximus root */
  97.    }
  98.  
  99.    if (IsLocal >= 2) 
  100.       MaxMsgs = 9999;        /* Allow tons of messages in local mode */
  101.  
  102.    sprintf(temp,"MxMlAct.%03x",Task);        /* Create a task id */
  103.    x = sopen(temp,O_RDWR | O_BINARY | O_CREAT,SH_DENYWR,S_IWRITE);
  104.    close(x);        /* Create just a null file */
  105.  
  106.    if (Task && SumFile[0]) {
  107.       sprintf(temp,".%03x",Task);
  108.       strcat(SumFile,temp);
  109.    }
  110.  
  111.    /* See if helpfile exists */
  112.    if (_dos_findfirst(HelpFile,_A_NORMAL,&fbuf) && HelpFile[0])
  113.       HelpFile[0] = 0;        /* Disable */
  114.  
  115. }
  116.  
  117. /* Close up MaxMail, clean up loose ends */
  118. void deinit(int errcode)
  119. {
  120.    int x,y,z;
  121.    long secdiff;
  122.    struct _restart *rst;
  123.    struct find_t fbuf;
  124.  
  125.    if (fido_init)
  126.       _ffree(msgbuffer);
  127.  
  128.    switch_dir(PRM(sys_path));        /* Return to Maximus root */
  129.  
  130.    if (tdir[0])
  131.       switch_dir(tdir);
  132.  
  133.    if (QWKDir[0])
  134.       if(chdir(QWKDir) != 0)
  135.          QWKDir[0] = 0;
  136.  
  137.    if(packer_del) 
  138.       unlink(ArcFile);
  139.  
  140.    if (USERCFG.msgfrmt == 1) {
  141.       if (QWKDir[0]) {        /* We are in private subdir */
  142.          if (IsLocal) {        /* We gotta keep qwk file! */
  143.             sprintf(temp,"%s.qwk",BBSid);
  144.             chmod(temp,S_IREAD);    /* Thus make it read only */
  145.          }
  146.          if (!_dos_findfirst("*.*",_A_NORMAL,&fbuf)) {    /* Kill everything in subdir */
  147.             unlink(fbuf.name);
  148.             while (!_dos_findnext(&fbuf)) 
  149.                unlink(fbuf.name);
  150.          }
  151.          if (IsLocal)         /* We gotta keep qwk file! */
  152.             chmod(temp,S_IWRITE);    /* restore it */
  153.       }
  154.       else {        /* Try to do a decent cleanup */
  155.          sprintf(temp,"%s.rep",BBSid);
  156.          unlink(temp);
  157.          unlink("control.dat");
  158.          unlink("messages.dat");
  159.          unlink("NewFiles.dat");
  160.          unlink("Door.id");
  161.  
  162.          _splitpath(QWKnews,dummy,dummy,temp,temp1);
  163.          sprintf(dummy,"%s%s",temp,temp1);
  164.          unlink(dummy);        /* Kill all the special files */
  165.  
  166.          _splitpath(QWKbye,dummy,dummy,temp,temp1);
  167.          sprintf(dummy,"%s%s",temp,temp1);
  168.          unlink(dummy);        /* Kill all the special files */
  169.  
  170.          _splitpath(QWKWelcome,dummy,dummy,temp,temp1);
  171.          sprintf(dummy,"%s%s",temp,temp1);
  172.          unlink(dummy);        /* Kill all the special files */
  173.  
  174.          if (!_dos_findfirst("???.ndx",_A_NORMAL,&fbuf)) {
  175.             unlink(fbuf.name);
  176.             while (!_dos_findnext(&fbuf)) 
  177.                unlink(fbuf.name);
  178.          }
  179.          if (!_dos_findfirst("blt-*.*",_A_NORMAL,&fbuf)) {
  180.             unlink(fbuf.name);
  181.             while (!_dos_findnext(&fbuf)) 
  182.                unlink(fbuf.name);
  183.          }
  184.       }
  185.    }
  186.    else {
  187.       unlink(TxtFile);
  188.       unlink(StatName);
  189.    }
  190.  
  191.  
  192.    if(QWKDir[0]) {
  193.       chdir("..");
  194.       rmdir(QWKDir);        /* Remove temp directory */
  195.       QWKDir[0] = 0;
  196.    }
  197.  
  198.    homedir();
  199.  
  200.    x = USRCFG_UPD | USRCFG_FUPD | USRCFG_MSGUPD;
  201.    x ^= 0xffff;
  202.    USERCFG.flags &= x;        /* Turn off forced update flags */
  203.  
  204.    if (newuser) {
  205.       printf("Building new user message areas\n");
  206.       build_areas(FALSE,FALSE);        /* Recalc totareas */
  207.    }
  208.  
  209.    sprintf(temp,"MxMlAct.%03x",Task);        /* Create a task id */
  210.    unlink(temp);
  211.    if (!SysopMode) {
  212.       x = sopen(CfgFile,O_RDWR | O_BINARY,SH_DENYWR,S_IWRITE);
  213.       if (x != -1) {
  214.          time(&USERCFG.lasttime);
  215.          USERCFG.totprotos = totprotocols;
  216.          USERCFG.totpackers = totpackers;
  217.          USERCFG.calls++;
  218.          strcpy(USERCFG.name,LastUser.name);
  219.          if (USERCFG.calls < USERCFG.packcount)
  220.             USERCFG.calls = USERCFG.packcount;
  221.          update_usercfg(x);
  222.          close(x);
  223.       }
  224.       else logit("Error updating User Config file",'!');
  225.       sprintf(temp,"%s off-line. Calls=%u, Len=%u",UserName,USERCFG.calls,timeon());
  226.    }
  227.    else {
  228.       sprintf(temp,"Local Sysop off-line. Calls=~, Len=~");
  229.       errcode = 7;
  230.    }
  231.    logit(temp,':');
  232.    sprintf(temp,"End, (%d)",errcode);
  233.    logit(temp,':');
  234.  
  235.    if (LogFile[0]) {
  236.       x = sopen(LogFile,O_BINARY | O_RDWR | O_APPEND,SH_DENYWR,S_IWRITE);
  237.       if (x > 0) {
  238.          write(x,"\r\n",2);
  239.          close(x);
  240.       }
  241.    }
  242.  
  243.    if (TimeAdjust) {
  244.       sprintf(temp,"Restar%02x.bbs",Task); 
  245.       if(_dos_findfirst(temp,_A_NORMAL,&fbuf) == 0 ) { 
  246.          rst = (struct _restart *) malloc(sizeof(struct _restart));
  247.          if (rst != NULL) {
  248.             x = sopen(temp,O_BINARY | O_RDWR,SH_DENYWR,S_IWRITE);
  249.             if (x != -1) {
  250.                if(read(x,(char *)rst,sizeof(struct _restart)) != 0) {
  251.                   secdiff = rst->timeoff - rst->timeon;
  252.                   z = (int) (secdiff / 60L);        /* convert to minutes */
  253.                   y = timeon();
  254.                   if ((unsigned long)(y + z) <= rst->max_time){ /* We can bump it up */
  255.                      rst->timeoff += 60 * timeon();
  256.                      rst->timeon += 60 * timeon();
  257.                   }
  258.                   lseek(x,0L,SEEK_SET);        /* Rewind the file */
  259.                   write(x,(struct _restart *) rst,sizeof(struct _restart));
  260.                }
  261.                close(x);
  262.             }
  263.          }
  264.       }
  265.       else {        /* RestarXX doesn't exist so we muck LastUser instead */
  266.          x = sopen(LastUse,O_RDWR | O_BINARY ,SH_DENYWR,S_IWRITE); 
  267.          if (x != -1) {
  268.             lseek(x,0L,SEEK_SET);        /* Rewind the file */
  269.             LastUser.timeremaining += timeon();
  270.             write(x,(char *) &LastUser,user_slen);
  271.             close(x);
  272.          }
  273.       }
  274.    }
  275.  
  276.    fclose(afile);
  277.    sprintf(temp,"%s%s",sdrive,sdir);
  278.    switch_dir(temp);        /* Change back to startup dir */
  279.    FossilDeInit();
  280.    setcolor(TextAttr[STD_TEXT]);
  281.    exit(errcode);
  282. }
  283.  
  284. void aborterror(int code,char *strng)
  285. {
  286.    int exitcode;
  287.  
  288.    fclose(outfile);
  289.    exitcode = 1;
  290.  
  291.  
  292.    switch (code) {
  293.       case DEADMODEM:
  294.          strcpy(temp,"Modem appears dead");
  295.          break;
  296.  
  297.       case BADALLOC:
  298.          strcpy(temp,"Error allocating memory");
  299.          break;
  300.  
  301.       case BADEXEC:
  302.          strcpy(temp,"Error executing external program");
  303.          break;
  304.  
  305.       case FILEOPEN:
  306.          strcpy(temp,"Error opening file");
  307.          exitcode = 4;
  308.          break;
  309.  
  310.       case FILECREATE:
  311.          strcpy(temp,"Error creating file");
  312.          exitcode = 4;
  313.          break;
  314.  
  315.       case FILEWRITE:
  316.          strcpy(temp,"Error writing file");
  317.          exitcode = 4;
  318.          break;
  319.  
  320.       case DROPCARRIER:
  321.          strcpy(temp,"User dropped carrier!");
  322.          IsLocal = TRUE;
  323.          exitcode = 3;
  324.          break;
  325.  
  326.       case USERIDLE:
  327.          sprintf(temp,"User was idle more than %d minutes!",IDLETIME);
  328.          IsLocal = TRUE;
  329.          exitcode = 3;
  330.          break;
  331.  
  332.       default:
  333.          strcpy(temp,"General failure");
  334.          break;
  335.    }
  336.  
  337.    if (code != DEADMODEM) {
  338.  
  339.       setcolor(TextAttr[ATTN_TEXT]);
  340.       strout("\r\n");
  341.       if (strng)  {
  342.          strout(strng);
  343.          logit(strng,'!');
  344.       }
  345.       else {
  346.          strout(temp);
  347.          logit(temp,'!');
  348.       }
  349.       strout("\r\n");
  350.       setcolor(TextAttr[STD_TEXT]);
  351.    }
  352.    else logit(strng,'!');
  353.  
  354.    deinit(exitcode);
  355. }
  356.  
  357. int load_cfgfile(char *cfgfile)
  358. {
  359.    FILE *cfile;
  360.    char *p1,*p2,*p3;
  361.    int x,y;
  362.  
  363.    cfile = _fsopen(cfgfile,"rt",SH_DENYNO);
  364.    if (cfile == NULL) {        /* Try to open it in executable maxmail dir */
  365.       _splitpath(cfgfile,dummy,dummy,temp,temp1);        /* Extract just filename */
  366.       _makepath(dummy,hdrive,hdir,temp,temp1);
  367.       cfile = _fsopen(dummy,"rt",SH_DENYNO);
  368.       if (cfile == NULL) {        /* Not there? Then its hopeless! */
  369.          sprintf(temp1,"Error opening '%s' config file!\r\n",dummy);
  370.          aborterror(FILEOPEN,temp1);
  371.       }
  372.    }
  373.  
  374.    fgets(temp,81,cfile);
  375.    while (!feof(cfile)) {
  376.       if (*temp != '\0') {        /* Parse out token string */
  377.          p1 = strtok(temp," \n\t");
  378.          p2 = strtok(NULL," \n\t;");
  379.          if (strcmpi(p1,";") == 0) {        /* Just ignore comment lines */
  380.             fgets(temp,81,cfile);
  381.             continue;
  382.          }
  383.          if (strcmpi(p1,"TxtFile") == 0) {
  384.             if (p2) strcpy(TxtFile,p2);
  385.          }
  386.          else if (strcmpi(p1,"CfgFile") == 0) {
  387.             if (p2) strcpy(CfgFile,p2);
  388.          }
  389.          else if (strcmpi(p1,"LogFile") == 0) {
  390.             if (p2) strcpy(LogFile,p2);
  391.             LogMode = VERBOSE;        /* Default mode */
  392.          }
  393.          else if (strcmpi(p1,"NewHelpFile") == 0) {
  394.             if (p2) strcpy(NewHelpFil,p2);
  395.          }
  396.          else if (strcmpi(p1,"HelpFile") == 0) {
  397.             if (p2) strcpy(HelpFile,p2);
  398.          }
  399.          else if (strcmpi(p1,"MaximumMessages") == 0) {
  400.             if (p2) MaxMsgs = atoi(p2);
  401.          }
  402.          else if (strcmpi(p1,"MessageHeader") == 0) {
  403.             if (p2) strcpy(MsgHdrFile,p2);
  404.          }
  405.          else if (strcmpi(p1,"NewFilesList") == 0) {
  406.             if (p2) strcpy(NewFiles,p2);
  407.          }
  408.          else if (strcmpi(p1,"SignOutMsg") == 0) {
  409.             x = 0;
  410.             p3 = strtok(p2," ;_\n\t");
  411.             while (p3) {
  412.                x += strlen(p3);
  413.                strncat(SignOff,p3,79);
  414.                strcat(SignOff," ");
  415.                p3 = strtok(NULL," ;_\n\t");
  416.                if (strlen(SignOff) >= 80)
  417.                   break;
  418.             }
  419.          }
  420.          else if (strcmpi(p1,"Packer") == 0) {
  421.             x = 0;
  422.             temp1[0] = '\0';
  423.             while (p2) {
  424.                strcat(temp1,p2);        /* Description string */
  425.                strcat(temp1," ");        /* Add a blank for safety */
  426.                if (++x > 4)        /* Packer requires 4 parameter fields */
  427.                   break;
  428.                p2 = strtok(NULL," ;\n\t");
  429.             }
  430.             if (x >= 4) enable_packer(temp1);
  431.          }
  432.          else if (strcmpi(p1,"Protos") == 0) {
  433.             x = 0;
  434.             temp1[0] = '\0';
  435.             while (p2) {
  436.                strcat(temp1,p2);        /* Description string */
  437.                strcat(temp1," ");        /* Add a blank for safety */
  438.                if (++x >= 3)        /* Packer requires 3 parameter fields */
  439.                   break;
  440.                p2 = strtok(NULL," ;\n\t");
  441.             }
  442.             if (x >= 3) enable_proto(temp1);
  443.          }
  444.          else if (strcmpi(p1,"RepUpload") == 0) {
  445.             x = 0;
  446.             temp1[0] = '\0';
  447.             while (p2) {
  448.                strcat(temp1,p2);        /* Description string */
  449.                strcat(temp1," ");        /* Add a blank for safety */
  450.                if (++x >= 3)        /* Packer requires 3 parameter fields */
  451.                   break;
  452.                p2 = strtok(NULL," ;\n\t");
  453.             }
  454.             if (x >= 3) enable_upl(temp1);
  455.          }
  456.          else if (strcmpi(p1,"SkipAreas") == 0) {
  457.             strcpy(temp1,p2);        /* Copy area numbers */
  458.             p2 = strtok(temp1,", \t");
  459.             y = 1;
  460.             while (p2) {
  461.                if (!SkipCount)
  462.                   SkipAreas = (int **) calloc(1,sizeof(int *));
  463.                else SkipAreas = (int **) realloc(SkipAreas,sizeof(int *) * (y+1));
  464.                if (SkipAreas == NULL)
  465.                   aborterror(BADALLOC,NULL);
  466.                SkipAreas[y-1] = (int *) malloc(sizeof(int));
  467.                if (SkipAreas[y-1] == NULL)
  468.                   aborterror(BADALLOC,NULL);
  469.                *(SkipAreas[y-1]) = atoi(p2);        /* Plug in the area number */
  470.                y++;
  471.                SkipCount++;
  472.                p2 = strtok(NULL,", \t");
  473.             }
  474.          }
  475.          else if (strcmpi(p1,"ForceAreas") == 0) {
  476.             strcpy(temp1,p2);        /* Copy area numbers */
  477.             p2 = strtok(temp1,", \t");
  478.             y = 1;
  479.             while (p2) {
  480.                if (!ForceCount)
  481.                   ForceAreas = (int **) calloc(1,sizeof(int *));
  482.                else ForceAreas = (int **) realloc(ForceAreas,sizeof(int *) * (y+1));
  483.                if (ForceAreas == NULL)
  484.                   aborterror(BADALLOC,NULL);
  485.                ForceAreas[y-1] = (int *) malloc(sizeof(int));
  486.                if (ForceAreas[y-1] == NULL)
  487.                   aborterror(BADALLOC,NULL);
  488.                *(ForceAreas[y-1]) = atoi(p2);        /* Plug in the area number */
  489.                y++;
  490.                ForceCount++;
  491.                p2 = strtok(NULL,", \t");
  492.             }
  493.          }
  494.          else if (strcmpi(p1,"TempDir") == 0) {
  495.             if (p2) strcpy(tdir,p2);
  496.          }
  497.          else if (strcmpi(p1,"ExtendedBarrier") == 0) {
  498.             if (p2) {
  499.                if(strcmpi(p2,"yes") == 0)
  500.                   ExtendOk = TRUE;
  501.                else ExtendOk = FALSE;
  502.             }
  503.          }
  504.          else if (strcmpi(p1,"WatchDog") == 0) {
  505.             if (p2) {
  506.                if(strcmpi(p2,"yes") == 0)
  507.                   WatchDog = TRUE;
  508.             }
  509.          }
  510.          else if(strcmpi(p1,"Colors") == 0) {
  511.             strcpy(temp1,p2);        /* Copy colors numbers */
  512.             p2 = strtok(temp1,", \t");
  513.             for (x=0; x < 7; x++) {
  514.                if (p2) TextAttr[x] = (byte) atoi(p2);
  515.                else {        /* Sysop didn't give full set! */
  516.                   y = TextAttr[x-1];        /* Fetch last attribute */
  517.                   while (x < 7) 
  518.                      TextAttr[x++] = (byte) y;        /* And store to remainder */
  519.                   break;
  520.                }
  521.                p2 = strtok(NULL,", \t");        /* Fetch next token */
  522.             }
  523.          }
  524.          else if (strcmpi(p1,"Bulletin") == 0) {
  525.             if (p2) strcpy(BullFile,p2);
  526.          }
  527.          else if (strcmpi(p1,"DownloadHangup") == 0) {
  528.             if (strcmpi(p2,"STRING") == 0) {
  529.                Hangup = 1;
  530.                HangupMode = 1;
  531.             }
  532.             else if (strcmpi(p2,"DTR") == 0){
  533.                Hangup = 2;
  534.                HangupMode = 2;
  535.             }
  536.             else Hangup = 0;        /* Disable it */
  537.          }
  538.          else if (strcmpi(p1,"MaxDailyCalls") == 0) {
  539.             if (p2) MaxDaily = atoi(p2);
  540.          }
  541.          else if (strcmpi(p1,"ReDirectPacker") == 0) {
  542.             if (p2) {
  543.                if(strcmpi(p2,"yes") == 0)
  544.                   ReDirect = TRUE;
  545.             }
  546.          }
  547.          else if (strcmpi(p1,"UseCommand") == 0) {
  548.             if (p2) {
  549.                if(strcmpi(p2,"yes") == 0)
  550.                   Command = TRUE;
  551.             }
  552.          }
  553.          else if (strcmpi(p1,"StripTags") == 0) {
  554.             if (p2) {
  555.                if(strcmpi(p2,"no") == 0)
  556.                   StripTags = FALSE;
  557.             }
  558.          }
  559.          else if (strcmpi(p1,"QWKWelcome") == 0) {
  560.             if (p2) {
  561.                strcpy(QWKWelcome,p2);
  562.             }
  563.          }
  564.          else if (strcmpi(p1,"QWKnews") == 0) {
  565.             if (p2) {
  566.                strcpy(QWKnews,p2);
  567.             }
  568.          }
  569.          else if (strcmpi(p1,"QWKbye") == 0) {
  570.             if (p2) {
  571.                strcpy(QWKbye,p2);
  572.             }
  573.          }
  574.          else if (strcmpi(p1,"BBSphone") == 0) {
  575.             if (p2) {
  576.                memset(BBSphone,0,15);
  577.                strncpy(BBSphone,p2,14);
  578.             }
  579.          }
  580.          else if (strcmpi(p1,"BBSid") == 0) {
  581.             if (p2) {
  582.                memset(BBSid,0,15);
  583.                strncpy(BBSid,p2,8);
  584.             }
  585.          }
  586.          else if (strcmpi(p1,"RepZip") == 0) {
  587.             if (p2 && ZIPREP == NULL) {
  588.                ZIPREP = (struct reparc_st *) malloc(sizeof(struct reparc_st));
  589.                if (ZIPREP == NULL)
  590.                   aborterror(BADALLOC,NULL);
  591.                ZIPREP->packexe = (char *) malloc(strlen(p2) + 1);
  592.                if (ZIPREP->packexe == NULL)
  593.                   aborterror(BADALLOC,NULL);
  594.                strcpy(ZIPREP->packexe,p2);
  595.                p3 = strtok(NULL," \n\t;");
  596.                if (p3) {
  597.                   p2 = strchr(p3,'_');        /* Look for replacements */
  598.                   while (p2) {
  599.                      *p2 = ' ';                    /* Put a blank instead */
  600.                      p2++;
  601.                      p2 = strchr(p2,'_');        /* Look for replacements */
  602.                   }
  603.                   ZIPREP->packstring = (char *) malloc(strlen(p3) + 1);
  604.                   if (ZIPREP->packstring == NULL)
  605.                      aborterror(BADALLOC,NULL);
  606.                   strcpy(ZIPREP->packstring,p3);
  607.                }
  608.             }
  609.          }
  610.          else if (strcmpi(p1,"RepLha") == 0) {
  611.             if (p2 && LHAREP == NULL) {
  612.                LHAREP = (struct reparc_st *) malloc(sizeof(struct reparc_st));
  613.                if (LHAREP == NULL)
  614.                   aborterror(BADALLOC,NULL);
  615.                LHAREP->packexe = (char *) malloc(strlen(p2) + 1);
  616.                if (LHAREP->packexe == NULL)
  617.                   aborterror(BADALLOC,NULL);
  618.                strcpy(LHAREP->packexe,p2);
  619.                p3 = strtok(NULL," \n\t;");
  620.                if (p3) {
  621.                   p2 = strchr(p3,'_');        /* Look for replacements */
  622.                   while (p2) {
  623.                      *p2 = ' ';                    /* Put a blank instead */
  624.                      p2++;
  625.                      p2 = strchr(p2,'_');        /* Look for replacements */
  626.                   }
  627.                   LHAREP->packstring = (char *) malloc(strlen(p3) + 1);
  628.                   if (LHAREP->packstring == NULL)
  629.                      aborterror(BADALLOC,NULL);
  630.                   strcpy(LHAREP->packstring,p3);
  631.                }
  632.             }
  633.          }
  634.          else if (strcmpi(p1,"RepArc") == 0) {
  635.             if (p2 && ARCREP == NULL) {
  636.                ARCREP = (struct reparc_st *) malloc(sizeof(struct reparc_st));
  637.                if (ARCREP == NULL)
  638.                   aborterror(BADALLOC,NULL);
  639.                ARCREP->packexe = (char *) malloc(strlen(p2) + 1);
  640.                if (ARCREP->packexe == NULL)
  641.                   aborterror(BADALLOC,NULL);
  642.                strcpy(ARCREP->packexe,p2);
  643.                p3 = strtok(NULL," \n\t;");
  644.                if (p3) {
  645.                   p2 = strchr(p3,'_');        /* Look for replacements */
  646.                   while (p2) {
  647.                      *p2 = ' ';                    /* Put a blank instead */
  648.                      p2++;
  649.                      p2 = strchr(p2,'_');        /* Look for replacements */
  650.                   }
  651.                   ARCREP->packstring = (char *) malloc(strlen(p3) + 1);
  652.                   if (ARCREP->packstring == NULL)
  653.                      aborterror(BADALLOC,NULL);
  654.                   strcpy(ARCREP->packstring,p3);
  655.                }
  656.             }
  657.          }
  658.       }
  659.       fgets(temp,81,cfile);
  660.    }
  661.    fclose(cfile);
  662.    return(TRUE);
  663. }
  664.  
  665.  
  666. /* Setup a protocol using string format as follows:
  667.    "Description Filename Commandline"
  668.         |           |          |----------- Command line for program.
  669.         |           |
  670.         |           |---------------------- Full filename (No path)
  671.         |
  672.         |---------------------------------- Desribe protocol in 1-2 words
  673. */
  674.  
  675. void enable_proto(char *strng)
  676. {
  677.    char cmndline[40];
  678.    char describe[20];
  679.    char fname[14];
  680.    char *p,*p1;
  681.    int x;
  682.    struct proto_st *proto1;
  683.  
  684.  
  685.    p = strtok(strng," \t");        /* Fetch description */
  686.    if (!p)
  687.       return;        /* Invalid */
  688.    p1 = strchr(p,'_');        /* Look for replacements */
  689.    while (p1) {
  690.       *p1 = ' ';                    /* Put a blank instead */
  691.       p1++;
  692.       p1 = strchr(p1,'_');        /* Look for replacements */
  693.    }
  694.    x = strlen(p);
  695.    x = x > 29 ? 29 : x;
  696.    strncpy(describe,p,x);
  697.    describe[x] = '\0';
  698.    
  699.    p = strtok(NULL," \t");        /* Fetch filename */
  700.    if (!p)
  701.       return;        /* Invalid */
  702.    p1 = strchr(p,'_');        /* Look for replacements */
  703.    while (p1) {
  704.       *p1 = ' ';                    /* Put a blank instead */
  705.       p1++;
  706.       p1 = strchr(p1,'_');        /* Look for replacements */
  707.    }
  708.    x = strlen(p);
  709.    x = x > 13 ? 13 : x;
  710.    strncpy(fname,p,x);
  711.    fname[x] = '\0';
  712.    
  713.    p = strtok(NULL," \t");        /* Fetch command line */
  714.    if (!p)
  715.       return;        /* Invalid */
  716.    p1 = strchr(p,'_');        /* Look for replacements */
  717.    while (p1) {
  718.       *p1 = ' ';                    /* Put a blank instead */
  719.       p1++;
  720.       p1 = strchr(p1,'_');        /* Look for replacements */
  721.    }
  722.    x = strlen(p);
  723.    x = x > 39 ? 39 : x;
  724.    strncpy(cmndline,p,x);
  725.    cmndline[x] = '\0';
  726.    
  727.  
  728.    proto1 = (struct proto_st *) malloc(sizeof(struct proto_st));
  729.    if (proto1 == NULL)
  730.       aborterror(BADALLOC,NULL);
  731.  
  732.    if (totprotocols)
  733.       PROTO_cur->next = proto1;
  734.    else PROTO_1 = proto1;
  735.  
  736.    proto1->protoexe = (char *) malloc(strlen(fname) + 1);
  737.    if (proto1->protoexe == NULL)
  738.       aborterror(BADALLOC,NULL);
  739.    strcpy(proto1->protoexe,fname);
  740.  
  741.    proto1->protostring = (char *) malloc(strlen(cmndline) + 1);
  742.    if (proto1->protostring == NULL)
  743.       aborterror(BADALLOC,NULL);
  744.    strcpy(proto1->protostring,cmndline);
  745.  
  746.    proto1->protoname = (char *) malloc(strlen(describe) + 1);
  747.    if (proto1->protoname == NULL)
  748.       aborterror(BADALLOC,NULL);
  749.    strcpy(proto1->protoname,describe);
  750.  
  751.    PROTO_cur = proto1;
  752.    proto1->next = NULL;
  753.  
  754.    totprotocols++;
  755. }
  756.  
  757. /* Setup an upload protocol using string format as follows:
  758.    "Filename Commandline"
  759.         |          |----------- Command line for program.
  760.         |---------------------- Full filename (No path)
  761. */
  762.  
  763. void enable_upl(char *strng)
  764. {
  765.    char cmndline[40];
  766.    char fname[14];
  767.    char describe[20];
  768.    char *p,*p1;
  769.    int x;
  770.    struct repupl_st *upl1;
  771.  
  772.    p = strtok(strng," \t");        /* Fetch description */
  773.    if (!p)
  774.       return;        /* Invalid */
  775.    p1 = strchr(p,'_');        /* Look for replacements */
  776.    while (p1) {
  777.       *p1 = ' ';                    /* Put a blank instead */
  778.       p1++;
  779.       p1 = strchr(p1,'_');        /* Look for replacements */
  780.    }
  781.    x = strlen(p);
  782.    x = x > 29 ? 29 : x;
  783.    strncpy(describe,p,x);
  784.    describe[x] = '\0';
  785.    
  786.    p = strtok(NULL," \t");        /* Fetch filename */
  787.    if (!p)
  788.       return;        /* Invalid */
  789.    p1 = strchr(p,'_');        /* Look for replacements */
  790.    while (p1) {
  791.       *p1 = ' ';                    /* Put a blank instead */
  792.       p1++;
  793.       p1 = strchr(p1,'_');        /* Look for replacements */
  794.    }
  795.    x = strlen(p);
  796.    x = x > 13 ? 13 : x;
  797.    strncpy(fname,p,x);
  798.    fname[x] = '\0';
  799.    
  800.    p = strtok(NULL," \t");        /* Fetch command line */
  801.    if (!p)
  802.       return;        /* Invalid */
  803.    p1 = strchr(p,'_');        /* Look for replacements */
  804.    while (p1) {
  805.       *p1 = ' ';                    /* Put a blank instead */
  806.       p1++;
  807.       p1 = strchr(p1,'_');        /* Look for replacements */
  808.    }
  809.    x = strlen(p);
  810.    x = x > 39 ? 39 : x;
  811.    strncpy(cmndline,p,x);
  812.    cmndline[x] = '\0';
  813.    
  814.  
  815.    upl1 = (struct repupl_st *) malloc(sizeof(struct repupl_st));
  816.    if (upl1 == NULL)
  817.       aborterror(BADALLOC,NULL);
  818.  
  819.    if (!totuplreps)
  820.       REPUPL_1 = upl1;
  821.    else REPUPL_cur->next = upl1;
  822.  
  823.    upl1->protoexe = (char *) malloc(strlen(fname) + 1);
  824.    if (upl1->protoexe == NULL)
  825.       aborterror(BADALLOC,NULL);
  826.    strcpy(upl1->protoexe,fname);
  827.  
  828.    upl1->protostring = (char *) malloc(strlen(cmndline) + 1);
  829.    if (upl1->protostring == NULL)
  830.       aborterror(BADALLOC,NULL);
  831.    strcpy(upl1->protostring,cmndline);
  832.  
  833.    upl1->protoname = (char *) malloc(strlen(describe) + 1);
  834.    if (upl1->protoname == NULL)
  835.       aborterror(BADALLOC,NULL);
  836.    strcpy(upl1->protoname,describe);
  837.  
  838.    REPUPL_cur = upl1;
  839.    upl1->next = NULL;
  840.  
  841.    totuplreps++;
  842. }
  843.  
  844. /* Setup a packer using string format as follows:
  845.    "Description Filename ArcFname Commandline"
  846.         |           |       |        |------ Command line for program.
  847.         |           |       |
  848.         |           |       |--------------- Name of packed file
  849.         |           |
  850.         |           |---------------------- Full filename (No path)
  851.         |
  852.         |---------------------------------- Desribe packer in 1-2 words
  853. */
  854.  
  855. void enable_packer(char *strng)
  856. {
  857.    char cmndline[40];
  858.    char viewline[40];
  859.    char describe[20];
  860.    char fname[14];
  861.    char aname[14];
  862.    char *p,*p1;
  863.    int x;
  864.    struct packer_st *pack1;
  865.  
  866.  
  867.    p = strtok(strng," \t");        /* Fetch description */
  868.    if (!p)
  869.       return;        /* Invalid */
  870.    p1 = strchr(p,'_');        /* Look for replacements */
  871.    while (p1) {
  872.       *p1 = ' ';                    /* Put a blank instead */
  873.       p1++;
  874.       p1 = strchr(p1,'_');        /* Look for replacements */
  875.    }
  876.    x = strlen(p);
  877.    x = x > 29 ? 29 : x;
  878.    strncpy(describe,p,x);
  879.    describe[x] = '\0';
  880.    
  881.    p = strtok(NULL," \t");        /* Fetch filename */
  882.    if (!p)
  883.       return;        /* Invalid */
  884.    p1 = strchr(p,'_');        /* Look for replacements */
  885.    while (p1) {
  886.       *p1 = ' ';                    /* Put a blank instead */
  887.       p1++;
  888.       p1 = strchr(p1,'_');        /* Look for replacements */
  889.    }
  890.    x = strlen(p);
  891.    x = x > 13 ? 13 : x;
  892.    strncpy(fname,p,x);
  893.    fname[x] = '\0';
  894.    
  895.    p = strtok(NULL," \t");        /* Fetch packed filename */
  896.    if (!p)
  897.       return;        /* Invalid */
  898.    p1 = strchr(p,'_');        /* Look for replacements */
  899.    while (p1) {
  900.       *p1 = ' ';                    /* Put a blank instead */
  901.       p1++;
  902.       p1 = strchr(p1,'_');        /* Look for replacements */
  903.    }
  904.    x = strlen(p);
  905.    x = x > 13 ? 13 : x;
  906.    strncpy(aname,p,x);
  907.    aname[x] = '\0';
  908.    
  909.    p = strtok(NULL," \t");        /* Fetch command line */
  910.    if (!p)
  911.       return;        /* Invalid */
  912.    p1 = strchr(p,'_');        /* Look for replacements */
  913.    while (p1) {
  914.       *p1 = ' ';                    /* Put a blank instead */
  915.       p1++;
  916.       p1 = strchr(p1,'_');        /* Look for replacements */
  917.    }
  918.    x = strlen(p);
  919.    x = x > 39 ? 39 : x;
  920.    strncpy(cmndline,p,x);
  921.    cmndline[x] = '\0';
  922.    
  923.    viewline[0] = '\0';
  924.    p = strtok(NULL," \t");        /* Fetch viewline */
  925.    if (p) {
  926.       p1 = strchr(p,'_');        /* Look for replacements */
  927.       while (p1) {
  928.          *p1 = ' ';                    /* Put a blank instead */
  929.          p1++;
  930.          p1 = strchr(p1,'_');        /* Look for replacements */
  931.       }
  932.       x = strlen(p);
  933.       x = x > 39 ? 39 : x;
  934.       strncpy(viewline,p,x);
  935.       viewline[x] = '\0';
  936.    }
  937.    
  938.    pack1 = (struct packer_st *) malloc(sizeof(struct packer_st));
  939.    if (pack1 == NULL)
  940.       aborterror(BADALLOC,NULL);
  941.  
  942.    if (totpackers) 
  943.       PACKER_cur->next = pack1;
  944.    else PACKER_1 = pack1;        /* Start up linked list */
  945.  
  946.    pack1->viewstring = NULL;
  947.  
  948.    pack1->packexe = (char *) malloc(strlen(fname) + 1);
  949.    if (pack1->packexe == NULL)
  950.       aborterror(BADALLOC,NULL);
  951.    strcpy(pack1->packexe,fname);
  952.  
  953.    pack1->packstring = (char *) malloc(strlen(cmndline) + 1);
  954.    if (pack1->packstring == NULL)
  955.       aborterror(BADALLOC,NULL);
  956.    strcpy(pack1->packstring,cmndline);
  957.  
  958.    if (viewline[0]) {
  959.       pack1->viewstring = (char *) malloc(strlen(viewline) + 1);
  960.       if (pack1->viewstring == NULL)
  961.          aborterror(BADALLOC,NULL);
  962.       strcpy(pack1->viewstring,viewline);
  963.    }
  964.  
  965.    pack1->packname = (char *) malloc(strlen(describe) + 1);
  966.    if (pack1->packname == NULL)
  967.       aborterror(BADALLOC,NULL);
  968.    strcpy(pack1->packname,describe);
  969.  
  970.    pack1->packpname = (char *) malloc(strlen(aname) + 1);
  971.    if (pack1->packpname == NULL)
  972.       aborterror(BADALLOC,NULL);
  973.    strcpy(pack1->packpname,aname);
  974.  
  975.    PACKER_cur = pack1;
  976.    pack1->next = NULL;
  977.  
  978.    totpackers++;
  979. }
  980.  
  981.  
  982.