Added confidence and prediction intervals to model export
[pspp-builds.git] / src / ascii.c
index 6fa1573be050ae5ade4cf94ad947f03be6f8a266..738526f388e2b4ba3241471faeac348133374d29 100644 (file)
@@ -14,8 +14,8 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA. */
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA. */
 
 #include <config.h>
 #include "error.h"
 #include "alloc.h"
 #include "error.h"
 #include "filename.h"
+#include "glob.h"
 #include "main.h"
 #include "misc.h"
 #include "output.h"
 #include "pool.h"
 #include "version.h"
 
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
 /* ASCII driver options: (defaults listed first)
 
    output-file="pspp.list"
@@ -165,9 +169,9 @@ struct ascii_driver_ext
     int bottom_margin;         /* Bottom margin in lines. */
     int paginate;              /* 1=insert formfeeds. */
     int tab_width;             /* Width of a tab; 0 not to use tabs. */
-    struct len_string ops[OPS_COUNT]; /* Basic output strings. */
-    struct len_string box[LNS_COUNT]; /* Line & box drawing characters. */
-    struct len_string fonts[FSTY_COUNT]; /* Font styles; NULL=overstrike. */
+    struct fixed_string ops[OPS_COUNT]; /* Basic output strings. */
+    struct fixed_string box[LNS_COUNT]; /* Line & box drawing characters. */
+    struct fixed_string fonts[FSTY_COUNT]; /* Font styles; NULL=overstrike. */
     int overstrike_style;      /* OVS_SINGLE or OVS_LINE. */
     int carriage_return_style; /* Carriage return style. */
     int squeeze_blank_lines;    /* 1=squeeze multiple blank lines into one. */
@@ -187,16 +191,26 @@ struct ascii_driver_ext
 static int postopen (struct file_ext *);
 static int preclose (struct file_ext *);
 
+static struct outp_option_info *option_info;
+
 static int
 ascii_open_global (struct outp_class *this UNUSED)
 {
+  option_info = xmalloc (sizeof *option_info);
+  option_info->initial = 0;
+  option_info->options = 0;
   return 1;
 }
 
 
+static char *s;
 static int
 ascii_close_global (struct outp_class *this UNUSED)
 {
+  free(option_info->initial);
+  free(option_info->options);
+  free(option_info);
+  free(s);
   return 1;
 }
 
@@ -218,7 +232,7 @@ ascii_preopen_driver (struct outp_driver *this)
   
   assert (this->driver_open == 0);
   msg (VM (1), _("ASCII driver initializing as `%s'..."), this->name);
-  this->ext = x = xmalloc (sizeof (struct ascii_driver_ext));
+  this->ext = x = xmalloc (sizeof *x);
   x->char_set = CHS_ASCII;
   x->headers = 1;
   x->page_length = 66;
@@ -456,7 +470,6 @@ static struct outp_option option_tab[] =
     {"squeeze", boolean_arg, 2},
     {"", 0, 0},
   };
-static struct outp_option_info option_info;
 
 static void
 ascii_option (struct outp_driver *this, const char *key,
@@ -484,7 +497,7 @@ ascii_option (struct outp_driver *this, const char *key,
       return;
     }
 
-  cat = outp_match_keyword (key, option_tab, &option_info, &subcat);
+  cat = outp_match_keyword (key, option_tab, option_info, &subcat);
   switch (cat)
     {
     case 0:
@@ -590,7 +603,7 @@ ascii_option (struct outp_driver *this, const char *key,
       break;
     case string_arg:
       {
-       struct len_string *s;
+       struct fixed_string *s;
        switch (subcat)
          {
          case 0:
@@ -661,7 +674,7 @@ int
 postopen (struct file_ext *f)
 {
   struct ascii_driver_ext *x = f->param;
-  struct len_string *s = &x->ops[OPS_INIT];
+  struct fixed_string *s = &x->ops[OPS_INIT];
 
   if (!ls_empty_p (s) && fwrite (ls_c_str (s), ls_length (s), 1, f->file) < 1)
     {
@@ -676,7 +689,7 @@ int
 preclose (struct file_ext *f)
 {
   struct ascii_driver_ext *x = f->param;
-  struct len_string *d = &x->ops[OPS_DONE];
+  struct fixed_string *d = &x->ops[OPS_DONE];
 
   if (!ls_empty_p (d) && fwrite (ls_c_str (d), ls_length (d), 1, f->file) < 1)
     {
@@ -704,7 +717,7 @@ ascii_open_page (struct outp_driver *this)
 
   if (x->l > x->lines_cap)
     {
-      x->lines = xrealloc (x->lines, sizeof *x->lines * x->l);
+      x->lines = xnrealloc (x->lines, x->l, sizeof *x->lines);
       for (i = x->lines_cap; i < x->l; i++) 
         {
           struct line *line = &x->lines[i];
@@ -734,8 +747,8 @@ expand_line (struct ascii_driver_ext *x, int i, int l)
   if (l > line->char_cap) 
     {
       line->char_cap = l * 2;
-      line->chars = xrealloc (line->chars,
-                              line->char_cap * sizeof *line->chars); 
+      line->chars = xnrealloc (line->chars,
+                               line->char_cap, sizeof *line->chars); 
     }
   for (j = line->char_cnt; j < l; j++)
     line->chars[j] = ' ';
@@ -1146,8 +1159,8 @@ text_draw (struct outp_driver *this, struct outp_text *t)
 /* ascii_close_page () and support routines. */
 
 #define LINE_BUF_SIZE 1024
-static unsigned char *line_buf;
-static unsigned char *line_p;
+static char *line_buf;
+static char *line_p;
 
 static inline int
 commit_line_buf (struct outp_driver *this)
@@ -1200,7 +1213,7 @@ output_shorts (struct outp_driver *this,
     {
       if (*bp & 0x800)
        {
-         struct len_string *box = &ext->box[*bp & 0xff];
+         struct fixed_string *box = &ext->box[*bp & 0xff];
          size_t len = ls_length (box);
 
          if (remaining >= len)
@@ -1219,7 +1232,7 @@ output_shorts (struct outp_driver *this,
        }
       else if (*bp & 0x0300)
        {
-         struct len_string *on;
+         struct fixed_string *on;
          char buf[5];
          int len;
 
@@ -1300,7 +1313,7 @@ output_shorts (struct outp_driver *this,
 /* Writes CH into line_buf N times, or to THIS->output if line_buf
    overflows. */
 static inline void
-output_char (struct outp_driver *this, int n, int ch)
+output_char (struct outp_driver *this, int n, char ch)
 {
   if (LINE_BUF_SIZE - (line_p - line_buf) >= n)
     {
@@ -1364,7 +1377,7 @@ output_lines (struct outp_driver *this, int first, int count)
   struct ascii_driver_ext *ext = this->ext;
   int line_num;
 
-  struct len_string *newline = &ext->ops[OPS_NEWLINE];
+  struct fixed_string *newline = &ext->ops[OPS_NEWLINE];
 
   int n_chars;
   int n_passes;
@@ -1412,7 +1425,7 @@ output_lines (struct outp_driver *this, int first, int count)
          /* Turn off old font. */
          if (attr != (OUTP_F_R << 8))
            {
-             struct len_string *off;
+             struct fixed_string *off;
 
              switch (attr)
                {
@@ -1437,7 +1450,7 @@ output_lines (struct outp_driver *this, int first, int count)
          attr = (*bp & 0x0300);
          if (attr != (OUTP_F_R << 8))
            {
-             struct len_string *on;
+             struct fixed_string *on;
 
              switch (attr)
                {
@@ -1462,7 +1475,7 @@ output_lines (struct outp_driver *this, int first, int count)
        }
       if (n_passes > 1)
        {
-         unsigned char ch;
+         char ch;
 
          return_carriage (this, n_chars);
          n_chars = 0;
@@ -1518,15 +1531,15 @@ output_lines (struct outp_driver *this, int first, int count)
     }
 }
 
+
 static int
 ascii_close_page (struct outp_driver *this)
 {
-  static unsigned char *s;
   static int s_len;
 
   struct ascii_driver_ext *x = this->ext;
   int nl_len, ff_len, total_len;
-  unsigned char *cp;
+  char *cp;
   int i;
 
   assert (this->driver_open && this->page_open);
@@ -1567,7 +1580,8 @@ ascii_close_page (struct outp_driver *this)
       {
        char temp[40];
 
-       snprintf (temp, 80, _("%s - Page %d"), curdate, x->page_number);
+       snprintf (temp, 80, _("%s - Page %d"), get_start_date (),
+                  x->page_number);
        memcpy (&s[x->w - strlen (temp)], temp, strlen (temp));
       }
 
@@ -1610,6 +1624,7 @@ ascii_close_page (struct outp_driver *this)
   memcpy (cp, ls_c_str (&x->ops[OPS_FORMFEED]), ff_len);
   if ( x->paginate ) 
          output_string (this, s, &s[total_len]);
+
   if (line_p != line_buf && !commit_line_buf (this))
     return 0;
 
@@ -1617,6 +1632,21 @@ ascii_close_page (struct outp_driver *this)
   return 1;
 }
 
+
+
+static void
+ascii_chart_initialise(struct outp_driver *d UNUSED, struct chart *ch )
+{
+  msg(MW, _("Charts are unsupported with ascii drivers."));
+  ch->lp = 0;
+}
+
+static void 
+ascii_chart_finalise(struct outp_driver *d UNUSED, struct chart *ch UNUSED)
+{
+  
+}
+
 struct outp_class ascii_class =
 {
   "ascii",
@@ -1655,4 +1685,7 @@ struct outp_class ascii_class =
   ascii_text_get_size,
   ascii_text_metrics,
   ascii_text_draw,
+
+  ascii_chart_initialise,
+  ascii_chart_finalise
 };