Changeset eec616b in mainline for kernel/generic/src/printf/vprintf.c


Ignore:
Timestamp:
2009-03-24T14:43:25Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8f29e336
Parents:
74c8da2c
Message:

Unicode aware printf and family functions
(this breaks some things, but will be fixed soon)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/printf/vprintf.c

    r74c8da2c reec616b  
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
     
    4040#include <arch/types.h>
    4141#include <typedefs.h>
     42#include <string.h>
    4243
    43 SPINLOCK_INITIALIZE(printf_lock);                       /**< vprintf spinlock */
     44SPINLOCK_INITIALIZE(printf_lock);  /**< vprintf spinlock */
    4445
    45 static int vprintf_write(const char *str, size_t count, void *unused)
     46static int vprintf_write_utf8(const char *str, size_t size, void *data)
    4647{
    47         size_t i;
    48         for (i = 0; i < count; i++)
    49                 putchar(str[i]);
    50         return i;
     48        index_t index = 0;
     49        index_t chars = 0;
     50       
     51        while (index < size) {
     52                putchar(utf8_decode(str, &index, size - 1));
     53                index++;
     54                chars++;
     55        }
     56       
     57        return chars;
    5158}
    5259
    53 int puts(const char *s)
     60static int vprintf_write_utf32(const wchar_t *str, size_t size, void *data)
    5461{
    55         size_t i;
    56         for (i = 0; s[i] != 0; i++)
    57                 putchar(s[i]);
    58         return i;
     62        index_t index = 0;
     63       
     64        while (index < (size / sizeof(wchar_t))) {
     65                putchar(str[index]);
     66                index++;
     67        }
     68       
     69        return index;
     70}
     71
     72int puts(const char *str)
     73{
     74        index_t index = 0;
     75        index_t chars = 0;
     76        wchar_t uc;
     77       
     78        while ((uc = utf8_decode(str, &index, UTF8_NO_LIMIT)) != 0) {
     79                putchar(uc);
     80                index++;
     81                chars++;
     82        }
     83       
     84        return chars;
    5985}
    6086
    6187int vprintf(const char *fmt, va_list ap)
    6288{
    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        };
    6494       
    6595        ipl_t ipl = interrupts_disable();
Note: See TracChangeset for help on using the changeset viewer.