Metropoli BBS
VIEWER: xfermsg.c MODE: TEXT (ASCII)
/*
Copyright (C) Magna Carta Software, Inc. 1990-1991.  All Rights Reserved.
XFERMSG.C -- Sample file transfer status function. Do not execute directly.
This file is #included by the examples.
*/

#if !defined(CCTZ_H_INCLUDED)
    #include <cctz.h>
#endif

#if !defined(KERMIT_H_INCLUDED)
    #include <kermit.h>
#endif

/* KERMIT PACKET TYPES */
static char *k_msg[] = {
    "ABORT",
    "BREAK",
    "DATA",
    "ERROR",
    "FILE HEADER",
    "SEND-INIT",
    "END OF FILE"
};


static char *z_msg[] = {"ZRQINIT", "ZRINIT", "ZSINIT", "ZACK", "ZFILE",
    "ZSKIP", "ZNAK", "ZABORT", "ZFIN", "ZRPOS", "ZDATA", "ZEOF", "ZFERR",
    "ZCRC", "ZCHALLENGE", "ZCOMPL", "ZCAN", "ZFREECNT", "ZCMD", "ZSTDERR"};

char *a_cap[]    = {"CANFDX", "CANOVIO", "CANBRK", "CANCRY",
                       "CANLZW", "CANFC32", "ESCCTL", "ESC8"};
char *a_bool[]   = {"FALSE", "TRUE"};


/*
TRANSFER_PROGRESS -- This function is called during file transfer to
report status.
*/
short CDECL_ xfer_progress(COMM_PORT *p, short status, unsigned long parm)
{
    static short file_started;
    p = p;      /* nuke compiler warning */

    switch (status) {
        case 0:
            conouts("\nFile transfer successful");
            break;

        case BAD_HEADER_FORMAT:
            conoutf("\nBad header format");
            break;

        case BAD_PACKET_NUMBER:
            conoutf("\nBad packet number");
            break;

        case CAN:
            conoutf("\nCAN received!");
            break;

        case CONNECTION_LOST:
            conoutf("\nConnection lost at %ld bytes", parm);
            break;

        case CRC_ERROR:
            conoutf("\nCRC/checksum error");
            break;

        case DISK_FULL:
            conoutf("\nI/O Error Writing to Disk");
            break;

        case EOF:
            conoutf("\nNo character received");
            break;

        case EOT:
            conoutf("\nFinal ACK received!");
            break;

        case FILE_INFO_RECEIVED:
            conoutf("\nFile Information Received");
            if (fname[0] != '\0') conoutf("\nFile Name: %s", fname);
            if (fsize != 0L) conoutf("\nFile Size: %lu\n", fsize);
            break;

        case FILE_SOURCE:
            conoutf("\nFile being sent from %s", (parm == DISK) ? "DISK" : "RAM");
            break;

        case GARBAGE_RECEIVED:
            conoutf("\nUnrecognized character received");
            break;

        case FILE_LENGTH_ERROR:
            conoutf("\nFile length error");
            break;

        case HEADER_NOT_ACKNOWLEDGED:
            conoutf("\nHeader not acknowledged");
            break;

        case MAX_ERRORS_REACHED:
            conoutf("\nMaximum number of errors reached");
            break;

        case NAK:
            conoutf("\nNAK received");
            break;

        case NO_RX_START:
            conoutf("\nFile receiver did not poll. Attempt %ld", parm);
            break;

        case NO_TX_START:
            conoutf("\nTransmitter did not start. Attempt %ld", parm);
            break;

        case RX_CANCELLED:
            conoutf("\nRemote Cancelled");
            break;

        case RX_DATA_ERROR:
            conoutf("\nReceive data error");
            break;

        case RX_TIMEOUT:
            conoutf("\nReceiver Timeout");
            break;

        case SOH:
        case STX:
            if (!file_started) {
                if (parm == 0) conoutf("\nReceived Start of Header");
                file_started = TRUE;
            }
            break;

        case TX_CANCELLED:
            conoutf("\nTransmitter cancelled");
            break;

        case UNSPECIFIED:
            conoutf("\nUnspecified error");
            break;

        case USER_CANCELLED:
            conoutf("\nKeyboard cancel received");
            break;

        case USING_CHECKSUM:
            conoutf("\nUsing checksum error correction");
            break;

        case USING_CRC:
            conoutf("\nUsing CRC error correction");
            break;

        case XFER_POSITION:
            conoutf("\rBytes %ld", parm);
            break;

        case XMODEM:
            conoutf("\nUsing XMODEM");
            break;

        case XMODEM_CRC:
            conoutf("\nUsing XMODEM-CRC");
            break;

        case XMODEM_1K:
            conoutf("\nUsing XMODEM-1K");
            break;

        case YMODEM:
            conoutf("\nUsing YMODEM protocol");
            break;

        case YMODEM_G:
            conoutf("\nUsing YMODEM-g protocol");
            break;
#if 0
        case 'A':
            conoutf("\nABORT received");
            break;

        case 'B':
            conoutf("\nBREAK received");
            break;

        case 'D':
/*          conoutf("\nSending DATA packet"); */
            break;

        case 'E':
            conoutf("\nERROR packet received");
            break;

        case 'F':
            conoutf("\nFile header OK");
            break;

        case 'S':
            conoutf("\nSending Send-Init packet");
            break;

        case 'Z':
            conoutf("\nSending End-of-File packet");
            break;
#endif
        /* THIS BLOCK HANDLES KERMIT-SPECIFIC STATUS CODES */
        case K_ABORT | 0X1000:
        case K_BREAK | 0X1000:
        case K_DATA  | 0X1000:
        case K_EOF   | 0X1000:
        case K_ERROR | 0X1000:
        case K_FHEAD | 0X1000:
        case K_SINIT | 0X1000:
            status &= ~0X1000;
            if (status < sizeof(k_msg)/sizeof(k_msg[0]))
                conoutf("\r%s at packet %ld", k_msg[status], parm);
            break;

        /* THIS BLOCK HANDLES ZMODEM-SPECIFIC STATUS CODES */
        case ZRQINIT    | 0X2000:
        case ZSINIT     | 0X2000:
        case ZACK       | 0X2000:
        case ZFILE      | 0X2000:
        case ZSKIP      | 0X2000:
        case ZNAK       | 0X2000:
        case ZABORT     | 0X2000:
        case ZFIN       | 0X2000:
        case ZRPOS      | 0X2000:
        case ZDATA      | 0X2000:
        case ZEOF       | 0X2000:
        case ZFERR      | 0X2000:
        case ZCRC       | 0X2000:
        case ZCHALLENGE | 0X2000:
        case ZCOMPL     | 0X2000:
        case ZCAN       | 0X2000:
        case ZFREECNT   | 0X2000:
        case ZCOMMAND   | 0X2000:
        case ZSTDERR    | 0X2000:
            status &= ~0X2000;
            if (status < sizeof(z_msg)/sizeof(z_msg[0]))
                conoutf("\nReceived %s", z_msg[status]);
            break;

        case ZRINIT | 0X2000:
            {
                short i;
                for (i=0; i < 8; i++) {
                    conoutf("\nReceiver %s = %s",
                        a_cap[i], (parm & (1 << i)) ? a_bool[1] : a_bool[0]);
                }
                break;
            }

        default:
            conoutf("\nUnrecognized error report %#x", status);
            break;
    }

    return (0);
}
[ RETURN TO DIRECTORY ]