From e09387a550b0224ee76204d750f57a05fd1aa719 Mon Sep 17 00:00:00 2001 From: Rutger Hofman Date: Tue, 5 May 2009 16:01:50 +0000 Subject: [PATCH] start replacing calls to printf() with calls to urj_log(), for starters with src/part git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1566 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- urjtag/include/urjtag/part.h | 9 +++++-- urjtag/src/bsdl/bsdl_bison.y | 2 +- urjtag/src/cmd/cmd_bus.c | 1 - urjtag/src/cmd/cmd_detect.c | 3 +-- urjtag/src/cmd/cmd_signal.c | 7 ++---- urjtag/src/part/bsbit.c | 4 ++-- urjtag/src/part/instruction.c | 7 +++++- urjtag/src/part/part.c | 44 ++++++++++++++++++++++++----------- urjtag/src/part/signal.c | 13 +++++++---- 9 files changed, 57 insertions(+), 33 deletions(-) diff --git a/urjtag/include/urjtag/part.h b/urjtag/include/urjtag/part.h index d6e6e3d5..23faab6e 100644 --- a/urjtag/include/urjtag/part.h +++ b/urjtag/include/urjtag/part.h @@ -60,8 +60,13 @@ urj_data_register_t *urj_part_find_data_register (urj_part_t *p, urj_part_signal_t *urj_part_find_signal (urj_part_t *p, const char *signalname); void urj_part_set_instruction (urj_part_t *p, const char *iname); -void urj_part_set_signal (urj_part_t *p, urj_part_signal_t *s, int out, - int val); +/** + * @return URJ_STATUS_FAIL on error; URJ_STATUS_OK on success + */ +int urj_part_set_signal (urj_part_t *p, urj_part_signal_t *s, int out, int val); +/** + * @return -1 on error; >= 0 for success + */ int urj_part_get_signal (urj_part_t *p, urj_part_signal_t *s); void urj_part_print (urj_part_t *p); /** diff --git a/urjtag/src/bsdl/bsdl_bison.y b/urjtag/src/bsdl/bsdl_bison.y index fc0db6e9..38a52906 100644 --- a/urjtag/src/bsdl/bsdl_bison.y +++ b/urjtag/src/bsdl/bsdl_bison.y @@ -515,7 +515,7 @@ Safe_Value : IDENTIFIER | DECIMAL_NUMBER { char *tmp; - /* @@@@ ToDo check malloc result RFHH */ + /* @@@@ RFHH check malloc result */ tmp = malloc (2); snprintf (tmp, 2, "%i", $1); tmp[1] = '\0'; diff --git a/urjtag/src/cmd/cmd_bus.c b/urjtag/src/cmd/cmd_bus.c index ae6816ae..1ade97b3 100644 --- a/urjtag/src/cmd/cmd_bus.c +++ b/urjtag/src/cmd/cmd_bus.c @@ -57,7 +57,6 @@ cmd_bus_run (urj_chain_t *chain, char *params[]) if (urj_bus_buses_set (n) != URJ_STATUS_OK) { - printf ("%s\n", urj_error_describe()); urj_error_reset(); } diff --git a/urjtag/src/cmd/cmd_detect.c b/urjtag/src/cmd/cmd_detect.c index c3009353..006f30ae 100644 --- a/urjtag/src/cmd/cmd_detect.c +++ b/urjtag/src/cmd/cmd_detect.c @@ -45,9 +45,8 @@ cmd_detect_run (urj_chain_t *chain, char *params[]) if (urj_tap_detect (chain) != URJ_STATUS_OK) { - printf ("%s\n", urj_error_describe()); urj_error_reset(); - return -1; + return 1; } return 1; diff --git a/urjtag/src/cmd/cmd_signal.c b/urjtag/src/cmd/cmd_signal.c index 4dd01b12..16327489 100644 --- a/urjtag/src/cmd/cmd_signal.c +++ b/urjtag/src/cmd/cmd_signal.c @@ -60,11 +60,9 @@ cmd_signal_run (urj_chain_t *chain, char *params[]) { printf ("Defining pin for signal %s\n", s->name); - if (urj_part_signal_redefine_pin(chain, s, params[2]) != URJ_STATUS_OK) - { - printf ("%s\n", urj_error_describe()); + if (urj_part_signal_redefine_pin(chain, s, + params[2]) != URJ_STATUS_OK) urj_error_reset(); - } return 1; } else @@ -83,7 +81,6 @@ cmd_signal_run (urj_chain_t *chain, char *params[]) s = urj_part_signal_define(chain, params[1]); } if (s == NULL) { - printf ("%s\n", urj_error_describe()); urj_error_reset(); return 1; } diff --git a/urjtag/src/part/bsbit.c b/urjtag/src/part/bsbit.c index 53e8ca1f..4dbfde10 100644 --- a/urjtag/src/part/bsbit.c +++ b/urjtag/src/part/bsbit.c @@ -89,7 +89,7 @@ urj_part_bsbit_alloc_control (urj_part_t *part, int bit, const char *name, b->bit = bit; b->type = type; b->signal = signal; - b->safe = safe; + b->safe = (safe == 1); b->control = -1; part->bsbits[bit] = b; @@ -115,7 +115,7 @@ urj_part_bsbit_alloc_control (urj_part_t *part, int bit, const char *name, { b->control = ctrl_num; b->control_value = ctrl_val; - b->control_state = URJ_BSBIT_STATE_Z; + b->control_state = ctrl_state; } return URJ_STATUS_OK; diff --git a/urjtag/src/part/instruction.c b/urjtag/src/part/instruction.c index 88e0f939..805d0bcd 100644 --- a/urjtag/src/part/instruction.c +++ b/urjtag/src/part/instruction.c @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -41,10 +42,14 @@ urj_part_instruction_alloc (const char *name, int len, const char *val) i = malloc (sizeof *i); if (!i) + { + urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "malloc(%zd) fails", sizeof *i); return NULL; + } if (strlen (name) > URJ_INSTRUCTION_MAXLEN_INSTRUCTION) - printf (_("Warning: Instruction name too long\n")); + urj_log (URJ_LOG_LEVEL_WARNINGS, + _("Warning: Instruction name too long\n")); strncpy (i->name, name, URJ_INSTRUCTION_MAXLEN_INSTRUCTION); i->name[URJ_INSTRUCTION_MAXLEN_INSTRUCTION] = '\0'; diff --git a/urjtag/src/part/part.c b/urjtag/src/part/part.c index c56eba83..1e029a26 100644 --- a/urjtag/src/part/part.c +++ b/urjtag/src/part/part.c @@ -42,7 +42,11 @@ urj_part_alloc (const urj_tap_register_t *id) { urj_part_t *p = malloc (sizeof *p); if (!p) + { + urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "malloc(%zd) fails", sizeof *p); return NULL; + } + p->alias = NULL; /* djf */ p->id = urj_tap_register_duplicate (id); p->manufacturer[0] = '\0'; @@ -187,21 +191,24 @@ urj_part_set_instruction (urj_part_t *p, const char *iname) p->active_instruction = urj_part_find_instruction (p, iname); } -void +int urj_part_set_signal (urj_part_t *p, urj_part_signal_t *s, int out, int val) { urj_data_register_t *bsr; if (!p || !s) - return; + { + urj_error_set (URJ_ERROR_INVALID, "part or signal is NULL"); + return URJ_STATUS_FAIL; + } /* search for Boundary Scan Register */ bsr = urj_part_find_data_register (p, "BSR"); if (!bsr) { - printf (_("%s(%s:%d) Boundary Scan Register (BSR) not found\n"), - __FUNCTION__, __FILE__, __LINE__); - return; + urj_error_set (URJ_ERROR_NOTFOUND, + _("Boundary Scan Register (BSR) not found\n")); + return URJ_STATUS_FAIL; } /* setup signal */ @@ -210,8 +217,9 @@ urj_part_set_signal (urj_part_t *p, urj_part_signal_t *s, int out, int val) int control; if (!s->output) { - printf (_("signal '%s' cannot be set as output\n"), s->name); - return; + urj_error_set (URJ_ERROR_INVALID, + _("signal '%s' cannot be set as output\n"), s->name); + return URJ_STATUS_FAIL; } bsr->in->data[s->output->bit] = val & 1; @@ -224,13 +232,16 @@ urj_part_set_signal (urj_part_t *p, urj_part_signal_t *s, int out, int val) { if (!s->input) { - printf (_("signal '%s' cannot be set as input\n"), s->name); - return; + urj_error_set (URJ_ERROR_INVALID, + _("signal '%s' cannot be set as input\n"), s->name); + return URJ_STATUS_FAIL; } if (s->output) bsr->in->data[s->output->control] = p->bsbits[s->output->bit]->control_value; } + + return URJ_STATUS_OK; } int @@ -239,20 +250,24 @@ urj_part_get_signal (urj_part_t *p, urj_part_signal_t *s) urj_data_register_t *bsr; if (!p || !s) + { + urj_error_set (URJ_ERROR_INVALID, "part or signal is NULL"); return -1; + } /* search for Boundary Scan Register */ bsr = urj_part_find_data_register (p, "BSR"); if (!bsr) { - printf (_("%s(%s:%d) Boundary Scan Register (BSR) not found\n"), - __FUNCTION__, __FILE__, __LINE__); + urj_error_set (URJ_ERROR_NOTFOUND, + _("Boundary Scan Register (BSR) not found\n")); return -1; } if (!s->input) { - printf (_("signal '%s' is not input signal\n"), s->name); + urj_error_set (URJ_ERROR_INVALID, + _("signal '%s' is not input signal\n"), s->name); return -1; } @@ -284,7 +299,8 @@ urj_part_print (urj_part_t *p) instruction = _("(none)"); if (dr == NULL) dr = _("(none)"); - printf (format, p->manufacturer, p->part, p->stepping, instruction, dr); + urj_log (URJ_LOG_LEVEL_NORMAL, format, p->manufacturer, p->part, + p->stepping, instruction, dr); } @@ -422,7 +438,7 @@ urj_part_parts_print (urj_parts_t *ps) if (!p) continue; - printf (_(" %3d "), i); + urj_log (URJ_LOG_LEVEL_NORMAL, _(" %3d "), i); urj_part_print (p); } } diff --git a/urjtag/src/part/signal.c b/urjtag/src/part/signal.c index 53f8ee91..6f3af3d0 100644 --- a/urjtag/src/part/signal.c +++ b/urjtag/src/part/signal.c @@ -37,7 +37,7 @@ urj_part_signal_alloc (const char *name) urj_part_signal_t *s = malloc (sizeof *s); if (!s) { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "malloc fails"); + urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "malloc(%zd) fails", sizeof *s); return NULL; } @@ -45,7 +45,7 @@ urj_part_signal_alloc (const char *name) if (!s->name) { free (s); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "malloc fails"); + urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "strdup(%s) fails", name); return NULL; } s->pin = NULL; /* djf hack pin number */ @@ -72,7 +72,8 @@ urj_part_salias_alloc (const char *name, const urj_part_signal_t *signal) if (sa == NULL) { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "malloc fails"); + urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "malloc(%zd) fails", + sizeof *sa); return NULL; } @@ -80,7 +81,7 @@ urj_part_salias_alloc (const char *name, const urj_part_signal_t *signal) if (sa->name == NULL) { free (sa); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "malloc fails"); + urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "strdup(%s) fails", name); return NULL; } sa->next = NULL; @@ -124,7 +125,9 @@ urj_part_signal_define_pin (urj_chain_t *chain, const char *signal_name, s->pin = strdup (pin_name); if (s->pin == NULL) { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "strdup fails"); + urj_part_signal_free (s); + urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "strdup(%s) fails", + pin_name); return NULL; } }