home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / MAKEARC3.ZIP / MAKEARC2.C < prev   
Encoding:
C/C++ Source or Header  |  1992-03-01  |  19.3 KB  |  772 lines

  1. /* MakeArc copyright (c) 1990 by M. Kimes -- All Rights Reserved    */
  2. /* Version 3.02   You can use this freely.  Check with me before    */
  3. /* releasing modified executables or source, please (I'll probably  */
  4. /* allow it).  Exceptions:  Strict translation to foreign languages */
  5. /* and ports to other platforms (non-MS/DOS.                        */
  6. /* Corrections, bug reports, etc. welcome.  Flames ignored by a     */
  7. /* master.  Meaningless "bugs" handled via DUFUS verb.              */
  8.  
  9.  
  10. #include <time.h>
  11. #include <dos.h>
  12. #include <stdio.h>
  13. #include <conio.h>
  14. #include <stdlib.h>
  15. #include <io.h>
  16. #include <fcntl.h>
  17. #include <ctype.h>
  18. #include <process.h>
  19. #include <string.h>
  20.  
  21. typedef unsigned int _word;
  22.  
  23. /* Message header */
  24.  
  25. struct _msg {
  26.   char from[36];
  27.   char to[36];
  28.   char subj[72];
  29.   char date[20];
  30.   _word times;
  31.   _word dest;
  32.   _word orig;
  33.   _word cost;
  34.   _word orig_net;
  35.   _word dest_net;
  36.   int  msg_filler[4];
  37.   _word reply;
  38.   _word attr;
  39.   _word up;
  40. };
  41.  
  42. /* Message attributes */
  43.  
  44. #define MSGPRIVATE 0x0001
  45. #define MSGCRASH   0x0002
  46. #define MSGREAD    0x0004
  47. #define MSGSENT    0x0008
  48. #define MSGFILE    0x0010
  49. #define MSGFWD     0x0020
  50. #define MSGORPHAN  0x0040
  51. #define MSGKILL    0x0080
  52. #define MSGLOCAL   0x0100
  53. #define MSGXX1     0x0200
  54. #define MSGXX2     0x0400
  55. #define MSGFRQ     0x0800
  56. #define MSGRRQ     0x1000
  57. #define MSGCPT     0x2000
  58. #define MSGARQ     0x4000
  59. #define MSGURQ     0x8000
  60.  
  61. /* Packet header structure per FSC-0045 */
  62.  
  63.     struct _pkthdr {
  64.         unsigned int
  65.             onode,
  66.             dnode,
  67.             opoint,
  68.             dpoint;
  69.         char
  70.             zeros[8];
  71.         unsigned int
  72.             subver,
  73.             version,
  74.             onet,
  75.             dnet;
  76.         char
  77.             product,
  78.             rev_lev,
  79.             password[8];
  80.         unsigned int
  81.             ozone,
  82.             dzone;
  83.         char
  84.             odomain[8],
  85.             ddomain[8];
  86.         long
  87.             specific;
  88.         unsigned int
  89.             first;
  90.     };
  91.  
  92.     typedef struct _pkthdr PKTHDR;
  93.  
  94. /* Global flags and variables */
  95.  
  96. extern unsigned char msgattach;     /* Make *.MSG attaches? */
  97. extern _word myzone;                /* For our address */
  98. extern _word mynet;                 /* " */
  99. extern _word mynode;                /* " */
  100. extern _word mypoint;               /* " */
  101. extern char configfile[133];        /* Config file to read */
  102. extern char root[128];                /* 'Root' outbound dir */
  103. extern char outbound[133];            /* Extended outbound dir */
  104. extern char netdir[128];            /* Net msg directory if *.MSG attaches */
  105. extern char arccmd[128];            /* Default archive command */
  106. extern unsigned char alltype;       /* Default mail type */
  107. extern unsigned char didbreak;      /* CTRL-BREAK flag */
  108. extern char schedtag[128];            /* Schedule tag */
  109. extern _word lines;                 /* For debug info */
  110. extern unsigned char debug;         /* debug on? */
  111. extern unsigned char more;          /* more on? */
  112. extern unsigned char usingbink;     /* Use BINKLEY.CFG? */
  113. extern _word rzone;                 /* For routing */
  114. extern _word rnet;                  /* " */
  115. extern _word rnode;                 /* " */
  116. extern _word rpoint;                /* " */
  117.  
  118. /* Function definitions */
  119.  
  120. char     _fastcall spawnit (char *a);
  121. char     _fastcall check_4flo (_word zone,_word net,_word node,_word point);
  122. char *   _fastcall stristr (char *t, char *s);
  123. void     _cdecl  deinit(void);
  124. void     _fastcall say_error (long lastpos,FILE *fp);
  125. int      _fastcall makearc (char *arcfile,char *pktfile,char *origpkt,char *outbound);
  126. _word    _fastcall makeflo(_word zone,_word net,_word node,_word point,char *sendfile,char type);
  127. _word    _fastcall makemessage (_word zone,_word net,_word node,_word point,char *sendfile,char type);
  128. void     _fastcall next_name(char *);
  129. void     _fastcall make_poll (char *line,long lastpos,FILE *fp);
  130. FILE *   _fastcall analyze(char *);
  131. char *   _fastcall arcname(_word,_word);
  132. char *   _fastcall filename(_word,_word);
  133. char *   _fastcall fidodate(void);
  134. char *   _fastcall lstrip(char *);
  135. char *   _fastcall rstrip(char *);
  136. char *   _fastcall stripcr(char *);
  137. void     _fastcall moveit (struct find_t *f, char *myoutbound, char *outbound, char type, char archive,_word net,_word node,_word fromzone);
  138. void     _fastcall move_prep(char *line,long lastpos,FILE *fp);
  139. void     _fastcall change_mail(char *line,long lastpos,FILE *fp);
  140. long     _fastcall make_msgid(void);
  141. char *   _fastcall find_sched(FILE *fp,char *schedtag,int wholefile);
  142. char *   _fastcall skip_white(char *);
  143. char *   _fastcall skip_nonwhite(char *);
  144. char *   _fastcall to_delim(char *,char *);
  145.  
  146. /* ID stuff */
  147.  
  148. #define MAKEVER "302"
  149.  
  150. #define PID_ID "MA 302"
  151.  
  152. #define BETA
  153.  
  154.  
  155.  
  156. void _fastcall move_prep (char *line,long lastpos,FILE *fp) {
  157.  
  158.     char flo[133];                /* Used to find (& destroy) flo files */
  159.     char arc[133];                /* Used to find arc files */
  160.     char pkt[133];                /* Used to find packets */
  161.     unsigned int zone,net,node; /* Address to move to */
  162.     unsigned int fromzone;        /* Zone to move mail from */
  163.     char outbound[84];            /* His calculated outbound name */
  164.     struct find_t f;                  /* The better to find them with, my dearie */
  165.     char *p;                    /* Used to parse address */
  166.     char type;                    /* Type of mail ([H]old, [C]rash, etc.) */
  167.  
  168.     lstrip(line);
  169.     stripcr(line);
  170.     rstrip(line);
  171.     p=strtok(line," ");
  172.     if(!p) return;
  173.     fromzone=(_word)atol(p);
  174.     if(!fromzone) return;
  175.     p=strtok(0,":");
  176.     if(!p) return;
  177.     zone=(_word)atol(p);
  178.     if(zone==fromzone) return;    /* Duh... */
  179.     if(!zone) return;
  180.     p=strtok(0,"/");
  181.     if(!p) return;
  182.     net=(_word)atol(p);
  183.     if(!net) return;
  184.     p=strtok(0," ");
  185.     if(!p) return;
  186.     node=(_word)atol(p);
  187.     p=strtok(0,";\n");
  188.     type=toupper(*p);
  189.     if(type!='H' && type!='C' && type!='F' && type!='D' && type!='N' && type!='O') return;
  190.  
  191.     /* Make mask for outbound flo, packet and arc files */
  192.  
  193.     if(fromzone!=myzone) {
  194.         sprintf(pkt,"%s.%03x\\%04x%04x.?UT",root,fromzone,net,node);
  195.         sprintf(arc,"%s.%03x\\%04x%04x.*",root,fromzone,mynet-net,mynode-node);
  196.         sprintf(flo,"%s.%03x\\%04x%04x.?LO",root,fromzone,net,node);
  197.     }
  198.     else {
  199.         sprintf(pkt,"%s\\%04x%04x.?UT",root,net,node);
  200.         sprintf(arc,"%s\\%04x%04x.*",root,mynet-net,mynode-node);
  201.         sprintf(flo,"%s\\%04x%04x.?LO",root,net,node);
  202.     }
  203.     if(zone!=myzone) sprintf(outbound,"%s.%03x",root,zone);
  204.     else strcpy(outbound,root);
  205.  
  206.     if(!_dos_findfirst(flo,0,&f)) {
  207.         printf("Removing FLO files addressed to %u:%u/%u\n",fromzone,net,node);
  208.         do {
  209.             if(fromzone==myzone) sprintf(flo,"%s\\%s",root,f.name);
  210.             else sprintf(flo,"%s.%03x\\%s",root,fromzone,f.name);
  211.             unlink(flo);
  212.         } while(!_dos_findnext(&f));
  213.     }
  214.     if(!_dos_findfirst(pkt,0,&f)) {
  215.         if(fromzone==myzone) {
  216.             moveit(&f,root,outbound,type,0,net,node,fromzone);
  217.         }
  218.         else {
  219.             sprintf(flo,"%s.%03x",root,fromzone);
  220.             moveit(&f,flo,outbound,type,0,net,node,fromzone);
  221.         }
  222.     }
  223.     if(!_dos_findfirst(arc,0,&f)) {
  224.         if(fromzone==myzone)moveit(&f,root,outbound,type,1,net,node,fromzone);
  225.         else {
  226.             sprintf(flo,"%s.%03x",root,fromzone);
  227.             moveit(&f,flo,outbound,type,0,net,node,fromzone);
  228.         }
  229.     }
  230.     return;
  231. }
  232.  
  233.  
  234.  
  235.  
  236. void _fastcall moveit (struct find_t *f, char *myoutbound, char *outbound, char type, char archive,_word net,_word node,_word fromzone) {
  237.  
  238.     FILE *fp=NULL;
  239.     FILE *fp2;
  240.     char once=0;
  241.     long temp=0L;
  242.  
  243.     char wasname[133];
  244.     char isname[133];
  245.     char scratch[290];
  246.  
  247.     if(archive) {                   /* If archive, open flo file for append */
  248.         sprintf(wasname,"%s\\%04x%04x.%cLO",outbound,net,node,type);
  249.         fp=fopen(wasname,"at");
  250.         if(fp)fseek(fp,0L,SEEK_END);
  251.     }
  252.  
  253.     do {
  254.         if(!f->size) continue;
  255.         if(!once){
  256.             if(archive)printf("Moving archived mail addressed to %u:%u/%u\n",fromzone,net,node);
  257.             else printf("Moving packets addressed to %u:%u/%u\n",fromzone,net,node);
  258.         }
  259.         once=1;
  260.         sprintf(wasname,"%s\\%s",myoutbound,f->name);
  261.         sprintf(isname,"%s\\%s",outbound,f->name);
  262.         if(!archive) isname[strlen(isname)-3]=type;   /* Set mail type */
  263.         sprintf(scratch,"COPY %s %s > NUL",wasname,isname);
  264.         system(scratch);
  265.         unlink(wasname);
  266.         if(archive) {                           /* Only for archives */
  267.             fp2=fopen(wasname,"wb");
  268.             if(fp2)fclose(fp2);                   /* Leave truncated filename */
  269.             if(fp) fprintf(fp,"^%s\n",isname); /* Add name to the flo file */
  270.         }
  271.     } while(!_dos_findnext(f));                /* Til there ain't no more */
  272.  
  273.     if(fp) {
  274.         fseek(fp,0L,SEEK_END);
  275.         if(ftell(fp)==0L) {
  276.             fclose(fp);
  277.             sprintf(wasname,"%s\\%04x%04x.%cLO",outbound,net,node,type);
  278.             unlink(wasname);
  279.         }
  280.         else fclose(fp);
  281.     }
  282. }
  283.  
  284.  
  285. void _fastcall change_mail (char *line,long lastpos,FILE *fp) {
  286.  
  287.     unsigned int zone,net,node; /* Address to change mail type for */
  288.     char flo[133];
  289. /*    char req[133];    */
  290.     char pkt[133];
  291.     char outbound[84];
  292.     struct find_t f;
  293.     struct find_t f1;
  294.     char *p;
  295.     char type;
  296.     char s[133];
  297.     char s1[133];
  298.     FILE *infile=NULL;
  299.     FILE *outfile;
  300.     unsigned int bytes;
  301.  
  302.     lstrip(line);
  303.     stripcr(line);
  304.     rstrip(line);
  305.     zone=myzone;
  306.     net=0;
  307.     node=0;
  308. printf("!!!%s!!!\n",line);
  309.     if(!strnicmp(line,"ALL ",4)) {    /* This doesn't work yet; don't use it */
  310.         p=line+4;
  311.         lstrip(p);
  312. printf("!!!%s!!!\n",p);
  313.         if(!strnicmp(p,"ZONE ",5)) {
  314.             p+=5;
  315.             lstrip(p);
  316. printf("!!!%s!!!\n",p);
  317.             zone=(_word)atol(p);
  318.             if(!zone) {
  319.                 fprintf(stderr,"\nZero Zone #\n");
  320.                 say_error(lastpos,fp);
  321.                 return;
  322.             }
  323.         }
  324.         if(strchr(p,' ')) {
  325.             p=strchr(p,' ');
  326.             p++;
  327.             type=*p;
  328.         }
  329.         else type=alltype;
  330.         p=NULL;
  331.     }
  332.     else {
  333.         p=strtok(line,":");
  334.         if(!p) {
  335.             fprintf(stderr,"\nMissing Zone\n");
  336.             say_error(lastpos,fp);
  337.             return;
  338.         }
  339.         zone=(_word)atol(p);
  340.         if(!zone) {
  341.             fprintf(stderr,"\nZero Zone\n");
  342.             say_error(lastpos,fp);
  343.             return;
  344.         }
  345.         p=strtok(0,"/");
  346.         if(!p) {
  347.             fprintf(stderr,"\nMissing Net\n");
  348.             say_error(lastpos,fp);
  349.             return;
  350.         }
  351.         net=(_word)atol(p);
  352.         if(!net) {
  353.             fprintf(stderr,"\nZero Net\n");
  354.             say_error(lastpos,fp);
  355.             return;
  356.         }
  357.         p=strtok(0," ");
  358.         if(!p) {
  359.             fprintf(stderr,"\nMissing Node\n");
  360.             say_error(lastpos,fp);
  361.             return;
  362.         }
  363.         node=(_word)atol(p);
  364.         p=strtok(0,"; \n");
  365.         if(!p) type=alltype;
  366.         else type=toupper(*p);
  367.     }
  368.     if(type!='H' && type!='C' && type!='F' && type!='D' && type!='N' && type!='O') {
  369.         fprintf(stderr,"\nInvalid mail type `%c'\n",type);
  370.         say_error(lastpos,fp);
  371.         return;
  372.     }
  373.  
  374.     /* Make mask for outbound flo, packet and arc files */
  375.  
  376.     if(zone!=myzone)sprintf(outbound,"%s.%03x",root,zone);
  377.     else strcpy(outbound,root);
  378.  
  379.     if(net)sprintf(pkt,"%s\\%04x%04x.?UT",outbound,net,node);
  380.     else sprintf(pkt,"%s\\*.?UT",outbound);
  381.  
  382.     /* Removed the following since Bink 2.40 no longer forces call for REQ */
  383.     /* Left the code in in case you need it */
  384.  
  385. /*    if(type!='H')sprintf(req,"%s\\%04x%04x.HEQ",outbound,net,node);
  386.     else sprintf(req,"%s\\%04x%04x.REQ",outbound,net,node);    */
  387.  
  388.     if(net)sprintf(flo,"%s\\%04x%04x.?LO",outbound,net,node);
  389.     else sprintf(flo,"%s\\*.?LO",outbound);
  390.  
  391.     if(!_dos_findfirst(pkt,0,&f)) {
  392.         if(type=='F') type='N';
  393.         sprintf(s,"%s\\%s",outbound,f.name);
  394.         s[strlen(s)-3]=type;
  395.         if(net)printf("Changing flavor of %u:%u:%01u's mail to %c\n",zone,net,node,type);
  396.         else printf("Changing flavor of Zone #%u's mail to %c\n",zone,type);
  397.         do {
  398.             if(infile==NULL) {
  399.                 if(!_dos_findfirst(s,0,&f1)) {
  400.                     if(f1.size==0L) unlink(s);
  401.                     else {
  402.                         infile=fopen(s,"r+b");
  403.                         if(!infile) {
  404.                             fprintf(stderr,"\nCan't open \'%s\'\n",s);
  405.                             break;
  406.                         }
  407.                         fseek(infile,f.size-4L,SEEK_SET);
  408.                         while((char)fgetc(infile)!='\0' && !feof(infile));    /* Should be right after first of last NULLs */
  409.                     }
  410.                 }
  411.             }
  412.             if(f.name[9]!=type) {
  413.                 sprintf(s1,"%s\\%s",outbound,f.name);
  414.                 if(!infile)rename(s1,s);
  415.                 else {
  416.                     outfile=fopen(s1,"rb");
  417.                     if(!outfile) {
  418.                         fprintf(stderr,"\nCan't open \'%s\'\n",s1);
  419.                         fclose(infile);
  420.                         infile=NULL;
  421.                         break;
  422.                     }
  423.                     fseek(outfile,(long)sizeof(struct _pkthdr),SEEK_SET);    /* skip header to 1st msg */
  424.                     while (!feof(outfile)) {
  425.                         bytes=fread(s1,1,133,outfile);
  426.                         fwrite(s1,1,bytes,infile);
  427.                         if(bytes!=133) break;
  428.                     }
  429.                     fclose(outfile);
  430.                 }
  431.             }
  432.         } while(!_dos_findnext(&f));
  433.     }
  434.     if(infile)fclose(infile);
  435.  
  436.     if(!_dos_findfirst(flo,0,&f)) {
  437.         if(type=='N' || type=='O') type='F';
  438.         sprintf(s,"%s\\%s",outbound,f.name);
  439.         s[strlen(s)-3]=type;
  440.         if(net)printf("Changing flavor of %u:%u:%01u's attach(es) to %c\n",zone,net,node,type);
  441.         else printf("Changing flavor of Zone #%u's attach(es) to %c\n",zone,type);
  442.         do {
  443.             if(infile==NULL) {
  444.                 if(!_dos_findfirst(s,0,&f1)) {
  445. /*                  if(f1.size==0L) unlink(s);
  446.                     else {
  447. */                        infile=fopen(s,"r+b");
  448.                         if(!infile) {
  449.                             fprintf(stderr,"\nCan't open \'%s\'\n",s);
  450.                             break;
  451.                         }
  452.                         fseek(infile,0L,SEEK_END);
  453. /*                    } */
  454.                 }
  455.             }
  456.             if(f.name[9]!=type) {
  457.                 sprintf(s1,"%s\\%s",outbound,f.name);
  458.                 if(!infile)rename(s1,s);
  459.                 else {
  460.                     outfile=fopen(s1,"rb");
  461.                     if(!outfile) {
  462.                         fprintf(stderr,"\nCan't open \'%s\'\n",s1);
  463.                         fclose(infile);
  464.                         infile=NULL;
  465.                         break;
  466.                     }
  467.                     fseek(outfile,0L,SEEK_SET);
  468.                     while (!feof(outfile)) {
  469.                         bytes=fread(s1,1,133,outfile);
  470.                         fwrite(s1,1,bytes,infile);
  471.                         if(bytes!=133) break;
  472.                     }
  473.                     fclose(outfile);
  474.                 }
  475.             }
  476.         } while(!_dos_findnext(&f));
  477.     }
  478.     if(infile)fclose(infile);
  479.  
  480. /*    if(!_dos_findfirst(req,0,&f)) {
  481.         sprintf(s,"%s\\%s",outbound,f.name);
  482.         if(type=='H')s[strlen(s)-3]='H';
  483.         else {
  484.             type='R';
  485.             s[strlen(s)-3]='R';
  486.         }
  487.         if(net)printf("Changing flavor of %u:%u:%01u's REQ(s) to %c\n",zone,net,node,type);
  488.         else printf("Changing flavor of Zone #%u's REQ(s) to %c\n",zone,type);
  489.         do {
  490.             if(infile==NULL) {
  491.                 if(!_dos_findfirst(s,0,&f1)) {
  492.                     if(f1.size==0L) unlink(s);
  493.                     else {
  494.                         infile=fopen(s,"r+b");
  495.                         if(!infile) {
  496.                             fprintf(stderr,"\nCan't open \'%s\'\n",s);
  497.                             break;
  498.                         }
  499.                         fseek(infile,0L,SEEK_END);
  500.                     }
  501.                 }
  502.             }
  503.             if(f.name[9]!=type) {
  504.                 sprintf(s1,"%s\\%s",outbound,f.name);
  505.                 if(!infile)rename(s1,s);
  506.                 else {
  507.                     outfile=fopen(s1,"rb");
  508.                     if(!outfile) {
  509.                         fprintf(stderr,"\nCan't open \'%s\'\n",s1);
  510.                         fclose(infile);
  511.                         infile=NULL;
  512.                         break;
  513.                     }
  514.                     fseek(outfile,0L,SEEK_SET);
  515.                     while (!feof(outfile)) {
  516.                         bytes=fread(s1,1,133,outfile);
  517.                         fwrite(s1,1,bytes,infile);
  518.                         if(bytes!=133) break;
  519.                     }
  520.                     fclose(outfile);
  521.                 }
  522.             }
  523.         } while(!_dos_findnext(&f));
  524.     }
  525.     if(infile)fclose(infile);
  526. */
  527. }
  528.  
  529.  
  530. void _fastcall make_poll (char *line,long lastpos,FILE *pf) {
  531.  
  532.     char *p;
  533. /*    char *pw;    */
  534.     _word zone,net,node;
  535. /*  _word point; */
  536. /*    FILE *fp;    */
  537.     char s[133];
  538. /*    struct _pkthdr ph;    */
  539.     struct find_t f;
  540.  
  541.     /* Once created an empty poll packet.  Left the code in (commented
  542.        out) in case you need them.  What I do now is just create an empty
  543.        *.CLO file, which won't be routed on subsequent passes. */
  544.  
  545.     lstrip(line);
  546.     stripcr(line);
  547.     rstrip(line);
  548.     p=strtok(line,":");
  549.     if(!p) return;
  550.     zone=(_word)atol(p);
  551.     if(!zone) return;
  552.     p=strtok(0,"/");
  553.     if(!p) return;
  554.     net=(_word)atol(p);
  555.     if(!net) return;
  556.     p=strtok(0,". ");
  557.     if(!p) return;
  558.     node=(_word)atol(p);
  559. /*    if(strchr(p,'.')) {
  560.         p=strchr(p,'.');
  561.         p++;
  562.         point=(_word)atol(p);
  563.     }
  564.     else point=0;
  565. */
  566.  
  567.     /* The empty *.CLO creator */
  568.  
  569.     if(zone!=myzone) sprintf(outbound,"%s\\.%03x",root,zone);
  570.     else strcpy(outbound,root);
  571.     sprintf(s,"%s\\%04x%04x.CLO",outbound,net,node);
  572.     if(_dos_findfirst(s,0,&f)) return;
  573.     fclose(fopen(s,"wb"));
  574.     printf("Created poll attach for %u:%u/%01u\n",zone,net,node);
  575.     return;
  576.  
  577. /*  Code below is the empty packet creator, commented out... */
  578. /*
  579.     pw=strtok(0,"\n ");    */        /* Password if any */
  580. /*
  581.     if(zone!=myzone) sprintf(outbound,"%s\\.%03x",root,zone);
  582.     else strcpy(outbound,root);
  583.  
  584.     sprintf(s,"%s\\%04x%04x.CUT",outbound,net,node);
  585.     if(!_dos_findfirst(s,0,&f)) return;
  586.  
  587.     fp=fopen(s,"wb");
  588.     if(!fp) {
  589.         fprintf(stderr,"\nCan't open poll packet `%s'\n",s);
  590.         return;
  591.     }
  592.  
  593.     memset(ph,0,sizeof(PKTHDR));
  594.     ph.onode=mynode;
  595.     ph.dnode=node;
  596.     ph.rate=2;
  597.     ph.ver=2;
  598.     ph.onet=mynet;
  599.     ph.dnet=net;    */
  600. /*    ph.product=0;    */    /* Until I get a product code (snore) */
  601. /*    ph.rev_lev=201;    */    /* Well, it's gotta be something... */
  602. /*  if(pw) strcpy(ph.password,pw);
  603.     ph.ozone=myzone;
  604.     ph.dzone=zone;
  605.     ph.opoint=mypoint;
  606.     ph.dpoint=point;
  607.     ph.pr_data=0L;
  608.  
  609.     fwrite(&ph,sizeof(struct _pkthdr),1,fp);
  610.     printf("Created poll packet for %u:%u/%01u.%01u\n",zone,net,node,point);
  611.     fclose(fp);
  612. */
  613. }
  614.  
  615.  
  616.  
  617. char * _fastcall stristr (char *t, char *s) {
  618.  
  619.    char *t1;
  620.    char *s1;
  621.  
  622.    /* Case-insensitive strstr()--Turbo C didn't have one */
  623.  
  624.    while(*t) {
  625.       t1=t;
  626.       s1=s;
  627.       while(*s1) {
  628.          if (toupper(*s1)!=toupper(*t)) break;
  629.          else {
  630.             s1++;
  631.             t++;
  632.          }
  633.       }
  634.       if (!*s1) return t1;
  635.       t=t1+1;
  636.    }
  637.    return NULL;
  638. }
  639.  
  640.  
  641.  
  642. char _fastcall spawnit (char *a) {
  643.  
  644.    /* Handle spawning external programs (usually archivers) */
  645.  
  646.     return system(a);
  647. }
  648.  
  649.  
  650.  
  651. long _fastcall make_msgid (void) {
  652.  
  653.     time_t t;
  654.     static _word counter = 0;
  655.  
  656.     /* Create a msgid serial number, including a counter */
  657.  
  658.     t = time(NULL);
  659.     t = (t << 4L) | (long)(counter++ & 15);
  660.     return t;
  661. }
  662.  
  663.  
  664.  
  665. char * _fastcall find_sched (FILE *pf, char *schedtag, int wholefile) {
  666.  
  667.     char *p;
  668.     char s[256];
  669.  
  670.     /* Given a file pointer and schedule tag string, searches file for
  671.        schedule tag and returns it if found.  Returns NULL if not. */
  672.  
  673.     while(1) {
  674.         if(!fgets(s,256,pf)) {
  675.             if(wholefile) {        /* Reset and try once more */
  676.                 wholefile=0;
  677.                 lines=0;
  678.                 fseek(pf,0L,SEEK_SET);
  679.                 continue;
  680.             }
  681.             fprintf(stderr,"\nRequested schedule tag '%s' not found.\n",schedtag);
  682.             return NULL;
  683.         }
  684.         lines++;
  685.         if(debug)printf("%u. %s",lines,s);
  686.         lstrip(s);
  687.         while(p=strchr(s,'\t')) *p=' ';
  688.         if(p=strchr(s,';')) *p=0;
  689.         p=s;
  690.         if(usingbink) {
  691.            if(strnicmp(p,"APPLICATION MAKEARC ",20)) continue; /* Not ours */
  692.            p+=20;
  693.            lstrip(p);
  694.         }
  695.         if(!strnicmp(p,"SCHED ",6)) {
  696.             p+=6;
  697.             lstrip(p);
  698.             stripcr(p);
  699.             rstrip(p);
  700.  
  701.             if(!stricmp(p,schedtag)) {
  702.                 printf("Processing schedule tag '%s'\n",schedtag);
  703.                 break;
  704.             }
  705.         }
  706.     }
  707.     return p;
  708. }
  709.  
  710.  
  711.  
  712. char * _fastcall skip_white (char *p) {
  713.  
  714.     while(*p && (*p==' ' || *p=='\t')) *p++;
  715.     return p;
  716. }
  717.  
  718.  
  719. char * _fastcall skip_nonwhite (char *p) {
  720.  
  721.     while(*p && *p!=' ' && *p!='\t')*p++;
  722.     return p;
  723. }
  724.  
  725.  
  726. char * _fastcall to_delim (char *p, char *delim) {
  727.  
  728.     char *d;
  729.  
  730.     while(*p) {
  731.          d=delim;
  732.          while(*d && *p!=*d) d++;
  733.          if(*p==*d) break;
  734.          p++;
  735.     }
  736.     return p;
  737. }
  738.  
  739.  
  740.  
  741. char * _fastcall rstrip (char *a) {    /* Remove trailing spaces and tabs */
  742.  
  743.   register int x;
  744.  
  745.   x=strlen(a);
  746.   while (x && a && (a[x-1]==' ' || a[x-1]=='\t')) a[--x]=0;
  747.   return a;
  748. }
  749.  
  750.  
  751.  
  752.  
  753. char * _fastcall lstrip (char *a) {    /* Remove leading spaces and tabs */
  754.  
  755.   register int x;
  756.  
  757.   x=strlen(a);
  758.   while (x && (*a==' ' || *a=='\t')) memmove (a,(a+1),x--);
  759.   return (a);
  760. }
  761.  
  762.  
  763.  
  764. char * _fastcall stripcr (char *a) {   /* Remove trailing crs and lfs */
  765.  
  766.   register int x;
  767.  
  768.   x=strlen(a);
  769.   while (x && (a[x-1]=='\n' || a[x-1]=='\r')) a[--x]=0;
  770.   return a;
  771. }
  772.