DataMuseum.dk

Presents historical artifacts from the history of:

Commodore CBM-900

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Commodore CBM-900

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦0c63a2c5f⟧ TextFile

    Length: 1009 (0x3f1)
    Types: TextFile
    Notes: UNIX file
    Names: »sum.c«

Derivation

└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
    └─⟦f4b8d8c84⟧ UNIX V7 Filesystem
        └─ ⟦this⟧ »cmd/sum.c« 

TextFile



/*
 * sum -- generate checksum
 */
#include	<errno.h>
#include	<stdio.h>


#define	BUFSZ	(20*512)


int	err;
char	*filename;		/* used by error( ) */
extern	errno;


main( argc, argv)
register char	**argv;
{

	if (*++argv == NULL) {
		filename = "[stdin]";
		sum( (char *)0);
	}
	else
		while (filename = *argv++) {
			close( 0);
			if (open( filename, 0)) {
				error( (char *)0);
				continue;
			}
			sum( argc>2? filename: (char *)0);
		};

	return (err);
}


sum( file)
char	*file;
{
	register char	*p;
	register	a,
			n;
	long		size;
	static char	buf[BUFSZ];

	a = 0;
	size = 0;

	while ((n=read( 0, buf, sizeof buf)) > 0) {
		size += n;
		p = buf;
		do {
			a += *p++;
		} while (--n);
	}

	if (n < 0)
		error( errno==EIO? "read error": (char *)0);
	printf( "%5u %2D", a, (size+BUFSIZ-1)/BUFSIZ);
	if (file)
		printf( " %s", file);
	printf( "\n");
}


error( mesg)
char	*mesg;
{
	extern char	*sys_errlist[];

	fprintf( stderr, "sum: %s: %s\n", filename,
		mesg? mesg: sys_errlist[errno]);
	err = 1;
}