[net.sources] file format programs

hart@cp1.UUCP (08/19/84)

echo fix.c
sed 's/^	//' > fix.c << 'Rod Hart was here'
	#include <stdio.h>
	#define LINEWIDTH	80
	
	/*
	 * fix - Convert files to fix format.
	 *
	 * Fix format files use a single character to represent four bit
	 * nibbles.  The characters start at character 0 (30H) and extend
	 * through the character ? (3FH).  The first line contains the
	 * name of the original file (excluding path or disk specification)
	 * preceeded by a minus sign.  The rest of the file contains 80 
	 * characters per line.
	 */
	main(argc,argv)
	int	argc;
	char	**argv;
	{
		int c,column;
		FILE *fd;
	
		if (argc != 2) {
			fprintf(stderr,"usage: fix file\n");
			exit(-1);
		}
		argv++;			/* skip command name */
		if ((fd = fopen(*argv,"r")) == NULL) {
			fprintf(stderr,"cannot open %s\n",*argv);
			exit(-1);
		}
		printf("-%s\n",*argv);	/* write filename line */
		column=0;
		for (c=fgetc(fd); c != EOF; c=fgetc(fd)) {
			putchar(((c>>4) & 0xF)+'0');
			putchar((c & 0xF)+'0');
			column += 2;
			if (column == LINEWIDTH) {
				putchar('\n');
				column=0;
			}
		}
	}
Rod Hart was here
echo unfix.c
sed 's/^	//' > unfix.c << 'Rod Hart was here'
	
	#include <stdio.h>
	#define LINEWIDTH	80
	
	/*
	 * unfix - Convert fix format files back to original form.
	 *
	 * Fix format files use a single character to represent four bit
	 * nibbles.  The characters start at character 0 (30H) and extend
	 * through the character ? (3FH).  The first line contains the
	 * name of the original file (excluding path or disk specification)
	 * preceeded by a minus sign.  The rest of the file contains 80 
	 * characters per line.
	 */
	main(argc,argv)
	int	argc;
	char	**argv;
	{
		int  c,cout;
		char filename[128];
		char line[LINEWIDTH+1];
		char *cp;
		FILE *fd,*ofd;
	
		if (argc != 2) {
			fprintf(stderr,"usage: fix file\n");
			exit(-1);
		}
		argv++;			/* skip command name */
		if ((fd = fopen(*argv,"r")) == NULL) {
			fprintf(stderr,"cannot open %s\n",*argv);
			exit(-1);
		}
		fgets(filename,128,fd);	/* read filename line */
		for (cp=filename; *cp != '\n' && cp < filename+128; cp++) ;
		if (*cp == '\n')	/* remove newline at end of line */
			*cp = '\0';
		if (filename[0] != '-') {
			fprintf(stderr,"file is not in fix format\n");
			exit(-1);
		}
		if ((ofd = fopen(&filename[1],"w")) == NULL) {
			fprintf(stderr,"cannot open output file %s\n",&filename[1]);
			exit(-1);
		}
		for (c=fgetc(fd); c != EOF; c=fgetc(fd)) {
			if (c == '\n')
				continue;
			cout = (c-'0') << 4;
			c = fgetc(fd);
			cout |= c-'0';
			putc(cout,ofd);
		}
	}
Rod Hart was here
-- 


======================================================================
signed: Rod Hart (wa3mez) 
        Chesapeake & Potomac Tel. Co.
        Bell Atlantic Inc.
        Silver Spring, Md.
        gamma!cp1!hart - umcp-cs!cp1!hart - aplvax!cp1!hart
======================================================================