Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4198 → Rev 4199

/trunk/kernel/generic/src/printf/vprintf.c
49,8 → 49,7
index_t chars = 0;
while (index < size) {
putchar(utf8_decode(str, &index, size - 1));
index++;
putchar(utf8_decode(str, &index, size));
chars++;
}
77,7 → 76,6
while ((uc = utf8_decode(str, &index, UTF8_NO_LIMIT)) != 0) {
putchar(uc);
index++;
chars++;
}
/trunk/kernel/generic/src/printf/vsnprintf.c
84,13 → 84,10
index_t index = 0;
while (index < size) {
wchar_t uc = utf8_decode(str, &index, size - 1);
if (!utf8_encode(uc, data->dst, &data->len, data->size - 2))
wchar_t uc = utf8_decode(str, &index, size);
 
if (!utf8_encode(uc, data->dst, &data->len, data->size - 1))
break;
data->len++;
index++;
}
/* Put trailing zero at end, but not count it
149,10 → 146,9
return ((int) size);
}
if (!utf8_encode(str[index], data->dst, &data->len, data->size - 2))
if (!utf8_encode(str[index], data->dst, &data->len, data->size - 1))
break;
data->len++;
index++;
}
/trunk/kernel/generic/src/printf/printf_core.c
257,7 → 257,7
size_t size = strlen_utf8(str);
if (precision == 0)
precision = size;
 
count_t counter = 0;
width -= precision;
if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
266,7 → 266,7
counter++;
}
}
 
int retval;
size_t bytes = utf8_count_bytes(str, min(size, precision));
if ((retval = printf_putnchars_utf8(str, bytes, ps)) < 0)
278,7 → 278,7
if (printf_putchar(' ', ps) == 1)
counter++;
}
 
return ((int) counter);
}
 
585,6 → 585,7
int printf_core(const char *fmt, printf_spec_t *ps, va_list ap)
{
index_t i = 0; /* Index of the currently processed character from fmt */
index_t nxt = 0;
index_t j = 0; /* Index to the first not printed nonformating character */
wchar_t uc; /* Current UTF-32 character decoded from fmt */
591,7 → 592,12
count_t counter = 0; /* Number of UTF-8 characters printed */
int retval; /* Return values from nested functions */
while ((uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT)) != 0) {
while (true) {
i = nxt;
uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
 
if (uc == '\0') break;
 
/* Control character */
if (uc == '%') {
/* Print common characters if any processed */
611,8 → 617,8
bool end = false;
do {
i++;
uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT);
i = nxt;
uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
switch (uc) {
case '#':
flags |= __PRINTF_FLAG_PREFIX;
637,18 → 643,21
/* Width & '*' operator */
int width = 0;
if (isdigit(uc)) {
while ((uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT)) != 0) {
while (true) {
width *= 10;
width += uc - '0';
 
i = nxt;
uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
if (uc == '\0')
break;
if (!isdigit(uc))
break;
width *= 10;
width += uc - '0';
i++;
}
} else if (uc == '*') {
/* Get width value from argument list */
i++;
uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT);
i = nxt;
uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
width = (int) va_arg(ap, int);
if (width < 0) {
/* Negative width sets '-' flag */
660,21 → 669,24
/* Precision and '*' operator */
int precision = 0;
if (uc == '.') {
i++;
uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT);
i = nxt;
uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
if (isdigit(uc)) {
while ((uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT)) != 0) {
while (true) {
precision *= 10;
precision += uc - '0';
 
i = nxt;
uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
if (uc == '\0')
break;
if (!isdigit(uc))
break;
precision *= 10;
precision += uc - '0';
i++;
}
} else if (fmt[i] == '*') {
} else if (uc == '*') {
/* Get precision value from the argument list */
i++;
uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT);
i = nxt;
uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
precision = (int) va_arg(ap, int);
if (precision < 0) {
/* Ignore negative precision */
692,11 → 704,11
case 'h':
/* Char or short */
qualifier = PrintfQualifierShort;
i++;
uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT);
i = nxt;
uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
if (uc == 'h') {
i++;
uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT);
i = nxt;
uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
qualifier = PrintfQualifierByte;
}
break;
703,11 → 715,11
case 'l':
/* Long or long long */
qualifier = PrintfQualifierLong;
i++;
uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT);
i = nxt;
uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
if (uc == 'l') {
i++;
uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT);
i = nxt;
uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT);
qualifier = PrintfQualifierLongLong;
}
break;
734,7 → 746,7
}
counter += retval;
j = i + 1;
j = nxt;
goto next_char;
case 'c':
if (qualifier == PrintfQualifierLong)
748,7 → 760,7
};
counter += retval;
j = i + 1;
j = nxt;
goto next_char;
/*
852,11 → 864,10
}
counter += retval;
j = i + 1;
j = nxt;
}
next_char:
i++;
;
}
if (i > j) {
/trunk/kernel/generic/src/lib/string.c
59,8 → 59,9
/** Decode a single UTF-8 character from a NULL-terminated string.
*
* Decode a single UTF-8 character from a plain char NULL-terminated
* string. Decoding starts at @index and this index is incremented
* if the current UTF-8 string is encoded in more than a single byte.
* string. Decoding starts at @index and this index is moved to the
* beginning of the next character. In case of decoding error,
* index advances. However, index is never moved beyond (str+limit).
*
* @param str Plain character NULL-terminated string.
* @param index Index (counted in plain characters) where to start
78,10 → 79,10
int b0_bits; /* Data bits in first byte. */
int cbytes; /* Number of continuation bytes. */
 
if (*index > limit)
if (*index + 1 > limit)
return invalch;
 
b0 = (uint8_t) str[*index];
b0 = (uint8_t) str[(*index)++];
 
/* Determine code length. */
 
114,8 → 115,7
 
/* Decode continuation bytes. */
while (cbytes > 0) {
b = (uint8_t) str[*index + 1];
++(*index);
b = (uint8_t) str[(*index)++];
 
/* Must be 10xxxxxx. */
if ((b & 0xc0) != 0x80) {
134,8 → 134,8
*
* Encode a single UTF-32 character as UTF-8 and store it into
* the given buffer at @index. Encoding starts at @index and
* this index is incremented if the UTF-8 character takes
* more than a single byte.
* this index is moved at the position where the next character
* can be written to.
*
* @param ch Input UTF-32 character.
* @param str Output buffer.
156,7 → 156,7
int b0_bits; /* Number of data bits in first byte. */
int i;
 
if (*index > limit)
if (*index >= limit)
return false;
 
if (ch < 0)
184,7 → 184,7
}
 
/* Check for available space in buffer. */
if (*index + cbytes > limit)
if (*index + cbytes >= limit)
return false;
 
/* Encode continuation bytes. */
197,7 → 197,7
str[*index] = (cc & LO_MASK_32(b0_bits)) | HI_MASK_8(8 - b0_bits - 1);
 
/* Advance index. */
*index += cbytes;
*index += (1 + cbytes);
return true;
}
219,13 → 219,20
{
size_t size = 0;
index_t index = 0;
index_t iprev;
wchar_t ch;
while ((utf8_decode(str, &index, UTF8_NO_LIMIT) != 0) && (size < count)) {
while (true) {
iprev = index;
if (size >= count)
break;
ch = utf8_decode(str, &index, UTF8_NO_LIMIT);
if (ch == '\0') break;
 
size++;
index++;
}
return index;
return iprev;
}
 
/** Check whether character is plain ASCII.
283,7 → 290,6
while (utf8_decode(str, &index, UTF8_NO_LIMIT) != 0) {
size++;
index++;
}
return size;