X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fhtml.c;h=1b56ba1c2f77d2ee52af6a943e25b6846fad3124;hb=4a73877b4d56caed03d383fb4d38347a9774046f;hp=ea11459d132d642449c348227a9d623a65829760;hpb=92bfefccd465052e492f669ce561aa25b0110283;p=pspp-builds.git diff --git a/src/html.c b/src/html.c index ea11459d..1b56ba1c 100644 --- a/src/html.c +++ b/src/html.c @@ -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. */ /* This #if encloses the rest of the file. */ #if !NO_HTML @@ -35,11 +35,17 @@ #include "alloc.h" #include "error.h" #include "filename.h" +#include "getl.h" #include "getline.h" +#include "getlogin_r.h" #include "output.h" #include "som.h" #include "tab.h" #include "version.h" +#include "mkfile.h" + +#include "gettext.h" +#define _(msgid) gettext (msgid) /* Prototypes. */ static int postopen (struct file_ext *); @@ -122,6 +128,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 { @@ -217,9 +239,7 @@ postopen (struct file_ext *f) {"source-file", 0}, {0, 0}, }; -#if HAVE_UNISTD_H - char host[128]; -#endif + char login[128], host[128]; time_t curtime; struct tm *loctime; @@ -230,7 +250,7 @@ postopen (struct file_ext *f) FILE *prologue_file; char *buf = NULL; - int buf_size = 0; + size_t buf_size = 0; if (prologue_fn == NULL) { @@ -260,14 +280,13 @@ postopen (struct file_ext *f) *cp = 0; } - /* PORTME: Determine username, net address. */ -#if HAVE_UNISTD_H - dict[2].value = getenv ("LOGNAME"); - if (!dict[2].value) - dict[2].value = getlogin (); - if (!dict[2].value) - dict[2].value = _("nobody"); + if (getenv ("LOGNAME") != NULL) + str_copy_rpad (login, sizeof login, getenv ("LOGNAME")); + else if (getlogin_r (login, sizeof login)) + strcpy (login, _("nobody")); + dict[2].value = login; +#ifdef HAVE_UNISTD_H if (gethostname (host, 128) == -1) { if (errno == ENAMETOOLONG) @@ -275,11 +294,10 @@ postopen (struct file_ext *f) else strcpy (host, _("nowhere")); } +#else + strcpy (host, _("nowhere")); +#endif dict[3].value = host; -#else /* !HAVE_UNISTD_H */ - dict[2].value = _("nobody"); - dict[3].value = _("nowhere"); -#endif /* !HAVE_UNISTD_H */ dict[4].value = outp_title ? outp_title : ""; dict[5].value = outp_subtitle ? outp_subtitle : ""; @@ -392,7 +410,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; @@ -404,10 +422,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 @@ -481,7 +510,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; @@ -554,6 +583,31 @@ output_tab_table (struct outp_driver *this, struct tab_table *t) fputs ("\n\n", x->file.file); } +static void +html_initialise_chart(struct outp_driver *d 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 + +} + +static void +html_finalise_chart(struct outp_driver *d UNUSED, struct chart *ch) +{ + free(ch->filename); +} + + + /* HTML driver class. */ struct outp_class html_class = { @@ -593,6 +647,10 @@ struct outp_class html_class = NULL, NULL, NULL, + + html_initialise_chart, + html_finalise_chart + }; #endif /* !NO_HTML */