3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * convert_to_ascii() - converts a number to it's ascii equivalent
23 * GRUB -- GRand Unified Bootloader
24 * Copyright (C) 1996 Erich Boleyn <erich@uruk.org>
26 char *convert_to_ascii(char *buf
, int c
, int num
)
28 unsigned long mult
= 10;
34 if ((num
& 0x80000000uL
) && c
== 'd')
44 *(ptr
++) = ( (dig
> 9) ? dig
+ 'a' - 10 : '0' + dig
);
48 /* reorder to correct direction!! */
65 char *convert_i64_to_ascii(char *buf
, int c
, unsigned long long num
)
73 if ((num
& 0x8000000000000000uLL
) && c
== 'd')
83 *(ptr
++) = ( (dig
> 9) ? dig
+ 'a' - 10 : '0' + dig
);
87 /* reorder to correct direction!! */
104 char *itoa(int value
, char *string
, int radix
)
107 *convert_to_ascii(string
, 'x', value
) = 0;
109 *convert_to_ascii(string
, 'd', value
) = 0;
116 if((c
>= 'a') && (c
<= 'z'))
124 if((c
>= 'A') && (c
<= 'Z'))
130 int atoi(const char *string
)
136 if((string
[0] == '0') && (string
[1] == 'x'))
151 if(((*str
< '0') || (*str
> '9')) && ((*str
< 'a') || (*str
> 'f')) && ((*str
< 'A') || (*str
> 'F')))
155 if((*str
>= '0') && (*str
<= '9'))
156 result
+= (*str
- '0');
157 if((*str
>= 'a') && (*str
<= 'f'))
158 result
+= (*str
- 'a') + 10;
159 if((*str
>= 'A') && (*str
<= 'F'))
160 result
+= (*str
- 'A') + 10;
163 else //if(base == 10)
165 if((*str
< '0') || (*str
> '9'))
169 result
+= (*str
- '0');
179 return(c
== ' ' || (c
>= 0x09 && c
<= 0x0D));
184 return(c
>= '0' && c
<= '9');
189 return((c
>= '0' && c
<= '9')||(c
>= 'a' && c
<= 'f')||(c
>= 'A' && c
<= 'F'));