WINCHAIN cleanup

This started out as some formatting cleanup for src/windows.c but
ended up removing calloc() from the WINCHAIN code, plus fixing a
couple of compiler complaints for win/chain/wc_trace.c.

I tried to actually run with +trace enabled and never managed to
get anything to happen.  trace_procs_init() was never called.  I've
never tried to use it before so don't know whether something which
used to work has gotten broken or I'm just doing it wrong.
This commit is contained in:
PatR
2018-10-20 02:23:45 -07:00
parent 7ed01793b4
commit f211953b43
4 changed files with 75 additions and 49 deletions

View File

@@ -64,7 +64,8 @@ STATIC_DCL void FDECL(dump_clear_nhwindow, (winid));
STATIC_DCL void FDECL(dump_display_nhwindow, (winid, BOOLEAN_P)); STATIC_DCL void FDECL(dump_display_nhwindow, (winid, BOOLEAN_P));
STATIC_DCL void FDECL(dump_destroy_nhwindow, (winid)); STATIC_DCL void FDECL(dump_destroy_nhwindow, (winid));
STATIC_DCL void FDECL(dump_start_menu, (winid)); STATIC_DCL void FDECL(dump_start_menu, (winid));
STATIC_DCL void FDECL(dump_add_menu, (winid, int, const ANY_P *, CHAR_P, CHAR_P, int, const char *, BOOLEAN_P)); STATIC_DCL void FDECL(dump_add_menu, (winid, int, const ANY_P *, CHAR_P,
CHAR_P, int, const char *, BOOLEAN_P));
STATIC_DCL void FDECL(dump_end_menu, (winid, const char *)); STATIC_DCL void FDECL(dump_end_menu, (winid, const char *));
STATIC_DCL int FDECL(dump_select_menu, (winid, int, MENU_ITEM_P **)); STATIC_DCL int FDECL(dump_select_menu, (winid, int, MENU_ITEM_P **));
STATIC_DCL void FDECL(dump_putstr, (winid, int, const char *)); STATIC_DCL void FDECL(dump_putstr, (winid, int, const char *));
@@ -145,14 +146,22 @@ static struct winlink *chain = 0;
static struct winlink * static struct winlink *
wl_new() wl_new()
{ {
return calloc(1, sizeof(struct winlink)); struct winlink *wl = (struct winlink *) alloc(sizeof *wl);
wl->nextlink = 0;
wl->wincp = 0;
wl->linkdata = 0;
return wl;
} }
static void static void
wl_addhead(struct winlink *wl) wl_addhead(struct winlink *wl)
{ {
wl->nextlink = chain; wl->nextlink = chain;
chain = wl; chain = wl;
} }
static void static void
wl_addtail(struct winlink *wl) wl_addtail(struct winlink *wl)
{ {
@@ -255,24 +264,28 @@ const char *s;
if (!winchoices[0].procs) { if (!winchoices[0].procs) {
raw_printf("No window types?"); raw_printf("No window types?");
exit(EXIT_FAILURE); nh_terminate(EXIT_FAILURE);
} }
if (!winchoices[1].procs) { if (!winchoices[1].procs) {
config_error_add("Window type %s not recognized. The only choice is: %s", config_error_add(
s, winchoices[0].procs->name); "Window type %s not recognized. The only choice is: %s",
s, winchoices[0].procs->name);
} else { } else {
char buf[BUFSZ]; char buf[BUFSZ];
boolean first = TRUE; boolean first = TRUE;
buf[0] = '\0'; buf[0] = '\0';
for (i = 0; winchoices[i].procs; i++) { for (i = 0; winchoices[i].procs; i++) {
if ('+' == winchoices[i].procs->name[0]) if ('+' == winchoices[i].procs->name[0])
continue; continue;
if ('-' == winchoices[i].procs->name[0]) if ('-' == winchoices[i].procs->name[0])
continue; continue;
Sprintf(eos(buf), "%s%s", first ? "" : ",", winchoices[i].procs->name); Sprintf(eos(buf), "%s%s",
first ? "" : ", ", winchoices[i].procs->name);
first = FALSE; first = FALSE;
} }
config_error_add("Window type %s not recognized. Choices are: %s", s, buf); config_error_add("Window type %s not recognized. Choices are: %s",
s, buf);
} }
if (windowprocs.win_raw_print == def_raw_print) if (windowprocs.win_raw_print == def_raw_print)
@@ -291,6 +304,7 @@ const char *s;
continue; continue;
if (!strcmpi(s, winchoices[i].procs->name)) { if (!strcmpi(s, winchoices[i].procs->name)) {
struct winlink *p = wl_new(); struct winlink *p = wl_new();
p->wincp = &winchoices[i]; p->wincp = &winchoices[i];
wl_addtail(p); wl_addtail(p);
/* NB: The ini_routine() will be called during commit. */ /* NB: The ini_routine() will be called during commit. */
@@ -307,7 +321,7 @@ const char *s;
raw_printf(" %s", winchoices[i].procs->name); raw_printf(" %s", winchoices[i].procs->name);
} }
exit(EXIT_FAILURE); nh_terminate(EXIT_FAILURE);
} }
void void
@@ -494,7 +508,8 @@ static short FDECL(hup_set_font_name, (winid, char *));
#endif #endif
static char *NDECL(hup_get_color_string); static char *NDECL(hup_get_color_string);
#endif /* CHANGE_COLOR */ #endif /* CHANGE_COLOR */
static void FDECL(hup_status_update, (int, genericptr_t, int, int, int, unsigned long *)); static void FDECL(hup_status_update, (int, genericptr_t, int, int, int,
unsigned long *));
static int NDECL(hup_int_ndecl); static int NDECL(hup_int_ndecl);
static void NDECL(hup_void_ndecl); static void NDECL(hup_void_ndecl);

View File

@@ -27,23 +27,26 @@ void *me;
void *nextprocs; void *nextprocs;
void *nextdata; void *nextdata;
{ {
struct chainin_data *tdp = 0;
switch (cmd) { switch (cmd) {
case WINCHAIN_ALLOC: { case WINCHAIN_ALLOC:
struct chainin_data *tdp = calloc(1, sizeof(struct chainin_data)); tdp = (struct chainin_data *) alloc(sizeof *tdp);
tdp->nprocs = 0;
tdp->ndata = 0;
tdp->linknum = n; tdp->linknum = n;
cibase = tdp; cibase = 0;
return tdp; break;
} case WINCHAIN_INIT:
case WINCHAIN_INIT: { tdp = me;
struct chainin_data *tdp = me;
tdp->nprocs = nextprocs; tdp->nprocs = nextprocs;
tdp->ndata = nextdata; tdp->ndata = nextdata;
return tdp; break;
}
default: default:
raw_printf("chainin_procs_chain: bad cmd\n"); panic("chainin_procs_chain: bad cmd\n");
exit(EXIT_FAILURE); /*NOTREACHED*/
} }
return tdp;
} }
/* XXX if we don't need this, take it out of the table */ /* XXX if we don't need this, take it out of the table */

View File

@@ -10,7 +10,7 @@
struct chainout_data { struct chainout_data {
struct window_procs *nprocs; struct window_procs *nprocs;
#if 0 #if 0
void *ndata; void *ndata;
#endif #endif
int linknum; int linknum;
@@ -24,21 +24,23 @@ void *me;
void *nextprocs; void *nextprocs;
void *nextdata UNUSED; void *nextdata UNUSED;
{ {
struct chainout_data *tdp = 0;
switch (cmd) { switch (cmd) {
case WINCHAIN_ALLOC: { case WINCHAIN_ALLOC:
struct chainout_data *tdp = calloc(1, sizeof(struct chainout_data)); tdp = (struct chainout_data *) alloc(sizeof *tdp);
tdp->nprocs = 0;
tdp->linknum = n; tdp->linknum = n;
return tdp; break;
} case WINCHAIN_INIT:
case WINCHAIN_INIT: { tdp = me;
struct chainout_data *tdp = me;
tdp->nprocs = nextprocs; tdp->nprocs = nextprocs;
return tdp; break;
}
default: default:
raw_printf("chainout_procs_chain: bad cmd\n"); panic("chainout_procs_chain: bad cmd\n");
exit(EXIT_FAILURE); /*NOTREACHED*/
} }
return tdp;
} }
/* XXX if we don't need this, take it out of the table */ /* XXX if we don't need this, take it out of the table */

View File

@@ -48,22 +48,25 @@ void *me;
void *nextprocs; void *nextprocs;
void *nextdata; void *nextdata;
{ {
struct trace_data *tdp = 0;
switch (cmd) { switch (cmd) {
case WINCHAIN_ALLOC: { case WINCHAIN_ALLOC:
struct trace_data *tdp = calloc(1, sizeof(struct trace_data)); tdp = (struct trace_data *) alloc(sizeof *tdp);
tdp->nprocs = 0;
tdp->ndata = 0;
tdp->linknum = n; tdp->linknum = n;
return tdp; break;
} case WINCHAIN_INIT:
case WINCHAIN_INIT: { tdp = me;
struct trace_data *tdp = me;
tdp->nprocs = nextprocs; tdp->nprocs = nextprocs;
tdp->ndata = nextdata; tdp->ndata = nextdata;
return tdp; break;
}
default: default:
raw_printf("trace_procs_chain: bad cmd\n"); panic("trace_procs_chain: bad cmd\n");
exit(EXIT_FAILURE); /*NOTREACHED*/
} }
return tdp;
} }
void void
@@ -71,20 +74,22 @@ trace_procs_init(dir)
int dir; int dir;
{ {
char fname[200]; char fname[200];
long pid;
/* processors shouldn't need this test, but just in case */ /* processors shouldn't need this test, but just in case */
if (dir != WININIT) if (dir != WININIT)
return; return;
sprintf(fname, "%s/tlog.%d", HACKDIR, getpid()); pid = (long) getpid();
Sprintf(fname, "%s/tlog.%ld", HACKDIR, pid);
wc_tracelogf = fopen(fname, "w"); wc_tracelogf = fopen(fname, "w");
if (wc_tracelogf == NULL) { if (!wc_tracelogf) {
fprintf(stderr, "Can't open trace log file %s: %s\n", fname, fprintf(stderr, "Can't open trace log file %s: %s\n", fname,
strerror(errno)); strerror(errno));
exit(EXIT_FAILURE); nh_terminate(EXIT_FAILURE);
} }
setvbuf(wc_tracelogf, (char *) NULL, _IONBF, 0); setvbuf(wc_tracelogf, (char *) 0, _IONBF, 0);
fprintf(wc_tracelogf, "Trace log started for pid %d\n", getpid()); fprintf(wc_tracelogf, "Trace log started for pid %ld\n", pid);
indent_level = 0; indent_level = 0;
} }
@@ -769,7 +774,7 @@ char *bufp;
} }
if (bufp) { if (bufp) {
fprintf(wc_tracelogf, "%p)\n", bufp); fprintf(wc_tracelogf, "%s)\n", fmt_ptr((genericptr_t) bufp));
} else { } else {
fprintf(wc_tracelogf, "NULL)\n"); fprintf(wc_tracelogf, "NULL)\n");
} }
@@ -785,7 +790,7 @@ void *vp;
{ {
struct trace_data *tdp = vp; struct trace_data *tdp = vp;
int rv; int rv;
int ecl_size; int ecl_size = 0;
/* this is ugly, but the size isn't exposed */ /* this is ugly, but the size isn't exposed */
const struct ext_func_tab *efp; const struct ext_func_tab *efp;
@@ -1095,7 +1100,8 @@ unsigned long *colormasks;
ptr, chg, percent); ptr, chg, percent);
PRE; PRE;
(*tdp->nprocs->win_status_update)(tdp->ndata, idx, ptr, chg, percent, color, colormasks); (*tdp->nprocs->win_status_update)(tdp->ndata, idx, ptr, chg, percent,
color, colormasks);
POST; POST;
} }