]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
Add macro for testing parse option flags
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Wed, 18 Aug 2010 16:31:13 +0000 (19:31 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Wed, 18 Aug 2010 16:34:04 +0000 (19:34 +0300)
The parse option structure parse_mask variable is tested for option
bits in quite many places. Add a macro that makes testing easier and
moves the duplicate code in one macro.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
pagemap.h
parse.c

index d7dacdf151b908d6f5e5b0557ebe53d591d6ba48..5a58c833e306e4fa140794a5e270aaf573b2d4de 100644 (file)
--- a/pagemap.h
+++ b/pagemap.h
@@ -105,4 +105,7 @@ struct parse_opts {
        int with_threads;
 };
 
+#define is_parse_option(parse_opts, flag) \
+       (!!((parse_opts)->parse_mask & (flag)))
+
 #endif
diff --git a/parse.c b/parse.c
index fc7d69e4d41ba65f40797aa17b602aa8e06c0e70..d4cae143389a67a7005c2a1dc6c66e901a4f4d40 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -154,21 +154,21 @@ static int should_scan_process(struct parse_opts *opts, struct process *process)
        int match = 0;
        char *name;
 
-       if (opts->parse_mask & PARSE_PROCESS_NAME) {
+       if (is_parse_option(opts, PARSE_PROCESS_NAME)) {
                name = get_name_by_pid(process->pid);
                if (!strcmp(opts->name, name ? name : ""))
                        match = 1;
        }
 
-       if (opts->parse_mask & PARSE_PID) {
+       if (is_parse_option(opts, PARSE_PID)) {
                if (opts->pid == process->pid)
                        match = 1;
        }
 
-       if (opts->parse_mask & PARSE_MAP_NAME)
+       if (is_parse_option(opts, PARSE_MAP_NAME))
                match = 1;
 
-       if (opts->parse_mask & PARSE_NOADD_TREE)
+       if (is_parse_option(opts, PARSE_NOADD_TREE))
                match = !match;
 
        return match;
@@ -178,11 +178,11 @@ static int should_scan_mapping(struct parse_opts *opts, struct maps *map)
 {
        int match = 0;
 
-       if (opts->parse_mask & PARSE_MAP_NAME) {
+       if (is_parse_option(opts, PARSE_MAP_NAME)) {
                if (!strcmp(opts->name, map->name))
                        match = 1;
 
-               if (opts->parse_mask & PARSE_NOADD_TREE)
+               if (is_parse_option(opts, PARSE_NOADD_TREE))
                        match = !match;
        } else
                match = 1;
@@ -193,7 +193,7 @@ static int should_scan_mapping(struct parse_opts *opts, struct maps *map)
 static int should_add_to_tree(struct parse_opts *opts, struct pageframe *pf,
                struct maps *map)
 {
-       if (opts->parse_mask & PARSE_NOADD_TREE)
+       if (is_parse_option(opts, PARSE_NOADD_TREE))
                return 0;
 
        return 1;
@@ -468,7 +468,7 @@ int scan_all_pids(struct pageframe *pf, struct process *process_list,
        int pid;
        int count = 0;
 
-       if (opts->parse_mask & PARSE_PROCESS_NAME) {
+       if (is_parse_option(opts, PARSE_PROCESS_NAME)) {
                while ((pid = get_next_pid_by_name(&dir, opts->name))) {
                        count += read_pageframe_with_threads(pid, pf,
                                                        process_list,
@@ -477,20 +477,20 @@ int scan_all_pids(struct pageframe *pf, struct process *process_list,
                dir = NULL;
        }
 
-       if (opts->parse_mask & PARSE_PID)
+       if (is_parse_option(opts, PARSE_PID))
                count = read_pageframe_with_threads(opts->pid, pf, process_list,
                                                opts);
 
-       if ((count == 0) && !(opts->parse_mask & PARSE_MAP_NAME)) {
+       if ((count == 0) && !(is_parse_option(opts, PARSE_MAP_NAME))) {
                printf("Failed to find any matching processes "
                        "with given arguments\n");
                return -1;
        }
 
-       if (opts->parse_mask & PARSE_DUMP)
+       if (is_parse_option(opts, PARSE_DUMP))
                return 0;
 
-       if (opts->parse_mask & PARSE_MAP_NAME) {
+       if (is_parse_option(opts, PARSE_MAP_NAME)) {
                while (1) {
                        pid = get_next_pid(&dir);
                        if (pid <= 0)