rsalz@uunet.uu.net (Rich Salz) (09/20/89)
Submitted-by: Brian Renaud <huron.ann-arbor.mi.us!bdr> Posting-number: Volume 20, Issue 19 Archive-name: metrics/part12 ---- Cut Here and unpack ---- #!/bin/sh # this is part 12 of a multipart archive # do not concatenate these parts, unpack them in order with /bin/sh # file src/testfiles/test3.c continued # CurArch=12 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/testfiles/test3.c" sed 's/^X//' << 'SHAR_EOF' >> src/testfiles/test3.c X Bool found = False; X X /* find in data dictionary */ X for ( curr_dd = dd_base; X curr_dd != FDNULL && !found; X curr_dd = curr_dd->fd_next ) X if ( strcmp( curr_dd->fd_name, searchstr ) == 0 ) X { X found = True; X *p_ddrec = curr_dd; X } X return found; X} X X Xstruct fdesc * Xfirstdd( dd_base ) X struct fdesc *dd_base; X{ X extern struct fdesc *dd_current; X X dd_current = dd_base; X return dd_current; X} X Xstruct fdesc * Xnextdd() X{ X extern struct fdesc *dd_current; X X if ( dd_current != FDNULL) X dd_current = dd_current->fd_next; X X return dd_current; X} X X Xstruct fdesc * Xnewfd( p_next, name, num ) X struct fdesc **p_next; X char *name; X int num; X{ X *p_next = (struct fdesc *) Malloc( sizeof( struct fdesc ) ); X X (*p_next)->fd_name = Malloc( strlen( name ) ); X X strcpy( (*p_next)->fd_name, name ); X (*p_next)->fd_fldno = num; X (*p_next)->fd_next = FDNULL; X X return *p_next; X} X X Xchar * Xbuildcmd( fl_base, fld_count ) X struct fdesc *fl_base; X int fld_count; X{ X char *cmdbuf; X char numbuf[6]; X struct fdesc *curr_fl; X int idx; X X cmdbuf = Malloc( 15 + ( 4 * fld_count ) ); X strcpy( cmdbuf, "awk '{print" ); X for ( idx = 1, curr_fl = fl_base; X curr_fl != FDNULL; X idx++, curr_fl = curr_fl->fd_next ) X { X X if ( idx == fld_count ) X sprintf(numbuf, " $%d;", curr_fl->fd_fldno ); X else X sprintf(numbuf, " $%d,", curr_fl->fd_fldno ); X strcat( cmdbuf, numbuf ); X } X strcat( cmdbuf, "}'" ); X X return cmdbuf; X} X Xvoid Xdata_filter( fl_base, fld_count ) X struct fdesc *fl_base; X int fld_count; X{ X char *systemcmd; X extern char *Cmdname; X X systemcmd = buildcmd( fl_base, fld_count ); X if ( system( systemcmd ) == 127 ) X fprintf( stderr, "%s: couldn't execute: %s\n", X Cmdname, systemcmd); X} X X Xint Xbuild_outlist( p_fl_base, dd_base, ddname, exclude ) X struct fdesc **p_fl_base; X struct fdesc *dd_base; X char *ddname; X Bool exclude; X{ X struct fdesc *curr_fl, *curr_dd, *new_base, *new_fl; X int fld_count = 0; X extern char *Cmdname; X Bool found; X X if ( exclude ) X { X /* need to rebuild arglist with unnamed dictionary fields */ X for ( curr_dd = firstdd( dd_base ); X curr_dd != FDNULL; X curr_dd = nextdd() ) X { X /* if current dd entry not in arglist, put in the X * new output list X */ X for ( curr_fl = *p_fl_base, found = False; X curr_fl != FDNULL & !found; X curr_fl = curr_fl->fd_next ) X if ( strcmp( curr_dd->fd_name, curr_fl->fd_name) == 0 ) X found = True; X if ( !found ) X { X if ( new_base == FDNULL ) X new_fl = newfd( &new_base, X curr_dd->fd_name, curr_dd->fd_fldno); X else X new_fl = newfd( &(new_fl->fd_next), X curr_dd->fd_name, curr_dd->fd_fldno); X fld_count++; X } X } X *p_fl_base = new_base; X } X else X { X /* for each specified field, find it's field number in the dict */ X for ( curr_fl = *p_fl_base; X curr_fl != FDNULL; X curr_fl = curr_fl->fd_next ) X { X if ( !finddd( &curr_dd, dd_base, curr_fl->fd_name ) ) X { X fprintf(stderr, X "%s: field \"%s\" not found in %s\n", X Cmdname, curr_fl->fd_name, ddname ); X exit(1); X } X else X curr_fl->fd_fldno = curr_dd->fd_fldno; X fld_count++; X } X } X X#ifdef DEBUG X for ( curr_fl = *p_fl_base; curr_fl != FDNULL; curr_fl = curr_fl->fd_next ) X { X fprintf(stderr, X "arglist entry: %s\t%d\n", X curr_fl->fd_name, curr_fl->fd_fldno); X } X#endif /* DEBUG */ X X return fld_count; X} X Xchar * XMalloc( size ) X register int size; X{ X register char *vast_tracts ; X char *malloc(); X extern char * Cmdname; 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 echo "File src/testfiles/test3.c is complete" chmod 0644 src/testfiles/test3.c || echo "restore of src/testfiles/test3.c fails" echo "x - extracting src/utils/Makefile (Text)" sed 's/^X//' << 'SHAR_EOF' > src/utils/Makefile X# makefile for utilities used in halstead, mccabe X XBIN=../bin X XLDFLAGS= X XCFLAGS= -O X XPROGS= stripcom stripstr X Xall: $(PROGS) X Xstripcom: stripcom.o argfiles.o X $(CC) $(LDFLAGS) stripcom.o argfiles.o -o stripcom X Xstripstr: stripstr.o X $(CC) $(LDFLAGS) stripstr.o -o stripstr X Xstripcom.o argfiles.o: argfiles.h X Xstripcom.o: bdr.h X X Xinstall: all X mv stripcom $(BIN)/stripcom X chmod 755 $(BIN)/stripcom X X mv stripstr $(BIN)/stripstr X chmod 755 $(BIN)/stripstr X Xclean: X -rm -f $(PROGS) core *.o SHAR_EOF chmod 0644 src/utils/Makefile || echo "restore of src/utils/Makefile fails" echo "x - extracting src/utils/argfiles.c (Text)" sed 's/^X//' << 'SHAR_EOF' > src/utils/argfiles.c X/* strip comments from c program */ X/* read from stdin, write to stdout */ X#include <stdio.h> X#include "argfiles.h" X XFILE *nextfp(); Xint filetype(); X XFILE * Xnextfp( argc, argv, p_filetype) X int argc; X char *argv[]; X int *p_filetype; X{ X /* looks through parameters trying to return next FILE * to next X * specified file X * passes back the filetype as a side effect X */ X X static Bool first = True; X static int index = 1; X static FILE *result = FNULL; X int curr_index, temp_type; X X temp_type = SYSERR; /* default to ensure no accidental execution */ X X if ( result != FNULL ) X { X fclose( result ); X result = FNULL; X } X /* skip over any flags to this routine */ X while ( index < argc && *argv[index] == '-' ) X index++; X X if ( index < argc ) X { X if ( (result = fopen( argv[index], "r")) == NULL ) X { X fprintf(stderr, "%s: unable to open %s for read\n", X argv[0], argv[index]); X exit(1); X } X curr_index = index++; X } X if ( first ) X { X /* if no files specified, read from stdin */ X if ( result == FNULL ) X result = stdin; X first = False; X } X if ( result != FNULL ) X { X if ( result == stdin ) X temp_type = STDINP; X else X temp_type = filetype( argv[curr_index] ); X } X *p_filetype = temp_type; X return ( result ); X} X Xint Xfiletype( filename ) X char *filename; X{ X int type; X register int len; X register char *suffix; X X if ( !filename ) X type = SYSERR; X else X { X /* find where the suffix starts */ X len = strlen(filename); X suffix = filename + len - 1; /* end of string */ X while ( *suffix != '.' && suffix != filename ) X suffix--; X X if ( suffix == filename ) X { X if ( *filename == 'M' || *filename == 'm' ) X { X if (strncmp(filename+1,"akefile",7)==0) X type = MAKEFILE; X else X type = OTHER; X } X } X else X { X /* if suffix is one char long, optimize by doing X * switch on char, otherwise, have to do strcmp X */ X if ( strlen(++suffix) == 1 ) X { X switch ( *suffix ) X { X case 'c': /* a C file */ X type = C; X break; X case 'h': /* a header file */ X type = HEADER; X break; X case 'y': /* a yacc file */ X type = YACC; X break; X case 'p': /* a pascal file */ X type = PASCAL; X break; X case 's': /* an assembly file */ X type = ASSEMBLY; X break; X case 'm': /* a Visual/Menu file */ X type = VMENU; X break; X default: X type = OTHER; X break; X } X } X else X { X if ( strcmp(suffix, "sh") == 0 ) X type = SHELL; X else if (strcmp(suffix, "cob") == 0) X type = COBOL; X else if (strcmp(suffix, "awk") == 0) X type = AWK; X else X type = OTHER; X } X } X } X return type; X} SHAR_EOF chmod 0644 src/utils/argfiles.c || echo "restore of src/utils/argfiles.c fails" echo "x - extracting src/utils/argfiles.h (Text)" sed 's/^X//' << 'SHAR_EOF' > src/utils/argfiles.h X/* header file for programs using argfiles.o (nextfp) */ X#include "bdr.h" X X/* file types */ X#define SYSERR -1 X#define OTHER 0 X#define C 1 X#define PASCAL 2 X#define SHELL 3 X#define STDINP 4 X#define HEADER 5 X#define YACC 6 X#define ASSEMBLY 7 X#define AWK 8 X#define VMENU 9 X#define COBOL 10 X#define MAKEFILE 11 SHAR_EOF chmod 0644 src/utils/argfiles.h || echo "restore of src/utils/argfiles.h fails" echo "x - extracting src/utils/bdr.h (Text)" sed 's/^X//' << 'SHAR_EOF' > src/utils/bdr.h X#ifndef BDR_H X#define BDR_H X Xtypedef char Bool; X#define True 1 X#define False 0 X Xtypedef char Status; X#define Error 0 X#define Ok 1 X Xtypedef char FileIO; /* also uses Error and Ok */ X#define End_File 2 X X/* xxNULL retained for compatibility until some reasonable percentage of X * code is changed, but xx_NIL is now preferred usage for 'null' pointer X*/ X#define CNULL ( (char *) 0) X#define C_NIL ( (char *) 0) X X#define FNULL ( (FILE *) 0) X#define F_NIL ( (FILE *) 0) X X#define CNTRL(X) ('X' - 64) X#define Odd(X) (X & 1) X X/* Global means used througout system, SHAR_EOF echo "End of part 12" echo "File src/utils/bdr.h is continued in part 13" echo "13" > s2_seq_.tmp exit 0 -- Please send comp.sources.unix-related mail to rsalz@uunet.uu.net. Use a domain-based address or give alternate paths, or you may lose out.