Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!nbires!hao!husc6!bloom-beacon!oberon!cit-vax!ucla-cs!zen!ucbvax!CC.UTAH.EDU!BOB%HOWARD From: BOB%HOWARD@CC.UTAH.EDU Newsgroups: comp.os.vms Subject: checksum/verify program (4 of 4) Message-ID: <8709131312.AA06966@ucbvax.Berkeley.EDU> Date: Sun, 13-Sep-87 06:38:00 EDT Article-I.D.: ucbvax.8709131312.AA06966 Posted: Sun Sep 13 06:38:00 1987 Date-Received: Sun, 13-Sep-87 21:38:31 EDT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The ARPA Internet Lines: 303 $Part4: $ File_is="TYPEDEFS.H" $ Check_Sum_is=958757556 $ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY X/* X typedefs.h - type definitions X*/ X V#ifndef TYPEDEFS /* if we h Xave not included typdefs then do it */ V#define TYPEDEFS /* define XTYPEDEFS to indicate they are defined */ X Xtypedef unsigned int u_int; Xtypedef int s_int; Xtypedef unsigned char u_byte; Xtypedef char s_byte; Xtypedef unsigned short u_word; Xtypedef short s_word; Xtypedef unsigned long u_long; Xtypedef long s_long; Xtypedef float s_real; Xtypedef double d_real; X X#endif $ GoSub Convert_File $ File_is="VERIFY.C" $ Check_Sum_is=436419089 $ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY X/* XCHECKSUM / VERIFY X X Computes a checksum for a file or files. These checksums are often used X with the VERIFY command to verify that files have not been changed since X the checksum was performed. X X Format: X X CHECKSUM [filespec1] [filespec2] X VERIFY [filespec2] [filespec3] X X Filespec1 determins which files are to be checksummed. Wildcards and full X pathnames are allowed. If the filespec is not given on the command line X you will be prompted for it. This filespec is required. X X Filespec2 specifies the name of an optional output file for the checksums X or required input file for the VERIFY command. No wildcards are allowed. X If the filespec is not given on the command line you will be prompted for it. X The CHECKSUM command will send its output to stdio if you press return at X this prompt. X X Filespec3 specifies an optional output file for the VERIFY command. If X the filespec is not given on the command line you will be prompted for it. X The VERIFY command will send its output to stdio if you press return at X this prompt. X X X Example: X X CHECKSUM *.* FOO.CKS X VERIFY FOO.CKS X X The example above checksums all files in the current directory and writes X the results to FOO.CKS. These checksums are then verified against the X current files by using the VERIFY command which writes its verifications X to stdio. X X If you want to verify files against those in another directory you X must edit the pathnames in the checksum file (FOO.CKS in the example.) X X Note: X X Directories and multiple versions of files are not checksummed. X X*/ X X#include X#include X#include X#include "typedefs.h" X X#define out_of_chars -1 X#define max_spec_chars 80 X Xstatic struct dsc$descriptor_s search_file; Xstatic struct dsc$descriptor_s result_file; Xstatic u_long context; Xstatic u_byte search_filename[max_spec_chars]; Xstatic u_byte result_filename[max_spec_chars]; X Xu_byte filespec[max_spec_chars]; Xu_byte infile[max_spec_chars]; /* FILENAME OF FILES TO VERIFY */ Xu_byte outfile[max_spec_chars]; /* FILENAME TO WRITE CHECKSUMS TO */ X Xs_long old_checksum; X XFILE *fp, *in_fp, *out_fp; X X X/**********************************************************************/ X/* */ X/* GET_FILESPEC */ X/* */ X/**********************************************************************/ X Xs_word get_filespec() X{ X register s_word i; X u_byte buff; X X /* READ FILE SPECIFICATION BY READING TO THE FIRST SPACE IN THE LINE. */ X /* THEN SCAN BACKWARDS THROUGH THE CHARS AND REPLACE DOTS WITH NULLS */ X X for( i=0; i 3 ) { X fprintf(stderr,"To many command line arguments.\n"); X goto bail_out; X } X X if( argc > 1) { /* GET INPUT FILE IF ON COMMAND LINE */ X files_on_com_line = TRUE; X strcpy(&infile, argv[1]); X } X X if( argc == 3) { /* GET OUTPUT FILE IF ON COMMAND LINE */ X write_to_file = TRUE; X strcpy(&outfile, argv[2]); X } X X Xif( !files_on_com_line ) { /* GET FROM USER IF NOT ON COMMAND LINE */ X X while ( infile[0] == '\0' ) { X printf("File : "); X gets (infile); X } X printf("Output file : "); X gets (outfile); X printf("\n\n"); X} X X /* OPEN THE INPUT FILE */ X X if ( (in_fp = fopen(infile, "r")) == NULL) { X fprintf(stderr,"Can't open %s\n",infile); X goto bail_out; X } X X X /* IF AN OUTPUT FILE WAS SPECIFIED THEN SET A FLAG AND OPEN THE FILE */ X X if (outfile[0] != '\0') { X write_to_file = TRUE; X if ( (out_fp = fopen(outfile, "w")) == NULL) { X fprintf(stderr,"Can't open %s\n",outfile); X goto bail_out; X } X } X X X /* FOR EACH FILE, IF YOU CAN OPEN IT THEN CHECKSUM IT ELSE SET missing */ X /* TO TRUE. */ X X while ( get_filespec() != out_of_chars ) { X X missing = FALSE; X if ( (fp = fopen(filespec, "r")) != NULL) { X sum = 1; X while ( !feof(fp)){ /* WHILE NOT EOF */ X sum += (unsigned) fgetc(fp); /* READ A CHARACTER */ X if (sum & 0X8000) { /* ROTATE IF HIGH BIT SET */ X sum <<= 1; X sum++; X } X else X sum <<= 1; /* ELSE JUST SHIFT */ X } X fclose(fp); X } X else missing = TRUE; X X X /* IF OUTPUT IS TO A FILE... */ X X if (write_to_file) { X fprintf(out_fp,"%s",filespec); X dots = 70 - strlen(filespec); X if (dots > 0) for(i=1; i 0) for(i=1; i