home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
8bitfiles.net/archives
/
archives.tar
/
archives
/
canada-remote-systems
/
cpower
/
cpmsd.arc
/
CPMSD.C
next >
Wrap
Text File
|
2019-04-13
|
8KB
|
327 lines
/*
** CPMSD.C - FILTER ├ LANGUAGE SOURCE
** FILE TO/FROM C-POWER AND
** MS-DOS
**
** THIS SOURCE FILE CONTAINS SOME
** CHANGES TO THE MS-DOS VERSION TO
** ACCOMMODATE C-POWER PECULIARITIES
** IE. - 'UNSIGNED'S RATHER THAN 'INT'S
** - USE OF PRINTF() RATHER THAN
** PUTS() WHICH IS MORE EFFICIENT
** WITHIN THE SHELL
** - FILE SIZE ASSUMED TO BE UNDER
** 65535 BYTES
** - SPECIFIC DECLARATION OF 'AUTO'
** STORAGE WHEN POINTERS ARE TO BE
** PASSED DUE TO THE WAY C-POWER
** USES THE 65XX'S ZERO PAGE
**
** MAR88 BEN PEDERSEN SYSOP C-POWER BBS
** FEB90 MINOR UPDATES BEN PEDERSEN
**
** NOTE: ORIGINAL C-POWER LIBRARY
** FREAD() AND FWRITE() CONTAIN A BUG.
** THEY DO NOT RETURN THE NUMBER OF
** ELEMENTS READ OR WRITTEN IF FEWER ARE
** AVAILABLE THAN ARE SPECIFIED -- THEY
** RETURN ZERO INSTEAD OF THE ACTUAL
** NUMBER READ OR WRITTEN WHICH IS
** NON-STANDARD. THIS PROGRAM REQUIRES
** THE CORRECTED VERSIONS TO FUNCTION
** PROPERLY. OBTAIN UPDATED FREAD() AND
** FWRITE() OR FIX THE OLD ONES YOURSELF
** USING ═ARK ╥INFRET'S ╥┴ (╥EVERSE
** ┴SSEMBLER) AND ├┴╙╙═ (├ ┴SSEMBLER).
**
** ╠EARNING ┼XPERIENCE ┬┬╙ 416-665-3263
** ╟╘ ╬ODE 053/012
*/
#INCLUDE <STDIO.H>
/* C-POWER TO MS-DOS OUTPUT BUFFER MUST
BE BIGGER DUE TO LINE-FEED INSERTION */
#DEFINE ╧╒╘╙╔┌┼ 32 * 254 /* BLOCK SIZE OF OUTPUT FILE BUFFER */
#DEFINE ╔╬╙╔┌┼ 28 * 254 /* BLOCK SIZE OF INPUT FILE BUFFER */
/* ├╘╠-┌ CHAR USED FOR MS-DOS END-OF-FILE
AND FOR PADDING THE FINAL BLOCK OF
XMODEM TRANSFERS BUT ISN'T USED ON ├┬═
SYSTEMS SO THEY'RE STRIPPED IN MSDTOCP() */
#DEFINE ├╘╠ñ┌ 0X001A
/* PROGRAM STATUS CODES */
#DEFINE ╧╦┴┘ 0
#DEFINE ╘┼╥═╔╬ 1
#DEFINE ╔╬┬╒╞╞ 2
#DEFINE ╧╒╘┬╒╞ 3
#DEFINE ╔╬╞╔╠┼ 4
#DEFINE ╧╒╘╞╔╠ 5
#DEFINE ╥┼┴─╔╬ 6
#DEFINE ╫╥╘╧╒╘ 7
#DEFINE ╞╔╬╔╙╚ 8
/* PROGRAM STATUS MESSAGES */
CHAR *S[] = █
"",
" USER TERMINATED",
" ERROR ALLOCATING INPUT BUFFER",
" ERROR ALLOCATING OUTPUT BUFFER",
" ERROR OPENING INPUT FILE",
" ERROR OPENING OUTPUT FILE",
" ERROR READING INPUT FILE",
" ERROR WRITING OUTPUT FILE",
" FILE TRANSLATION COMPLETE"
▌;
CHAR *MALLOC();
UNSIGNED CPTOMSD(), MSDTOCP(); /* TRANSLATION FUNCTIONS */
╞╔╠┼ INñFN, OUTñFN; /* FILE NUMBERS */
CHAR *INñBUF, *OUTñBUF; /* DATA BUFFER POINTERS */
MAIN()
█
AUTO UNSIGNED TOTALñIN, TOTALñOUT; /* DATA BYTE TOTALS */
AUTO UNSIGNED (*FUNCñPTR)(); /* POINTER TO TRANSLATION OPTION FUNCTION */
CHAR INñFIL[17],OUTñFIL[17]; /* FILE NAME BUFFERS */
UNSIGNED STATUS; /* FUNCTION ERROR STATUS */
TOTALñIN = TOTALñOUT = 0;
/* GET OPTION FROM USER */
IF(STATUS = GETñOPT(&FUNCñPTR))
EXSTAT(STATUS);
/* ALLOCATE BUFFERS */
IF(STATUS = MAKEñBUFFS())
EXSTAT(STATUS);
/* GET AN INPUT FILE */
IF(STATUS = GETñINFILE(INñFIL))
EXSTAT(STATUS);
/* GET AN OUTPUT FILE */
IF(STATUS = GETñOUTFILE(OUTñFIL))
EXSTAT(STATUS);
/* DO FILE TRANSLATION */
DO █
IF(STATUS = TRANSFILE(&TOTALñIN, &TOTALñOUT, FUNCñPTR))
EXSTAT(STATUS);
▌ WHILE(!FEOF(INñFN));
PRINTF("\N %-16S: %U BYTES\N %-16S: %U BYTES\N", INñFIL, TOTALñIN, OUTñFIL, TOTALñOUT);
/* BYE! */
EXSTAT(╞╔╬╔╙╚);
▌
/* ALLOCATE DATA BUFFERS */
MAKEñBUFFS()
█
/* ALLOCATE ╔╬╙╔┌┼ INPUT BUFFER */
IF((INñBUF = (CHAR *)MALLOC(╔╬╙╔┌┼ * SIZEOF(CHAR))) == ╬╒╠╠)
RETURN(╔╬┬╒╞╞);
/* ALLOCATE ╧╒╘╙╔┌┼ OUTPUT BUFFER */
/* C-POWER TO MS-DOS OUTPUT FILE WILL BE BIGGER DUE TO INSERTED LINE-FEEDS */
IF((OUTñBUF = (CHAR *)MALLOC(╧╒╘╙╔┌┼ * SIZEOF(CHAR))) == ╬╒╠╠)
RETURN(╧╒╘┬╒╞);
RETURN(╧╦┴┘);
▌
/* GET AN INPUT FILE */
GETñINFILE(INñFIL)
CHAR *INñFIL;
█
/* GET PATH TO INPUT FILE */
PRINTF("\N INPUT FILE : ");
SCANF("%16S", INñFIL);
/* OPEN INPUT FILE */
IF((INñFN = FOPEN(INñFIL, "R")) == ╬╒╠╠ ▀▀ FERROR(INñFN))
RETURN(╔╬╞╔╠┼);
ELSE RETURN(╧╦┴┘);
▌
/* GET AN OUTPUT FILE */
GETñOUTFILE(OUTñFIL)
CHAR *OUTñFIL;
█
/* GET PATH TO OUTPUT FILE */
PRINTF(" OUTPUT FILE: ");
SCANF("%16S", OUTñFIL);
/* OPEN OUTPUT FILE */
IF((OUTñFN = FOPEN(OUTñFIL, "W")) == ╬╒╠╠ ▀▀ FERROR(OUTñFN))
RETURN(╧╒╘╞╔╠);
ELSE RETURN(╧╦┴┘);
▌
/* DO FILE TRANSLATION */
TRANSFILE(TOTñIN, TOTñOUT, FñPTR)
UNSIGNED *TOTñIN, *TOTñOUT;
UNSIGNED (*FñPTR)();
█
AUTO UNSIGNED INBYTES;
UNSIGNED OUTBYTES, STATUS;
IF(STATUS = DATAñIN(&INBYTES))
RETURN(STATUS);
*TOTñIN += INBYTES;
OUTBYTES = (*FñPTR)(INBYTES);
*TOTñOUT += OUTBYTES;
IF(STATUS = DATAñOUT(OUTBYTES))
RETURN(STATUS);
RETURN(╧╦┴┘);
▌
/* DO MS-DOS TO C-POWER DATA TRANSLATION */
UNSIGNED MSDTOCP(INBYTES)
UNSIGNED INBYTES;
█
UNSIGNED OUTBYTES;
CHAR *INñPTR, *OUTñPTR;
INñPTR = INñBUF;
OUTñPTR = OUTñBUF;
FOR(OUTBYTES = 0; INñPTR <= INñBUF + INBYTES; INñPTR++, OUTñPTR++, OUTBYTES++) █
IF(*INñPTR == ├╘╠ñ┌) BREAK; /* STRIP ├╘╠-┌ CHARS */
ELSE IF(*INñPTR >= 0X0041 && *INñPTR <= 0X005A)
*OUTñPTR = *INñPTR + 0X0080; /* UPPER CASE */
ELSE IF(*INñPTR >= 0X0061 && *INñPTR <= 0X007A)
*OUTñPTR = *INñPTR - 0X0020; /* LOWER CASE */
ELSE IF(*INñPTR == 0X005F) *OUTñPTR = 0X00A4; /* UNDERSCORE */
ELSE IF(*INñPTR == 0X007E) *OUTñPTR = 0X00AF; /* TILDE */
ELSE IF(*INñPTR == 0X007B) *OUTñPTR = 0X00DB; /* LEFT BRACE */
ELSE IF(*INñPTR == 0X007D) *OUTñPTR = 0X00DD; /* RIGHT BRACE */
ELSE IF(*INñPTR == 0X007C) *OUTñPTR = 0X00DF; /* VERTICAL BAR */
ELSE IF(*INñPTR == 0X0009) *OUTñPTR = 0X0020; /* TAB TO SPACE */
ELSE IF(*INñPTR == 0X000A) █ /* STRIP LINE FEEDS */
--OUTñPTR;
--OUTBYTES;
▌
ELSE *OUTñPTR = *INñPTR; /* NO TRANSLATION */
▌
RETURN(--OUTBYTES);
▌
/* DO C-POWER TO MS-DOS DATA TRANSLATION */
UNSIGNED CPTOMSD(INBYTES)
UNSIGNED INBYTES;
█
UNSIGNED OUTBYTES;
CHAR *INñPTR, *OUTñPTR;
INñPTR = INñBUF;
OUTñPTR = OUTñBUF;
FOR(OUTBYTES = 0; INñPTR <= INñBUF + INBYTES; INñPTR++, OUTñPTR++, OUTBYTES++) █
IF(*INñPTR >= 0X00C1 && *INñPTR <= 0X00DA)
*OUTñPTR = *INñPTR - 0X0080; /* UPPER CASE */
ELSE IF(*INñPTR >= 0X0041 && *INñPTR <= 0X005A)
*OUTñPTR = *INñPTR + 0X0020; /* LOWER CASE */
ELSE IF(*INñPTR == 0X00A4) *OUTñPTR = 0X005F; /* UNDERSCORE */
ELSE IF(*INñPTR == 0X00AF) *OUTñPTR = 0X007A; /* TILDE */
ELSE IF(*INñPTR == 0X00DB) *OUTñPTR = 0X007B; /* LEFT BRACE */
ELSE IF(*INñPTR == 0X00DD) *OUTñPTR = 0X007D; /* RIGHT BRACE */
ELSE IF(*INñPTR == 0X00DF) *OUTñPTR = 0X007C; /* VERTICAL BAR */
ELSE IF(*INñPTR == 0X000D) █ /* ADD LINE-FEEDS */
*OUTñPTR = *INñPTR;
++OUTñPTR;
*OUTñPTR = 0X000A;
++OUTBYTES;
▌
ELSE *OUTñPTR = *INñPTR; /* NO TRANSLATION */
▌
RETURN(--OUTBYTES);
▌
/* GET DATA TRANSLATE OPTION */
GETñOPT(FñPTR)
UNSIGNED (**FñPTR)();
█
PRINTF("\N C-POWER <=> MS-DOS FILE TRANSLATION\N MAR88 BEN PEDERSEN\N");
PRINTF("\N 1) C-POWER TO MS-DOS\N 2) MS-DOS TO C-POWER\N 3) QUIT\N\N OPTION: ");
SWITCH(GETCHAR()) █
CASE '1':
PRINTF("\N C-POWER TO MS-DOS\N");
*FñPTR = CPTOMSD;
RETURN(╧╦┴┘);
BREAK;
CASE '2':
PRINTF("\N MS-DOS TO C-POWER\N");
*FñPTR = MSDTOCP;
RETURN(╧╦┴┘);
BREAK;
CASE '3':
DEFAULT:
RETURN(╘┼╥═╔╬);
BREAK;
▌
▌
/* READ DATA TO INPUT BUFFER */
DATAñIN(INBYTES)
UNSIGNED *INBYTES;
█
*INBYTES = FREAD(INñBUF, SIZEOF(CHAR), ╔╬╙╔┌┼, INñFN);
IF(FERROR(INñFN)) RETURN(╥┼┴─╔╬);
RETURN(╧╦┴┘);
▌
/* WRITE DATA TO OUTPUT FILE */
DATAñOUT(OUTBYTES)
UNSIGNED OUTBYTES;
█
IF((FWRITE(OUTñBUF, SIZEOF(CHAR), OUTBYTES, OUTñFN) != OUTBYTES) ▀▀ FERROR(OUTñFN))
RETURN(╫╥╘╧╒╘);
ELSE RETURN(╧╦┴┘);
▌
/* EXIT FROM PROGRAM */
EXSTAT(STATUS)
UNSIGNED STATUS;
█
PRINTF("\N%S\N\N",S[STATUS]);
SWITCH(STATUS) █
CASE 0:
CASE 1:
BREAK;
CASE 2:
FREE(INñBUF);
BREAK;
CASE 3:
FREE(INñBUF);
FREE(OUTñBUF);
BREAK;
CASE 4:
FREE(INñBUF);
FREE(OUTñBUF);
FCLOSE(INñFN);
BREAK;
CASE 5:
CASE 6:
CASE 7:
FREE(INñBUF);
FREE(OUTñBUF);
FCLOSE(INñFN);
FCLOSE(OUTñFN);
BREAK;
CASE 8:
DEFAULT:
BREAK;
▌
EXIT();
▌
/* END OF CPMSD.C */