Rev 4055 | Rev 4296 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4055 | Rev 4201 | ||
|---|---|---|---|
| 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(chr_decode(str, &index, size)); |
|
| 49 | putchar(str[i]); |
53 | chars++; |
| - | 54 | } |
|
| - | 55 | ||
| 50 | return i; |
56 | return chars; |
| 51 | } |
57 | } |
| 52 | 58 | ||
| 53 | int puts(const char *s) |
59 | static int vprintf_write_utf32(const wchar_t *str, size_t size, void *data) |
| 54 | { |
60 | { |
| - | 61 | index_t index = 0; |
|
| - | 62 | ||
| - | 63 | while (index < (size / sizeof(wchar_t))) { |
|
| - | 64 | putchar(str[index]); |
|
| 55 | size_t i; |
65 | index++; |
| - | 66 | } |
|
| - | 67 | ||
| - | 68 | return index; |
|
| - | 69 | } |
|
| - | 70 | ||
| - | 71 | int puts(const char *str) |
|
| - | 72 | { |
|
| - | 73 | index_t index = 0; |
|
| 56 | for (i = 0; s[i] != 0; i++) |
74 | index_t chars = 0; |
| - | 75 | wchar_t uc; |
|
| - | 76 | ||
| - | 77 | while ((uc = chr_decode(str, &index, UTF8_NO_LIMIT)) != 0) { |
|
| 57 | putchar(s[i]); |
78 | putchar(uc); |
| - | 79 | chars++; |
|
| - | 80 | } |
|
| - | 81 | ||
| 58 | return i; |
82 | return chars; |
| 59 | } |
83 | } |
| 60 | 84 | ||
| 61 | int vprintf(const char *fmt, va_list ap) |
85 | int vprintf(const char *fmt, va_list ap) |
| 62 | { |
86 | { |
| 63 | struct printf_spec ps = {(int(*)(void *, size_t, void *)) vprintf_write, NULL}; |
87 | printf_spec_t ps = { |
| - | 88 | vprintf_write_utf8, |
|
| - | 89 | vprintf_write_utf32, |
|
| - | 90 | NULL |
|
| - | 91 | }; |
|
| 64 | 92 | ||
| 65 | ipl_t ipl = interrupts_disable(); |
93 | ipl_t ipl = interrupts_disable(); |
| 66 | spinlock_lock(&printf_lock); |
94 | spinlock_lock(&printf_lock); |
| 67 | 95 | ||
| 68 | int ret = printf_core(fmt, &ps, ap); |
96 | int ret = printf_core(fmt, &ps, ap); |