2003-06-03 Marcel Telka <marcel@telka.sk>
* Makefile.am (libbrux_a_SOURCES): Added cmd/cmd.c, cmd/help.c, cmd/quit.c, and cmd/detectflash.c. * cmd/cmd.c: New file moved from jtag module, direcory src/cmd. * cmd/help.c: Ditto. * cmd/quit.c: Ditto. * cmd/detectflash.c: Ditto. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@465 b68d4a1b-bc3d-0410-92ed-d4ac073336b7master
parent
7bce9968e1
commit
6831c9f100
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2002, 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 <marcel@telka.sk>, 2002, 2003.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <brux/cmd.h>
|
||||
|
||||
int
|
||||
cmd_run( char *params[] )
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!params[0])
|
||||
return 1;
|
||||
|
||||
for (i = 0; cmds[i]; i++)
|
||||
if (strcmp( cmds[i]->name, params[0] ) == 0) {
|
||||
int r = cmds[i]->run( params );
|
||||
if (r < 0)
|
||||
printf( _("%s: syntax error!\n"), params[0] );
|
||||
return r;
|
||||
}
|
||||
|
||||
printf( _("%s: unknown command\n"), params[0] );
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_params( char *params[] )
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (params[i])
|
||||
i++;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_get_number( char *s, unsigned int *i )
|
||||
{
|
||||
int n;
|
||||
int r;
|
||||
int l;
|
||||
|
||||
if (!s || !i)
|
||||
return -1;
|
||||
|
||||
l = strlen( s );
|
||||
r = sscanf( s, "0x%x%n", i, &n);
|
||||
if (r == 1 && n == l)
|
||||
return 0;
|
||||
r = sscanf( s, "%u%n", i, &n );
|
||||
if (r == 1 && n == l)
|
||||
return 0;
|
||||
|
||||
return -1;
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* $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 <marcel@telka.sk>, 2003.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <brux/flash.h>
|
||||
#include <brux/cmd.h>
|
||||
|
||||
static int
|
||||
cmd_detectflash_run( char *params[] )
|
||||
{
|
||||
if (cmd_params( params ) != 1)
|
||||
return -1;
|
||||
|
||||
if (!bus) {
|
||||
printf( _("Error: Bus driver missing.\n") );
|
||||
return 1;
|
||||
}
|
||||
|
||||
detectflash( bus );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_detectflash_help( void )
|
||||
{
|
||||
printf( _(
|
||||
"Usage: %s\n"
|
||||
"Detect flash memory type connected to a part.\n"
|
||||
), "detectflash" );
|
||||
}
|
||||
|
||||
cmd_t cmd_detectflash = {
|
||||
"detectflash",
|
||||
N_("detect parameters of flash chips attached to a part"),
|
||||
cmd_detectflash_help,
|
||||
cmd_detectflash_run
|
||||
};
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* $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 <marcel@telka.sk>, 2003.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <brux/cmd.h>
|
||||
|
||||
extern cmd_t *cmds[];
|
||||
|
||||
static int
|
||||
cmd_help_run( char *params[] )
|
||||
{
|
||||
int i;
|
||||
|
||||
/* short description generation */
|
||||
if (!params[1]) {
|
||||
int i;
|
||||
printf( _("Command list:\n\n") );
|
||||
for (i = 0; cmds[i]; i++)
|
||||
printf( _("%-13s %s\n"), cmds[i]->name, cmds[i]->desc ? _(cmds[i]->desc) : _("(no description available)") );
|
||||
printf( _("\nType \"help COMMAND\" for details about particular command.\n") );
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (params[2])
|
||||
return -1;
|
||||
|
||||
/* search and print help for particular command */
|
||||
for (i = 0; cmds[i]; i++)
|
||||
if (strcmp( cmds[i]->name, params[1] ) == 0) {
|
||||
if (cmds[i]->help)
|
||||
cmds[i]->help();
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf( _("%s: unknown command\n"), params[1] );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_help_help( void )
|
||||
{
|
||||
printf( _(
|
||||
"Usage: %s [COMMAND]\n"
|
||||
"Print short help for COMMAND, or list of available commands.\n"
|
||||
), "help" );
|
||||
}
|
||||
|
||||
cmd_t cmd_help = {
|
||||
"help",
|
||||
N_("display this help"),
|
||||
cmd_help_help,
|
||||
cmd_help_run
|
||||
};
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* $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 <marcel@telka.sk>, 2003.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <brux/cmd.h>
|
||||
|
||||
static int
|
||||
cmd_quit_run( char *params[] )
|
||||
{
|
||||
if (params[1])
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_quit_help( void )
|
||||
{
|
||||
printf( _(
|
||||
"Usage: %s\n"
|
||||
"Exit from %s.\n"
|
||||
), "quit", PACKAGE );
|
||||
}
|
||||
|
||||
cmd_t cmd_quit = {
|
||||
"quit",
|
||||
N_("exit and terminate this session"),
|
||||
cmd_quit_help,
|
||||
cmd_quit_run
|
||||
};
|
Loading…
Reference in New Issue