#include <stdlib.h>
#include <string.h>
-#include "data/file-name.h"
+#include "data/file-handle-def.h"
#include "data/settings.h"
#include "libpspp/array.h"
#include "libpspp/assertion.h"
#include "output/output-item.h"
#include "output/text-item.h"
+#include "gl/error.h"
#include "gl/xalloc.h"
#include "gl/xmemdup0.h"
{
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
{
if (!ds_is_empty (&e->deferred_syntax))
{
- char *syntax = ds_steal_cstr (&e->deferred_syntax);
- output_submit__ (e, text_item_super (
- text_item_create_nocopy (TEXT_ITEM_SYNTAX, syntax)));
+ ds_trim (&e->deferred_syntax, ss_cstr ("\n"));
+ if (!ds_is_empty (&e->deferred_syntax))
+ {
+ char *syntax = ds_steal_cstr (&e->deferred_syntax);
+ output_submit__ (e, text_item_super (text_item_create_nocopy (
+ TEXT_ITEM_SYNTAX, syntax)));
+ }
}
}
{
struct output_engine *e = engine_stack_top ();
+ if (item == NULL)
+ return;
+
if (is_syntax_item (item))
{
ds_put_cstr (&e->deferred_syntax, text_item_get_text (to_text_item (item)));
}
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;
extern const struct output_driver_factory csv_driver_factory;
-#ifdef ODF_WRITE_SUPPORT
extern const struct output_driver_factory odt_driver_factory;
-#endif
#ifdef HAVE_CAIRO
extern const struct output_driver_factory pdf_driver_factory;
extern const struct output_driver_factory ps_driver_factory;
&list_driver_factory,
&html_driver_factory,
&csv_driver_factory,
-#ifdef ODF_WRITE_SUPPORT
&odt_driver_factory,
-#endif
#ifdef HAVE_CAIRO
&pdf_driver_factory,
&ps_driver_factory,
device_type = default_device_type (file_name);
}
- driver = f->create (file_name, device_type, options);
+ struct file_handle *fh = fh_create_file (NULL, file_name, NULL, fh_default_properties ());
+
+ driver = f->create (fh, device_type, options);
if (driver != NULL)
{
const struct string_map_node *node;
return driver;
}
+
+void
+output_driver_parse_option (const char *option, struct string_map *options)
+{
+ const char *equals = strchr (option, '=');
+ if (equals == NULL)
+ {
+ error (0, 0, _("%s: output option missing `='"), option);
+ return;
+ }
+
+ char *key = xmemdup0 (option, equals - option);
+ if (string_map_contains (options, key))
+ {
+ error (0, 0, _("%s: output option specified more than once"), key);
+ free (key);
+ return;
+ }
+
+ char *value = xmemdup0 (equals + 1, strlen (equals + 1));
+ string_map_insert_nocopy (options, key, value);
+}