Move namelist function to output_util.

This commit is contained in:
Daniel Beer 2012-10-09 10:03:10 +13:00
parent 18cf2a561f
commit 41cf65d880
7 changed files with 60 additions and 55 deletions

View File

@ -19,6 +19,7 @@
#include <string.h> #include <string.h>
#include "output.h" #include "output.h"
#include "output_util.h"
#include "dis.h" #include "dis.h"
#include "simio.h" #include "simio.h"
#include "simio_cpu.h" #include "simio_cpu.h"

View File

@ -37,6 +37,7 @@
#include "opdb.h" #include "opdb.h"
#include "reader.h" #include "reader.h"
#include "output.h" #include "output.h"
#include "output_util.h"
#include "simio.h" #include "simio.h"
#include "ctrlc.h" #include "ctrlc.h"

View File

@ -25,6 +25,7 @@
#include "vector.h" #include "vector.h"
#include "stdcmd.h" #include "stdcmd.h"
#include "output.h" #include "output.h"
#include "output_util.h"
#include "reader.h" #include "reader.h"
#include "expr.h" #include "expr.h"

View File

@ -179,53 +179,3 @@ void capture_end(void)
{ {
capture_func = NULL; 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");
}
}

View File

@ -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_start(capture_func_t, void *user_data);
void capture_end(void); 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 #endif

View File

@ -18,6 +18,8 @@
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include <string.h>
#include <stdlib.h>
#include "dis.h" #include "dis.h"
#include "output_util.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); snprintf(out, max_len, "0x%04x", addr);
return 0; 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");
}
}

View File

@ -39,4 +39,9 @@ void show_regs(const address_t *regs);
*/ */
int print_address(address_t addr, char *buf, int max_len); 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 #endif