Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libform PR/50919: David Binderman: Re-do all the debug s...



details:   https://anonhg.NetBSD.org/src/rev/29af3141ebf2
branches:  trunk
changeset: 344010:29af3141ebf2
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Mar 09 19:47:13 2016 +0000

description:
PR/50919: David Binderman: Re-do all the debug stuff in a more sustainable way.

diffstat:

 lib/libform/field.c     |   42 ++----
 lib/libform/form.c      |    8 +-
 lib/libform/internals.c |  274 ++++++++++++++++++-----------------------------
 lib/libform/internals.h |   14 +-
 lib/libform/post.c      |    9 +-
 lib/libform/type_enum.c |  116 +++++++-------------
 lib/libform/type_ipv4.c |   10 +-
 7 files changed, 176 insertions(+), 297 deletions(-)

diffs (truncated from 893 to 300 lines):

diff -r 4efad852d4a1 -r 29af3141ebf2 lib/libform/field.c
--- a/lib/libform/field.c       Wed Mar 09 16:12:14 2016 +0000
+++ b/lib/libform/field.c       Wed Mar 09 19:47:13 2016 +0000
@@ -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
  *                         (blymn%baea.com.au@localhost, brett_lymn%yahoo.com.au@localhost)
@@ -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 @@
            && ((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);
+               _formi_dbg_printf("%s: string=%s, len = %d\n", __func__,
+                   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=(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 @@
        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;
 }
diff -r 4efad852d4a1 -r 29af3141ebf2 lib/libform/form.c
--- a/lib/libform/form.c        Wed Mar 09 16:12:14 2016 +0000
+++ b/lib/libform/form.c        Wed Mar 09 19:47:13 2016 +0000
@@ -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 @@
                }
        }
        
-#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);
 
diff -r 4efad852d4a1 -r 29af3141ebf2 lib/libform/internals.c
--- a/lib/libform/internals.c   Wed Mar 09 16:12:14 2016 +0000
+++ b/lib/libform/internals.c   Wed Mar 09 19:47:13 2016 +0000
@@ -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 @@
 #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 @@
  *  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 @@
  * 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;
+
+       if (dbg == NULL && (dbg = fopen(dbg_file, "w")) == NULL) {
+               warn("Cannot open debug file `%s'", dbg_file);
+               return;
        }
-
-       return E_OK;
+       va_start(ap, fmt);
+       vfprintf(dbg, fmt, ap);
+       va_end(ap);
 }
 #endif
 
@@ -709,18 +713,9 @@
        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 @@
                        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 @@
                  /* 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 @@
                        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 @@
 
                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 @@
        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 @@
        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);
 



Home | Main Index | Thread Index | Old Index