Rev 4341 | Rev 4348 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4341 | Rev 4347 | ||
---|---|---|---|
Line 24... | Line 24... | ||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup generic |
29 | /** @addtogroup generic |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
Line 37... | Line 37... | ||
37 | #include <putchar.h> |
37 | #include <putchar.h> |
38 | #include <synch/spinlock.h> |
38 | #include <synch/spinlock.h> |
39 | #include <arch/asm.h> |
39 | #include <arch/asm.h> |
40 | #include <arch/types.h> |
40 | #include <arch/types.h> |
41 | #include <typedefs.h> |
41 | #include <typedefs.h> |
- | 42 | #include <string.h> |
|
42 | 43 | ||
43 | SPINLOCK_INITIALIZE(printf_lock); /**< vprintf spinlock */ |
44 | SPINLOCK_INITIALIZE(printf_lock); /**< vprintf spinlock */ |
44 | 45 | ||
45 | static int vprintf_write(const char *str, size_t count, void *unused) |
46 | static int vprintf_write_utf8(const char *str, size_t size, void *data) |
46 | { |
47 | { |
47 | size_t i; |
48 | index_t index = 0; |
- | 49 | index_t chars = 0; |
|
- | 50 | ||
48 | for (i = 0; i < count; i++) |
51 | while (index < size) { |
- | 52 | putchar(utf8_decode(str, &index, size - 1)); |
|
- | 53 | index++; |
|
49 | putchar(str[i]); |
54 | chars++; |
- | 55 | } |
|
- | 56 | ||
50 | return i; |
57 | return chars; |
51 | } |
58 | } |
52 | 59 | ||
53 | int puts(const char *s) |
60 | static int vprintf_write_utf32(const wchar_t *str, size_t size, void *data) |
54 | { |
61 | { |
- | 62 | index_t index = 0; |
|
- | 63 | ||
- | 64 | while (index < (size / sizeof(wchar_t))) { |
|
- | 65 | putchar(str[index]); |
|
55 | size_t i; |
66 | index++; |
- | 67 | } |
|
- | 68 | ||
- | 69 | return index; |
|
- | 70 | } |
|
- | 71 | ||
- | 72 | int puts(const char *str) |
|
- | 73 | { |
|
- | 74 | index_t index = 0; |
|
56 | for (i = 0; s[i] != 0; i++) |
75 | index_t chars = 0; |
- | 76 | wchar_t uc; |
|
- | 77 | ||
- | 78 | while ((uc = utf8_decode(str, &index, UTF8_NO_LIMIT)) != 0) { |
|
57 | putchar(s[i]); |
79 | putchar(uc); |
- | 80 | index++; |
|
- | 81 | chars++; |
|
- | 82 | } |
|
- | 83 | ||
58 | return i; |
84 | return chars; |
59 | } |
85 | } |
60 | 86 | ||
61 | int vprintf(const char *fmt, va_list ap) |
87 | int vprintf(const char *fmt, va_list ap) |
62 | { |
88 | { |
63 | struct printf_spec ps = {(int(*)(void *, size_t, void *)) vprintf_write, NULL}; |
89 | printf_spec_t ps = { |
- | 90 | vprintf_write_utf8, |
|
- | 91 | vprintf_write_utf32, |
|
- | 92 | NULL |
|
- | 93 | }; |
|
64 | 94 | ||
65 | ipl_t ipl = interrupts_disable(); |
95 | ipl_t ipl = interrupts_disable(); |
66 | spinlock_lock(&printf_lock); |
96 | spinlock_lock(&printf_lock); |
67 | 97 | ||
68 | int ret = printf_core(fmt, &ps, ap); |
98 | int ret = printf_core(fmt, &ps, ap); |