home *** CD-ROM | disk | FTP | other *** search
- #include "msgg.h"
-
- word export (char *,word,char *,char *);
- void leftt (char *,char *,int);
- int makemsg (char *file,struct _xmsg *xmsg, char *text);
- extern char * pascal unpack_msg (char **hold);
-
- word textsize;
- word codesize;
-
- int main (int argc,char *argv[]) {
-
- word howmany;
-
- if (argc<4) {
- fputs("\n\nError calling MakeMsg.\n",stdout);
- fputs("\nUsage: MakeMsg <msg dir\\> <base#> <netmail_dir\\> <to_whom>\n",stdout);
- fputs("\nI'll check the message base for messages addressed to <to_whom>",stdout);
- fputs("\nand export, then mark deleted, any I find. This lets you use",stdout);
- fputs("\nthings like AreaFix that rely on netmail *.MSG directories.\n",stdout);
- fputs("\nReturns 0 (none exported), 1 (exported ok), or 2-4 (fatal error)\n",stdout);
- fputs("\nExample: MakeMsg C:\\XBBS\\MESS\\ 5 C:\\BT\\MSG\\ \"AreaFix\"\n\n",stdout);
- return 0;
- }
- howmany=export(argv[1],(word)atol(argv[2]),argv[3],argv[4]);
- if(howmany) {
- printf("\nExported %u message(s).\n");
- return 1;
- }
- else return 0;
- }
-
-
-
-
-
-
- word export (char *dir,word base,char *netdir,char *whoto) {
-
- word howmany=0;
- char filename[127];
- char textname[127];
- char text[124];
- FILE *fp;
- FILE *pf;
- char once;
- long pos;
- word count=1;
- struct _xmsg msg2;
- char *hold=NULL;
- struct ffblk filestat;
- struct _xmsg msg;
- word nomess,messno;
-
- sprintf(filename,"%sXDATA.%03x",dir,base);
- sprintf(textname,"%sXTEXT.%03x",dir,base);
-
- if (findfirst(filename,&filestat,0)!=0) {
- printf("\nCan't find %s\n",stdout);
- return 0;
- }
- if(filestat.ff_fsize==0L) {
- printf("\nZero-length filebase.\n");
- return 0;
- }
- nomess=(word)(filestat.ff_fsize/(long)sizeof(struct _xmsg));
-
- if(!(pf=fopen(textname,"rb"))) {
- printf("\nCan't open %s\n",textname);
- return 0;
- }
- if(!(fp=fopen(filename,"r+b"))) {
- fclose(pf);
- printf("\nCan't open %s\n",filename);
- return 0;
- }
-
- fseek(fp,0L,SEEK_SET);
- for(messno=0;messno<nomess;messno++) {
- pos=ftell(fp);
- fread(&msg,sizeof(struct _xmsg),1,fp);
- if(msg.m_attr & MSGDELETED) continue;
-
- /* A quick note: at this point it would be simple to check other things
- and export based on those checks... */
-
- if(stricmp(msg.to,whoto)) continue;
-
- once=0;
- TryThatOver:
- if (fseek(pf,msg.start,SEEK_SET)!=0) {
- if (ferror(pf)) {
- if (!once) {
- once++;
- goto TryThatOver;
- }
- else {
- perror ("\nXTEXT SEEK ERROR");
- fclose(fp);
- fclose(pf);
- exit(2);
- }
- }
- }
- hold=(char *)malloc(msg.length+1);
- if (hold==NULL) {
- fputs("\nOut of memory.\n",stdout);
- fclose(pf);
- fclose(fp);
- exit(3);
- }
- fread(hold,msg.length,1,pf);
- if(msg.m_attr & MSGPACKED) {
- unpack_msg(&hold);
- if(hold==NULL) {
- fputs("\nCan't uncompress message...\n",stdout);
- exit(4);
- }
- else {
- msg.length=strlen(hold)+1;
- }
- }
- hold[msg.length-1]=0;
-
- sprintf(text,"%s\\%u.MSG",netdir,count);
- while(!findfirst(text,&filestat,0)) {
- count++;
- if(!count) {
- fprintf(stderr,"\nDamn Msg directory is full\n");
- return howmany;
- }
- sprintf(text,"%s\\%u.MSG",netdir,count);
- }
-
- printf("Exporting #%lu as %u.MSG...\n",(pos/(long)sizeof(struct _xmsg))+1L,count);
- if(makemsg(text,&msg,hold)) {
- msg.m_attr |= MSGDELETED; /* Mark deleted so it won't export again */
- fseek(fp,pos,SEEK_SET);
- fwrite(&msg,sizeof(struct _xmsg),1,fp);
- }
- else printf("Export error...\n");
-
- if(hold)free(hold);
- hold=NULL;
- }
- fclose(pf);
- fclose(fp);
- return howmany;
- }
-
-
-
-
- int makemsg (char *file,struct _xmsg *xmsg, char *text) {
-
- FILE *pp;
-
- pp=fopen(file,"wb");
- if(!pp) {
- printf("\nCan't open %s\n",file);
- return 0;
- }
- fwrite(xmsg,sizeof(struct _xmsg),1,pp);
- fwrite(text,strlen(text),1,pp);
- fputc('\0',pp);
- fclose(pp);
- return 1;
- }
-
-
-
- void leftt(a,b,x)
-
- char *a,*b;
- int x;
-
- {
-
- int i=0;
-
- x = (x <= strlen(b)) ? x : strlen(b);
-
- while (i++ < x) *a++ = *b++;
-
- *a = '\0';
-
- }
-
-
- char * pascal rstrip (char *a) {
-
- register int x;
-
- x=strlen(a);
- while (x && a && a[x-1]==' ') a[--x]=0;
- return a;
- }
-
-
-
- char * pascal lstrip (char *a) {
-
- register int x;
-
- x=strlen(a);
- while (x && *a==' ') memmove (a,(a+1),x--);
- return (a);
- }