/* ** Functions associated with LYCharSets.c and the Lynx version of HTML.c - FM ** ========================================================================== */ #include #include #define Lynx_HTML_Handler #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef VMS #include #endif /* VMS */ #ifdef DOSPATH #include #endif #include #include extern BOOL HTPassEightBitRaw; extern BOOL HTPassEightBitNum; extern BOOL HTPassHighCtrlRaw; extern BOOL HTPassHighCtrlNum; extern HTkcode kanji_code; extern HTCJKlang HTCJK; /* * Used for nested lists. - FM */ PUBLIC int OL_CONTINUE = -29999; /* flag for whether CONTINUE is set */ PUBLIC int OL_VOID = -29998; /* flag for whether a count is set */ /* ** This function converts any ampersands in allocated ** strings to "&". If isTITLE is TRUE, it also ** converts any angle-brackets to "<" or ">". - FM */ PUBLIC void LYEntify ARGS2( char **, str, BOOLEAN, isTITLE) { char *p = *str; char *q = NULL, *cp = NULL; int amps = 0, lts = 0, gts = 0; if (p == NULL || *p == '\0') return; /* * Count the ampersands. - FM */ while ((*p != '\0') && (q = strchr(p, '&')) != NULL) { amps++; p = (q + 1); } /* * Count the left-angle-brackets, if needed. - FM */ if (isTITLE == TRUE) { p = *str; while ((*p != '\0') && (q = strchr(p, '<')) != NULL) { lts++; p = (q + 1); } } /* * Count the right-angle-brackets, if needed. - FM */ if (isTITLE == TRUE) { p = *str; while ((*p != '\0') && (q = strchr(p, '>')) != NULL) { gts++; p = (q + 1); } } /* * Check whether we need to convert anything. - FM */ if (amps == 0 && lts == 0 && gts == 0) return; /* * 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); } /* ** 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; if (!str || *str == '\0') return; 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'; } } /* ** 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, "