From 1a2ac66b7db3c229b508b9b1fb68bcc5b4a6b907 Mon Sep 17 00:00:00 2001 From: "Thomas E. Dickey" Date: Wed, 27 Aug 1997 10:10:45 -0400 Subject: snapshot of project "lynx", label v2-7-1ac_0-55 --- src/HTFWriter.c | 9 +- src/HTInit.c | 4 +- src/LYCharUtils.c | 2992 +++++++++++++++++++++++----------------------- src/LYCookie.c | 6 +- src/LYHistory.c | 4 +- src/LYNews.c | 4 - src/LYUtils.c | 11 +- src/chrtrans/makefile.in | 6 + src/makefile.in | 17 +- 9 files changed, 1528 insertions(+), 1525 deletions(-) (limited to 'src') diff --git a/src/HTFWriter.c b/src/HTFWriter.c index 5f41becb..ccd85a00 100644 --- a/src/HTFWriter.c +++ b/src/HTFWriter.c @@ -608,7 +608,7 @@ SaveAndExecute_tempname: if (me->remove_command == NULL) outofmem(__FILE__, "HTSaveAndExecute"); - sprintf(me->remove_command, REMOVE_COMMAND, fnam, "", "", "", "", "", ""); + sprintf(me->remove_command, REMOVE_COMMAND, fnam); StrAllocCopy(anchor->FileCache, fnam); return me; @@ -808,8 +808,7 @@ SaveToFile_tempname: if (ret_obj->remove_command == NULL) outofmem(__FILE__, "HTSaveToFile"); - sprintf(ret_obj->remove_command, - REMOVE_COMMAND, fnam, "", "", "", "", "", ""); + sprintf(ret_obj->remove_command, REMOVE_COMMAND, fnam); #ifdef VMS if (IsBinary && UseFixedRecords) { @@ -881,7 +880,7 @@ PUBLIC HTStream* HTCompressed ARGS3( HTStream* me; HTFormat format; char *type = NULL; - HTPresentation *Pres; + HTPresentation *Pres = NULL; int n, i; BOOL can_present = FALSE; char fnam[256]; @@ -1099,7 +1098,7 @@ Compressed_tempname: strlen(fnam)) * sizeof(char)); if (me->remove_command == NULL) outofmem(__FILE__, "HTCompressed"); - sprintf(me->remove_command, REMOVE_COMMAND, fnam, "", "", "", "", "", ""); + sprintf(me->remove_command, REMOVE_COMMAND, fnam); /* * Save the filename and return the structure. - FM diff --git a/src/HTInit.c b/src/HTInit.c index 5c27d8bf..db3a9225 100644 --- a/src/HTInit.c +++ b/src/HTInit.c @@ -112,7 +112,7 @@ PUBLIC void HTFormatInit NOARGS HTSetConversion("application/html", "text/plain", HTMLToPlain, 0.5, 0.0, 0.0, 0); HTSetConversion("application/html", "www/present", - HTMLPresent, 1.0, 0.0, 0.0, 0); + HTMLPresent, 2.0, 0.0, 0.0, 0); HTSetConversion("application/html", "www/source", HTPlainPresent, 1.0, 0.0, 0.0, 0); HTSetConversion("application/x-wais-source", "www/source", @@ -147,7 +147,7 @@ PUBLIC void HTFormatInit NOARGS HTSetConversion("text/x-sgml", "www/source", HTPlainPresent, 1.0, 0.0, 0.0, 0); HTSetConversion("text/x-sgml", - "www/present", HTMLPresent, 1.0, 0.0, 0.0, 0); + "www/present", HTMLPresent, 2.0, 0.0, 0.0, 0); HTSetConversion("text/sgml", "www/source", HTPlainPresent, 1.0, 0.0, 0.0, 0); HTSetConversion("text/sgml", "www/present", HTMLPresent, 1.0, 0.0, 0.0, 0); HTSetConversion("text/plain","www/present", HTPlainPresent, 1.0, 0.0, 0.0, 0); diff --git a/src/LYCharUtils.c b/src/LYCharUtils.c index 8ee363e8..14f2646c 100644 --- a/src/LYCharUtils.c +++ b/src/LYCharUtils.c @@ -66,1651 +66,1652 @@ PUBLIC int OL_VOID = -29998; /* flag for whether a count is set */ /* -** This function converts HTML named entities within a string -** to their translations in the active LYCharSets.c array. -** It also converts numeric entities to their HTML entity names -** and then similarly translates those. The string is converted -** in place, on the assumption that the conversion strings will -** not be longer than the entity strings, such that the overall -** string will never grow. This assumption is true for the -** current LYCharSets arrays. Make sure it stays true! If -** plain_space is TRUE, nbsp (160) will be treated as an ASCII -** space (32). If hidden is TRUE, entities will be translated -** but escape sequences will be passed unaltered. - FM +** This function converts any ampersands in allocated +** strings to "&". If isTITLE is TRUE, it also +** converts any angle-brackets to "<" or ">". - FM */ -PUBLIC char * LYUnEscapeEntities ARGS3( - char *, str, - BOOLEAN, plain_space, - BOOLEAN, hidden) +PUBLIC void LYEntify ARGS2( + char **, str, + BOOLEAN, isTITLE) { - char * p = str; - char * q = str; - char * cp; - char cpe; - int len, value; - int high, low, diff = 0, i; - enum _state - { S_text, S_esc, S_dollar, S_paren, - S_nonascii_text, S_dollar_paren } state = S_text; + char *p = *str; + char *q = NULL, *cp = NULL; + int amps = 0, lts = 0, gts = 0; + + if (p == NULL || *p == '\0') + return; /* - ** Make sure we have a non-empty string. - FM - */ - if (!str || *str == '\0') - return str; + * Count the ampersands. - FM + */ + while ((*p != '\0') && (q = strchr(p, '&')) != NULL) { + amps++; + p = (q + 1); + } /* - ** Loop through string, making conversions as needed. - FM - */ - while (*p) { - if (HTCJK != NOCJK && !hidden) { - /* - ** Handle CJK escape sequences, based on patch - ** from Takuya ASADA (asada@three-a.co.jp). - FM - */ - switch(state) { - case S_text: - if (*p == '\033') { - state = S_esc; - *q++ = *p++; - continue; - } - break; + * Count the left-angle-brackets, if needed. - FM + */ + if (isTITLE == TRUE) { + p = *str; + while ((*p != '\0') && (q = strchr(p, '<')) != NULL) { + lts++; + p = (q + 1); + } + } - case S_esc: - if (*p == '$') { - state = S_dollar; - *q++ = *p++; - continue; - } else if (*p == '(') { - state = S_paren; - *q++ = *p++; - continue; - } else { - state = S_text; - } + /* + * Count the right-angle-brackets, if needed. - FM + */ + if (isTITLE == TRUE) { + p = *str; + while ((*p != '\0') && (q = strchr(p, '>')) != NULL) { + gts++; + p = (q + 1); + } + } - case S_dollar: - if (*p == '@' || *p == 'B' || *p == 'A') { - state = S_nonascii_text; - *q++ = *p++; - continue; - } else if (*p == '(') { - state = S_dollar_paren; - *q++ = *p++; - continue; - } else { - state = S_text; - } - break; + /* + * Check whether we need to convert anything. - FM + */ + if (amps == 0 && lts == 0 && gts == 0) + return; - case S_dollar_paren: - if (*p == 'C') { - state = S_nonascii_text; - *q++ = *p++; - continue; - } else { - state = S_text; - } - break; + /* + * Allocate space and convert. - FM + */ + q = (char *)calloc(1, + (strlen(*str) + (4 * amps) + (3 * lts) + (3 * gts) + 1)); + if ((cp = q) == NULL) + outofmem(__FILE__, "LYEntify"); + for (p = *str; *p; p++) { + if (*p == '&') { + *q++ = '&'; + *q++ = 'a'; + *q++ = 'm'; + *q++ = 'p'; + *q++ = ';'; + } else if (isTITLE && *p == '<') { + *q++ = '&'; + *q++ = 'l'; + *q++ = 't'; + *q++ = ';'; + } else if (isTITLE && *p == '>') { + *q++ = '&'; + *q++ = 'g'; + *q++ = 't'; + *q++ = ';'; + } else { + *q++ = *p; + } + } + StrAllocCopy(*str, cp); + FREE(cp); +} - case S_paren: - if (*p == 'B' || *p == 'J' || *p == 'T') { - state = S_text; - *q++ = *p++; - continue; - } else if (*p == 'I') { - state = S_nonascii_text; - *q++ = *p++; - continue; - } else { - state = S_text; - } - break; +/* +** This function trims characters <= that of a space (32), +** including HT_NON_BREAK_SPACE (1) and HT_EM_SPACE (2), +** but not ESC, from the heads of strings. - FM +*/ +PUBLIC void LYTrimHead ARGS1( + char *, str) +{ + int i = 0, j; - case S_nonascii_text: - if (*p == '\033') - state = S_esc; - *q++ = *p++; - continue; - break; + if (!str || *str == '\0') + return; - default: - p++; - continue; - } - } else if (*p == '\033' && - !hidden) { - /* - ** CJK handling not on, and not a hidden INPUT, - ** so block escape. - FM - */ - p++; - continue; + while (str[i] != '\0' && WHITE(str[i]) && (unsigned char)str[i] != 27) + i++; + if (i > 0) { + for (j = 0; str[i] != '\0'; i++) { + str[j++] = str[i]; } + str[j] = '\0'; + } +} - /* - ** Check for a numeric or named entity. - FM - */ - if (*p == '&') { - BOOL isHex = FALSE; - BOOL isDecimal = FALSE; - p++; - len = strlen(p); - /* - ** Check for a numeric entity. - FM - */ - if (*p == '#' && len > 2 && - (unsigned char)*(p+1) == 'x' && - (unsigned char)*(p+2) < 127 && - isxdigit((unsigned char)*(p+2))) { - isHex = TRUE; - } else if (*p == '#' && len > 2 && - (unsigned char)*(p+1) < 127 && - isdigit((unsigned char)*(p+1))) { - isDecimal = TRUE; - } - if (isHex || isDecimal) { - if (isHex) { - p += 2; - cp = p; - } else { - cp = ++p; - } - while (*p && (unsigned char)*p < 127 && - (isHex ? isxdigit((unsigned char)*p) : - isdigit((unsigned char)*p))) { - p++; - } - /* - ** Save the terminator and isolate the digit(s). - FM - */ - cpe = *p; - if (*p) - *p++ = '\0'; - /* - ** Show the numeric entity if the value: - ** (1) Is greater than 255 and unhandled Unicode. - ** (2) Is less than 32, and not valid or we don't - ** have HTCJK set. - ** (3) Is 127 and we don't have HTPassHighCtrlRaw - ** or HTCJK set. - ** (4) Is 128 - 159 and we don't have HTPassHighCtrlNum set. - */ - if (((isHex ? sscanf(cp, "%x", &value) : - sscanf(cp, "%d", &value)) != 1) || - (value > 255 && - value != 8194 && value != 8195 && value != 8201 && - value != 8211 && value != 8212 && value != 8482) || - (value < 32 && - value != 9 && value != 10 && value != 13 && - HTCJK == NOCJK) || - (value == 127 && - !(HTPassHighCtrlRaw || HTCJK != NOCJK)) || - (value > 127 && value < 160 && - !HTPassHighCtrlNum)) { +/* +** This function trims characters <= that of a space (32), +** including HT_NON_BREAK_SPACE (1), HT_EM_SPACE (2), and +** ESC from the tails of strings. - FM +*/ +PUBLIC void LYTrimTail ARGS1( + char *, str) +{ + int i; + + if (!str || *str == '\0') + return; + + i = (strlen(str) - 1); + while (i >= 0) { + if (WHITE(str[i])) + str[i] = '\0'; + else + break; + i--; + } +} + +/* +** This function should receive a pointer to the start +** of a comment. It returns a pointer to the end ('>') +** character of comment, or it's best guess if the comment +** is invalid. - FM +*/ +PUBLIC char *LYFindEndOfComment ARGS1( + char *, str) +{ + char *cp, *cp1; + enum comment_state { start1, start2, end1, end2 } state; + + if (str == NULL) + /* + * We got NULL, so return NULL. - FM + */ + return NULL; + + if (strncmp(str, "