// Dackral Phillips // COMP 6700 - Software Process // 6/18/2K1 // Assignment 2A // This assignment is an extension of assignment 2A, in that lines of code are counted, however, in this program, // certain other information about the program is also computed, for instance, how many lines of code per proxy, // the number and names of the proxys,and the number of methods per proxy. #include #include #include #include #include int countLines(char* progname); void printFunctions(char* progname); void printInfo(char* progname); int main(int argc, char* argv[]) { char* progname; if (argc == 2) { strcpy(progname, argv[1]); printInfo(progname); } else { cout << endl << "Error: Please type the filename after the program name." << endl; } return 0; } int countLines(char* progname) { int i; int j = 0; int lines = 0; char buffer[1024]; ifstream program(progname, ios::in); while (!(program.eof())) { j = 0; for (i = 0; i < 1024; i++) { buffer[i] = '\0'; } program.getline(buffer, 1024, '\n'); if (buffer[0] != '\0') { while ((buffer[j] == ' ') || (buffer[j] == '\t')) { j++; } if (buffer[j] != '\0') { lines++; } } else { lines++; } } program.close(); return lines; } void printFunctions(char* progname) { int i = 0; int j = 0; int k = 0; int l = 0; int flag = 0; int lines = 0; int linenum = 0; int methods = 0; int level = 0; char buffer1[1024] = ""; char buffer2[1024] = ""; char proxyName[100]; ifstream program(progname, ios::in); while (!(program.eof())) { i = 0; j = 0; k = 0; l = 0; strcpy(buffer2, buffer1); program.getline(buffer1, 1024, '\n'); while ((buffer1[i] == ' ') || (buffer1[i] == '\t')) { i++; } if (buffer1[i] == '{') { flag = 1; level++; if (level == 1) { while ((buffer2[j] == ' ') || (buffer2[j] == '\t')) { j++; } while (buffer2[j] != ' ') { j++; } while (buffer2[j] != '(') { methods = 1; proxyName[k] = buffer2[j]; k++; j++; } proxyName[k] = '\0'; cout << " \t\t" << setw(10) << proxyName << "\t\t\t" << methods; } } while ((buffer1[l] == ' ') ||(buffer1[l] == '\t')) { l++; } if ((buffer1[l] != '\0') && (level > 0)) { lines++; } if (buffer1[i] == '}') { level--; } if ((level == 0) && (flag == 1)) { lines++; linenum = lines; lines = 0; cout << " \t\t " << linenum << endl; flag = 0; } } program.close(); } void printInfo(char* progname) { system("clear"); cout << endl << endl << "Program Name\t\tProxy Name\t\tNumber of Methods\t\tProxy LOC\t\tTotal LOC" << endl << "____________\t\t__________\t\t_________________\t\t_________\t\t_________" << endl << endl; cout << progname << endl; printFunctions(progname); cout << endl <<" \t\t \t\t \t\t \t\t " << countLines(progname) << endl << endl; }