home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / MISC / XDEV_117.ZIP / XSCAN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-08  |  20.1 KB  |  778 lines

  1. /* XSCAN -- compile in Compact model */
  2.  
  3. #include "msgg.h"
  4.  
  5. char * pascal stristr (char *t, char *s);
  6. int    pascal export (char *,word,char *);
  7. int    pascal import (char *,word,char *);
  8. char * pascal rstrip (char *);
  9. char * pascal lstrip (char *);
  10. char * pascal stripcr (char *);
  11. void   pascal getone (char *,FILE *,word);
  12. void   pascal strip (char *,int);
  13. void   pascal read_control (char *);
  14. int    cdecl  break_handler (void);
  15. void   cdecl  close_em (void);
  16. void   pascal make_attach (char *filetosend);
  17. char * pascal unpack_msg (char **hold);
  18. char * pascal pack_msg (char *hold,struct _xmsg *msg);
  19.  
  20. char area_tag[48];
  21. int  no_strip=0;
  22. int  nofillin=0;
  23. int  net=0;
  24. int  rescanning=0;
  25. int  process_assoc=0;
  26. long pos=0;
  27. FILE *pf;
  28. char *nodes;
  29. char outbound[133];
  30. word compress_size=0;
  31. word textsize;
  32. word codesize;
  33.  
  34. /* Notes on msg handling with XBBS:
  35.     First, when I import a message, I set the MSGORPHAN bit if:
  36.         1.  The message had stripping done to it (eliminating SEEN-BYs, etc.)
  37.         2.  The message was too long (>64K) to import in its entirity.
  38.     Setting the MSGORPHAN bit guarantees a message will never be reexported.
  39.  
  40.     Second, on import I reset MSGLOCAL.  This ensures that imported messages
  41.     will never be reexported unless a rescan is requested.
  42.  
  43.     Third, on export I set the MSGLOCAL bit.  oMMM won't touch a message with
  44.     its MSGLOCAL bit unset, so it might affect other programs farther down
  45.     line.  Better safe than sorry.
  46.  
  47.     Fourth, after export I set the MSGSCANNED bit in msg.m_attr.  This is
  48.     XBBS' version of a high-water mark, and tells XST which messages have
  49.     already been sent.  XSCAN would override the scanned bit only if a
  50.     rescan has been requested, and the message is a candidate for exporting
  51.     (i.e. doesn't have MSGORPHAN set).
  52.  
  53.     The MSGSENT bit isn't really used other than as information to the sysop.
  54.  
  55.     Note that the msg.length value is a byte larger than you might think.
  56.     XBBS uses the extra byte to assure null termination even if the message
  57.     was grunged (local XBBS use only).
  58. */
  59.  
  60.  
  61.  
  62. void cdecl main (argc,argv)
  63.  
  64.     int argc;
  65.     char *argv[];
  66.  
  67. {
  68.  
  69.     word register x;
  70.     char do_import=0;
  71.     char do_export=0;
  72.     static char configfile[132]="XAREAS.BBS";
  73.     static char s[512];
  74.     static char messdir[120]="";
  75.     word areasprocessed=0;
  76.     word lineno=0;
  77.     word boardno;
  78.     static char directory[120];
  79.  
  80.     ctrlbrk(break_handler);
  81.     atexit(close_em);
  82.  
  83.     printf("\n\n\x1b[0;1;37mXSCAN copyright (c) 1989/90 by M. Kimes--All Rights Reserved\x1b[0;2;37m\n");
  84.     printf("Compiled: %s  %s\n",__DATE__,__TIME__);
  85.  
  86.     for (x=1;x<(word)argc;x++) {  /* Parse command line */
  87.         strupr(argv[x]);
  88.         if (!strncmp(argv[x],"-I",2)) do_import=1;
  89.         else if (!strncmp(argv[x],"-E",2)) do_export=1;
  90.         else if (!strncmp(argv[x],"-F",2)) strcpy(configfile,&argv[x][2]);
  91.         else if (!strncmp(argv[x],"-Z",2)) no_strip=1;
  92.         else if (!strncmp(argv[x],"-N",2)) nofillin=1;
  93.         else if (!strncmp(argv[x],"-R",2)) {
  94.             do_export=1;
  95.             rescanning=1;
  96.         }
  97.         else if (!strncmp(argv[x],"-C",2)) {
  98.             compress_size=(word)atol(&argv[x][2]);
  99.             if(compress_size<1024)compress_size=1024;
  100.         }
  101.         else if (!strncmp(argv[x],"-A",2)) process_assoc=1;
  102.         else printf("\nUnknown parameter `%s'\n",argv[x]);
  103.     }
  104.  
  105.     if (!do_import && !do_export) {
  106.         printf("\nXSCAN is the link between XBBS X*.### msg area files and *.MSG msg files\n");
  107.         printf("  Please note that XST is recommended over XSCAN where it will work!\n");
  108.         printf("\nIt'd be a good idea to specify -Import and/or -Export\n");
  109.         printf("You can also specify a config file with -F<filename>\n");
  110.         printf("and/or tell me not to strip SEEN-BYs and other extraneous info with -Z\n");
  111.         printf("I will fill in incomplete message headers from kludge lines unless you say -N\n");
  112.         printf("Rescans can be had by passing -Rescan, but use *carefully*!\n");
  113.         printf("Msgs that had SEEN-BYs stripped when imported cannot be rescanned.\n");
  114.         printf("-C<#bytes> tells me how big a msg must be before compressing (none default)\n");
  115.         printf("Associated msgs can be processed if you pass the -Assoc argument.\n");
  116.         printf("Associated filepath look up uses ASSOC.BBS in the default directory.\n");
  117.         printf("ASSOC.BBS should be in the form Area_Tag File_Path<cr><lf>\n");
  118. printf("\x1b[0;1;37m(NOTE: at this time, -Assoc is not supported)\x1b[0;2;37m\n");
  119.         goto Something_Bad;
  120.     }
  121.     if(rescanning) printf("\nRescan activated...hope you know what you're doing...");
  122.     if (!do_import && do_export) printf("\nExporting messages...");
  123.     if (do_import && !do_export) printf("\nImporting messages...");
  124.     if (do_import && do_export)  printf("\nImporting and exporting messages...");
  125.     printf("\nConfig file is: %s\n",configfile);
  126.  
  127.     if(!(pf=fopen(configfile,"r"))) {
  128.         printf("\nCan't open ctl file\n");
  129.         exit(4);
  130.     }
  131.     getone(s,pf,lineno);
  132.     if (!*s) {
  133.         printf("\nBig bad goof in config file\n");
  134. Something_Bad:
  135.         printf("\nConfig file format: (Default: XAREAS.BBS)\n\nFirst line:    Drive:\\XBBS_message_directory_path\\");
  136.         printf("\nSecond line:   Drive:\\Outbound_directory_path\\ (used with -Assoc)");
  137.         printf("\nSubsequent lines:\n Area#  Drive:\\MSG_Directory\\  Area_tag <and then nodes if using -Assoc>\n");
  138.         printf("\nUse reserved area name *NETMAIL* (including *'s) for netmail areas.\n");
  139.         exit(4);
  140.     }
  141.     lstrip(s);
  142.     stripcr(s);
  143.     rstrip(s);
  144.     if (s[strlen(s)-1]!='\\') strcat(s,"\\");
  145.     strcpy(messdir,s);
  146.     getone(s,pf,lineno);
  147.     if(!*s) goto Something_Bad;
  148.     lstrip(s);
  149.     stripcr(s);
  150.     rstrip(s);
  151.     if (s[strlen(s)-1]!='\\') strcat(s,"\\");
  152.     strcpy(outbound,s);
  153.     do {
  154.         pos=ftell(pf);  /* In case rewind sometime required */
  155.         getone(s,pf,lineno);
  156.         if (!*s) break;
  157.         lstrip(s);
  158.         stripcr(s);
  159.         rstrip(s);
  160.         strupr(s);
  161.         boardno=(word)atol(strtok(s,"; "));
  162.         if (!boardno) {
  163.             printf("\nError in ctl file line#%u",lineno);
  164.             continue;
  165.         }
  166.         strcpy(directory,strtok(0," "));
  167.         if (directory[strlen(directory)-1]!='\\') strcat(directory,"\\");
  168.         strcpy(area_tag,strtok(0," "));
  169.         nodes=strtok(0,"\n");    /* Point to trailing list of nodes, if any */
  170.         printf("\nProcessing area %s",area_tag);
  171.         if(!strcmp(area_tag,"*NETMAIL*")) net=1;
  172.         else net=0;
  173.         if (do_import) {
  174.             printf("\nImporting...");
  175.             import(messdir,boardno,directory);
  176.         }
  177.         if (do_export) {
  178.             printf("\nExporting...");
  179.             export(messdir,boardno,directory);
  180.         }
  181.         areasprocessed++;
  182.     } while (*s);
  183.  
  184.     printf("\nProcessed mail in %u areas.\n",areasprocessed);
  185.  
  186. }
  187.  
  188.  
  189.  
  190.  
  191. int cdecl break_handler (void)
  192.  
  193. {
  194.  
  195.    return 1;
  196.  
  197. }
  198.  
  199.  
  200.  
  201. void cdecl close_em (void) {
  202.  
  203.     fcloseall();
  204.  
  205. }
  206.  
  207.  
  208. int pascal export (dir,base,filedir)
  209.  
  210.  char *dir;
  211.  word base;
  212.  char *filedir;
  213.  
  214. {
  215.  
  216.  static char filename[132];  /* static vars are just to speed things up (?) */
  217.  static char textname[132];
  218.  static char file[132];
  219.  static struct _xmsg msg;
  220.  FILE *fp;
  221.  FILE *pf;
  222.  FILE *pp=NULL;
  223.  char once;
  224.  char *hold;
  225.  struct ffblk filestat;
  226.  register word messno;
  227.  word nomess;
  228.  char msgto[133];
  229.  register word number=1;
  230.  
  231.  sprintf(filename,"%sXDATA.%03x",dir,base);
  232.  sprintf(textname,"%sXTEXT.%03x",dir,base);
  233.  
  234.  if (findfirst(filename,&filestat,0)!=0) {
  235.     printf("\nCannot find %s",filename);
  236.     return 0;
  237.  }
  238.  nomess=(word)(filestat.ff_fsize/(long)sizeof(struct _xmsg));
  239.  if (!nomess) return 0;
  240.  
  241.  if(!(pf=fopen(textname,"rb"))) {
  242.     printf("\nCannot open %s",textname);
  243.     return (0);
  244.  }
  245.  
  246.  if(!(fp=fopen(filename,"r+b"))) {
  247.    if (!(fp=fopen(filename,"a+b"))) {
  248.         fclose(pf);
  249.         printf("\nCannot open %s",filename);
  250.         return(0);
  251.    }
  252.  }
  253.  
  254.  for (messno=1;messno<nomess+1;messno++) {
  255.      if ((fseek(fp,(long)(messno-1)*(long)sizeof(struct _xmsg),SEEK_SET)!=0) || (fread(&msg,sizeof(struct _xmsg),1,fp)!=1)) {
  256.         if (ferror(fp)) perror ("\nXDATA SEEK ERROR");
  257.         fclose(fp);
  258.         fclose(pf);
  259.         if (pp) fclose(pp);
  260.         return(0);
  261.      }
  262.      if(msg.attr & MSGORPHAN) continue;
  263.      if(((msg.m_attr & MSGSCANNED) || !(msg.attr & MSGLOCAL)) && !rescanning) continue;
  264.      if(!net){
  265.         if ((msg.m_attr & MSGDELETED) || (!(msg.m_attr & MSGECHO))) continue;
  266.      }
  267.      else if ((msg.m_attr & MSGDELETED) || (!(msg.m_attr & MSGNET))) continue;
  268.  
  269.      do {
  270.         if (number>=65534) {
  271.             printf("\nOut of message numbers...\n");
  272.             return 0;
  273.         }
  274.         if(!net)number++;
  275.         sprintf(file,"%s%u.MSG",filedir,number);
  276.      } while (!findfirst(file,&filestat,0));
  277.  
  278.      printf("%5d.MSG\x1b[9D",number);
  279.  
  280.      if ((fseek(fp,(long)(messno-1)*(long)sizeof(struct _xmsg),SEEK_SET)!=0)) {
  281.         if (ferror(fp)) perror ("\nXDATA SEEK ERROR");
  282.         fclose(fp);
  283.         fclose(pf);
  284.         if (pp) fclose(pp);
  285.         return(0);
  286.      }
  287. /*     if(!net)msg.m_attr = msg.m_attr & (~MSGECHO); */  /* Unmark echo bit */
  288. /*     else msg.m_attr = msg.m_attr & (~MSGNET);     */
  289.  
  290.      if(net) {
  291.         if(msg.attr & MSGKILL) msg.m_attr = (msg.m_attr | MSGDELETED);
  292.      }
  293.  
  294.      msg.m_attr = (msg.m_attr | MSGSCANNED);   /* Set scanned bit */
  295.      msg.attr = (msg.attr | MSGSENT);
  296.  
  297.      fwrite(&msg,sizeof(struct _xmsg),1,fp); /* Update header   */
  298.  
  299.      msg.attr = (msg.attr & (~MSGSENT));
  300.  
  301.      if(!(pp=fopen(file,"wb"))) {
  302.         fclose (fp);
  303.         fclose (pf);
  304.         printf("\nCannot open %s",file);
  305.         return 0;
  306.      }
  307.  
  308.           once=0;
  309. TryThatOver:
  310.           if (fseek(pf,msg.start,SEEK_SET)!=0) {
  311.              if (ferror(pf)) {
  312.                 if (!once) {
  313.                     once++;
  314.                     goto TryThatOver;
  315.                 }
  316.                 else {
  317.                     perror ("\nXTEXT SEEK ERROR");
  318.                     fclose(fp);
  319.                     fclose(pf);
  320.                     fclose(pp);
  321.                     exit(3);
  322.                 }
  323.               }
  324.           }
  325.           hold=(char *)malloc(msg.length+1);
  326.           if (hold==NULL) {
  327.             printf("\nOut of memory.\n");
  328.             fclose(pf);
  329.             fclose(fp);
  330.             fclose(pp);
  331.             exit(4);
  332.           }
  333.           fread(hold,msg.length,1,pf);
  334.           hold[msg.length-1]=0;
  335.  
  336.           if(msg.m_attr & MSGPACKED) {
  337.             unpack_msg(&hold);
  338.             if(hold==NULL) continue;    /* Compression error, screw it */
  339.             msg.length=strlen(hold)+1;
  340.           }
  341.  
  342.           if(process_assoc && nodes) {
  343.                     /* Associated msg file attaching... */
  344.  
  345.                 char assocfile[13]="";
  346.                 char filepath[133]="";
  347.                 char *p;
  348.                 struct ffblk f;
  349.                 FILE *fp;
  350.  
  351.                 if((p=(strstr(hold,"\01ASSOC: ")))) {
  352.                     p+=8;
  353.                     strncpy(assocfile,p,13);
  354.                     assocfile[12]=0;
  355.                     if(!(p=(strstr(hold,"\r\01REPLY: ")))) {
  356.                         fp=fopen("ASSOC.BBS","rt");
  357.                         if(fp) {
  358.                            while (!feof(fp) && stricmp(strtok(filepath," "),area_tag)) {
  359.                               if(!fgets(filepath,133,fp)) break;
  360.                               filepath[132]=0;
  361.                               stripcr(filepath);
  362.                            }
  363.                            fclose(fp);
  364.                            if(!stricmp(filepath,area_tag)) {
  365.                                 p=strtok(filepath,"\n");
  366.                                 if(p) {
  367.                                     strncpy(filepath,p,133);
  368.                                     filepath[119]=0;
  369.                                 }
  370.                                 else *filepath=0;
  371.                            }
  372.                            else *filepath=0;
  373.                         }
  374.                     }
  375.                 }
  376.                 if(*assocfile && *filepath) {
  377.                     strcat(filepath,assocfile);
  378.                     make_attach(filepath);
  379.                 }
  380.           }
  381.           if(net) {        /* Construct MSGTO for bomb runs, carbons */
  382.             if(!stristr(hold,"\01MSGTO: ")) {
  383.                 sprintf(msgto,"\01MSGTO: %u:%u/%u.%u\r",msg.d_zone,msg.dest_net,msg.dest,msg.d_point);
  384.             }
  385.             else *msgto=0;
  386.           }
  387.           else *msgto=0;
  388.           msg.length=0;
  389.           msg.start=0;
  390.           msg.d_point=0;
  391.           msg.o_point=0;
  392.           msg.d_zone=0;
  393.           msg.o_zone=0;
  394.           msg.attr = msg.attr | MSGLOCAL;
  395.           fwrite(&msg,sizeof(struct _xmsg),1,pp);
  396.           if(*msgto) fwrite(msgto,strlen(msgto),1,pp);
  397.           fwrite(hold,strlen(hold),1,pp);
  398.           fputc('\0',pp);
  399.           free(hold);
  400.           fclose(pp);
  401.  }
  402.  fclose(pf);
  403.  fclose(fp);
  404.  return number;
  405.  
  406. }
  407.  
  408.  
  409.  
  410. int pascal import (char *dir,word base,char *filedir) {
  411.  
  412.  static char filename[132];  /* static vars are just to speed things up? */
  413.  static char textname[132];
  414.  static char file[132];
  415.  static char filecheck[132];
  416.  static struct _xmsg msg;
  417.  FILE *fp;
  418.  FILE *pf;
  419.  FILE *pp=NULL;
  420.  char once;
  421.  char *hold;
  422.  struct ffblk filestat;
  423.  register word messno;
  424.  register word number;
  425.  struct date dos_date;
  426.  long length;
  427.  long pos;
  428.  
  429.  sprintf(filecheck,"%s0.MSG",filedir);       /* In case of screw-up */
  430.  remove(filecheck);
  431.  if (!net) {
  432.     sprintf(filecheck,"%s1.MSG",filedir);  /* Kill high-water mark */
  433.     remove (filecheck);
  434.  }
  435.  
  436.  sprintf(filecheck,"%s*.MSG",filedir);  /* Check for *.MSG Files */
  437.  if (findfirst(filecheck,&filestat,0)) return 0;
  438.  
  439.  getdate(&dos_date);
  440.  
  441.  sprintf(filename,"%sXDATA.%03x",dir,base);
  442.  sprintf(textname,"%sXTEXT.%03x",dir,base);
  443.  
  444.  if (findfirst(filename,&filestat,0)!=0) messno=0;
  445.  else messno=(word)(filestat.ff_fsize/(long)sizeof(struct _xmsg));
  446.  if (messno==(word)65535) {
  447.     printf("\nMessage base is full\n");
  448.     return 0;
  449.  }
  450.  
  451.  if(!(pf=fopen(textname,"a+b"))) {
  452.     printf("\nCannot open %s",textname);
  453.     return (0);
  454.  }
  455.  
  456.  fseek(pf,0L,SEEK_END);  /* Positively position to end of file */
  457.  
  458.  if (!(fp=fopen(filename,"a+b"))) {
  459.     fclose(pf);
  460.     printf("\nCannot open %s",filename);
  461.     return(0);
  462.  }
  463.  
  464.  fseek(fp,0L,SEEK_END);  /* Positively position to end of file */
  465.  
  466.  number=0;
  467.  if(!net)number++;
  468.  do {
  469.                                                        /* Get *.MSG's  */
  470.     number++;                                           /* in numerical */
  471.     printf("%5u.MSG\x1b[9D",number);                   /* order        */
  472.     sprintf(file,"%s%u.MSG",filedir,number);
  473.     if (findfirst(file,&filestat,0)) {
  474.         sprintf(file,"%s*.MSG",filedir);
  475.         if(findfirst(file,&filestat,0)) break;
  476.         continue;
  477.     }
  478.  
  479.     if(!(pp=fopen(file,"rb"))) {
  480.         fclose (fp);
  481.         fclose (pf);
  482.         printf("\nCannot open %s",file);
  483.         return 0;
  484.     }
  485.     rewind(pp);
  486.     fread(&msg,sizeof(struct _xmsg),1,pp);
  487.     if(msg.attr & MSGORPHAN) goto Discard;
  488.     if (filestat.ff_fsize>65100L) {
  489.         filestat.ff_fsize=65100L;
  490.         msg.attr = (msg.attr | MSGORPHAN);
  491.     }
  492.     length=(filestat.ff_fsize-(long)sizeof(struct _msg));
  493.     if (length<1L) {
  494.         printf("\nGrunged msg discarded...");
  495.         goto Discard;
  496.     }
  497.     if(length>65100L) {
  498.         printf("\nMsg truncated...");
  499.         length=65100L;
  500.     }
  501.     msg.length=(word)(length+1L);
  502.     msg.attr = msg.attr & (~MSGLOCAL);
  503.     if(net) {
  504.         msg.m_attr = (msg.m_attr | MSGNET);
  505.     }
  506.     else {
  507.         msg.m_attr = (msg.m_attr | MSGECHO);
  508.     }
  509.     msg.start=ftell(pf);
  510.     msg.subj[63]=0;
  511.     msg.o_zone=0;
  512.     msg.o_point=0;
  513.     msg.d_point=0;
  514.     msg.d_zone=0;
  515.     msg.m_attr=0;
  516.     msg.indate[0]=(char)dos_date.da_year-1989;
  517.     msg.indate[1]=(char)dos_date.da_mon;
  518.     msg.indate[2]=(char)dos_date.da_day;
  519.     msg.indate[3]=0;
  520.     msg.times=0;
  521.  
  522.     hold=(char *)malloc(msg.length+1);    /* Allocate buffer */
  523.     if (hold==NULL) {
  524.         printf("\nOut of memory.\n");
  525.         fclose(pf);
  526.         fclose(fp);
  527.         fclose(pp);
  528.         exit(4);
  529.     }
  530.     pos=ftell(pp);
  531.     fread(hold,msg.length,1,pp);    /* Read in msg text    */
  532.     fclose(pp);                        /* Done with that file */
  533.  
  534.     hold[msg.length-1]=0;    /* Make sure it's NULL terminated */
  535.  
  536.   {
  537.  
  538.     char *tempo;
  539.  
  540.     tempo=hold;
  541.     while (*tempo) {    /* Strip linefeeds and soft cr's FAST */
  542.         if(*tempo=='\x8d' || *tempo=='\n') {
  543.             if(*tempo=='\n')
  544.                 memmove(tempo,&tempo[1],msg.length-((word)tempo-(word)hold));
  545.             else {
  546.                 if(*(tempo-1)==' ' && tempo>hold)
  547.                     memmove(tempo,&tempo[1],msg.length-((word)tempo-(word)hold));
  548.                 else *tempo=' ';
  549.             }
  550.         }
  551.         tempo++;
  552.     }
  553.     msg.m_attr = (msg.m_attr | MSGTREATED);        /* Reads quicker */
  554.   }
  555.  
  556.     if (!no_strip) {        /* Strip SEEN-BYs, EIDs and other
  557.                                totally useless, inane bullshit  */
  558.         char *tempo=NULL;
  559.         char *path=NULL;
  560.         char *seenby=NULL;
  561.         char *origin=NULL;
  562.  
  563.         msg.attr = (msg.attr | MSGORPHAN);    /* Don't allow reexport of stripped msgs */
  564.         tempo=hold;        /* They oughta outlaw EID's */
  565.         while ((tempo=strstr(tempo,"\01EID:"))) memmove(tempo,strchr(&tempo[1],'\r'),strlen(strchr(&tempo[1],'\r'))+1);
  566.         origin=strstr(hold,"\r * Origin:");        /* Find the origin line */
  567.         if (origin) {        /* Ain't one; oh, well, screw it */
  568.             while(tempo=strstr(&origin[1],"\r * Origin:")) origin=tempo; /* Find last */
  569.             path=strstr(origin,"\r\01PATH:");   /* Find the PATH line */
  570.             seenby=strstr(origin,"\rSEEN-BY:");    /* Find start of SEEN-BYs */
  571.             if (!seenby) seenby=strstr(origin,"\r\01SEEN-BY:");
  572.             if (!path) if (seenby) *seenby=0;  /* Mercifully kill SEEN-BYs */
  573.             if ((seenby && path) && seenby<path) memmove (seenby,path,strlen(path)+1); /* Keep PATH */
  574.         }
  575.         if (hold[strlen(hold)-1]!='\r') strcat(hold,"\r");    /* Assure trailing cr for appearance */
  576.     }
  577.  
  578.     if(!nofillin) {        /* Fill in header address info from kludges */
  579.  
  580.         char *p;
  581.         char *tempo;
  582.         char message[133];
  583.  
  584.         if ((p=strstr(hold,"\01FMPT "))) {
  585.             strncpy(message,p,133);
  586.             message[132]=0;
  587.             p=message;
  588.             msg.o_point=(char)atoi(&p[5]);
  589.         }
  590.         if ((p=strstr(hold,"\01INTL "))) {
  591.             strncpy(message,p,133);
  592.             message[132]=0;
  593.             p=message;
  594.             strtok(p," :");
  595.             strtok(0," ");
  596.             tempo=strtok(0,":");
  597.             if(tempo)if ((word)atol(tempo)) msg.o_zone=(word)atol(tempo);
  598.         }
  599.         if ((p=strstr(hold,"\01MSGID: "))) {
  600.  
  601.             char *ispoint;
  602.             char *isnumsign;
  603.  
  604.                 strncpy(message,&p[7],133);
  605.                 message[132]=0;
  606.                 lstrip(rstrip(message));
  607.                 p=message;
  608.                 ispoint=strchr(p,'.');
  609.                 isnumsign=strchr(p,'#');
  610.                 if(isnumsign) {     /* For [user@]domain#z:n/n.p */
  611.                     if(isnumsign<ispoint || !ispoint) {
  612.                         strtok(p,"#");
  613.                         p=strtok(0,"\n");
  614.                     }
  615.                 }
  616.                 strtok(p," :");
  617.                 p=strtok(0,":");
  618.                 if(p)msg.o_zone=(word)atol(p);
  619.                 p=strtok(0,"/");
  620.                 msg.orig_net=(word)atol(p);
  621.                 if(ispoint) p=strtok(0,".");
  622.                 else p=strtok(0,"@ ");
  623.                 if(p)msg.orig=(word)atol(p);
  624.                 if(ispoint) {
  625.                     p=strtok(0,"@ ");
  626.                     if(p && (word)atol(p) && atol(p)<65536)
  627.                         msg.o_point=(word)atol(p);
  628.                 }
  629.         }
  630.         if ((p=strstr(hold,"\01MSGTO: "))) {
  631.  
  632.             char *ispoint;
  633.             char *isnumsign;
  634.  
  635.             strncpy(message,p,133);
  636.             message[132]=0;
  637.             lstrip(rstrip(message));
  638.             p=message;
  639.             ispoint=strchr(p,'.');
  640.             isnumsign=strtok(p,"#");
  641.             if(isnumsign<ispoint || !ispoint) {
  642.                 p=strtok(p,"#");  /* Get past domain */
  643.                 p=strtok(0,"\n");
  644.             }
  645.             strtok(p," :");
  646.             p=strtok(0,":");
  647.             if(p)msg.d_zone=(word)atol(p);
  648.             p=strtok(0,"/");
  649.             msg.dest_net=(word)atol(p);
  650.             if(ispoint) p=strtok(0,".");
  651.             else p=strtok(0,"@ ");
  652.             if(p)msg.dest=(word)atol(p);
  653.             if(ispoint) {
  654.                 p=strtok(0,"@ ");
  655.                 if(p && (word)atol(p) && atol(p)<65536)
  656.                     msg.d_point=(word)atol(p);
  657.             }
  658.         }
  659.     }
  660.  
  661.     msg.length=(word)(strlen(hold))+1;  /* How long the useful part is */
  662.  
  663.     if(compress_size && strlen(hold)>compress_size) {
  664.  
  665.         char *tempo;
  666.  
  667.         tempo=hold;
  668.         hold=pack_msg(hold,&msg);
  669.         if(!hold) hold=tempo;
  670.         else {
  671.             free(tempo);
  672.             msg.m_attr = msg.m_attr | MSGPACKED;
  673.         }
  674.     }
  675.  
  676.     fwrite(&msg,sizeof(struct _xmsg),1,fp); /* Write header */
  677.     messno++;
  678.  
  679.     fwrite(hold,msg.length,1,pf);    /* Save text */
  680.     fputc('\0',pf);                     /* NULL terminate */
  681.     free(hold);                         /* Free buffer */
  682.  
  683. Discard:
  684.  
  685.     remove(file);            /* Get rid of pesky *.MSG  */
  686.     if (!messno) {            /* Rolled over word bounds */
  687.         printf("\nMessage base is full\n");
  688.         return 0;
  689.     }
  690.  } while (number);            /* Do it again...    */
  691.  fclose(pf);                /* Clean up and exit */
  692.  fclose(fp);
  693.  return number;
  694.  
  695. }
  696.  
  697.  
  698.  
  699. void pascal getone (char *s, FILE *fp, word lineno) {
  700.  
  701.     /* Get one line at a time from file, skip comments, stop at eof */
  702.  
  703.    do {
  704.        if (!fgets(s,512,fp)) *s=0;
  705.        lineno++;
  706.    } while (!feof(fp) && *s==';');
  707.    if (feof(fp)) *s=0;
  708.  
  709. }
  710.  
  711.  
  712.  
  713. char * pascal rstrip (char *a) {    /* Strip trailing blanks */
  714.  
  715.   register word x;
  716.  
  717.   x=strlen(a)-1;
  718.   while (a[x-1]==' ' && x) a[--x]=0;
  719.   return a;
  720. }
  721.  
  722.  
  723.  
  724. char * pascal lstrip (char *a) {    /* Strip leading blanks */
  725.  
  726.   register word x;
  727.  
  728.   x=strlen(a);
  729.   while (*a && *a==' ') memmove (a,&a[1],x--);
  730.   return (a);
  731. }
  732.  
  733.  
  734.  
  735. char * pascal stripcr (char *a)        /* Strip ending cr's &/| lf's */
  736.  
  737. {
  738.  
  739.   register word x;
  740.  
  741.   x=strlen(a);
  742.   while (a[x-1]=='\n' || a[x-1]=='\r') a[--x]=0;
  743.   return a;
  744.  
  745. }
  746.  
  747.  
  748. char * pascal stristr (char *t, char *s) {
  749.  
  750.    char *t1;
  751.    char *s1;
  752.  
  753.    while(*t) {
  754.       t1=t;
  755.       s1=s;
  756.       while(*s1) {
  757.          if (toupper(*s1)!=toupper(*t)) break;
  758.          else {
  759.             s1++;
  760.             t++;
  761.          }
  762.       }
  763.       if (!*s1) return t1;
  764.       t=t1+1;
  765.    }
  766.    return NULL;
  767. }
  768.  
  769.  
  770. void pascal make_attach (char *filetosend) {
  771.  
  772.     char *p;
  773.  
  774.     p=nodes;  /* Point to list of nodes          */
  775.               /* This, obviously, isn't finished */
  776.  
  777. }
  778.