/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "codecomments.p" */ #include /* codecomments: comment density of a pascal program Dr. Thomas D. Schneider National Cancer Institute Laboratory of Experimental and Computational Biology Frederick, Maryland 21702-1201 toms@ncifcrf.gov permanent email: toms@alum.mit.edu http://www.lecb.ncifcrf.gov/~toms/ modules: delman */ /* begin module version */ #define version 2.10 /* of codecomments.p 2001 June 7 2001 Jun 7, 2.10: lowest percentage is 30 2001 Jun 7, 2.09: output upgrade 2000 Oct 24, 2.07: change name from code.p to codecomments.p use standard input instead of fin 2000 May 26, 2.06: last change 1986 dec 9 last major change as code.p origin before 1982 august 29 */ /* end module version */ /* begin module describe.codecomments */ /* name codecomments: find the comment density of a pascal program synopsis codecomments(input: in, output: out) files input: a pascal source code. output: a report on the comment density of the pascal program. description With the comment density program, you can find out how much of your program is devoted to comments. In general, the better programs will have more comments than those that are poor. The program gives you the percent of characters devoted to comments. A typical value should probably be around 50 percent of the characters devoted to description. Suggested places to put comments are in the delman manual in the module delman.guide.programming. examples Here is the distribution of comments in all Delila programs on 2000 Oct 24: * genhis 1.75: generalized histogram data from * name percent * * parameters: * 6 is the data column used * 314 numbers are in the file * 31.60000 is the minimum number * 91.60000 is the maximum number * 52.11592 is the MEAN * 11.50619 is the STANDARD DEVIATION * 0.65037 is the STANDARD ERROR OF THE MEAN (SEM) * 132.39246 is the variance * 3.41127 is the uncertainty in bits * 5.57143 is the computed uncertainty in bits (Shannon p.57) * * 0.00000 to 100.00000 is the range of data plotted * 4.00000 is the x-axis interval * 26 is the number of intervals * 51 is the maximum y-axis value * 1.00000 is the y-axis scale * * gaussian standard plotted * * interval histogram * beginning value * 0.00000 0 4.00000 0 8.00000 0 12.00000 0 16.00000 0 : 20.00000 0 : 24.00000 0 : 28.00000 1 + : 32.00000 9 +++++++++ : 36.00000 26 ++++++++++++++++++++*+++++ 40.00000 50 +++++++++++++++++++++++++++++*++++++++++++++++++++ 44.00000 51 +++++++++++++++++++++++++++++++++++++*+++++++++++++ 48.00000 41 +++++++++++++++++++++++++++++++++++++++++ : 52.00000 41 +++++++++++++++++++++++++++++++++++++++++ : 56.00000 25 +++++++++++++++++++++++++ : 60.00000 14 ++++++++++++++ : 64.00000 21 ++++++++++++++++++++* 68.00000 15 ++++++++++++*++ 72.00000 10 ++++++*+++ 76.00000 5 ++*++ 80.00000 0 : 84.00000 2 *+ 88.00000 3 +++ 92.00000 0 96.00000 0 100.00000 0 documentation see also {Current list of Delila programs and graph of % comments:} http://www.lecb.ncifcrf.gov/~toms/timelist.html decom.p nocom.p genhis.p http://www.lecb.ncifcrf.gov/~toms/delman1.html author Thomas D. Schneider bugs The program does not keep track of blanks, so one's style with blanks could affect the percentage. The program does not know about comments of the form {} The program does not handle comments inside quotes. */ /* end module describe.codecomments */ /* more const */ #define debugging false /* to write debug output */ main(argc, argv) int argc; Char *argv[]; { long numchar = 0; /* number of characters */ long numcomchar = 0; /* number of characters in comments */ long numcom = 0; /* number of comments */ /* number of lines */ long numline = 0; /* in the input file */ boolean comment = false; /* true when inside a comment */ Char first, second; /* two neighboring characters in input */ double percent; /* the percent of comments in the program by characters */ PASCAL_MAIN(argc, argv); printf(" codecomments %4.2f: comment density of a pascal program\n", version); printf(" Only comments of the form (* ... *) are recorded, \n"); printf(" including comments inside quote marks...\n\n"); /* zooks */ /* initialize */ if (!P_eof(stdin)) { second = getchar(); /* first will be set below */ if (second == '\n') second = ' '; numchar++; } while (!P_eof(stdin)) { if (P_eoln(stdin)) { scanf("%*[^\n]"); getchar(); numline++; second = ' '; /* block fragmented comments from being recorded */ if (debugging) printf("eoln %3ld\n", numline); continue; } /* step forewards */ first = second; second = getchar(); if (second == '\n') second = ' '; numchar++; if (debugging) printf("%c%3ld", second, numchar); switch (comment) { case false: if (first == '(') { if (second == '*') { comment = true; numcom++; numcomchar += 2; /* count comment start */ } } break; case true: numcomchar++; if (first == '*') { if (second == ')') comment = false; } break; } if (debugging) { if (comment) printf("c\n"); else putchar('\n'); } } printf(" number of characters: %ld\n", numchar); printf(" number of lines: %ld\n", numline); if (numchar == 0) exit(EXIT_SUCCESS); printf(" number of comment characters: %ld\n", numcomchar); printf(" number of comments: %ld\n", numcom); percent = 100 * ((double)numcomchar / numchar); printf(" percent comments by characters: %3.1f\n", percent); if (percent < 30) printf(" The program needs more comments!\n"); else putchar('\n'); exit(EXIT_SUCCESS); } /* End. */