Module Name: src
Committed By: christos
Date: Wed Mar 9 19:47:13 UTC 2016
Modified Files:
src/lib/libform: field.c form.c internals.c internals.h post.c
type_enum.c type_ipv4.c
Log Message:
PR/50919: David Binderman: Re-do all the debug stuff in a more sustainable way.
To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/lib/libform/field.c
cvs rdiff -u -r1.15 -r1.16 src/lib/libform/form.c
cvs rdiff -u -r1.37 -r1.38 src/lib/libform/internals.c
cvs rdiff -u -r1.10 -r1.11 src/lib/libform/internals.h \
src/lib/libform/type_ipv4.c
cvs rdiff -u -r1.9 -r1.10 src/lib/libform/post.c
cvs rdiff -u -r1.11 -r1.12 src/lib/libform/type_enum.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libform/field.c
diff -u src/lib/libform/field.c:1.30 src/lib/libform/field.c:1.31
--- src/lib/libform/field.c:1.30 Fri Dec 11 16:22:57 2015
+++ src/lib/libform/field.c Wed Mar 9 14:47:13 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: field.c,v 1.30 2015/12/11 21:22:57 joerg Exp $ */
+/* $NetBSD: field.c,v 1.31 2016/03/09 19:47:13 christos Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn
* ([email protected], [email protected])
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: field.c,v 1.30 2015/12/11 21:22:57 joerg Exp $");
+__RCSID("$NetBSD: field.c,v 1.31 2016/03/09 19:47:13 christos Exp $");
#include <sys/param.h>
#include <stdlib.h>
@@ -425,26 +425,19 @@ set_field_buffer(FIELD *field, int buffe
&& ((field->rows + field->nrows) == 1))
len = field->cols;
-#ifdef DEBUG
- if (_formi_create_dbg_file() != E_OK)
- return E_SYSTEM_ERROR;
-
- fprintf(dbg,
- "set_field_buffer: entry: len = %d, value = %s, buffer=%d\n",
- len, value, buffer);
- fprintf(dbg, "set_field_buffer: entry: string = ");
+ _formi_dbg_printf( "%s: len = %d, value = %s, buffer=%d\n", __func__,
+ len, value, buffer);
if (field->buffers[buffer].string != NULL)
- fprintf(dbg, "%s, len = %d\n", field->buffers[buffer].string,
- field->buffers[buffer].length);
- else
- fprintf(dbg, "(null), len = 0\n");
- fprintf(dbg, "set_field_buffer: entry: lines.len = %d\n",
- field->alines[0].length);
-#endif
+ _formi_dbg_printf("%s: string=%s, len = %d\n", __func__,
+ field->buffers[buffer].string,
+ field->buffers[buffer].length);
+ else
+ _formi_dbg_printf("%s: string=(null), len = 0\n", __func__);
+ _formi_dbg_printf("%s: lines.len = %d\n", __func__,
+ field->alines[0].length);
- if ((field->buffers[buffer].string =
- (char *) realloc(field->buffers[buffer].string,
- (size_t) len + 1)) == NULL)
+ if ((field->buffers[buffer].string = realloc(
+ field->buffers[buffer].string, (size_t) len + 1)) == NULL)
return E_SYSTEM_ERROR;
strlcpy(field->buffers[buffer].string, value, (size_t) len + 1);
@@ -452,14 +445,11 @@ set_field_buffer(FIELD *field, int buffe
field->buffers[buffer].allocated = len + 1;
status = field_buffer_init(field, buffer, len);
-#ifdef DEBUG
- fprintf(dbg, "set_field_buffer: exit: len = %d, value = %s\n",
- len, value);
- fprintf(dbg, "set_field_buffer: exit: string = %s, len = %d\n",
- field->buffers[buffer].string, field->buffers[buffer].length);
- fprintf(dbg, "set_field_buffer: exit: lines.len = %d\n",
+ _formi_dbg_printf("%s: len = %d, value = %s\n", __func__, len, value);
+ _formi_dbg_printf("%s: string = %s, len = %d\n", __func__,
+ field->buffers[buffer].string, field->buffers[buffer].length);
+ _formi_dbg_printf("%s: lines.len = %d\n", __func__,
field->alines[0].length);
-#endif
return status;
}
Index: src/lib/libform/form.c
diff -u src/lib/libform/form.c:1.15 src/lib/libform/form.c:1.16
--- src/lib/libform/form.c:1.15 Wed Nov 24 06:57:09 2004
+++ src/lib/libform/form.c Wed Mar 9 14:47:13 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: form.c,v 1.15 2004/11/24 11:57:09 blymn Exp $ */
+/* $NetBSD: form.c,v 1.16 2016/03/09 19:47:13 christos Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: form.c,v 1.15 2004/11/24 11:57:09 blymn Exp $");
+__RCSID("$NetBSD: form.c,v 1.16 2016/03/09 19:47:13 christos Exp $");
#include <stdlib.h>
#include <strings.h>
@@ -603,9 +603,7 @@ pos_form_cursor(FORM *form)
}
}
-#ifdef DEBUG
- fprintf(dbg, "pos_cursor: row=%d, col=%d\n", row, col);
-#endif
+ _formi_dbg_printf("%s: row=%d, col=%d\n", __func__, row, col);
wmove(form->scrwin, row, col);
Index: src/lib/libform/internals.c
diff -u src/lib/libform/internals.c:1.37 src/lib/libform/internals.c:1.38
--- src/lib/libform/internals.c:1.37 Mon Nov 25 20:17:00 2013
+++ src/lib/libform/internals.c Wed Mar 9 14:47:13 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: internals.c,v 1.37 2013/11/26 01:17:00 christos Exp $ */
+/* $NetBSD: internals.c,v 1.38 2016/03/09 19:47:13 christos Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: internals.c,v 1.37 2013/11/26 01:17:00 christos Exp $");
+__RCSID("$NetBSD: internals.c,v 1.38 2016/03/09 19:47:13 christos Exp $");
#include <limits.h>
#include <ctype.h>
@@ -38,6 +38,8 @@ __RCSID("$NetBSD: internals.c,v 1.37 201
#include <stdlib.h>
#include <strings.h>
#include <assert.h>
+#include <err.h>
+#include <stdarg.h>
#include "internals.h"
#include "form.h"
@@ -46,12 +48,11 @@ __RCSID("$NetBSD: internals.c,v 1.37 201
* file handle to write debug info to, this will be initialised when
* the form is first posted.
*/
-FILE *dbg = NULL;
/*
* map the request numbers to strings for debug
*/
-char *reqs[] = {
+static const char *reqs[] = {
"NEXT_PAGE", "PREV_PAGE", "FIRST_PAGE", "LAST_PAGE", "NEXT_FIELD",
"PREV_FIELD", "FIRST_FIELD", "LAST_FIELD", "SNEXT_FIELD",
"SPREV_FIELD", "SFIRST_FIELD", "SLAST_FIELD", "LEFT_FIELD",
@@ -317,18 +318,21 @@ _formi_init_field_xpos(FIELD *field)
* Open the debug file if it is not already open....
*/
#ifdef DEBUG
-int
-_formi_create_dbg_file(void)
+static FILE *dbg;
+static const char dbg_file[] = "___form_dbg.out";
+
+void
+_formi_dbg_printf(const char *fmt, ...)
{
- if (dbg == NULL) {
- dbg = fopen("___form_dbg.out", "w");
- if (dbg == NULL) {
- fprintf(stderr, "Cannot open debug file!\n");
- return E_SYSTEM_ERROR;
- }
- }
+ va_list ap;
- return E_OK;
+ if (dbg == NULL && (dbg = fopen(dbg_file, "w")) == NULL) {
+ warn("Cannot open debug file `%s'", dbg_file);
+ return;
+ }
+ va_start(ap, fmt);
+ vfprintf(dbg, fmt, ap);
+ va_end(ap);
}
#endif
@@ -709,18 +713,9 @@ _formi_join_line(FIELD *field, _FORMI_FI
struct _formi_field_lines *saved;
char *newp;
_FORMI_FIELD_LINES *row = *rowp;
-#ifdef DEBUG
- int dbg_ok = FALSE;
-
- if (_formi_create_dbg_file() == E_OK) {
- dbg_ok = TRUE;
- }
- if (dbg_ok == TRUE) {
- fprintf(dbg, "join_line: working on row %p, row_count = %d\n",
- row, field->row_count);
- }
-#endif
+ _formi_dbg_printf("%s: working on row %p, row_count = %d\n",
+ __func__, row, field->row_count);
if ((direction == JOIN_NEXT) || (direction == JOIN_NEXT_NW)) {
/*
@@ -732,16 +727,12 @@ _formi_join_line(FIELD *field, _FORMI_FI
return E_REQUEST_DENIED;
}
-#ifdef DEBUG
- if (dbg_ok == TRUE) {
- fprintf(dbg,
- "join_line: join_next before length = %d, expanded = %d",
- row->length, row->expanded);
- fprintf(dbg,
- " :: next row length = %d, expanded = %d\n",
- row->length, row->expanded);
- }
-#endif
+ _formi_dbg_printf(
+ "%s: join_next before length = %d, expanded = %d",
+ __func__, row->length, row->expanded);
+ _formi_dbg_printf(
+ " :: next row length = %d, expanded = %d\n",
+ row->length, row->expanded);
if (row->allocated < (row->length + row->next->length + 1)) {
if ((newp = realloc(row->string, (size_t)(row->length +
@@ -787,13 +778,9 @@ _formi_join_line(FIELD *field, _FORMI_FI
/* remove joined line record from the row list */
add_to_free(field, row->next);
-#ifdef DEBUG
- if (dbg_ok == TRUE) {
- fprintf(dbg,
- "join_line: exit length = %d, expanded = %d\n",
- row->length, row->expanded);
- }
-#endif
+ _formi_dbg_printf(
+ "%s: exit length = %d, expanded = %d\n",
+ __func__, row->length, row->expanded);
} else {
if (row->prev == NULL) {
return E_REQUEST_DENIED;
@@ -809,16 +796,12 @@ _formi_join_line(FIELD *field, _FORMI_FI
return E_REQUEST_DENIED;
}
-#ifdef DEBUG
- if (dbg_ok == TRUE) {
- fprintf(dbg,
- "join_line: join_prev before length = %d, expanded = %d",
- row->length, row->expanded);
- fprintf(dbg,
- " :: prev row length = %d, expanded = %d\n",
- saved->length, saved->expanded);
- }
-#endif
+ _formi_dbg_printf(
+ "%s: join_prev before length = %d, expanded = %d",
+ __func__, row->length, row->expanded);
+ _formi_dbg_printf(
+ " :: prev row length = %d, expanded = %d\n",
+ saved->length, saved->expanded);
if (saved->allocated < (row->length + saved->length + 1)) {
if ((newp = realloc(saved->string,
@@ -855,13 +838,9 @@ _formi_join_line(FIELD *field, _FORMI_FI
add_to_free(field, row);
-#ifdef DEBUG
- if (dbg_ok == TRUE) {
- fprintf(dbg,
- "join_line: exit length = %d, expanded = %d\n",
- saved->length, saved->expanded);
- }
-#endif
+ _formi_dbg_printf(
+ "%s: exit length = %d, expanded = %d\n", __func__,
+ saved->length, saved->expanded);
row = saved;
}
@@ -910,9 +889,6 @@ split_line(FIELD *field, bool hard_split
struct _formi_field_lines *new_line;
char *newp;
_FORMI_FIELD_LINES *row = *rowp;
-#ifdef DEBUG
- short dbg_ok = FALSE;
-#endif
/* if asked to split right where the line already starts then
* just return - nothing to do unless we are appending a line
@@ -921,12 +897,7 @@ split_line(FIELD *field, bool hard_split
if ((pos == 0) && (hard_split == FALSE))
return E_OK;
-#ifdef DEBUG
- if (_formi_create_dbg_file() == E_OK) {
- fprintf(dbg, "split_line: splitting line at %d\n", pos);
- dbg_ok = TRUE;
- }
-#endif
+ _formi_dbg_printf("%s: splitting line at %d\n", __func__, pos);
/* Need an extra line struct, check free list first */
if (field->free != NULL) {
@@ -935,8 +906,7 @@ split_line(FIELD *field, bool hard_split
if (field->free != NULL)
field->free->prev = NULL;
} else {
- if ((new_line = (struct _formi_field_lines *)
- malloc(sizeof(struct _formi_field_lines))) == NULL)
+ if ((new_line = malloc(sizeof(*new_line))) == NULL)
return E_SYSTEM_ERROR;
new_line->prev = NULL;
new_line->next = NULL;
@@ -948,13 +918,8 @@ split_line(FIELD *field, bool hard_split
new_line->tabs = NULL;
}
-#ifdef DEBUG
- if (dbg_ok == TRUE) {
- fprintf(dbg,
- "split_line: enter: length = %d, expanded = %d\n",
- row->length, row->expanded);
- }
-#endif
+ _formi_dbg_printf("%s: enter: length = %d, expanded = %d\n", __func__,
+ row->length, row->expanded);
assert((row->length < INT_MAX) && (row->expanded < INT_MAX));
@@ -1043,17 +1008,12 @@ split_line(FIELD *field, bool hard_split
(row->length < INT_MAX) &&
(new_line->length < INT_MAX)));
-#ifdef DEBUG
- if (dbg_ok == TRUE) {
- fprintf(dbg, "split_line: exit: ");
- fprintf(dbg, "row.length = %d, row.expanded = %d, ",
- row->length, row->expanded);
- fprintf(dbg,
- "next_line.length = %d, next_line.expanded = %d, ",
- new_line->length, new_line->expanded);
- fprintf(dbg, "row_count = %d\n", field->row_count + 1);
- }
-#endif
+ _formi_dbg_printf("%s: exit: ", __func__);
+ _formi_dbg_printf("row.length = %d, row.expanded = %d, ",
+ row->length, row->expanded);
+ _formi_dbg_printf("next_line.length = %d, next_line.expanded = %d, ",
+ new_line->length, new_line->expanded);
+ _formi_dbg_printf("row_count = %d\n", field->row_count + 1);
field->row_count++;
*rowp = new_line;
@@ -1662,40 +1622,35 @@ _formi_redraw_field(FORM *form, int fiel
str = &row->string[cur->start_char];
#ifdef DEBUG
- if (_formi_create_dbg_file() == E_OK) {
- fprintf(dbg,
- "redraw_field: start=%d, pre=%d, slen=%d, flen=%d, post=%d, start_char=%d\n",
- start, pre, slen, flen, post, cur->start_char);
- if (str != NULL) {
- if (row->expanded != 0) {
- strncpy(buffer, str, flen);
- } else {
- strcpy(buffer, "(empty)");
- }
+ _formi_dbg_printf(
+ "%s: start=%d, pre=%d, slen=%d, flen=%d, post=%d, "
+ "start_char=%d\n", __func__,
+ start, pre, slen, flen, post, cur->start_char);
+ if (str != NULL) {
+ if (row->expanded != 0) {
+ strncpy(buffer, str, flen);
} else {
- strcpy(buffer, "(null)");
+ strcpy(buffer, "(empty)");
}
- buffer[flen] = '\0';
- fprintf(dbg, "redraw_field: %s\n", buffer);
+ } else {
+ strcpy(buffer, "(null)");
}
+ buffer[flen] = '\0';
+ _formi_dbg_printf("%s: %s\n", __func__, buffer);
#endif
for (i = start + cur->start_char; i < pre; i++)
waddch(form->scrwin, cur->pad);
-#ifdef DEBUG
- fprintf(dbg, "redraw_field: will add %d chars\n",
+ _formi_dbg_printf("%s: will add %d chars\n", __func__,
min(slen, flen));
-#endif
for (i = 0, cpos = cur->start_char; i < min(slen, flen);
i++, str++, cpos++)
{
c = *str;
tab = 0; /* just to shut gcc up */
-#ifdef DEBUG
- fprintf(dbg, "adding char str[%d]=%c\n",
- cpos + cur->start_char, c);
-#endif
+ _formi_dbg_printf("adding char str[%d]=%c\n",
+ cpos + cur->start_char, c);
if (((cur->opts & O_PUBLIC) != O_PUBLIC)) {
if (c == '\t')
tab = add_tab(form, row, cpos,
@@ -1817,28 +1772,23 @@ _formi_add_char(FIELD *field, unsigned i
}
if (_formi_validate_char(field, c) != E_OK) {
-#ifdef DEBUG
- fprintf(dbg, "add_char: char %c failed char validation\n", c);
-#endif
+ _formi_dbg_printf("%s: char %c failed char validation\n",
+ __func__, c);
return E_INVALID_FIELD;
}
if ((c == '\t') && (field->cols <= 8)) {
-#ifdef DEBUG
- fprintf(dbg, "add_char: field too small for a tab\n");
-#endif
+ _formi_dbg_printf("%s: field too small for a tab\n", __func__);
return E_NO_ROOM;
}
-#ifdef DEBUG
- fprintf(dbg, "add_char: pos=%d, char=%c\n", pos, c);
- fprintf(dbg, "add_char enter: xpos=%d, row_pos=%d, start=%d\n",
+ _formi_dbg_printf("%s: pos=%d, char=%c\n", __func__, pos, c);
+ _formi_dbg_printf("%s: xpos=%d, row_pos=%d, start=%d\n", __func__,
field->cursor_xpos, field->row_xpos, field->start_char);
- fprintf(dbg, "add_char enter: length=%d(%d), allocated=%d\n",
+ _formi_dbg_printf("%s: length=%d(%d), allocated=%d\n", __func__,
row->expanded, row->length, row->allocated);
- fprintf(dbg, "add_char enter: %s\n", row->string);
- fprintf(dbg, "add_char enter: buf0_status=%d\n", field->buf0_status);
-#endif
+ _formi_dbg_printf("%s: %s\n", __func__, row->string);
+ _formi_dbg_printf("%s: buf0_status=%d\n", __func__, field->buf0_status);
if (((field->opts & O_BLANK) == O_BLANK) &&
(field->buf0_status == FALSE) &&
((field->row_xpos + field->start_char) == 0)) {
@@ -1980,18 +1930,16 @@ _formi_add_char(FIELD *field, unsigned i
assert((field->cursor_xpos <= field->cols)
&& (field->cursor_ypos < 400000));
-#ifdef DEBUG
- fprintf(dbg, "add_char exit: xpos=%d, row_pos=%d, start=%d\n",
+ _formi_dbg_printf("%s: xpos=%d, row_pos=%d, start=%d\n", __func__,
field->cursor_xpos, field->row_xpos, field->start_char);
- fprintf(dbg, "add_char_exit: length=%d(%d), allocated=%d\n",
+ _formi_dbg_printf("%s: length=%d(%d), allocated=%d\n", __func__,
row->expanded, row->length, row->allocated);
- fprintf(dbg, "add_char exit: ypos=%d, start_line=%p\n",
+ _formi_dbg_printf("%s: ypos=%d, start_line=%p\n", __func__,
field->cursor_ypos, field->start_line);
- fprintf(dbg,"add_char exit: %s\n", row->string);
- fprintf(dbg, "add_char exit: buf0_status=%d\n", field->buf0_status);
- fprintf(dbg, "add_char exit: status = %s\n",
+ _formi_dbg_printf("%s: %s\n", __func__, row->string);
+ _formi_dbg_printf("%s: buf0_status=%d\n", __func__, field->buf0_status);
+ _formi_dbg_printf("%s: status = %s\n", __func__,
(status == E_OK)? "OK" : "FAILED");
-#endif
return status;
}
@@ -2009,11 +1957,9 @@ _formi_set_cursor_xpos(FIELD *field, int
just = field->justification;
pos = field->start_char + field->row_xpos;
-#ifdef DEBUG
- fprintf(dbg,
- "cursor_xpos enter: pos %d, start_char %d, row_xpos %d, xpos %d\n",
- pos, field->start_char, field->row_xpos, field->cursor_xpos);
-#endif
+ _formi_dbg_printf(
+ "%s: pos %d, start_char %d, row_xpos %d, xpos %d\n", __func__,
+ pos, field->start_char, field->row_xpos, field->cursor_xpos);
/*
* make sure we apply the correct justification to non-static
@@ -2097,11 +2043,9 @@ _formi_set_cursor_xpos(FIELD *field, int
break;
}
-#ifdef DEBUG
- fprintf(dbg,
- "cursor_xpos exit: pos %d, start_char %d, row_xpos %d, xpos %d\n",
- pos, field->start_char, field->row_xpos, field->cursor_xpos);
-#endif
+ _formi_dbg_printf(
+ "%s: pos %d, start_char %d, row_xpos %d, xpos %d\n", __func__,
+ pos, field->start_char, field->row_xpos, field->cursor_xpos);
return E_OK;
}
@@ -2125,20 +2069,19 @@ _formi_manipulate_field(FORM *form, int
if (cur->cur_line->string == NULL)
return E_REQUEST_DENIED;
-#ifdef DEBUG
- fprintf(dbg, "entry: request is REQ_%s\n", reqs[c - REQ_MIN_REQUEST]);
- fprintf(dbg,
- "entry: xpos=%d, row_pos=%d, start_char=%d, length=%d, allocated=%d\n",
- cur->cursor_xpos, cur->row_xpos, cur->start_char,
- cur->cur_line->length, cur->cur_line->allocated);
- fprintf(dbg, "entry: start_line=%p, ypos=%d\n", cur->start_line,
- cur->cursor_ypos);
- fprintf(dbg, "entry: string=");
+ _formi_dbg_printf("%s: request is REQ_%s\n",
+ __func__, reqs[c - REQ_MIN_REQUEST]);
+ _formi_dbg_printf(
+ "%s: xpos=%d, row_pos=%d, start_char=%d, length=%d, allocated=%d\n",
+ __func__, cur->cursor_xpos, cur->row_xpos, cur->start_char,
+ cur->cur_line->length, cur->cur_line->allocated);
+ _formi_dbg_printf("%s: start_line=%p, ypos=%d\n", __func__,
+ cur->start_line, cur->cursor_ypos);
if (cur->cur_line->string == NULL)
- fprintf(dbg, "(null)\n");
+ _formi_dbg_printf("%s: string=(null)\n", __func__);
else
- fprintf(dbg, "\"%s\"\n", cur->cur_line->string);
-#endif
+ _formi_dbg_printf("%s: string=\"%s\"\n", __func__,
+ cur->cur_line->string);
/* Cannot manipulate a null string! */
if (cur->cur_line->string == NULL)
@@ -2981,17 +2924,16 @@ _formi_manipulate_field(FORM *form, int
return 0;
}
-#ifdef DEBUG
- fprintf(dbg,
- "exit: cursor_xpos=%d, row_xpos=%d, start_char=%d, length=%d, allocated=%d\n",
- cur->cursor_xpos, cur->row_xpos, cur->start_char,
- cur->cur_line->length, cur->cur_line->allocated);
- fprintf(dbg, "exit: start_line=%p, ypos=%d\n", cur->start_line,
- cur->cursor_ypos);
- fprintf(dbg, "exit: string=\"%s\"\n", cur->cur_line->string);
+ _formi_dbg_printf(
+ "%s: cursor_xpos=%d, row_xpos=%d, start_char=%d, length=%d, "
+ "allocated=%d\n", __func__, cur->cursor_xpos, cur->row_xpos,
+ cur->start_char, cur->cur_line->length, cur->cur_line->allocated);
+ _formi_dbg_printf("%s: start_line=%p, ypos=%d\n", __func__,
+ cur->start_line, cur->cursor_ypos);
+ _formi_dbg_printf("%s: string=\"%s\"\n", __func__,
+ cur->cur_line->string);
assert ((cur->cursor_xpos < INT_MAX) && (cur->row_xpos < INT_MAX)
&& (cur->cursor_xpos >= cur->row_xpos));
-#endif
return 1;
}
@@ -3415,13 +3357,9 @@ _formi_tab_expanded_length(char *str, un
len++;
}
-#ifdef DEBUG
- if (dbg != NULL) {
- fprintf(dbg,
- "tab_expanded: start=%d, end=%d, expanded=%d (diff=%d)\n",
- start, end, (len - start_len), (end - start));
- }
-#endif
+ _formi_dbg_printf(
+ "%s: start=%d, end=%d, expanded=%d (diff=%d)\n", __func__,
+ start, end, (len - start_len), (end - start));
return (len - start_len);
}
Index: src/lib/libform/internals.h
diff -u src/lib/libform/internals.h:1.10 src/lib/libform/internals.h:1.11
--- src/lib/libform/internals.h:1.10 Wed Nov 24 06:57:09 2004
+++ src/lib/libform/internals.h Wed Mar 9 14:47:13 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: internals.h,v 1.10 2004/11/24 11:57:09 blymn Exp $ */
+/* $NetBSD: internals.h,v 1.11 2016/03/09 19:47:13 christos Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn
@@ -35,10 +35,6 @@
#ifndef FORMI_INTERNALS_H
#define FORMI_INTERNALS_H 1
-#ifdef DEBUG
-extern FILE *dbg;
-#endif
-
/* direction definitions for _formi_pos_new_field */
#define _FORMI_BACKWARD 1
#define _FORMI_FORWARD 2
@@ -141,11 +137,9 @@ int
_formi_sync_buffer(FIELD *field);
#ifdef DEBUG
-int
-_formi_create_dbg_file(void);
+void _formi_dbg_printf(const char *, ...) __printflike(1, 2);
+#else
+#define _formi_dbg_printf(a,...)
#endif /* DEBUG */
#endif
-
-
-
Index: src/lib/libform/type_ipv4.c
diff -u src/lib/libform/type_ipv4.c:1.10 src/lib/libform/type_ipv4.c:1.11
--- src/lib/libform/type_ipv4.c:1.10 Wed Jan 17 18:24:22 2007
+++ src/lib/libform/type_ipv4.c Wed Mar 9 14:47:13 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: type_ipv4.c,v 1.10 2007/01/17 23:24:22 hubertf Exp $ */
+/* $NetBSD: type_ipv4.c,v 1.11 2016/03/09 19:47:13 christos Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: type_ipv4.c,v 1.10 2007/01/17 23:24:22 hubertf Exp $");
+__RCSID("$NetBSD: type_ipv4.c,v 1.11 2016/03/09 19:47:13 christos Exp $");
#include <string.h>
#include <stdlib.h>
@@ -72,7 +72,7 @@ ipv4_check_field(FIELD *field, char *arg
return FALSE;
#ifdef DEBUG
- fprintf(dbg, "ipv4_check_field: enter with args of %s\n", keeper);
+ _formi_dbg_printf("%s: enter with args of %s\n", __func__, keeper);
#endif
style = FORMI_DOTTED_QUAD;
buf = keeper;
@@ -168,8 +168,8 @@ ipv4_check_field(FIELD *field, char *arg
set_field_buffer(field, 1, buf1);
#ifdef DEBUG
- fprintf(dbg, "ipv4_check_field: buf0 set to %s\n", buf);
- fprintf(dbg, "ipv4_check_field: buf1 set to %s\n", buf1);
+ _formi_dbg_printf("%s: buf0 set to %s\n", __func__, buf);
+ _formi_dbg_printf("%s: buf1 set to %s\n", __func__, buf1);
#endif
free(buf);
free(buf1);
Index: src/lib/libform/post.c
diff -u src/lib/libform/post.c:1.9 src/lib/libform/post.c:1.10
--- src/lib/libform/post.c:1.9 Sat Mar 8 19:57:19 2003
+++ src/lib/libform/post.c Wed Mar 9 14:47:13 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: post.c,v 1.9 2003/03/09 00:57:19 lukem Exp $ */
+/* $NetBSD: post.c,v 1.10 2016/03/09 19:47:13 christos Exp $ */
/*-
* Copyright (c) 1998-2000 Brett Lymn
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: post.c,v 1.9 2003/03/09 00:57:19 lukem Exp $");
+__RCSID("$NetBSD: post.c,v 1.10 2016/03/09 19:47:13 christos Exp $");
#include "form.h"
#include "internals.h"
@@ -63,11 +63,6 @@ post_form(FORM *form)
return E_NO_ROOM;
}
-#ifdef DEBUG
- if (_formi_create_dbg_file() != E_OK)
- return E_SYSTEM_ERROR;
-#endif
-
form->in_init = 1;
if (form->form_init != NULL)
form->form_init(form);
Index: src/lib/libform/type_enum.c
diff -u src/lib/libform/type_enum.c:1.11 src/lib/libform/type_enum.c:1.12
--- src/lib/libform/type_enum.c:1.11 Thu May 13 13:52:12 2010
+++ src/lib/libform/type_enum.c Wed Mar 9 14:47:13 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: type_enum.c,v 1.11 2010/05/13 17:52:12 tnozaki Exp $ */
+/* $NetBSD: type_enum.c,v 1.12 2016/03/09 19:47:13 christos Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: type_enum.c,v 1.11 2010/05/13 17:52:12 tnozaki Exp $");
+__RCSID("$NetBSD: type_enum.c,v 1.12 2016/03/09 19:47:13 christos Exp $");
#include <ctype.h>
#include <stdlib.h>
@@ -87,39 +87,28 @@ create_enum_args(va_list *args)
enum_args *new;
char **choices;
- new = (enum_args *) malloc(sizeof(enum_args));
-
- if (new != NULL) {
- new->choices = va_arg(*args, char **);
- new->ignore_case = (va_arg(*args, int)) ? TRUE : FALSE;
- new->exact = (va_arg(*args, int)) ? TRUE : FALSE;
-
-#ifdef DEBUG
- if (_formi_create_dbg_file() != E_OK)
- return NULL;
- fprintf(dbg,
- "create_enum_args: ignore_case %d, no_blanks %d\n",
- new->ignore_case, new->exact);
-#endif
-
- /* count the choices we have */
- choices = new->choices;
- new->num_choices = 0;
- while (*choices != NULL) {
-#ifdef DEBUG
- fprintf(dbg, "create_enum_args: choice[%d] = \'%s\'\n",
- new->num_choices,
- new->choices[new->num_choices]);
-#endif
- new->num_choices++;
- choices++;
- }
-#ifdef DEBUG
- fprintf(dbg, "create_enum_args: have %d choices\n",
- new->num_choices);
-#endif
-
+ new = malloc(sizeof(*new));
+ if (new == NULL)
+ return NULL;
+
+ new->choices = va_arg(*args, char **);
+ new->ignore_case = (va_arg(*args, int)) ? TRUE : FALSE;
+ new->exact = (va_arg(*args, int)) ? TRUE : FALSE;
+
+ _formi_dbg_printf("%s: ignore_case %d, no_blanks %d\n", __func__,
+ new->ignore_case, new->exact);
+
+ /* count the choices we have */
+ choices = new->choices;
+ new->num_choices = 0;
+ while (*choices != NULL) {
+ _formi_dbg_printf("%s: choice[%u] = \'%s\'\n", __func__,
+ new->num_choices, new->choices[new->num_choices]);
+ new->num_choices++;
+ choices++;
}
+ _formi_dbg_printf("%s: have %u choices\n", __func__,
+ new->num_choices);
return (void *) new;
}
@@ -171,9 +160,7 @@ match_enum(char **choices, unsigned num_
else
blen = 0;
-#ifdef DEBUG
- fprintf(dbg, "match_enum: start %d, blen %d\n", start, blen);
-#endif
+ _formi_dbg_printf("%s: start %u, blen %u\n", __func__, start, blen);
for (i = 0; i < num_choices; i++) {
enum_start = _formi_skip_blanks(choices[i], 0);
enum_end = trim_blanks(choices[i]);
@@ -184,12 +171,10 @@ match_enum(char **choices, unsigned num_
else
elen = 0;
-#ifdef DEBUG
- fprintf(dbg, "match_enum: checking choice \'%s\'\n",
+ _formi_dbg_printf("%s: checking choice \'%s\'\n", __func__,
choices[i]);
- fprintf(dbg, "match_enum: enum_start %d, elen %d\n",
+ _formi_dbg_printf("%s: enum_start %u, elen %u\n", __func__,
enum_start, elen);
-#endif
/* don't bother if we are after an exact match
* and the test length is not equal to the enum
@@ -217,10 +202,8 @@ match_enum(char **choices, unsigned num_
(size_t) blen) == 0) ?
TRUE : FALSE;
-#ifdef DEBUG
- fprintf(dbg, "match_enum: curmatch is %s\n",
+ _formi_dbg_printf("%s: curmatch is %s\n", __func__,
(cur_match == TRUE)? "TRUE" : "FALSE");
-#endif
if (cur_match == TRUE) {
*match_num = i;
@@ -229,9 +212,7 @@ match_enum(char **choices, unsigned num_
}
-#ifdef DEBUG
- fprintf(dbg, "match_enum: no match found\n");
-#endif
+ _formi_dbg_printf("%s: no match found\n", __func__);
return FALSE;
}
@@ -251,12 +232,10 @@ enum_check_field(FIELD *field, char *arg
if (match_enum(ta->choices, ta->num_choices, ta->ignore_case,
ta->exact, args, &match_num) == TRUE) {
-#ifdef DEBUG
- fprintf(dbg, "enum_check_field: We matched, match_num %d\n",
- match_num);
- fprintf(dbg, "enum_check_field: buffer is \'%s\'\n",
- ta->choices[match_num]);
-#endif
+ _formi_dbg_printf("%s: We matched, match_num %u\n", __func__,
+ match_num);
+ _formi_dbg_printf("%s: buffer is \'%s\'\n", __func__,
+ ta->choices[match_num]);
set_field_buffer(field, 0, ta->choices[match_num]);
return TRUE;
}
@@ -278,31 +257,23 @@ next_enum(FIELD *field, char *args)
ta = (enum_args *) (void *) field->args;
-#ifdef DEBUG
- fprintf(dbg, "next_enum: attempt to match \'%s\'\n", args);
-#endif
+ _formi_dbg_printf("%s: attempt to match \'%s\'\n", __func__, args);
if (match_enum(ta->choices, ta->num_choices, ta->ignore_case,
ta->exact, args, &cur_choice) == FALSE) {
-#ifdef DEBUG
- fprintf(dbg, "next_enum: match failed\n");
-#endif
+ _formi_dbg_printf("%s: match failed\n", __func__);
return FALSE;
}
-#ifdef DEBUG
- fprintf(dbg, "next_enum: cur_choice is %d\n", cur_choice);
-#endif
+ _formi_dbg_printf("%s: cur_choice is %u\n", __func__, cur_choice);
cur_choice++;
if (cur_choice >= ta->num_choices)
cur_choice = 0;
-#ifdef DEBUG
- fprintf(dbg, "next_enum: cur_choice is %d on exit\n",
- cur_choice);
-#endif
+ _formi_dbg_printf("%s: cur_choice is %u on exit\n", __func__,
+ cur_choice);
set_field_buffer(field, 0, ta->choices[cur_choice]);
return TRUE;
@@ -322,29 +293,22 @@ prev_enum(FIELD *field, char *args)
ta = (enum_args *) (void *) field->args;
-#ifdef DEBUG
- fprintf(dbg, "prev_enum: attempt to match \'%s\'\n", args);
-#endif
+ _formi_dbg_printf("%s: attempt to match \'%s\'\n", __func__, args);
if (match_enum(ta->choices, ta->num_choices, ta->ignore_case,
ta->exact, args, &cur_choice) == FALSE) {
-#ifdef DEBUG
- fprintf(dbg, "prev_enum: match failed\n");
-#endif
+ _formi_dbg_printf("%s: match failed\n", __func__);
return FALSE;
}
-#ifdef DEBUG
- fprintf(dbg, "prev_enum: cur_choice is %d\n", cur_choice);
-#endif
+ _formi_dbg_printf("%s: cur_choice is %u\n", __func__, cur_choice);
if (cur_choice == 0)
cur_choice = ta->num_choices - 1;
else
cur_choice--;
-#ifdef DEBUG
- fprintf(dbg, "prev_enum: cur_choice is %d on exit\n", cur_choice);
-#endif
+ _formi_dbg_printf("%s: cur_choice is %u on exit\n",
+ __func__, cur_choice);
set_field_buffer(field, 0, ta->choices[cur_choice]);
return TRUE;