/*.........................................................*/
/*DATA DEFINITION SECTION */
/*.........................................................*/
#include <stdio.h>
#include <fcntl.h>
#include "global.h"/ *SNA62 global variables*/
#include "basic.h"/ *SNA62 Basic Verb Header*/
long cnvid; */ Conversation Identifier*/
#define BUFFSIZE 802
#define RECSIZE 84
#define REMOTPGM "s2_frcv"
/*.........................................................*/
/*MAINLINE */
/*.........................................................*/
main(argc, argv)
int argc;
char**argv;
{
extern interrno;
extern intoptind;
extern intopterr;
extern char*optarg;
intrc;
intfildes;
FILE*stream;
char*ch;
int nbyte;
int c;
int start = 2;/* Default to basic*/
int mapped = 0; /* Default to basic*/
int ebcdic = 0; /* Default to ascii*/
int doc = 0 /* Default to not a document*/
char **names;
char *rpgm;
struct snddta_ds snddta_ds;
union {
short II
hex buff[BUFFSIZE];
} s;
union {
short II
hex buff[RECSIZE];
} e;
/*.........................................................*/
/* Find Option flags -m, -e, -d, and -r */
/*.........................................................*/
opterr = 1; /* Turn off option error */
rpgm = REMOTPGM;
while( (c=getopt(argv, "mer:d") ) !=EOF)
{
switch (c)
{
case 'm':
mapped = 1;
start = 4;
break;
case 'e':
if (doc)
{
printf("-e for ebcdic assumes document mode./n");
printf("-e and -d cannot be specified
simultaneously.\n");
exit(-1);
}
ebcdic = 1;
break;
case 'r':
rpgm = optarg;
if( !rpgm )
{
printf("A program name is required with the -r
option.\n");
printf("s2_fsnd exiting.\n");
exit(-1);
}
break;
case 'd':
if ( ebcdic )
{
printf("-e for ebcdic assumes document mode.\n");
printf("-e and -d cannot be specified
simultaneously.\n");
exit(-1);
}
doc = 1;
break;
}
}
names = (argv + optind);
/*.........................................................*/
/* Six parameters must be entered. Exit if not */
/*.........................................................*/
if ( (argc - optind) <6 )
{
printf("These parameters must be entered to
s2_fsnd:\n");
printf("The configuration file name, the local LU,
the partner LU, the mode,
\n");
printf("the file you wish to transfer, and its name
on the remote system.\n");
printf("The -m -e and -r flags are optional, but
must come first if present.
\n");
printf("s2_fsnd exiting.\n");
exit(-1);
}
/*.........................................................*/
/* Open a local file. Exit if it cannot be opened */
/*.........................................................*/
if ( (fildes = open( *(names + 4), O_RDONLY ) ) == -1 )
{
printf("File %s open unsuccessful, errno %d\n",
*(names + 4),errno);
printf("s2_fsnd exiting.\n"); exit(-1);
}
else if ( doc || ebcdic)
{
if( !(stream = fdopen(fildes, "r") ) )
{
printf("File %s open unsuccessful, errno %d\n",
*(names + 4), errno);
printf("s2_fsnd exiting.\n"); exit(-1);
}
}
/*.........................................................*/
LOCALLY ATTACH THE PROGRAM
LATTACH requires the node name, local LU name, and transaction program name to be present as parameters.
/*.........................................................*/
rc = lattach( *(names + 0), *(names + 1), argv[0] );
if( rc == S2_ERR )
{
prterr(names);
exit( -1 );
}
/*.........................................................*/
ALLOCATE THE CONVERSATION
Pass mapped and ebcdic values, the remote pgm name, and the pointer to the array of pointers that contain the names.
/*.........................................................*/
rc = lconv( mapped, ebcdic, rpgm, names); /* Allocate
Conversation*/
if (rc == S2_ERR )
{
prterr(names);
exit( -1 );
}
/*.........................................................*/
READ AND SEND DATA
If ebcdic, call sndibm - else call sndunix.
/*.........................................................*/
if ( ebcdic )
{
sndibm(snddta_ds, mapped, stream, start, names);
}
else
{
sndunix(snddta_ds, mapped, stream, start, names,
doc, fildes, ebcdic);
}
/*.........................................................*/
DEALLOCATE, FLUSH
If the deallocate returns OK, detach from the LU and end the program. If the deallocate fails, (a negative response was received), deallocate locally, detach, and end program with an abend code.
/*.........................................................*/
if ( snamaj != S2_OK )
{
cleanup( );
}
else
{
rc = ldealloc( DC_SYNC );
if ( rc == S2_NOERR )
{
rc = detach( );
rc = 0;
}
else
{
prterr(names);
cleanup();
}
}
exit( rc );
/* END SPEEDL */
/*.........................................................*/
LOCAL ATTACH
/*.........................................................*/
lattach( pfile, llu, tpn )
char *pfile, *llu, *tpn;
{
struct attach_ds attach_ds;
int rc;
attach_ds.type = AT_LU
attach_ds.path = pfile;
attach_ds.name = llu;
attach_ds.tpn = tpn;
attach_ds.wait = NO;
rc = attach(&attach_ds);
return( rc );
}
/*.........................................................*/
LALLOC
/*.........................................................*/
lconv(mapped, ebcdic, rpgm, names)
int mapped;
int ebcdic;
char *rpgm;
char *names[ ];
{
int rc, i, j;
char wrkrlu[8];
char wrkmode[8];
struct alcnv_ds alcnv_ds;
alcnv_ds.rlu = names[2];
alcnv_ds.mode = names[3]; alcnv_ds.tpn = rpgm;
alcnv_ds.when = AC_WHEN; /* Delay */
alcnv_ds.type = mapped; /* Basic or mapped */
alcnv_ds.sync = 1;
alcnv_ds.user = NULL;
alcnv_ds.pass = NULL;
alcnv_ds.sec = 0;
alcnv_ds.pipused = 1;
if ( ebcdic )
alcnv_ds.pipa[0] = "EBCDIC";
else
alcnv_ds.pipa(0) = "ASCII";
atoe( alcnv_ds.pipa[0], strlen(alcnv_ds.pipa[0]) );
strcpy(wrkrlu, alcnv_ds.rlu);
alcnv_ds.pipa(1) = wrkrlu;
atoe( alcnv_ds.pipa{1}, strlen(alcnv_ds.pipa[1]) );
strcpy(wrkmode, alcnv_ds.mode);
alcnv_ds.pipa(2) = wrkmode;
atoe( alcnv_ds.pipa{2}, strlen(alcnv_ds.pipa[2]) );
for( i = 5, j = 3; names[i]; i++, j++ )
{
alcnv_ds.pipa[j] = names[i];
atoe( alcnv_ds.pipa[j],
strlen(alcnv_ds.pipa[j]) );
}
alcnv_ds.pipa[j] = NULL;
rc = alcnv(&alcnv_ds);
cnvid = alcnv_ds.cnvid;
return( rc );
}
/*.........................................................*/
LDEALLOC
/*.........................................................*/
ldealloc(type)
int type;
{
int rc;
if( snastat == S2_DLCED )
type = DC_LOCAL;
rc = dalcnv(cnvid,type,NULL);
return( rc );
}
/*.........................................................*/
PRTERR
/*.........................................................*/
prterr(names)
char *names[];
{
if( !(snamaj == S2_DEALC && snamin == S2_DNORM ) )
{
printf("Major code: %-4d %s\n", snamaj,
dspmaj(snamaj));
printf("Minor code: %-4d %s\n", snamin,
dspmin(snamaj,snamin));
printf("Error in s2_fsnd, file '%s' not sent
to '%s'\n", names[4], names[2] );
}
}
/*.........................................................*/
CLEANUP
Called if a conversation terminates abnormally.
/*.........................................................*/
cleanup()
{
ldealloc( DC_AB_PGM );
detach( );
exit(-1);
}
/*.........................................................*/
READ FROM THE FILE, SEND THE DATA, UNIX TO IBM
Leave the first two bytes for the logical record length field.
Read eighty bytes of data or less at one time.
/*.........................................................*/
sndibm(snddta_ds, mapped, stream, start, names)
struct snddta_ds snddta_ds;
int mapped;
FILE *stream;
int start;
char **names;
{
int nbyte;
int rc;
union {
short II
hex buff[RECSIZE];
} e;
snddta_ds.cnvid = cnvid;
snddta_ds.data = e.buff;
/* while snastat is in send state, and read is successful,
is successful, perform the send data */
while( snastat == S2_SEND &&
(fgets(e.buff + start, RECSIZE - start, stream)) )
{
nbyte = strlen( e.buff +start );
if( e.buff[nbyte + start -1] =='\n' ) nbyte--;
atoe( e.buff + start, nbyte );
e.II = nbyte + start;
snddta_ds.length = nbyte + start ;
if( mapped )
{
*( e.buff + 2 ) = 0x12;
*( e.buff + 3 ) = 0xFF;
}
rc = snddta( &snddta_ds );
if( rc == S2_ERR )
prterr(names);
}
}
/*.........................................................*/
READ FROM THE FILE, SEND THE DATA, UNIX TO UNIX
Leave the first two bytes for the logical record length field.
/*.........................................................*/
sndunix(snddta_ds, mapped, stream, start, names, doc, fildes,
ebcdic)
struct snddta_ds snddta_ds;
int mapped;
FILE *stream;
int start;
char **names;
int doc;
int fildes;
int ebcdic;
{
int nbyte;
int rc;
union {
short II
hex buff[BUFFSIZE];
} s;
snddta_ds.cnvid = cnvid;
snddta_ds.data = s.buff;
/* while snastat is in send state, and either of
the read types are successful, perform the
send data */
while( snastat == S2_SEND && ( (!doc && (nbyte =
read(fildes, s.buff + start,
BUFFSIZE - start ) )
&& (nbyte != -1)) ||
(doc&& (fgets(s.buff + start,
BUFFSIZE - start,stream)) ) ) )
{
if( doc ) nbyte = strlen( s.buff + start );
if( ebcdic )
atoe( s.buff + start, nbyte );
s.II = nbyte + start;
snddta_ds.length = nbyte F+ start ;
if( mapped )
{
*( s.buff + 2 ) = 0x12;
*( s.buff + 3 ) = 0xFF;
}
rc = snddta( &snddta_ds );
if( rec == S2_ERR )
prterr(names);
}
}
|