static XP_S16 findStartsWithChars( DictIter* iter, const XP_UCHAR* chars, XP_U16 charsOffset, array_edge* edge, XP_U16 nTilesUsed ) { XP_S16 result = -1; XP_U16 charsLen = XP_STRLEN( &chars[charsOffset] ); if ( NULL == edge ) { if ( 0 == charsLen ) { iter->nEdges = nTilesUsed; result = charsOffset; } } else if ( 0 == charsLen ) { iter->nEdges = nTilesUsed; result = charsOffset; } else { const DictionaryCtxt* dict = iter->dict; XP_U16 nodeSize = dict->nodeSize; for ( ; ; ) { /* for all the tiles */ Tile tile = EDGETILE( dict, edge ); const XP_UCHAR* facep = NULL; for ( ; ; ) { /* for each string that tile can be */ facep = dict_getNextTileString( dict, tile, facep ); if ( NULL == facep ) { break; } XP_U16 faceLen = XP_STRLEN( facep ); if ( faceLen > charsLen ) { faceLen = charsLen; } if ( 0 == XP_STRNCMP( facep, &chars[charsOffset], faceLen ) ) { XP_S16 newOffset = findStartsWithChars( iter, chars, charsOffset + faceLen, dict_follow( dict, edge ), nTilesUsed + 1 ); if ( result < newOffset ) { iter->edges[nTilesUsed] = edge; result = newOffset; } break; } } if ( IS_LAST_EDGE( dict, edge ) ) { break; } edge += nodeSize; } } return result; }
static XP_Bool vr_CompareDirs( char *dir1, char *dir2 ) { int len1,len2; XP_ASSERT( dir1 && dir2 ); if (!dir1 || !dir2) return FALSE; len1 = XP_STRLEN( dir1 ); len2 = XP_STRLEN( dir2 ); if ( dir1[len1-1] == VR_FILE_SEP ) len1--; if ( dir2[len2-1] == VR_FILE_SEP ) len2--; if ( len1 != len2 ) return FALSE; #if defined(XP_UNIX) && !defined(XP_MACOSX) return ( XP_STRNCMP(dir1, dir2, len1) == 0 ); #else return ( XP_STRNCASECMP(dir1, dir2, len1) == 0 ); #endif }
MWContext * XP_FindNamedContextInList(MWContext * context, char *name) { int i; if ((name == NULL) || (xp_GlobalContextList == NULL)) return context; /* * Check for special magic window target names */ if (name[0] == '_') { if (XP_STRNCMP(name, "_self", 5) == 0) { return context; } else if (XP_STRNCMP(name, "_parent", 7) == 0) { if ((context)&&(context->grid_parent)) { return context->grid_parent; } else { return context; } } else if (XP_STRNCMP(name, "_top", 4) == 0) { MWContext *top; top = context; while ((top)&&(top->grid_parent)) { top = top->grid_parent; } return top; } else if (XP_STRNCMP(name, "_blank", 6) == 0) { return NULL; } /* else, search for the name, below */ } { MWContext* cx = context; MWContext* found; if (context) { /* If our current context has the right name, go there */ if (cx->name && (XP_STRCMP(cx->name, name) == 0)) return cx; found = xp_FindNamedContextInChildren(cx, name, NULL); if (found) return found; while (cx->is_grid_cell) { MWContext* parent = cx->grid_parent; found = xp_FindNamedContextInChildren(parent, name, cx); if (found) return found; cx = parent; } } /* otherwise, just get any other context */ for (i=1; i<= XP_ListCount(xp_GlobalContextList); i++) { MWContext* compContext = (MWContext *)XP_ListGetObjectNum(xp_GlobalContextList, i); /* Only search other top-level contexts that aren't the one we just came from: */ if (!compContext->is_grid_cell && compContext != cx) { found = xp_FindNamedContextInChildren(compContext, name, NULL); if (found) return found; } } } return NULL; }
PRIVATE int net_ColorHTMLWrite (NET_StreamClass *stream, CONST char *s, int32 l) { int32 i; int32 last_output_point; char *new_markup=0; char *tmp_markup=0; char tiny_buf[4]; CONST char *cp; int status; DataObject *obj=stream->data_object; last_output_point = 0; for(i = 0, cp = s; i < l; i++, cp++) { switch(obj->state) { case IN_CONTENT: /* do nothing until you find a '<' "<!--" or '&' */ if(*cp == '<') { /* XXX we can miss a comment spanning a block boundary */ if(i+4 <= l && !XP_STRNCMP(cp, "<!--", 4)) { StrAllocCopy(new_markup, BEGIN_COMMENT_MARKUP); StrAllocCat(new_markup, "<"); obj->state = IN_COMMENT; } else { new_markup = net_BeginColorHTMLTag(obj); } } else if(*cp == '&') { StrAllocCopy(new_markup, BEGIN_AMPERSAND_THINGY_MARKUP); StrAllocCat(new_markup, "&"); obj->state = IN_AMPERSAND_THINGY; } break; case IN_SCRIPT: /* do nothing until you find '</SCRIPT>' */ if(*cp == '<') { /* XXX we can miss a </SCRIPT> spanning a block boundary */ if(i+8 <= l && !XP_STRNCASECMP(cp, "</SCRIPT", 8)) { new_markup = net_BeginColorHTMLTag(obj); } } break; case ABOUT_TO_BEGIN_TAG: /* we have seen the first '<' * once we see a non-whitespace character * we will be in the tag identifier */ if(*cp == '>') { StrAllocCopy(new_markup, END_TAG_NAME_MARKUP); tmp_markup = net_EndColorHTMLTag(obj); StrAllocCat(new_markup, tmp_markup); FREE_AND_CLEAR(tmp_markup); } else if(!XP_IS_SPACE(*cp)) { obj->state = IN_BEGIN_TAG; obj->tag_index = 0; obj->tag[obj->tag_index++] = *cp; if(*cp == '<') StrAllocCopy(new_markup, "<"); } break; case IN_BEGIN_TAG: /* go to the IN_TAG state when we see * the first whitespace */ if(XP_IS_SPACE(*cp)) { StrAllocCopy(new_markup, END_TAG_NAME_MARKUP); XP_SPRINTF(tiny_buf, "%c", *cp); StrAllocCat(new_markup, tiny_buf); obj->state = IN_TAG; obj->tag[obj->tag_index] = '\0'; obj->tag_type = pa_tokenize_tag(obj->tag); } else if(*cp == '>') { StrAllocCopy(new_markup, END_TAG_NAME_MARKUP); tmp_markup = net_EndColorHTMLTag(obj); StrAllocCat(new_markup, tmp_markup); FREE_AND_CLEAR(tmp_markup); } else if(*cp == '<') { /* protect ourselves from markup */ if(!obj->in_broken_html) { obj->in_broken_html = TRUE; StrAllocCopy(new_markup, BEGIN_BROKEN_ATTRIBUTE_MARKUP); StrAllocCat(new_markup, "<"); } else { StrAllocCopy(new_markup, "<"); } } else { if (obj->tag_index < MAXTAGLEN) obj->tag[obj->tag_index++] = *cp; } break; case IN_TAG: /* do nothing until you find a opening '=' or end '>' */ if(*cp == '=') { StrAllocCopy(new_markup, "="); StrAllocCat(new_markup, BEGIN_ATTRIBUTE_VALUE_MARKUP); obj->state = BEGIN_ATTRIBUTE_VALUE; } else if(*cp == '>') { new_markup = net_EndColorHTMLTag(obj); } else if(*cp == '<') { /* protect ourselves from markup */ StrAllocCopy(new_markup, "<"); } break; case BEGIN_ATTRIBUTE_VALUE: /* when we reach the first non-whitespace * we will enter the UNQUOTED or the QUOTED * ATTRIBUTE state */ if(!XP_IS_SPACE(*cp)) { if(*cp == '"') { obj->state = IN_QUOTED_ATTRIBUTE_VALUE; /* no need to jump to the quoted attr handler * since this char can't be a dangerous char */ } else { obj->state = IN_UNQUOTED_ATTRIBUTE_VALUE; /* need to jump to the unquoted attr handler * since this char can be a dangerous character */ goto unquoted_attribute_jump_point; } } else if(*cp == '>') { StrAllocCopy(new_markup, END_ATTRIBUTE_VALUE_MARKUP); tmp_markup = net_EndColorHTMLTag(obj); StrAllocCat(new_markup, tmp_markup); FREE_AND_CLEAR(tmp_markup); } else if(*cp == '<') { /* protect ourselves from markup */ StrAllocCopy(new_markup, "<"); } break; case IN_UNQUOTED_ATTRIBUTE_VALUE: unquoted_attribute_jump_point: /* do nothing until you find a whitespace */ if(XP_IS_SPACE(*cp)) { StrAllocCopy(new_markup, END_ATTRIBUTE_VALUE_MARKUP); XP_SPRINTF(tiny_buf, "%c", *cp); StrAllocCat(new_markup, tiny_buf); obj->state = IN_TAG; } else if(*cp == '>') { StrAllocCopy(new_markup, END_ATTRIBUTE_VALUE_MARKUP); tmp_markup = net_EndColorHTMLTag(obj); StrAllocCat(new_markup, tmp_markup); FREE_AND_CLEAR(tmp_markup); } else if(*cp == '<') { /* protect ourselves from markup */ StrAllocCopy(new_markup, "<"); } else if(*cp == '&') { /* protect ourselves from markup */ StrAllocCopy(new_markup, "&"); } break; case IN_QUOTED_ATTRIBUTE_VALUE: /* do nothing until you find a closing '"' */ if(*cp == '\"') { if(obj->in_broken_html) { StrAllocCopy(new_markup, END_BROKEN_ATTRIBUTE_MARKUP); obj->in_broken_html = FALSE; } StrAllocCat(new_markup, "\""); StrAllocCat(new_markup, END_ATTRIBUTE_VALUE_MARKUP); obj->state = IN_TAG; } else if(*cp == '<') { /* protect ourselves from markup */ StrAllocCopy(new_markup, "<"); } else if(*cp == '&') { /* protect ourselves from markup */ StrAllocCopy(new_markup, "&"); } else if(*cp == '>') { /* probably a broken attribute value */ if(!obj->in_broken_html) { obj->in_broken_html = TRUE; StrAllocCopy(new_markup, BEGIN_BROKEN_ATTRIBUTE_MARKUP); StrAllocCat(new_markup, ">"); } } break; case IN_COMMENT: /* do nothing until you find a closing '-->' */ if(!XP_STRNCMP(cp, "-->", 3)) { StrAllocCopy(new_markup, ">"); cp += 2; i += 2; StrAllocCat(new_markup, END_COMMENT_MARKUP); obj->state = IN_CONTENT; } else if(*cp == '<') { /* protect ourselves from markup */ StrAllocCopy(new_markup, "<"); } break; case IN_AMPERSAND_THINGY: /* do nothing until you find a ';' or space */ if(*cp == ';' || XP_IS_SPACE(*cp)) { XP_SPRINTF(tiny_buf, "%c", *cp); StrAllocCopy(new_markup, tiny_buf); StrAllocCat(new_markup, END_AMPERSAND_THINGY_MARKUP); obj->state = IN_CONTENT; } else if(*cp == '<') { /* protect ourselves from markup */ StrAllocCopy(new_markup, "<"); } break; default: XP_ASSERT(0); break; } if(new_markup) { /* push all the way up to but not including *cp */ status = (*obj->next_stream->put_block) (obj->next_stream, &s[last_output_point], i-last_output_point); last_output_point = i+1; if(status < 0) { FREE(new_markup); return(status); } /* add new markup */ status = (*obj->next_stream->put_block) (obj->next_stream, new_markup, XP_STRLEN(new_markup)); if(status < 0) { FREE(new_markup); return(status); } FREE_AND_CLEAR(new_markup); } } if(last_output_point < l) return((*obj->next_stream->put_block)(obj->next_stream, &s[last_output_point], (l-last_output_point))); else return(0); }