output: New function output_log().
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 24 Jan 2021 22:53:41 +0000 (14:53 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 25 Jan 2021 00:54:48 +0000 (16:54 -0800)
src/language/data-io/print-space.c
src/language/data-io/print.c
src/language/utilities/echo.c
src/language/utilities/host.c
src/output/driver.c
src/output/driver.h

index fafaff81a96d86be310110696e38b29bb42c08de..e166df5f63f0d6b16f4ecc5f9779c70e9b79b7e0 100644 (file)
@@ -27,7 +27,7 @@
 #include "language/expressions/public.h"
 #include "language/lexer/lexer.h"
 #include "libpspp/message.h"
-#include "output/output-item.h"
+#include "output/driver.h"
 
 #include "gl/xalloc.h"
 
@@ -134,7 +134,7 @@ print_space_trns_proc (void *t_, struct ccase **c,
 
   while (n--)
     if (trns->writer == NULL)
-      output_item_submit (text_item_create (TEXT_ITEM_LOG, "", NULL));
+      output_log ("%s", "");
     else
       dfm_put_record (trns->writer, " ", 1); /* XXX */
 
index 3b5541a3c3e68a62584f2a6ddb8373c2748f8b41..cc6971ded25938b53a3a1eba5609fe97dff08eb6 100644 (file)
@@ -40,6 +40,7 @@
 #include "libpspp/misc.h"
 #include "libpspp/pool.h"
 #include "libpspp/u8-line.h"
+#include "output/driver.h"
 #include "output/pivot-table.h"
 #include "output/table.h"
 #include "output/output-item.h"
@@ -562,9 +563,7 @@ print_text_flush_records (struct print_trns *trns, struct u8_line *line,
       *u8_line_reserve (line, 0, 1, 1) = leader;
 
       if (trns->writer == NULL)
-        output_item_submit (text_item_create (TEXT_ITEM_LOG,
-                                              ds_cstr (&line->s) + 1,
-                                              NULL));
+        output_log ("%s", ds_cstr (&line->s) + 1);
       else
         {
           size_t len = ds_length (&line->s);
index 13fa72155645a94224dd2e96e9ca3990bec923cb..e1871a9737f26a85eb6b3b38712470c9e5c68d95 100644 (file)
@@ -35,8 +35,7 @@ cmd_echo (struct lexer *lexer, struct dataset *ds UNUSED)
   if (!lex_force_string (lexer))
     return CMD_FAILURE;
 
-  output_submit (text_item_create (TEXT_ITEM_LOG, lex_tokcstr (lexer),
-                                   _("Echo")));
+  output_log ("%s", lex_tokcstr (lexer));
   lex_get (lexer);
 
   return CMD_SUCCESS;
index e38dc7ab27342c0924836ed4f31041998fc7646b..5273a8918b5a211bfd9ea2d18c910e365e7c2eaf 100644 (file)
@@ -38,7 +38,7 @@
 #include "libpspp/str.h"
 #include "libpspp/string-array.h"
 #include "libpspp/temp-file.h"
-#include "output/output-item.h"
+#include "output/driver.h"
 
 #include "gl/error.h"
 #include "gl/intprops.h"
@@ -261,8 +261,7 @@ run_command (const char *command, struct timespec timeout)
       if (end > output && end[-1] == '\n')
         end[-1] = '\0';
 
-      output_item_submit (text_item_create_nocopy (TEXT_ITEM_LOG, output,
-                                                   xstrdup (_("Host Output"))));
+      output_log ("%s", output);
     }
   free (locale_output);
 
index 7c0bff8bf58e708630adf742f49de875587aaa07..6dfebab854cf6a3164e4220cf780053b82a1bcca 100644 (file)
@@ -22,6 +22,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <limits.h>
+#include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
@@ -41,6 +42,7 @@
 #include "gl/error.h"
 #include "gl/xalloc.h"
 #include "gl/xmemdup0.h"
+#include "gl/xvasprintf.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -321,6 +323,17 @@ output_set_title__ (struct output_engine *e, char **dst, const char *src)
                                                page_title, NULL));
 }
 
+void PRINTF_FORMAT (1, 2)
+output_log (const char *format, ...)
+{
+  va_list args;
+  va_start (args, format);
+  char *s = xvasprintf (format, args);
+  va_end (args);
+
+  output_submit (text_item_create_nocopy (TEXT_ITEM_LOG, s, NULL));
+}
+
 void
 output_set_title (const char *title)
 {
index 32c0f87c44619301d9c2da87b954e15b8b5e2da0..8c386cb0650614d596b49ed3344322f38cae2d5e 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <stdbool.h>
 #include <stddef.h>
+#include "libpspp/compiler.h"
 
 struct output_item;
 struct string_set;
@@ -32,6 +33,8 @@ void output_engine_pop (void);
 void output_submit (struct output_item *);
 void output_flush (void);
 
+void output_log (const char *, ...) PRINTF_FORMAT (1, 2);
+
 void output_set_title (const char *);
 void output_set_subtitle (const char *);
 void output_set_filename (const char *);