Files
rtems/cpukit/libmisc/shell/str2int.c
Joel Sherrill e41eaa881a 2008-12-18 Sebastian Huber <sebastian.huber@embedded-brains.de>
* libmisc/serdbg/termios_printk.c, libmisc/serdbg/termios_printk.h:
	Fixed incompatible return value.

	* libmisc/cpuuse/cpuusagereport.c: Changed output format.

	* libmisc/Makefile.am, libmisc/monitor/mon-editor.c: New file.

	* libmisc/capture/capture-cli.c, libmisc/monitor/mon-command.c,
	libmisc/monitor/mon-monitor.c, libmisc/monitor/mon-object.c,
	libmisc/monitor/mon-prmisc.c, libmisc/monitor/mon-symbols.c,
	libmisc/monitor/monitor.h, libmisc/shell/cat_file.c,
	libmisc/shell/cmds.c, libmisc/shell/internal.h,
	libmisc/shell/main_help.c, libmisc/shell/shell.c,
	libmisc/shell/shell.h, libmisc/shell/shell_cmdset.c,
	libmisc/shell/shell_getchar.c, libmisc/shell/str2int.c: Various global
	data is now read only.  Added 'const' qualifier to many pointer
	parameters.  It is no longer possible to remove monitor commands.
	Moved monitor line editor into a separate file to avoid unnecessary
	dependencies.
2008-12-18 15:25:27 +00:00

96 lines
1.6 KiB
C

/*
* Author: Fernando RUIZ CASAS
* Work: fernando.ruiz@ctv.es
* Home: correo@fernando-ruiz.com
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/shell.h>
#include "internal.h"
/*
* str to int "0xaffe" "0b010010" "0123" "192939"
*/
int rtems_shell_str2int(const char * s) {
int sign=1;
int base=10;
int value=0;
int digit;
if (!s) return 0;
if (*s) {
if (*s=='-') {
sign=-1;
s++;
if (!*s) return 0;
}
if (*s=='0') {
s++;
switch(*s) {
case 'x':
case 'X':
s++;
base=16;
break;
case 'b':
case 'B':
s++;
base=2;
break;
default:
base=8;
break;
}
}
while (*s) {
switch(*s) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
digit=*s-'0';
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
digit=*s-'A'+10;
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
digit=*s-'a'+10;
break;
default:
return value*sign;
}
if (digit>base)
return value*sign;
value=value*base+digit;
s++;
}
}
return value*sign;
}