home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / bbs_opus / newmlupd.arj / NEWMLUPD.C next >
C/C++ Source or Header  |  1990-12-29  |  12KB  |  383 lines

  1.  
  2. /* Quasi-Replacement for ML-UPDATE Copyright 1988, Doug Boone */
  3.  
  4. /* compiled with Turbo C 2.0  */
  5.  
  6. #include    <dir.h>
  7. #include    <stdio.h>
  8. #include    <stdlib.h>
  9. #include    <string.h>
  10. #include    <ctype.h>
  11. #include    <time.h>
  12. #include    <alloc.h>
  13. #include    <process.h>
  14. #include    <fcntl.h>
  15. #include    <conio.h>
  16.  
  17. typedef unsigned int  word;
  18. typedef unsigned char byte;
  19.  
  20. #include    "nfile.h"
  21.  
  22. #define     EOS         '\0'
  23. #define     MAX_PATH    82
  24.  
  25. #define     DIRECT      0x01
  26. #define     HOLD        0x02
  27. #define     CRASH       0x04
  28. #define     SHRINK      0x10
  29. #define     DELETE      0x20
  30.  
  31. char    *find_parm(char *,int);
  32. void    go_4_it(void);
  33.  
  34. struct  _list   {
  35.     int     area;
  36.     struct  _list *next;
  37. };
  38.  
  39. struct  _list   *head;
  40. struct  _list   *current;
  41. struct  _list   *next;
  42.  
  43. FILE    *output;
  44.  
  45. main(int argc,char *argv[])
  46. {
  47.     FILE    *config;
  48.  
  49.     char    one_line[120];
  50.     char    *result;
  51.  
  52.     char    *conf_path = "MLUPD.CFG";
  53.     char    out_path[MAX_PATH];
  54.  
  55.     char    address[25];        /* Zone:Net/Node.Point */
  56.     char    add_name[12];
  57.     char    password[16];        /* ML-UPD password */
  58.     char    phone[20];        /* Phone number */
  59.     char    baud[6];        /* baud rate */
  60.     char    name[MAX_PATH];        /* Board name */
  61.     char    comment_1[MAX_PATH];        /* comments for file */
  62.     char    comment_2[MAX_PATH];
  63.     char    outbound[MAX_PATH];
  64.     char    packer[MAX_PATH];
  65.     char    collector[20];
  66.     int     this_area;
  67.     int     mail = 0;        /* How to mail the output file */
  68.     int     i;
  69.     int     do_head = 0;
  70.     int        infile = 0;
  71.     long    now;
  72.     struct  tm  *timept;
  73.  
  74.  
  75.     cputs("MLUPD by Doug Boone, FidoNet 119/5 Copyright 1990, ? for help\n\r");
  76.  
  77.     head = current = next = NULL;
  78.  
  79.     if (argc > 1)
  80.         conf_path = argv[1];
  81.  
  82.     else if ((result = getenv("PENGUIN")) != NULL) {
  83.         conf_path = result;
  84.         infile = 0;
  85.         }
  86.  
  87.     if (strchr(conf_path,'?')) {
  88.         cputs("\n\r\n\r Build ML-UPD compatible file for ML-COL and ML-FIND. But uses cofiguration\n\r");
  89.         cputs(" file instead of SYSTEM*.BBS files. (makes it QuickBBS compatible) Also expands\n\r");
  90.         cputs(" wildcards for Opus systems.\n\r\n\rUsage:\n\r");
  91.         cputs("MLUPD [config.fil] \n\r\n\r Configuration name is optional, default to 'MLUPD.CFG'\n\r\n\r");
  92.         cputs("Contact Doug Boone at FidoNet 119/5 if you find any problems. (916) 893-9019\n\r");
  93.         cputs(" Copyright 1988\n\r\n\r");
  94.         exit(5);
  95.         }
  96.  
  97.     if ((config = fopen(conf_path,"rt")) == NULL) {
  98.         perror("Failed to open configuration file ");
  99.         exit(2);
  100.         }
  101.  
  102.     memset(&comment_2,EOS,MAX_PATH);
  103.     memset(&comment_1,EOS,MAX_PATH);
  104.     memset(&collector,EOS,20);
  105.     memset(&packer,EOS,MAX_PATH);
  106.     memset(&outbound,EOS,MAX_PATH);
  107.     memset(&baud,EOS,6);
  108.  
  109.     while ((result = fgets(one_line,90,config)) != NULL) {
  110.         if ((result = strrchr(one_line,'\n')) != NULL)    /* get rid of trailing \n */
  111.             *result = EOS;
  112.         if ((result = strchr(one_line,';')) != NULL)        /* get rid of comments */
  113.             *result = EOS;
  114.         if (!(one_line[0]))
  115.             continue;
  116.  
  117.         if (strnicmp(one_line,"BEGIN",5) == 0) {
  118.             result = find_parm(one_line,5);
  119.             if (strnicmp(result,"MLUPD",5) == 0)
  120.                 infile++;
  121.             continue;
  122.             }
  123.         if (infile > 0 ) {            /* we're inside the MLUPD section */
  124.             if (strnicmp(one_line,"ADDRESS",7) == 0) {
  125.                 result = find_parm(one_line,7);
  126.                 strcpy(address,result);
  127.                 if ((result = strchr(address,' ')) != NULL)
  128.                     *result = EOS;
  129.                 if ((result = strchr(address,':')) != NULL)
  130.                     i = atoi(++result);
  131.                 else
  132.                     i = atoi(address);
  133.                 result = strchr(address,'/');
  134.                 result++;
  135.                 sprintf(add_name,"%04X%04X",i,atoi(result));
  136.                 sprintf(out_path,"%04X%04X.MLU",i,atoi(result));
  137.                 if ((output = fopen(out_path,"wt")) == NULL) {
  138.                     fclose(config);
  139.                     perror("Failed to open output file");
  140.                     exit(3);
  141.                     }
  142.                 }
  143.  
  144.             else if (strnicmp(one_line,"PASSWORD",8) == 0) {
  145.                 result = find_parm(one_line,8);
  146.                 strcpy(password,result);
  147.                 if ((result = strchr(password,' ')) != NULL)
  148.                     *result = EOS;
  149.                 }
  150.  
  151.             else if (strnicmp(one_line,"PHONE",5) == 0) {
  152.                 result = find_parm(one_line,5);
  153.                 strcpy(phone,result);
  154.                 strcpy(one_line,phone);
  155.                 memset(&phone,EOS,20);
  156.                 i=0;
  157.                 result = one_line;
  158.                 do {
  159.                     if (isdigit(*result)) {
  160.                         phone[i] = *result;
  161.                         i++;
  162.                         }
  163.                     result++;
  164.                     } while (*result != NULL && i<20);
  165.                 }
  166.  
  167.             else if (strnicmp(one_line,"BAUD",4) == 0) {
  168.                 int i;
  169.                 result = find_parm(one_line,4);
  170.                 for (i=0;i<6 && *result>' ';i++,result++)
  171.                     baud[i] = *result;
  172.                 }
  173.  
  174.             else if (strnicmp(one_line,"name",4) == 0) {
  175.                 result = find_parm(one_line,4);
  176.                 strcpy(name,result);
  177.                 }
  178.  
  179.             else if (strnicmp(one_line,"comment:",8) == 0){
  180.                 result = one_line + 8*(sizeof(char));
  181.                 if (strlen(comment_1) == 0)
  182.                     strcpy(comment_1,result);
  183.                 else
  184.                     strcpy(comment_2,result);
  185.                 }
  186.  
  187.             else if (strnicmp(one_line,"scan",4) == 0) {
  188.                 result = find_parm(one_line,4);
  189.                 if (!head) {
  190.                     head = (struct _list *) malloc(sizeof(struct _list));
  191.                     current = head;
  192.                     }
  193.                 else {
  194.                     current->next = (struct _list *) malloc(sizeof(struct _list));
  195.                     current = current->next;
  196.                     }
  197.                 current->next = NULL;
  198.                 current->area = atoi(result);
  199.                 }        /* end of scan */
  200.  
  201.             else if (strnicmp(one_line,"packer",6) == 0) {
  202.                 result = find_parm(one_line,6);
  203.                 strcpy(packer,result);
  204.                 }
  205. /* Shrink or Delete the outbound file after mailing? */
  206.             else if (strnicmp(one_line,"shrink",6) == 0) {
  207.                 mail |= SHRINK;
  208.                 }
  209.  
  210.             else if (strnicmp(one_line,"delete",6) == 0) {
  211.                 mail |= DELETE;
  212.                 }
  213. /* Decide how to handle outbound mail attach */
  214.             else if (strnicmp(one_line,"hold",4) == 0) {
  215.                 mail |= HOLD;
  216.                 }
  217.             else if (strnicmp(one_line,"direct",6) == 0) {
  218.                 mail |= DIRECT;
  219.                 }
  220.             else if (strnicmp(one_line,"crash",5) == 0) {
  221.                 mail |= CRASH;
  222.                 }
  223.  
  224.             else if (strnicmp(one_line,"outbound",8) == 0) {
  225.                 result = find_parm(one_line,8);
  226.                 strcpy(outbound,result);
  227.                 if ((result = strchr(outbound,' ')) != NULL)
  228.                     *result = EOS;
  229.                 i = strlen(outbound) -1;
  230.                 if (outbound[i] != '\\')
  231.                     strcat(outbound,"\\");
  232.                 }
  233.  
  234.             else if (strnicmp(one_line,"collector",9) == 0) {
  235.                 result = find_parm(one_line,9);
  236.                 strcpy(collector,result);
  237.                 if ((result = strchr(collector,':')) != NULL) {
  238.                     result++;
  239.                     strcpy(one_line,result);
  240.                     strcpy(collector,one_line);
  241.                     }
  242.                 if ((result = strchr(collector,' ')) != NULL)
  243.                     *result = EOS;
  244.                 }
  245.             else if (strnicmp(one_line,"end",3) == 0) {
  246.                 result = find_parm(one_line,3);
  247.                 if (strnicmp(result,"MLUPD",5) == 0)
  248.                     infile = 0;
  249.                 }
  250.             }        /* end of parsing configuration lines */
  251.         }; 
  252.  
  253.     time(&now);
  254.     timept = localtime(&now);
  255.     fprintf(output,"* Created by MLUPD %s",ctime(&now));
  256.     fprintf(output,"%s\n",address);
  257.     fprintf(output,"%02d%02d%02d %s\n",timept->tm_year,
  258.         (1+timept->tm_mon),timept->tm_mday,password);
  259.     fprintf(output,"%s\n",phone);
  260.     fprintf(output,"%s\n",baud);
  261.     fprintf(output,"%s\n",name);
  262.     fprintf(output,"%s\n",comment_1);
  263.     fprintf(output,"%s\n",comment_2);
  264.     go_4_it();
  265.     fprintf(output,"*EOF");
  266.     flushall();
  267.     fclose(config);
  268.     fclose(output);
  269.     do_head = 0;
  270.     if (strlen(packer) > 0) {
  271.         sprintf(one_line,"%s.MLA",add_name);
  272.         unlink(one_line);
  273.         if ((result = strchr(packer,' ')) != NULL) {
  274.             *result = EOS;
  275.             result++;
  276.             if (strnicmp(packer,"arca",4) == 0)
  277.                 do_head = spawnlp(P_WAIT,packer,packer,one_line,out_path,result,NULL);
  278.             else
  279.                 do_head = spawnlp(P_WAIT,packer,packer,result,one_line,out_path,NULL);
  280.             }
  281.         else
  282.             do_head = spawnlp(P_WAIT,packer,packer,one_line,out_path,NULL);
  283.         }
  284.  
  285.     if (strlen(outbound) > 0 &&
  286.         strlen(collector) > 0) {
  287.         i = atoi(collector);
  288.         result = strchr(collector,'/');
  289.         ++result;
  290.         if (mail & CRASH)
  291.             sprintf(name,"%s%04X%04X.CLO",outbound,i,atoi(result));
  292.         else if (mail & HOLD)
  293.             sprintf(name,"%s%04X%04X.HLO",outbound,i,atoi(result));
  294.         else
  295.             sprintf(name,"%s%04X%04X.DLO",outbound,i,atoi(result));
  296.         if ((output = fopen(name,"at")) != NULL) {
  297.             getcwd(one_line,MAX_PATH);
  298.             strcat(one_line,"\\");
  299.             strcat(one_line,add_name);
  300.             if (do_head == 0)
  301.                 strcat(one_line,".MLA");
  302.             else
  303.                 strcat(one_line,".MLU");
  304.             if (mail & SHRINK)
  305.                 fprintf(output,"#%s\n",one_line);
  306.             else if (mail & DELETE)
  307.                 fprintf(output,"^%s\n",one_line);
  308.             else
  309.                 fprintf(output,"%s\n",one_line);
  310.             fclose(output);
  311.             }
  312.         else {
  313.             cputs("\n\rFailed to open mail file!\n\r");
  314.             free(one_line);
  315.             exit(5);
  316.             }
  317.         }
  318.     free(one_line);
  319.     exit(do_head);
  320.     return;
  321. }
  322.  
  323. char    *find_parm(char *line,int  start)
  324. {
  325.     char    *step;
  326.  
  327.     step = line+start;
  328.     while (isspace(*step) != 0)
  329.         step++;
  330.     return(step);
  331. }
  332.  
  333.  
  334. void go_4_it()
  335. {
  336.     struct  _afile  afile;
  337.     struct  _numb_idx   nidx;
  338.     int     datfh;
  339.     int     ndxfh;
  340.     long    next_key;
  341.     long    pos;
  342.  
  343.     current = head;
  344.     datfh = open("FILESBBS.DAT",O_RDONLY|O_BINARY);
  345.     ndxfh = open("FILESBBS.ADX",O_RDONLY|O_BINARY);
  346.  
  347.     while (current != NULL) {
  348.         lseek(ndxfh,0L,SEEK_SET);
  349.         printf("\nWorking on area: %d",current->area);
  350.         while (((read(ndxfh,(char *)&nidx,sizeof(struct _numb_idx))) == sizeof(struct _numb_idx)) &&
  351.             (nidx.area_number != current->area));
  352.         if (nidx.area_number == current->area) {
  353. NEXT:       lseek(datfh,nidx.pos,SEEK_SET);
  354.             while ((read(datfh,(char *)&afile,sizeof(struct _afile))) == sizeof(struct _afile)) {
  355.                 if (afile.area_number != current->area) {
  356.                     if (next_key != 0L) {
  357.                         nidx.pos = next_key;
  358.                         next_key = 0;
  359.                         goto NEXT;
  360.                         }
  361.                     else
  362.                         goto Change;
  363.                     }
  364.                 pos = (long) afile.altpath_len;
  365.                 pos += (long) afile.upld_by_len;
  366.                 pos += (long) afile.descr_len;
  367.                 lseek(datfh,pos,SEEK_CUR);
  368.                 if (afile.nxt_key != 0L)
  369.                     next_key = afile.nxt_key;
  370.                 if ((afile.aflag & IS_FILE) && (!(afile.aflag & (MISSING|DELETED|STAR_NAME))) && (afile.dl_priv < 0x80))
  371.                     fprintf(output,"%-12s   %2d  %3d\n",afile.name,afile.area_number,(afile.size/1024L));
  372.                 }        /* end of reading datfh */
  373.             }        /* End of one area */
  374. Change:    next = current->next;
  375.         free(current);
  376.         current = next;
  377.         }
  378.     close(datfh);
  379.     close(ndxfh);
  380.     return;
  381. }
  382.  
  383.