version 1.2, 2009/06/03 16:05:46 |
version 1.3, 2009/06/03 16:54:26 |
|
|
} |
} |
|
|
/* Calculate string length. */ |
/* Calculate string length. */ |
size_t printflike1 |
size_t printflike2 |
screen_write_strlen(const char *fmt, ...) |
screen_write_strlen(int utf8flag, const char *fmt, ...) |
{ |
{ |
va_list ap; |
va_list ap; |
char *msg; |
char *msg; |
|
|
|
|
ptr = msg; |
ptr = msg; |
while (*ptr != '\0') { |
while (*ptr != '\0') { |
if (*ptr > 0x7f) { /* Assume this is UTF-8. */ |
if (utf8flag && *ptr > 0x7f) { |
memset(utf8buf, 0xff, sizeof utf8buf); |
memset(utf8buf, 0xff, sizeof utf8buf); |
|
|
left = strlen(ptr); |
left = strlen(ptr); |
|
|
return (size); |
return (size); |
} |
} |
|
|
/* Write string. */ |
/* Write simple string (no UTF-8 or maximum length). */ |
void printflike3 |
void printflike3 |
screen_write_puts( |
screen_write_puts( |
struct screen_write_ctx *ctx, struct grid_cell *gc, const char *fmt, ...) |
struct screen_write_ctx *ctx, struct grid_cell *gc, const char *fmt, ...) |
|
|
va_list ap; |
va_list ap; |
|
|
va_start(ap, fmt); |
va_start(ap, fmt); |
screen_write_vnputs(ctx, -1, gc, fmt, ap); |
screen_write_vnputs(ctx, -1, gc, 0, fmt, ap); |
va_end(ap); |
va_end(ap); |
} |
} |
|
|
/* Write string with length limit (-1 for unlimited). */ |
/* Write string with length limit (-1 for unlimited). */ |
void printflike4 |
void printflike5 |
screen_write_nputs(struct screen_write_ctx *ctx, |
screen_write_nputs(struct screen_write_ctx *ctx, |
ssize_t maxlen, struct grid_cell *gc, const char *fmt, ...) |
ssize_t maxlen, struct grid_cell *gc, int utf8flag, const char *fmt, ...) |
{ |
{ |
va_list ap; |
va_list ap; |
|
|
va_start(ap, fmt); |
va_start(ap, fmt); |
screen_write_vnputs(ctx, maxlen, gc, fmt, ap); |
screen_write_vnputs(ctx, maxlen, gc, utf8flag, fmt, ap); |
va_end(ap); |
va_end(ap); |
} |
} |
|
|
void |
void |
screen_write_vnputs(struct screen_write_ctx *ctx, |
screen_write_vnputs(struct screen_write_ctx *ctx, ssize_t maxlen, |
ssize_t maxlen, struct grid_cell *gc, const char *fmt, va_list ap) |
struct grid_cell *gc, int utf8flag, const char *fmt, va_list ap) |
{ |
{ |
char *msg; |
char *msg; |
u_char *ptr, utf8buf[4]; |
u_char *ptr, utf8buf[4]; |
|
|
|
|
ptr = msg; |
ptr = msg; |
while (*ptr != '\0') { |
while (*ptr != '\0') { |
if (*ptr > 0x7f) { /* Assume this is UTF-8. */ |
if (utf8flag && *ptr > 0x7f) { |
memset(utf8buf, 0xff, sizeof utf8buf); |
memset(utf8buf, 0xff, sizeof utf8buf); |
|
|
left = strlen(ptr); |
left = strlen(ptr); |