// code-analyzer creates graph from a C source code. // Copyright © 2021 Volodymyr Patuta // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . #include "cmdline.h" #include "colors.h" #include "cparse.h" #include "matcom.h" #include "vec.h" #include #include #include int main(int argc, char *argv[]) { struct gengetopt_args_info ai; char *path; graph_vec gv; graph_mco gmc; int i, n; if (cmdline_parser(argc, argv, &ai) != 0) { exit(1); } if (ai.path_given && ai.file_given) { fprintf(stderr, "Cannot use -p and -f together.\n"); exit(2); } if (!ai.path_given && !ai.file_given) { fprintf(stderr, "You have to give a -p or -f option.\n"); exit(2); } gv = vnew_graph(); gmc = mcgragh(); if (ai.path_given) { path = ai.path_arg; findAndParse(path, &gv, &gmc); } if (ai.file_given) { path = ai.file_arg; find_funcs(path, &gv, &gmc); } if (ai.print_vec_flag) { n = 0; puts("Printing with vector:\n"); for (i = 0; i <= gv.n; ++i) { if (!gv.node[i]->call) { if (ai.color_flag) printf(GREEN "CC %d:\n" RESET_COLOR, n++); else printf("CC %d:\n", n++); vprint(gv.node[i], &gv, ai.color_flag); puts(""); } } } if (ai.print_mc_flag) { n = 0; puts("Printing with compact matrice:"); for (i = 0; i <= gmc.nbs; ++i) { if (!gmc.call[i]) { if (ai.color_flag) printf(GREEN "CC %d:\n" RESET_COLOR, n++); else printf("CC %d:\n", n++); mcprint(gmc, i, ai.color_flag); puts(""); } } } if (ai.cycles_mc_flag) mcfind_cycles(&gmc); if (ai.cycles_vec_flag) vfind_cycles(&gv); vdot_graph(gv, ai.main_graph_flag); mcdot_graph(&gmc, ai.main_graph_flag); mcdelete_graph(&gmc); vdelete_graph(&gv); cmdline_parser_free(&ai); return 0; }