home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
TELECOM
/
tterm_src.lzh
/
transfer.c
< prev
Wrap
Text File
|
1996-03-04
|
7KB
|
302 lines
/*********************************************************************
transfer.c
*********************************************************************/
#include "common.h"
#include <process.h>
#include <module.h>
#define EXTENSION ".xyt"
#define DIRECTORY "/dd/USR/TTERM/"
#define NONAME 0
#define FILENAME 1
#define LISTNAME 2
int typeflg=NONAME;
char errstrng[128];
char transfile[128],
logfile[128],
transtr[128],
*logstr=errstrng,
portstr[16],
*arglist[5];
mh_com
*xyt_head; /* XY_PROG module header */
extern char
**_environ;
/*********************************************************************
SET the LOG FILE name
*********************************************************************/
SetLogFile()
{
char *t;
strcpy(logfile,DIRECTORY);
t=getenv("USER"); /* get the user name */
if(t == 0)
t="generic";
strcat(logfile,t);
strcat(logfile,EXTENSION);
tprint("Logfile is "); tprint(logfile); tprint("\012\n");
}
/*********************************************************************
LOAD the TRANSFER program - return 0 on successful load/link
*********************************************************************/
LoadTransfer(name)
char *name; /* module name */
{
char nameptr[128],
*mod_name;
void *mod_exec; /* execution entry point */
u_int16
attr_rev,
type_lang=0;
mod_name=name; /* OS9000 may modify this pointer */
xyt_head=0;
/* first try linking to module */
if(_os_link(&mod_name,&xyt_head,&mod_exec,&type_lang,&attr_rev) == 0)
return 0;
/* OK maybe we can load the module */
if(_os_loadp(mod_name,0,nameptr,&xyt_head) == 0)
return 0;
/* guess it just ain't avaliable */
fprintf(stderr,"Unable to load transfer module \"%s\"!%c\012\n",name,BELL);
return 1;
}
/*********************************************************************
UNLOAD the TRANSFER program
*********************************************************************/
UnloadTransfer()
{
if(xyt_head) /* if sucessfully linked to */
_os_unlink(xyt_head);
}
/*********************************************************************
FILE TRANSFER
*********************************************************************/
void FileTransfer(prog,port)
char *prog; /* program name */
char *port; /* modem port */
{
int c;
if(xyt_head == 0)
{
tprint("\012\nTransfer program unavailable!\012\n");
return;
}
tprint("\n\012<S>end or <R>eceive? ");
c=GetOneChar();
switch(c)
{
case 'r':
case 'R':
ReceiveFiles(prog,port);
break;
case 's':
case 'S':
SendFiles(prog,port);
break;
default:
t_puts("\n\012ABORTED");
break;
}
t_puts("\n\012**** Transfer Complete ****\n\012");
}
/*********************************************************************
RECEIVE FILES from host
*********************************************************************/
ReceiveFiles(prog,port)
char *prog;
char *port;
{
sprintf(logstr,"-l=%s",logfile);
sprintf(portstr,"-t=%s",port);
arglist[0]=prog;
arglist[1]=logstr;
arglist[2]=portstr;
arglist[3]=0;
DoTransfer();
}
/*********************************************************************
SEND FILES to host
*********************************************************************/
SendFiles(prog,port)
char *prog;
char *port;
{
switch(typeflg)
{
case NONAME:
t_puts("\n\012You Must set the file name first\n\012");
return 0;
case FILENAME:
strcpy(transtr,transfile);
break;
case LISTNAME:
sprintf(transtr,"-z=%s",transfile);
break;
default:
return 0;
}
sprintf(portstr,"-t=%s",port);
sprintf(logstr,"-l=%s",logfile);
arglist[0]=prog;
arglist[1]=transtr;
arglist[2]=portstr;
arglist[3]=logstr;
arglist[4]=0;
DoTransfer();
}
/*********************************************************************
DO the TRANSFER
*********************************************************************/
DoTransfer()
{
process_id process;
status_code status;
ReleaseModemSignal();
cook_io();
errno=_os_exec(_os_fork,0,3,arglist[0],arglist,_environ,0,&process,0,0);
if(errno != 0)
{
sprintf(errstrng,"Unable to initiate transfer. Error # %d\n\012",
errno);
tprint(errstrng);
}
_os_wait(&process,&status);
raw_io();
}
/*********************************************************************
SET the TRANSFER FILE - filename to transfer
*********************************************************************/
SetTransferFile()
{
t_puts("File Name: ");
if(GetFileName() == 0)
{
sprintf(errstrng,"Transfer file set to \"%s\"\n\012",transfile);
tprint(errstrng);
typeflg=FILENAME;
}
else
{
tprint("Aborted!\n\012");
typeflg=NONAME;
}
}
/*********************************************************************
SET the FILE LIST - get the file to read for batch transfers
*********************************************************************/
SetFileList()
{
t_puts("List Name: ");
if(GetFileName() == 0)
{
if(CheckListFile() == 0)
{
sprintf(errstrng,"Transfer file names will be read from \"%s\"\n\012",transfile);
tprint(errstrng);
typeflg=LISTNAME;
return 0;
}
}
t_puts("Aborted!\n\012");
typeflg=NONAME;
}
/*********************************************************************
CHECK LIST FILE to be sure it will work
returns 0 if file looks good or bad file accepted
*********************************************************************/
CheckListFile()
{
static char *wheel="\\|/-";
char pathlist[128];
int good,total,wheelie,
offset;
FILE *fpath;
path_id path;
fpath=fopen(transfile,"r");
if(fpath == 0) /* access already chacked */
return 1;
t_puts("\012\nChecking File List...");
good=total=wheelie=0;
while(fgets(pathlist,128,fpath) != 0)
{
ToScreen(wheel[wheelie++]);
ToScreen(0x08);
if(wheelie > 3) wheelie=0;
offset=strlen(pathlist)-1; /* clear the CR */
if(offset < 1) /* if a null entry */
continue;
pathlist[offset]=0;
if(_os_open(pathlist,FAM_READ,&path) == 0)
{
good++;
_os_close(path);
}
total++;
}
fclose(fpath);
if(good == 0) /* if no good files */
{
t_puts("No valid file names found!\012\n");
return 1;
}
else if(good != total)
{
sprintf(errstrng,"Only %d of %d are valid. Accept anyway?",
good,total);
if(getans(errstrng) == TRUE)
return 0;
else
return 1;
}
else
{
sprintf(errstrng,"%d valid files names found\012\n",total);
tprint(errstrng);
}
return 0;
}
/*********************************************************************
GET the actual FILE NAME
*********************************************************************/
GetFileName()
{
path_id path;
t_gets(transfile,sizeof(transfile));
if(_os_open(transfile,FAM_READ,&path) != 0)
{
t_puts("\n\012Unable to access requested file!\n\012");
return 1;
}
_os_close(path);
return 0;
}