2004-11-21 Marcel Telka <marcel@telka.sk>

* src/jtag.c (jtag_parse_stream, cleanup): New function.
	(jtag_parse_file): Replaced stream parsing algorithm with jtag_parse_stream() call. Removed support
		for special filename '-'.
	(main): Rewritten and improved startup sequence to distinguish between interactive invocation
		and stdin input (fixed bug 858535, thanks to Andrew Dyer for an idea).


git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@623 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Marcel Telka 20 years ago
parent ebdbdee65c
commit 5968bafaf9

@ -1,3 +1,11 @@
2004-11-21 Marcel Telka <marcel@telka.sk>
* src/jtag.c (jtag_parse_stream, cleanup): New function.
(jtag_parse_file): Replaced stream parsing algorithm with jtag_parse_stream() call. Removed support
for special filename '-'.
(main): Rewritten and improved startup sequence to distinguish between interactive invocation
and stdin input (fixed bug 858535, thanks to Andrew Dyer for an idea).
2004-11-17 Marcel Telka <marcel@telka.sk>
* acinclude.m4: New file with VL_LIB_READLINE macro (removed dependency on ac-archive package).

@ -28,6 +28,9 @@ See libbrux/NEWS for more news.
* Fixed minor bugs (including bug 857039).
* Fixed compiler error on Debian Woody (patch 986414, Martin Buck).
* Added support for different Intel IXP425 frequency variants (patch 1030647, Trevor Man).
* Rewritten and improved startup sequence to distinguish between interactive invocation
and stdin input (fixed bug 858535, thanks to Andrew Dyer for an idea).
* Removed support for parameter '-' (stdin).
* New translations:
- French (Michel Robitaille)

@ -27,6 +27,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <readline/readline.h>
@ -195,28 +196,35 @@ jtag_readline_loop( const char *prompt )
free( line );
}
int
jtag_parse_file( const char *filename )
static int
jtag_parse_stream( FILE *f )
{
FILE *f;
int go = 1;
char *line = NULL;
int n = 0;
if (strcmp( filename, "-" ) != 0)
f = fopen( filename, "r" );
else
f = stdin;
if (!f)
return -1;
while (go && (getline( &line, &n, f ) != -1))
if ((strlen(line) > 0) && (line[0] != '#'))
go = jtag_parse_line(line);
free(line);
if (strcmp( filename, "-" ) != 0)
fclose(f);
return go;
}
int
jtag_parse_file( const char *filename )
{
FILE *f;
int go;
f = fopen( filename, "r" );
if (!f)
return -1;
go = jtag_parse_stream( f );
fclose(f);
return go;
}
@ -248,10 +256,24 @@ jtag_parse_rc( void )
return go;
}
static void
cleanup( void )
{
cfi_array_free( cfi_array );
cfi_array = NULL;
if (bus) {
bus_free( bus );
bus = NULL;
}
chain_free( chain );
chain = NULL;
}
int
main( int argc, const char **argv )
{
int go = 1;
int go;
int i;
#ifdef ENABLE_NLS
@ -261,6 +283,41 @@ main( int argc, const char **argv )
textdomain( PACKAGE );
#endif /* ENABLE_NLS */
/* input from files */
if (argc > 1) {
for (i = 1; i < argc; i++) {
chain = chain_alloc();
if (!chain) {
printf( _("Out of memory\n") );
return -1;
}
go = jtag_parse_file( argv[i] );
cleanup();
if (go < 0) {
printf( _("Unable to open file `%s'!\n"), argv[i] );
break;
}
}
return 0;
}
/* input from stdin */
if (!isatty(0)) {
chain = chain_alloc();
if (!chain) {
printf( _("Out of memory\n") );
return -1;
}
jtag_parse_stream( stdin );
cleanup();
return 0;
}
/* interactive */
printf(
_("%s\n"
"Copyright (C) 2002, 2003 ETC s.r.o.\n"
@ -278,41 +335,24 @@ main( int argc, const char **argv )
printf( _("Warning: %s may damage your hardware! Type \"quit\" to exit!\n\n"), PACKAGE_NAME );
printf( _("Type \"help\" for help.\n\n") );
for (i = 1; i < argc; i++) {
go = jtag_parse_file( argv[i] );
if (go < 0)
printf( _("Unable to open file `%s'!\n"), argv[i] );
if (!go)
break;
}
if (go) {
/* Create ~/.jtag */
jtag_create_jtagdir();
/* Create ~/.jtag */
jtag_create_jtagdir();
/* Parse and execute the RC file */
go = jtag_parse_rc();
/* Parse and execute the RC file */
go = jtag_parse_rc();
if (go) {
/* Load history */
jtag_load_history();
if (go) {
/* Load history */
jtag_load_history();
/* main loop */
jtag_readline_loop( "jtag> " );
/* main loop */
jtag_readline_loop( "jtag> " );
/* Save history */
jtag_save_history();
}
/* Save history */
jtag_save_history();
}
cfi_array_free( cfi_array );
cfi_array = NULL;
if (bus) {
bus_free( bus );
bus = NULL;
}
chain_free( chain );
cleanup();
return 0;
}

Loading…
Cancel
Save