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

  1. /* XBBS Home Message System GateKeeper */
  2. /* Copyright (c) 1989 by M. Kimes      */
  3. /* This could probably use some kind of local dupe checking mechanism... */
  4. /* Doesn't SHARE yet */
  5.  
  6. #include "msgg.h"
  7.  
  8. struct _config conf;
  9. struct _user user;    /* Dodging some kinda bug */
  10. struct _user useit;
  11. word   userno=0;
  12.  
  13. char   reader[48]="XHMS";
  14. struct ffblk f;
  15. char   nodenumber=1;
  16. word   othernumber;
  17.  
  18. void   pascal getline (char *);
  19. char * pascal say_prompt(word);
  20. char * pascal addtolog (char *);
  21. void   pascal readconfig(void);
  22. void   killall(void);
  23. ulong  merge_area(void);
  24. char * stripcr(char *);
  25. char * fidodate(void);
  26. word   find__msgarea(char *,char *);
  27.  
  28. main (int argc, char *argv[]) {
  29.  
  30.     struct fdate {
  31.       bit day:   5;
  32.       bit month: 4;
  33.       bit year:  7;
  34.     };
  35.     union df {
  36.       struct fdate fd;
  37.       int x;
  38.     } fdf;
  39.     struct date dos_date;
  40.     FILE *fp;
  41.     char s[256];
  42.     char *pp;
  43.     word zone;
  44.     word net;
  45.     word node;
  46.     ulong tempposts;
  47.     char indir[133]="MPORT"; /* Would be MPORT0 for node 0, MPORT2 for node 2, etc. */
  48.  
  49.     if(argc>1) nodenumber=(char)atoi(argv[1]);
  50.     if(nodenumber!=1) {
  51.         sprintf(indir,"MPORT%01hu",nodenumber);
  52.     }
  53.  
  54.     printf("\n\n\n\x1b[A\x1b[0;2;37;7mXGATEKPR copyright (c) 1989/90 by M. Kimes running...\x1b[0;2;37m\n");
  55.     printf("  (Pass node number if not 1)\n");
  56.  
  57.     readconfig();                      /* Get config info */
  58.     if (!conf.lastusernum) {          /* Check to see valid user was last */
  59.         addtolog("XGATEKPR: Last user number was 0");
  60.         printf("\nLast user number is 0, aborting...\n");
  61.         exit(253);
  62.     }
  63.     sprintf(s,"%sonline.xbs",conf.homepath);
  64.     if((fp=fopen(s,"rb"))) {
  65.         fread(&useit,sizeof(struct _user),1,fp);
  66.         fread(&userno,sizeof(userno),1,fp);
  67.         fclose(fp);
  68.         if (userno!=conf.lastusernum) {
  69.  
  70.             char temp[30];
  71.             char logem=60;
  72.             char keyin=0;
  73.  
  74.             printf("\nMismatch between user number from ONLINE.XBS and CONFIG.BBS!\x7\n");
  75.             printf("\n[ESC] to process as %s, [Enter] to abort:    ",conf.lastcaller);
  76.             while (--logem) {
  77.                 printf("%s%s%02u",BACKSPACE,BACKSPACE,logem);
  78.                 if (kbhit()) keyin=(char)getch();
  79.                 if (keyin==13) {
  80.                     printf("\nAborting...\n");
  81.                     exit(0);
  82.                 }
  83.                 if (keyin==27) {
  84.                     printf("\nProcessing anyway...\n");
  85.                     break;
  86.                 }
  87.                 if (!(logem % 5)) printf("\x7");
  88.                 sleep(1);
  89.             }
  90.             if (keyin!=27) {
  91.                 printf("\nTime out: aborting...\n");
  92.                 addtolog("XGATEKPR: Mismatch in last user # ONLINE.XBS <-> CONFIG.BBS");
  93.                 exit(240);
  94.             }
  95.         }
  96.     }
  97.     if(findfirst("users.bbs",&f,0)) { /* Get user info   */
  98.         addtolog("XGATEKPR: Can't find userfile");
  99.         printf("\nYou don't have a userfile.\n");
  100.         exit(253);
  101.     }
  102.     if (!(fp=fopen("users.bbs","rb"))) {
  103.         addtolog("XGATEKPR: Can't open userfile");
  104.         printf("\nError opening userfile.\n");
  105.         exit(253);
  106.     }
  107.     fseek(fp,((long)sizeof(struct _user)*(long)(conf.lastusernum-1L)),SEEK_SET);
  108.     fread(&useit,sizeof(struct _user),1,fp);
  109.     fclose(fp);
  110.     tempposts=useit.posts;
  111.  
  112.     printf("\nUser#%u: %s (%s)\n",conf.lastusernum,useit.name,useit.handle);
  113.  
  114.     sprintf(s,"%s\\*.RPK",indir);
  115.     if (findfirst(s,&f,0)) {    /* Check for packet */
  116.         addtolog("XGATEKPR: No mail to process");
  117.         printf("\nNo mail to process in directory %s.\n",indir);
  118.         exit(254);
  119.     }
  120.     if (chdir (indir)) {               /* Switch to response directory */
  121.         addtolog("XGATEKPR: Directory switching error");
  122.         printf("\nCouldn't switch to response directory\n");
  123.         printf("\nAborting...\n");
  124.         exit(252);
  125.     }
  126.     sprintf(s,"%04x%04x.RPK",conf.net,conf.node);  /* Check filename */
  127.     strupr(s);
  128.     strupr(f.ff_name);
  129.     if (strcmp(s,f.ff_name)) {
  130.         printf("\nMail packet %s is not for this BBS!\n",f.ff_name);
  131.         remove(f.ff_name);
  132.         chdir("..");
  133.         sprintf(s,"XGATEKPR: Mail packet %s not for us",f.ff_name);
  134.         addtolog(s);
  135.         exit(247);
  136.     }
  137.  
  138.     printf("\nDisassembling reply packet...\n");
  139.     sprintf(s,say_prompt(357),f.ff_name);
  140.     system (s);                       /* Unarchive packet */
  141.     remove(f.ff_name);
  142.     if (findfirst("rareas.xbs",&f,0)) f.ff_ftime=1;
  143.     if (f.ff_ftime!=0) {
  144.         printf("\nFile has been tampered with!\n");
  145.         printf("\nClearing out response directory...\n");
  146.         killall();
  147.         chdir("..");
  148.         addtolog("XGATEKPR: Tampered files wiped");
  149.         exit(248);
  150.     }
  151.     getdate(&dos_date);
  152.     fdf.x=f.ff_fdate;
  153.     if (((fdf.fd.year+1980)<(dos_date.da_year-1)) || fdf.fd.month>dos_date.da_mon || fdf.fd.day>dos_date.da_day) {
  154.         printf("\nQuestionable packet date: %02u/%02u/%02u -- %02d/%02hu/%02hu\n",(word)((fdf.fd.year+80)%100),(word)fdf.fd.month,(word)fdf.fd.day,dos_date.da_year,dos_date.da_mon,dos_date.da_day);
  155.         sprintf(s,"XGATEKPR: Questionable pkt date: %02u/%02u/%04u",(word)fdf.fd.month,(word)fdf.fd.day,(word)(fdf.fd.year+1980));
  156.         addtolog(s);
  157.     }
  158.     if (!(fp=fopen("rareas.xbs","r"))) {
  159.         addtolog("XGATEKPR: No RAREAS.XBS in packet");
  160.         printf("\nCan't open RAREAS.XBS control file\n");
  161.         printf("\nClearing out response directory...\n");
  162.         killall();
  163.         chdir("..");
  164.         exit(251);
  165.     }
  166.     fgets(s,256,fp);               /* Check first line for valid address */
  167.     stripcr(s);
  168.     zone=(word)atol(strtok(s,":"));
  169.     net=(word)atol(strtok(0,"/"));
  170.     node=(word)atol(strtok(0,"."));
  171.     pp=strtok(0,"-");
  172.     if (pp) strncpy(reader,pp,48);
  173.     reader[47]=0;
  174.     printf("\nPacket is for %u:%u/%u\n",zone,net,node);
  175.     if (zone!=conf.zone || net!=conf.net || node!=conf.node) {
  176.         printf("\nReply packet is not for this BBS!\n");
  177.         printf("\nClearing out response directory...\n");
  178.         killall();
  179.         chdir("..");
  180.         sprintf(s,"XGATEKPR: Mail packet for %u:%u/%u",zone,net,node);
  181.         addtolog(s);
  182.         exit(250);
  183.     }
  184.  
  185.     /* Ok, we've got an apparently valid RAREAS.XBS control file.
  186.        Now we can process the msg areas listed in it, merging them
  187.        into our own message base */
  188.  
  189.     printf("Processing reply packet from %s...\n",reader);
  190.     while (!feof(fp)) {                    /* Get area from uploaded list */
  191.         if (!fgets(s,255,fp)) break;
  192.         if (*s=='\n' || *s==';') continue;
  193.         stripcr(s);
  194.         strncpy(conf.mboard.name,strtok(s,","),48);
  195.         conf.mboard.name[47]=0;
  196.         conf.mboard.attr=(word)atoi(strtok(0," ,"));
  197.         conf.mboard.max=(word)atoi(strtok(0," ,"));
  198.         conf.mboard.number=(word)atoi(strtok(0," ,"));
  199.         if(conf.mboard.attr & READONLY || conf.mboard.attr & NET || conf.mboard.attr & ALTERNATE) {
  200.             printf("\nMsg in unsupported area type\n");
  201.             continue;
  202.         }
  203.         if (conf.mboard.number) { /* Check for moved area against BBS list
  204.                                      and use our info, anyway */
  205.  
  206.             word tempnumber;
  207.             char tmp[133];
  208.  
  209.             sprintf(tmp,"%sMSGAREAS.XBS",conf.messpath);
  210.             tempnumber=find__msgarea(tmp,conf.mboard.name);
  211.             if (!tempnumber) {  /* Couldn't find area at all in BBS list */
  212.                 printf("\nUnmatched or unsupported area #%u: `%s' untossed\n",conf.mboard.number,conf.mboard.name);
  213.                 sprintf(s,"XGATEKPR: Unmatched or unsupported area #%u: `%s'",conf.mboard.number,conf.mboard.name);
  214.                 addtolog(s);
  215.                 continue;
  216.             }
  217.             if (tempnumber!=conf.mboard.number) {  /* Correct moved area # */
  218.                 printf("\nArea #%u (%s) changed to #%u per MSGAREAS.XBS\n",conf.mboard.number,conf.mboard.name,tempnumber);
  219.                 sprintf(s,"XGATEKPR: Area #%u (%s) -> #%u",conf.mboard.number,conf.mboard.name,tempnumber);
  220.                 addtolog(s);
  221.             }
  222.             othernumber=conf.mboard.number;
  223.             conf.mboard.number=tempnumber;
  224.         }
  225.             useit.posts+=merge_area();
  226.     }
  227.     fclose(fp);
  228.  
  229.     /* We've finished processing the mail, clean up */
  230.  
  231.     printf("\nMail processing complete...imported %lu msgs.\n",useit.posts-tempposts);
  232.     killall();
  233.     chdir("..");
  234.  
  235.     /* Update number of user posts if we imported anything */
  236.  
  237.     if (useit.posts!=tempposts) {
  238.         if (!(fp=fopen("users.bbs","rb"))) {
  239.             printf("\nError opening userfile.\n");
  240.             exit(250);
  241.         }
  242.         fseek(fp,((long)sizeof(struct _user)*((long)conf.lastusernum-1L)),SEEK_SET);
  243.         fwrite(&useit,sizeof(struct _user),1,fp);
  244.         fclose(fp);
  245.     }
  246.     exit(0);                /* We are outta here */
  247. }
  248.  
  249.  
  250.  
  251. char * rstrip (char *a)
  252.  
  253. {
  254.   while ((strlen(a)) && (a[strlen(a)-1]==' ')) a[strlen(a)-1]=0;
  255.   return a;
  256. }
  257.  
  258.  
  259.  
  260. char * lstrip (char *a)
  261.  
  262. {
  263.   while ((strlen(a)) && (*a==' ')) memmove (a,(a+1),strlen(a));
  264.   return (a);
  265. }
  266.  
  267.  
  268.  
  269. char *stripcr (char *a)
  270.  
  271. {
  272.  
  273.   while (a[strlen(a)-1]=='\n' || a[strlen(a)-1]=='\r') a[strlen(a)-1]=0;
  274.   return a;
  275.  
  276. }
  277.  
  278.  
  279.  
  280. void killall (void) {
  281.  
  282.     if (findfirst("*.*",&f,0)) return;
  283.     remove(f.ff_name);
  284.     while (!findnext(&f)) remove (f.ff_name);
  285. }
  286.  
  287.  
  288. void pascal readconfig (void) {
  289.  
  290.  FILE *fp;
  291.  char s[15];
  292.  
  293.     if (nodenumber!=1) sprintf(s,"config%01hu.bbs",nodenumber);
  294.     else strcpy(s,"config.bbs");
  295.  
  296.     if(!(fp=fopen(s,"rb"))) {
  297. Fatal:
  298.        printf("\nFatal Error\n");
  299.        perror("\nCONFIG ERROR");
  300.        chdir("..");
  301.        exit(254);
  302.     }
  303.   if (fread(&conf,sizeof(conf),1,fp)!=1) goto Fatal;
  304.   fclose(fp);
  305.  
  306. }
  307.  
  308.  
  309. ulong merge_area (void) {
  310.  
  311.     char filename[132];
  312.     char textname[132];
  313.     char arcfile[20];
  314.     char arctext[20];
  315.     char message[81];
  316.     char origin[67]="";
  317.     struct ffblk origsize;
  318.     struct ffblk replysize;
  319.     FILE *origfile;
  320.     FILE *origtext;
  321.     FILE *replyfile;
  322.     FILE *replytext;
  323.     FILE *pp;
  324.     char *p;
  325.     word lenmess;
  326.     word exported=0;
  327.     char once=0;
  328.     struct _xmsg msg;
  329.     char *hold;
  330.     char *usethis;
  331.     word messno=1;
  332.     word nomess;
  333.     char lastreply[145]="";
  334.     char assocfile[145]="";
  335.     static long counter;
  336.     char idstr[12];
  337.  
  338.     sprintf(filename,"%sXDATA.%03x",conf.messpath,conf.mboard.number);
  339.     sprintf(textname,"%sXTEXT.%03x",conf.messpath,conf.mboard.number);
  340.     sprintf(arcfile,"XXDATA.%03x",othernumber);
  341.     sprintf(arctext,"XXTEXT.%03x",othernumber);
  342.  
  343.     if (findfirst(arctext,&f,0)) {
  344.         printf("\nArea #%u (%s) listed but not present\n",othernumber,conf.mboard.name);
  345. BadArea:
  346.         remove(arcfile);
  347.         remove(arctext);
  348.         return 0;
  349.     }
  350.     if (findfirst(arcfile,&replysize,0)) {
  351.         printf("\nArea #%u (%s) listed but not present\n",othernumber,conf.mboard.name);
  352.         goto BadArea;
  353.     }
  354.     if (replysize.ff_fsize==0) {
  355.         printf("\nArea #%u (%s) is empty.\n",othernumber,conf.mboard.name);
  356.         goto BadArea;
  357.     }
  358.     if (findfirst(filename,&origsize,0)) origsize.ff_fsize=0;
  359.     nomess=(word)(replysize.ff_fsize/(long)sizeof(struct _xmsg));
  360.  
  361.     if (!(replyfile=fopen(arcfile,"rb"))) {
  362.         printf("\nUnable to open reply datafile\n");
  363.         return 0;
  364.     }
  365.     if (!(replytext=fopen(arctext,"rb"))) {
  366.         printf("\nUnable to open reply textfile\n");
  367.         fclose(replyfile);
  368.         return 0;
  369.     }
  370.     if (!(origfile=fopen(filename,"a+b"))) {
  371.         printf("\nUnable to open BBS datafile\n");
  372.         fclose(replyfile);
  373.         fclose(replytext);
  374.         return 0;
  375.     }
  376.     if (!(origtext=fopen(textname,"a+b"))) {
  377.         printf("\nUnable to open BBS textfile\n");
  378.         return 0;
  379.     }
  380.     fseek(origtext,0L,SEEK_END);
  381.     fseek(origfile,0L,SEEK_END);
  382.     fseek(replyfile,0L,SEEK_SET);
  383.     fseek(replytext,0L,SEEK_SET);
  384.  
  385.     printf("\nWorking on #%u...",conf.mboard.number);
  386.  
  387.     while (messno<(nomess+1)) {
  388.  
  389.       if ((fseek(replyfile,(long)((long)(messno-1)*(long)sizeof(struct _xmsg)),SEEK_SET)) || (fread(&msg,sizeof(struct _xmsg),1,replyfile)!=1)) {
  390.         if (ferror(replyfile)) perror ("\nSEEK ERROR");
  391.         fclose(replyfile);
  392.         goto EndIt;
  393.       }
  394.  
  395. #ifdef DEBUG
  396.  
  397.     printf("\nMSG.LENGTH: %u bytes\n",msg.length);
  398.  
  399. #endif
  400.  
  401.       once=0;
  402. TryThatAgain:
  403.       if (fseek(replytext,msg.start,SEEK_SET)) {
  404.          if (ferror(replytext)) {
  405.             if (!once) {
  406.                 once++;
  407.                 goto TryThatAgain;
  408.             }
  409.             else perror ("\nSEEK ERROR");
  410.             goto EndIt;
  411.          }
  412.       }
  413.       hold=(char *)malloc(msg.length+1);
  414.       if (hold==NULL) {
  415.         printf("\nOut of memory\n");
  416.         chdir("..");
  417.         exit(249);
  418.       }
  419.       fread(hold,msg.length,1,replytext);
  420.       hold[msg.length-1]=0;
  421.  
  422. #ifdef DEBUG
  423.  
  424.     printf("\nLENGTH before strip: %u bytes\n",strlen(hold));
  425.  
  426. #endif
  427.       /* Strip out nasty stuff */
  428.  
  429.       *lastreply=0;
  430.       *assocfile=0;
  431.       if(p=strstr(hold,"\01REPLY: ")) {
  432.         if(p==hold) {
  433.             p++;
  434.             usethis=p;
  435.             if(p=strchr(usethis,'\r')) {
  436.                 p++;
  437.                 usethis=p;
  438.             }
  439.         }
  440.         else usethis=hold;
  441.       }
  442.       else usethis=hold;
  443.       if(p=strstr(usethis,"\01ASSOC: ")) {
  444.         if(p==usethis) {
  445.             p++;
  446.             usethis=p;
  447.         }
  448.       }
  449.  
  450.       while (p=strstr(usethis,"\r\n")) memmove(&p[1],&p[2],strlen(&p[2])+1);
  451.       while (p=strchr(usethis,'\n')) *p='\r';
  452.       while (p=strstr(usethis," \x8d")) memmove(&p[1],&p[2],strlen(&p[2])+1);
  453.       while (p=strchr(usethis,'\x8d')) *p=' ';
  454.       while (p=strstr(usethis,"\r--- ")) memmove(&p[2],&p[3],strlen(&p[3])+1);
  455.       while (p=strstr(usethis,"\r * Origin: ")) p[2]='@';
  456.       while (p=strchr(usethis,'\x1')) *p='@';
  457.       while(hold[strlen(hold)-1]=='\r' && hold[strlen(hold)-2]=='\r') hold[strlen(hold)-1]=0;
  458.  
  459. #ifdef DEBUG
  460.  
  461.     printf("\nLENGTH after strip: %u bytes\n",strlen(hold));
  462.  
  463. #endif
  464.  
  465.  
  466.       msg.start=ftell(origtext);
  467.       msg.attr = msg.attr | MSGLOCAL;
  468.       msg.m_attr = msg.m_attr & (~MSGTAGGED);
  469.       msg.subj[63]=0;
  470.       msg.d_point=0;
  471.       msg.o_point=0;
  472.       msg.times=0;
  473.       lenmess=0;
  474.  
  475.       /* Build 'unique id string' for MSGID using time & counter
  476.          You would have to import more than 15 msgs/sec to get a
  477.          dupe MSGID, in which case you could shift two bytes of
  478.          the counter into the id string (%256, idstr[10]=0, &idstr[2]) */
  479.  
  480.       sprintf(idstr,"%08lX%01hX",time(NULL),(char)(counter%16L));
  481.       idstr[9]=0;
  482.       counter++;
  483.  
  484.       if(nodenumber==1) {
  485.           if((conf.mboard.attr & ALTECHO) || (conf.mboard.attr & ALTERNATE)) lenmess+=fprintf(origtext,"\01MSGID: %u:%u/%u.0@%s %-8.8s\r", conf.alt_zone,conf.alt_net,conf.alt_node,conf.alt_domain,&idstr[1]);
  486.           else lenmess+=fprintf(origtext,"\01MSGID: %u:%u/%u.0@%s %-8.8s\r", conf.zone,conf.net,conf.node,conf.domain,&idstr[1]);
  487.       }
  488.       else {
  489.  
  490.           /* Note:  Non-standard but very smart */
  491.  
  492.           if((conf.mboard.attr & ALTECHO) || (conf.mboard.attr & ALTERNATE)) lenmess+=fprintf(origtext,"\01MSGID: %u:%u/%u.0.n%01hu@%s %-8.8s\r", conf.alt_zone,conf.alt_net,conf.alt_node,nodenumber,conf.alt_domain,&idstr[1]);
  493.           else lenmess+=fprintf(origtext,"\01MSGID: %u:%u/%u.0.n%01hu@%s %-8.8s\r", conf.zone,conf.net,conf.node,nodenumber,conf.domain,&idstr[1]);
  494.       }
  495.  
  496.       if(*lastreply) {
  497.         lenmess+=fprintf(origtext,"%s",lastreply);
  498.         *lastreply=0;
  499.       }
  500.       if(*assocfile) {
  501.         lenmess+=fprintf(origtext,"%s",assocfile);
  502.         *assocfile=0;
  503.       }
  504.  
  505.       if (conf.mboard.attr & REAL) strcpy(msg.from,useit.name);
  506.       else strcpy(msg.from,useit.handle);
  507.  
  508.       fwrite(hold,strlen(hold),1,origtext);
  509.       lenmess+=strlen(hold);
  510.       if ((conf.mboard.attr & ALTECHO) || (conf.mboard.attr & ECHO)) {
  511.         if (!*origin) {
  512.  
  513.           char originpath[133];
  514.  
  515.           sprintf(originpath,"%sORIGINS.BBS",conf.messpath);
  516.           if(!(pp=fopen(originpath,"r"))) {
  517.                 strcpy(origin,conf.origin);
  518.                 goto SkipOrigins;
  519.           }
  520.           rewind(pp);
  521.           while (!(feof(pp)) && ((word)atol(message)!=conf.mboard.number)) {
  522.              fgets(message,80,pp);
  523.              message[66]=0;
  524.              stripcr(message);
  525.           }
  526.           fclose(pp);
  527.           if ((word)atol(message)!=conf.mboard.number) {
  528.             strcpy(origin,conf.origin);
  529.           }
  530.           else {
  531.               strtok(message,"; ");
  532.               strcpy(origin,strtok(0,"\n"));
  533.           }
  534.         }
  535. SkipOrigins:
  536.           if(conf.mboard.attr & ALTECHO) lenmess+=(fprintf(origtext,"\r\n--- XBBS/%s\r\n * Origin: %s (%u:%u/%u)\r\n",reader,origin,conf.alt_zone,conf.alt_net,conf.alt_node));
  537.           lenmess+=(fprintf(origtext,"\r\n--- XBBS/%s\r\n * Origin: %s (%u:%u/%u)\r\n",reader,origin,conf.zone,conf.net,conf.node));
  538.       }
  539.       else {
  540.           fputc('\r',origtext);
  541.           lenmess++;
  542.       }
  543.  
  544. GotOrigin:
  545.       fputc('\0',origtext);
  546.       lenmess+=2;
  547.  
  548. #ifdef DEBUG
  549.  
  550.     printf("\nLENGTH in header: %u bytes\n",lenmess);
  551.  
  552. #endif
  553.  
  554.       msg.length=lenmess;
  555.       msg.m_attr |= MSGTREATED;
  556.       fwrite(&msg,sizeof(struct _xmsg),1,origfile);
  557.       if (hold) free(hold);
  558.       exported++;
  559.       messno++;
  560.       printf("%-5u\b\b\b\b\b",exported);
  561.   }
  562. EndIt:
  563.   fclose(replyfile);
  564.   fclose(replytext);
  565.   fclose(origfile);
  566.   fclose(origtext);
  567.   if (exported) printf("Imported %u msgs",exported);
  568.   sprintf(message,"XGATEKPR: Imported %u msgs to area #%u",exported,conf.mboard.number);
  569.   addtolog(message);
  570.   return (ulong)exported;
  571.  
  572. }
  573.  
  574.  
  575. char * fidodate (void)
  576.  
  577. {
  578.  
  579.  char months[12][4]={
  580.     "Jan",
  581.     "Feb",
  582.     "Mar",
  583.     "Apr",
  584.     "May",
  585.     "Jun",
  586.     "Jul",
  587.     "Aug",
  588.     "Sep",
  589.     "Oct",
  590.     "Nov",
  591.     "Dec"
  592.  };
  593.  static char fdate[20];
  594.  struct date dos_date;
  595.  struct time dos_time;
  596.  
  597. /* 26 Jul 89  06:23:47 */
  598.  
  599.  getdate(&dos_date);
  600.  gettime(&dos_time);
  601.  
  602.  sprintf(fdate,"%02hu %s %02d  %02hu:%02hu:%02hu",dos_date.da_day,months[dos_date.da_mon-1],dos_date.da_year%100,dos_time.ti_hour,dos_time.ti_min,dos_time.ti_sec);
  603.  return(fdate);
  604.  
  605. }
  606.  
  607.  
  608. char * pascal addtolog (char *text) { /* WRITE LOGFILE ENTRIES */
  609.  
  610.  FILE *pf;
  611.  char p[127];
  612.  
  613.  pf = fopen(conf.logfile,"a");
  614.  if (pf == NULL) return text;
  615.  fseek(pf,0,SEEK_END);
  616.  if (text[0]!='*') {
  617.    strcpy(p,fidodate());
  618.    p[16]=0;
  619.    strcat(p,"  ");
  620.    strncat(p,text,126-strlen(p));
  621.    p[126]=0;
  622.  }
  623.  else {
  624.         strncpy(p,text,79);
  625.         p[79]=0;
  626.  }
  627.  fputs(p,pf);
  628.  if(nodenumber!=1) fprintf(pf," (Node %01hu)",nodenumber);
  629.  fputs("\n",pf);
  630.  fclose(pf);
  631.  return text;
  632.  
  633. }
  634.  
  635.  
  636. word find__msgarea (char *filename,char *areaname) {
  637.  
  638.     FILE *fp;
  639.     char s[256];
  640.     char *p;
  641.     word attr;
  642.  
  643.     fp=fopen(filename,"r");
  644.     if (fp==NULL) {
  645.         printf("\nCan't open %s...continuing...\n",filename);
  646.         return (conf.mboard.number);
  647.     }
  648.     strupr(areaname);
  649.     while (!feof(fp) && !ferror(fp)) {
  650.         if (!fgets(s,256,fp)) break;
  651.         if (*s=='\n' || *s==';') continue;
  652.         stripcr(s);
  653.         strtok(s,",");
  654.         strupr(s);
  655.         if (strcmp(s,areaname)) continue;
  656.         conf.mboard.attr=(word)atoi(strtok(0," ,"));
  657.         conf.mboard.max=(word)atoi(strtok(0," ,"));
  658.         fclose(fp);
  659.         if(conf.mboard.attr & READONLY || conf.mboard.attr & NET || conf.mboard.attr & ALTERNATE) {
  660.             printf("\nUnsupported area type skipped...\n");
  661.             return 0;
  662.         }
  663.         return((word)atol(strtok(0," ,")));
  664.     }
  665.     fclose(fp);
  666.     return (0);
  667. }
  668.  
  669.  
  670. char * pascal say_prompt (word x) {
  671.  
  672.     char ss[]="LHARC e %s";
  673.     char s[257];
  674.     long pos;
  675.     FILE *fp;
  676.  
  677.     fp=fopen(searchpath("XBBS.IDX"),"rb");
  678.     if(!fp) return ss;
  679.     if(fseek(fp,(long)(x*(word)sizeof(long)),SEEK_SET)!=0) return ss;
  680.     if(fread(&pos,sizeof(long),1,fp)!=1) return ss;
  681.     fclose(fp);
  682.     fp=fopen(searchpath("XBBS.TXT"),"r");
  683.     if(!fp) return ss;
  684.     if(fseek(fp,pos,SEEK_SET)!=0) {
  685.         fclose(fp);
  686.         return ss;
  687.     }
  688.     if(!fgets(s,256,fp)) {
  689.         fclose(fp);
  690.         return ss;
  691.     }
  692.     fclose(fp);
  693.     if(s[strlen(s)-1]=='\n') s[strlen(s)-1]=0;
  694.     if(s[strlen(s)-1]==';') s[strlen(s)-1]=0;
  695.     if(!*s || !s[1]) return ss;
  696.     return &s[1];
  697. }
  698.