This project was constructed to analyze code files in c/c++ language and resume some informations to the user:
- The number of total lines of the code
- The quantity and percentage of code lines
- The quantity and percentage of comment lines
- The quantity and percentage of doxygen comment lines
- The quantity and percentage of blank lines
This project was made to verify more than one file per run, and it also has the option of verify all c/c++ files of a directory, recursive or not.
The main reason of doing this project is to verify the quality of code of our next projects, searching for decrease the quantity of code lines to do something. It is also important understand the reading process of a compiler, something programmers use a lot, but not always knows exactly how it works.
Theo Henrique da Silva Borges: theo123b@gmail.com
Haniel Lucas Machado: hani.lucas70@gmail.com
- Theo: did the entire state machine and organized the classes to the program work. Also did the treatment of the user inputs.
- Haniel: Did the print of the table, the recursive and the sort function. Also organized the doxygen comments and helped with the user inputs, doing the capture of the program extension and treating error handlings.
Making a good project always has some difficult parts, and sometimes it does not works exactly how the proggrammer has planned. This case don't have limitations on its purpose, but on the development we found some issues that we solved, but it was harder than the rest of the project. In this topic we are listing this difficulties.
The problems were solved, but we are writing here because it was very hard to do. We never organized a project with classes, and this one was a good first experience of OOP (Object-Oriented Programming). Also, the state mechanic was easy to learn, but hard to implement.
Work with states was certainly the worst part of the project, not just because statement is something new, but also because a StateMachine is something with a very difficult logic in this case. Thats because of the way this program works, there are very tiny details that if the programmer do not pay attention, he will make mistakes, like:
#include <iostream>
/**
the function says hello to the world
*/ int main(){ ///Says Hello to the World
std::cout << "//Hello World!";
}Note that the */ determine the end of the doc-comment block, so this line will count as a line of doc-comment line. But also, this line has a code after the */, so it will be also count as a code line. That as such a hard do implement because we dit the function recursively.
To the next projects we intend to make better plans before we start code. We think that this confusion about states was because we didn't planned too much.
That was not so hard comparing to statement, but it was a bit difficult to understand where my input was going. Hopefully, this knowledge will bring us some smoothness in next projects.
This program has no limitations on its purpose.
| Item | Valor máximo | Valor esperado |
|---|---|---|
| Read one or multiple source file | 10 | 10 |
| Read a list of files from a directory | 10 | 10 |
| Read a list of files recursively from a directory | 8 | 8 |
Show help as requested -h |
4 | 4 |
| Treat error situations | 10 | 10 |
| Show correct number of blank lines | 5 | 5 |
| Show correct number of comment lines | 10 | 10 |
| Show correct number of doc comment lines | 10 | 10 |
| Show correct number of code lines | 10 | 10 |
| Show correct number of total lines | 5 | 5 |
| Show the type of source file | 5 | 5 |
| Show percentages as requested | 10 | 10 |
| Show consolidation at the bottom of a table | 5 | 5 |
| Table is formatted as requested | 8 | 8 |
| The project contains at least one struct or classes | 5 | 5 |
| Overall evaluation of the program | 5 | 5 |
To compile this code, we are using g++ compiler. To compile, use this code in root directory of the project:
g++ ./src/main.cpp -o slocTo run the sloc executable created, run this code
./sloc dir file.cppWhere:
- ./sloc: Call the executable created
- dir: The directory you want to analyse the c/c++ files inside
- file: The c/c++ files you want to analyse
Parameters:
-hto show help-sto sort it ascending-Sto sort it descending
The parameters of the sort parameter (-s and -S) are:
fto sort by filenametto sort by filetypecto sort by commentsdto sort by doc commentsbto sort by blank linessto sort by line of codesato sort by all