From c2e46cb20dfa9cb12c535641090601d839fdf313 Mon Sep 17 00:00:00 2001 From: Steffen Nurpmeso Date: Wed, 15 Nov 2017 23:44:01 +0100 Subject: [PATCH] Implement false groff:[09040dbf] used to fix #47161 --- include/html-strings.h | 5 +- src/pre-html/pre-html.cpp | 114 ++++++++++++++++++++++++---------------------- 2 files changed, 62 insertions(+), 57 deletions(-) diff --git a/include/html-strings.h b/include/html-strings.h index dc8dd051..ad6d3950 100644 --- a/include/html-strings.h +++ b/include/html-strings.h @@ -23,8 +23,9 @@ #ifndef _HTML_STRINGS_H #define _HTML_STRINGS_H -#define HTML_IMAGE_INLINE_BEGIN "\\O[HTML-IMAGE-INLINE-BEGIN]" -#define HTML_IMAGE_INLINE_END "\\O[HTML-IMAGE-INLINE-END]" +#define HTML_INLINE_LEADER_CHAR '\\' +#define HTML_IMAGE_INLINE_BEGIN "\\O[HTML-IMAGE-INLINE-BEGIN]" +#define HTML_IMAGE_INLINE_END "\\O[HTML-IMAGE-INLINE-END]" #endif // _HTML_STRINGS_H // s-it2-mode diff --git a/src/pre-html/pre-html.cpp b/src/pre-html/pre-html.cpp index 3284c598..dd04d6a8 100644 --- a/src/pre-html/pre-html.cpp +++ b/src/pre-html/pre-html.cpp @@ -26,12 +26,7 @@ #include -#ifdef _POSIX_VERSION -# include -# define PID_T pid_t -#else -# define PID_T int -#endif +#include #include #include @@ -143,8 +138,6 @@ # define DEBUG_FILE(name) DEBUG_NAME(DEBUG_FILE_DIR) "/" name #endif -#define INLINE_LEADER_CHAR '\\' - // Don't use colour names here! Otherwise there is a dependency on // a file called `rgb.txt' which maps names to colours. #define TRANSPARENT "-background rgb:f/f/f -transparent rgb:f/f/f" @@ -372,7 +365,7 @@ class char_block public: enum { SIZE = 256 }; char buffer[SIZE]; - int used; + int used; // TODO size_t char_block *next; char_block(); @@ -403,10 +396,16 @@ public: int do_html(int argc, char *argv[]); int do_image(int argc, char *argv[]); void emit_troff_output(int device_format_selector); - void write_upto_newline(char_block **t, int *i, int is_html); - int can_see(char_block **t, int *i, const char *string); - int skip_spaces(char_block **t, int *i); - void skip_until_newline(char_block **t, int *i); + + + // Write the contents of the buffer until a newline is seen. + // Check for HTML_IMAGE_INLINE_BEGIN and HTML_IMAGE_INLINE_END; process them + // if they are present. + static void write_upto_newline(char_block **t, int *i, int is_html); + + static int can_see(char_block **t, int *i, const char *string); + static int skip_spaces(char_block **t, int *i); + static void skip_until_newline(char_block **t, int *i); }; /* @@ -622,55 +621,58 @@ static void write_start_image(IMAGE_ALIGNMENT pos, int is_html) writeString("\\O[1]\\O[3]"); } -/* - * write_upto_newline - Write the contents of the buffer until a newline - * is seen. Check for HTML_IMAGE_INLINE_BEGIN and - * HTML_IMAGE_INLINE_END; process them if they are - * present. - */ +rf_static void +char_buffer::write_upto_newline(char_block **t, int *i, int is_html){ + enum {a_NONE, a_NL, a_LEADER} ev; + char *b; + int j, u; -void char_buffer::write_upto_newline(char_block **t, int *i, int is_html) -{ - int j = *i; + if(*t == NULL) + goto jleave; - if (*t) { - while (j < (*t)->used - && (*t)->buffer[j] != '\n' - && (*t)->buffer[j] != INLINE_LEADER_CHAR) - j++; - if (j < (*t)->used - && (*t)->buffer[j] == '\n') - j++; - writeNbytes((*t)->buffer + (*i), j - (*i)); - if ((*t)->buffer[j] == INLINE_LEADER_CHAR) { - if (can_see(t, &j, HTML_IMAGE_INLINE_BEGIN)) - write_start_image(INLINE, is_html); - else if (can_see(t, &j, HTML_IMAGE_INLINE_END)) - write_end_image(is_html); - else { - if (j < (*t)->used) { - *i = j; - j++; - writeNbytes((*t)->buffer + (*i), j - (*i)); - } - } + j = *i; + u = (*t)->used; + b = (*t)->buffer; + ev = a_NONE; + + for(; j < u; ++j){ + if(b[j] == '\n'){ + ev = (++j < u && b[j] == HTML_INLINE_LEADER_CHAR) ? a_LEADER : a_NL; + break; + }else if(b[j] == HTML_INLINE_LEADER_CHAR){ + ev = a_LEADER; + break; } - if (j == (*t)->used) { - *i = 0; - *t = (*t)->next; - if (*t && (*t)->buffer[j - 1] != '\n') - write_upto_newline(t, i, is_html); + } + + writeNbytes(&b[*i], j - *i); + *i = j; + + if(ev == a_LEADER){ + if(can_see(t, &j, HTML_IMAGE_INLINE_BEGIN)) + write_start_image(INLINE, is_html); + else if(can_see(t, &j, HTML_IMAGE_INLINE_END)) + write_end_image(is_html); + else if(j < u){ + ++j; + writeNbytes(&b[*i], 1); } - else - // newline was seen - *i = j; } + + // Rotate block if all the buffer was consumed + if(j == u){ + *i = 0; + if((*t = (*t)->next) != NULL) + write_upto_newline(t, i, is_html); + } +jleave:; } /* * can_see - Return true if we can see string in t->buffer[i] onwards. */ +rf_static int char_buffer::can_see(char_block **t, int *i, const char *str) { int j = 0; @@ -701,6 +703,7 @@ int char_buffer::can_see(char_block **t, int *i, const char *str) * Consume spaces also. */ +rf_static int char_buffer::skip_spaces(char_block **t, int *i) { char_block *s = *t; @@ -726,6 +729,7 @@ int char_buffer::skip_spaces(char_block **t, int *i) * The newline is not consumed. */ +rf_static void char_buffer::skip_until_newline(char_block **t, int *i) { int j = *i; @@ -1277,7 +1281,7 @@ void print_args(int, char **) int char_buffer::run_output_filter(int filter, int argc, char **argv) { int pipedes[2]; - PID_T child_pid; + pid_t child_pid; int status; print_args(argc, argv); @@ -1395,13 +1399,13 @@ int char_buffer::run_output_filter(int filter, int argc, char **argv) set_redirection(STDIN_FILENO, pipedes[0]); // if we redirected `stderr', for use by the image post-processor, - // then we also need to reinstate its original assignment. + // then we also need to reinstantiate its original assignment. if (filter == IMAGE_OUTPUT_FILTER) set_redirection(STDERR_FILENO, saved_stderr); // Now we redirect the `stdout' stream to the inlet end of the pipe, - // and push out the appropiately formatted data to the filter. + // and push out the appropriately formatted data to the filter. set_redirection(STDOUT_FILENO, pipedes[1]); emit_troff_output(DEVICE_FORMAT(filter)); @@ -1749,7 +1753,7 @@ int main(int argc, char **argv) #endif /* CAPTURE_MODE */ device = "html"; if (!font::load_desc()) - fatal("cannot find dev-html/DESC exiting"); + fatal("cannot find dev-html/DESC, exiting"); image_gen = font::image_generator; if (image_gen == NULL || (strcmp(image_gen, "") == 0)) fatal("dev-html/DESC must set the image_generator field, exiting"); -- 2.11.4.GIT