diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index 3421226d..32237e6b 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -1,5 +1,10 @@ 2009-05-05 Rutger Hofman + * src/lib/getline.c, src/lib/getdelim.c: remove because unused + + * src/global/parse.c: replace calls to printf() with calls to urj_log() and + urj_error_set() + * include/urjtag/jim.h, include/urjtag/jim/some_cpu.h, src/jim/tap.c, src/jim/jim_tap.c, src/jim/some_cpu.c, src/jim/intel_28f800b3.c: replace calls to printf() with calls to urj_log() and urj_error_set() diff --git a/urjtag/Makefile.rules b/urjtag/Makefile.rules index 3faa5789..efc27cc6 100644 --- a/urjtag/Makefile.rules +++ b/urjtag/Makefile.rules @@ -22,6 +22,8 @@ # Written by Marcel Telka , 2003, 2004. # +# CFLAGS += -Werror + LINT_FLAGS = LINT_FLAGS += -warnposixheaders LINT_FLAGS += +boolint diff --git a/urjtag/configure.ac b/urjtag/configure.ac index 0f58723d..770bc617 100644 --- a/urjtag/configure.ac +++ b/urjtag/configure.ac @@ -104,7 +104,6 @@ else fi fi -AC_CHECK_FUNCS(getline getdelim) AC_CHECK_FUNCS(swprintf) AC_CHECK_FUNC(clock_gettime, [], [ AC_CHECK_LIB(rt, clock_gettime) ]) diff --git a/urjtag/include/urjtag/cmd.h b/urjtag/include/urjtag/cmd.h index b7826d1b..a81d36ca 100644 --- a/urjtag/include/urjtag/cmd.h +++ b/urjtag/include/urjtag/cmd.h @@ -36,7 +36,21 @@ #include "types.h" +/** + * @return: + * 1 on unrecognized command + * otherwise: result from command implementation + * 1 success or library function error + * 0 + * -1 command syntax error: wrong number of arguments, + * illegal arguments + */ int urj_cmd_run (urj_chain_t *chain, char *params[]); +/** + * @return + * malloc'ed value. The caller is responsible for freeing it. + * NULL for malloc failure or end of command list. + */ char *urj_cmd_find_next (const char *text, int state); /* @@@@ RFHH candidate to become local in src/cmd/: */ int urj_cmd_params (char *params[]); diff --git a/urjtag/include/urjtag/parse.h b/urjtag/include/urjtag/parse.h index 47a371fa..76a976fd 100644 --- a/urjtag/include/urjtag/parse.h +++ b/urjtag/include/urjtag/parse.h @@ -29,8 +29,17 @@ #include "types.h" +/** + * @return -1 on failure; see urj_parse_line() otherwise + */ int urj_parse_file (urj_chain_t *chain, const char *filename); +/** + * @return 1 on failure; urj_cmd_run() otherwise + */ int urj_parse_line (urj_chain_t *chain, char *line); +/** + * @return see urj_parse_line() + */ int urj_parse_stream (urj_chain_t *chain, FILE *f); #endif /* URJ_PARSE_H */ diff --git a/urjtag/src/apps/jtag/jtag.c b/urjtag/src/apps/jtag/jtag.c index b249b71d..67fce4a1 100644 --- a/urjtag/src/apps/jtag/jtag.c +++ b/urjtag/src/apps/jtag/jtag.c @@ -53,10 +53,6 @@ #include #include -#ifndef HAVE_GETLINE -ssize_t urj_lib_getline (char **lineptr, size_t *n, FILE *stream); -#endif - static int urj_interactive = 0; #define JTAGDIR ".jtag" diff --git a/urjtag/src/cmd/cmd_debug.c b/urjtag/src/cmd/cmd_debug.c index 0a0c4509..ada1b2a0 100644 --- a/urjtag/src/cmd/cmd_debug.c +++ b/urjtag/src/cmd/cmd_debug.c @@ -43,7 +43,7 @@ cmd_debug_run (urj_chain_t *chain, char *params[]) return -1; if (urj_cmd_get_number (params[1], &i)) - return 1; + return -1; urj_debug_mode = i; return 1; diff --git a/urjtag/src/global/parse.c b/urjtag/src/global/parse.c index a9543621..6dc5507c 100644 --- a/urjtag/src/global/parse.c +++ b/urjtag/src/global/parse.c @@ -32,6 +32,8 @@ #include #include +#include +#include #include #include #include @@ -59,7 +61,7 @@ urj_parse_line (urj_chain_t *chain, char *line) sline = malloc (l + 1); if (sline == NULL) { - printf (_("Out of memory\n")); + urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "malloc(%d) fails", l + 1); return 1; } @@ -97,7 +99,8 @@ urj_parse_line (urj_chain_t *chain, char *line) a = malloc ((tcnt + 1) * sizeof (char *)); if (a == NULL) { - fprintf (stderr, _("Out of memory\n")); + urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "malloc(%zd) fails", + (tcnt + 1) * sizeof (char *)); return 1; } @@ -112,10 +115,10 @@ urj_parse_line (urj_chain_t *chain, char *line) a[tcnt] = NULL; r = urj_cmd_run (chain, a); - if (urj_debug_mode & 1) - printf ("Return in urj_parse_line r=%d\n", r); + urj_log (URJ_LOG_LEVEL_DEBUG, "Return in urj_parse_line r=%d\n", r); free (a); free (sline); + return r; } @@ -150,9 +153,9 @@ urj_parse_stream (urj_chain_t *chain, FILE *f) inputline[i] = '\0'; lnr++; if (clip && !found_comment) - fprintf (stdout, - "Warning: line %d exceeds %d characters, clipped\n", lnr, - (int) sizeof (inputline) - 1); + urj_log (URJ_LOG_LEVEL_WARNINGS, + "line %d exceeds %zd characters, clipped\n", lnr, + sizeof (inputline) - 1); go = urj_parse_line (chain, inputline); urj_tap_chain_flush (chain); } @@ -178,7 +181,7 @@ urj_parse_file (urj_chain_t *chain, const char *filename) go = urj_parse_stream (chain, f); fclose (f); - if (urj_debug_mode & 1) - printf ("File Closed gp=%d\n", go); + urj_log (URJ_LOG_LEVEL_DEBUG, "File Closed go=%d\n", go); + return go; } diff --git a/urjtag/src/lib/Makefile.am b/urjtag/src/lib/Makefile.am index 70a4588a..006ab6a7 100644 --- a/urjtag/src/lib/Makefile.am +++ b/urjtag/src/lib/Makefile.am @@ -40,7 +40,5 @@ libiberty_sources = endif libjtaglib_la_SOURCES = \ - getdelim.c \ - getline.c \ fclock.c \ $(libiberty_sources) diff --git a/urjtag/src/lib/getdelim.c b/urjtag/src/lib/getdelim.c deleted file mode 100644 index e140f857..00000000 --- a/urjtag/src/lib/getdelim.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 2003 ETC s.r.o. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - * Written by Marcel Telka , 2003. - * - */ - -#include - -#include -#include -#include - -#ifndef HAVE_GETDELIM - -#define GETDELIM_BUFFER 128 - -ssize_t -urj_lib_getdelim (char **lineptr, size_t *n, int delimiter, FILE *stream) -{ - char *p; - int c; - size_t len = 0; - - if (!lineptr || !n || (!*lineptr && *n)) - return -1; - - /* allocate initial buffer */ - if (!*lineptr || !*n) - { - char *np; - np = realloc (*lineptr, GETDELIM_BUFFER); - if (!np) - return -1; - *n = GETDELIM_BUFFER; - *lineptr = np; - } - - p = *lineptr; - - /* read characters from stream */ - while ((c = fgetc (stream)) != EOF) - { - if (len >= *n) - { - char *np = realloc (*lineptr, *n * 2); - if (!np) - return -1; - p = np + (p - *lineptr); - *lineptr = np; - *n *= 2; - } - *p++ = (char) c; - len++; - if (delimiter == c) - break; - } - - /* end of file without any bytes read */ - if ((c == EOF) && (len == 0)) - return -1; - - /* trailing '\0' */ - if (len >= *n) - { - char *np = realloc (*lineptr, *n + 1); - if (!np) - return -1; - p = np + (p - *lineptr); - *lineptr = np; - *n += 1; - } - *p = '\0'; - - return len; -} - -#endif /* HAVE_GETDELIM */ diff --git a/urjtag/src/lib/getline.c b/urjtag/src/lib/getline.c deleted file mode 100644 index 96d17e6b..00000000 --- a/urjtag/src/lib/getline.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 2003 ETC s.r.o. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - * Written by Marcel Telka , 2003. - * - */ - -#include - -#include -#include - -#ifndef HAVE_GETLINE - -#ifndef HAVE_GETDELIM -ssize_t urj_lib_getdelim (char **lineptr, size_t *n, int delimiter, - FILE *stream); -#endif /* HAVE_GETDELIM */ - -ssize_t -urj_lib_getline (char **lineptr, size_t *n, FILE *stream) -{ - return urj_lib_getdelim (lineptr, n, '\n', stream); -} - -#endif /* HAVE_GETLINE */ diff --git a/urjtag/src/tap/cable/jim.c b/urjtag/src/tap/cable/jim.c index 3a8b327a..3eb03c36 100644 --- a/urjtag/src/tap/cable/jim.c +++ b/urjtag/src/tap/cable/jim.c @@ -44,8 +44,8 @@ typedef struct } jim_cable_params_t; -int -urj_tap_cable_jim_cable_connect (char *params[], urj_cable_t *cable) +static int +jim_cable_connect (char *params[], urj_cable_t *cable) { jim_cable_params_t *cable_params; urj_jim_state_t *s; @@ -80,15 +80,15 @@ urj_tap_cable_jim_cable_connect (char *params[], urj_cable_t *cable) return 0; } -void -urj_tap_cable_jim_cable_disconnect (urj_cable_t *cable) +static void +jim_cable_disconnect (urj_cable_t *cable) { urj_tap_cable_done (cable); urj_tap_chain_disconnect (cable->chain); } -void -urj_tap_cable_jim_cable_free (urj_cable_t *cable) +static void +jim_cable_free (urj_cable_t *cable) { if (cable->params != NULL) { @@ -98,8 +98,8 @@ urj_tap_cable_jim_cable_free (urj_cable_t *cable) free (cable); } -void -urj_tap_cable_jim_cable_done (urj_cable_t *cable) +static void +jim_cable_done (urj_cable_t *cable) { } @@ -156,11 +156,11 @@ jim_cable_help (const char *cablename) urj_cable_driver_t urj_tap_cable_jim_driver = { "JIM", N_("JTAG target simulator JIM"), - urj_tap_cable_jim_cable_connect, - urj_tap_cable_jim_cable_disconnect, - urj_tap_cable_jim_cable_free, + jim_cable_connect, + jim_cable_disconnect, + jim_cable_free, jim_cable_init, - urj_tap_cable_jim_cable_done, + jim_cable_done, urj_tap_cable_generic_set_frequency, jim_cable_clock, jim_cable_get_tdo,