home *** CD-ROM | disk | FTP | other *** search
- /* WARNING: This has never been tested _at all_!!!!! */
-
-
- #include "msgg.h"
-
- int get_mess(word,word,char *);
- int put_mess(word,char *);
- char *get_text(word,char *,char *);
- void put_text(word,char *,char *);
-
-
- char buffer[333];
- struct _xmsg msg;
-
- void main (argc,argv)
-
- int argc;
- char *argv[];
-
- {
-
- struct ffblk f;
- char *hold=NULL;
-
- if (argc<6) {
- fputs("\nError calling XMove.\n",stdout);
- fputs("\nUsage: Xport <directory\\> <frombase#> <msg#> <tobase#>\n",stdout);
- exit(0);
- }
-
- sprintf(buffer,"%sXDATA.%03x",argv[1],(word)atol(argv[2]));
- if(!findfirst(buffer,&f,0)) {
- fputs("\nCan't find message data file.\n",stdout);
- exit(1);
- }
- if(((word)(f.ff_fsize/(long)sizeof(struct _xmsg))<(word)atol(argv[3])) {
- fputs("\nRequested message doesn't exist!\n",stdout);
- exit(2);
- }
- get_mess((word)atol(argv[3]),(word)atol(argv[2]),argv[1]);
- msg.m_attr = msg.m_attr & (~MSGDELETED);
- get_text((word)atol(argv[2]),argv[1],hold);
- if(hold==NULL) {
- fputs("\nCouldn't load message text...\n",stdout);
- exit(5);
- }
- put_text((word)atol(argv[4]),argv[1],hold);
- put_mess((word)atol(argv[4]),argv[1]);
- }
-
-
-
-
- int get_mess (word messno,word areano,char *directory)
-
- {
-
- int handle;
- register word x=0;
-
- sprintf(buffer,"%sXDATA.%03x",directory,areano);
-
- while ((handle=_open(buffer,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
- if (errno==EACCES) {
- x++;
- if(x>2) {
- fputs("\nGot tired of waiting...\n",stdout);
- exit (3);
- }
- fputs("\nAwaiting access...\n",stdout);
- sleep(1);
- }
- else {
- fputs("\nError opening message data file...\n",stdout);
- exit(4);
- }
- }
- if ((lseek(handle,(long)((long)(messno-1)*(long)sizeof(struct _xmsg)),SEEK_SET)==(-1)) || (_read(handle,&msg,sizeof(struct _xmsg))<1)) {
- if (eof(handle)==(-1)) perror ("\nSEEK ERROR");
- _close(handle);
- return -1;
- }
- _close(handle);
- if(msg.m_attr & MSGPACKED) {
- fputs("\nI can't handle compressed messages\n",stdout);
- exit(3);
- }
- return 0;
- }
-
-
-
-
- int put_mess (word areano,char *directory)
-
- {
-
- int handle;
- register word x=0;
- long temp;
-
- sprintf(buffer,"%sXDATA.%03x",directory,areano);
-
- while ((handle=_open(buffer,O_RDWR | O_BINARY | O_DENYNONE))==-1) {
- if (errno==EACCES) {
- x++;
- if(x>2) {
- fputs("\nGot tired of waiting...\n",stdout);
- return -1;
- }
- fputs("\nAwaiting access....\n",stdout);
- sleep(1);
- }
- else {
- if((handle=creat(buffer,S_IWRITE))==-1) {
- fputs("\nCan't open message data file...\n",stdout);
- return -1;
- }
- break;
- }
- }
- temp=filelength(handle);
- lock(handle,temp,(long)sizeof(struct _xmsg));
- if ((lseek(handle,0L,SEEK_END)==(-1)) || (_write(handle,&msg,sizeof(struct _xmsg))<1)) {
- if (eof(handle)==(-1)) {
- fputs(" SEEK ERROR ",stdout);
- unlock(handle,temp,(long)sizeof(struct _xmsg));
- _close(handle);
- return -1;
- }
- }
- unlock(handle,temp,(long)sizeof(struct _xmsg));
- _close(handle);
- return 0;
- }
-
-
-
- char far * get_text (word areano,char *directory,char *hold)
-
- {
-
- char once;
- char *tempo;
- word temp=0;
- int handle;
-
- sprintf(buffer,"%sXTEXT.%03x",directory,areano);
-
- while ((handle=_open(buffer,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
- if (errno==EACCES) {
- temp++;
- if (temp>2) {
- fputs("\nGot tired of waiting...\n",stdout);
- return NULL;
- }
- fputs("\nAwaiting access...\n",stdout);
- sleep(1);
- }
- else {
- fputs("\nCan't open message text file...\n",stdout);
- return NULL;
- }
- }
- once=0;
- TryThatAgain:
- if (lseek(handle,msg.start,SEEK_SET)) {
- if (eof(handle)) {
- if (!once) {
- once++;
- goto TryThatAgain;
- }
- else perror (" TEXT SEEK ERROR");
- return NULL;
- }
- }
- temp=msg.length;
- ReTry:
- hold=(char far*)farmalloc(msg.length+1);
- if (hold==NULL) {
- if (msg.length>1024) {
- msg.length-=256;
- goto ReTry;
- }
- else {
- fputs("\nReducing text size...\n",stdout);
- msg.length=temp;
- return NULL;
- }
- }
- memset(hold,0,msg.length);
- _read(handle,hold,msg.length);
- _close(handle);
- hold[msg.length-1]=0;
- while ((tempo=strstr(hold," \x8d"))) memmove(&tempo[1],&tempo[2],strlen(&tempo[2])+1);
- while ((tempo=strchr(hold,'\x8d'))) *tempo=' ';
- while ((tempo=strchr(hold,'\n'))) memmove(tempo,&tempo[1],strlen(&tempo[1])+1);
- if (hold[strlen(hold)-1]!='\r') strcat(hold,"\r");
- msg.length=temp;
- return hold;
- }
-
-
-
-
- void put_text (word areano,char *directory,char *hold)
-
- {
-
- word temp=0;
- int handle;
-
- sprintf(buffer,"%sXTEXT.%03x",directory,areano);
-
- while ((handle=_open(buffer,O_RDWR| O_BINARY | O_DENYNONE))==-1) {
- if (errno==EACCES) {
- temp++;
- if (temp>2) {
- fputs("\nGot tired of waiting...\n",stdout);
- return;
- }
- fputs("\nAwaiting access...\n",stdout);
- sleep(1);
- }
- else {
- if((handle=creat(buffer,S_IWRITE))==-1) {
- fputs("\nCan't open message text file...\n",stdout);
- return;
- }
- else break;
- }
- }
- msg.length=(word)strlen(hold);
- msg.start=tell(handle);
- lock(handle,msg.start,msg.length);
- _write(handle,hold,msg.length);
- unlock(handle,msg.start,msg.length);
- _close(handle);
- return;
- }
-