home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / bbs / tmlman03 / tml_man.c < prev    next >
C/C++ Source or Header  |  1994-04-13  |  26KB  |  1,069 lines

  1. /* T-Mail Data Structur Manager
  2.     by Wolfgang Zweygart
  3.     Start of Project:      24.12.1993
  4.     Version: see VERSION
  5. */
  6.  
  7. /* History:
  8.     0.01a        24.12.1993        Where it all starts....
  9.     0.02        20.02.1994        Address statement added
  10.     0.03        04.04.1994        Commandline options and Help added
  11. */
  12.  
  13. #define VERSION "0.03"
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <math.h>
  19. #include <tos.h>
  20. #include <ext.h>
  21. #include <ctype.h>
  22.  
  23. #define min(a, b)    ((a) < (b) ? (a) : (b))
  24. #define max(a, b)    ((a) > (b) ? (a) : (b))
  25. #define EOS    '\0'        /* end-of-string indicator */
  26.  
  27. enum _bool
  28.    {
  29.       FALSE,
  30.       TRUE
  31.    };
  32.  
  33. typedef enum _bool  boolean;
  34. const char **envi; /* noch ein Environment-pointer */
  35.  
  36. #define MAX_SIG 10
  37.  
  38. struct DOM_ADR
  39. {
  40.     int Zone;
  41.     int Net;
  42.     int Node;
  43.     int Point;
  44.     char Outbound[40];
  45. };
  46.  
  47. struct Q_ARC
  48. {
  49.     char name[3];
  50.     char path[50];
  51.     char para_ext[20];
  52.     char para_add[20];
  53. };
  54.  
  55. struct SIG_S
  56. {
  57.     char name[24];
  58.     long level;
  59.     char description[45];
  60. };
  61.  
  62. struct AREA_S
  63. {
  64.     char filename[50];
  65.     char Tagname[14];
  66.     char description[50];
  67.     long access;
  68.     long flags;
  69.     char Area_header[285];
  70.     boolean found;
  71. };
  72.  
  73. struct TML_BODY
  74. {
  75.     int total_mes;
  76.     int total_mail;
  77.     int bbs_type;
  78.     long echos_sig;
  79.     char sysop_name[32];
  80.     char led_point[52];
  81.     char ProtInbound[52];
  82.     char KnownInbound[52];
  83.     char Inbound[52];
  84.     char NetMail[52];
  85.     int qwk_confs;
  86.     long system_flags;
  87.     long write_access;
  88.     int inacti_days;
  89.     char temp_file[52];
  90.     char log_file[52];
  91.     char transfer[52];
  92.     int gate_zone;
  93.     int gate_net;
  94.     int gate_node;
  95.     int gate_point;
  96.     int inet_zone;
  97.     int inet_net;
  98.     int inet_node;
  99.     int inet_point;
  100.     struct DOM_ADR domains[12];
  101.     char NetMail_menu[285];
  102.     char SIGs_menu[285];
  103.     char Echo_menu[285];
  104.     char Qmail_menu[285];
  105. /*    char reserved[10];    */
  106.     int Q_max_packet;
  107.     int Q_max_mes;
  108.     char Q_phone[15];
  109.     char Q_short_name[9];
  110.     char Q_location[24];
  111.     char Q_work_dir[40];
  112.     char Q_system_name[28];
  113.     struct Q_ARC Q_archivers[5];
  114.     struct SIG_S SIGs[MAX_SIG];
  115. };
  116.  
  117. struct TML_BODY tml_body;
  118. struct AREA_S *areas;
  119. char tmail_path[128];
  120. char areas_path[128];
  121. boolean save_data = FALSE;
  122. boolean cross_check = FALSE;
  123. char exclude_groups[40];
  124. char to_add_groups[40];
  125. long dev_access;
  126. char dev_description[50];
  127. long dev_flags;
  128. int swap_dest;
  129. int swap_source;
  130. boolean swap_flag = FALSE;
  131.  
  132. struct AREA_T
  133. {
  134.     char *origin;
  135.     char group;
  136.     char *randorigin;
  137.     char *path;
  138.     char *name;
  139.     boolean found;
  140. };
  141.  
  142. struct AREA_T areabb[500];
  143. char *main_origin;
  144. int msgareas;
  145. int users;            /* # of users in Tmail.ptr */
  146.  
  147. struct S_P
  148. {
  149.     char new_name[25];
  150.     char group[10];
  151.     long level;
  152.     char description[45];
  153. };
  154.  
  155. struct S_P sig_preset[MAX_SIG];
  156. boolean loging = FALSE;
  157. char *logfile;
  158. FILE *logf;
  159. boolean info = FALSE;
  160.  
  161. struct ADR
  162. {
  163.     int Zone;
  164.     int Net;
  165.     int Node;
  166.     int Point;
  167.     char *Outbound;
  168.     char adr_flag;
  169. };
  170.  
  171. struct ADR new_adr[12];
  172. int cur_adr = 0;
  173.  
  174. boolean dcd = FALSE;        /* carrier detect    */
  175.  
  176. void cd_check(void)
  177. {
  178. long old_stack;
  179. char *gpip;
  180. char test;
  181.  
  182.     gpip=(char *)0xFFFFFA01L;
  183.     old_stack = Super(0L);
  184.     test= *gpip;    
  185.     Super((void *) old_stack);
  186.     if (test & 2) dcd=FALSE; else dcd=TRUE;
  187. }
  188.  
  189. int printf(const char *format, ...)
  190. {
  191.  va_list arg_point;
  192.  char temp[255];
  193.  char *s;
  194.  char c;
  195.  int chs;
  196.  
  197.  va_start(arg_point, format);
  198.  chs=vsprintf(temp, format, arg_point);
  199.  if(loging && logf!=NULL) fputs(temp,logf);
  200.  cd_check();
  201.  s=temp;
  202.  while ((c = *s++) !=0)
  203.   {
  204.     if(dcd) if(Bcostat(1)==0) break;
  205.     if(c == 10)    /* LF */
  206.      {
  207.         if(dcd) Bconout(1,13);
  208.         Bconout(2,13);
  209.      }
  210.     if(dcd) Bconout(1,(int)c);
  211.     Bconout(2,(int)c);
  212.   }
  213.  va_end(arg_point);
  214.  return(chs);
  215. }
  216.  
  217.  
  218. void read_tml_area(FILE *fp, int i)
  219. {
  220.  fread(&areas[i].filename,50,1,fp);
  221.  fread(&areas[i].Tagname,12,1,fp);
  222.  fread(&areas[i].description,50,1,fp);
  223.  fread(&areas[i].access,4,2,fp);
  224.  fread(&areas[i].Area_header,285,1,fp);
  225. }
  226.  
  227. void write_tml_area(FILE *fp, int i)
  228. {
  229.  fwrite(&areas[i].filename,50,1,fp);
  230.  fwrite(&areas[i].Tagname,12,1,fp);
  231.  fwrite(&areas[i].description,50,1,fp);
  232.  fwrite(&areas[i].access,4,2,fp);
  233.  fwrite(&areas[i].Area_header,285,1,fp);
  234. }
  235.  
  236. void read_tml_dat(void)
  237. {
  238.  FILE *fp;
  239.  int i;
  240.  char file[128];
  241.  
  242.  strcpy(file,tmail_path);
  243.  strcat(file,"TMAIL.DAT");
  244.  memset(&tml_body,0,sizeof(tml_body));
  245.  fp=fopen(file,"rb");
  246.  if(fp==NULL) return;
  247.  fread(&tml_body,2,3,fp);
  248.  fread(&(tml_body.echos_sig),4,1,fp);
  249.  fread(&tml_body.sysop_name,31,1,fp);
  250.  fread(&tml_body.led_point,50,1,fp);
  251.  fread(&tml_body.ProtInbound,50,1,fp);
  252.  fread(&tml_body.KnownInbound,50,1,fp);
  253.  fread(&tml_body.Inbound,50,1,fp);
  254.  fread(&tml_body.NetMail,50,1,fp);
  255.  fread(&tml_body.qwk_confs,2,1,fp);
  256.  fread(&tml_body.system_flags,4,2,fp);
  257.  fread(&tml_body.inacti_days,2,1,fp);
  258.  fread(&tml_body.temp_file,50,1,fp);
  259.  fread(&tml_body.log_file,50,1,fp);
  260.  fread(&tml_body.transfer,50,1,fp);
  261.  fread(&tml_body.gate_zone,2,8,fp);
  262.  fread(&tml_body.domains[0],48,12,fp);
  263.  fread(&tml_body.NetMail_menu,1140,1,fp);
  264.  fread(&tml_body.Q_max_packet,2,2,fp);
  265.  fread(&tml_body.Q_phone,13,1,fp);
  266.  fread(&tml_body.Q_short_name,8,1,fp);
  267.  fread(&tml_body.Q_location,22,1,fp);
  268.  fread(&tml_body.Q_work_dir,40,1,fp);
  269.  fread(&tml_body.Q_system_name,27,1,fp);
  270.  for(i=0; i<5; i++) fread(&tml_body.Q_archivers[i],93,1,fp);
  271.  for(i=0; i<MAX_SIG; i++) fread(&tml_body.SIGs[i],73,1,fp);
  272.  
  273.  areas=calloc(tml_body.echos_sig * MAX_SIG, sizeof(struct AREA_S));
  274.  if(areas==NULL) return;
  275.  for(i=0; i<(int)tml_body.echos_sig * MAX_SIG; i++) read_tml_area(fp,i);
  276.  
  277.  fclose(fp);
  278. }
  279.  
  280. void write_tml_dat(void)
  281. {
  282.  FILE *fp;
  283.  int i;
  284.  char file[128];
  285.  
  286.  strcpy(file,tmail_path);
  287.  strcat(file,"TMAIL.DAT");
  288.  fp=fopen(file,"wb");
  289.  if(fp==NULL) return;
  290.  fwrite(&tml_body,2,3,fp);
  291.  fwrite(&(tml_body.echos_sig),4,1,fp);
  292.  fwrite(&tml_body.sysop_name,31,1,fp);
  293.  fwrite(&tml_body.led_point,50,1,fp);
  294.  fwrite(&tml_body.ProtInbound,50,1,fp);
  295.  fwrite(&tml_body.KnownInbound,50,1,fp);
  296.  fwrite(&tml_body.Inbound,50,1,fp);
  297.  fwrite(&tml_body.NetMail,50,1,fp);
  298.  fwrite(&tml_body.qwk_confs,2,1,fp);
  299.  fwrite(&tml_body.system_flags,4,2,fp);
  300.  fwrite(&tml_body.inacti_days,2,1,fp);
  301.  fwrite(&tml_body.temp_file,50,1,fp);
  302.  fwrite(&tml_body.log_file,50,1,fp);
  303.  fwrite(&tml_body.transfer,50,1,fp);
  304.  fwrite(&tml_body.gate_zone,2,8,fp);
  305.  fwrite(&tml_body.domains[0],48,12,fp);
  306.  fwrite(&tml_body.NetMail_menu,1140,1,fp);
  307.  fwrite(&tml_body.Q_max_packet,2,2,fp);
  308.  fwrite(&tml_body.Q_phone,13,1,fp);
  309.  fwrite(&tml_body.Q_short_name,8,1,fp);
  310.  fwrite(&tml_body.Q_location,22,1,fp);
  311.  fwrite(&tml_body.Q_work_dir,40,1,fp);
  312.  fwrite(&tml_body.Q_system_name,27,1,fp);
  313.  for(i=0; i<5; i++) fwrite(&tml_body.Q_archivers[i],93,1,fp);
  314.  for(i=0; i<MAX_SIG; i++) fwrite(&tml_body.SIGs[i],73,1,fp);
  315.  for(i=0; i<(int)tml_body.echos_sig * MAX_SIG; i++) write_tml_area(fp,i);
  316.  fclose(fp);
  317. }
  318.  
  319. void read_tml_ptr(void)
  320. {
  321.  FILE *fp;
  322.  char file[128];
  323.  long filesi;
  324.  
  325.  strcpy(file,tmail_path);
  326.  strcat(file,"TMAIL.PTR");
  327.  fp=fopen(file,"rb");
  328.  if(fp==NULL) exit(-2);
  329.  fseek(fp,0,SEEK_END);
  330.  filesi = ftell(fp);
  331.  users = (int) ((filesi - 5L)/(5L*MAX_SIG*(tml_body.echos_sig+1L)));
  332.  fclose(fp);
  333. }
  334.  
  335. char *skip_after_blanks(char *string)
  336. {
  337.     char *q = &string[strlen(string)-1];
  338.     while (isspace(*q)) q--;
  339.     *++q = EOS;
  340.     return(string);
  341. }
  342.  
  343. char *skip_blanks(char *string)
  344. {
  345.     while (*string && isspace(*string)) string++;
  346.     return(string);
  347. }
  348.  
  349. char *skip_to_blank(char *string)
  350. {
  351.     while (*string && !isspace(*string)) string++;
  352.     return(string);
  353. }
  354.  
  355. char *ctl_string(char *string)
  356. {
  357.  char *p = skip_blanks(string),
  358.         *d = (char *) malloc(strlen(p)+1);
  359.     
  360.  if (d == NULL)
  361.     {
  362.         printf("String allocation failed.\n");
  363.         return("");
  364.     }
  365.     p = skip_after_blanks(p);
  366.     strcpy(d, p);
  367.     return(d);
  368. }
  369.  
  370. char *ctl_file(char *str)
  371. {
  372.     char *q;
  373.     
  374.     str = skip_blanks(str);
  375.     for (q = str; *q && !isspace(*q); q++);
  376.     *q = EOS;
  377.     return(ctl_string(str));
  378. }
  379.  
  380. void address_4d(char *s, int *zone, int *net, int *node, int *point)
  381. {
  382.     char *p = s,
  383.         n[9],
  384.         have = 0;
  385.     int i = 0;
  386.     
  387.     if (!s) return;
  388.     *zone = 0;
  389.     *net = 0;
  390.     *node = 0;
  391.     *point = 0;
  392.     
  393.     do
  394.     {
  395.         while (*p != ':' && *p != '/' && *p != '.' && *p != EOS &&
  396.                 *p != ' ' && *p != '\t' && *p !='@') n[i++] = *p++;
  397.         
  398.         n[i] = EOS;
  399.         
  400.         if (!strlen(n))
  401.         {
  402.             if (*p == EOS) return;
  403.             p = skip_blanks(++p);
  404.             continue;
  405.         }
  406.         
  407.         if (!isdigit(n[0])) return;
  408.         
  409.         if (!have && *p == ':')    *zone = atoi(n);
  410.         else if (have == 1 || *p == '/')
  411.         {
  412.             *net = atoi(n);
  413.             have = 1;
  414.         }
  415.         else if (have == 2) *node = atoi(n);
  416.         else if (have == 3) *point = atoi(n);
  417.         have++;
  418.         
  419.         if (*p == EOS) return;
  420.         p = skip_blanks(++p);
  421.         i = 0;
  422.         
  423.     } while (*p != '\r', have < 4);
  424. }
  425.  
  426. void read_cfg(void)
  427. {
  428.  FILE *fd;
  429.  char buffer[256];
  430.  char temp[256];
  431.  char *p,*q;
  432.  int line =0;
  433.  int i;
  434.  
  435.  memset(sig_preset,0,sizeof(sig_preset));
  436.  if((fd = fopen("TML_MAN.CFG","r")) == NULL)
  437.     {
  438.         printf("No TML_MAN.CFG -file found!\n");
  439.         return;
  440.     }
  441.  while((fgets(buffer,255,fd)))
  442.     {
  443.         line++;
  444.         p = skip_blanks(buffer);
  445.         if (*p == ';') continue;
  446.         if ((i = (int)strlen(p)) < 3) continue;
  447.         if ((p = strchr(buffer, ';')) != NULL) *p = EOS;
  448.         p = &buffer[--i];
  449.         if (*p == '\r' || *p == '\n') *p = EOS;
  450.         p = skip_blanks(buffer);
  451.  
  452.         if(!strnicmp(p, "tmailpath", 9))
  453.          {
  454.             p = skip_blanks(&p[9]);
  455.             p = skip_after_blanks(p);
  456.             strncpy(tmail_path, p, 127);
  457.             tmail_path[127] = EOS;
  458.             continue;
  459.          }
  460.         if(!strnicmp(p, "areaspath", 9))
  461.          {
  462.             p = skip_blanks(&p[9]);
  463.             p = skip_after_blanks(p);
  464.             strncpy(areas_path, p, 127);
  465.             areas_path[127] = EOS;
  466.             continue;
  467.          }
  468.         if(!strnicmp(p,"savedata",8))
  469.          {
  470.             save_data = TRUE;
  471.             continue;
  472.          }
  473.         if(!strnicmp(p,"crosscheck",10))
  474.          {
  475.             cross_check = TRUE;
  476.             continue;
  477.          }
  478.         if(!strnicmp(p, "exclude", 7))
  479.          {
  480.             p = skip_blanks(&p[7]);
  481.             p = skip_after_blanks(p);
  482.             strncpy(exclude_groups, p, 39);
  483.             exclude_groups[39] = EOS;
  484.             continue;
  485.          }
  486.         if(!strnicmp(p, "autoadd", 7))
  487.          {
  488.             p = skip_blanks(&p[7]);
  489.             p = skip_after_blanks(p);
  490.             strncpy(to_add_groups, p, 39);
  491.             to_add_groups[39] = EOS;
  492.             continue;
  493.          }
  494.         if(!strnicmp(p, "access", 6))
  495.          {
  496.             p = skip_blanks(&p[6]);
  497.             dev_access = atol(p);
  498.             continue;
  499.          }
  500.         if(!strnicmp(p, "description", 11))
  501.          {
  502.             p = skip_blanks(&p[11]);
  503.             strncpy(dev_description, p, 49);
  504.             dev_description[49] = EOS;
  505.             continue;
  506.          }
  507.         if(!strnicmp(p, "flags", 5))
  508.          {
  509.             p = skip_blanks(&p[5]);
  510.             dev_flags = atol(p);
  511.             continue;
  512.          }
  513.         if(!strnicmp(p, "sig", 3))
  514.          {
  515.             p = skip_blanks(&p[3]);
  516.             for (q = temp; *p && !isspace(*p); *q++ = *p++);
  517.             *q = EOS;
  518.             i = atoi(temp);
  519.             if(i<0 || i>=MAX_SIG) return;
  520.             p = skip_blanks(p);
  521.             if(!*p) return;
  522.             for (q = temp; *p && !isspace(*p); *q++ = *p++);
  523.             *q = EOS;
  524.             strcpy(sig_preset[i].new_name,temp);
  525.             p = skip_blanks(p);
  526.             for (q = temp; *p && !isspace(*p); *q++ = *p++);
  527.             *q = EOS;
  528.             if(!*p) continue;
  529.             strncpy(sig_preset[i].group,temp,9);
  530.             p = skip_blanks(p);
  531.             for (q = temp; *p && !isspace(*p); *q++ = *p++);
  532.             *q = EOS;
  533.             if(!*p)
  534.              {
  535.                 sig_preset[i].level = -1;
  536.                 continue;
  537.              }
  538.             sig_preset[i].level = atol(temp);
  539.             p = skip_blanks(p);
  540.             if(!*p) continue;
  541.             strncpy(sig_preset[i].description,p,44);
  542.             sig_preset[i].description[44]=EOS;
  543.  
  544.             continue;
  545.          }        
  546.         if(!strnicmp(p, "swapsigs", 8))
  547.          {
  548.             p = skip_blanks(&p[8]);
  549.             for (q = temp; *p && !isspace(*p); *q++ = *p++);
  550.             *q = EOS;
  551.             swap_dest = atoi(temp);
  552.             if(swap_dest<0 || swap_dest>=MAX_SIG) return;
  553.             p = skip_blanks(p);
  554.             if(!*p) return;
  555.             swap_source = atoi(p);
  556.             if(swap_source<0 || swap_source>=MAX_SIG) return;
  557.             swap_flag = TRUE;
  558.             continue;
  559.          }
  560.         if (!strnicmp(p, "logfile", 7))
  561.          {
  562.             logfile = ctl_string(&p[7]);
  563.             loging = TRUE;
  564.             continue;
  565.          }
  566.         if(!strnicmp(p,"info",4))
  567.          {
  568.             info = TRUE;
  569.             continue;
  570.          }
  571.         if(!strnicmp(p,"address",7))
  572.          {
  573.             if(cur_adr>=12) continue;
  574.             p = skip_blanks(&p[7]);
  575.             for (q = temp; *p && !isspace(*p); *q++ = *p++);
  576.             new_adr[cur_adr].adr_flag = temp[0];
  577.             p = skip_blanks(p);
  578.             for (q = temp; *p && !isspace(*p); *q++ = *p++);
  579.             *q = EOS;
  580.             address_4d(temp, &new_adr[cur_adr].Zone, 
  581.                     &new_adr[cur_adr].Net,
  582.                     &new_adr[cur_adr].Node,
  583.                     &new_adr[cur_adr].Point);
  584.             new_adr[cur_adr].Outbound = ctl_string(p);
  585.             cur_adr++;
  586.             continue;
  587.          }
  588.  
  589.         printf("Unknown Command in line %d\n",line);
  590.     }
  591.  if(loging)
  592.   {
  593.     logf = fopen(logfile,"a");
  594.     if(logf == NULL) loging = FALSE;
  595.   }
  596. }
  597.  
  598. void read_areas(void)
  599. {
  600.  char buffer[512],
  601.         temp[130],
  602.         file[130],
  603.         *q, *p;
  604.  FILE *fd;
  605.  
  606.  int i;
  607.  
  608.  msgareas =0;
  609.  areabb[msgareas].origin = NULL;
  610.  areabb[msgareas].group =' ';
  611.  areabb[msgareas].randorigin = NULL;
  612.  areabb[msgareas].path = NULL;
  613.  areabb[msgareas].name = NULL;
  614.  areabb[msgareas].found = FALSE;
  615.  
  616.  strcpy(file,areas_path);
  617.  strcat(file,"AREAS.BBS");
  618.  if ((fd=fopen(file,"r")) == NULL)
  619.     {
  620.         return;
  621.     }
  622.  
  623.  while(fgets(buffer,511,fd))
  624.     {
  625.         p = skip_blanks(buffer);
  626.         if (*p == ';') continue;
  627.         if ((i = (int)strlen(p)) < 3) continue;
  628.         p = &p[--i];
  629.         *p = EOS;
  630.         if ((p = strchr(buffer,';')) != NULL) *p = EOS;
  631.         p = skip_blanks(buffer);
  632.         if (*p)
  633.          {
  634.                 main_origin = ctl_string(p);
  635.                 break;
  636.          }
  637.         else continue;
  638.     }
  639.  
  640.  while(fgets(buffer,511,fd))
  641.     {
  642.         p = skip_blanks(buffer);
  643.         if (*p == ';') continue;
  644.         if ((i = (int)strlen(p)) < 3) continue;
  645.         p = &p[--i];
  646.         *p = EOS;
  647.         if ((p = strchr(buffer, ';')) != NULL) *p = EOS;
  648.         p = skip_blanks(buffer);
  649.         if (!*p) continue;
  650.         
  651.         if (*p == '-')
  652.         {
  653.             switch (toupper(*++p))
  654.             {
  655.                 case 'O':        /* Origin line */
  656.                     p = skip_to_blank(p);
  657.                     areabb[msgareas].origin = ctl_string(p);
  658.                     break;
  659.                 
  660.                 case 'G':
  661.                     p = skip_to_blank(p);
  662.                     p = skip_blanks(p);
  663.                     if (*p)
  664.                      {
  665.                         if (isalnum(*p)) areabb[msgareas].group = *p;
  666.                      }
  667.                     break;
  668.                 
  669.                 case 'F':
  670.                     p = skip_to_blank(p);
  671.                     p = skip_blanks(p);
  672.                     if (!*p) break;
  673.                     areabb[msgareas].randorigin = ctl_file(p);
  674.                     break;
  675.             }
  676.             continue;
  677.         }
  678.         
  679.         for (q = temp; *p && !isspace(*p); *q++ = *p++);
  680.         *q = EOS;
  681.         areabb[msgareas].path = ctl_string(temp);
  682.         
  683.         p = skip_blanks(p);
  684.         for (q = temp; *p && !isspace(*p); *q++ = *p++);
  685.         *q = EOS;
  686.         areabb[msgareas].name = ctl_string(temp);
  687. /*        p = skip_blanks(p);    */
  688.  
  689.         if((!stricmp(temp, "mail")) || (!stricmp(temp, "trasharea")) ||
  690.             (!stricmp(temp, "dupe_area")) || (!stricmp(temp, "privateboxarea")) ||
  691.             (!stricmp(temp, "privatemailbox")) || (!stricmp(temp, "privatemail")))
  692.                 areabb[msgareas].group = (char)-1;
  693.  
  694.         if(areabb[msgareas].origin == NULL)
  695.             areabb[msgareas].origin = ctl_string(main_origin);
  696.         
  697.         msgareas++;
  698.         areabb[msgareas].origin = NULL;
  699.         areabb[msgareas].group =' ';
  700.         areabb[msgareas].randorigin = NULL;
  701.         areabb[msgareas].path = NULL;
  702.         areabb[msgareas].name = NULL;
  703.         areabb[msgareas].found = FALSE;
  704.     }
  705.  fclose(fd);
  706. }
  707.  
  708. void free_areabb(void)
  709. {
  710.  int i;
  711.  for(i=0; i<msgareas; i++)
  712.   {
  713.     if(areabb[i].origin!=NULL)
  714.      {
  715.         free(areabb[i].origin);
  716.         areabb[i].origin = NULL;
  717.      }
  718.     if(areabb[i].randorigin!=NULL)
  719.      {
  720.         free(areabb[i].randorigin);
  721.         areabb[i].randorigin = NULL;
  722.      }
  723.     if(areabb[i].path!=NULL)
  724.      {
  725.         free(areabb[i].path);
  726.         areabb[i].path = NULL;
  727.      }
  728.     if(areabb[i].name!=NULL)
  729.      {
  730.         free(areabb[i].name);
  731.         areabb[i].name = NULL;
  732.      }
  733.   }
  734. }
  735.  
  736. void add_area(int group, int sig)
  737. {
  738.  int i,j;
  739.  
  740.  i=sig * (int)tml_body.echos_sig;
  741.  j=(sig+1) * (int)tml_body.echos_sig;
  742.  for( ; i<j; i++) if(strlen(areas[i].filename)==0) break;
  743.  if(i==j)
  744.   {
  745.     printf("No room left. No add. No save!\n");
  746.     exit(-2);
  747.   }
  748.  strncpy(areas[i].filename,areabb[group].path,49);
  749.  areas[i].filename[49]='\0';
  750.  strncpy(areas[i].Tagname,areabb[group].name,13);
  751.  areas[i].Tagname[13]='\0';
  752.  areas[i].access = dev_access;
  753.  areas[i].flags = dev_flags;
  754.  strncpy(areas[i].description,dev_description,49);
  755.  areas[i].description[49]='\0';
  756.  printf("Area %s with Path %s\n allowed for level %ld Users\n\n",
  757.      areas[i].Tagname,areas[i].filename,areas[i].access);
  758.  areas[i].found = TRUE;
  759. }
  760.  
  761. void do_check_adr(void)
  762. {
  763.  int i,j,k;
  764.  for(i=0; i<cur_adr; i++)
  765.   {
  766.     if(new_adr[i].adr_flag=='+')
  767.      {
  768.         for(j=0; j<11 && tml_body.domains[j].Zone!=0; j++)
  769.         if(j==11)
  770.          {
  771.             printf("Address statements full!\n");
  772.             continue;
  773.          }
  774.         tml_body.domains[j].Zone  = new_adr[i].Zone;
  775.         tml_body.domains[j].Net   = new_adr[i].Net;
  776.         tml_body.domains[j].Node  = new_adr[i].Node;
  777.         tml_body.domains[j].Point = new_adr[i].Point;
  778.         strncpy(tml_body.domains[j].Outbound,new_adr[i].Outbound,39);
  779.         printf("Address: %d:%d/%d.%d with %s added.\n",
  780.         tml_body.domains[j].Zone,tml_body.domains[j].Net,
  781.         tml_body.domains[j].Node,tml_body.domains[j].Point,
  782.         tml_body.domains[j].Outbound);
  783.      }    else
  784.     if(new_adr[i].adr_flag=='-')
  785.      {
  786.         for(j=0; j<12; j++)
  787.             if(tml_body.domains[j].Zone  == new_adr[i].Zone &&
  788.                 tml_body.domains[j].Net   == new_adr[i].Net &&
  789.                 tml_body.domains[j].Node  == new_adr[i].Node &&
  790.                 tml_body.domains[j].Point == new_adr[i].Point) break;
  791.         if(j==12) continue;
  792.         printf("Removing Address: %d:%d/%d.%d\n",
  793.         tml_body.domains[j].Zone,tml_body.domains[j].Net,
  794.         tml_body.domains[j].Node,tml_body.domains[j].Point);
  795.         for(k=j+1; k<12; k++)
  796.          {
  797.             tml_body.domains[k-1].Zone  = tml_body.domains[k].Zone;
  798.             tml_body.domains[k-1].Net   = tml_body.domains[k].Net;
  799.             tml_body.domains[k-1].Node  = tml_body.domains[k].Node;
  800.             tml_body.domains[k-1].Point = tml_body.domains[k].Point;
  801.             strncpy(tml_body.domains[k-1].Outbound,
  802.                         tml_body.domains[k].Outbound,39);
  803.          }
  804.      } else
  805.     if(new_adr[i].adr_flag=='c')
  806.      {
  807.         for(j=0; j<12; j++)
  808.             if(tml_body.domains[j].Zone  == new_adr[i].Zone &&
  809.                 tml_body.domains[j].Net   == new_adr[i].Net &&
  810.                 tml_body.domains[j].Node  == new_adr[i].Node &&
  811.                 tml_body.domains[j].Point == new_adr[i].Point) break;
  812.         if(j==12) continue;
  813.         strncpy(tml_body.domains[j].Outbound,new_adr[i].Outbound,39);
  814.         printf("Address: %d:%d/%d.%d with %s changed.\n",
  815.         tml_body.domains[j].Zone,tml_body.domains[j].Net,
  816.         tml_body.domains[j].Node,tml_body.domains[j].Point,
  817.         tml_body.domains[j].Outbound);
  818.      }
  819.   }
  820. }
  821.  
  822. void do_cross_check(void)
  823. {
  824.  int i,j,k;
  825.  boolean do_exclude;
  826.  
  827.  for(i=0; i<msgareas; i++)
  828.   {
  829.     for(j=0; j<(int)tml_body.echos_sig * MAX_SIG; j++)
  830.      {
  831.         if(strlen(areas[j].filename) > 0 && areabb[i].path != NULL)
  832.             if(stricmp(areas[j].filename,areabb[i].path) == 0)
  833.              {
  834.                 areabb[i].found = TRUE;
  835.                 areas[j].found = TRUE;
  836.              }
  837.      }
  838.   }
  839.  for(i=0; i<msgareas; i++)
  840.   {
  841.     if((!areabb[i].found) && areabb[i].group!=-1)
  842.      {
  843.         printf("Warning! Area: %s not found in TMail.DAT\n",areabb[i].name);
  844.         do_exclude = FALSE;
  845.         for(j=0; j<strlen(exclude_groups); j++)
  846.             if(areabb[i].group == exclude_groups[j])
  847.              {
  848.                 printf("Area %s excluded.\n",areabb[i].name);
  849.                 do_exclude=TRUE;
  850.                 break;
  851.              }
  852.         if(!do_exclude && strlen(to_add_groups)>0)
  853.          {
  854.             for(j=0; j<strlen(to_add_groups); j++)
  855.                 if(areabb[i].group == to_add_groups[j] && j<=MAX_SIG)
  856.                  {
  857.                     for(j=0; j<MAX_SIG; j++)
  858.                         for(k=0; k<strlen(sig_preset[j].group); k++)
  859.                             if(sig_preset[j].group[k] == areabb[i].group)
  860.                              {
  861.                                 printf("Adding Area to Group %c : %s\n",
  862.                                     sig_preset[j].group[k],
  863.                                     tml_body.SIGs[j].name);
  864.                                 add_area(i,j);
  865.                              }
  866.                  }
  867.          }
  868.      }
  869.   }
  870.  printf("\n\n");
  871.  for(j=0; j<(int)tml_body.echos_sig * MAX_SIG; j++)
  872.     {
  873.         if((!areas[j].found) && strlen(areas[j].filename) > 0)
  874.             printf("Warning! Area: %s not found!\n",areas[j].Tagname);
  875.     }
  876. }
  877.  
  878. void check_preset(void)
  879. {
  880.  int j;
  881.  
  882.  printf("Special Interest Grouping\n");
  883.  for(j=0; j<MAX_SIG; j++)
  884.   {
  885.     if(sig_preset[j].new_name[0] == '*')
  886.         strcpy(sig_preset[j].new_name,tml_body.SIGs[j].name);
  887.     else if(strlen(sig_preset[j].new_name)>0)
  888.         strcpy(tml_body.SIGs[j].name,sig_preset[j].new_name);
  889.     if(sig_preset[j].level <=0)
  890.         sig_preset[j].level=tml_body.SIGs[j].level;
  891.     else tml_body.SIGs[j].level=sig_preset[j].level;
  892.     if(sig_preset[j].description[0] == '*' ||
  893.              strlen(sig_preset[j].description) ==0)
  894.         strcpy(sig_preset[j].description,tml_body.SIGs[j].description);
  895.     else strcpy(tml_body.SIGs[j].description,sig_preset[j].description);
  896.     if(strlen(tml_body.SIGs[j].name)==0) continue;
  897.     printf("(%2d) %-22s :%6ld : %s\n",j,tml_body.SIGs[j].name,
  898.             tml_body.SIGs[j].level,tml_body.SIGs[j].description);
  899.   }
  900.  printf("\n");
  901. }
  902.  
  903. void do_swap_sigs(void)
  904. {
  905.  int i,j,k;
  906.  struct AREA_S *temp_areas;
  907.  struct SIG_S temp_sig;
  908.  FILE *fp;
  909.  char file[128];
  910.  long offs;
  911.  long seek1,seek2;
  912.  char *temp1;
  913.  char *temp2;
  914.  
  915.  strcpy(file,tmail_path);
  916.  strcat(file,"TMAIL.PTR");
  917.  fp=fopen(file,"rb+");
  918.  if(fp==NULL) exit(-2);
  919.  temp1 = malloc(5L*tml_body.echos_sig);
  920.  if(temp1==NULL) exit(-2);
  921.  temp2 = malloc(5L*tml_body.echos_sig);
  922.  if(temp2==NULL) exit(-2);
  923.  
  924.  printf("Swapping Sig's\n(%d) %s <--> (%d) %s\n",
  925.          swap_source,tml_body.SIGs[swap_source].name,
  926.          swap_dest,tml_body.SIGs[swap_dest].name);
  927.  i=swap_source * (int)tml_body.echos_sig;
  928.  temp_areas=calloc(tml_body.echos_sig, sizeof(struct AREA_S));
  929.  if(temp_areas==NULL) return;
  930.  memcpy(temp_areas,&areas[i],
  931.      sizeof(struct AREA_S)*(int)tml_body.echos_sig);
  932.  j=swap_dest * (int)tml_body.echos_sig;
  933.  memcpy(&areas[i],&areas[j],
  934.      sizeof(struct AREA_S)*(int)tml_body.echos_sig);
  935.  memcpy(&areas[j],temp_areas,
  936.      sizeof(struct AREA_S)*(int)tml_body.echos_sig);
  937.  free(temp_areas);
  938.  
  939.  memcpy(&temp_sig,&tml_body.SIGs[swap_source],sizeof(struct SIG_S));
  940.  memcpy(&tml_body.SIGs[swap_source],&tml_body.SIGs[swap_dest],
  941.          sizeof(struct SIG_S));
  942.  memcpy(&tml_body.SIGs[swap_dest],&temp_sig,sizeof(struct SIG_S));
  943.  
  944.  printf("One moment .... Updating PTR File\n");
  945.  for(k=0; k<users; k++)        /* Users loop */
  946.     {
  947.         offs = (5L*MAX_SIG*(tml_body.echos_sig+1L) * k) + 5L;
  948.         seek1 = offs + (tml_body.echos_sig*5*swap_source);
  949.         seek2 = offs + (tml_body.echos_sig*5*swap_dest);
  950.         fseek(fp,seek1,SEEK_SET);
  951.         fread(temp1,1,tml_body.echos_sig*5,fp);
  952.         fseek(fp,seek2,SEEK_SET);
  953.         fread(temp2,1,tml_body.echos_sig*5,fp);
  954.         fseek(fp,seek2,SEEK_SET);
  955.         fwrite(temp1,1,tml_body.echos_sig*5,fp);
  956.         fseek(fp,seek1,SEEK_SET);
  957.         fwrite(temp2,1,tml_body.echos_sig*5,fp);
  958.     }
  959.  fclose(fp);
  960.  free(temp1);
  961.  free(temp2);
  962. }
  963.  
  964. void give_help(void)
  965. {
  966.     printf("\nT-Mail Data Structur Manager\nby Wolfgang Zweygart\n");
  967.     printf("Usage: tml_man -[C] -[I] -[H] -[S]\n");
  968.     printf("-C   : check TMAIL.DAT against AREAS.BBS\n");
  969.     printf("-I   : print information from TMAIL.DAT\n");
  970.     printf("-H   : this mini help\n-S   : save data (TMAIL.DAT) to disk\n\n");
  971.     printf("The file TML_MAN.CFG has the following keywords:\n");
  972.     printf("TmailPath <path to TMAIL.DAT and TMAIL.PTR>\n");
  973.     printf("AreasPath <path to AREAS.BBS>\nLogFile <Name of Logfile>\n");
  974.     printf("Info\nCrossCheck\nAutoAdd [Group-id][Group-id][..]\n");
  975.     printf("Exclude [Group-id][Group-id][..]\nAccess <Level>\n");
  976.     printf("Description <description for new areas>\n");
  977.     printf("Flags [flag]\nSaveData\n");
  978.     printf("Sig [number] <name of sig> [group-id] [level] <description>\n");
  979.     printf("SwapSigs [number] [number]\n");
  980.     printf("Address [flag] <4D-Address> <Outbound-Path>\n   flag is:\n");
  981.     printf("    + for adding a new Address and Outbound\n");
  982.     printf("    - for removing a Address\n");
  983.     printf("    c for change Outbound-Path of existing Address\n\n");
  984. }
  985.  
  986. void do_info(void)
  987. {
  988.  int i;
  989.  
  990.  printf("Information taken from %sTMAIL.DAT\n",tmail_path);
  991.  if(tml_body.bbs_type == 0) printf("\\\\\\TurboBoard BBS\n");
  992.  else if(tml_body.bbs_type == 1) printf("QBBS\n");
  993.  else if(tml_body.bbs_type == 2) printf("Other BBS\n");
  994.  printf("Max %ld echos per SIG\n",tml_body.echos_sig);
  995.  printf("Sysop is %s\n",tml_body.sysop_name);
  996.  printf("Path to LED: %s\n",tml_body.led_point);
  997.  printf("Inbound:      %s\n",tml_body.Inbound);
  998.  printf("KnownInbound: %s\n",tml_body.KnownInbound);
  999.  printf("ProtInbound:  %s\n",tml_body.ProtInbound);
  1000.  printf("NetMail:      %s\n",tml_body.NetMail);
  1001.  printf("Num. of QWK confs %d\n",tml_body.qwk_confs);
  1002.  printf("Min write access level %d\n",tml_body.write_access);
  1003.  printf("QWK prepack inactivity days %d\n",tml_body.inacti_days);
  1004.  printf("Temp File:    %s\n",tml_body.temp_file);
  1005.  printf("Log  File:    %s\n",tml_body.log_file);
  1006.  printf("Transfer :    %s\n",tml_body.transfer);
  1007.  printf("Gateway is %d:%d/%d.%d\n",tml_body.gate_zone,tml_body.gate_net,
  1008.              tml_body.gate_node,tml_body.gate_point);
  1009.  printf("Internet gate %d:%d/%d.%d\n",tml_body.inet_zone,
  1010.             tml_body.inet_net,tml_body.inet_node,tml_body.inet_point);
  1011.  for(i=0; i<12; i++)
  1012.   {
  1013.     if(tml_body.domains[i].Zone == 0) continue;
  1014.     printf("Address: %d:%d/%d.%d with %s\n",
  1015.         tml_body.domains[i].Zone,tml_body.domains[i].Net,
  1016.         tml_body.domains[i].Node,tml_body.domains[i].Point,
  1017.         tml_body.domains[i].Outbound);
  1018.   }
  1019.  printf("\n");
  1020. }
  1021.  
  1022. int main(int argc, char **argv, const char *envp[] )
  1023. {
  1024.  char cmdline[129];
  1025.  int i;
  1026.  
  1027.  envi = envp;
  1028.  read_cfg();
  1029.  if (argc > 1)    strcpy(cmdline,argv[1]);
  1030.  for(i=2; i < argc; i++)
  1031.   {
  1032.     strcat(cmdline," ");
  1033.     strcat(cmdline,argv[i]);
  1034.   }
  1035.  i = 0;
  1036.  if (cmdline[i] == '-')
  1037.   {
  1038.     while(cmdline[i+1] != EOS)
  1039.      {
  1040.         i++;
  1041.         switch(toupper(cmdline[i]))
  1042.          {
  1043.                     case ' ':     
  1044.                     case '-':    i++; break;
  1045.                     case 'C':    cross_check = TRUE;        break;
  1046.                     case 'I':    info = TRUE;                break;
  1047.                     case 'H':    give_help(); exit(0);    break;
  1048.                     case 'S':    save_data = TRUE;            break;
  1049.                     default: printf("\nDon't know option -%c. Try -H for Help.\n",
  1050.                                     cmdline[i]);                break;
  1051.             }
  1052.         } 
  1053.     }
  1054.  printf("\nT-Mail Data Structur Manager\nby Wolfgang Zweygart\n");
  1055.  printf("Version: %s\n\n",VERSION);
  1056.  read_tml_dat();
  1057.  read_tml_ptr();
  1058.  if(info) do_info();
  1059.  check_preset();
  1060.  read_areas();
  1061.  if(cross_check) do_cross_check();
  1062.  if(swap_flag && save_data) do_swap_sigs();
  1063.  if(cur_adr>0) do_check_adr();
  1064.  if(save_data) write_tml_dat();
  1065.  free_areabb();
  1066.  if(loging) fclose(logf);
  1067.  return(0);
  1068. }
  1069.