change interface of format functions
This commit is contained in:
parent
876e40bfa5
commit
a94ef9433d
4
error.c
4
error.c
|
@ -27,7 +27,7 @@ pic_warnf(pic_state *pic, const char *fmt, ...)
|
||||||
pic_value err_line;
|
pic_value err_line;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
err_line = pic_vformat(pic, fmt, ap);
|
err_line = pic_xvformat(pic, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
fprintf(stderr, "warn: %s\n", pic_str_cstr(pic_str_ptr(pic_car(pic, err_line))));
|
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;
|
const char *msg;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
err_line = pic_vformat(pic, fmt, ap);
|
err_line = pic_xvformat(pic, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
msg = pic_str_cstr(pic_str_ptr(pic_car(pic, err_line)));
|
msg = pic_str_cstr(pic_str_ptr(pic_car(pic, err_line)));
|
||||||
|
|
|
@ -31,9 +31,13 @@ int pic_strcmp(pic_str *, pic_str *);
|
||||||
|
|
||||||
const char *pic_str_cstr(pic_str *);
|
const char *pic_str_cstr(pic_str *);
|
||||||
|
|
||||||
pic_value pic_format(pic_state *, const char *, ...);
|
pic_str *pic_format(pic_state *, const char *, ...);
|
||||||
pic_value pic_vformat(pic_state *, const char *, va_list);
|
pic_str *pic_vformat(pic_state *, const char *, va_list);
|
||||||
pic_value pic_vfformat(pic_state *, xFILE *, 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)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|
44
string.c
44
string.c
|
@ -137,7 +137,7 @@ pic_str_cstr(pic_str *str)
|
||||||
}
|
}
|
||||||
|
|
||||||
pic_value
|
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;
|
char c;
|
||||||
pic_value irrs = pic_nil_value();
|
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_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;
|
struct pic_port *port;
|
||||||
pic_value irrs;
|
pic_value irrs;
|
||||||
|
|
||||||
port = pic_open_output_string(pic);
|
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);
|
irrs = pic_cons(pic, pic_obj_value(pic_get_output_string(pic, port)), irrs);
|
||||||
|
|
||||||
pic_close_port(pic, port);
|
pic_close_port(pic, port);
|
||||||
|
@ -220,18 +220,52 @@ pic_vformat(pic_state *pic, const char *fmt, va_list ap)
|
||||||
}
|
}
|
||||||
|
|
||||||
pic_value
|
pic_value
|
||||||
pic_format(pic_state *pic, const char *fmt, ...)
|
pic_xformat(pic_state *pic, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
pic_value objs;
|
pic_value objs;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
objs = pic_vformat(pic, fmt, ap);
|
objs = pic_xvformat(pic, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
return objs;
|
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
|
static pic_value
|
||||||
pic_str_string_p(pic_state *pic)
|
pic_str_string_p(pic_state *pic)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue