better print and cc other than main
This commit is contained in:
		
							parent
							
								
									0ac868fb25
								
							
						
					
					
						commit
						b890edbbe6
					
				
							
								
								
									
										1
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								Makefile
									
									
									
									
									
								
							@ -29,6 +29,7 @@ all: $(NAME)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
graph:
 | 
					graph:
 | 
				
			||||||
	$(DOT) graph.dot > out.pdf
 | 
						$(DOT) graph.dot > out.pdf
 | 
				
			||||||
 | 
						$(DOT) CC.dot > cc.pdf
 | 
				
			||||||
 | 
					
 | 
				
			||||||
debug: CFLAGS += -DDEBUG -g
 | 
					debug: CFLAGS += -DDEBUG -g
 | 
				
			||||||
debug: $(NAME)
 | 
					debug: $(NAME)
 | 
				
			||||||
 | 
				
			|||||||
@ -28,7 +28,7 @@ void myfunc3(void)
 | 
				
			|||||||
	free(strings);
 | 
						free(strings);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void myfunc2(void) /* "static" means don't export the symbol... */
 | 
					static void myfunc2(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	myfunc3();
 | 
						myfunc3();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										21
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								src/main.c
									
									
									
									
									
								
							@ -24,26 +24,13 @@ int main(int argc, char *argv[])
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	(void)argc;
 | 
						(void)argc;
 | 
				
			||||||
	(void)argv;
 | 
						(void)argv;
 | 
				
			||||||
	// fix_str m = "main";
 | 
					 | 
				
			||||||
	graph_vec gv = vnew_graph();
 | 
						graph_vec gv = vnew_graph();
 | 
				
			||||||
	graph_mco gmc = mcgragh();
 | 
						graph_mco gmc = mcgragh();
 | 
				
			||||||
	// find_funcs("/home/user/files/dot_files/st/x.c", &gv, &gmc);
 | 
						// find_funcs("/home/user/files/dot_files/st/x.c", &gv, &gmc);
 | 
				
			||||||
	// find_funcs("test.c", &gv, &gmc);
 | 
						find_funcs("test.c", &gv, &gmc);
 | 
				
			||||||
	findAndParse("/home/user/files/dot_files/st/", &gv, &gmc);
 | 
						// findAndParse("/home/user/files/dot_files/st/", &gv, &gmc);
 | 
				
			||||||
	// int n = mcis_in(gmc, m);
 | 
						// vprint_nodes(gv.node[8]);
 | 
				
			||||||
	// printf("%d\n", n);
 | 
						mcprint_edges(gmc, 8);
 | 
				
			||||||
	// mcprint_edges(gmc, n);
 | 
					 | 
				
			||||||
	// for (int i = 0; i <= gmc.nbs; i++) {
 | 
					 | 
				
			||||||
	// 	printf("Node %d: %s\n", i, gmc.func[i]);
 | 
					 | 
				
			||||||
	// 	for (int j = 0; j <= gmc.nba; j++) {
 | 
					 | 
				
			||||||
	// 		if (strcmp(gmc.func[i], gmc.func[gmc.vec[j].i]) == 0) {
 | 
					 | 
				
			||||||
	// 			printf("  Succ %d: %s\n", gmc.vec[j].j, gmc.func[gmc.vec[j].j]);
 | 
					 | 
				
			||||||
	// 		}
 | 
					 | 
				
			||||||
	// 	}
 | 
					 | 
				
			||||||
	// }
 | 
					 | 
				
			||||||
	// printf("TEST: %s %d\n", gmc.func[2], gmc.vec[2].j);
 | 
					 | 
				
			||||||
	//
 | 
					 | 
				
			||||||
	// vprint_nodes(gv.node[0]);
 | 
					 | 
				
			||||||
	vfind_cycles(&gv);
 | 
						vfind_cycles(&gv);
 | 
				
			||||||
	mcdelete_graph(&gmc);
 | 
						mcdelete_graph(&gmc);
 | 
				
			||||||
	vdot_graph(gv, true);
 | 
						vdot_graph(gv, true);
 | 
				
			||||||
 | 
				
			|||||||
@ -37,6 +37,7 @@ void mcinsert_edge(graph_mco *g, int dep, int arr)
 | 
				
			|||||||
		assert(g->vec);
 | 
							assert(g->vec);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	e.i = dep;
 | 
						e.i = dep;
 | 
				
			||||||
 | 
						e.vu = 0;
 | 
				
			||||||
	if (arr == -1)
 | 
						if (arr == -1)
 | 
				
			||||||
		e.j = g->nbs;
 | 
							e.j = g->nbs;
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
@ -76,6 +77,9 @@ static void mcprint_succ(graph_mco g, int succ)
 | 
				
			|||||||
void mcprint_edges(graph_mco g, int n)
 | 
					void mcprint_edges(graph_mco g, int n)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
 | 
						if (g.vec[n].vu)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						g.vec[n].vu = 1;
 | 
				
			||||||
	printf("NODE %d: %s\n", n, g.func[n]);
 | 
						printf("NODE %d: %s\n", n, g.func[n]);
 | 
				
			||||||
	for (i = 0; i <= g.nba; ++i) {
 | 
						for (i = 0; i <= g.nba; ++i) {
 | 
				
			||||||
		if (g.vec[i].i == n) {
 | 
							if (g.vec[i].i == n) {
 | 
				
			||||||
 | 
				
			|||||||
@ -8,6 +8,7 @@ typedef struct graph_mco graph_mco;
 | 
				
			|||||||
struct edge {
 | 
					struct edge {
 | 
				
			||||||
	int i; // noeud de depart
 | 
						int i; // noeud de depart
 | 
				
			||||||
	int j; // noeud d'arrivé
 | 
						int j; // noeud d'arrivé
 | 
				
			||||||
 | 
						int vu;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct graph_mco {
 | 
					struct graph_mco {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										35
									
								
								src/vec.c
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								src/vec.c
									
									
									
									
									
								
							@ -5,6 +5,8 @@
 | 
				
			|||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum { NOT_VISITED = 0, IN_STACK = 1, DONE = 2 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
graph_vec vnew_graph(void)
 | 
					graph_vec vnew_graph(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	graph_vec g;
 | 
						graph_vec g;
 | 
				
			||||||
@ -65,17 +67,13 @@ int vis_in(graph_vec g, fix_str func)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static void vprint_succ(nodept node)
 | 
					static void vprint_succ(nodept node)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	// int i;
 | 
					 | 
				
			||||||
	printf("  Succ: %s\n", node->func);
 | 
						printf("  Succ: %s\n", node->func);
 | 
				
			||||||
	// for (i = 0; i < node->nbs; ++i) {
 | 
					 | 
				
			||||||
	// 	printf("SUCC %d: %s\n", i, node->succ[i]->func);
 | 
					 | 
				
			||||||
	// }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void vprint_nodes(nodept node)
 | 
					void vprint_nodes(nodept node)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
	if (node->vu == 1)
 | 
						if (node->vu)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	node->vu = 1;
 | 
						node->vu = 1;
 | 
				
			||||||
	printf("NODE: %s\n", node->func);
 | 
						printf("NODE: %s\n", node->func);
 | 
				
			||||||
@ -83,11 +81,12 @@ void vprint_nodes(nodept node)
 | 
				
			|||||||
		vprint_succ(node->succ[i]);
 | 
							vprint_succ(node->succ[i]);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for (i = 0; i < node->nbs; ++i) {
 | 
						for (i = 0; i < node->nbs; ++i) {
 | 
				
			||||||
		vprint_nodes(node->succ[i]);
 | 
							if (node->succ[i]->nbs != 0)
 | 
				
			||||||
 | 
								vprint_nodes(node->succ[i]);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void vwrite_node_dot(FILE *fp, graph_vec g)
 | 
					static void vwrite_node_dot(FILE *fp, graph_vec g)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i, j;
 | 
						int i, j;
 | 
				
			||||||
	for (i = 0; i <= g.n; i++) {
 | 
						for (i = 0; i <= g.n; i++) {
 | 
				
			||||||
@ -98,7 +97,7 @@ void vwrite_node_dot(FILE *fp, graph_vec g)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void main_graph(FILE *fp, nodept node)
 | 
					static void main_graph(FILE *fp, nodept node)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
	if (node->vu == 1)
 | 
						if (node->vu == 1)
 | 
				
			||||||
@ -115,11 +114,14 @@ void main_graph(FILE *fp, nodept node)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void vdot_graph(graph_vec g, bool main)
 | 
					void vdot_graph(graph_vec g, bool main)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	FILE *fp;
 | 
						FILE *fp, *fp1;
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fp = fopen("graph.dot", "w");
 | 
						fp = fopen("graph.dot", "w");
 | 
				
			||||||
 | 
						fp1 = fopen("CC.dot", "w");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fprintf(fp, "digraph main {\n");
 | 
						fprintf(fp, "digraph CCmain {\n");
 | 
				
			||||||
 | 
						fprintf(fp1, "digraph CC {\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (main) {
 | 
						if (main) {
 | 
				
			||||||
		fix_str m = "main";
 | 
							fix_str m = "main";
 | 
				
			||||||
@ -130,20 +132,25 @@ void vdot_graph(graph_vec g, bool main)
 | 
				
			|||||||
			fprintf(stderr, "main not found.\n");
 | 
								fprintf(stderr, "main not found.\n");
 | 
				
			||||||
			exit(1);
 | 
								exit(1);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							for (i = 0; i <= g.n; ++i) {
 | 
				
			||||||
 | 
								if (!g.node[i]->vu) {
 | 
				
			||||||
 | 
									main_graph(fp1, g.node[i]);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		vwrite_node_dot(fp, g);
 | 
							vwrite_node_dot(fp, g);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fprintf(fp, "}");
 | 
						fprintf(fp, "}");
 | 
				
			||||||
 | 
						fprintf(fp1, "}");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fclose(fp);
 | 
						fclose(fp);
 | 
				
			||||||
 | 
						fclose(fp1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum { NOT_VISITED = 0, IN_STACK = 1, DONE = 2 };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// NOTE: https://www.baeldung.com/cs/detecting-cycles-in-directed-graph
 | 
					// NOTE: https://www.baeldung.com/cs/detecting-cycles-in-directed-graph
 | 
				
			||||||
void print_cycle(graph_vec g, stack_t s, int v)
 | 
					static void print_cycle(graph_vec g, stack_t s, int v)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	stack_t s2 = init_stack();
 | 
						stack_t s2 = init_stack();
 | 
				
			||||||
	push(&s2, pop(&s));
 | 
						push(&s2, pop(&s));
 | 
				
			||||||
@ -157,7 +164,7 @@ void print_cycle(graph_vec g, stack_t s, int v)
 | 
				
			|||||||
	free_stack(&s2);
 | 
						free_stack(&s2);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void processDFS(nodept n, stack_t *s, graph_vec g)
 | 
					static void processDFS(nodept n, stack_t *s, graph_vec g)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
	for (i = 0; i < n->nbs; ++i) {
 | 
						for (i = 0; i < n->nbs; ++i) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user