home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
comm
/
xprzmodem-3.1.lha
/
XprZmodem
/
Utils.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-21
|
38KB
|
1,311 lines
/**********************************************************************
* Utils.c: Miscellaneous support routines for xprzmodem.library;
* Version 2.10, 12 February 1991, by Rick Huebner.
* Released to the Public Domain; do as you like with this code.
*
* Version 2.50, 15 November 1991, by William M. Perkins. Added code
* to update_rate() function in utils.c to avoid the Guru # 80000005
* you would have gotten if you had decided to adjust the system clock
* back during an upload or download.
*
* Mysprintf() function to replace sprintf() and proto code to use
* libinit.o and linent.o library code was supplied by Jim Cooper of SAS.
*
* Version 2.61, 3 July 1993 Mysprintf changed to xprsprintf(), written
* in Assembler, because under SAS/C the old code running not correctly.
*
* Version 2.62, 27 July 1993 build in variable Blocksize.
*
* Version 2.63, 30 July 1993 build in locale, by Rainer Hess
*
* Version 2.64, 3 Aug 1993 global vaiable Blocksize, now in
* struct Vars, by Rainer Hess
*
* 4 Aug 1993 changes in update_rate() function because
* it always GURU 8000 0005 on little files (testet with 2 byte-file)
* when you send. If on receiver the file exists when receiver ask for
* overwrite, the machine crash if you click overwrite on receiver.
* Testet on Term 3.4 -> Ncomm 2.0, by Rainer Hess
*
**********************************************************************/
#include "xprzmodem_all.h"
#define CATCOMP_NUMBERS
#include "xprzmodem_catalog.h"
/*
* Transfer options to use if XProtocolSetup not called
*/
struct SetupVars Default_Config =
{
NULL, /* = *matchptr */
NULL, /* = *bufpos */
0, /* = buflen */
"C", /* option_t[2] */
"N", /* option_o[2] */
"16", /* option_b[8] */
"0", /* option_f[8] */
"10", /* option_e[8] */
"N", /* option_s[4] */
"N", /* option_r[4] */
"Y", /* option_a[4] */
"N", /* option_d[4] */
"Y", /* option_k[4] */
"", /* option_p[256] */
"1024" /* option_m[8] */
};
#ifdef DEBUGLOG
UBYTE DebugName[] = "T:XDebug.Log";
void *DebugLog = NULL;
#endif
struct DosLibrary *DOSBase;
struct ExecBase *SysBase;
#ifdef UP_TO_2X
struct Library *UtilityBase;
#endif
#define LIBRARY_ANY 0L
#define LocaleBase li.li_LocaleBase
#define catalog li.li_Catalog
struct LocaleInfo li;
struct TagItem LocalTags[3] =
{
OC_BuiltInLanguage, (ULONG) "english",
OC_Version, 1, /* Catalog-Nummer */
TAG_DONE
};
/**********************************************************
* int __UserLibInit(struct Library *libbase)
**********************************************************/
int __saveds __asm
__UserLibInit (register __a6 struct MyLibrary *libbase)
{
SysBase = *(struct ExecBase **) 4L;
if (!(DOSBase = (struct DosLibrary *) OpenLibrary ("dos.library", LIBRARY_ANY)))
return (RETURN_FAIL);
#ifdef UP_TO_2X
if (!(UtilityBase = OpenLibrary ("utility.library", 37L)))
return (RETURN_FAIL);
#endif
if (LocaleBase = OpenLibrary ("locale.library", 38L))
catalog = OpenCatalogA (NULL, "xprzmodem.catalog", &LocalTags[0]);
return (RETURN_OK);
} /* End of __UserLibInit() */
/**********************************************************
* void __UserLibCleanup(struct Library *libbase)
**********************************************************/
void __saveds __asm
__UserLibCleanup (register __a6 struct MyLibrary *libbase)
{
if (DOSBase)
CloseLibrary ((struct Library *) DOSBase);
#ifdef UP_TO_2X
if (UtilityBase)
CloseLibrary (UtilityBase);
#endif
if (LocaleBase)
{
if (catalog)
CloseCatalog (catalog);
CloseLibrary (LocaleBase);
}
} /* End of __UserLibCleanup() */
/**********************************************************
* long XProtocolSetup(struct XPR_IO *xio)
*
* Called by comm program to set transfer options
**********************************************************/
long __saveds __asm
XProtocolSetup (register __a0 struct XPR_IO *xio)
{
struct SetupVars *sv, tempsv;
struct xpr_option *option_ptrs[13];
struct xpr_option *optr, xo_hdr, xo_t, xo_o, xo_b, xo_f, xo_e, xo_s,
xo_r, xo_a, xo_d, xo_k, xo_p, xo_m;
UBYTE buf[256], *p;
long i, len;
/* Allocate memory for transfer options string */
if (!(sv = (void *) xio->xpr_data))
{
xio->xpr_data = AllocMem ((ULONG) sizeof (struct SetupVars), MEMF_CLEAR);
if (!(sv = (void *) xio->xpr_data))
{
ioerr (xio, "Not enough memory!");
return XPRS_FAILURE;
}
/* Start out with default options; merge user changes into defaults */
*sv = Default_Config;
}
/* If options string passed by comm prog, use it; else prompt user */
if (xio->xpr_filename)
strcpy (buf, xio->xpr_filename);
else
{
/* If xpr_options() implemented by comm program, use it */
if (xio->xpr_extension >= 1 && xio->xpr_options)
{
/*
* Let user edit temp copy of options so we can ignore invalid
* entries. Have to init all this crud the hard way 'cause it's
* got to be on the stack in order to maintain reentrancy
*/
tempsv = *sv;
xo_hdr.xpro_description = GetLocalString( &li, MSG_ZMODEM_OPTIONS );
xo_hdr.xpro_type = XPRO_HEADER;
xo_hdr.xpro_value = NULL;
xo_hdr.xpro_length = 0;
option_ptrs[0] = &xo_hdr;
xo_t.xpro_description = GetLocalString( &li, MSG_TEXT_MODE );
xo_t.xpro_type = XPRO_STRING;
xo_t.xpro_value = tempsv.option_t;
xo_t.xpro_length = sizeof (tempsv.option_t);
option_ptrs[1] = &xo_t;
xo_o.xpro_description = GetLocalString( &li, MSG_OVERWRITE_MODE );
xo_o.xpro_type = XPRO_STRING;
xo_o.xpro_value = tempsv.option_o;
xo_o.xpro_length = sizeof (tempsv.option_o);
option_ptrs[2] = &xo_o;
xo_b.xpro_description = GetLocalString( &li, MSG_IO_BUFFER_SIZE );
xo_b.xpro_type = XPRO_LONG;
xo_b.xpro_value = tempsv.option_b;
xo_b.xpro_length = sizeof (tempsv.option_b);
option_ptrs[3] = &xo_b;
xo_f.xpro_description = GetLocalString( &li, MSG_FRAME_SIZE );
xo_f.xpro_type = XPRO_LONG;
xo_f.xpro_value = tempsv.option_f;
xo_f.xpro_length = sizeof (tempsv.option_f);
option_ptrs[4] = &xo_f;
xo_e.xpro_description = GetLocalString( &li, MSG_ERROR_LIMIT );
xo_e.xpro_type = XPRO_LONG;
xo_e.xpro_value = tempsv.option_e;
xo_e.xpro_length = sizeof (tempsv.option_e);
option_ptrs[5] = &xo_e;
xo_a.xpro_description = GetLocalString( &li, MSG_AUTO_ACTIVATE_RECEIVER );
xo_a.xpro_type = XPRO_BOOLEAN;
xo_a.xpro_value = tempsv.option_a;
xo_a.xpro_length = sizeof (tempsv.option_a);
option_ptrs[6] = &xo_a;
xo_d.xpro_description = GetLocalString( &li, MSG_DELETE_AFTER_SENDING );
xo_d.xpro_type = XPRO_BOOLEAN;
xo_d.xpro_value = tempsv.option_d;
xo_d.xpro_length = sizeof (tempsv.option_d);
option_ptrs[7] = &xo_d;
xo_k.xpro_description = GetLocalString( &li, MSG_KEEP_PARTIAL_FILES );
xo_k.xpro_type = XPRO_BOOLEAN;
xo_k.xpro_value = tempsv.option_k;
xo_k.xpro_length = sizeof (tempsv.option_k);
option_ptrs[8] = &xo_k;
xo_s.xpro_description = GetLocalString( &li, MSG_SEND_FULL_PATH );
xo_s.xpro_type = XPRO_BOOLEAN;
xo_s.xpro_value = tempsv.option_s;
xo_s.xpro_length = sizeof (tempsv.option_s);
option_ptrs[9] = &xo_s;
xo_r.xpro_description = GetLocalString( &li, MSG_USE_RECEIVED_PATH );
xo_r.xpro_type = XPRO_BOOLEAN;
xo_r.xpro_value = tempsv.option_r;
xo_r.xpro_length = sizeof (tempsv.option_r);
option_ptrs[10] = &xo_r;
xo_p.xpro_description = GetLocalString( &li, MSG_DEFAULT_RECEIVE_PATH );
xo_p.xpro_type = XPRO_STRING;
xo_p.xpro_value = tempsv.option_p;
xo_p.xpro_length = sizeof (tempsv.option_p);
option_ptrs[11] = &xo_p;
xo_m.xpro_description = GetLocalString( &li, MSG_MAXIMUM_BLOCK_SIZE );
xo_m.xpro_type = XPRO_LONG;
xo_m.xpro_value = tempsv.option_m;
xo_m.xpro_length = sizeof (tempsv.option_m);
option_ptrs[12] = &xo_m;
/* Convert Y/N used elsewhere into "yes"/"no" required by spec */
for (i = 6; i <= 10; ++i)
{
optr = option_ptrs[i];
strcpy (optr->xpro_value, (*optr->xpro_value == 'Y') ? "yes" :