home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
kermit.columbia.edu
/
kermit.columbia.edu.tar
/
kermit.columbia.edu
/
archives
/
rt11pascal.zip
/
rtxlod.c
< prev
Wrap
C/C++ Source or Header
|
1984-05-22
|
2KB
|
156 lines
/*
* XLOAD
*
* Create a 'HEX' file from 'SAV' for RT-11 Kermit
* By Philip Murton - UTCS
* (EUNICE Version for VAX/VMS)
*
*/
#include <stdio.h>
#define LF '\n'
#define CR '\r'
#define TRUE 1
#define FALSE 0
#define puteol() fputs("\n",op)
#define RS 036
#define CONTROLX 030
#define BSIZE 64
#define TEXT FALSE
#define BINARY TRUE
#define TEST TRUE
FILE *op; /* output file pointer */
FILE *ip; /* input file pointer */
int mode; /* mode -- text or binary */
FILE *fopen();
main(argc,argv)
int argc;
char *argv[];
{
char *s;
int fd;
if(argc < 3)
error("usage: xload <HEX file> <SAV file>");
mode = BINARY;
op = NULL;
while(--argc > 0 && (*++argv) [0] == '-')
for(s = argv[0] + 1; *s != '\0'; s++)
switch(*s) {
case 'o':
op = stdout;
break;
default:
error("xload: illegal option");
break;
}
/* VMS Text File for EUNICE */
if(op == NULL)
{
if((fd = creat(*argv++,0664,"txt")) < 0)
error("xload: Cannot open output");
op = fdopen(fd,"w");
argc--;
}
while(argc-- >0 ) {
if ((ip = fopen(*argv++,"r")) == NULL)
error("xload: cannot open input file");
if(mode == TEXT)
{
}
else
{
expand();
puteof();
}
}
}
/*
*
*/
error(s)
char *s;
{
fprintf(stderr,"%s\n",s);
exit(1);
}
/*
* E X P A N D -- for PACKER
*/
char hex[] = "0123456789ABCDEF";
expand()
{
char c[2];
unsigned int t;
while(fread(c,sizeof(char),2,ip) != 0)
{
t = c[1] & 0xF0;
t = t >> 4;
packchar(hex[t]);
t = c[1] & 0x0F;
packchar(hex[t]);
t = c[0] & 0xF0;
t = t >> 4;
packchar(hex[t]);
t = c[0] & 0x0F;
packchar(hex[t]);
}
return(TRUE);
}
/*
* P A C K
*/
char buffer[BSIZE + 1];
char *bp = buffer;
char *endbuf = &buffer[BSIZE];
packchar(c)
char c;
{
if(bp < endbuf)
*bp++ = c;
else
{
*bp = '\0';
fputs(buffer,op);
puteol();
bp = buffer;
packchar(c);
}
}
puteof()
{
if(bp > buffer)
{
*bp = '\0';
fputs(buffer,op);
puteol();
}
}