v20i012: Tools for generating software metrics, Part05/14
Rich Salz
rsalz at uunet.uu.net
Wed Sep 20 04:45:44 AEST 1989
Submitted-by: Brian Renaud <huron.ann-arbor.mi.us!bdr>
Posting-number: Volume 20, Issue 12
Archive-name: metrics/part05
---- Cut Here and unpack ----
#!/bin/sh
# this is part 5 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file src/control/proj_stats continued
#
CurArch=5
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/control/proj_stats"
sed 's/^X//' << 'SHAR_EOF' >> src/control/proj_stats
X# -files <filename> - <filename> is name of a file containing a line
X# for every directory of code to be analyzed. Each
X# line is of the form:
X#
X# dirname filelist sccsdir sccsfiles
X#
X# dirname is the name of a directory containing code
X# filelist is a pattern which describes source code
X# sccsdir is where this source is sccs'ed
X# sccsfiles is a pattern which describes the sccs
X# files
X#
X# an example line from <filename> is:
X# /usr/pascal/src/compiler *.[cy] /usr/pascal/sccs/compiler s.*.[cy]
X
Xsourcebase=`pwd`
Xgottarget=0
Xgotfiles=0
X
Xwhile [ $# -gt 0 ]
Xdo
X case $1 in
X -sourcebase)
X sourcebase=$2
X shift ;;
X -target)
X gottarget=1
X target=$2
X shift ;;
X -files)
X gotfiles=1
X filespec=$2
X shift ;;
X *)
X echo "usage: $0 -target <directory> -files <filename> [-sourcebase <directory>]"
X exit 1
X esac
X shift
Xdone
X
Xbase=`pwd`
Xcd $sourcebase
X
X# where we find the directories and file specs
Xif [ $gotfiles -ne 1 ]
Xthen
X echo "usage: $0 -target <directory> -files <filename> [-sourcebase <directory>]"
X exit 1
Xfi
Xthen
X
X
X# temporary log for statistics for each directory
Xroutine=$base/@routine_defs
Xfile=$base/@file_defs
X
X# empty out the target statistics fiels
X>$target/@file_defs
X>$target/@routine_defs
X
Xexec < $filespec
X
Xwhile read dirname filelist sccsdir sccsfiles
Xdo
X echo gathering stats in $dirname file types "$filelist"
X gather_stats -file $file -routine $routine \
X -source $dirname "$filelist" -sccs $sccsdir "$sccsfiles"
X if [ $? != 0 ]
X then
X echo "unable to gather statistics on the $dirname directory"
X exit 1
X fi
X sed "s@^@$dirname/@" < $file >> $target/@file_defs
X sed "s@^@$dirname/@" < $routine >> $target/@routine_defs
Xdone
SHAR_EOF
echo "File src/control/proj_stats is complete"
chmod 0754 src/control/proj_stats || echo "restore of src/control/proj_stats fails"
echo "x - extracting src/halstead/Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > src/halstead/Makefile
X# makefile for halstead utilities
X
XBIN=../bin
XTEST=../testfiles
X
X#LDFLAGS= -i -s
XLDFLAGS=
X
XCFLAGS= -O
X
XPROGS= halstead c_halsfilt
X
Xall: $(PROGS)
X
X
Xhalstead: halstead.sh
X cp halstead.sh halstead
X chmod u+x halstead
X
X# if you have lex problems, "cp c_halsfilt_c c_halsfilt.c"
Xc_halsfilt: c_halsfilt.l
X $(LEX) c_halsfilt.l
X mv lex.yy.c c_halsfilt.c
X $(CC) $(LDFLAGS) c_halsfilt.c -o c_halsfilt -ll
X
X
Xinstall: all
X mv halstead $(BIN)/halstead
X chmod 755 $(BIN)/halstead
X
X mv c_halsfilt $(BIN)/c_halsfilt
X chmod 755 $(BIN)/c_halsfilt
X
Xclean:
X -rm -f $(PROGS) core *.o c_halsfilt.c _test
X
Xtest:
X @echo results of this command should be the same as test.result
X @echo see halstead/README for systems with known differences
X @cp $(TEST)/test1.c $(TEST)/test2.y $(TEST)/test3.c .
X halstead test1.c test2.y test3.c > _test
X diff _test test.result
X @/bin/rm -f test1.c test2.y test3.c
SHAR_EOF
chmod 0644 src/halstead/Makefile || echo "restore of src/halstead/Makefile fails"
echo "x - extracting src/halstead/c_halsfilt.l (Text)"
sed 's/^X//' << 'SHAR_EOF' > src/halstead/c_halsfilt.l
X/* this lex routine breaks up C programs into operators and operands */
X/* operands go to stdout, operators go to stderr */
X/* distinction is based on my reading of various articles and K&R */
X/* this routine expects comments and strings to be stripped before */
X%%
X(\'.\'|\'\\.\'|\'\\[0-9]+\') {
X /* character constants go to operand output */
X printf(" %s ", yytext);
X }
X
X(\-\>|\+\+|\-\-|\<\<|\>\>|\<\=|\>\=|\=\=|\!\=|\&\&|\|\||[+*/%\-]\=) {
X /* print 2 character symbols to operator output */
X fprintf(stderr,"%s\n", yytext);
X putchar(' ');
X }
X
X[\.\(\)\[\]\!\~\&\+\/\%\<\>\&\^\|\?\=\,\-] {
X /* print most 1 char symbols to operator output */
X fprintf(stderr,"%s\n", yytext);
X putchar(' ');
X }
X
X\*/[^ \t\n0-9] {
X /* print indirection operator to operator output */
X fprintf(stderr,"*indirection\n");
X putchar(' ');
X }
X
X\* {
X /* multiplication operator */
X fprintf(stderr,"%s\n", yytext);
X putchar(' ');
X }
X
X[\:\;\{\}] {
X /* delete delimiters */
X /* NOTE - prints to stdout, unlike above */
X putchar(' ');
X }
X
Xsizeof/([ \t\(]|$) {
X /* sizeof operator to operator output */
X fprintf(stderr, "sizeof\n" );
X putchar(' ');
X }
X
X^#[a-z]+/[ \t\n] {
X /* preprocessor operators to operator output */
X fprintf(stderr, "%s\n", yytext);
X putchar(' ');
X }
X
X(if|else|while|do|for|switch|case|default|break|continue|return|goto|case)/[:; \t\(\n] {
X /* statements */
X fprintf(stderr, "%s\n", yytext);
X putchar(' ');
X }
X
X(auto|static|extern|register|typedef)/[ \t\(\n] {
X /* storage class specifiers */
X fprintf(stderr, "%s\n", yytext);
X putchar(' ');
X }
X
X(char|short|int|long|unsigned|float|double)/[ \t\(\)\n] {
X /* type specifier */
X fprintf(stderr, "%s\n", yytext);
X putchar(' ');
X }
X
X(struct|union)/[ \t\(\n] {
X /* struct or union specifier */
X fprintf(stderr, "%s\n", yytext);
X putchar(' ');
X }
X
X[a-zA-Z_][a-zA-Z0-9_]* {
X /* catch operand names */
X printf(" %s ", yytext);
X }
X
X. ECHO;
X%%
SHAR_EOF
chmod 0644 src/halstead/c_halsfilt.l || echo "restore of src/halstead/c_halsfilt.l fails"
echo "x - extracting src/halstead/c_halsfilt_c (Text)"
sed 's/^X//' << 'SHAR_EOF' > src/halstead/c_halsfilt_c
X# include "stdio.h"
X# define U(x) x
X# define NLSTATE yyprevious=YYNEWLINE
X# define BEGIN yybgin = yysvec + 1 +
X# define INITIAL 0
X# define YYLERR yysvec
X# define YYSTATE (yyestate-yysvec-1)
X# define YYOPTIM 1
X# define YYLMAX 200
X# define output(c) putc(c,yyout)
X# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
X# define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
X# define yymore() (yymorfg=1)
X# define ECHO fprintf(yyout, "%s",yytext)
X# define REJECT { nstr = yyreject(); goto yyfussy;}
Xint yyleng; extern char yytext[];
Xint yymorfg;
Xextern char *yysptr, yysbuf[];
Xint yytchar;
XFILE *yyin ={stdin}, *yyout ={stdout};
Xextern int yylineno;
Xstruct yysvf {
X struct yywork *yystoff;
X struct yysvf *yyother;
X int *yystops;};
Xstruct yysvf *yyestate;
Xextern struct yysvf yysvec[], *yybgin;
X# define YYNEWLINE 10
Xyylex(){
Xint nstr; extern int yyprevious;
Xwhile((nstr = yylook()) >= 0)
Xyyfussy: switch(nstr){
Xcase 0:
Xif(yywrap()) return(0); break;
Xcase 1:
X{
X /* character constants go to operand output */
X printf(" %s ", yytext);
X }
Xbreak;
Xcase 2:
X{
X /* print 2 character symbols to operator output */
X fprintf(stderr,"%s\n", yytext);
X putchar(' ');
X }
Xbreak;
Xcase 3:
X{
X /* print most 1 char symbols to operator output */
X fprintf(stderr,"%s\n", yytext);
X putchar(' ');
X }
Xbreak;
Xcase 4:
X {
X /* print indirection operator to operator output */
X fprintf(stderr,"*indirection\n");
X putchar(' ');
X }
Xbreak;
Xcase 5:
X {
X /* multiplication operator */
X fprintf(stderr,"%s\n", yytext);
X putchar(' ');
X }
Xbreak;
Xcase 6:
X {
X /* delete delimiters */
X /* NOTE - prints to stdout, unlike above */
X putchar(' ');
X }
Xbreak;
Xcase 7:
X{
X /* sizeof operator to operator output */
X fprintf(stderr, "sizeof\n" );
X putchar(' ');
X }
Xbreak;
Xcase 8:
X{
X /* preprocessor operators to operator output */
X fprintf(stderr, "%s\n", yytext);
X putchar(' ');
X }
Xbreak;
Xcase 9:
X{
X /* statements */
X fprintf(stderr, "%s\n", yytext);
X putchar(' ');
X }
Xbreak;
Xcase 10:
X{
X /* storage class specifiers */
X fprintf(stderr, "%s\n", yytext);
X putchar(' ');
X }
Xbreak;
Xcase 11:
X{
X /* type specifier */
X fprintf(stderr, "%s\n", yytext);
X putchar(' ');
X }
Xbreak;
Xcase 12:
X {
X /* struct or union specifier */
X fprintf(stderr, "%s\n", yytext);
X putchar(' ');
X }
Xbreak;
Xcase 13:
X{
X /* catch operand names */
X printf(" %s ", yytext);
X }
Xbreak;
Xcase 14:
X ECHO;
Xbreak;
Xcase -1:
Xbreak;
Xdefault:
Xfprintf(yyout,"bad switch yylook %d",nstr);
X} return(0); }
X/* end of yylex */
Xint yyvstop[] ={
X0,
X
X14,
X0,
X
X3,
X14,
X0,
X
X3,
X14,
X0,
X
X3,
X14,
X0,
X
X14,
X0,
X
X3,
X14,
X0,
X
X5,
X14,
X-4,
X0,
X
X3,
X14,
X0,
X
X3,
X14,
X0,
X
X6,
X14,
X0,
X
X3,
X14,
X0,
X
X3,
X14,
X0,
X
X3,
X14,
X0,
X
X13,
X14,
X0,
X
X13,
X14,
X0,
SHAR_EOF
echo "End of part 5"
echo "File src/halstead/c_halsfilt_c is continued in part 6"
echo "6" > 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