From c91769acf89e163c06e86be0f17022572f33bbab Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Sat, 23 Feb 2008 09:42:02 -0700 Subject: [PATCH] s/obstack_print/shipout_string_trunc/. * src/m4.h (obstack_print): Rename... (shipout_string_trunc): ...to this, to leave obstack_ prefix for actual obstack API. * src/debug.c (trace_format): Adjust caller. (obstack_print): Move... * src/output.c (shipout_string_trunc): ...here, including rename. * src/input.c (input_print): Adjust caller. * src/macro.c (arg_print): Likewise. Reported by Ralf Wildenhues. Signed-off-by: Eric Blake --- ChangeLog | 11 +++++++++++ src/debug.c | 30 +----------------------------- src/input.c | 6 +++--- src/m4.h | 2 +- src/macro.c | 23 ++++++++++++++--------- src/output.c | 29 +++++++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index e902f673..22110522 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2008-02-23 Eric Blake + s/obstack_print/shipout_string_trunc/. + * src/m4.h (obstack_print): Rename... + (shipout_string_trunc): ...to this, to leave obstack_ prefix for + actual obstack API. + * src/debug.c (trace_format): Adjust caller. + (obstack_print): Move... + * src/output.c (shipout_string_trunc): ...here, including rename. + * src/input.c (input_print): Adjust caller. + * src/macro.c (arg_print): Likewise. + Reported by Ralf Wildenhues. + s/shipout_text/divert_text/. * src/m4.h (shipout_text): Rename... (divert_text): ...to this, so that shipout_ prefix can be used for diff --git a/src/debug.c b/src/debug.c index 737ee524..1c0c99bb 100644 --- a/src/debug.c +++ b/src/debug.c @@ -294,7 +294,7 @@ trace_format (const char *fmt, ...) break; } - if (obstack_print (&trace, s, SIZE_MAX, &maxlen)) + if (shipout_string_trunc (&trace, s, SIZE_MAX, &maxlen)) break; } @@ -401,31 +401,3 @@ trace_post (const char *name, int id, macro_arguments *argv, trace_format (" -> %l%B%r", expanded); trace_flush (); } - -/* Dump the string STR of length LEN to the obstack OBS. If LEN is - SIZE_MAX, use strlen (STR) instead. If MAX_LEN is non-NULL, - truncate the dump at MAX_LEN bytes and return true if MAX_LEN was - reached; otherwise, return false and update MAX_LEN as - appropriate. */ -bool -obstack_print (struct obstack *obs, const char *str, size_t len, int *max_len) -{ - int max = max_len ? *max_len : INT_MAX; - - if (len == SIZE_MAX) - len = strlen (str); - if (len < max) - { - obstack_grow (obs, str, len); - max -= len; - } - else - { - obstack_grow (obs, str, max); - obstack_grow (obs, "...", 3); - max = 0; - } - if (max_len) - *max_len = max; - return max == 0; -} diff --git a/src/input.c b/src/input.c index e2bf0aa3..e2d332a5 100644 --- a/src/input.c +++ b/src/input.c @@ -687,7 +687,7 @@ input_print (struct obstack *obs, const input_block *input) switch (input->type) { case INPUT_STRING: - obstack_print (obs, input->u.u_s.str, input->u.u_s.len, &maxlen); + shipout_string_trunc (obs, input->u.u_s.str, input->u.u_s.len, &maxlen); break; case INPUT_FILE: obstack_grow (obs, "type) { case CHAIN_STR: - if (obstack_print (obs, chain->u.u_s.str, chain->u.u_s.len, - &maxlen)) + if (shipout_string_trunc (obs, chain->u.u_s.str, + chain->u.u_s.len, &maxlen)) return; break; case CHAIN_ARGV: diff --git a/src/m4.h b/src/m4.h index 037482d5..7694ba0a 100644 --- a/src/m4.h +++ b/src/m4.h @@ -249,7 +249,6 @@ void trace_pre (const char *, int, macro_arguments *); void trace_post (const char *, int, macro_arguments *, const input_block *); -bool obstack_print (struct obstack *, const char *, size_t, int *); /* File: input.c --- lexical definitions. */ @@ -425,6 +424,7 @@ void output_init (void); void output_exit (void); void output_text (const char *, int); void divert_text (struct obstack *, const char *, int, int); +bool shipout_string_trunc (struct obstack *, const char *, size_t, int *); void make_diversion (int); void insert_diversion (int); void insert_file (FILE *); diff --git a/src/macro.c b/src/macro.c index b81697a4..366584ac 100644 --- a/src/macro.c +++ b/src/macro.c @@ -1212,23 +1212,27 @@ arg_print (struct obstack *obs, macro_arguments *argv, unsigned int index, { if (quote_each && max_len) len = *max_len; - if (use_sep && obstack_print (obs, sep, sep_len, plen)) + if (use_sep && shipout_string_trunc (obs, sep, sep_len, plen)) return true; use_sep = true; token = arg_token (argv, i, NULL); switch (TOKEN_DATA_TYPE (token)) { case TOKEN_TEXT: - if (quotes && obstack_print (obs, quotes->str1, quotes->len1, plen)) + if (quotes && shipout_string_trunc (obs, quotes->str1, quotes->len1, + plen)) return true; - if (obstack_print (obs, TOKEN_DATA_TEXT (token), - TOKEN_DATA_LEN (token), &len) && !quote_each) + if (shipout_string_trunc (obs, TOKEN_DATA_TEXT (token), + TOKEN_DATA_LEN (token), &len) + && !quote_each) return true; - if (quotes && obstack_print (obs, quotes->str2, quotes->len2, plen)) + if (quotes && shipout_string_trunc (obs, quotes->str2, quotes->len2, + plen)) return true; break; case TOKEN_COMP: - if (quotes && obstack_print (obs, quotes->str1, quotes->len1, plen)) + if (quotes && shipout_string_trunc (obs, quotes->str1, quotes->len1, + plen)) return true; chain = token->u.u_c.chain; done = false; @@ -1237,8 +1241,8 @@ arg_print (struct obstack *obs, macro_arguments *argv, unsigned int index, switch (chain->type) { case CHAIN_STR: - if (obstack_print (obs, chain->u.u_s.str, chain->u.u_s.len, - &len)) + if (shipout_string_trunc (obs, chain->u.u_s.str, + chain->u.u_s.len, &len)) done = true; break; case CHAIN_ARGV: @@ -1256,7 +1260,8 @@ arg_print (struct obstack *obs, macro_arguments *argv, unsigned int index, } if (done && !quote_each) return true; - if (quotes && obstack_print (obs, quotes->str2, quotes->len2, plen)) + if (quotes && shipout_string_trunc (obs, quotes->str2, quotes->len2, + plen)) return true; break; case TOKEN_FUNC: diff --git a/src/output.c b/src/output.c index 73a0e477..56ac1f42 100644 --- a/src/output.c +++ b/src/output.c @@ -571,6 +571,35 @@ divert_text (struct obstack *obs, const char *text, int length, int line) } } } + +/* Dump the string STR of length LEN to the obstack OBS. If LEN is + SIZE_MAX, use strlen (STR) instead. If MAX_LEN is non-NULL, + truncate the dump at MAX_LEN bytes and return true if MAX_LEN was + reached; otherwise, return false and update MAX_LEN as + appropriate. */ +bool +shipout_string_trunc (struct obstack *obs, const char *str, size_t len, + int *max_len) +{ + int max = max_len ? *max_len : INT_MAX; + + if (len == SIZE_MAX) + len = strlen (str); + if (len < max) + { + obstack_grow (obs, str, len); + max -= len; + } + else + { + obstack_grow (obs, str, max); + obstack_grow (obs, "...", 3); + max = 0; + } + if (max_len) + *max_len = max; + return max == 0; +} /* Functions for use by diversions. */ -- 2.11.4.GIT