one pdf, colors/no colors
This commit is contained in:
		
							parent
							
								
									6766b07787
								
							
						
					
					
						commit
						9c66012da8
					
				
							
								
								
									
										9
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								Makefile
									
									
									
									
									
								
							@ -15,8 +15,6 @@ TAR 		= tar
 | 
				
			|||||||
MKDIR 		= mkdir
 | 
					MKDIR 		= mkdir
 | 
				
			||||||
CHMOD 		= chmod
 | 
					CHMOD 		= chmod
 | 
				
			||||||
CP 			= rsync -Rr
 | 
					CP 			= rsync -Rr
 | 
				
			||||||
DOT 		= dot -Tpdf -Grankdir=LR
 | 
					 | 
				
			||||||
# DOT 		= sfdp -Tpdf -Grankdir=LR -Goverlap=scale 
 | 
					 | 
				
			||||||
EXTRAFILES 	= LICENSE README.md
 | 
					EXTRAFILES 	= LICENSE README.md
 | 
				
			||||||
DISTFILES 	= $(SRCDIR) $(TESTDIR) Makefile $(EXTRAFILES)
 | 
					DISTFILES 	= $(SRCDIR) $(TESTDIR) Makefile $(EXTRAFILES)
 | 
				
			||||||
distdir 	= $(AUTHOR)-$(NAME)-$(VERSION)
 | 
					distdir 	= $(AUTHOR)-$(NAME)-$(VERSION)
 | 
				
			||||||
@ -24,10 +22,7 @@ distdir 	= $(AUTHOR)-$(NAME)-$(VERSION)
 | 
				
			|||||||
all: $(NAME)
 | 
					all: $(NAME)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
graph:
 | 
					graph:
 | 
				
			||||||
	$(DOT) vgraph.dot > vgraph.pdf
 | 
						dot -Grankdir=LR -Tps:cairo:cairo graph.dot | ps2pdf - > graph.pdf
 | 
				
			||||||
	$(DOT) vCC.dot > vCC.pdf
 | 
					 | 
				
			||||||
	$(DOT) mcgraph.dot > mcgraph.pdf
 | 
					 | 
				
			||||||
	$(DOT) mcCC.dot > mcCC.pdf
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
debug: CFLAGS += -DDEBUG -g
 | 
					debug: CFLAGS += -DDEBUG -g
 | 
				
			||||||
debug: $(NAME)
 | 
					debug: $(NAME)
 | 
				
			||||||
@ -53,6 +48,6 @@ clean:
 | 
				
			|||||||
	$(RM) $(OBJS)
 | 
						$(RM) $(OBJS)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fclean: clean
 | 
					fclean: clean
 | 
				
			||||||
	$(RM) $(NAME) vgraph.pdf vgraph.dot mcgraph.pdf mcgraph.dot mcCC.dot mcCC.pdf vCC.dot vCC.pdf
 | 
						$(RM) $(NAME) graph.dot graph.pdf
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: all clean fclean re dist distdir debug
 | 
					.PHONY: all clean fclean re dist distdir debug
 | 
				
			||||||
 | 
				
			|||||||
@ -38,6 +38,7 @@ const char *gengetopt_args_info_help[] = {
 | 
				
			|||||||
  "  -V, --version      Print version and exit",
 | 
					  "  -V, --version      Print version and exit",
 | 
				
			||||||
  "  -p, --path=STRING  Path to the source-code directory.",
 | 
					  "  -p, --path=STRING  Path to the source-code directory.",
 | 
				
			||||||
  "  -f, --file=STRING  Path to the .c file.",
 | 
					  "  -f, --file=STRING  Path to the .c file.",
 | 
				
			||||||
 | 
					  "  -c, --color        Colors on print.  (default=off)",
 | 
				
			||||||
  "  -m, --main-graph   Generate main graph separated from other CC.  (default=on)",
 | 
					  "  -m, --main-graph   Generate main graph separated from other CC.  (default=on)",
 | 
				
			||||||
  "      --print-vec    Print vector graph.  (default=off)",
 | 
					  "      --print-vec    Print vector graph.  (default=off)",
 | 
				
			||||||
  "      --print-mc     Print compact matrice graph.  (default=off)",
 | 
					  "      --print-mc     Print compact matrice graph.  (default=off)",
 | 
				
			||||||
@ -71,6 +72,7 @@ void clear_given (struct gengetopt_args_info *args_info)
 | 
				
			|||||||
  args_info->version_given = 0 ;
 | 
					  args_info->version_given = 0 ;
 | 
				
			||||||
  args_info->path_given = 0 ;
 | 
					  args_info->path_given = 0 ;
 | 
				
			||||||
  args_info->file_given = 0 ;
 | 
					  args_info->file_given = 0 ;
 | 
				
			||||||
 | 
					  args_info->color_given = 0 ;
 | 
				
			||||||
  args_info->main_graph_given = 0 ;
 | 
					  args_info->main_graph_given = 0 ;
 | 
				
			||||||
  args_info->print_vec_given = 0 ;
 | 
					  args_info->print_vec_given = 0 ;
 | 
				
			||||||
  args_info->print_mc_given = 0 ;
 | 
					  args_info->print_mc_given = 0 ;
 | 
				
			||||||
@ -86,6 +88,7 @@ void clear_args (struct gengetopt_args_info *args_info)
 | 
				
			|||||||
  args_info->path_orig = NULL;
 | 
					  args_info->path_orig = NULL;
 | 
				
			||||||
  args_info->file_arg = NULL;
 | 
					  args_info->file_arg = NULL;
 | 
				
			||||||
  args_info->file_orig = NULL;
 | 
					  args_info->file_orig = NULL;
 | 
				
			||||||
 | 
					  args_info->color_flag = 0;
 | 
				
			||||||
  args_info->main_graph_flag = 1;
 | 
					  args_info->main_graph_flag = 1;
 | 
				
			||||||
  args_info->print_vec_flag = 0;
 | 
					  args_info->print_vec_flag = 0;
 | 
				
			||||||
  args_info->print_mc_flag = 0;
 | 
					  args_info->print_mc_flag = 0;
 | 
				
			||||||
@ -103,11 +106,12 @@ void init_args_info(struct gengetopt_args_info *args_info)
 | 
				
			|||||||
  args_info->version_help = gengetopt_args_info_help[1] ;
 | 
					  args_info->version_help = gengetopt_args_info_help[1] ;
 | 
				
			||||||
  args_info->path_help = gengetopt_args_info_help[2] ;
 | 
					  args_info->path_help = gengetopt_args_info_help[2] ;
 | 
				
			||||||
  args_info->file_help = gengetopt_args_info_help[3] ;
 | 
					  args_info->file_help = gengetopt_args_info_help[3] ;
 | 
				
			||||||
  args_info->main_graph_help = gengetopt_args_info_help[4] ;
 | 
					  args_info->color_help = gengetopt_args_info_help[4] ;
 | 
				
			||||||
  args_info->print_vec_help = gengetopt_args_info_help[5] ;
 | 
					  args_info->main_graph_help = gengetopt_args_info_help[5] ;
 | 
				
			||||||
  args_info->print_mc_help = gengetopt_args_info_help[6] ;
 | 
					  args_info->print_vec_help = gengetopt_args_info_help[6] ;
 | 
				
			||||||
  args_info->cycles_vec_help = gengetopt_args_info_help[7] ;
 | 
					  args_info->print_mc_help = gengetopt_args_info_help[7] ;
 | 
				
			||||||
  args_info->cycles_mc_help = gengetopt_args_info_help[8] ;
 | 
					  args_info->cycles_vec_help = gengetopt_args_info_help[8] ;
 | 
				
			||||||
 | 
					  args_info->cycles_mc_help = gengetopt_args_info_help[9] ;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -239,6 +243,8 @@ cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
 | 
				
			|||||||
    write_into_file(outfile, "path", args_info->path_orig, 0);
 | 
					    write_into_file(outfile, "path", args_info->path_orig, 0);
 | 
				
			||||||
  if (args_info->file_given)
 | 
					  if (args_info->file_given)
 | 
				
			||||||
    write_into_file(outfile, "file", args_info->file_orig, 0);
 | 
					    write_into_file(outfile, "file", args_info->file_orig, 0);
 | 
				
			||||||
 | 
					  if (args_info->color_given)
 | 
				
			||||||
 | 
					    write_into_file(outfile, "color", 0, 0 );
 | 
				
			||||||
  if (args_info->main_graph_given)
 | 
					  if (args_info->main_graph_given)
 | 
				
			||||||
    write_into_file(outfile, "main-graph", 0, 0 );
 | 
					    write_into_file(outfile, "main-graph", 0, 0 );
 | 
				
			||||||
  if (args_info->print_vec_given)
 | 
					  if (args_info->print_vec_given)
 | 
				
			||||||
@ -500,6 +506,7 @@ cmdline_parser_internal (
 | 
				
			|||||||
        { "version",	0, NULL, 'V' },
 | 
					        { "version",	0, NULL, 'V' },
 | 
				
			||||||
        { "path",	1, NULL, 'p' },
 | 
					        { "path",	1, NULL, 'p' },
 | 
				
			||||||
        { "file",	1, NULL, 'f' },
 | 
					        { "file",	1, NULL, 'f' },
 | 
				
			||||||
 | 
					        { "color",	0, NULL, 'c' },
 | 
				
			||||||
        { "main-graph",	0, NULL, 'm' },
 | 
					        { "main-graph",	0, NULL, 'm' },
 | 
				
			||||||
        { "print-vec",	0, NULL, 0 },
 | 
					        { "print-vec",	0, NULL, 0 },
 | 
				
			||||||
        { "print-mc",	0, NULL, 0 },
 | 
					        { "print-mc",	0, NULL, 0 },
 | 
				
			||||||
@ -508,7 +515,7 @@ cmdline_parser_internal (
 | 
				
			|||||||
        { 0,  0, 0, 0 }
 | 
					        { 0,  0, 0, 0 }
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      c = getopt_long (argc, argv, "hVp:f:m", long_options, &option_index);
 | 
					      c = getopt_long (argc, argv, "hVp:f:cm", long_options, &option_index);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (c == -1) break;	/* Exit from `while (1)' loop.  */
 | 
					      if (c == -1) break;	/* Exit from `while (1)' loop.  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -547,6 +554,16 @@ cmdline_parser_internal (
 | 
				
			|||||||
              additional_error))
 | 
					              additional_error))
 | 
				
			||||||
            goto failure;
 | 
					            goto failure;
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
 | 
					          break;
 | 
				
			||||||
 | 
					        case 'c':	/* Colors on print..  */
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					          if (update_arg((void *)&(args_info->color_flag), 0, &(args_info->color_given),
 | 
				
			||||||
 | 
					              &(local_args_info.color_given), optarg, 0, 0, ARG_FLAG,
 | 
				
			||||||
 | 
					              check_ambiguity, override, 1, 0, "color", 'c',
 | 
				
			||||||
 | 
					              additional_error))
 | 
				
			||||||
 | 
					            goto failure;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
        case 'm':	/* Generate main graph separated from other CC..  */
 | 
					        case 'm':	/* Generate main graph separated from other CC..  */
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
 | 
				
			|||||||
@ -6,6 +6,7 @@ By Volodymyr Patuta <volodymyr.patuta@etud.univ-paris8.fr>"
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
option "path" p "Path to the source-code directory." string optional
 | 
					option "path" p "Path to the source-code directory." string optional
 | 
				
			||||||
option "file" f "Path to the .c file." string optional
 | 
					option "file" f "Path to the .c file." string optional
 | 
				
			||||||
 | 
					option "color" c "Colors on print." flag off
 | 
				
			||||||
option "main-graph" m "Generate main graph separated from other CC." flag on
 | 
					option "main-graph" m "Generate main graph separated from other CC." flag on
 | 
				
			||||||
option "print-vec" - "Print vector graph." flag off
 | 
					option "print-vec" - "Print vector graph." flag off
 | 
				
			||||||
option "print-mc" - "Print compact matrice graph." flag off
 | 
					option "print-mc" - "Print compact matrice graph." flag off
 | 
				
			||||||
 | 
				
			|||||||
@ -45,6 +45,8 @@ struct gengetopt_args_info
 | 
				
			|||||||
  char * file_arg;	/**< @brief Path to the .c file..  */
 | 
					  char * file_arg;	/**< @brief Path to the .c file..  */
 | 
				
			||||||
  char * file_orig;	/**< @brief Path to the .c file. original value given at command line.  */
 | 
					  char * file_orig;	/**< @brief Path to the .c file. original value given at command line.  */
 | 
				
			||||||
  const char *file_help; /**< @brief Path to the .c file. help description.  */
 | 
					  const char *file_help; /**< @brief Path to the .c file. help description.  */
 | 
				
			||||||
 | 
					  int color_flag;	/**< @brief Colors on print. (default=off).  */
 | 
				
			||||||
 | 
					  const char *color_help; /**< @brief Colors on print. help description.  */
 | 
				
			||||||
  int main_graph_flag;	/**< @brief Generate main graph separated from other CC. (default=on).  */
 | 
					  int main_graph_flag;	/**< @brief Generate main graph separated from other CC. (default=on).  */
 | 
				
			||||||
  const char *main_graph_help; /**< @brief Generate main graph separated from other CC. help description.  */
 | 
					  const char *main_graph_help; /**< @brief Generate main graph separated from other CC. help description.  */
 | 
				
			||||||
  int print_vec_flag;	/**< @brief Print vector graph. (default=off).  */
 | 
					  int print_vec_flag;	/**< @brief Print vector graph. (default=off).  */
 | 
				
			||||||
@ -60,6 +62,7 @@ struct gengetopt_args_info
 | 
				
			|||||||
  unsigned int version_given ;	/**< @brief Whether version was given.  */
 | 
					  unsigned int version_given ;	/**< @brief Whether version was given.  */
 | 
				
			||||||
  unsigned int path_given ;	/**< @brief Whether path was given.  */
 | 
					  unsigned int path_given ;	/**< @brief Whether path was given.  */
 | 
				
			||||||
  unsigned int file_given ;	/**< @brief Whether file was given.  */
 | 
					  unsigned int file_given ;	/**< @brief Whether file was given.  */
 | 
				
			||||||
 | 
					  unsigned int color_given ;	/**< @brief Whether color was given.  */
 | 
				
			||||||
  unsigned int main_graph_given ;	/**< @brief Whether main-graph was given.  */
 | 
					  unsigned int main_graph_given ;	/**< @brief Whether main-graph was given.  */
 | 
				
			||||||
  unsigned int print_vec_given ;	/**< @brief Whether print-vec was given.  */
 | 
					  unsigned int print_vec_given ;	/**< @brief Whether print-vec was given.  */
 | 
				
			||||||
  unsigned int print_mc_given ;	/**< @brief Whether print-mc was given.  */
 | 
					  unsigned int print_mc_given ;	/**< @brief Whether print-mc was given.  */
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										14
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/main.c
									
									
									
									
									
								
							@ -60,8 +60,11 @@ int main(int argc, char *argv[])
 | 
				
			|||||||
		puts("Printing with vector:\n");
 | 
							puts("Printing with vector:\n");
 | 
				
			||||||
		for (i = 0; i <= gv.n; ++i) {
 | 
							for (i = 0; i <= gv.n; ++i) {
 | 
				
			||||||
			if (!gv.node[i]->call) {
 | 
								if (!gv.node[i]->call) {
 | 
				
			||||||
				printf(GREEN "CC %d:\n" RESET_COLOR, n++);
 | 
									if (ai.color_flag)
 | 
				
			||||||
				vprint(gv.node[i], &gv);
 | 
										printf(GREEN "CC %d:\n" RESET_COLOR, n++);
 | 
				
			||||||
 | 
									else
 | 
				
			||||||
 | 
										printf("CC %d:\n", n++);
 | 
				
			||||||
 | 
									vprint(gv.node[i], &gv, ai.color_flag);
 | 
				
			||||||
				puts("");
 | 
									puts("");
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -72,8 +75,11 @@ int main(int argc, char *argv[])
 | 
				
			|||||||
		puts("Printing with compact matrice:");
 | 
							puts("Printing with compact matrice:");
 | 
				
			||||||
		for (i = 0; i <= gmc.nbs; ++i) {
 | 
							for (i = 0; i <= gmc.nbs; ++i) {
 | 
				
			||||||
			if (!gmc.call[i]) {
 | 
								if (!gmc.call[i]) {
 | 
				
			||||||
				printf(GREEN "CC %d:\n" RESET_COLOR, n++);
 | 
									if (ai.color_flag)
 | 
				
			||||||
				mcprint(gmc, i);
 | 
										printf(GREEN "CC %d:\n" RESET_COLOR, n++);
 | 
				
			||||||
 | 
									else
 | 
				
			||||||
 | 
										printf("CC %d:\n", n++);
 | 
				
			||||||
 | 
									mcprint(gmc, i, ai.color_flag);
 | 
				
			||||||
				puts("");
 | 
									puts("");
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										41
									
								
								src/matcom.c
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								src/matcom.c
									
									
									
									
									
								
							@ -84,22 +84,28 @@ int mcis_in(graph_mco g, fix_str func)
 | 
				
			|||||||
	return -1;
 | 
						return -1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void mcprint_succ(graph_mco g, int succ)
 | 
					static void mcprint_succ(graph_mco g, int succ, int color)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	printf(YELLOW "  Succ:" RESET_COLOR CYAN " %s"RESET_COLOR"\n" , g.func[succ]);
 | 
						if (color)
 | 
				
			||||||
 | 
							printf(YELLOW "  Succ:" RESET_COLOR CYAN " %s"RESET_COLOR"\n" , g.func[succ]);
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							printf("  Succ: %s\n" , g.func[succ]);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void mcprint_edges(graph_mco g, int n)
 | 
					static void mcprint_edges(graph_mco g, int n, int color)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i, j = 0;
 | 
						int i, j = 0;
 | 
				
			||||||
	if (g.vu[n])
 | 
						if (g.vu[n])
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	g.vu[n] = 1;
 | 
						g.vu[n] = 1;
 | 
				
			||||||
	printf(BLUE "NODE:" RESET_COLOR MAGENTA " %s\n" RESET_COLOR, g.func[n]);
 | 
						if (color)
 | 
				
			||||||
 | 
							printf(BLUE "NODE:" RESET_COLOR MAGENTA " %s\n" RESET_COLOR, g.func[n]);
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							printf("NODE: %s\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) {
 | 
				
			||||||
			j++;
 | 
								j++;
 | 
				
			||||||
			mcprint_succ(g, g.vec[i].j);
 | 
								mcprint_succ(g, g.vec[i].j, color);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// HACK
 | 
						// HACK
 | 
				
			||||||
@ -111,18 +117,18 @@ static void mcprint_edges(graph_mco g, int 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) {
 | 
				
			||||||
			if (g.vec[g.vec[i].j].i != -1)
 | 
								if (g.vec[g.vec[i].j].i != -1)
 | 
				
			||||||
				mcprint_edges(g, g.vec[i].j);
 | 
									mcprint_edges(g, g.vec[i].j, color);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void mcprint(graph_mco g, int n)
 | 
					void mcprint(graph_mco g, int n, int color)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (g.vu == NULL) {
 | 
						if (g.vu == NULL) {
 | 
				
			||||||
		g.vu = calloc(g.nbs + 1, sizeof(int));
 | 
							g.vu = calloc(g.nbs + 1, sizeof(int));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mcprint_edges(g, n);
 | 
						mcprint_edges(g, n, color);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (g.vu) {
 | 
						if (g.vu) {
 | 
				
			||||||
		free(g.vu);
 | 
							free(g.vu);
 | 
				
			||||||
@ -153,7 +159,7 @@ static void main_graph(FILE *fp, graph_mco g, int n)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void mcdot_graph(graph_mco *g, bool main)
 | 
					void mcdot_graph(graph_mco *g, bool main)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	FILE *fp, *fp1;
 | 
						FILE *fp;
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (g->vu == NULL) {
 | 
						if (g->vu == NULL) {
 | 
				
			||||||
@ -164,36 +170,35 @@ void mcdot_graph(graph_mco *g, bool main)
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fp = fopen("mcgraph.dot", "w");
 | 
						fp = fopen("graph.dot", "a");
 | 
				
			||||||
	fp1 = fopen("mcCC.dot", "w");
 | 
						// fp1 = fopen("mcCC.dot", "w");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fprintf(fp, "digraph mcCCmain {\n");
 | 
						fprintf(fp, "digraph mcCCmain {\n\tlabelloc=\"t\";\n\tlabel=\"MAIN Compact Matrice\";\n");
 | 
				
			||||||
	fprintf(fp1, "digraph mcCC {\n");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (main) {
 | 
						if (main) {
 | 
				
			||||||
		fix_str m = "main";
 | 
							fix_str m = "main";
 | 
				
			||||||
		int n = mcis_in(*g, m);
 | 
							int n = mcis_in(*g, m);
 | 
				
			||||||
		if (n != -1) {
 | 
							if (n != -1) {
 | 
				
			||||||
			main_graph(fp, *g, n);
 | 
								main_graph(fp, *g, n);
 | 
				
			||||||
 | 
								fprintf(fp, "}\n");
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			fprintf(stderr, "main not found.\n");
 | 
								fprintf(stderr, "main not found.\n");
 | 
				
			||||||
			exit(1);
 | 
								exit(1);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							fprintf(fp, "digraph mcCC {\n\tlabelloc=\"t\";\n\tlabel=\"CC Compact Matrice\";\n");
 | 
				
			||||||
		for (i = 0; i <= g->nbs; ++i) {
 | 
							for (i = 0; i <= g->nbs; ++i) {
 | 
				
			||||||
			if (!g->vu[i]) {
 | 
								if (!g->vu[i]) {
 | 
				
			||||||
				main_graph(fp1, *g, i);
 | 
									main_graph(fp, *g, i);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							fprintf(fp, "}\n");
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		write_node_dot(fp, *g);
 | 
							write_node_dot(fp, *g);
 | 
				
			||||||
 | 
							fprintf(fp, "}\n");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fprintf(fp, "}");
 | 
					 | 
				
			||||||
	fprintf(fp1, "}");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fclose(fp);
 | 
						fclose(fp);
 | 
				
			||||||
	fclose(fp1);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NOTE: https://www.baeldung.com/cs/detecting-cycles-in-directed-graph
 | 
					// NOTE: https://www.baeldung.com/cs/detecting-cycles-in-directed-graph
 | 
				
			||||||
 | 
				
			|||||||
@ -28,7 +28,7 @@ void mcinsert_func(graph_mco *g, fix_str i);
 | 
				
			|||||||
void mcinsert_edge(graph_mco *g, int dep, int arr);
 | 
					void mcinsert_edge(graph_mco *g, int dep, int arr);
 | 
				
			||||||
void mcdelete_graph(graph_mco *g);
 | 
					void mcdelete_graph(graph_mco *g);
 | 
				
			||||||
int mcis_in(graph_mco g, fix_str func);
 | 
					int mcis_in(graph_mco g, fix_str func);
 | 
				
			||||||
void mcprint(graph_mco g, int n);
 | 
					void mcprint(graph_mco g, int n, int color);
 | 
				
			||||||
void mcdot_graph(graph_mco *g, bool main);
 | 
					void mcdot_graph(graph_mco *g, bool main);
 | 
				
			||||||
void mcfind_cycles(graph_mco *g);
 | 
					void mcfind_cycles(graph_mco *g);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										40
									
								
								src/vec.c
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								src/vec.c
									
									
									
									
									
								
							@ -66,34 +66,40 @@ int vis_in(graph_vec g, fix_str func)
 | 
				
			|||||||
	return -1;
 | 
						return -1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void vprint_succ(nodept node)
 | 
					static void vprint_succ(nodept node, int color)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	printf(YELLOW "  Succ:" RESET_COLOR CYAN "%s\n" RESET_COLOR, node->func);
 | 
						if (color)
 | 
				
			||||||
 | 
							printf(YELLOW "  Succ:" RESET_COLOR CYAN "%s\n" RESET_COLOR, node->func);
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							printf("  Succ:%s\n", node->func);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void vprint_nodes(nodept node)
 | 
					static void vprint_nodes(nodept node, int color)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
	if (node->vu)
 | 
						if (node->vu)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	node->vu = 1;
 | 
						node->vu = 1;
 | 
				
			||||||
	printf(BLUE "NODE:" RESET_COLOR MAGENTA" %s\n" RESET_COLOR, node->func);
 | 
						if (color)
 | 
				
			||||||
 | 
							printf(BLUE "NODE:" RESET_COLOR MAGENTA " %s\n" RESET_COLOR, node->func);
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							printf("NODE: %s\n", node->func);
 | 
				
			||||||
	for (i = 0; i < node->nbs; ++i) {
 | 
						for (i = 0; i < node->nbs; ++i) {
 | 
				
			||||||
		vprint_succ(node->succ[i]);
 | 
							vprint_succ(node->succ[i], color);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for (i = 0; i < node->nbs; ++i) {
 | 
						for (i = 0; i < node->nbs; ++i) {
 | 
				
			||||||
		if (node->succ[i]->nbs != 0)
 | 
							if (node->succ[i]->nbs != 0)
 | 
				
			||||||
			vprint_nodes(node->succ[i]);
 | 
								vprint_nodes(node->succ[i], color);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void vprint(nodept node, graph_vec *g)
 | 
					void vprint(nodept node, graph_vec *g, int color)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
	for (i = 0; i <= g->n; i++) {
 | 
						for (i = 0; i <= g->n; i++) {
 | 
				
			||||||
		g->node[i]->vu = 0;
 | 
							g->node[i]->vu = 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	vprint_nodes(node);
 | 
						vprint_nodes(node, color);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void write_node_dot(FILE *fp, graph_vec g)
 | 
					static void write_node_dot(FILE *fp, graph_vec g)
 | 
				
			||||||
@ -122,43 +128,41 @@ static 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, *fp1;
 | 
						FILE *fp;
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i <= g.n; i++) {
 | 
						for (i = 0; i <= g.n; i++) {
 | 
				
			||||||
		g.node[i]->vu = 0;
 | 
							g.node[i]->vu = 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fp = fopen("vgraph.dot", "w");
 | 
						fp = fopen("graph.dot", "a");
 | 
				
			||||||
	fp1 = fopen("vCC.dot", "w");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fprintf(fp, "digraph vCCmain {\n");
 | 
						fprintf(fp, "digraph vCCmain {\n\tlabelloc=\"t\";\n\tlabel=\"MAIN Vector\";\n");
 | 
				
			||||||
	fprintf(fp1, "digraph vCC {\n");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (main) {
 | 
						if (main) {
 | 
				
			||||||
		fix_str m = "main";
 | 
							fix_str m = "main";
 | 
				
			||||||
		int n = vis_in(g, m);
 | 
							int n = vis_in(g, m);
 | 
				
			||||||
		if (n != -1) {
 | 
							if (n != -1) {
 | 
				
			||||||
			main_graph(fp, g.node[n]);
 | 
								main_graph(fp, g.node[n]);
 | 
				
			||||||
 | 
								fprintf(fp, "}\n");
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			fprintf(stderr, "main not found.\n");
 | 
								fprintf(stderr, "main not found.\n");
 | 
				
			||||||
			exit(1);
 | 
								exit(1);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							fprintf(fp, "digraph vCC {\n\tlabelloc=\"t\";\n\tlabel=\"CC Vector\";\n");
 | 
				
			||||||
		for (i = 0; i <= g.n; ++i) {
 | 
							for (i = 0; i <= g.n; ++i) {
 | 
				
			||||||
			if (!g.node[i]->call) {
 | 
								if (!g.node[i]->call) {
 | 
				
			||||||
				main_graph(fp1, g.node[i]);
 | 
									main_graph(fp, g.node[i]);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							fprintf(fp, "}\n");
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		write_node_dot(fp, g);
 | 
							write_node_dot(fp, g);
 | 
				
			||||||
 | 
							fprintf(fp, "}\n");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fprintf(fp, "}");
 | 
					 | 
				
			||||||
	fprintf(fp1, "}");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	fclose(fp);
 | 
						fclose(fp);
 | 
				
			||||||
	fclose(fp1);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NOTE: https://www.baeldung.com/cs/detecting-cycles-in-directed-graph
 | 
					// NOTE: https://www.baeldung.com/cs/detecting-cycles-in-directed-graph
 | 
				
			||||||
 | 
				
			|||||||
@ -29,7 +29,7 @@ void vinsert_node(graph_vec *g, fix_str str);
 | 
				
			|||||||
void vdelete_graph(graph_vec *g);
 | 
					void vdelete_graph(graph_vec *g);
 | 
				
			||||||
int vis_in(graph_vec g, fix_str func);
 | 
					int vis_in(graph_vec g, fix_str func);
 | 
				
			||||||
void vdot_graph(graph_vec g, bool main);
 | 
					void vdot_graph(graph_vec g, bool main);
 | 
				
			||||||
void vprint(nodept node, graph_vec *g);
 | 
					void vprint(nodept node, graph_vec *g, int color);
 | 
				
			||||||
void vfind_cycles(graph_vec *g);
 | 
					void vfind_cycles(graph_vec *g);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* end of include guard: VEC_H */
 | 
					#endif /* end of include guard: VEC_H */
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user