diff --git a/simio/simio.c b/simio/simio.c index 2e3fb72..4e338c3 100644 --- a/simio/simio.c +++ b/simio/simio.c @@ -19,6 +19,7 @@ #include #include "output.h" +#include "output_util.h" #include "dis.h" #include "simio.h" #include "simio_cpu.h" diff --git a/ui/main.c b/ui/main.c index eb9bddc..83da0a9 100644 --- a/ui/main.c +++ b/ui/main.c @@ -37,6 +37,7 @@ #include "opdb.h" #include "reader.h" #include "output.h" +#include "output_util.h" #include "simio.h" #include "ctrlc.h" diff --git a/ui/stdcmd.c b/ui/stdcmd.c index 50cea1e..abb5197 100644 --- a/ui/stdcmd.c +++ b/ui/stdcmd.c @@ -25,6 +25,7 @@ #include "vector.h" #include "stdcmd.h" #include "output.h" +#include "output_util.h" #include "reader.h" #include "expr.h" diff --git a/util/output.c b/util/output.c index d11d7b5..9442a34 100644 --- a/util/output.c +++ b/util/output.c @@ -179,53 +179,3 @@ void capture_end(void) { capture_func = NULL; } - -/************************************************************************ - * Name lists - */ - -static int namelist_cmp(const void *a, const void *b) -{ - return strcasecmp(*(const char **)a, *(const char **)b); -} - -void namelist_print(struct vector *v) -{ - int i; - int max_len = 0; - int rows, cols; - - qsort(v->ptr, v->size, v->elemsize, namelist_cmp); - - for (i = 0; i < v->size; i++) { - const char *text = VECTOR_AT(*v, i, const char *); - int len = strlen(text); - - if (len > max_len) - max_len = len; - } - - max_len += 2; - cols = 72 / max_len; - rows = (v->size + cols - 1) / cols; - - for (i = 0; i < rows; i++) { - int j; - - printc(" "); - for (j = 0; j < cols; j++) { - int k = j * rows + i; - const char *text; - - if (k >= v->size) - break; - - text = VECTOR_AT(*v, k, const char *); - printc("%s", text); - for (k = strlen(text); k < max_len; k++) - printc(" "); - } - - printc("\n"); - } -} diff --git a/util/output.h b/util/output.h index 1fd548e..7d1c7b9 100644 --- a/util/output.h +++ b/util/output.h @@ -48,9 +48,4 @@ typedef void (*capture_func_t)(void *user_data, const char *text); void capture_start(capture_func_t, void *user_data); void capture_end(void); -/* Name lists. This function is used for printing multi-column sorted - * lists of constant strings. Expected is a vector of const char *. - */ -void namelist_print(struct vector *v); - #endif diff --git a/util/output_util.c b/util/output_util.c index b9f438c..324741d 100644 --- a/util/output_util.c +++ b/util/output_util.c @@ -18,6 +18,8 @@ #include #include +#include +#include #include "dis.h" #include "output_util.h" @@ -304,3 +306,53 @@ int print_address(address_t addr, char *out, int max_len) snprintf(out, max_len, "0x%04x", addr); return 0; } + +/************************************************************************ + * Name lists + */ + +static int namelist_cmp(const void *a, const void *b) +{ + return strcasecmp(*(const char **)a, *(const char **)b); +} + +void namelist_print(struct vector *v) +{ + int i; + int max_len = 0; + int rows, cols; + + qsort(v->ptr, v->size, v->elemsize, namelist_cmp); + + for (i = 0; i < v->size; i++) { + const char *text = VECTOR_AT(*v, i, const char *); + int len = strlen(text); + + if (len > max_len) + max_len = len; + } + + max_len += 2; + cols = 72 / max_len; + rows = (v->size + cols - 1) / cols; + + for (i = 0; i < rows; i++) { + int j; + + printc(" "); + for (j = 0; j < cols; j++) { + int k = j * rows + i; + const char *text; + + if (k >= v->size) + break; + + text = VECTOR_AT(*v, k, const char *); + printc("%s", text); + for (k = strlen(text); k < max_len; k++) + printc(" "); + } + + printc("\n"); + } +} diff --git a/util/output_util.h b/util/output_util.h index 339328c..ac6add9 100644 --- a/util/output_util.h +++ b/util/output_util.h @@ -39,4 +39,9 @@ void show_regs(const address_t *regs); */ int print_address(address_t addr, char *buf, int max_len); +/* Name lists. This function is used for printing multi-column sorted + * lists of constant strings. Expected is a vector of const char *. + */ +void namelist_print(struct vector *v); + #endif