From: Stefan E. <se...@us...> - 2001-10-05 11:53:49
|
Update of /cvsroot/blob/blob/src In directory usw-pr-cvs1:/tmp/cvs-serv24606 Modified Files: command_hist.c Log Message: - simple command line history Index: command_hist.c =================================================================== RCS file: /cvsroot/blob/blob/src/command_hist.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- command_hist.c 2001/10/05 11:48:11 1.1 +++ command_hist.c 2001/10/05 11:53:46 1.2 @@ -0,0 +1,260 @@ +/********************************************************************** + * Command history + * + * AUTOR: SELETZ + * + * Implements a simple command history + * + * Copyright (C) 2001 Stefan Eletzhofer <ste...@ww...> + * + * 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 + * + */ + +#ident "$Id$" + +/********************************************************************** + * Includes + */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "command.h" +#include "errno.h" +#include "init.h" +#include "serial.h" +#include "time.h" +#include "types.h" +#include "util.h" + +/********************************************************************** + * Defines / Makros + */ + +#define CMDHIST_DEBUG 0 + +#define MAX_HIST 32 + +/********************************************************************** + * Programmglobale Variable + */ + +/********************************************************************** + * Modulglobale Variable + */ + +static int is_initialized = 0; +static int cmdhist_entries = 0; +static int cmdhist_read = 0; +static int cmdhist_write = 0; +static char cmdhistory[MAX_HIST][MAX_COMMANDLINE_LENGTH]; + + +/********************************************************************** + * Prototypen + */ + +/********************************************************************** + * Exportierte Funktionen + */ + +/********************************************************************* + * cmdhist_init + * + * AUTOR: SELETZ + * REVISED: + * + * Initializes this module + * + */ +int cmdhist_init( void ) +{ + int i; + + cmdhist_read = 0; + cmdhist_write = 0; + cmdhist_entries = 0; + + i=MAX_HIST - 1; + while ( i-- ) { + cmdhistory[i][0]=0; + } + + is_initialized = 1; + return 0; +} + + +/********************************************************************* + * cmd_push + * + * AUTOR: SELETZ + * REVISED: + * + * Push a command to the history buffer + * + */ +int cmdhist_push( char *cmd ) +{ + if ( !is_initialized ) { + cmdhist_init(); + } + + if ( !cmd ) + return -EINVAL; + + if ( strlen( cmd ) > MAX_COMMANDLINE_LENGTH ) + return -EINVAL; + + if ( strlen( cmd ) == 0 ) + return 0; + + strcpy( cmdhistory[ cmdhist_write ], cmd ); + + cmdhist_write ++; + cmdhist_write = cmdhist_write % MAX_HIST; + + if ( cmdhist_entries < MAX_HIST ) + cmdhist_entries++; + +#if CMDHIST_DEBUG + SerialOutputString( "e=" ); + SerialOutputDec( cmdhist_entries ); + SerialOutputString( " r=" ); + SerialOutputDec( cmdhist_read ); + SerialOutputString( " w=" ); + SerialOutputDec( cmdhist_write ); + SerialOutputString( "\n" ); +#endif + + return 0; +} + + +/********************************************************************* + * cmdhist_reset + * + * AUTOR: SELETZ + * REVISED: + * + * Resets read ptr + * + */ +int cmdhist_reset( void ) +{ + cmdhist_read = cmdhist_write; + + return 0; +} + + + +/********************************************************************* + * cmd_next + * + * AUTOR: seletz + * REVISED: + * + * Gets next command in history + * + */ +int cmdhist_next( char **cmd ) +{ + int ptr; + + if ( !is_initialized ) { + cmdhist_init(); + } + + if ( !cmdhist_entries ) + return -EINVAL; + + if ( !cmd ) + return -EINVAL; + + ptr = cmdhist_read; + + if ( ptr == 0 ) { + if ( cmdhist_entries != MAX_HIST ) + return -EINVAL; + ptr = MAX_HIST - 1; + } else { + ptr--; + } + + if ( !cmdhistory[ptr][0] ) + return -EINVAL; + + *cmd = cmdhistory[ptr]; + + cmdhist_read = ptr; + +#if CMDHIST_DEBUG + SerialOutputString( "e=" ); + SerialOutputDec( cmdhist_entries ); + SerialOutputString( " r=" ); + SerialOutputDec( cmdhist_read ); + SerialOutputString( " w=" ); + SerialOutputDec( cmdhist_write ); + SerialOutputString( "\n" ); +#endif + + return 0; +} + + +/********************************************************************* + * cmd_prev + * + * AUTOR: SELETZ + * REVISED: + * + * Gets previous command from history + * + */ +int cmdhist_prev( char **cmd ) +{ + int ptr; + + if ( !is_initialized ) { + cmdhist_init(); + } + + if ( !cmd ) + return -EINVAL; + + if ( !cmdhist_entries ) + return -EINVAL; + + ptr = cmdhist_read + 1; + ptr = ptr % MAX_HIST; + + if ( ptr == cmdhist_write ) + return -EINVAL; + + if ( !cmdhistory[ptr][0] ) + return -EINVAL; + + *cmd = cmdhistory[ptr]; + + cmdhist_read = ptr; + + return 0; +} + +/********************************************************************** + * Statische Funktionen + */ |
From: Erik M. <J.A...@IT...> - 2001-10-05 12:13:28
|
On Fri, Oct 05, 2001 at 04:53:48AM -0700, Stefan Eletzhofer wrote: > Update of /cvsroot/blob/blob/src > In directory usw-pr-cvs1:/tmp/cvs-serv24606 > > Modified Files: > command_hist.c > Log Message: > - simple command line history Why would we need this at all? Blob is a bootloader, not a shell. You know you've achieved perfection in design, not when you have nothing more to add, but when you have nothing more to take away. -- Antoine de Saint-Exupery Erik -- J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department of Electrical Engineering, Faculty of Information Technology and Systems, Delft University of Technology, PO BOX 5031, 2600 GA Delft, The Netherlands Phone: +31-15-2783635 Fax: +31-15-2781843 Email: J.A...@it... WWW: http://www-ict.its.tudelft.nl/~erik/ |
From: J.D. B. <ba...@th...> - 2001-10-05 12:21:00
|
At 14:13 +0200 05-10-2001, Erik Mouw wrote: >On Fri, Oct 05, 2001 at 04:53:48AM -0700, Stefan Eletzhofer wrote: >> Update of /cvsroot/blob/blob/src >> In directory usw-pr-cvs1:/tmp/cvs-serv24606 >> >> Modified Files: >> command_hist.c >> Log Message: >> - simple command line history > >Why would we need this at all? Blob is a bootloader, not a shell. Seconded. What *would* be useful, though, is either auto-completion or command abbreviation. JDB. -- LART. 250 MIPS under one Watt. Free hardware design files. http://www.lart.tudelft.nl/ |
From: Abraham vd M. <ab...@2d...> - 2001-10-05 12:30:53
|
Hi J.D.! > >> Update of /cvsroot/blob/blob/src > >> In directory usw-pr-cvs1:/tmp/cvs-serv24606 > >> > >> Modified Files: > >> command_hist.c > >> Log Message: > >> - simple command line history > > > >Why would we need this at all? Blob is a bootloader, not a shell. >=20 > Seconded. What *would* be useful, though, is either auto-completion=20 > or command abbreviation. I don't think it should be removed though. As long as there's a configure option not to compile this in. In that case, those who want a stripped down bootloader can have one and rest in peace that there's no bloated code and those who wants a bells & whistles boot loader can also have one (: --=20 Regards Abraham When the speaker and he to whom he is speaks do not understand, that is metaphysics. -- Voltaire __________________________________________________________ Abraham vd Merwe - 2d3D, Inc. Device Driver Development, Outsourcing, Embedded Systems Cell: +27 82 565 4451 Snailmail: Tel: +27 21 761 7549 Block C, Antree Park Fax: +27 21 761 7648 Doncaster Road Email: ab...@2d... Kenilworth, 7700 Http: http://www.2d3d.com South Africa |