From de7066457850952b2b54af16927030998a7e7f45 Mon Sep 17 00:00:00 2001 From: Kolja Waschk Date: Fri, 11 Apr 2008 21:31:55 +0000 Subject: [PATCH] [ 1940323 ] OS X support for UrJTAG (by Ville Voipio) git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1167 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- jtag/ChangeLog | 6 ++++++ jtag/THANKS | 1 + jtag/src/bsdl/bsdl.c | 13 +++++++++++-- jtag/src/jtag.c | 26 +++++++++++++++++++++----- jtag/src/lib/fclock.c | 25 +++++++++++++++++++++++++ jtag/src/tap/parport/ftd2xx.c | 2 -- jtag/src/tap/parport/ftdi.c | 1 - jtag/src/tap/usbconn/libusb.c | 2 -- 8 files changed, 64 insertions(+), 12 deletions(-) diff --git a/jtag/ChangeLog b/jtag/ChangeLog index e8019f5f..4fe1eb84 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,9 @@ +2008-04-11 Kolja Waschk + + * src/bsdl/bsdl.c, src/tap/parport/ftd2xx.c, src/tap/parport/ftdi.c, + src/tap/usbconn/libusb.c, src/lib/fclock.c, src/jtag.c: + [ 1940323 ] OS X support for UrJTAG (by Ville Voipio) + 2008-04-11 Arnim Laeuger * src/tap/parport/ftdi.c (ftdi_flush_output): removed unused variables diff --git a/jtag/THANKS b/jtag/THANKS index a814250d..1a03af55 100644 --- a/jtag/THANKS +++ b/jtag/THANKS @@ -63,6 +63,7 @@ Holger Schurig Robert Sedevici Juergen Stuber Hartley Sweeten +Ville Voipio David Vrabel Alan Wallace Jeff Wittrock diff --git a/jtag/src/bsdl/bsdl.c b/jtag/src/bsdl/bsdl.c index 062603a8..ed9c399b 100644 --- a/jtag/src/bsdl/bsdl.c +++ b/jtag/src/bsdl/bsdl.c @@ -198,8 +198,10 @@ void bsdl_set_path(chain_t *chain, const char *pathlist) bsdl_globs_t *globs = &(chain->bsdl); char *delim; char *elem; + char *pathelem; int num; - + size_t len; + /* free memory of current path list */ if (globs->path_list) { for (num = 0; globs->path_list[num]; num++) @@ -217,7 +219,14 @@ void bsdl_set_path(chain_t *chain, const char *pathlist) /* extend path list array */ globs->path_list = (char **)realloc(globs->path_list, (num+1) * sizeof(char *)); /* enter path element up to the delimeter */ - globs->path_list[num-1] = strndup(elem, (size_t)(delim - elem)); + if (delim == NULL) + len = strlen(elem); + else + len = delim-elem; + pathelem = malloc(len + 1); + memcpy(pathelem, elem, len); + pathelem[len] = '\0'; + globs->path_list[num-1] = pathelem; globs->path_list[num] = NULL; } elem = delim ? delim + 1 : elem + strlen(elem); diff --git a/jtag/src/jtag.c b/jtag/src/jtag.c index 656799cd..ac541c9c 100644 --- a/jtag/src/jtag.c +++ b/jtag/src/jtag.c @@ -150,7 +150,7 @@ static int jtag_readline_multiple_commands_support(chain_t *chain, char * line) if (!line || !(strlen( line ) > 0)) return 1; - + do { line = nextcmd; @@ -176,6 +176,9 @@ jtag_readline_loop( chain_t *chain, const char *prompt ) { #ifdef HAVE_LIBREADLINE char *line = NULL; +#ifdef HAVE_READLINE_HISTORY + HIST_ENTRY *hptr; +#endif /* Iterate */ while (jtag_readline_multiple_commands_support( chain, line )) { @@ -194,8 +197,22 @@ jtag_readline_loop( chain_t *chain, const char *prompt ) #ifdef HAVE_READLINE_HISTORY /* Check if we actually got something , Don't add duplicate lines*/ - if (strlen( line ) &&( !history_length ||strcmp(line,history_get(history_length)->line))) - add_history( line ); + if (strlen( line )) { + if (history_length == 0) + add_history( line ); + else { + hptr = history_get( history_length ); + /* Apple leopard libreadline emulation screws up indexing, try the other one */ + if (hptr == NULL) + hptr = history_get( history_length-1 ); + if (hptr != NULL) { + if (strcmp( line, hptr->line )) + add_history( line ); + } + else + add_history( line ); + } + } #endif } free( line ); @@ -204,7 +221,7 @@ jtag_readline_loop( chain_t *chain, const char *prompt ) line[0] = 0; do { - jtag_readline_multiple_commands_support( line ); + jtag_readline_multiple_commands_support( chain, line ); printf("%s", prompt); fflush(stdout); } @@ -404,7 +421,6 @@ main( int argc, char *const argv[] ) printf( _("Out of memory\n") ); return -1; } - jtag_parse_stream( chain, stdin ); cleanup( chain ); diff --git a/jtag/src/lib/fclock.c b/jtag/src/lib/fclock.c index 5bd06ade..08d0a914 100644 --- a/jtag/src/lib/fclock.c +++ b/jtag/src/lib/fclock.c @@ -30,6 +30,12 @@ #include #include +#ifdef __APPLE__ +#include +#include +#include +#endif + #ifndef CLK_TCK static clock_t CLK_TCK = 0; @@ -50,6 +56,24 @@ long double frealtime() { long double result; +#ifdef __APPLE__ + static uint64_t start_mat; + static long double start_time; + static double multiplier; + + mach_timebase_info_data_t mtid; + struct timeval tv; + + if(!mtid.denom == 0) { + mach_timebase_info(&mtid); + multiplier = (double)mtid.numer / (double)mtid.denom; + gettimeofday(&tv, NULL); + start_time = (long double)tv.tv_sec + (long double)tv.tv_usec * 1000.0; + start_mat = mach_absolute_time(); + } + + result = start_time + (mach_absolute_time() - start_mat) * multiplier; +#else #ifdef _POSIX_TIMERS struct timespec t; if (clock_gettime(CLOCK_REALTIME, &t)==-1) { @@ -65,6 +89,7 @@ frealtime() exit(EXIT_FAILURE); } result = (long double)c/CLK_TCK; +#endif #endif assert(isnormal(result)); assert(result > 0); diff --git a/jtag/src/tap/parport/ftd2xx.c b/jtag/src/tap/parport/ftd2xx.c index db531591..418076b9 100644 --- a/jtag/src/tap/parport/ftd2xx.c +++ b/jtag/src/tap/parport/ftd2xx.c @@ -33,8 +33,6 @@ #include #if __CYGWIN__ #include -#else -#include #endif #ifdef HAVE_STROPTS_H #include diff --git a/jtag/src/tap/parport/ftdi.c b/jtag/src/tap/parport/ftdi.c index 54952945..cff1cdcd 100644 --- a/jtag/src/tap/parport/ftdi.c +++ b/jtag/src/tap/parport/ftdi.c @@ -33,7 +33,6 @@ #include #endif #include -#include #include #include diff --git a/jtag/src/tap/usbconn/libusb.c b/jtag/src/tap/usbconn/libusb.c index 45216960..47dac86a 100644 --- a/jtag/src/tap/usbconn/libusb.c +++ b/jtag/src/tap/usbconn/libusb.c @@ -31,8 +31,6 @@ #include #if __CYGWIN__ #include -#else -#include #endif #include #include