[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
style: isolate the creation of tname in a function
From: |
Akim Demaille |
Subject: |
style: isolate the creation of tname in a function |
Date: |
Sat, 12 Jan 2019 07:50:15 +0100 |
Just moving code, no actual change.
commit c8ee05c2b2695c354012a6f3f0aee9062fdb517e
Author: Akim Demaille <address@hidden>
Date: Fri Jan 11 07:04:50 2019 +0100
style: isolate the creation of tname in a function
* src/output.c (prepare_symbol_names): New.
Use it.
diff --git a/src/output.c b/src/output.c
index 7298fc7e..6e3e0c2c 100644
--- a/src/output.c
+++ b/src/output.c
@@ -137,6 +137,46 @@ string_output (FILE *out, char const *string)
}
+/*----------------------------.
+| Prepare the symbols names. |
+`----------------------------*/
+
+static void
+prepare_symbol_names (char const *muscle_name)
+{
+ /* We assume that the table will be output starting at column 2. */
+ int j = 2;
+ struct quoting_options *qo = clone_quoting_options (0);
+ set_quoting_style (qo, c_quoting_style);
+ set_quoting_flags (qo, QA_SPLIT_TRIGRAPHS);
+ for (int i = 0; i < nsyms; i++)
+ {
+ char *cp = quotearg_alloc (symbols[i]->tag, -1, qo);
+ /* Width of the next token, including the two quotes, the
+ comma and the space. */
+ int width = strlen (cp) + 2;
+
+ if (j + width > 75)
+ {
+ obstack_sgrow (&format_obstack, "\n ");
+ j = 1;
+ }
+
+ if (i)
+ obstack_1grow (&format_obstack, ' ');
+ obstack_escape (&format_obstack, cp);
+ free (cp);
+ obstack_1grow (&format_obstack, ',');
+ j += width;
+ }
+ free (qo);
+ obstack_sgrow (&format_obstack, " ]b4_null[");
+
+ /* Finish table and store. */
+ muscle_insert (muscle_name, obstack_finish0 (&format_obstack));
+}
+
+
/*------------------------------------------------------------------.
| Prepare the muscles related to the symbols: translate, tname, and |
| toknum. |
@@ -157,38 +197,7 @@ prepare_symbols (void)
1, max_user_token_number + 1);
/* tname -- token names. */
- {
- /* We assume that the table will be output starting at column 2. */
- int j = 2;
- struct quoting_options *qo = clone_quoting_options (0);
- set_quoting_style (qo, c_quoting_style);
- set_quoting_flags (qo, QA_SPLIT_TRIGRAPHS);
- for (int i = 0; i < nsyms; i++)
- {
- char *cp = quotearg_alloc (symbols[i]->tag, -1, qo);
- /* Width of the next token, including the two quotes, the
- comma and the space. */
- int width = strlen (cp) + 2;
-
- if (j + width > 75)
- {
- obstack_sgrow (&format_obstack, "\n ");
- j = 1;
- }
-
- if (i)
- obstack_1grow (&format_obstack, ' ');
- obstack_escape (&format_obstack, cp);
- free (cp);
- obstack_1grow (&format_obstack, ',');
- j += width;
- }
- free (qo);
- obstack_sgrow (&format_obstack, " ]b4_null[");
-
- /* Finish table and store. */
- muscle_insert ("tname", obstack_finish0 (&format_obstack));
- }
+ prepare_symbol_names ("tname");
/* Output YYTOKNUM. */
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- style: isolate the creation of tname in a function,
Akim Demaille <=