change interface of format functions

This commit is contained in:
Yuichi Nishiwaki 2014-08-26 13:30:08 +09:00
parent 876e40bfa5
commit a94ef9433d
4 changed files with 49 additions and 11 deletions

View File

@ -27,7 +27,7 @@ pic_warnf(pic_state *pic, const char *fmt, ...)
pic_value err_line;
va_start(ap, fmt);
err_line = pic_vformat(pic, fmt, ap);
err_line = pic_xvformat(pic, fmt, ap);
va_end(ap);
fprintf(stderr, "warn: %s\n", pic_str_cstr(pic_str_ptr(pic_car(pic, err_line))));
@ -130,7 +130,7 @@ pic_errorf(pic_state *pic, const char *fmt, ...)
const char *msg;
va_start(ap, fmt);
err_line = pic_vformat(pic, fmt, ap);
err_line = pic_xvformat(pic, fmt, ap);
va_end(ap);
msg = pic_str_cstr(pic_str_ptr(pic_car(pic, err_line)));

View File

@ -31,9 +31,13 @@ int pic_strcmp(pic_str *, pic_str *);
const char *pic_str_cstr(pic_str *);
pic_value pic_format(pic_state *, const char *, ...);
pic_value pic_vformat(pic_state *, const char *, va_list);
pic_value pic_vfformat(pic_state *, xFILE *, const char *, va_list);
pic_str *pic_format(pic_state *, const char *, ...);
pic_str *pic_vformat(pic_state *, const char *, va_list);
void pic_vfformat(pic_state *, xFILE *, const char *, va_list);
pic_value pic_xformat(pic_state *, const char *, ...);
pic_value pic_xvformat(pic_state *, const char *, va_list);
pic_value pic_xvfformat(pic_state *, xFILE *, const char *, va_list);
#if defined(__cplusplus)
}

View File

@ -137,7 +137,7 @@ pic_str_cstr(pic_str *str)
}
pic_value
pic_vfformat(pic_state *pic, xFILE *file, const char *fmt, va_list ap)
pic_xvfformat(pic_state *pic, xFILE *file, const char *fmt, va_list ap)
{
char c;
pic_value irrs = pic_nil_value();
@ -205,14 +205,14 @@ pic_vfformat(pic_state *pic, xFILE *file, const char *fmt, va_list ap)
}
pic_value
pic_vformat(pic_state *pic, const char *fmt, va_list ap)
pic_xvformat(pic_state *pic, const char *fmt, va_list ap)
{
struct pic_port *port;
pic_value irrs;
port = pic_open_output_string(pic);
irrs = pic_vfformat(pic, port->file, fmt, ap);
irrs = pic_xvfformat(pic, port->file, fmt, ap);
irrs = pic_cons(pic, pic_obj_value(pic_get_output_string(pic, port)), irrs);
pic_close_port(pic, port);
@ -220,18 +220,52 @@ pic_vformat(pic_state *pic, const char *fmt, va_list ap)
}
pic_value
pic_format(pic_state *pic, const char *fmt, ...)
pic_xformat(pic_state *pic, const char *fmt, ...)
{
va_list ap;
pic_value objs;
va_start(ap, fmt);
objs = pic_vformat(pic, fmt, ap);
objs = pic_xvformat(pic, fmt, ap);
va_end(ap);
return objs;
}
void
pic_vfformat(pic_state *pic, xFILE *file, const char *fmt, va_list ap)
{
pic_xvfformat(pic, file, fmt, ap);
}
pic_str *
pic_vformat(pic_state *pic, const char *fmt, va_list ap)
{
struct pic_port *port;
pic_str *str;
port = pic_open_output_string(pic);
pic_vfformat(pic, port->file, fmt, ap);
str = pic_get_output_string(pic, port);
pic_close_port(pic, port);
return str;
}
pic_str *
pic_format(pic_state *pic, const char *fmt, ...)
{
va_list ap;
pic_str *str;
va_start(ap, fmt);
str = pic_vformat(pic, fmt, ap);
va_end(ap);
return str;
}
static pic_value
pic_str_string_p(pic_state *pic)
{

View File

@ -442,7 +442,7 @@ pic_printf(pic_state *pic, const char *fmt, ...)
va_start(ap, fmt);
str = pic_str_ptr(pic_car(pic, pic_vformat(pic, fmt, ap)));
str = pic_str_ptr(pic_car(pic, pic_xvformat(pic, fmt, ap)));
va_end(ap);