static void html_styled_ostream::free (html_styled_ostream_t stream) { html_ostream_free (stream->html_destination); ostream_write_str (stream->destination, "</body>\n"); ostream_write_str (stream->destination, "</html>\n"); }
void message_print_comment_dot (const message_ty *mp, ostream_t stream) { if (mp->comment_dot != NULL) { size_t j; begin_css_class (stream, class_extracted_comment); for (j = 0; j < mp->comment_dot->nitems; ++j) { const char *s = mp->comment_dot->item[j]; ostream_write_str (stream, "#."); if (*s != '\0') ostream_write_str (stream, " "); ostream_write_str (stream, s); ostream_write_str (stream, "\n"); } end_css_class (stream, class_extracted_comment); } }
static void emit_pending_spans (html_ostream_t stream, bool shrink_stack) { if (stream->curr_class_stack_size > stream->last_class_stack_size) { size_t i; for (i = stream->last_class_stack_size; i < stream->curr_class_stack_size; i++) { char *classname = (char *) gl_list_get_at (stream->class_stack, i); ostream_write_str (stream->destination, "<span class=\""); ostream_write_str (stream->destination, classname); ostream_write_str (stream->destination, "\">"); } stream->last_class_stack_size = stream->curr_class_stack_size; } else if (stream->curr_class_stack_size < stream->last_class_stack_size) { size_t i = stream->last_class_stack_size; while (i > stream->curr_class_stack_size) { char *classname; --i; classname = (char *) gl_list_get_at (stream->class_stack, i); ostream_write_str (stream->destination, "</span>"); if (shrink_stack) { gl_list_remove_at (stream->class_stack, i); free (classname); } } stream->last_class_stack_size = stream->curr_class_stack_size; } }
void message_print_comment (const message_ty *mp, ostream_t stream) { if (mp->comment != NULL) { size_t j; begin_css_class (stream, class_translator_comment); for (j = 0; j < mp->comment->nitems; ++j) { const char *s = mp->comment->item[j]; do { const char *e; ostream_write_str (stream, "#"); if (*s != '\0') ostream_write_str (stream, " "); e = strchr (s, '\n'); if (e == NULL) { ostream_write_str (stream, s); s = NULL; } else { ostream_write_mem (stream, s, e - s); s = e + 1; } ostream_write_str (stream, "\n"); } while (s != NULL); } end_css_class (stream, class_translator_comment); } }
static void html_ostream::write_mem (html_ostream_t stream, const void *data, size_t len) { if (len > 0) { #define BUFFERSIZE 2048 char inbuffer[BUFFERSIZE]; size_t inbufcount; inbufcount = stream->buflen; if (inbufcount > 0) memcpy (inbuffer, stream->buf, inbufcount); for (;;) { /* At this point, inbuffer[0..inbufcount-1] is filled. */ { /* Combine the previous rest with a chunk of new input. */ size_t n = (len <= BUFFERSIZE - inbufcount ? len : BUFFERSIZE - inbufcount); if (n > 0) { memcpy (inbuffer + inbufcount, data, n); data = (char *) data + n; inbufcount += n; len -= n; } } { /* Handle complete UTF-8 characters. */ const char *inptr = inbuffer; size_t insize = inbufcount; while (insize > 0) { unsigned char c0; ucs4_t uc; int nbytes; c0 = ((const unsigned char *) inptr)[0]; if (insize < (c0 < 0xc0 ? 1 : c0 < 0xe0 ? 2 : c0 < 0xf0 ? 3 : c0 < 0xf8 ? 4 : c0 < 0xfc ? 5 : 6)) break; nbytes = u8_mbtouc (&uc, (const unsigned char *) inptr, insize); if (uc == '\n') { size_t prev_class_stack_size = stream->curr_class_stack_size; stream->curr_class_stack_size = 0; emit_pending_spans (stream, false); ostream_write_str (stream->destination, "<br/>"); stream->curr_class_stack_size = prev_class_stack_size; } else { emit_pending_spans (stream, true); switch (uc) { case '"': ostream_write_str (stream->destination, """); break; case '&': ostream_write_str (stream->destination, "&"); break; case '<': ostream_write_str (stream->destination, "<"); break; case '>': /* Needed to avoid "]]>" in the output. */ ostream_write_str (stream->destination, ">"); break; case ' ': /* Needed because HTML viewers merge adjacent spaces and drop spaces adjacent to <br> and similar. */ ostream_write_str (stream->destination, " "); break; default: if (uc >= 0x20 && uc < 0x7F) { /* Output ASCII characters as such. */ char bytes[1]; bytes[0] = uc; ostream_write_mem (stream->destination, bytes, 1); } else { /* Output non-ASCII characters in #&nnn; notation. */ char bytes[32]; sprintf (bytes, "&#%d;", (int) uc); ostream_write_str (stream->destination, bytes); } break; } } inptr += nbytes; insize -= nbytes; } /* Put back the unconverted part. */ if (insize > BUFSIZE) abort (); if (len == 0) { if (insize > 0) memcpy (stream->buf, inptr, insize); stream->buflen = insize; break; } if (insize > 0) memmove (inbuffer, inptr, insize); inbufcount = insize; } } #undef BUFFERSIZE } }
/* Print a color test page. */ void print_color_test () { /* Code copied from test-term-ostream.c. */ static struct { const char *name; term_color_t c; int r; int g; int b; } colors[] = { { "black", -2, 0, 0, 0 }, { "blue", -2, 0, 0, 255 }, { "green", -2, 0, 255, 0 }, { "cyan", -2, 0, 255, 255 }, { "red", -2, 255, 0, 0 }, { "magenta", -2, 255, 0, 255 }, { "yellow", -2, 255, 255, 0 }, { "white", -2, 255, 255, 255 }, { "default", COLOR_DEFAULT } }; term_ostream_t stream; int i, row, col; stream = term_ostream_create (1, "stdout"); for (i = 0; i < 8; i++) colors[i].c = term_ostream_rgb_to_color (stream, colors[i].r, colors[i].g, colors[i].b); ostream_write_str (stream, "Colors (foreground/background):\n"); ostream_write_str (stream, " "); for (col = 0; col <= 8; col++) { const char *name = colors[col].name; ostream_write_str (stream, "|"); ostream_write_str (stream, name); ostream_write_mem (stream, " ", 7 - strlen (name)); } ostream_write_str (stream, "\n"); for (row = 0; row <= 8; row++) { const char *name = colors[row].name; ostream_write_str (stream, name); ostream_write_mem (stream, " ", 7 - strlen (name)); for (col = 0; col <= 8; col++) { term_color_t row_color = colors[row].c; term_color_t col_color = colors[col].c; ostream_write_str (stream, "|"); term_ostream_set_color (stream, row_color); term_ostream_set_bgcolor (stream, col_color); if (!(term_ostream_get_color (stream) == row_color && term_ostream_get_bgcolor (stream) == col_color)) abort (); ostream_write_str (stream, " Words "); term_ostream_set_color (stream, COLOR_DEFAULT); term_ostream_set_bgcolor (stream, COLOR_DEFAULT); if (!(term_ostream_get_color (stream) == COLOR_DEFAULT && term_ostream_get_bgcolor (stream) == COLOR_DEFAULT)) abort (); } ostream_write_str (stream, "\n"); } ostream_write_str (stream, "\n"); ostream_write_str (stream, "Colors (hue/saturation):\n"); /* Hue from 0 to 1. */ for (row = 0; row <= 17; row++) { ostream_write_str (stream, row == 0 ? "red: " : " "); for (col = 0; col <= 64; col++) { int r = 255; int b = (int) (255.0f / 64.0f * col + 0.5f); int g = b + (int) (row / 17.0f * (r - b) + 0.5f); term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); term_ostream_set_bgcolor (stream, c); ostream_write_str (stream, " "); term_ostream_set_bgcolor (stream, COLOR_DEFAULT); } ostream_write_str (stream, "\n"); } /* Hue from 1 to 2. */ for (row = 17; row >= 0; row--) { ostream_write_str (stream, row == 17 ? "yellow: " : " "); for (col = 0; col <= 64; col++) { int g = 255; int b = (int) (255.0f / 64.0f * col + 0.5f); int r = b + (int) (row / 17.0f * (g - b) + 0.5f); term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); term_ostream_set_bgcolor (stream, c); ostream_write_str (stream, " "); term_ostream_set_bgcolor (stream, COLOR_DEFAULT); } ostream_write_str (stream, "\n"); } /* Hue from 2 to 3. */ for (row = 0; row <= 17; row++) { ostream_write_str (stream, row == 0 ? "green: " : " "); for (col = 0; col <= 64; col++) { int g = 255; int r = (int) (255.0f / 64.0f * col + 0.5f); int b = r + (int) (row / 17.0f * (g - r) + 0.5f); term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); term_ostream_set_bgcolor (stream, c); ostream_write_str (stream, " "); term_ostream_set_bgcolor (stream, COLOR_DEFAULT); } ostream_write_str (stream, "\n"); } /* Hue from 3 to 4. */ for (row = 17; row >= 0; row--) { ostream_write_str (stream, row == 17 ? "cyan: " : " "); for (col = 0; col <= 64; col++) { int b = 255; int r = (int) (255.0f / 64.0f * col + 0.5f); int g = r + (int) (row / 17.0f * (b - r) + 0.5f); term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); term_ostream_set_bgcolor (stream, c); ostream_write_str (stream, " "); term_ostream_set_bgcolor (stream, COLOR_DEFAULT); } ostream_write_str (stream, "\n"); } /* Hue from 4 to 5. */ for (row = 0; row <= 17; row++) { ostream_write_str (stream, row == 0 ? "blue: " : " "); for (col = 0; col <= 64; col++) { int b = 255; int g = (int) (255.0f / 64.0f * col + 0.5f); int r = g + (int) (row / 17.0f * (b - g) + 0.5f); term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); term_ostream_set_bgcolor (stream, c); ostream_write_str (stream, " "); term_ostream_set_bgcolor (stream, COLOR_DEFAULT); } ostream_write_str (stream, "\n"); } /* Hue from 5 to 6. */ for (row = 17; row >= 0; row--) { ostream_write_str (stream, row == 17 ? "magenta: " : row == 0 ? "red: " : " "); for (col = 0; col <= 64; col++) { int r = 255; int g = (int) (255.0f / 64.0f * col + 0.5f); int b = g + (int) (row / 17.0f * (r - g) + 0.5f); term_color_t c = term_ostream_rgb_to_color (stream, r, g, b); term_ostream_set_bgcolor (stream, c); ostream_write_str (stream, " "); term_ostream_set_bgcolor (stream, COLOR_DEFAULT); } ostream_write_str (stream, "\n"); } ostream_write_str (stream, "\n"); ostream_write_str (stream, "Weights:\n"); term_ostream_set_weight (stream, WEIGHT_NORMAL); if (term_ostream_get_weight (stream) != WEIGHT_NORMAL) abort (); ostream_write_str (stream, "normal, "); term_ostream_set_weight (stream, WEIGHT_BOLD); if (term_ostream_get_weight (stream) != WEIGHT_BOLD) abort (); ostream_write_str (stream, "bold, "); term_ostream_set_weight (stream, WEIGHT_DEFAULT); if (term_ostream_get_weight (stream) != WEIGHT_DEFAULT) abort (); ostream_write_str (stream, "default \n"); ostream_write_str (stream, "\n"); ostream_write_str (stream, "Postures:\n"); term_ostream_set_posture (stream, POSTURE_NORMAL); if (term_ostream_get_posture (stream) != POSTURE_NORMAL) abort (); ostream_write_str (stream, "normal, "); term_ostream_set_posture (stream, POSTURE_ITALIC); if (term_ostream_get_posture (stream) != POSTURE_ITALIC) abort (); ostream_write_str (stream, "italic, "); term_ostream_set_posture (stream, POSTURE_DEFAULT); if (term_ostream_get_posture (stream) != POSTURE_DEFAULT) abort (); ostream_write_str (stream, "default \n"); ostream_write_str (stream, "\n"); ostream_write_str (stream, "Text decorations:\n"); term_ostream_set_underline (stream, UNDERLINE_OFF); if (term_ostream_get_underline (stream) != UNDERLINE_OFF) abort (); ostream_write_str (stream, "normal, "); term_ostream_set_underline (stream, UNDERLINE_ON); if (term_ostream_get_underline (stream) != UNDERLINE_ON) abort (); ostream_write_str (stream, "underlined, "); term_ostream_set_underline (stream, UNDERLINE_DEFAULT); if (term_ostream_get_underline (stream) != UNDERLINE_DEFAULT) abort (); ostream_write_str (stream, "default \n"); ostream_write_str (stream, "\n"); ostream_write_str (stream, "Colors (foreground) mixed with attributes:\n"); for (row = 0; row <= 8; row++) { const char *name = colors[row].name; ostream_write_str (stream, name); ostream_write_mem (stream, " ", 7 - strlen (name)); term_ostream_set_color (stream, colors[row].c); ostream_write_str (stream, "|normal|"); term_ostream_set_weight (stream, WEIGHT_BOLD); ostream_write_str (stream, "bold"); term_ostream_set_weight (stream, WEIGHT_NORMAL); ostream_write_str (stream, "|normal|"); term_ostream_set_posture (stream, POSTURE_ITALIC); ostream_write_str (stream, "italic"); term_ostream_set_posture (stream, POSTURE_NORMAL); ostream_write_str (stream, "|normal|"); term_ostream_set_underline (stream, UNDERLINE_ON); ostream_write_str (stream, "underlined"); term_ostream_set_underline (stream, UNDERLINE_OFF); ostream_write_str (stream, "|normal|"); term_ostream_set_color (stream, COLOR_DEFAULT); ostream_write_str (stream, "\n "); term_ostream_set_color (stream, colors[row].c); ostream_write_str (stream, "|normal|"); term_ostream_set_weight (stream, WEIGHT_BOLD); term_ostream_set_posture (stream, POSTURE_ITALIC); ostream_write_str (stream, "bold+italic"); term_ostream_set_weight (stream, WEIGHT_NORMAL); term_ostream_set_posture (stream, POSTURE_NORMAL); ostream_write_str (stream, "|normal|"); term_ostream_set_weight (stream, WEIGHT_BOLD); term_ostream_set_underline (stream, UNDERLINE_ON); ostream_write_str (stream, "bold+underl"); term_ostream_set_weight (stream, WEIGHT_NORMAL); term_ostream_set_underline (stream, UNDERLINE_OFF); ostream_write_str (stream, "|normal|"); term_ostream_set_posture (stream, POSTURE_ITALIC); term_ostream_set_underline (stream, UNDERLINE_ON); ostream_write_str (stream, "italic+underl"); term_ostream_set_posture (stream, POSTURE_NORMAL); term_ostream_set_underline (stream, UNDERLINE_OFF); ostream_write_str (stream, "|normal|"); term_ostream_set_color (stream, COLOR_DEFAULT); ostream_write_str (stream, "\n"); } ostream_write_str (stream, "\n"); ostream_write_str (stream, "Colors (background) mixed with attributes:\n"); for (row = 0; row <= 8; row++) { const char *name = colors[row].name; ostream_write_str (stream, name); ostream_write_mem (stream, " ", 7 - strlen (name)); term_ostream_set_bgcolor (stream, colors[row].c); ostream_write_str (stream, "|normal|"); term_ostream_set_weight (stream, WEIGHT_BOLD); ostream_write_str (stream, "bold"); term_ostream_set_weight (stream, WEIGHT_NORMAL); ostream_write_str (stream, "|normal|"); term_ostream_set_posture (stream, POSTURE_ITALIC); ostream_write_str (stream, "italic"); term_ostream_set_posture (stream, POSTURE_NORMAL); ostream_write_str (stream, "|normal|"); term_ostream_set_underline (stream, UNDERLINE_ON); ostream_write_str (stream, "underlined"); term_ostream_set_underline (stream, UNDERLINE_OFF); ostream_write_str (stream, "|normal|"); term_ostream_set_bgcolor (stream, COLOR_DEFAULT); ostream_write_str (stream, "\n "); term_ostream_set_bgcolor (stream, colors[row].c); ostream_write_str (stream, "|normal|"); term_ostream_set_weight (stream, WEIGHT_BOLD); term_ostream_set_posture (stream, POSTURE_ITALIC); ostream_write_str (stream, "bold+italic"); term_ostream_set_weight (stream, WEIGHT_NORMAL); term_ostream_set_posture (stream, POSTURE_NORMAL); ostream_write_str (stream, "|normal|"); term_ostream_set_weight (stream, WEIGHT_BOLD); term_ostream_set_underline (stream, UNDERLINE_ON); ostream_write_str (stream, "bold+underl"); term_ostream_set_weight (stream, WEIGHT_NORMAL); term_ostream_set_underline (stream, UNDERLINE_OFF); ostream_write_str (stream, "|normal|"); term_ostream_set_posture (stream, POSTURE_ITALIC); term_ostream_set_underline (stream, UNDERLINE_ON); ostream_write_str (stream, "italic+underl"); term_ostream_set_posture (stream, POSTURE_NORMAL); term_ostream_set_underline (stream, UNDERLINE_OFF); ostream_write_str (stream, "|normal|"); term_ostream_set_bgcolor (stream, COLOR_DEFAULT); ostream_write_str (stream, "\n"); } ostream_write_str (stream, "\n"); ostream_free (stream); }
void message_print_comment_flags (const message_ty *mp, ostream_t stream, bool debug) { if ((mp->is_fuzzy && mp->msgstr[0] != '\0') || has_significant_format_p (mp->is_format) || has_range_p (mp->range) || mp->do_wrap == no) { bool first_flag = true; size_t i; begin_css_class (stream, class_flag_comment); ostream_write_str (stream, "#,"); /* We don't print the fuzzy flag if the msgstr is empty. This might be introduced by the user but we want to normalize the output. */ if (mp->is_fuzzy && mp->msgstr[0] != '\0') { ostream_write_str (stream, " "); begin_css_class (stream, class_flag); begin_css_class (stream, class_fuzzy_flag); ostream_write_str (stream, "fuzzy"); end_css_class (stream, class_fuzzy_flag); end_css_class (stream, class_flag); first_flag = false; } for (i = 0; i < NFORMATS; i++) if (significant_format_p (mp->is_format[i])) { if (!first_flag) ostream_write_str (stream, ","); ostream_write_str (stream, " "); begin_css_class (stream, class_flag); ostream_write_str (stream, make_format_description_string (mp->is_format[i], format_language[i], debug)); end_css_class (stream, class_flag); first_flag = false; } if (has_range_p (mp->range)) { char *string; if (!first_flag) ostream_write_str (stream, ","); ostream_write_str (stream, " "); begin_css_class (stream, class_flag); string = make_range_description_string (mp->range); ostream_write_str (stream, string); free (string); end_css_class (stream, class_flag); first_flag = false; } if (mp->do_wrap == no) { if (!first_flag) ostream_write_str (stream, ","); ostream_write_str (stream, " "); begin_css_class (stream, class_flag); ostream_write_str (stream, make_c_width_description_string (mp->do_wrap)); end_css_class (stream, class_flag); first_flag = false; } ostream_write_str (stream, "\n"); end_css_class (stream, class_flag_comment); } }
void message_print_comment_filepos (const message_ty *mp, ostream_t stream, bool uniforum, size_t page_width) { if (mp->filepos_count != 0) { begin_css_class (stream, class_reference_comment); if (uniforum) { size_t j; for (j = 0; j < mp->filepos_count; ++j) { lex_pos_ty *pp = &mp->filepos[j]; const char *cp = pp->file_name; char *str; while (cp[0] == '.' && cp[1] == '/') cp += 2; ostream_write_str (stream, "# "); begin_css_class (stream, class_reference); /* There are two Sun formats to choose from: SunOS and Solaris. Use the Solaris form here. */ str = xasprintf ("File: %s, line: %ld", cp, (long) pp->line_number); ostream_write_str (stream, str); end_css_class (stream, class_reference); ostream_write_str (stream, "\n"); free (str); } } else { size_t column; size_t j; ostream_write_str (stream, "#:"); column = 2; for (j = 0; j < mp->filepos_count; ++j) { lex_pos_ty *pp; char buffer[21]; const char *cp; size_t len; pp = &mp->filepos[j]; cp = pp->file_name; while (cp[0] == '.' && cp[1] == '/') cp += 2; /* Some xgettext input formats, like RST, lack line numbers. */ if (pp->line_number == (size_t)(-1)) buffer[0] = '\0'; else sprintf (buffer, ":%ld", (long) pp->line_number); len = strlen (cp) + strlen (buffer) + 1; if (column > 2 && column + len >= page_width) { ostream_write_str (stream, "\n#:"); column = 2; } ostream_write_str (stream, " "); begin_css_class (stream, class_reference); ostream_write_str (stream, cp); ostream_write_str (stream, buffer); end_css_class (stream, class_reference); column += len; } ostream_write_str (stream, "\n"); } end_css_class (stream, class_reference_comment); } }