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
master
Rutger Hofman 16 years ago
parent ea6e5afaaf
commit e09387a550

@ -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);
/**

@ -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';

@ -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();
}

@ -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;

@ -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;
}

@ -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;

@ -28,6 +28,7 @@
#include <stdio.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/tap_register.h>
#include <urjtag/part_instruction.h>
@ -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';

@ -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);
}
}

@ -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;
}
}

Loading…
Cancel
Save