atari-sources-request@imagen.UUCP (04/16/87)
Submitted by: turner (D'arc Angel) comp.sources.atari.st: Volume 0, Issue 2 Archive-name: cksm +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= [Editor's Note] This is the third of three tools (dumas' uu*code and arc are the other two) to be used in 'unpacking' postings in this group and comp.binaries.atari.st. To compile this program on a non-ST computer make sure that the pre-compiler variable 'vax' is #define'd. I know that it will compile under Megamax C and Marc Williams on the ST and under UNIX. The output of the program on the ST looks like: bytes = 832 cksm = 700 cksblk.c bytes = 1499 cksm = 2347 cksm.c Hit return to continue and on the vax (or other non-ST computer) bytes = 802( 832) cksm = 700 /rd/turner/src/cksblk.c bytes = 1422( 1499) cksm = 2347 /rd/turner/src/cksm.c Hit return to continue The first number is the size of the file on the vax, the second (number) is the size of the file on the ST. The difference is due to the access routines on the ST adding a <CR> for every <LF> that they read in an ascii file. The checksums however match and thats what really counts. The binaries for the ST will be posted to comp.binaries.atari.st. +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= I will start including the output of cksm in each posting. #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # cksblk.c # cksm.c # This archive created: Wed Apr 15 21:02:20 1987 # By: D'arc Angel (The Houses of the Holy) export PATH; PATH=/bin:/usr/bin:$PATH echo shar: "extracting 'cksblk.c'" '(802 characters)' if test -f 'cksblk.c' then echo shar: "will not over-write existing file 'cksblk.c'" else sed 's/^ X//' << \SHAR_EOF > 'cksblk.c' X Xint cksblk(block, numbyt, initck, nlines) /* Checksum a block of bytes */ Xchar *block; Xlong int numbyt; Xint initck, *nlines; X X/* Arguments: block: Pointer to first byte of block to be checksummed. */ X/* numbyt: Number of bytes in the block. */ X/* initck: Initial value for checksum (i.e., partial sum */ X/* carried forward from previous blocks). */ X X{ X register char *curbyt, *endptr; X register int accsm; X X endptr = block + numbyt; /* Pointer to end+1 of block */ X accsm = initck; /* Checksum accumulator. */ X X X for ( curbyt = block; curbyt < endptr; curbyt++ ) { X#ifdef vax X if(*curbyt == 0x0a) X (*nlines)++; X#endif X accsm = (accsm + accsm + accsm) + (*curbyt & 0377); X accsm = (accsm & 07777) + ((accsm >> 12) & 7); X } X X return(accsm); X} SHAR_EOF if test 802 -ne "`wc -c < 'cksblk.c'`" then echo shar: "error transmitting 'cksblk.c'" '(should have been 802 characters)' fi fi echo shar: "extracting 'cksm.c'" '(1422 characters)' if test -f 'cksm.c' then echo shar: "will not over-write existing file 'cksm.c'" else sed 's/^ X//' << \SHAR_EOF > 'cksm.c' X#include <stdio.h> X#ifdef vax X#include <fcntl.h> X#else X#include <osbind.h> X#endif X X#define BUFRSIZ 1024 X#define FD_STDIN 0 X Xchar buff[BUFRSIZ]; X Xmain(argc, argv) /* cksm: Checksum files */ Xint argc; Xchar *argv[]; X X{ X /* Compilation instructions: cc -O cksm.c cksblk.c */ X X int fildes; X X if (argc == 1) { /* no args, so process std. input */ X chksum(FD_STDIN, "standard input"); X } X else { X while (--argc > 0) { X if ((fildes = X#ifdef vax X open(*++argv, O_RDONLY | O_NDELAY)) <= 0) { X#else X Fopen(*++argv, 0)) <= 0) { X#endif X printf("cksm: can't open '%s' error no = %d\n", *argv, fildes); X } X else { X chksum(fildes, *argv); X close(fildes); X } X } X } X printf("Hit return to continue\n"); X scanf("%c",buff); X} X Xchksum(fildes, fname) /* Read file, count bytes, compute checksum. */ Xint fildes; Xchar *fname; X X{ X int csum, nlines; X long bcnt, bgot; X extern char buff[BUFRSIZ]; X extern errno; X X csum = 0; X bcnt = 0; X nlines = 0; X X#ifdef vax X while ((bgot = read(fildes, buff, BUFRSIZ)) > 0) { X#else X while ((bgot = Fread(fildes, (long)BUFRSIZ, buff)) > 0) { X#endif X bcnt += bgot; X csum = cksblk(buff, bgot, csum, &nlines); X } X X if (bgot < 0) { X printf("cksm: error %ld reading from %s\n", bgot, fname); X } X X#ifdef vax X printf("bytes =%9ld(%9ld) cksm =%5d %s\n", bcnt, bcnt+nlines, csum, fname); X#else X printf("bytes =%9ld cksm =%5d %s\n", bcnt, csum, fname); X#endif X} SHAR_EOF if test 1422 -ne "`wc -c < 'cksm.c'`" then echo shar: "error transmitting 'cksm.c'" '(should have been 1422 characters)' fi fi exit 0 # End of shell archive