void str_dec(register STR *str) { register char *d; if (!str) return; if (str->str_nok) { str->str_nval -= 1.0; str->str_pok = 0; return; } if (!str->str_pok) { str->str_nval = -1.0; str->str_nok = 1; return; } for (d = str->str_ptr; *d && *d != '.'; d++) ; d--; if (!isDIGIT(*str->str_ptr) || !isDIGIT(*d) || (*d == '0' && d == str->str_ptr)) { str_numset(str,atof(str->str_ptr) - 1.0); /* punt */ return; } while (d >= str->str_ptr) { if (--*d >= '0') return; *(d--) = '9'; } }
void str_inc(register STR *str) { register char *d; if (!str) return; if (str->str_nok) { str->str_nval += 1.0; str->str_pok = 0; return; } if (!str->str_pok) { str->str_nval = 1.0; str->str_nok = 1; return; } for (d = str->str_ptr; *d && *d != '.'; d++) ; d--; if (!isDIGIT(*str->str_ptr) || !isDIGIT(*d) ) { str_numset(str,atof(str->str_ptr) + 1.0); /* punt */ return; } while (d >= str->str_ptr) { if (++*d <= '9') return; *(d--) = '0'; } /* oh,oh, the number grew */ GROWSTR(&(str->str_ptr), &(str->str_len), str->str_cur + 2); str->str_cur++; for (d = str->str_ptr + str->str_cur; d > str->str_ptr; d--) *d = d[-1]; *d = '1'; }
void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies, const char* firstExpectedFile, skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, fontFamilies[0]->fNames.count() == 5); REPORTER_ASSERT(reporter, !strcmp(fontFamilies[0]->fNames[0].c_str(), "sans-serif")); REPORTER_ASSERT(reporter, !strcmp(fontFamilies[0]->fFonts[0].fFileName.c_str(), firstExpectedFile)); REPORTER_ASSERT(reporter, !fontFamilies[0]->fIsFallbackFont); // Check that the languages are all sane. for (int i = 0; i < fontFamilies.count(); ++i) { const SkString& lang = fontFamilies[i]->fLanguage.getTag(); for (size_t j = 0; j < lang.size(); ++j) { int c = lang[j]; REPORTER_ASSERT(reporter, isALPHA(c) || isDIGIT(c) || '-' == c); } } // All file names in the test configuration files start with a capital letter. // This is not a general requirement, but it is true of all the test configuration data. // Verifying ensures the filenames have been read sanely and have not been 'sliced'. for (int i = 0; i < fontFamilies.count(); ++i) { FontFamily& family = *fontFamilies[i]; for (int j = 0; j < family.fFonts.count(); ++j) { FontFileInfo& file = family.fFonts[j]; REPORTER_ASSERT(reporter, !file.fFileName.isEmpty() && file.fFileName[0] >= 'A' && file.fFileName[0] <= 'Z'); } } }
sar_bool sar_checkNodeContainChar_c(sarNode_p checkNode, char checkChar, sar_nodeClass nodeClass) { if (nodeClass == SAR_CHAR) { if (checkNode->pathChar == checkChar) { return SAR_TRUE; } } else if (nodeClass == SAR_DIGIT) { if (isDIGIT(checkChar)) { return SAR_TRUE; } } else if (nodeClass == SAR_ALPHA_NUM) { if (isALNUM(checkChar)) { return SAR_TRUE; } } else if (nodeClass == SAR_ALPHA) { if (isALPHA(checkChar)) { return SAR_TRUE; } } else if (nodeClass == SAR_SPACE) { if (isSPACE(checkChar)) { return SAR_TRUE; } } else if (nodeClass == SAR_DOT) { return SAR_TRUE; } return SAR_FALSE; }
/* - regcurly - a little FSA that accepts {\d+,?\d*} Pulled from regcomp.c. */ PERL_STATIC_INLINE I32 S_regcurly(const char *s) { PERL_ARGS_ASSERT_REGCURLY; if (*s++ != '{') return FALSE; if (!isDIGIT(*s)) return FALSE; while (isDIGIT(*s)) s++; if (*s == ',') { s++; while (isDIGIT(*s)) s++; } return *s == '}'; }
/* - regcurly - a little FSA that accepts {\d+,?\d*} Pulled from regcomp.c. */ PERL_STATIC_INLINE I32 S_regcurly(pTHX_ register const char *s) { PERL_ARGS_ASSERT_REGCURLY; if (*s++ != '{') return FALSE; if (!isDIGIT(*s)) return FALSE; while (isDIGIT(*s)) s++; if (*s == ',') { s++; while (isDIGIT(*s)) s++; } if (*s != '}') return FALSE; return TRUE; }
/* Single hex char to int; -1 if not a hex char. */ static int fmm_hextoint(int c) { if (isDIGIT(c)) return c - '0'; if ((c >= 'a') && (c <= 'f')) return c + 10 - 'a'; if ((c >= 'A') && (c <= 'F')) return c + 10 - 'A'; return -1; }
NETDB_DEFINE_CONTEXT NETINET_DEFINE_CONTEXT #endif #ifdef I_SYSUIO # include <sys/uio.h> #endif #ifndef AF_NBS # undef PF_NBS #endif #ifndef AF_X25 # undef PF_X25 #endif #ifndef INADDR_NONE # define INADDR_NONE 0xffffffff #endif /* INADDR_NONE */ #ifndef INADDR_BROADCAST # define INADDR_BROADCAST 0xffffffff #endif /* INADDR_BROADCAST */ #ifndef INADDR_LOOPBACK # define INADDR_LOOPBACK 0x7F000001 #endif /* INADDR_LOOPBACK */ #ifndef HAS_INET_ATON /* * Check whether "cp" is a valid ascii representation * of an Internet address and convert to a binary address. * Returns 1 if the address is valid, 0 if not. * This replaces inet_addr, the return value from which * cannot distinguish between failure and a local broadcast address. */ static int my_inet_aton(register const char *cp, struct in_addr *addr) { dTHX; register U32 val; register int base; register char c; int nparts; const char *s; unsigned int parts[4]; register unsigned int *pp = parts; if (!cp || !*cp) return 0; for (;;) { /* * Collect number up to ``.''. * Values are specified as for C: * 0x=hex, 0=octal, other=decimal. */ val = 0; base = 10; if (*cp == '0') { if (*++cp == 'x' || *cp == 'X') base = 16, cp++; else base = 8; } while ((c = *cp) != '\0') { if (isDIGIT(c)) { val = (val * base) + (c - '0'); cp++; continue; } if (base == 16 && (s=strchr(PL_hexdigit,c))) { val = (val << 4) + ((s - PL_hexdigit) & 15); cp++; continue; } break; } if (*cp == '.') { /* * Internet format: * a.b.c.d * a.b.c (with c treated as 16-bits) * a.b (with b treated as 24 bits) */ if (pp >= parts + 3 || val > 0xff) return 0; *pp++ = val, cp++; } else break; } /* * Check for trailing characters. */ if (*cp && !isSPACE(*cp)) return 0; /* * Concoct the address according to * the number of parts specified. */ nparts = pp - parts + 1; /* force to an int for switch() */ switch (nparts) { case 1: /* a -- 32 bits */ break; case 2: /* a.b -- 8.24 bits */ if (val > 0xffffff) return 0; val |= parts[0] << 24; break; case 3: /* a.b.c -- 8.8.16 bits */ if (val > 0xffff) return 0; val |= (parts[0] << 24) | (parts[1] << 16); break; case 4: /* a.b.c.d -- 8.8.8.8 bits */ if (val > 0xff) return 0; val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); break; } addr->s_addr = htonl(val); return 1; }
EXTERN SV* decode_entities(pTHX_ SV* sv, HV* entity2char, bool expand_prefix) { STRLEN len; char *s = SvPV_force(sv, len); char *t = s; char *end = s + len; char *ent_start; char *repl; STRLEN repl_len; #ifdef UNICODE_HTML_PARSER char buf[UTF8_MAXLEN]; int repl_utf8; int high_surrogate = 0; #else char buf[1]; #endif #if defined(__GNUC__) && defined(UNICODE_HTML_PARSER) /* gcc -Wall reports this variable as possibly used uninitialized */ repl_utf8 = 0; #endif while (s < end) { assert(t <= s); if ((*t++ = *s++) != '&') continue; ent_start = s; repl = 0; if (s < end && *s == '#') { UV num = 0; int ok = 0; s++; if (s < end && (*s == 'x' || *s == 'X')) { s++; while (s < end) { char *tmp = strchr(PL_hexdigit, *s); if (!tmp) break; num = num << 4 | ((tmp - PL_hexdigit) & 15); if (num > 0x10FFFF) { /* overflow */ ok = 0; break; } s++; ok = 1; } } else { while (s < end && isDIGIT(*s)) { num = num * 10 + (*s - '0'); if (num > 0x10FFFF) { /* overflow */ ok = 0; break; } s++; ok = 1; } } if (num && ok) { #ifdef UNICODE_HTML_PARSER if (!SvUTF8(sv) && num <= 255) { buf[0] = (char) num; repl = buf; repl_len = 1; repl_utf8 = 0; } else if (num == 0xFFFE || num == 0xFFFF) { /* illegal */ } else { char *tmp; if ((num & 0xFFFFFC00) == 0xDC00) { /* low-surrogate */ if (high_surrogate != 0) { t -= 3; /* Back up past 0xFFFD */ num = ((high_surrogate - 0xD800) << 10) + (num - 0xDC00) + 0x10000; high_surrogate = 0; } else { num = 0xFFFD; } } else if ((num & 0xFFFFFC00) == 0xD800) { /* high-surrogate */ high_surrogate = num; num = 0xFFFD; } else { high_surrogate = 0; /* otherwise invalid? */ if ((num >= 0xFDD0 && num <= 0xFDEF) || ((num & 0xFFFE) == 0xFFFE) || num > 0x10FFFF) { num = 0xFFFD; } } tmp = (char*)uvuni_to_utf8((U8*)buf, num); repl = buf; repl_len = tmp - buf; repl_utf8 = 1; } #else if (num <= 255) { buf[0] = (char) num & 0xFF; repl = buf; repl_len = 1; } #endif } } else { char *ent_name = s; while (s < end && isALNUM(*s)) s++; if (ent_name != s && entity2char) { SV** svp; if ( (svp = hv_fetch(entity2char, ent_name, s - ent_name, 0)) || (*s == ';' && (svp = hv_fetch(entity2char, ent_name, s - ent_name + 1, 0))) ) { repl = SvPV(*svp, repl_len); #ifdef UNICODE_HTML_PARSER repl_utf8 = SvUTF8(*svp); #endif } else if (expand_prefix) { char *ss = s - 1; while (ss > ent_name) { svp = hv_fetch(entity2char, ent_name, ss - ent_name, 0); if (svp) { repl = SvPV(*svp, repl_len); #ifdef UNICODE_HTML_PARSER repl_utf8 = SvUTF8(*svp); #endif s = ss; break; } ss--; } } } #ifdef UNICODE_HTML_PARSER high_surrogate = 0; #endif } if (repl) { char *repl_allocated = 0; if (s < end && *s == ';') s++; t--; /* '&' already copied, undo it */ #ifdef UNICODE_HTML_PARSER if (*s != '&') { high_surrogate = 0; } if (!SvUTF8(sv) && repl_utf8) { /* need to upgrade sv before we continue */ STRLEN before_gap_len = t - SvPVX(sv); char *before_gap = (char*)bytes_to_utf8((U8*)SvPVX(sv), &before_gap_len); STRLEN after_gap_len = end - s; char *after_gap = (char*)bytes_to_utf8((U8*)s, &after_gap_len); sv_setpvn(sv, before_gap, before_gap_len); sv_catpvn(sv, after_gap, after_gap_len); SvUTF8_on(sv); Safefree(before_gap); Safefree(after_gap); s = t = SvPVX(sv) + before_gap_len; end = SvPVX(sv) + before_gap_len + after_gap_len; } else if (SvUTF8(sv) && !repl_utf8) { repl = (char*)bytes_to_utf8((U8*)repl, &repl_len); repl_allocated = repl; } #endif if (t + repl_len > s) { /* need to grow the string */ grow_gap(aTHX_ sv, repl_len - (s - t), &t, &s, &end); } /* copy replacement string into string */ while (repl_len--) *t++ = *repl++; if (repl_allocated) Safefree(repl_allocated); } else { while (ent_start < s) *t++ = *ent_start++; } } *t = '\0'; SvCUR_set(sv, t - SvPVX(sv)); return sv; }
sar_bool sar_lookPathPos_c(sarNode_p currNode, const char * checkStr, long startPos, long currPos, long len, sar_bool negative) { sar_bool matched = SAR_FALSE; int callPos = 0; while(currNode->callFunc[callPos] != (SV*)NULL) { matched = SAR_TRUE; sar_runCallFunc_c(currNode->callFunc[callPos], startPos, currPos); ++callPos; } if (currPos >= len) { return matched; } char checkChar = checkStr[currPos]; sarNode_p plusNode = currNode->plusNode; if (plusNode != (sarNode_p)NULL) { if (negative) { int pathCharNum = 0; for (pathCharNum=0; pathCharNum < plusNode->charNumber; ++pathCharNum) { if (checkChar != plusNode->sarPathChars[pathCharNum]) { sarNode_p nextPlusNode = plusNode->sarNodes[pathCharNum]; sar_bool plusNodesMatched = sar_matchPlusNode_c(nextPlusNode, checkStr, startPos, currPos, len, SAR_CHAR, negative); matched = matched || plusNodesMatched; } } if (plusNode->digitNode != (sarNode_p)NULL) { if (! isDIGIT(checkChar)) { sarNode_p nextPlusNode = plusNode->digitNode; sar_bool plusNodesMatched = sar_matchPlusNode_c(nextPlusNode, checkStr, startPos, currPos, len, SAR_DIGIT, negative); matched = matched || plusNodesMatched; } } } else { int existListPlusNodePos = sar_searchChar_c(plusNode->sarPathChars, plusNode->charNumber, checkChar); if (existListPlusNodePos >= 0) { sarNode_p nextPlusNode = plusNode->sarNodes[existListPlusNodePos]; sar_bool plusNodesMatched = sar_matchPlusNode_c(nextPlusNode, checkStr, startPos, currPos, len, SAR_CHAR, negative); matched = matched || plusNodesMatched; } if (plusNode->dotNode != (sarNode_p)NULL) { sarNode_p nextPlusNode = plusNode->dotNode; sar_bool plusNodesMatched = sar_matchPlusNode_c(nextPlusNode, checkStr, startPos, currPos, len, SAR_DOT, negative); matched = matched || plusNodesMatched; } if (plusNode->digitNode != (sarNode_p)NULL) { if (isDIGIT(checkChar)) { sarNode_p nextPlusNode = plusNode->digitNode; sar_bool plusNodesMatched = sar_matchPlusNode_c(nextPlusNode, checkStr, startPos, currPos, len, SAR_DIGIT, negative); matched = matched || plusNodesMatched; } } if (plusNode->alphaNumNode != (sarNode_p)NULL) { if (isALNUM(checkChar)) { sarNode_p nextPlusNode = plusNode->alphaNumNode; sar_bool plusNodesMatched = sar_matchPlusNode_c(nextPlusNode, checkStr, startPos, currPos, len, SAR_ALPHA_NUM, negative); matched = matched || plusNodesMatched; } } if (plusNode->alphaNode != (sarNode_p)NULL) { if (isALPHA(checkChar)) { sarNode_p nextPlusNode = plusNode->alphaNode; sar_bool plusNodesMatched = sar_matchPlusNode_c(nextPlusNode, checkStr, startPos, currPos, len, SAR_ALPHA, negative); matched = matched || plusNodesMatched; } } if (plusNode->spaceNode != (sarNode_p)NULL) { if (isSPACE(checkChar)) { sarNode_p nextPlusNode = plusNode->spaceNode; sar_bool plusNodesMatched = sar_matchPlusNode_c(nextPlusNode, checkStr, startPos, currPos, len, SAR_SPACE, negative); matched = matched || plusNodesMatched; } } } } if (negative) { int pathCharNum = 0; for (pathCharNum=0; pathCharNum < currNode->charNumber; ++pathCharNum) { if (checkChar != currNode->sarPathChars[pathCharNum]) { sar_bool nodesMatched = sar_lookPathPos_c(currNode->sarNodes[pathCharNum], checkStr, startPos, currPos + 1, len, SAR_FALSE); matched = matched || nodesMatched; } } if (currNode->spaceNode != (sarNode_p)NULL) { if (! isSPACE(checkChar)) { sar_bool nodesMatched = sar_lookPathPos_c(currNode->spaceNode, checkStr, startPos, currPos + 1, len, SAR_FALSE); matched = matched || nodesMatched; } } if (currNode->digitNode != (sarNode_p)NULL) { if (! isDIGIT(checkChar)) { sar_bool nodesMatched = sar_lookPathPos_c(currNode->digitNode, checkStr, startPos, currPos + 1, len, SAR_FALSE); matched = matched || nodesMatched; } } if (currNode->alphaNumNode != (sarNode_p)NULL) { if (! isALNUM(checkChar)) { sar_bool nodesMatched = sar_lookPathPos_c(currNode->alphaNumNode, checkStr, startPos, currPos + 1, len, SAR_FALSE); matched = matched || nodesMatched; } } if (currNode->alphaNode != (sarNode_p)NULL) { if (! isALPHA(checkChar)) { sar_bool nodesMatched = sar_lookPathPos_c(currNode->alphaNode, checkStr, startPos, currPos + 1, len, SAR_FALSE); matched = matched || nodesMatched; } } } else { int existListNodePos = sar_searchChar_c(currNode->sarPathChars, currNode->charNumber, checkChar); if (existListNodePos >= 0) { sar_bool nodesMatched = sar_lookPathPos_c(currNode->sarNodes[existListNodePos], checkStr, startPos, currPos + 1, len, SAR_FALSE); matched = matched || nodesMatched; } if (currNode->negativeNode != (sarNode_p)NULL) { sar_bool nodesMatched = sar_lookPathPos_c(currNode->negativeNode, checkStr, startPos, currPos, len, SAR_TRUE); matched = matched || nodesMatched; } if (currNode->dotNode != (sarNode_p)NULL) { sar_bool nodesMatched = sar_lookPathPos_c(currNode->dotNode, checkStr, startPos, currPos + 1, len, SAR_FALSE); matched = matched || nodesMatched; } if (currNode->spaceNode != (sarNode_p)NULL) { if (isSPACE(checkChar)) { sar_bool nodesMatched = sar_lookPathPos_c(currNode->spaceNode, checkStr, startPos, currPos + 1, len, SAR_FALSE); matched = matched || nodesMatched; } } if (currNode->digitNode != (sarNode_p)NULL) { if (isDIGIT(checkChar)) { sar_bool nodesMatched = sar_lookPathPos_c(currNode->digitNode, checkStr, startPos, currPos + 1, len, SAR_FALSE); matched = matched || nodesMatched; } } if (currNode->alphaNumNode != (sarNode_p)NULL) { if (isALNUM(checkChar)) { sar_bool nodesMatched = sar_lookPathPos_c(currNode->alphaNumNode, checkStr, startPos, currPos + 1, len, SAR_FALSE); matched = matched || nodesMatched; } } if (currNode->alphaNode != (sarNode_p)NULL) { if (isALPHA(checkChar)) { sar_bool nodesMatched = sar_lookPathPos_c(currNode->alphaNode, checkStr, startPos, currPos + 1, len, SAR_FALSE); matched = matched || nodesMatched; } } } return matched; }