home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume20 / metrics / part10 < prev    next >
Encoding:
Internet Message Format  |  1989-09-18  |  9.5 KB

  1. Subject:  v20i017:  Tools for generating software metrics, Part10/14
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Brian Renaud <huron.ann-arbor.mi.us!bdr>
  7. Posting-number: Volume 20, Issue 17
  8. Archive-name: metrics/part10
  9.  
  10. ---- Cut Here and unpack ----
  11. #!/bin/sh
  12. # this is part 10 of a multipart archive
  13. # do not concatenate these parts, unpack them in order with /bin/sh
  14. # file src/mccabe/mccabe.sh continued
  15. #
  16. CurArch=10
  17. if test ! -r s2_seq_.tmp
  18. then echo "Please unpack part 1 first!"
  19.      exit 1; fi
  20. ( read Scheck
  21.   if test "$Scheck" != $CurArch
  22.   then echo "Please unpack part $Scheck next!"
  23.        exit 1;
  24.   else exit 0; fi
  25. ) < s2_seq_.tmp || exit 1
  26. echo "x - Continuing file src/mccabe/mccabe.sh"
  27. sed 's/^X//' << 'SHAR_EOF' >> src/mccabe/mccabe.sh
  28. X              File, nofunc, complexity[nofunc], returns[nofunc]);
  29. X        else
  30. X            printf("%s\t%s\t%d\t%d\n",\
  31. X              File, nofunc, complexity[nofunc], returns[nofunc]);
  32. X        }
  33. X    }
  34. X    '
  35. Xdone
  36. Xexit 0
  37. SHAR_EOF
  38. echo "File src/mccabe/mccabe.sh is complete"
  39. chmod 0644 src/mccabe/mccabe.sh || echo "restore of src/mccabe/mccabe.sh fails"
  40. echo "x - extracting src/mccabe/test.result (Text)"
  41. sed 's/^X//' << 'SHAR_EOF' > src/mccabe/test.result
  42. XFile              Name               Complexity    No. of returns
  43. X--------------    ---------------    ----------    --------------
  44. Xtest1.c           Malloc                      2             2
  45. Xtest1.c           lockedtoday                 5             1
  46. Xtest1.c           main                        9             3
  47. Xtest1.c           touch                      18             1
  48. Xtest2.y           mbcheck                     7             0
  49. Xtest2.y           ***                        17             0
  50. Xtest2.y           savetype                    1             0
  51. Xtest2.y           savename                    1             0
  52. Xtest3.c           Malloc                      2             2
  53. Xtest3.c           data_filter                 2             0
  54. Xtest3.c           firstdd                     1             1
  55. Xtest3.c           build_outlist              13             2
  56. Xtest3.c           loaddd                      8             1
  57. Xtest3.c           finddd                      3             1
  58. Xtest3.c           main                        3             3
  59. Xtest3.c           argcheck                   13             1
  60. Xtest3.c           newfd                       1             1
  61. Xtest3.c           buildcmd                    4             1
  62. Xtest3.c           nextdd                      2             1
  63. SHAR_EOF
  64. chmod 0644 src/mccabe/test.result || echo "restore of src/mccabe/test.result fails"
  65. echo "x - extracting src/parse.sccs/parse.prs (Text)"
  66. sed 's/^X//' << 'SHAR_EOF' > src/parse.sccs/parse.prs
  67. X: parse output from sccs prs command
  68. X
  69. Xfor file in $*
  70. Xdo
  71. X    prs ${file} | awk '
  72. X    BEGIN {
  73. X        True = 1;
  74. X        False = 0;
  75. X        inMR = False;
  76. X        inComment = False;
  77. X        first = True;
  78. X        delcount = 0;
  79. X        # quarter into which month falls
  80. X        quarter[01] = 1; quarter[02] = 1; quarter[03] = 1;
  81. X        quarter[04] = 2; quarter[05] = 2; quarter[06] = 2;
  82. X        quarter[07] = 3; quarter[08] = 3; quarter[09] = 3;
  83. X        quarter[10] = 4; quarter[11] = 4; quarter[12] = 4;
  84. X    }
  85. X
  86. X    $0 == "" {    #blank line between entries
  87. X        inMR = False;
  88. X        inComment = False;
  89. X        next;
  90. X    }
  91. X
  92. X    $0 ~ /^D [0-9][0-9]*\.[0-9][0-9]*/ { # got delta entry
  93. X
  94. X        if ( split($8, delchgs, "/") != 3)
  95. X        {
  96. X            printf("%s: unable to split add/delete/nochange field in sccs\n", "'"$0"'");
  97. X            printf("   for entry %s\n", $0);
  98. X            next;
  99. X        }
  100. X        if ( delchgs[1] + 0 != 0 || delchgs[2] + 0 != 0 )
  101. X        {
  102. X            split($3, date, "/");
  103. X            if ( $2 == "1.1" )        # grab original author
  104. X            {
  105. X                origname = $5 "," date[1] "," quarter[date[2]+0];
  106. X                origlines = delchgs[1];
  107. X            }
  108. X            else
  109. X                changect++;
  110. X            delcount++;
  111. X            delname[delcount] = $5 "," date[1] "," quarter[date[2]+0];
  112. X            deladds[delcount] = delchgs[1] - delchgs[2];
  113. X        }
  114. X        next;
  115. X    }
  116. X
  117. X    $1 ~ /^MRs:/ {
  118. X        inMR = True;
  119. X        next;
  120. X    }
  121. X
  122. X    $1 ~ /^COMMENT/ {
  123. X        inComment = True;
  124. X        next;
  125. X    }
  126. X
  127. X    inMR == 1 {    # skipping through MR section - maybe use this later
  128. X        next;
  129. X    }
  130. X
  131. X    inComment == 1 {    # skipping through comment section
  132. X        next;
  133. X    }
  134. X
  135. X    {
  136. X        # a new file, right?
  137. X        if ( first )
  138. X            first = False;
  139. X        else
  140. X            # print stats for previous file
  141. X            printf("%s\t%d\n", file, changect);
  142. X        changect = 0;
  143. X        file = $1;
  144. X    }
  145. X    END {
  146. X        lines = 0;
  147. X        for ( i = 1; i <= delcount; i++ )
  148. X            lines += deladds[i];
  149. X        for ( i = 1; i <= delcount; i++)
  150. X        {
  151. X            if ( deladds[i] < 0 )
  152. X                deladds[i] *= -1;
  153. X            delpctg[ delname[i] ] += deladds[i] / lines;
  154. X        }
  155. X        printf("%s\t%d", file, changect);
  156. X        printf("\t%s\t%.3f", origname, origlines / lines);
  157. X        for (name in delpctg)
  158. X            printf("\t%s\t%.3f", name, delpctg[name]);
  159. X        printf("\n");
  160. X    }
  161. X    ' | sed 's/:    /    /' | sed 's@/s\.@/@'
  162. Xdone
  163. SHAR_EOF
  164. chmod 0644 src/parse.sccs/parse.prs || echo "restore of src/parse.sccs/parse.prs fails"
  165. echo "x - extracting src/testfiles/test1.c (Text)"
  166. sed 's/^X//' << 'SHAR_EOF' > src/testfiles/test1.c
  167. X/* cause program to be run once per day */
  168. X
  169. X/* arguments:
  170. X * argument 1    lock name
  171. X * argument 2..n    command to execute
  172. X */
  173. X#ifndef NO_SCCS_ID
  174. Xstatic char *sccsid = "@(#)daylock.c    1.1 (bdr) 11/6/86";
  175. X#endif
  176. X
  177. X#include <stdio.h>
  178. X#include <sys/types.h>
  179. X#include <sys/stat.h>
  180. X#include <time.h>
  181. X#include <errno.h>
  182. X#include "bdr.h"
  183. X
  184. XBool    lockedtoday();    /* lockedtoday returns true if locked today */
  185. XBool    touch();    /* returns true if touch succeeded */
  186. Xchar    *Cmdname;
  187. X
  188. Xmain( argc, argv )
  189. X    int    argc;
  190. X    char    *argv[];
  191. X{
  192. X    int    result;
  193. X    char    *Malloc();
  194. X    char    *usrcmd;
  195. X
  196. X    if ( argc < 2 )
  197. X    {
  198. X        fprintf(stderr,
  199. X            "usage: %s <lock-file> <command> [<argument>]\n",
  200. X            argv[0]);
  201. X        exit(1);
  202. X    }
  203. X    Cmdname = argv[0];
  204. X
  205. X
  206. X    if ( lockedtoday( argv[1] ) )
  207. X        result = 1;
  208. X    else
  209. X    {
  210. X        if ( ! touch( argv[1] ) )
  211. X            result = 1;
  212. X        else
  213. X        {
  214. X            int    cmdsize, argidx;
  215. X
  216. X        
  217. X            for (argidx = 2; argidx < argc; argidx++)
  218. X                cmdsize += strlen( argv[argidx] ) + 1;
  219. X            usrcmd = (char *) Malloc( cmdsize );
  220. X
  221. X            strcpy(usrcmd, argv[2]);
  222. X            for ( argidx = 3; argidx < argc; argidx++)
  223. X                {
  224. X                strcat(usrcmd, " ");
  225. X                strcat(usrcmd, argv[argidx]);
  226. X                }
  227. X            strcat(usrcmd,'\0');
  228. X
  229. X            /* ok, now execute the user's command */
  230. X            if ( system( usrcmd ) == 127 )
  231. X                {
  232. X                perror("");
  233. X                exit(1);
  234. X                }
  235. X            result = 0;
  236. X        }
  237. X    }
  238. X    exit (result);
  239. X}
  240. X
  241. X
  242. XBool
  243. Xlockedtoday( filename )
  244. X    char    *filename;
  245. X{
  246. X
  247. X    /* check to see if the file specified as an argument has been touched
  248. X     * (locked) today.  If so, return 0, else return 1.  If the file
  249. X     * cannot be opened, assume it has not been touched, return 1
  250. X     */
  251. X    long time();
  252. X    struct tm *localtime();
  253. X    struct stat    buf;
  254. X    Bool    result;
  255. X
  256. X    if ( stat(filename, &buf) == 0 )
  257. X    {
  258. X        /* even though systime and buf.st_mtime are declared
  259. X         * differently (thanks a lot berkeley) we are going
  260. X         * to compare them, assuming they represent the same
  261. X         * quality
  262. X         */
  263. X        long    systime, secs_today;
  264. X        struct tm    *tptr;
  265. X
  266. X        time( &systime );
  267. X        tptr = localtime( &systime );
  268. X
  269. X        secs_today = tptr->tm_sec + ( tptr->tm_min * 60L ) +
  270. X                     ( tptr->tm_hour * 3600L );
  271. X
  272. X        if ( ( systime - secs_today ) > buf.st_mtime )
  273. X            result = False;    /* locked before start of day */
  274. X        else
  275. X            result = True;    /* locked after start of day */
  276. X    }
  277. X    else
  278. X        result = False;
  279. X    return result;
  280. X}
  281. X
  282. XBool
  283. Xtouch( filename )
  284. X    char    *filename;
  285. X{
  286. X    /* create file if it does not exist, otherwise try to read then
  287. X     * write first byte of file
  288. X     * returns true if succeeded, false otherwise
  289. X     */
  290. X    extern int    errno;
  291. X
  292. X    FILE    *fp;
  293. X    char    buf;
  294. X    struct stat    statbuf;
  295. X    Bool    result, succeeded = False;
  296. X
  297. X    /* first check to see if file exists */
  298. X    if ( stat(filename, &statbuf) != 0 )
  299. X    {
  300. X        if ( errno == ENOENT )
  301. X        {
  302. X            if ( (fp = fopen( filename, "w")) != NULL )
  303. X                if ( fwrite( &buf, sizeof(buf), 1, fp) != 0 )
  304. X                    if ( fclose( fp ) != EOF )
  305. X                        succeeded = True;
  306. X            if ( succeeded )
  307. X                result = True;
  308. X            else
  309. X            {
  310. X                fprintf(stderr, "%s: %s: ",Cmdname, filename);
  311. X                perror("");
  312. X                result = False;
  313. X            }
  314. X        }
  315. X        else
  316. X        {
  317. X            fprintf(stderr, "%s: %s: ",Cmdname, filename);
  318. X            perror("");
  319. X            result = False;
  320. X        }
  321. X    }
  322. X    else
  323. X    {
  324. X        if ( (fp = fopen( filename, "r+")) != NULL )
  325. X        {
  326. X            if ( fread( &buf, sizeof(buf), 1, fp ) != 0)
  327. X                if ( fseek( fp, 0L, 0) !=  -1 )
  328. X                    if ( fwrite( &buf, sizeof(buf), 1, fp) != 0 )
  329. X                        if ( fclose( fp ) != EOF )
  330. X                            succeeded = True;
  331. X
  332. X            if ( succeeded )
  333. X                result = True;
  334. X            else
  335. X            {
  336. X                fclose(fp);
  337. X                result = False;
  338. X            }
  339. X        }
  340. X        else
  341. X        {
  342. X            fprintf( stderr, "%s: %s: ", Cmdname, filename);
  343. X            perror("");
  344. X            result = False;
  345. X        }
  346. X    }
  347. X    return result;
  348. X}
  349. X
  350. X
  351. Xchar *
  352. XMalloc( size )
  353. X    register int    size;
  354. X{
  355. X    register char *vast_tracts ;
  356. X    char    *malloc();
  357. X
  358. X    if ( ! ( vast_tracts = malloc( size ) ) )
  359. X    {
  360. X        fprintf(stderr, "%s: unable to allocate more space\n", Cmdname);
  361. X        exit(1);
  362. X    }
  363. X    return( vast_tracts );
  364. X}
  365. SHAR_EOF
  366. chmod 0644 src/testfiles/test1.c || echo "restore of src/testfiles/test1.c fails"
  367. echo "x - extracting src/testfiles/test2.y (Text)"
  368. sed 's/^X//' << 'SHAR_EOF' > src/testfiles/test2.y
  369. X%{
  370. X/* this file (cdgram.y) borrowed from the excellent ``cdecl'' utility
  371. X * currently maintained by Chris Torek.  I should produce code this
  372. X * useful.
  373. X*/
  374. X#include <stdio.h>
  375. X
  376. X#define    MB_SHORT    0001
  377. X#define    MB_LONG        0002
  378. X#define    MB_UNSIGNED    0004
  379. X#define MB_INT        0010
  380. X#define MB_CHAR        0020
  381. X#define MB_FLOAT    0040
  382. X#define MB_DOUBLE    0100
  383. X
  384. Xint modbits = 0;
  385. Xint arbdims = 1;
  386. Xchar *savedtype;
  387. Xchar *savedname;
  388. Xchar *ds(), *cat();
  389. Xchar *index(), *malloc();
  390. Xchar prev;
  391. X%}
  392. X
  393. X%union {
  394. X    char *dynstr;
  395. X    struct {
  396. X        char *left;
  397. X        char *right;
  398. X    } halves;
  399. X}
  400. X
  401. SHAR_EOF
  402. echo "End of part 10"
  403. echo "File src/testfiles/test2.y is continued in part 11"
  404. echo "11" > s2_seq_.tmp
  405. exit 0
  406.  
  407.  
  408.