/* Copyright (C) Magna Carta Software, Inc. 1990, 1991. All Rights Reserved. C COMMUNICATIONS TOOLKIT RXTX.C -- Routines used in both receive and transmit file transfers. */ #define CCT_DEVELOPMENT #if (defined(CCTW) || defined(_WINDOWS)) #include #endif #include #include #include #include #include #include #if (defined(MSC) || defined(__WATCOMC__) || defined(_INTELC32_)) #include #elif defined(__TURBOC__) || defined(__POWERC) #include #endif short a_xfer_errors[MAX_XFER_ERROR_TYPES]; /* an array of error counters */ short mcfileatt = 0X20; /* default file attributes (A) */ short cct_xfer_status; /* FSEEKBUF_ -- Seek to position 'pos' relative to the beginning of the file transfer buffer. */ long fseekbuf_(XFER *x, long offset, int where) { short ret; long i, pos; where = where; /* nuke compiler warning */ ret = cct_file_close_(x->fh); if (!ret) { x->f_pos = 1; /* SET FLAG TO INDICATE START OF FILE */ pos = (offset == 0L) ? 0L : offset-1; for (i=0; i < pos && !ret; i++) if (c_fgetc_(x) == EOF) ret = EOF; } return (ret); } /* FFREEBUF_ -- Deallocate memory for file buffer. Return value: NONE; */ void ffreebuf_(XFER *x) { /* FREE THE FILE TRANSFER BUFFER */ if (x->buf != NULL) memfree(x->buf); x->pb = x->buf = NULL; } /* FQUEUE -- Queue the next file for transmission to a remote system. This function allocates a structure of type XFER_FILE and adds it to the end of the linked list. If "fname" is not NULL it attempts to find the file. Return value: 0 -- normal return; NO_FILE_OPEN -- unable to open file; NO_RAM -- Insufficient memory for a new XFER_FILE structure; EOF -- Unable to add file to queue; */ short fqueue(XFER *x, char *fspec) { XFER_FILE *xf; short ret; FHANDLE fh; /* FIRST, DETERMINE THAT FILE EXISTS */ fh = cct_file_open_(fspec, O_RDONLY | O_BINARY); if (!fh) return (NO_FILE); cct_file_close_(fh); /* FILE EXISTS -- ALLOCATE MEMORY FOR ITS XFER_FILE STRUCTURE */ xf = (XFER_FILE *) memcalloc(1, sizeof(XFER_FILE)); if (xf == NULL) return (NO_RAM); /* ADD FILE TO LINKED LIST */ if (!x->num_files) x->xf = xf; else { ret = ll_append_link(x->xf, xf); if (ret == EOF) return (EOF); } strcpy(xf->fspec, fspec); x->num_files++; return (0); } /* FUNQUEUE -- Unqueue a file. If "fspec" != NULL then search for the file by name. Else, use the first file. Free the XFER_FILE structure. Called from funload(). Return value: 0 -- normal return; NO_FILE -- No files queued; */ short funqueue(XFER *x, const char *fspec) { XFER_FILE *xf; short ret; if (x == NULL || x->xf == NULL || fspec == NULL) return (NO_FILE); xf = x->xf; /* SEARCH FOR THE FILE NAMED IN fspec */ while (xf != NULL) { if (strcmpi(xf->fspec, (char *) fspec) == 0) break; xf = xf->next; } if (xf == NULL) return (NO_FILE); /* DELETE THIS FILE FROM THE LINKED LIST */ ret = ll_delete_link(xf); if (ret == EOF) { if (xf->next != NULL) { x->xf = xf->next; x->xf->prev = NULL; } else x->xf = NULL; memfree(xf); ret = 0; } --x->num_files; return (ret); } short get_file_xfer_status(void) { short ret = cct_xfer_status; cct_xfer_status = 0; return (ret); }