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.
22 * convert_to_ascii() - converts a number to it's ascii equivalent
24 * GRUB -- GRand Unified Bootloader
25 * Copyright (C) 1996 Erich Boleyn <erich@uruk.org>
27 char *convert_to_ascii(char *buf
, int c
, ...)
29 unsigned long num
= *((&c
) + 1), mult
= 10;
35 if ((num
& 0x80000000uL
) && c
== 'd')
45 *(ptr
++) = ( (dig
> 9) ? dig
+ 'a' - 10 : '0' + dig
);
49 /* reorder to correct direction!! */
66 char *convert_i64_to_ascii(char *buf
, int c
, ...)
68 unsigned long long num
= *(long long*)((&c
) + 1);
75 if ((num
& 0x8000000000000000uLL
) && c
== 'd')
85 *(ptr
++) = ( (dig
> 9) ? dig
+ 'a' - 10 : '0' + dig
);
89 /* reorder to correct direction!! */
106 char *itoa(int value
, char *string
, int radix
)
109 *convert_to_ascii(string
, 'x', value
) = 0;
111 *convert_to_ascii(string
, 'd', value
) = 0;
118 if((c
>= 'a') && (c
<= 'z'))
126 if((c
>= 'A') && (c
<= 'Z'))
132 int atoi(char *string
)
138 if((string
[0] == '0') && (string
[1] == 'x'))
153 if(((*str
< '0') || (*str
> '9')) && ((*str
< 'a') || (*str
> 'f')) && ((*str
< 'A') || (*str
> 'F')))
157 if((*str
>= '0') && (*str
<= '9'))
158 result
+= (*str
- '0');
159 if((*str
>= 'a') && (*str
<= 'f'))
160 result
+= (*str
- 'a') + 10;
161 if((*str
>= 'A') && (*str
<= 'F'))
162 result
+= (*str
- 'A') + 10;
165 else //if(base == 10)
167 if((*str
< '0') || (*str
> '9'))
171 result
+= (*str
- '0');
181 return(c
== ' ' || (c
>= 0x09 && c
<= 0x0D));
186 return(c
>= '0' && c
<= '9');
191 return((c
>= '0' && c
<= '9')||(c
>= 'a' && c
<= 'f')||(c
>= 'A' && c
<= 'F'));