From 0d8d7d5b915ddd5a8cd63ebdddf1cea4a8590b72 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 8 Feb 2016 01:32:13 +0900 Subject: [PATCH] remove xformat family --- extlib/benz/error.c | 15 +++++---- extlib/benz/include/picrin/string.h | 5 --- extlib/benz/string.c | 48 ++++------------------------- extlib/benz/write.c | 2 +- 4 files changed, 14 insertions(+), 56 deletions(-) diff --git a/extlib/benz/error.c b/extlib/benz/error.c index 9097518f..42d3251c 100644 --- a/extlib/benz/error.c +++ b/extlib/benz/error.c @@ -21,30 +21,29 @@ void pic_warnf(pic_state *pic, const char *fmt, ...) { va_list ap; - pic_value err_line; + pic_str *err; va_start(ap, fmt); - err_line = pic_xvformat(pic, fmt, ap); + err = pic_vformat(pic, fmt, ap); va_end(ap); - xfprintf(pic, pic_stderr(pic)->file, "warn: %s\n", pic_str_cstr(pic, pic_str_ptr(pic_car(pic, err_line)))); + xfprintf(pic, pic_stderr(pic)->file, "warn: %s\n", pic_str_cstr(pic, err)); } void pic_errorf(pic_state *pic, const char *fmt, ...) { va_list ap; - pic_value err_line, irrs; const char *msg; + pic_str *err; va_start(ap, fmt); - err_line = pic_xvformat(pic, fmt, ap); + err = pic_vformat(pic, fmt, ap); va_end(ap); - msg = pic_str_cstr(pic, pic_str_ptr(pic_car(pic, err_line))); - irrs = pic_cdr(pic, err_line); + msg = pic_str_cstr(pic, err); - pic_error(pic, msg, irrs); + pic_error(pic, msg, pic_nil_value()); } pic_value diff --git a/extlib/benz/include/picrin/string.h b/extlib/benz/include/picrin/string.h index 68479d75..36389412 100644 --- a/extlib/benz/include/picrin/string.h +++ b/extlib/benz/include/picrin/string.h @@ -32,11 +32,6 @@ const char *pic_str_cstr(pic_state *, pic_str *); 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) } diff --git a/extlib/benz/string.c b/extlib/benz/string.c index 25e9099d..a5ab3191 100644 --- a/extlib/benz/string.c +++ b/extlib/benz/string.c @@ -283,13 +283,12 @@ pic_str_cstr(pic_state *pic, pic_str *str) return rope_cstr(pic, str->rope); } -pic_value -pic_xvfformat(pic_state *pic, xFILE *file, const char *fmt, va_list ap) +static void +pic_vfformat(pic_state *pic, xFILE *file, const char *fmt, va_list ap) { char c; - pic_value irrs = pic_nil_value(); - while ((c = *fmt++)) { + while ((c = *fmt++) != '\0') { switch (c) { default: xfputc(pic, c, file); @@ -337,52 +336,17 @@ pic_xvfformat(pic_state *pic, xFILE *file, const char *fmt, va_list ap) xfputc(pic, '\n', file); break; case 'a': - irrs = pic_cons(pic, pic_fdisplay(pic, va_arg(ap, pic_value), file), irrs); + pic_fdisplay(pic, va_arg(ap, pic_value), file); break; case 's': - irrs = pic_cons(pic, pic_fwrite(pic, va_arg(ap, pic_value), file), irrs); + pic_fwrite(pic, va_arg(ap, pic_value), file); break; } break; } } exit: - - return pic_reverse(pic, irrs); -} - -pic_value -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_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); - return irrs; -} - -pic_value -pic_xformat(pic_state *pic, const char *fmt, ...) -{ - va_list ap; - pic_value objs; - - va_start(ap, fmt); - 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); + return; } pic_str * diff --git a/extlib/benz/write.c b/extlib/benz/write.c index 0092da02..e36a8a0b 100644 --- a/extlib/benz/write.c +++ b/extlib/benz/write.c @@ -437,7 +437,7 @@ pic_printf(pic_state *pic, const char *fmt, ...) va_start(ap, fmt); - str = pic_str_ptr(pic_car(pic, pic_xvformat(pic, fmt, ap))); + str = pic_vformat(pic, fmt, ap); va_end(ap);