From c29506a51108d3093b323b05a4f356847c60b607 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Fri, 8 Feb 2019 11:58:26 +0200 Subject: New options: --all and --no-main * NEWS: Document --all and --no-main * configure.ac: Version 1.5.90 * doc/cflow.texi: Document --all and --no-main * src/cflow.h (all_functions): New extern. * src/main.c: New options: -A (--all) and --no-main * src/output.c (tree_output): Output all graphs if all_functions is set or no main function is defined. --- src/cflow.h | 4 ++-- src/main.c | 18 +++++++++++++++--- src/output.c | 10 ++++++---- 3 files changed, 23 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/cflow.h b/src/cflow.h index 1a5ec76..8779a68 100644 --- a/src/cflow.h +++ b/src/cflow.h @@ -1,6 +1,5 @@ /* This file is part of GNU cflow - Copyright (C) 1997, 2005, 2007, 2009-2010, 2014-2017 Sergey - Poznyakoff + Copyright (C) 1997-2019 Sergey Poznyakoff GNU cflow is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -162,6 +161,7 @@ extern int brief_listing; extern int reverse_tree; extern int out_line; extern char *start_name; +extern int all_functions; extern int max_depth; extern int emacs_option; extern int debug; diff --git a/src/main.c b/src/main.c index e67b3e0..a5535c7 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,5 @@ /* This file is part of GNU cflow - Copyright (C) 1997, 2005, 2007, 2009-2011, 2014-2017 Sergey - Poznyakoff + Copyright (C) 1997-2019 Sergey Poznyakoff GNU cflow is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -44,6 +43,7 @@ enum option_code { OPT_NO_TREE, OPT_NO_BRIEF, OPT_NO_EMACS, + OPT_NO_MAIN, OPT_NO_VERBOSE, OPT_NO_NUMBER, OPT_NO_PRINT_LEVEL, @@ -105,6 +105,8 @@ static struct argp_option options[] = { N_("Register SYMBOL with given TYPE, or define an alias (if := is used). Valid types are: keyword (or kw), modifier, qualifier, identifier, type, wrapper. Any unambiguous abbreviation of the above is also accepted"), GROUP_ID+1 }, { "main", 'm', N_("NAME"), 0, N_("Assume main function to be called NAME"), GROUP_ID+1 }, + { "no-main", OPT_NO_MAIN, NULL, 0, + N_("There's no main function; print graphs for all functions in the program") }, { "define", 'D', N_("NAME[=DEFN]"), 0, N_("Predefine NAME as a macro"), GROUP_ID+1 }, { "undefine", 'U', N_("NAME"), 0, @@ -121,6 +123,9 @@ static struct argp_option options[] = { #define GROUP_ID 20 { NULL, 0, NULL, 0, N_("Output control:"), GROUP_ID }, + { "all", 'A', NULL, 0, + N_("Show all functions, not only those reachable from main"), + GROUP_ID+1 }, { "number", 'n', NULL, 0, N_("* Print line numbers"), GROUP_ID+1 }, { "no-number", OPT_NO_NUMBER, NULL, OPTION_HIDDEN, @@ -216,7 +221,7 @@ char *level_begin = ""; int preprocess_option = 0; /* Do they want to preprocess sources? */ char *start_name = "main"; /* Name of start symbol */ - +int all_functions; struct linked_list *arglist; /* List of command line arguments */ /* Given the option_type array and (possibly abbreviated) option argument @@ -512,6 +517,9 @@ parse_opt (int key, char *arg, struct argp_state *state) int num; switch (key) { + case 'A': + all_functions = 1; + break; case 'a': strict_ansi = 1; break; @@ -616,6 +624,9 @@ parse_opt (int key, char *arg, struct argp_state *state) case 'm': start_name = strdup(arg); break; + case OPT_NO_MAIN: + start_name = NULL; + break; case 'n': print_line_numbers = 1; break; @@ -721,6 +732,7 @@ void xalloc_die(void) { error(EX_FATAL, ENOMEM, _("Exiting")); + abort(); } void diff --git a/src/output.c b/src/output.c index 764e926..7eaf7ac 100644 --- a/src/output.c +++ b/src/output.c @@ -1,6 +1,5 @@ /* This file is part of GNU cflow - Copyright (C) 1997, 2005, 2007, 2009-2011, 2014-2017 Sergey - Poznyakoff + Copyright (C) 1997-2019 Sergey Poznyakoff GNU cflow is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -393,11 +392,14 @@ tree_output() separator(); } } else { - main_sym = lookup(start_name); - if (main_sym) { + if ((main_sym = start_name ? lookup(start_name) : NULL) != NULL) { direct_tree(0, 0, main_sym); separator(); } else { + all_functions = 1; + } + + if (all_functions) { for (i = 0; i < num; i++) { if (symbols[i]->callee == NULL) continue; -- cgit v1.2.1