[net.sources] Microsoft Windows CRD file print program

zemon@fritz.UUCP (07/13/86)

I got tired of waiting for the cardfile program to churn out a
simple cardfile on my dot matrix printer.  It wastes an
incredible amount of time (and paper) on the cute graphics
boxes.  Soooo, I cranked out this little program to just print
the text and be done with it.  Enjoy.

Cheers,
    -- Art Z.

/*
 * crdprint -	print a Microsoft Windows cardfile
 *
 *		This program will print a cardfile in a simple fashion
 *		on any ASCII printer.  It does not bother drawing the
 *		cute (and timeconsuming) boxes around the cards.
 *
 * Art Zemon	July 12, 1986
 *
 * CompuServe:	72406,3275
 * UUCP:	ucbvax!trwrb!felix!zemon
 */

#include <stdio.h>

struct header {
	char		fill1[3];
	short		ncards;
	char		fill2[6];
} header;

struct cardheader {
	long		offset;
	char		fill1;
	char		text[47];
} cardheader;

struct cardbody {
	short		fill1;
	short		bytes;
} cardbody;


main(argc, argv)
int			argc;
char			*argv[];
{
	FILE		*h, *b;		/* we will open the card file
					   twice, once for the headers &
					   once for the bodies of the cards */
	char		text[256];
	int		card;
	static char	separator[] = "----------------------------------------";

	if (argc != 2) {
		fputs("Usage: crdprint {card-file}\n", stderr);
		fputs("\tCrdprint will display the entire cardfile in a simple format.\n", stderr);
		exit(1);
	}

	if ((h = fopen(argv[1], "r")) == NULL) {
		perror(argv[1]);
		exit(1);
	}
	b = fopen(argv[1], "r");
	
	/*
	 * Read the file header to determine how many cards there are.
	 */
	fread(&header, sizeof header, 1, h);
	
	/*
	 * Loop once for each card.
	 */
	for (card = 1; card <= header.ncards; ++card) {
		/*
		 * Read the cardheader to determine the location of the body.
		 */
		fread(&cardheader, sizeof cardheader, 1, h);

		/*
		 * Seek to the location of the body and read its length.
		 */
		fseek(b, cardheader.offset, 0);
		fread(&cardbody, sizeof cardbody, 1, b);

		/*
		 * Now read the text of the card's body.
		 */
		fread(text, 1, cardbody.bytes, b);
		
		/*
		 * Print everything.
		 */
		puts(separator);
		puts(cardheader.text);
		fwrite(text, 1, cardbody.bytes, stdout);
		putchar('\n');
	}
	
	puts(separator);
	exit(0);
}
-- 
	-- Art Zemon
	   FileNet Corp.
	   ...! {decvax, ihnp4, ucbvax} !trwrb!felix!zemon