X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fhtml.c;h=608de8a2d9c2f2ebc487a0cb4b39394d18f2792e;hb=843e8862e77bcc2813a944b6feb524ea6cc2ab6a;hp=6f56b47e9762efd6afbdb6ced40d556bdff609fd;hpb=7b98b3a4f58f6dc5a8e9cbc188b627966d5e652d;p=pspp-builds.git diff --git a/src/html.c b/src/html.c index 6f56b47e..608de8a2 100644 --- a/src/html.c +++ b/src/html.c @@ -22,7 +22,7 @@ #include #include "htmlP.h" -#include +#include "error.h" #include #include #include @@ -40,6 +40,7 @@ #include "som.h" #include "tab.h" #include "version.h" +#include "mkfile.h" /* Prototypes. */ static int postopen (struct file_ext *); @@ -122,6 +123,22 @@ html_close_driver (struct outp_driver *this) return 1; } + +/* Link the image contained in FILENAME to the + HTML stream in file F. */ +static int +link_image (struct file_ext *f, char *filename) +{ + fprintf (f->file, + "", filename); + + if (ferror (f->file)) + return 0; + + return 1; +} + + /* Generic option types. */ enum { @@ -156,7 +173,7 @@ html_option (struct outp_driver *this, const char *key, const struct string *val break; case 1: free (x->file.filename); - x->file.filename = xstrdup (ds_value (val)); + x->file.filename = xstrdup (ds_c_str (val)); break; case string_arg: { @@ -168,10 +185,11 @@ html_option (struct outp_driver *this, const char *key, const struct string *val break; default: assert (0); + abort (); } if (*dest) free (*dest); - *dest = xstrdup (ds_value (val)); + *dest = xstrdup (ds_c_str (val)); } break; default: @@ -391,7 +409,7 @@ html_close_page (struct outp_driver *this) static void output_tab_table (struct outp_driver *, struct tab_table *); static void -html_submit (struct outp_driver *this, struct som_table *s) +html_submit (struct outp_driver *this, struct som_entity *s) { extern struct som_table_class tab_table_class; struct html_driver_ext *x = this->ext; @@ -403,10 +421,21 @@ html_submit (struct outp_driver *this, struct som_table *s) return; } - if (s->class == &tab_table_class) - output_tab_table (this, (struct tab_table *) s->ext); - else - assert (0); + assert ( s->class == &tab_table_class ) ; + + switch (s->type) + { + case SOM_TABLE: + output_tab_table ( this, (struct tab_table *) s->ext); + break; + case SOM_CHART: + link_image( &x->file, ((struct chart *)s->ext)->filename); + break; + default: + assert(0); + break; + } + } /* Write string S of length LEN to file F, escaping characters as @@ -453,7 +482,7 @@ output_tab_table (struct outp_driver *this, struct tab_table *t) { fputs ("

", x->file.file); if (!ls_empty_p (t->cc)) - escape_string (x->file.file, ls_value (t->cc), ls_length (t->cc)); + escape_string (x->file.file, ls_c_str (t->cc), ls_length (t->cc)); fputs ("

\n", x->file.file); return; @@ -464,7 +493,7 @@ output_tab_table (struct outp_driver *this, struct tab_table *t) if (!ls_empty_p (&t->title)) { fprintf (x->file.file, " \n ", t->nc); - escape_string (x->file.file, ls_value (&t->title), + escape_string (x->file.file, ls_c_str (&t->title), ls_length (&t->title)); fputs ("\n \n", x->file.file); } @@ -480,7 +509,7 @@ output_tab_table (struct outp_driver *this, struct tab_table *t) fputs (" \n", x->file.file); for (c = 0; c < t->nc; c++, ct++) { - struct len_string *cc; + struct fixed_string *cc; int tag; char header[128]; char *cp; @@ -489,7 +518,7 @@ output_tab_table (struct outp_driver *this, struct tab_table *t) cc = t->cc + c + r * t->nc; if (*ct & TAB_JOIN) { - j = (struct tab_joined_cell *) ls_value (cc); + j = (struct tab_joined_cell *) ls_c_str (cc); cc = &j->contents; if (j->x1 != c || j->y1 != r) continue; @@ -532,7 +561,7 @@ output_tab_table (struct outp_driver *this, struct tab_table *t) if ( ! (*ct & TAB_EMPTY) ) { - char *s = ls_value (cc); + char *s = ls_c_str (cc); size_t l = ls_length (cc); while (l && isspace ((unsigned char) *s)) @@ -553,6 +582,36 @@ output_tab_table (struct outp_driver *this, struct tab_table *t) fputs ("\n\n", x->file.file); } + +void html_initialise_chart(struct outp_class *c, struct chart *ch); +void html_finalise_chart(struct outp_class *c, struct chart *ch); + + +void +html_initialise_chart(struct outp_class *c UNUSED, struct chart *ch) +{ + + FILE *fp; + + make_unique_file_stream(&fp, &ch->filename); + +#ifdef NO_CHARTS + ch->lp = 0; +#else + ch->pl_params = pl_newplparams(); + ch->lp = pl_newpl_r ("png", 0, fp, stderr, ch->pl_params); +#endif + +} + +void +html_finalise_chart(struct outp_class *c UNUSED, struct chart *ch) +{ + free(ch->filename); +} + + + /* HTML driver class. */ struct outp_class html_class = { @@ -592,6 +651,10 @@ struct outp_class html_class = NULL, NULL, NULL, + + html_initialise_chart, + html_finalise_chart + }; #endif /* !NO_HTML */