This reduces redundancy.
const ucs4_t *box; /* Line & box drawing characters. */
/* Internal state. */
- char *command_name;
struct file_handle *handle;
FILE *file; /* Output file. */
bool error; /* Output error? */
NULL_SENTINEL);
a->box = box == BOX_ASCII ? ascii_box_chars : unicode_box_chars;
- a->command_name = NULL;
a->file = NULL;
a->error = false;
a->lines = NULL;
if (a->file != NULL)
fn_close (a->handle, a->file);
fh_unref (a->handle);
- free (a->command_name);
free (a->chart_file_name);
for (i = 0; i < a->allocated_lines; i++)
u8_line_destroy (&a->lines[i]);
{
struct ascii_driver *a = ascii_driver_cast (driver);
- output_driver_track_current_command (output_item, &a->command_name);
-
if (a->error)
return;
{
const struct message_item *message_item = to_message_item (output_item);
const struct msg *msg = message_item_get_msg (message_item);
- char *s = msg_to_string (msg, a->command_name);
+ char *s = msg_to_string (msg, message_item->command_name);
ascii_output_text (a, s);
free (s);
}
cairo_destroy (xr->cairo);
}
- free (xr->command_name);
for (i = 0; i < XR_N_FONTS; i++)
{
struct xr_font *font = &xr->fonts[i];
{
struct xr_driver *xr = xr_driver_cast (driver);
- output_driver_track_current_command (output_item, &xr->command_name);
-
xr_driver_output_item (xr, output_item);
while (xr_driver_need_new_page (xr))
{
struct xr_render_fsm *fsm;
char *s;
- s = msg_to_string (msg, xr->command_name);
+ s = msg_to_string (msg, message_item->command_name);
fsm = xr_create_text_renderer (xr, s);
free (s);
bool captions; /* Print table captions? */
struct file_handle *handle;
- char *command_name; /* Current command. */
FILE *file; /* Output file. */
int n_items; /* Number of items output so far. */
};
{
struct csv_driver *csv = csv_driver_cast (driver);
- output_driver_track_current_command (output_item, &csv->command_name);
-
if (is_table_item (output_item))
{
struct table_item *table_item = to_table_item (output_item);
{
const struct message_item *message_item = to_message_item (output_item);
const struct msg *msg = message_item_get_msg (message_item);
- char *s = msg_to_string (msg, csv->command_name);
+ char *s = msg_to_string (msg, message_item->command_name);
csv_put_separator (csv);
csv_output_field (csv, s);
free (s);
void (*flush) (struct output_driver *driver);
};
-/* Useful for output driver implementation. */
-void output_driver_track_current_command (const struct output_item *, char **);
-\f
+
/* An abstract way for the output subsystem to create an output driver. */
struct output_driver_factory
{
{
struct llx_list drivers; /* Contains "struct output_driver"s. */
struct string deferred_syntax; /* TEXT_ITEM_SYNTAX being accumulated. */
+ char *command_name; /* Name of command being processed. */
};
static const struct output_driver_factory *factories[];
e = &engine_stack[n_stack++];
llx_init (&e->drivers);
ds_init_empty (&e->deferred_syntax);
+ e->command_name = NULL;
}
void
output_driver_destroy (d);
}
ds_destroy (&e->deferred_syntax);
+ free (e->command_name);
}
void
}
flush_deferred_syntax (e);
+
+ if (is_text_item (item))
+ {
+ const struct text_item *text_item = to_text_item (item);
+ const char *text = text_item_get_text (text_item);
+ enum text_item_type type = text_item_get_type (text_item);
+
+ if (type == TEXT_ITEM_COMMAND_OPEN)
+ {
+ free (e->command_name);
+ e->command_name = xstrdup (text);
+ }
+ else if (type == TEXT_ITEM_COMMAND_CLOSE)
+ {
+ free (e->command_name);
+ e->command_name = NULL;
+ }
+ }
+ else if (is_message_item (item))
+ {
+ struct message_item *message_item = to_message_item (item);
+ free (message_item->command_name);
+ message_item->command_name = (e->command_name
+ ? xstrdup (e->command_name)
+ : NULL);
+ }
+
output_submit__ (e, item);
}
return output_driver_get_engine (driver) != NULL;
}
\f
-/* Useful functions for output driver implementation. */
-
-void
-output_driver_track_current_command (const struct output_item *output_item,
- char **command_namep)
-{
- if (is_text_item (output_item))
- {
- const struct text_item *item = to_text_item (output_item);
- const char *text = text_item_get_text (item);
- enum text_item_type type = text_item_get_type (item);
-
- if (type == TEXT_ITEM_COMMAND_OPEN)
- {
- free (*command_namep);
- *command_namep = xstrdup (text);
- }
- else if (type == TEXT_ITEM_COMMAND_CLOSE)
- {
- free (*command_namep);
- *command_namep = NULL;
- }
- }
-}
-\f
extern const struct output_driver_factory txt_driver_factory;
extern const struct output_driver_factory list_driver_factory;
extern const struct output_driver_factory html_driver_factory;
struct file_handle *handle;
char *chart_file_name;
- char *command_name;
FILE *file;
size_t chart_cnt;
}
free (html->chart_file_name);
fh_unref (html->handle);
- free (html->command_name);
free (html);
}
{
struct html_driver *html = html_driver_cast (driver);
- output_driver_track_current_command (output_item, &html->command_name);
-
if (is_table_item (output_item))
{
struct table_item *table_item = to_table_item (output_item);
{
const struct message_item *message_item = to_message_item (output_item);
const struct msg *msg = message_item_get_msg (message_item);
- char *s = msg_to_string (msg, html->command_name);
+ char *s = msg_to_string (msg, message_item->command_name);
print_title_tag (html->file, "P", s);
free (s);
}
{
struct output_driver driver;
FILE *file;
- char *command_name;
/* Name of journal file. */
char *file_name;
struct journal_driver *j = journal_driver_cast (driver);
if ( !j->destroyed)
- {
- journal_close ();
- free (j->command_name);
- }
+ journal_close ();
j->destroyed = true;
}
{
struct journal_driver *j = journal_driver_cast (driver);
- output_driver_track_current_command (item, &j->command_name);
-
if (is_text_item (item))
{
const struct text_item *text_item = to_text_item (item);
{
const struct message_item *message_item = to_message_item (item);
const struct msg *msg = message_item_get_msg (message_item);
- char *s = msg_to_string (msg, j->command_name);
+ char *s = msg_to_string (msg, message_item->command_name);
journal_output (j, s);
free (s);
}
output_driver_init (&journal.driver, &journal_class, "journal",
SETTINGS_DEVICE_UNFILTERED);
journal.file = NULL;
- journal.command_name = NULL;
/* Register journal driver. */
output_driver_register (&journal.driver);
item = xmalloc (sizeof *msg);
output_item_init (&item->output_item, &message_item_class);
item->msg = msg_dup (msg);
+ item->command_name = NULL;
return item;
}
{
struct message_item *item = to_message_item (output_item);
msg_destroy (item->msg);
+ free (item->command_name);
free (item);
}
{
struct output_item output_item;
struct msg *msg;
+ char *command_name;
};
struct message_item *message_item_create (const struct msg *);
struct output_driver driver;
FILE *file;
struct file_handle *handle;
- char *command_name;
};
static const struct output_driver_class msglog_class;
ml->handle = handle;
output_driver_init (&ml->driver, &msglog_class, file_name, type);
ml->file = file;
- ml->command_name = NULL;
output_driver_register (&ml->driver);
struct msglog_driver *ml = msglog_driver_cast (driver);
fn_close (ml->handle, ml->file);
- free (ml->command_name);
fh_unref (ml->handle);
free (ml);
}
{
struct msglog_driver *ml = msglog_driver_cast (driver);
- output_driver_track_current_command (item, &ml->command_name);
-
if (is_message_item (item))
{
const struct message_item *message_item = to_message_item (item);
const struct msg *msg = message_item_get_msg (message_item);
- char *s = msg_to_string (msg, ml->command_name);
+ char *s = msg_to_string (msg, message_item->command_name);
fprintf (ml->file, "%s\n", s);
free (s);
}
/* Number of tables so far. */
int table_num;
- /* Name of current command. */
- char *command_name;
-
/* Number of footnotes so far. */
int n_footnotes;
};
}
free (odt->file_name);
- free (odt->command_name);
free (odt);
}
{
struct odt_driver *odt = odt_driver_cast (driver);
- output_driver_track_current_command (output_item, &odt->command_name);
-
if (is_table_item (output_item))
write_table (odt, to_table_item (output_item));
else if (is_text_item (output_item))
{
const struct message_item *message_item = to_message_item (output_item);
const struct msg *msg = message_item_get_msg (message_item);
- char *s = msg_to_string (msg, odt->command_name);
+ char *s = msg_to_string (msg, message_item->command_name);
odt_output_text (odt, s);
free (s);
}