home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
progc
/
xdev_118.arj
/
XPORT.C
< prev
next >
Wrap
Text File
|
1990-07-17
|
6KB
|
265 lines
#include "msg.h"
int export (char *,word,word,char *,char,char,char *);
void leftt (char *,char *,int);
word textsize;
word codesize;
int main (int argc,char *argv[]) {
if (argc<7) {
fputs("\nError calling Xport.\n",stdout);
fputs("\nUsage: Xport <directory\\> <base#> <msg#> <filename> <net> <width> <MSG>\n",stdout);
fputs("\nIf MSG is passed as the final argument, the resulting exported file will",stdout);
fputs("\nbe in Fido/Opus *.MSG format\n",stdout);
exit(0);
}
export(argv[1],(word)atol(argv[2]),(word)atol(argv[3]),argv[4],(char)atol(argv[5]),(char)atol(argv[6]),strupr(argv[7]));
fputs("\nSuccess.\n",stdout);
return 0;
}
int export (dir,base,messno,file,net,width,msgflag)
char *dir;
word base;
word messno;
char *file;
char net;
char width;
char *msgflag;
{
char filename[127];
char textname[127];
char text[124];
FILE *fp;
FILE *pf;
FILE *pp;
word temp;
char once;
char message[81];
struct _xmsg msg2;
char *hold;
char *tempo;
word count;
word count2;
struct ffblk filestat;
struct _xmsg msg;
sprintf(filename,"%sXDATA.%03x",dir,base);
sprintf(textname,"%sXTEXT.%03x",dir,base);
if (findfirst(file,&filestat,0)==0) {
fputs("\n",stdout);
fputs(file,stdout);
fputs(" exists...aborting...\n",stdout);
exit(5);
}
if (findfirst(filename,&filestat,0)!=0) {
fputs("\nCannot find ",stdout);
fputs(filename,stdout);
exit (1);
}
if ((long)((messno-1) * sizeof(struct _xmsg))>=filestat.ff_fsize) {
fputs("\nMessage requested does not exist.\n",stdout);
exit (1);
}
if(!(pf=fopen(textname,"rb"))) {
fputs("\nCannot open ",stdout);
fputs(textname,stdout);
exit (1);
}
if(!(fp=fopen(filename,"rb"))) {
fclose(pf);
fputs("\nCannot open ",stdout);
fputs(filename,stdout);
exit(1);
}
if(strcmp(msgflag,"MSG")) pp=fopen(file,"wt");
else pp=fopen(file,"wb");
if(!pp) {
fclose (fp);
fclose (pf);
fputs("\nCannot open ",stdout);
fputs(file,stdout);
exit(1);
}
if ((fseek(fp,(long)((long)(messno-1)*(long)sizeof(struct _xmsg)),SEEK_SET)!=0) || (fread(&msg,sizeof(struct _xmsg),1,fp)!=1)) {
if (ferror(fp)) perror ("\nXDATA SEEK ERROR");
fclose(fp);
fclose(pf);
fclose(pp);
remove(file);
exit (2);
}
Over:
if (strcmp(msgflag,"MSG")) {
sprintf(text,"Board #%u * Message #%u: ",base,messno);
fputs(text,pp);
if ((msg.attr & MSGPRIVATE)!=0) fputs("(Private)",pp);
if ((msg.m_attr & MSGDELETED)!=0) fputs("(Deleted)",pp);
if ((msg.attr & MSGCRASH)!=0) fputs("(CRASH)",pp);
if ((msg.attr & MSGKILL)!=0) fputs("(Kill)",pp);
if ((msg.attr & MSGSENT)!=0) fputs("(Sent)",pp);
if ((msg.attr & MSGFWD)!=0) fputs("(Fwd)",pp);
if ((msg.attr & MSGREAD)!=0) fputs("(Rec'd)",pp);
if ((msg.attr & MSGRRQ)!=0) fputs("(Rec.Req)",pp);
if ((msg.attr & MSGCPT)!=0) fputs("(Recpt)",pp);
if ((msg.attr & MSGARQ)!=0) fputs("(Aud.Req)",pp);
if ((msg.attr & MSGURQ)!=0) fputs("(Update Req)",pp);
sprintf(text,"(Read %u times)\n",msg.times);
fputs(text,pp);
sprintf(text,"To: %s",msg.to);
fputs(text,pp);
if ((net)!=0) {
sprintf(text," (%d/%d)",msg.dest_net,msg.dest);
fputs(text,pp);
}
fputs("\nFrom: ",pp);
if ((msg.m_attr & MSGANON)!=0) {
fputs("*Anonymous* (",pp);
fputs(msg.from,pp);
fputs(")",pp);
}
else fputs(msg.from,pp);
if (net) {
sprintf(text," (%d/%d)",msg.orig_net,msg.orig);
fputs(text,pp);
}
fputs("\nOn: ",pp);
if ((msg.m_attr & MSGANON)!=0) {
leftt(text,msg.date,9);
fputs(text,pp);
}
else fputs(msg.date,pp);
fputs("\n",pp);
if ((msg.attr & MSGFILE)!=0) fputs("File: ",pp);
else if ((msg.attr & MSGFRQ)!=0) fputs("FReq: ",pp);
else fputs("Subj: ",pp);
fputs(msg.subj,pp);
fputs("\n\n",pp);
}
else fwrite(&msg,sizeof(struct _xmsg),1,pp);
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);
fclose(pp);
exit(3);
}
}
}
hold=(char *)malloc(msg.length+1);
if (hold==NULL) {
fputs("\nOut of memory.\n",stdout);
fclose(pf);
fclose(fp);
fclose(pp);
exit (4);
}
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(9);
}
else {
msg.length=strlen(hold)+1;
}
}
hold[msg.length-1]=0;
while (strchr(hold,'\x8d')) {
tempo=strchr(hold,'\x8d');
memmove(tempo,&tempo[1],strlen(&tempo[1])+1);
}
tempo=hold;
count=0;
temp=strlen(hold);
if (strcmp(msgflag,"MSG")) {
while (count<temp) {
count2=(word)(width-1);
if ((count+count2)>temp) count2=temp-count;
strncpy(message,&hold[count],count2);
message[count2 + 1]=0;
tempo=strchr(message,'\r');
if (tempo!=NULL) tempo[0]=0;
else {
tempo=strrchr(message,' ');
if (tempo!=NULL) tempo[0]=0;
else message[count2]=0;
}
count=count+strlen(message)+1;
fprintf(pp,"%s\n",message);
}
fputc('\x1a',pp);
}
else {
fwrite(hold,strlen(hold),1,pp);
fputc('\0',pp);
}
free(hold);
fclose(pp);
fclose(pf);
fclose(fp);
return 0;
}
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);
}