Move namelist function to output_util.
This commit is contained in:
parent
18cf2a561f
commit
41cf65d880
|
@ -19,6 +19,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "output.h"
|
||||
#include "output_util.h"
|
||||
#include "dis.h"
|
||||
#include "simio.h"
|
||||
#include "simio_cpu.h"
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "opdb.h"
|
||||
#include "reader.h"
|
||||
#include "output.h"
|
||||
#include "output_util.h"
|
||||
#include "simio.h"
|
||||
#include "ctrlc.h"
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "vector.h"
|
||||
#include "stdcmd.h"
|
||||
#include "output.h"
|
||||
#include "output_util.h"
|
||||
#include "reader.h"
|
||||
#include "expr.h"
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue