remove whitespace from end of lines
[reactos.git] / reactos / boot / freeldr / freeldr / rtl / print.c
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
4 *
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.
9 *
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.
14 *
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.
18 */
19
20 #include <freeldr.h>
21 #include <machine.h>
22 #include <rtl.h>
23 #include <stdarg.h>
24
25 /*
26 * print() - prints unformatted text to stdout
27 */
28 void print(char *str)
29 {
30 int i;
31
32 for (i = 0; i < strlen(str); i++)
33 MachConsPutChar(str[i]);
34 }
35
36 /*
37 * printf() - prints formatted text to stdout
38 * originally from GRUB
39 */
40 void printf(char *format, ... )
41 {
42 va_list ap;
43 va_start(ap,format);
44 char c, *ptr, str[16];
45 int ll;
46
47 while ((c = *(format++)))
48 {
49 if (c != '%')
50 {
51 MachConsPutChar(c);
52 }
53 else
54 {
55 if (*format == 'I' && *(format+1) == '6' && *(format+2) == '4')
56 {
57 ll = 1;
58 format += 3;
59 }
60 else
61 {
62 ll = 0;
63 }
64 switch (c = *(format++))
65 {
66 case 'd': case 'u': case 'x':
67 if (ll)
68 {
69 *convert_i64_to_ascii(str, c, va_arg(ap, unsigned long long)) = 0;
70 }
71 else
72 {
73 *convert_to_ascii(str, c, va_arg(ap, unsigned long)) = 0;
74 }
75
76 ptr = str;
77
78 while (*ptr)
79 {
80 MachConsPutChar(*(ptr++));
81 }
82 break;
83
84 case 'c': MachConsPutChar((va_arg(ap,int))&0xff); break;
85
86 case 's':
87 ptr = va_arg(ap,char *);
88
89 while ((c = *(ptr++)))
90 {
91 MachConsPutChar(c);
92 }
93 break;
94 case '%':
95 MachConsPutChar(c);
96 break;
97 default:
98 printf("\nprintf() invalid format specifier - %%%c\n", c);
99 break;
100 }
101 }
102 }
103
104 va_end(ap);
105 }
106
107 void sprintf(char *buffer, char *format, ... )
108 {
109 va_list ap;
110 char c, *ptr, str[16];
111 char *p = buffer;
112 int ll;
113
114 va_start(ap,format);
115
116 while ((c = *(format++)))
117 {
118 if (c != '%')
119 {
120 *p = c;
121 p++;
122 }
123 else
124 {
125 if (*format == 'I' && *(format+1) == '6' && *(format+2) == '4')
126 {
127 ll = 1;
128 format += 3;
129 }
130 else
131 {
132 ll = 0;
133 }
134 switch (c = *(format++))
135 {
136 case 'd': case 'u': case 'x':
137 if (ll)
138 {
139 *convert_i64_to_ascii(str, c, va_arg(ap, unsigned long long)) = 0;
140 }
141 else
142 {
143 *convert_to_ascii(str, c, va_arg(ap, unsigned long)) = 0;
144 }
145
146 ptr = str;
147
148 while (*ptr)
149 {
150 *p = *(ptr++);
151 p++;
152 }
153 break;
154
155 case 'c':
156 *p = va_arg(ap,int)&0xff;
157 p++;
158 break;
159
160 case 's':
161 ptr = va_arg(ap,char *);
162
163 while ((c = *(ptr++)))
164 {
165 *p = c;
166 p++;
167 }
168 break;
169 case '%':
170 *p = c;
171 p++;
172 break;
173 default:
174 printf("\nsprintf() invalid format specifier - %%%c\n", c);
175 break;
176 }
177 }
178 }
179 va_end(ap);
180 *p=0;
181 }