v20i017: Tools for generating software metrics, Part10/14
Rich Salz
rsalz at uunet.uu.net
Wed Sep 20 04:47:05 AEST 1989
Submitted-by: Brian Renaud <huron.ann-arbor.mi.us!bdr>
Posting-number: Volume 20, Issue 17
Archive-name: metrics/part10
---- Cut Here and unpack ----
#!/bin/sh
# this is part 10 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file src/mccabe/mccabe.sh continued
#
CurArch=10
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
exit 1; fi
( read Scheck
if test "$Scheck" != $CurArch
then echo "Please unpack part $Scheck next!"
exit 1;
else exit 0; fi
) < s2_seq_.tmp || exit 1
echo "x - Continuing file src/mccabe/mccabe.sh"
sed 's/^X//' << 'SHAR_EOF' >> src/mccabe/mccabe.sh
X File, nofunc, complexity[nofunc], returns[nofunc]);
X else
X printf("%s\t%s\t%d\t%d\n",\
X File, nofunc, complexity[nofunc], returns[nofunc]);
X }
X }
X '
Xdone
Xexit 0
SHAR_EOF
echo "File src/mccabe/mccabe.sh is complete"
chmod 0644 src/mccabe/mccabe.sh || echo "restore of src/mccabe/mccabe.sh fails"
echo "x - extracting src/mccabe/test.result (Text)"
sed 's/^X//' << 'SHAR_EOF' > src/mccabe/test.result
XFile Name Complexity No. of returns
X-------------- --------------- ---------- --------------
Xtest1.c Malloc 2 2
Xtest1.c lockedtoday 5 1
Xtest1.c main 9 3
Xtest1.c touch 18 1
Xtest2.y mbcheck 7 0
Xtest2.y *** 17 0
Xtest2.y savetype 1 0
Xtest2.y savename 1 0
Xtest3.c Malloc 2 2
Xtest3.c data_filter 2 0
Xtest3.c firstdd 1 1
Xtest3.c build_outlist 13 2
Xtest3.c loaddd 8 1
Xtest3.c finddd 3 1
Xtest3.c main 3 3
Xtest3.c argcheck 13 1
Xtest3.c newfd 1 1
Xtest3.c buildcmd 4 1
Xtest3.c nextdd 2 1
SHAR_EOF
chmod 0644 src/mccabe/test.result || echo "restore of src/mccabe/test.result fails"
echo "x - extracting src/parse.sccs/parse.prs (Text)"
sed 's/^X//' << 'SHAR_EOF' > src/parse.sccs/parse.prs
X: parse output from sccs prs command
X
Xfor file in $*
Xdo
X prs ${file} | awk '
X BEGIN {
X True = 1;
X False = 0;
X inMR = False;
X inComment = False;
X first = True;
X delcount = 0;
X # quarter into which month falls
X quarter[01] = 1; quarter[02] = 1; quarter[03] = 1;
X quarter[04] = 2; quarter[05] = 2; quarter[06] = 2;
X quarter[07] = 3; quarter[08] = 3; quarter[09] = 3;
X quarter[10] = 4; quarter[11] = 4; quarter[12] = 4;
X }
X
X $0 == "" { #blank line between entries
X inMR = False;
X inComment = False;
X next;
X }
X
X $0 ~ /^D [0-9][0-9]*\.[0-9][0-9]*/ { # got delta entry
X
X if ( split($8, delchgs, "/") != 3)
X {
X printf("%s: unable to split add/delete/nochange field in sccs\n", "'"$0"'");
X printf(" for entry %s\n", $0);
X next;
X }
X if ( delchgs[1] + 0 != 0 || delchgs[2] + 0 != 0 )
X {
X split($3, date, "/");
X if ( $2 == "1.1" ) # grab original author
X {
X origname = $5 "," date[1] "," quarter[date[2]+0];
X origlines = delchgs[1];
X }
X else
X changect++;
X delcount++;
X delname[delcount] = $5 "," date[1] "," quarter[date[2]+0];
X deladds[delcount] = delchgs[1] - delchgs[2];
X }
X next;
X }
X
X $1 ~ /^MRs:/ {
X inMR = True;
X next;
X }
X
X $1 ~ /^COMMENT/ {
X inComment = True;
X next;
X }
X
X inMR == 1 { # skipping through MR section - maybe use this later
X next;
X }
X
X inComment == 1 { # skipping through comment section
X next;
X }
X
X {
X # a new file, right?
X if ( first )
X first = False;
X else
X # print stats for previous file
X printf("%s\t%d\n", file, changect);
X changect = 0;
X file = $1;
X }
X END {
X lines = 0;
X for ( i = 1; i <= delcount; i++ )
X lines += deladds[i];
X for ( i = 1; i <= delcount; i++)
X {
X if ( deladds[i] < 0 )
X deladds[i] *= -1;
X delpctg[ delname[i] ] += deladds[i] / lines;
X }
X printf("%s\t%d", file, changect);
X printf("\t%s\t%.3f", origname, origlines / lines);
X for (name in delpctg)
X printf("\t%s\t%.3f", name, delpctg[name]);
X printf("\n");
X }
X ' | sed 's/: / /' | sed 's@/s\.@/@'
Xdone
SHAR_EOF
chmod 0644 src/parse.sccs/parse.prs || echo "restore of src/parse.sccs/parse.prs fails"
echo "x - extracting src/testfiles/test1.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > src/testfiles/test1.c
X/* cause program to be run once per day */
X
X/* arguments:
X * argument 1 lock name
X * argument 2..n command to execute
X */
X#ifndef NO_SCCS_ID
Xstatic char *sccsid = "@(#)daylock.c 1.1 (bdr) 11/6/86";
X#endif
X
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <time.h>
X#include <errno.h>
X#include "bdr.h"
X
XBool lockedtoday(); /* lockedtoday returns true if locked today */
XBool touch(); /* returns true if touch succeeded */
Xchar *Cmdname;
X
Xmain( argc, argv )
X int argc;
X char *argv[];
X{
X int result;
X char *Malloc();
X char *usrcmd;
X
X if ( argc < 2 )
X {
X fprintf(stderr,
X "usage: %s <lock-file> <command> [<argument>]\n",
X argv[0]);
X exit(1);
X }
X Cmdname = argv[0];
X
X
X if ( lockedtoday( argv[1] ) )
X result = 1;
X else
X {
X if ( ! touch( argv[1] ) )
X result = 1;
X else
X {
X int cmdsize, argidx;
X
X
X for (argidx = 2; argidx < argc; argidx++)
X cmdsize += strlen( argv[argidx] ) + 1;
X usrcmd = (char *) Malloc( cmdsize );
X
X strcpy(usrcmd, argv[2]);
X for ( argidx = 3; argidx < argc; argidx++)
X {
X strcat(usrcmd, " ");
X strcat(usrcmd, argv[argidx]);
X }
X strcat(usrcmd,'\0');
X
X /* ok, now execute the user's command */
X if ( system( usrcmd ) == 127 )
X {
X perror("");
X exit(1);
X }
X result = 0;
X }
X }
X exit (result);
X}
X
X
XBool
Xlockedtoday( filename )
X char *filename;
X{
X
X /* check to see if the file specified as an argument has been touched
X * (locked) today. If so, return 0, else return 1. If the file
X * cannot be opened, assume it has not been touched, return 1
X */
X long time();
X struct tm *localtime();
X struct stat buf;
X Bool result;
X
X if ( stat(filename, &buf) == 0 )
X {
X /* even though systime and buf.st_mtime are declared
X * differently (thanks a lot berkeley) we are going
X * to compare them, assuming they represent the same
X * quality
X */
X long systime, secs_today;
X struct tm *tptr;
X
X time( &systime );
X tptr = localtime( &systime );
X
X secs_today = tptr->tm_sec + ( tptr->tm_min * 60L ) +
X ( tptr->tm_hour * 3600L );
X
X if ( ( systime - secs_today ) > buf.st_mtime )
X result = False; /* locked before start of day */
X else
X result = True; /* locked after start of day */
X }
X else
X result = False;
X return result;
X}
X
XBool
Xtouch( filename )
X char *filename;
X{
X /* create file if it does not exist, otherwise try to read then
X * write first byte of file
X * returns true if succeeded, false otherwise
X */
X extern int errno;
X
X FILE *fp;
X char buf;
X struct stat statbuf;
X Bool result, succeeded = False;
X
X /* first check to see if file exists */
X if ( stat(filename, &statbuf) != 0 )
X {
X if ( errno == ENOENT )
X {
X if ( (fp = fopen( filename, "w")) != NULL )
X if ( fwrite( &buf, sizeof(buf), 1, fp) != 0 )
X if ( fclose( fp ) != EOF )
X succeeded = True;
X if ( succeeded )
X result = True;
X else
X {
X fprintf(stderr, "%s: %s: ",Cmdname, filename);
X perror("");
X result = False;
X }
X }
X else
X {
X fprintf(stderr, "%s: %s: ",Cmdname, filename);
X perror("");
X result = False;
X }
X }
X else
X {
X if ( (fp = fopen( filename, "r+")) != NULL )
X {
X if ( fread( &buf, sizeof(buf), 1, fp ) != 0)
X if ( fseek( fp, 0L, 0) != -1 )
X if ( fwrite( &buf, sizeof(buf), 1, fp) != 0 )
X if ( fclose( fp ) != EOF )
X succeeded = True;
X
X if ( succeeded )
X result = True;
X else
X {
X fclose(fp);
X result = False;
X }
X }
X else
X {
X fprintf( stderr, "%s: %s: ", Cmdname, filename);
X perror("");
X result = False;
X }
X }
X return result;
X}
X
X
Xchar *
XMalloc( size )
X register int size;
X{
X register char *vast_tracts ;
X char *malloc();
X
X if ( ! ( vast_tracts = malloc( size ) ) )
X {
X fprintf(stderr, "%s: unable to allocate more space\n", Cmdname);
X exit(1);
X }
X return( vast_tracts );
X}
SHAR_EOF
chmod 0644 src/testfiles/test1.c || echo "restore of src/testfiles/test1.c fails"
echo "x - extracting src/testfiles/test2.y (Text)"
sed 's/^X//' << 'SHAR_EOF' > src/testfiles/test2.y
X%{
X/* this file (cdgram.y) borrowed from the excellent ``cdecl'' utility
X * currently maintained by Chris Torek. I should produce code this
X * useful.
X*/
X#include <stdio.h>
X
X#define MB_SHORT 0001
X#define MB_LONG 0002
X#define MB_UNSIGNED 0004
X#define MB_INT 0010
X#define MB_CHAR 0020
X#define MB_FLOAT 0040
X#define MB_DOUBLE 0100
X
Xint modbits = 0;
Xint arbdims = 1;
Xchar *savedtype;
Xchar *savedname;
Xchar *ds(), *cat();
Xchar *index(), *malloc();
Xchar prev;
X%}
X
X%union {
X char *dynstr;
X struct {
X char *left;
X char *right;
X } halves;
X}
X
SHAR_EOF
echo "End of part 10"
echo "File src/testfiles/test2.y is continued in part 11"
echo "11" > s2_seq_.tmp
exit 0
--
Please send comp.sources.unix-related mail to rsalz at uunet.uu.net.
Use a domain-based address or give alternate paths, or you may lose out.
More information about the Comp.sources.unix
mailing list