2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2000,2001,2002 Free Software Foundation, Inc.
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.
20 /* Based on "src/misc.c" in etherboot-5.0.5. */
23 #include <etherboot.h>
28 unsigned long tmo
= currticks () + secs
;
30 while (currticks () < tmo
)
37 static unsigned long lastticks
= 0;
39 static const char tiddles
[]="-\\|/";
44 if ((ticks
= currticks ()) == lastticks
)
48 grub_putchar (tiddles
[(count
++) & 3]);
53 /* Because Etherboot uses its own formats for the printf family,
54 define separate definitions from GRUB. */
55 /**************************************************************************
59 %[#]x - 4 bytes long (8 hex digits, lower case)
60 %[#]X - 4 bytes long (8 hex digits, upper case)
61 %[#]hx - 2 bytes int (4 hex digits, lower case)
62 %[#]hX - 2 bytes int (4 hex digits, upper case)
63 %[#]hhx - 1 byte int (2 hex digits, lower case)
64 %[#]hhX - 1 byte int (2 hex digits, upper case)
65 - optional # prefixes 0x or 0X
69 %@ - Internet address in ddd.ddd.ddd.ddd notation
70 %! - Ethernet address in xx:xx:xx:xx:xx:xx notation
71 Note: width specification not supported
72 **************************************************************************/
74 etherboot_vsprintf (char *buf
, const char *fmt
, const int *dp
)
79 for ( ; *fmt
!= '\0'; ++fmt
)
83 buf
? *s
++ = *fmt
: grub_putchar (*fmt
);
89 for (p
= (char *) *dp
++; *p
!= '\0'; p
++)
90 buf
? *s
++ = *p
: grub_putchar (*p
);
94 /* Length of item is bounded */
95 char tmp
[20], *q
= tmp
;
118 * Before each format q points to tmp buffer
119 * After each format q points past end of item
121 if ((*fmt
| 0x20) == 'x')
123 /* With x86 gcc, sizeof(long) == sizeof(int) */
124 const long *lp
= (const long *) dp
;
126 int ncase
= (*fmt
& 0x20);
128 dp
= (const int *) lp
;
134 for (; shift
>= 0; shift
-= 4)
135 *q
++ = "0123456789ABCDEF"[(h
>> shift
) & 0xF] | ncase
;
137 else if (*fmt
== 'd')
148 p
= q
; /* save beginning of digits */
151 *q
++ = '0' + (i
% 10);
156 /* reverse digits, stop in middle */
157 r
= q
; /* don't alter q */
165 else if (*fmt
== '@')
174 const long *lp
= (const long *) dp
;
177 dp
= (const int *) lp
;
179 for (r
= &u
.c
[0]; r
< &u
.c
[4]; ++r
)
180 q
+= etherboot_sprintf (q
, "%d.", *r
);
184 else if (*fmt
== '!')
189 for (r
= p
+ ETH_ALEN
; p
< r
; ++p
)
190 q
+= etherboot_sprintf (q
, "%hhX:", *p
);
194 else if (*fmt
== 'c')
199 /* now output the saved string */
200 for (p
= tmp
; p
< q
; ++p
)
201 buf
? *s
++ = *p
: grub_putchar (*p
);
212 etherboot_sprintf (char *buf
, const char *fmt
, ...)
214 return etherboot_vsprintf (buf
, fmt
, ((const int *) &fmt
) + 1);
218 etherboot_printf (const char *fmt
, ...)
220 (void) etherboot_vsprintf (0, fmt
, ((const int *) &fmt
) + 1);
224 inet_aton (char *p
, in_addr
*addr
)
226 unsigned long ip
= 0;
230 for (i
= 0; i
< 4; i
++)
234 if (val
< 0 || val
> 255)
237 if (i
!= 3 && *p
++ != '.')
240 ip
= (ip
<< 8) | val
;
243 addr
->s_addr
= htonl (ip
);
254 if (*p
< '0' || *p
> '9')
257 while (*p
>= '0' && *p
<= '9')
259 ret
= ret
* 10 + (*p
- '0');