diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/GridText.c | 129 | ||||
-rw-r--r-- | src/LYCharUtils.c | 9 | ||||
-rw-r--r-- | src/UCAux.c | 6 | ||||
-rw-r--r-- | src/UCdomap.c | 4 |
4 files changed, 99 insertions, 49 deletions
diff --git a/src/GridText.c b/src/GridText.c index 4b52f0c8..f5d59619 100644 --- a/src/GridText.c +++ b/src/GridText.c @@ -1,5 +1,5 @@ /* - * $LynxId: GridText.c,v 1.278 2014/07/24 22:08:24 tom Exp $ + * $LynxId: GridText.c,v 1.285 2014/12/11 10:07:02 tom Exp $ * * Character grid hypertext object * =============================== @@ -7916,7 +7916,7 @@ typedef struct _AnchorIndex { int size; /* character-width of field */ int length; /* byte-count for field's data */ int offset; /* byte-offset in line's data */ - int filler; /* character to use for filler */ + char filler; /* character to use for filler */ const char *value; /* field's value */ } AnchorIndex; @@ -8065,19 +8065,34 @@ static void freeAnchorIndex(AnchorIndex ** inx, unsigned inx_size) } /* + * Return the column (counting from zero) at which a field should be overlaid + * on the form. + */ +static int FieldFirst(AnchorIndex * p, int wrap) +{ + return (wrap ? 0 : (p)->offset); +} + +/* + * Return the column (counting from zero) just past the field in a form. + */ +static int FieldLast(AnchorIndex * p, int wrap) +{ + return ((p)->size - wrap) + FieldFirst(p, wrap); +} + +/* * Print the contents of the file in HTMainText to * the file descriptor fp. * If is_email is TRUE add ">" before each "From " line. * If is_reply is TRUE add ">" to the beginning of each * line to specify the file is a reply to message. */ -#define FieldFirst(p) (this_wrap ? 0 : (p)->offset) -#define FieldLast(p) (FieldFirst(p) + (p)->size - this_wrap) void print_wwwfile_to_fd(FILE *fp, int is_email, int is_reply) { - int line_num, byte_num, byte_count; + int line_num, byte_num, byte_count, byte_next, byte_offset; int first = TRUE; HTLine *line; AnchorIndex **inx; /* sorted index of input-fields */ @@ -8145,16 +8160,23 @@ void print_wwwfile_to_fd(FILE *fp, /* * Add data. */ + byte_offset = line->offset; byte_count = TrimmedLength(line->data); - for (byte_num = 0; byte_num < byte_count; byte_num++) { - int byte_offset = byte_num + line->offset; - int ch = UCH(line->data[byte_num]); - int c2; - - while (cur != 0 && FieldLast(cur) < byte_offset) { + byte_next = 1; + for (byte_num = 0; byte_num < byte_count; byte_num += byte_next) { + int cell_chr, temp_chr; + size_t cell_len, temp_len; + const char *cell_ptr, *temp_ptr, *try_utf8; + + cell_ptr = &line->data[byte_num]; + cell_len = 1; + cell_chr = UCH(*cell_ptr); + byte_next = 1; + + while (cur != 0 && FieldLast(cur, this_wrap) < byte_offset) { CTRACE2(TRACE_GRIDTEXT, (tfp, "skip field since last %d < %d\n", - FieldLast(cur), byte_offset)); + FieldLast(cur, this_wrap), byte_offset)); cur = cur->next; in_field = -1; } @@ -8162,15 +8184,15 @@ void print_wwwfile_to_fd(FILE *fp, CTRACE2(TRACE_GRIDTEXT, (tfp, "compare %d to [%d..%d]\n", byte_offset, - FieldFirst(cur), - FieldLast(cur) - 1)); + FieldFirst(cur, this_wrap), + FieldLast(cur, this_wrap) - 1)); } if (cur != 0 - && FieldFirst(cur) <= byte_offset - && FieldLast(cur) > byte_offset) { + && FieldFirst(cur, this_wrap) <= byte_offset + && FieldLast(cur, this_wrap) > byte_offset) { int off2 = ((in_field > 0) ? in_field - : (byte_offset - FieldFirst(cur))); + : (byte_offset - FieldFirst(cur, this_wrap))); /* * On the first time (for each line that the field appears on), @@ -8178,7 +8200,7 @@ void print_wwwfile_to_fd(FILE *fp, * the field which will be used to adjust the beginning of the * continuation line. */ - if (byte_offset == FieldFirst(cur)) { + if (byte_offset == FieldFirst(cur, this_wrap)) { next_wrap = 0; if (cur->size - this_wrap + byte_num > byte_count) { CTRACE((tfp, "size %d, offset %d, length %d\n", @@ -8193,20 +8215,37 @@ void print_wwwfile_to_fd(FILE *fp, } } - c2 = ((off2 < cur->length) - ? cur->value[off2] - : cur->filler); + if (off2 >= 0 && off2 < cur->length) { + temp_ptr = &(cur->value[off2]); + temp_len = 1; + try_utf8 = temp_ptr; + temp_chr = (int) UCGetUniFromUtf8String(&try_utf8); + if (temp_chr > 127) { + temp_len = (size_t) (try_utf8 - temp_ptr) + 1; + } else { + temp_chr = UCH(*temp_ptr); + temp_len = 1; + } + } else { + temp_ptr = &(cur->filler); + temp_len = 1; + temp_chr = UCH(*temp_ptr); + } - if (ch != c2) { + if (cell_chr != temp_chr) { CTRACE2(TRACE_GRIDTEXT, - (tfp, "line %d %d/%d [%d..%d] map %d %c->%c\n", + (tfp, "line %d %d/%d [%d..%d] map %d %04X->%04X\n", line_num, off2, cur->length, - FieldFirst(cur), FieldLast(cur) - 1, - byte_offset, ch, c2)); - ch = c2; + FieldFirst(cur, this_wrap), + FieldLast(cur, this_wrap) - 1, + byte_offset, cell_chr, temp_chr)); + cell_chr = temp_chr; + cell_ptr = temp_ptr; + cell_len = temp_len; } - ++off2; + off2 += (int) temp_len; + byte_offset += (int) temp_len; if ((off2 >= cur->size) && (off2 >= cur->length || F_TEXTLIKE(cur->type))) { in_field = -1; @@ -8215,26 +8254,37 @@ void print_wwwfile_to_fd(FILE *fp, } else { in_field = off2; } + } else { + byte_offset++; } - if (!IsSpecialAttrChar(ch)) { + if (!IsSpecialAttrChar(cell_chr)) { #ifndef NO_DUMP_WITH_BACKSPACES + size_t n; + if (in_b) { - fputc(ch, fp); - fputc('\b', fp); - fputc(ch, fp); + IGNORE_RC(fwrite(cell_ptr, sizeof(char), cell_len, fp)); + + for (n = 0; n < cell_len; ++n) { + fputc('\b', fp); + } + IGNORE_RC(fwrite(cell_ptr, sizeof(char), cell_len, fp)); } else if (in_u) { - fputc('_', fp); - fputc('\b', fp); - fputc(ch, fp); + for (n = 0; n < cell_len; ++n) { + fputc('_', fp); + } + for (n = 0; n < cell_len; ++n) { + fputc('\b', fp); + } + IGNORE_RC(fwrite(cell_ptr, sizeof(char), cell_len, fp)); } else #endif - fputc(ch, fp); - } else if (ch == LY_SOFT_HYPHEN && + IGNORE_RC(fwrite(cell_ptr, sizeof(char), cell_len, fp)); + } else if (cell_chr == LY_SOFT_HYPHEN && (byte_num + 1) >= byte_count) { write_hyphen(fp); } else if (dump_output_immediately && use_underscore) { - switch (ch) { + switch (cell_chr) { case LY_UNDERLINE_START_CHAR: case LY_UNDERLINE_END_CHAR: fputc('_', fp); @@ -8246,7 +8296,7 @@ void print_wwwfile_to_fd(FILE *fp, } #ifndef NO_DUMP_WITH_BACKSPACES else if (bs) { - switch (ch) { + switch (cell_chr) { case LY_UNDERLINE_START_CHAR: if (!in_b) in_u = TRUE; /*favor bold over underline */ @@ -11773,9 +11823,6 @@ int HText_SubmitForm(FormInfo * submit_item, DocInfo *doc, if (Boundary) { HTBprintf(&my_query, "\r\n--%s--\r\n", Boundary); } - /* - * The data may contain a null - so we use fwrite(). - */ if (TRACE) { CTRACE((tfp, "Query %d{", BStrLen(my_query))); trace_bstring(my_query); diff --git a/src/LYCharUtils.c b/src/LYCharUtils.c index 01d6a4b6..15909dc6 100644 --- a/src/LYCharUtils.c +++ b/src/LYCharUtils.c @@ -1,5 +1,5 @@ /* - * $LynxId: LYCharUtils.c,v 1.127 2013/11/28 11:17:59 tom Exp $ + * $LynxId: LYCharUtils.c,v 1.128 2014/12/10 10:30:58 tom Exp $ * * Functions associated with LYCharSets.c and the Lynx version of HTML.c - FM * ========================================================================== @@ -1081,7 +1081,7 @@ char **LYUCFullyTranslateString(char **str, BOOLEAN no_bytetrans; UCTransParams T; BOOL from_is_utf8 = FALSE; - char *puni; + char *puni = 0; enum _state { S_text, S_esc, @@ -1416,12 +1416,15 @@ char **LYUCFullyTranslateString(char **str, if (from_is_utf8) { if (((*p) & 0xc0) == 0xc0) { + const char *pq = p; + puni = p; - code = UCGetUniFromUtf8String(&puni); + code = UCGetUniFromUtf8String(&pq); if (code <= 0) { code = UCH(*p); } else { what = P_utf8; + puni += (pq - (const char *) p); } } } else if (use_lynx_specials && !Back && diff --git a/src/UCAux.c b/src/UCAux.c index bf41047e..0bdd064e 100644 --- a/src/UCAux.c +++ b/src/UCAux.c @@ -1,5 +1,5 @@ /* - * $LynxId: UCAux.c,v 1.49 2014/12/08 01:10:30 tom Exp $ + * $LynxId: UCAux.c,v 1.50 2014/12/10 09:48:57 tom Exp $ */ #include <HTUtils.h> @@ -560,10 +560,10 @@ BOOL UCConvertUniToUtf8(UCode_t code, char *buffer) * returns the UCS value * returns negative value on error (invalid UTF-8 sequence) */ -UCode_t UCGetUniFromUtf8String(char **ppuni) +UCode_t UCGetUniFromUtf8String(const char **ppuni) { UCode_t uc_out = 0; - char *p = *ppuni; + const char *p = *ppuni; int utf_count, i; if (!(**ppuni & 0x80)) diff --git a/src/UCdomap.c b/src/UCdomap.c index c073aa14..7a322909 100644 --- a/src/UCdomap.c +++ b/src/UCdomap.c @@ -1,5 +1,5 @@ /* - * $LynxId: UCdomap.c,v 1.98 2014/12/07 14:45:38 tom Exp $ + * $LynxId: UCdomap.c,v 1.99 2014/12/10 09:47:34 tom Exp $ * * UCdomap.c * ========= @@ -1199,7 +1199,7 @@ UCode_t UCTransToUni(int ch_in, } else if (charset_in == UTF8_handle) { if (is8bits(ch_iu)) { unsigned need; - char *ptr; + const char *ptr; buffer[inx++] = (char) ch_iu; buffer[inx] = '\0'; |