diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/LYCharUtils.c | 58 | ||||
-rw-r--r-- | src/LYCharUtils.h | 5 | ||||
-rw-r--r-- | src/LYCurses.c | 28 | ||||
-rw-r--r-- | src/LYOptions.c | 51 | ||||
-rw-r--r-- | src/LYShowInfo.c | 30 | ||||
-rw-r--r-- | src/LYStrings.c | 12 |
6 files changed, 143 insertions, 41 deletions
diff --git a/src/LYCharUtils.c b/src/LYCharUtils.c index c201d69d..9ecb3dff 100644 --- a/src/LYCharUtils.c +++ b/src/LYCharUtils.c @@ -1,5 +1,5 @@ /* - * $LynxId: LYCharUtils.c,v 1.94 2009/01/01 22:32:39 tom Exp $ + * $LynxId: LYCharUtils.c,v 1.96 2009/01/19 23:56:35 tom Exp $ * * Functions associated with LYCharSets.c and the Lynx version of HTML.c - FM * ========================================================================== @@ -229,6 +229,62 @@ void LYEntify(char **str, } /* + * Callers to LYEntifyTitle/LYEntifyValue do not look at the 'target' param. + * Optimize things a little by avoiding the memory allocation if not needed, + * as is usually the case. + */ +static BOOL MustEntify(const char *source) +{ + BOOL result; + +#ifdef CJK_EX + if (IS_CJK_TTY && strchr(source, '\033') != 0) { + result = TRUE; + } else +#endif + { + size_t length = strlen(source); + size_t reject = strcspn(source, "<&>"); + + result = (length != reject); + } + + return result; +} + +/* + * Wrappers for LYEntify() which do not assume that the source was allocated, + * e.g., output from gettext(). + */ +const char *LYEntifyTitle(char **target, const char *source) +{ + const char *result = 0; + + if (MustEntify(source)) { + StrAllocCopy(*target, source); + LYEntify(target, TRUE); + result = *target; + } else { + result = source; + } + return result; +} + +const char *LYEntifyValue(char **target, const char *source) +{ + const char *result = 0; + + if (MustEntify(source)) { + StrAllocCopy(*target, source); + LYEntify(target, FALSE); + result = *target; + } else { + result = source; + } + return result; +} + +/* * This function trims characters <= that of a space (32), * including HT_NON_BREAK_SPACE (1) and HT_EN_SPACE (2), * but not ESC, from the heads of strings. - FM diff --git a/src/LYCharUtils.h b/src/LYCharUtils.h index 83e63c06..6209778e 100644 --- a/src/LYCharUtils.h +++ b/src/LYCharUtils.h @@ -1,3 +1,6 @@ +/* + * $LynxId: LYCharUtils.h,v 1.24 2009/01/19 23:53:27 tom Exp $ + */ #ifndef LYCHARUTILS_H #define LYCHARUTILS_H @@ -37,6 +40,8 @@ extern "C" { BOOLEAN plain_space); extern void LYEntify(char **str, BOOLEAN isTITLE); + extern const char *LYEntifyTitle(char **target, const char *source); + extern const char *LYEntifyValue(char **target, const char *source); extern void LYTrimHead(char *str); extern void LYTrimTail(char *str); extern char *LYFindEndOfComment(char *str); diff --git a/src/LYCurses.c b/src/LYCurses.c index 77d29f23..8edde2fe 100644 --- a/src/LYCurses.c +++ b/src/LYCurses.c @@ -1,4 +1,4 @@ -/* $LynxId: LYCurses.c,v 1.137 2009/01/03 00:36:42 tom Exp $ */ +/* $LynxId: LYCurses.c,v 1.138 2009/01/20 01:03:02 tom Exp $ */ #include <HTUtils.h> #include <HTAlert.h> @@ -1714,16 +1714,25 @@ void LYsubAttr(int a) #ifndef USE_SLANG void LYpaddstr(WINDOW * the_window, int width, const char *the_string) { - int y, x; - int actual = (int) strlen(the_string); + int y, x1, x2; + int actual = (int) LYstrCells(the_string); + int length = (int) strlen(the_string); - getyx(the_window, y, x); - if (width + x > LYcolLimit) - width = LYcolLimit - x; - if (actual > width) + getyx(the_window, y, x1); + if (width + x1 > LYcolLimit) + width = LYcolLimit - x1; + if (actual > width) { actual = width; - LYwaddnstr(the_window, the_string, (size_t) actual); - width -= actual; +#ifdef WIDEC_CURSES + /* FIXME: a binary search might be faster */ + while (LYstrExtent(the_string, length, length) > actual) { + --length; + } +#endif + } + LYwaddnstr(the_window, the_string, (size_t) length); + getyx(the_window, y, x2); + width -= (x2 - x1); while (width-- > 0) waddstr(the_window, " "); } @@ -2872,6 +2881,7 @@ static void make_blink_boldbg(void) long LYgetattrs(WINDOW * win) { long result; + #if ( defined(HAVE_GETATTRS) && ( !defined(NCURSES_VERSION_MAJOR) || NCURSES_VERSION_MAJOR < 5 ) ) result = getattrs(win); diff --git a/src/LYOptions.c b/src/LYOptions.c index ba45925a..5f1e386c 100644 --- a/src/LYOptions.c +++ b/src/LYOptions.c @@ -1,4 +1,4 @@ -/* $LynxId: LYOptions.c,v 1.126 2009/01/01 22:02:02 tom Exp $ */ +/* $LynxId: LYOptions.c,v 1.128 2009/01/19 23:32:01 tom Exp $ */ #include <HTUtils.h> #include <HTFTP.h> #include <HTTP.h> /* 'reloading' flag */ @@ -23,6 +23,7 @@ #include <LYReadCFG.h> #include <LYPrettySrc.h> #include <HTFile.h> +#include <LYCharUtils.h> #include <LYLeaks.h> @@ -907,7 +908,7 @@ void LYoptions(void) int i, curval; const char **assume_list; assume_list = typecallocn(const char *, (unsigned) - (LYNumCharsets + 1)); + (LYNumCharsets + 1)); if (!assume_list) { outofmem(__FILE__, "options"); @@ -2426,7 +2427,7 @@ static const char *preferred_doc_lang_string = RC_PREFERRED_LANGUAGE; static const char *user_agent_string = RC_USERAGENT; #define PutHeader(fp, Name) \ - fprintf(fp, "\n%s<em>%s</em>\n", MARGIN_STR, Name); + fprintf(fp, "\n%s<em>%s</em>\n", MARGIN_STR, LYEntifyTitle(&buffer, Name)); #define PutTextInput(fp, Name, Value, Size, disable) \ fprintf(fp,\ @@ -3309,8 +3310,9 @@ static void PutLabel(FILE *fp, const char *name, int have = (int) strlen(name); int want = LABEL_LEN; int need = LYstrExtent(name, have, want); + char *buffer = NULL; - fprintf(fp, "%s%s", MARGIN_STR, name); + fprintf(fp, "%s%s", MARGIN_STR, LYEntifyTitle(&buffer, name)); if (will_save_rc(value) && !no_option_save) { while (need++ < want) @@ -3327,6 +3329,7 @@ static void PutLabel(FILE *fp, const char *name, } } fprintf(fp, ": "); + FREE(buffer); } /* @@ -3406,8 +3409,10 @@ void LYMenuVisitedLinks(FILE *fp0, int disable_all) */ static int gen_options(char **newfile) { - int i; static char tempfile[LY_MAXPATH] = "\0"; + + int i; + char *buffer = NULL; BOOLEAN disable_all = FALSE; FILE *fp0; size_t cset_len = 0; @@ -3463,22 +3468,29 @@ static int gen_options(char **newfile) /* Submit/Reset/Help */ fprintf(fp0, "<p align=center>\n"); if (!disable_all) { - fprintf(fp0, "<input type=\"submit\" value=\"%s\"> - \n", ACCEPT_CHANGES); - fprintf(fp0, "<input type=\"reset\" value=\"%s\"> - \n", RESET_CHANGES); - fprintf(fp0, "%s - \n", CANCEL_CHANGES); + fprintf(fp0, + "<input type=\"submit\" value=\"%s\"> - \n", + LYEntifyValue(&buffer, ACCEPT_CHANGES)); + fprintf(fp0, + "<input type=\"reset\" value=\"%s\"> - \n", + LYEntifyValue(&buffer, RESET_CHANGES)); + fprintf(fp0, + "%s - \n", + LYEntifyTitle(&buffer, CANCEL_CHANGES)); } fprintf(fp0, "<a href=\"%s%s\">%s</a>\n", - helpfilepath, OPTIONS_HELP, TO_HELP); + helpfilepath, LYEntifyTitle(&buffer, OPTIONS_HELP), TO_HELP); /* Save options */ if (!no_option_save) { if (!disable_all) { - fprintf(fp0, "<p align=center>%s: ", SAVE_OPTIONS); + fprintf(fp0, "<p align=center>%s: ", LYEntifyTitle(&buffer, SAVE_OPTIONS)); fprintf(fp0, "<input type=\"checkbox\" name=\"%s\">\n", save_options_string); } fprintf(fp0, "<br>%s\n", - gettext("(options marked with (!) will not be saved)")); + LYEntifyTitle(&buffer, + gettext("(options marked with (!) will not be saved)"))); } /* @@ -3895,7 +3907,8 @@ static int gen_options(char **newfile) if (LYMultiBookmarks) { PutLabel(fp0, gettext("Review/edit Bookmarks files"), mbm_string); fprintf(fp0, "<a href=\"%s\">%s</a>\n", - LYNXOPTIONS_PAGE(MBM_LINK), gettext("Goto multi-bookmark menu")); + LYNXOPTIONS_PAGE(MBM_LINK), + LYEntifyTitle(&buffer, gettext("Goto multi-bookmark menu"))); } else { PutLabel(fp0, gettext("Bookmarks file"), single_bookmark_string); PutTextInput(fp0, single_bookmark_string, @@ -3921,7 +3934,7 @@ static int gen_options(char **newfile) if (!no_lynxcfg_info) { fprintf(fp0, "\n %s<a href=\"%s\">lynx.cfg</a>.\n", - gettext("View the file "), + LYEntifyTitle(&buffer, gettext("View the file ")), STR_LYNXCFG); } @@ -3930,9 +3943,13 @@ static int gen_options(char **newfile) /* Submit/Reset */ if (!disable_all) { fprintf(fp0, "<p align=center>\n"); - fprintf(fp0, "<input type=\"submit\" value=\"%s\"> - \n", ACCEPT_CHANGES); - fprintf(fp0, "<input type=\"reset\" value=\"%s\"> - \n", RESET_CHANGES); - fprintf(fp0, "%s\n", CANCEL_CHANGES); + fprintf(fp0, + "<input type=\"submit\" value=\"%s\"> - \n", + LYEntifyValue(&buffer, ACCEPT_CHANGES)); + fprintf(fp0, + "<input type=\"reset\" value=\"%s\"> - \n", + LYEntifyValue(&buffer, RESET_CHANGES)); + fprintf(fp0, "%s\n", LYEntifyTitle(&buffer, CANCEL_CHANGES)); } /* @@ -3941,6 +3958,8 @@ static int gen_options(char **newfile) fprintf(fp0, "</form>\n"); EndInternalPage(fp0); + FREE(buffer); + LYCloseTempFP(fp0); return (NORMAL); } diff --git a/src/LYShowInfo.c b/src/LYShowInfo.c index 01740684..6e6f916d 100644 --- a/src/LYShowInfo.c +++ b/src/LYShowInfo.c @@ -1,4 +1,4 @@ -/* $LynxId: LYShowInfo.c,v 1.68 2009/01/03 00:37:51 tom Exp $ */ +/* $LynxId: LYShowInfo.c,v 1.69 2009/01/19 23:42:23 tom Exp $ */ #include <HTUtils.h> #include <HTFile.h> #include <HTParse.h> @@ -25,7 +25,7 @@ #define ADVANCED_INFO 1 /* to get more info in advanced mode */ -#define BEGIN_DL(text) fprintf(fp0, "<h2>%s</h2>\n<dl compact>", text) +#define BEGIN_DL(text) fprintf(fp0, "<h2>%s</h2>\n<dl compact>", LYEntifyTitle(&buffer, text)) #define END_DL() fprintf(fp0, "\n</dl>\n") #define ADD_SS(label,value) dt_String(fp0, label, value) @@ -98,10 +98,12 @@ static void dt_Number(FILE *fp0, const char *units) { char *value = NULL; + char *buffer = NULL; - HTSprintf(&value, "%ld %s", number, units); + HTSprintf(&value, "%ld %s", number, LYEntifyTitle(&buffer, units)); ADD_SS(label, value); FREE(value); + FREE(buffer); } /* @@ -113,11 +115,13 @@ int LYShowInfo(DocInfo *doc, char *owner_address) { static char tempfile[LY_MAXPATH] = "\0"; + int url_type; FILE *fp0; char *Title = NULL; const char *cp; char *temp = 0; + char *buffer = 0; #ifdef ADVANCED_INFO BOOLEAN LYInfoAdvanced = (BOOL) (user_mode == ADVANCED_MODE); @@ -307,7 +311,7 @@ int LYShowInfo(DocInfo *doc, LYformTitle(&Title, doc->title); HTSprintf(&temp, "%s%s", - Title, + LYEntifyTitle(&buffer, Title), ((doc->isHEAD && !strstr(Title, " (HEAD)") && !strstr(Title, " - HEAD")) ? " (HEAD)" : "")); @@ -330,7 +334,7 @@ int LYShowInfo(DocInfo *doc, if (p_in && non_empty(p_in->MIMEname) && HTAnchor_getUCLYhndl(HTMainAnchor, UCT_STAGE_MIME) >= 0) { HTSprintf(&temp, "%s %s", - p_in->MIMEname, + LYEntifyTitle(&buffer, p_in->MIMEname), gettext("(assumed)")); ADD_SS(gettext("Charset:"), p_in->MIMEname); FREE(temp); @@ -371,7 +375,7 @@ int LYShowInfo(DocInfo *doc, if (doc->post_data) { fprintf(fp0, "<dt><em>%s</em> <xmp>%.*s</xmp>\n", - gettext("Post Data:"), + LYEntifyTitle(&buffer, gettext("Post Data:")), BStrLen(doc->post_data), BStrData(doc->post_data)); ADD_SS(gettext("Post Content Type:"), doc->post_content_type); @@ -438,7 +442,8 @@ int LYShowInfo(DocInfo *doc, } if (!(links[doc->link].l_form->submit_method && links[doc->link].l_form->submit_action)) { - fprintf(fp0, "<dt> %s\n", gettext("(Form field)")); + fprintf(fp0, "<dt> %s\n", + LYEntifyTitle(&buffer, gettext("(Form field)"))); } } else { ADD_SS("URL:", @@ -447,13 +452,17 @@ int LYShowInfo(DocInfo *doc, END_DL(); } else { - fprintf(fp0, "<h2>%s</h2>", gettext("No Links on the current page")); + fprintf(fp0, "<h2>%s</h2>", + LYEntifyTitle(&buffer, + gettext("No Links on the current page"))); } #ifdef EXP_HTTP_HEADERS if ((cp = HText_getHttpHeaders()) != 0) { - fprintf(fp0, "<h2>%s</h2>", gettext("Server Headers:")); - fprintf(fp0, "<pre>%s</pre>", cp); + fprintf(fp0, "<h2>%s</h2>", + LYEntifyTitle(&buffer, gettext("Server Headers:"))); + fprintf(fp0, "<pre>%s</pre>", + LYEntifyTitle(&buffer, cp)); } #endif @@ -466,6 +475,7 @@ int LYShowInfo(DocInfo *doc, LYCloseTemp(tempfile); FREE(Title); + FREE(buffer); return (0); } diff --git a/src/LYStrings.c b/src/LYStrings.c index 303ce922..8c207994 100644 --- a/src/LYStrings.c +++ b/src/LYStrings.c @@ -1,4 +1,4 @@ -/* $LynxId: LYStrings.c,v 1.160 2009/01/01 21:50:59 tom Exp $ */ +/* $LynxId: LYStrings.c,v 1.161 2009/01/20 01:05:11 tom Exp $ */ #include <HTUtils.h> #include <HTCJK.h> #include <UCAux.h> @@ -479,7 +479,7 @@ static int set_clicked_link(int x, if (is_text) len = links[i].l_form->size; else - len = (int) strlen(text); + len = (int) LYstrCells(text); cur_err = XYdist(x, y, links[i].lx, links[i].ly, len); /* Check the second line */ while (cur_err > 0 @@ -488,7 +488,7 @@ static int set_clicked_link(int x, int cur_err_2 = XYdist(x, y, LYGetHilitePos(i, count), links[i].ly + count, - (int) strlen(text)); + (int) LYstrCells(text)); cur_err = HTMIN(cur_err, cur_err_2); } @@ -3997,8 +3997,10 @@ static unsigned options_width(const char **list) int count = 0; while (list[count] != 0) { - if (strlen(list[count]) > width) { - width = strlen(list[count]); + unsigned ncells = LYstrCells(list[count]); + + if (ncells > width) { + width = ncells; } count++; } |