void print_section(Elf_data* data, int i) { unsigned int j; while (++i < E_SHNUM(data)) if (SH_SIZE(data, i) > 0) { printf("Contents of section %s:\n", &data->strtab[SH_NAME(data, i)]); j = 0; while (j < SH_SIZE(data, i) && SH_OFFSET(data, i) + j < data->fsize) { if (j == 0) printf(" %04x\t", (unsigned int)SH_ADDR(data, i) + j); printf("%02x", *(UCHAR(data->data) + SH_OFFSET(data, i) + j)); ++j; if (j != 0 && j % 16 == 0) { print_char(UCHAR(data->data) + SH_OFFSET(data, i), j - 16, j); printf("\n %04x\t", (unsigned int)SH_ADDR(data, i) + j); } else if (j != 0 && j % 4 == 0) printf(" "); } print_char(UCHAR(data->data) + SH_OFFSET(data, i), j - (j % 16), j); printf("\n"); } }
int match(char *str, char *substr) /* **-------------------------------------------------------------- ** Input: *str = string being searched ** *substr = substring being searched for ** Output: returns 1 if substr found in str, 0 if not ** Purpose: sees if substr matches any part of str ** ** (Not case sensitive) **-------------------------------------------------------------- */ { int i,j; /*** Updated 9/7/00 ***/ /* Fail if substring is empty */ if (!substr[0]) return(0); /* Skip leading blanks of str. */ for (i=0; str[i]; i++) if (str[i] != ' ') break; /* Check if substr matches remainder of str. */ for (i=i,j=0; substr[j]; i++,j++) if (!str[i] || UCHAR(str[i]) != UCHAR(substr[j])) return(0); return(1); } /* end of match */
int match(char *str, char *substr) // // Input: str = character string being searched // substr = sub-string being searched for // Output: returns 1 if sub-string found, 0 if not // Purpose: sees if a sub-string of characters appears in a string // (not case sensitive). // { int i,j; // --- fail if substring is empty if (!substr[0]) return(0); // --- skip leading blanks of str for (i = 0; str[i]; i++) { if (str[i] != ' ') break; } // --- check if substr matches remainder of str for (i = i,j = 0; substr[j]; i++,j++) { if (!str[i] || UCHAR(str[i]) != UCHAR(substr[j])) return(0); } return(1); }
/* Case-insensitive comparison of strings s1 and s2 */ int samestr(char *s1, char *s2) { int i; for (i=0; UCHAR(s1[i]) == UCHAR(s2[i]); i++) if (!s1[i+1] && !s2[i+1]) return(1); return(0); } /* End of samestr */
int TkGetDoublePixels( Tcl_Interp *interp, /* Use this for error reporting. */ Tk_Window tkwin, /* Window whose screen determines conversion * from centimeters and other absolute * units. */ const char *string, /* String describing a number of pixels. */ double *doublePtr) /* Place to store converted result. */ { char *end; double d; d = strtod((char *) string, &end); if (end == string) { goto error; } while ((*end != '\0') && isspace(UCHAR(*end))) { end++; } switch (*end) { case 0: break; case 'c': d *= 10*WidthOfScreen(Tk_Screen(tkwin)); d /= WidthMMOfScreen(Tk_Screen(tkwin)); end++; break; case 'i': d *= 25.4*WidthOfScreen(Tk_Screen(tkwin)); d /= WidthMMOfScreen(Tk_Screen(tkwin)); end++; break; case 'm': d *= WidthOfScreen(Tk_Screen(tkwin)); d /= WidthMMOfScreen(Tk_Screen(tkwin)); end++; break; case 'p': d *= (25.4/72.0)*WidthOfScreen(Tk_Screen(tkwin)); d /= WidthMMOfScreen(Tk_Screen(tkwin)); end++; break; default: goto error; } while ((*end != '\0') && isspace(UCHAR(*end))) { end++; } if (*end != 0) { goto error; } *doublePtr = d; return TCL_OK; error: Tcl_SetObjResult(interp, Tcl_ObjPrintf( "bad screen distance \"%s\"", string)); Tcl_SetErrorCode(interp, "TK", "VALUE", "FRACTIONAL_PIXELS", NULL); return TCL_ERROR; }
/* * NAME: item->add() * DESCRIPTION: add an item to a set */ static void it_add(itchunk **c, item **ri, char *ref, unsigned short ruleno, unsigned short offset, bool sort) { /* * add item to set */ if (offset == UCHAR(ref[0]) << 1) { offset = UCHAR(ref[1]); /* skip possible function at the end */ } if (sort) { while (*ri != (item *) NULL && ((*ri)->ref < ref || ((*ri)->ref == ref && (*ri)->offset <= offset))) { if ((*ri)->ref == ref && (*ri)->offset == offset) { return; /* already in set */ } ri = &(*ri)->next; } } else { while (*ri != (item *) NULL) { if ((*ri)->ref == ref && (*ri)->offset == offset) { return; /* already in set */ } ri = &(*ri)->next; } } *ri = it_new(c, ref, ruleno, offset, *ri); }
int treatmnt_readExpression(char* tok[], int ntoks) // // Input: tok[] = array of string tokens // ntoks = number of tokens // Output: returns an error code // Purpose: reads a treatment expression from a tokenized line of input. // { char s[MAXLINE+1]; char* expr; int i, j, k, p; MathExpr* equation; // ptr. to a math. expression //(5.0.010 - LR) // --- retrieve node & pollutant if ( ntoks < 3 ) return error_setInpError(ERR_ITEMS, ""); j = project_findObject(NODE, tok[0]); if ( j < 0 ) return error_setInpError(ERR_NAME, tok[0]); p = project_findObject(POLLUT, tok[1]); if ( p < 0 ) return error_setInpError(ERR_NAME, tok[1]); // --- concatenate remaining tokens into a single string strcpy(s, tok[2]); for ( i=3; i<ntoks; i++) { strcat(s, " "); strcat(s, tok[i]); } // --- check treatment type if ( UCHAR(s[0]) == 'R' ) k = 0; else if ( UCHAR(s[0]) == 'C' ) k = 1; else return error_setInpError(ERR_KEYWORD, tok[2]); // --- start treatment expression after equals sign expr = strchr(s, '='); if ( expr == NULL ) return error_setInpError(ERR_KEYWORD, ""); else expr++; // --- create treatment objects at node j if they don't already exist if ( Node[j].treatment == NULL ) { if ( !createTreatment(j) ) return error_setInpError(ERR_MEMORY, ""); } // --- create a parsed expression tree from the string expr // (getVariableIndex is the function that converts a treatment // variable's name into an index number) equation = mathexpr_create(expr, getVariableIndex); if ( equation == NULL ) return error_setInpError(ERR_TREATMENT_EXPR, ""); // --- save the treatment parameters in the node's treatment object Node[j].treatment[p].treatType = k; Node[j].treatment[p].equation = equation; return 0; }
char * Ns_NextWord(char *line) { while (*line != '\0' && !isspace(UCHAR(*line))) { ++line; } while (*line != '\0' && isspace(UCHAR(*line))) { ++line; } return line; }
//检查1245 BOOL CStringChecker::CheckDirName( LPCTSTR cStr ) { // BOOL b; // b = CheckEmpty(cStr); // if(!b) return b; // b = CheckWindowsRuler(cStr); // if(!b) return b; // b = CheckSpacePoint(cStr); // if(!b) return b; // b = CheckLength(cStr, 20); // return b; //char str[] = "^[a-zA-Z_\\xB0-\\xF7\\xA1-\\xFE][a-zA-Z0-9_\\xB0-\\xF7\\xA1-\\xFE]*$"; //BOOL b = RegexMatch(cStr, str); BOOL b = TRUE; LPCTSTR p = cStr; unsigned char c = *p; //if(c >= '0' && c <= '9') b =FALSE; //else while(c = *p++) { if((c < '0' || c > '9') && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && c != '_' ) { if( (c >= 0xB0 && c<= 0xF7 && UCHAR(*p) >= 0xA1 && UCHAR(*p) <= 0xFE) || (c == 0xA6 && UCHAR(*p) >= 0xA1 && UCHAR(*p) <= 0xFE) ) {//属于汉字范围(16-87区)或希腊字母(6区) p++; continue; } if (c=='-') // 允许文件夹名称有中画线杠'-' continue; b = FALSE; break; } } if(CString(cStr).FindOneOf(CStringCheckerConfig::CheckFilter) != -1) {//字符查找 b = FALSE; } if(!b) { SetLastErr(CStringCheckerConfig::CheckErrorDir); return b; } b = CheckEmpty(cStr); if(!b) return b; b = CheckLength(cStr, 20); return b; }
a_sprite * compile_sprtext (const a_fontdata *font, const char *text, enum text_option topt, unsigned int maxwidth, int offset) { unsigned int nspaces; unsigned int text_width = 0; check_message_is_drawable (font, text); if (topt & T_FLUSHED_LEFT) { /* FLUSHED_LEFT or JUSTIFIED */ if (topt & T_FLUSHED_RIGHT) { /* JUSTIFIED */ text_width = compute_text_width (font, text, &nspaces); if (nspaces == 0) { /* we cannot justify a text without spaces */ topt &= ~T_JUSTIFIED; topt |= T_FLUSHED_LEFT; } } } else { /* FLUSHED_RIGHT or CENTERED */ text_width = compute_text_width (font, text, 0); if (topt & T_FLUSHED_RIGHT) /* FLUSHED_RIGHT */ offset -= (int) text_width; else /* CENTERED */ offset -= (int) text_width/2; } new_sprprog (); for (; *text; ++text) { if (*text == ' ') { if ((topt & T_JUSTIFIED) == T_JUSTIFIED) { unsigned int off = (maxwidth - text_width) / nspaces; offset += off; text_width += off; --nspaces; } else offset += font->width[' ']; } else { /* ensure that the letter actually exists before drawing it */ if (font->width[UCHAR (*text)]) add_sprprog (compile_sprrle (font->upper_left[UCHAR (*text)], 0, font->height, font->width[UCHAR (*text)], font->line_size, xbuf), offset); offset += font->width[UCHAR (*text)]; } } if (topt & T_WAVING) return end_sprprogwav (); else return end_sprprog (); }
int Tk_GetScreenMM( Tcl_Interp *interp, /* Use this for error reporting. */ Tk_Window tkwin, /* Window whose screen determines conversion * from centimeters and other absolute * units. */ const char *string, /* String describing a screen distance. */ double *doublePtr) /* Place to store converted result. */ { char *end; double d; d = strtod(string, &end); if (end == string) { error: Tcl_AppendResult(interp, "bad screen distance \"", string, "\"", NULL); return TCL_ERROR; } while ((*end != '\0') && isspace(UCHAR(*end))) { end++; } switch (*end) { case 0: d /= WidthOfScreen(Tk_Screen(tkwin)); d *= WidthMMOfScreen(Tk_Screen(tkwin)); break; case 'c': d *= 10; end++; break; case 'i': d *= 25.4; end++; break; case 'm': end++; break; case 'p': d *= 25.4/72.0; end++; break; default: goto error; } while ((*end != '\0') && isspace(UCHAR(*end))) { end++; } if (*end != 0) { goto error; } *doublePtr = d; return TCL_OK; }
mask_type init_thread_affinity_mask( std::size_t num_thread , bool numa_sensitive ) { // {{{ std::size_t num_of_cores = hardware_concurrency(); std::size_t affinity = num_thread % num_of_cores; ULONG numa_nodes = 1; if (GetNumaHighestNodeNumber(&numa_nodes)) ++numa_nodes; std::size_t num_of_cores_per_numa_node = num_of_cores / numa_nodes; ULONGLONG node_affinity_mask = 0; ULONGLONG mask = 0x01LL; if (numa_sensitive) { UCHAR numa_node = UCHAR(affinity % numa_nodes); if (!GetNumaNodeProcessorMask(numa_node, &node_affinity_mask)) { HPX_THROW_EXCEPTION(kernel_error , "hpx::threads::windows_topology::init_thread_affinity_mask" , boost::str(boost::format( "failed to initialize thread %1% affinity mask") % num_thread)); } mask = least_significant_bit(node_affinity_mask) << (affinity / numa_nodes); } else { UCHAR numa_node = UCHAR(get_numa_node_number(num_thread)); if (!GetNumaNodeProcessorMask(numa_node, &node_affinity_mask)) { HPX_THROW_EXCEPTION(kernel_error , "hpx::threads::windows_topology::init_thread_affinity_mask" , boost::str(boost::format( "failed to initialize thread %1% affinity mask") % num_thread)); } mask = least_significant_bit(node_affinity_mask) << (affinity % num_of_cores_per_numa_node); } while (!(mask & node_affinity_mask)) { mask <<= 1LL; if (0 == mask) mask = 0x01LL; } return static_cast<mask_type>(mask); } // }}}
std::string CStringChecker::ReplaceDirName( LPCTSTR str, LPCTSTR strRe ) { std::string strTemp(str); std::string strReplace(strRe); std::string strReturn; if(strTemp.empty()) return strReturn; for(int i = 0; i < (int)strTemp.length(); i++) { UCHAR c = strTemp[i]; BOOL b = TRUE; if(c < 0xB0 && CString(CHAR(c)).FindOneOf(CStringCheckerConfig::CheckFilterReplace) != -1) {//字符查找 b = FALSE; } else if(CString(strTemp.substr(i, 2).c_str()).FindOneOf(CStringCheckerConfig::CheckFilterReplace) != -1) {//汉字查找 i++; b = FALSE; } else if((c < '0' || c > '9') && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && c != '_' ) { if(c >= 0xB0 && c<= 0xF7 && UCHAR(strTemp[i + 1]) >= 0xA1 && UCHAR(strTemp[i + 1]) <= 0xFE) {//属于汉字范围 strReturn += strTemp.substr(i, 2); i++; continue; } if(c >= 0x80) {//是全角符号 strReturn += strTemp.substr(i, 2); i++; continue; } b = FALSE; } if(b) {//加上原字符 strReturn += c; } else {//加上替换字符串 strReturn += strRe; } } return strReturn; }
static int NextBitmapWord( ParseInfo *parseInfoPtr) /* Describes what we're reading and where we * are in it. */ { const char *src; char *dst; int c; parseInfoPtr->wordLength = 0; dst = parseInfoPtr->word; if (parseInfoPtr->string != NULL) { for (src = parseInfoPtr->string; isspace(UCHAR(*src)) || (*src == ','); src++) { if (*src == 0) { return TCL_ERROR; } } for ( ; !isspace(UCHAR(*src)) && (*src != ',') && (*src != 0); src++) { *dst = *src; dst++; parseInfoPtr->wordLength++; if (parseInfoPtr->wordLength > MAX_WORD_LENGTH) { return TCL_ERROR; } } parseInfoPtr->string = src; } else { for (c = GetByte(parseInfoPtr->chan); isspace(UCHAR(c)) || (c == ','); c = GetByte(parseInfoPtr->chan)) { if (c == EOF) { return TCL_ERROR; } } for ( ; !isspace(UCHAR(c)) && (c != ',') && (c != EOF); c = GetByte(parseInfoPtr->chan)) { *dst = c; dst++; parseInfoPtr->wordLength++; if (parseInfoPtr->wordLength > MAX_WORD_LENGTH) { return TCL_ERROR; } } } if (parseInfoPtr->wordLength == 0) { return TCL_ERROR; } parseInfoPtr->word[parseInfoPtr->wordLength] = 0; return TCL_OK; }
char * Ns_StrToUpper(char *string) { char *s; s = string; while (*s != '\0') { if (islower(UCHAR(*s))) { *s = toupper(UCHAR(*s)); } ++s; } return string; }
/* * NAME: parser->new() * DESCRIPTION: create a new parser instance */ static parser *ps_new(frame *f, string *source, string *grammar) { parser *ps; char *p; ps = ALLOC(parser, 1); ps->frame = f; ps->data = f->data; ps->data->parser = ps; str_ref(ps->source = source); str_ref(ps->grammar = grammar); ps->fastr = (char *) NULL; ps->lrstr = (char *) NULL; ps->fa = dfa_new(source->text, grammar->text); ps->lr = srp_new(grammar->text); ps->pnc = (pnchunk *) NULL; ps->list.snc = (snchunk *) NULL; ps->list.first = ps->list.free = (snode *) NULL; ps->strc = (strchunk *) NULL; ps->arrc = (arrchunk *) NULL; p = grammar->text; ps->ntoken = ((UCHAR(p[5]) + UCHAR(p[9]) + UCHAR(p[11])) << 8) + UCHAR(p[6]) + UCHAR(p[10]) + UCHAR(p[12]); ps->nprod = (UCHAR(p[13]) << 8) + UCHAR(p[14]); return ps; }
static TCL_HASH_TYPE HashStringKey( Tcl_HashTable *tablePtr, /* Hash table. */ void *keyPtr) /* Key from which to compute hash value. */ { register const char *string = keyPtr; register unsigned int result; register char c; /* * I tried a zillion different hash functions and asked many other people * for advice. Many people had their own favorite functions, all * different, but no-one had much idea why they were good ones. I chose * the one below (multiply by 9 and add new character) because of the * following reasons: * * 1. Multiplying by 10 is perfect for keys that are decimal strings, and * multiplying by 9 is just about as good. * 2. Times-9 is (shift-left-3) plus (old). This means that each * character's bits hang around in the low-order bits of the hash value * for ever, plus they spread fairly rapidly up to the high-order bits * to fill out the hash value. This seems works well both for decimal * and non-decimal strings, but isn't strong against maliciously-chosen * keys. * * Note that this function is very weak against malicious strings; it's * very easy to generate multiple keys that have the same hashcode. On the * other hand, that hardly ever actually occurs and this function *is* * very cheap, even by comparison with industry-standard hashes like FNV. * If real strength of hash is required though, use a custom hash based on * Bob Jenkins's lookup3(), but be aware that it's significantly slower. * Since Tcl command and namespace names are usually reasonably-named (the * main use for string hashes in modern Tcl) speed is far more important * than strength. * * See also HashString in tclLiteral.c. * See also TclObjHashKey in tclObj.c. * * See [tcl-Feature Request #2958832] */ if ((result = UCHAR(*string)) != 0) { while ((c = *++string) != 0) { result += (result << 3) + UCHAR(c); } } return (TCL_HASH_TYPE) result; }
/** * Given the name of a signal, returns the signal value if found, * or returns -1 (and sets an error) if not found. * We accept -SIGINT, SIGINT, INT or any lowercase version or a number, * either positive or negative. */ static int find_signal_by_name(Jim_Interp *interp, const char *name) { int i; const char *pt = name; /* Remove optional - and SIG from the front of the name */ if (*pt == '-') { pt++; } if (strncasecmp(name, "sig", 3) == 0) { pt += 3; } if (isdigit(UCHAR(pt[0]))) { i = atoi(pt); if (i > 0 && i < MAX_SIGNALS) { return i; } } else { for (i = 1; i < MAX_SIGNALS; i++) { /* Jim_SignalId() returns names such as SIGINT, and * returns "unknown signal" if unknown, so this will work */ if (strcasecmp(Jim_SignalId(i) + 3, pt) == 0) { return i; } } } Jim_SetResultFormatted(interp, "unknown signal %s", name); return -1; }
static Jim_Obj * Win32ErrorObj(Jim_Interp *interp, const char * szPrefix, DWORD dwError) { Jim_Obj *msgObj = NULL; char * lpBuffer = NULL; DWORD dwLen = 0; dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, LANG_NEUTRAL, (char *)&lpBuffer, 0, NULL); if (dwLen < 1) { dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, "code 0x%1!08X!%n", 0, LANG_NEUTRAL, (char *)&lpBuffer, 0, (va_list *)&dwError); } msgObj = Jim_NewStringObj(interp, szPrefix, -1); if (dwLen > 0) { char *p = lpBuffer + dwLen - 1; /* remove cr-lf at end */ for ( ; p && *p && isspace(UCHAR(*p)); p--) ; *++p = 0; Jim_AppendString(interp, msgObj, ": ", 2); Jim_AppendString(interp, msgObj, lpBuffer, -1); } LocalFree((HLOCAL)lpBuffer); return msgObj; }
int getVariableIndex(char* s) // // Input: s = name of a process variable or pollutant // Output: returns index of process variable or pollutant // Purpose: finds position of process variable/pollutant in list of names. // { // --- check for a process variable first int k; int m = PVMAX; // PVMAX is number of process variables k = findmatch(s, ProcessVarWords); if ( k >= 0 ) return k; // --- then check for a pollutant concentration k = project_findObject(POLLUT, s); if ( k >= 0 ) return (k + m); // --- finally check for a pollutant removal if ( UCHAR(s[0]) == 'R' && s[1] == '_') { k = project_findObject(POLLUT, s+2); if ( k >= 0 ) return (Nobjects[POLLUT] + k + m); } return -1; }
int datetime_findMonth(char* month) // Input: month = month of year as character string // Output: returns: month of year as a number (1-12) // Purpose: finds number (1-12) of month. { int i; for (i = 0; i < 12; i++) { if (UCHAR(month[0]) == MonthTxt[i][0] && UCHAR(month[1]) == MonthTxt[i][1] && UCHAR(month[2]) == MonthTxt[i][2]) return i+1; } return 0; }
char * Ns_EncodeUrlWithEncoding(Ns_DString *dsPtr, char *string, Tcl_Encoding encoding) { register int i, n; register char *p, *q; Tcl_DString ds; Tcl_DStringInit(&ds); if (encoding != NULL) { string = Tcl_UtfToExternalDString(encoding, string, -1, &ds); } /* * Determine and set the required dstring length. */ p = string; n = 0; while ((i = UCHAR(*p)) != 0) { n += enc[i].len; ++p; } i = dsPtr->length; Ns_DStringSetLength(dsPtr, dsPtr->length + n); /* * Copy the result directly to the pre-sized dstring. */ q = dsPtr->string + i; p = string; while ((i = UCHAR(*p)) != 0) { if (UCHAR(*p) == ' ') { *q++ = '+'; } else if (enc[i].str == NULL) { *q++ = *p; } else { *q++ = '%'; *q++ = enc[i].str[0]; *q++ = enc[i].str[1]; } ++p; } Tcl_DStringFree(&ds); return dsPtr->string; }
int Ns_ParseHeader(Ns_Set *set, char *line, Ns_HeaderCaseDisposition disp) { char *key, *sep; char *value; int index; Ns_DString ds; /* * Header lines are first checked if they continue a previous * header indicated by any preceeding white space. Otherwise, * they must be in well form key: value form. */ if (isspace(UCHAR(*line))) { index = Ns_SetLast(set); if (index < 0) { return NS_ERROR; /* Continue before first header. */ } while (isspace(UCHAR(*line))) { ++line; } if (*line != '\0') { value = Ns_SetValue(set, index); Ns_DStringInit(&ds); Ns_DStringVarAppend(&ds, value, " ", line, NULL); Ns_SetPutValue(set, index, ds.string); Ns_DStringFree(&ds); } } else { sep = strchr(line, ':'); if (sep == NULL) { return NS_ERROR; /* Malformed header. */ } *sep = '\0'; value = sep + 1; while (*value != '\0' && isspace(UCHAR(*value))) { ++value; } index = Ns_SetPut(set, line, value); key = Ns_SetKey(set, index); if (disp == ToLower) { while (*key != '\0') { if (isupper(UCHAR(*key))) { *key = tolower(UCHAR(*key)); } ++key; } } else if (disp == ToUpper) { while (*key != '\0') { if (islower(UCHAR(*key))) { *key = toupper(UCHAR(*key)); } ++key; } } *sep = ':'; } return NS_OK; }
static unsigned HashString( register const char *string, /* String for which to compute hash value. */ int length) /* Number of bytes in the string. */ { register unsigned int result = 0; /* * I tried a zillion different hash functions and asked many other people * for advice. Many people had their own favorite functions, all * different, but no-one had much idea why they were good ones. I chose * the one below (multiply by 9 and add new character) because of the * following reasons: * * 1. Multiplying by 10 is perfect for keys that are decimal strings, and * multiplying by 9 is just about as good. * 2. Times-9 is (shift-left-3) plus (old). This means that each * character's bits hang around in the low-order bits of the hash value * for ever, plus they spread fairly rapidly up to the high-order bits * to fill out the hash value. This seems works well both for decimal * and non-decimal strings. * * Note that this function is very weak against malicious strings; it's * very easy to generate multiple keys that have the same hashcode. On the * other hand, that hardly ever actually occurs and this function *is* * very cheap, even by comparison with industry-standard hashes like FNV. * If real strength of hash is required though, use a custom hash based on * Bob Jenkins's lookup3(), but be aware that it's significantly slower. * Tcl scripts tend to not have a big issue in this area, and literals * mostly aren't looked up by name anyway. * * See also HashStringKey in tclHash.c. * See also TclObjHashKey in tclObj.c. * * See [tcl-Feature Request #2958832] */ if (length > 0) { result = UCHAR(*string); while (--length) { result += (result << 3) + UCHAR(*++string); } } return result; }
char * Ns_Match(char *a, char *b) { if (a != NULL && b != NULL) { while (*a != '\0' && *b != '\0') { char c1, c2; c1 = islower(UCHAR(*a)) ? *a : tolower(UCHAR(*a)); c2 = islower(UCHAR(*b)) ? *b : tolower(UCHAR(*b)); if (c1 != c2) { return NULL; } a++; b++; } } return (char *) b; }
ACL_VSTRING *escape(ACL_VSTRING *result, const char *data, ssize_t len) { int ch; ACL_VSTRING_RESET(result); while (len-- > 0) { ch = *UCHAR(data++); if (ACL_ISASCII(ch)) { if (ACL_ISPRINT(ch)) { if (ch == '\\') ACL_VSTRING_ADDCH(result, ch); ACL_VSTRING_ADDCH(result, ch); continue; } else if (ch == '\a') { /* \a -> audible bell */ acl_vstring_strcat(result, "\\a"); continue; } else if (ch == '\b') { /* \b -> backspace */ acl_vstring_strcat(result, "\\b"); continue; } else if (ch == '\f') { /* \f -> formfeed */ acl_vstring_strcat(result, "\\f"); continue; } else if (ch == '\n') { /* \n -> newline */ acl_vstring_strcat(result, "\\n"); continue; } else if (ch == '\r') { /* \r -> carriagereturn */ acl_vstring_strcat(result, "\\r"); continue; } else if (ch == '\t') { /* \t -> horizontal tab */ acl_vstring_strcat(result, "\\t"); continue; } else if (ch == '\v') { /* \v -> vertical tab */ acl_vstring_strcat(result, "\\v"); continue; } } if (ACL_ISDIGIT(*UCHAR(data))) acl_vstring_sprintf_append(result, "\\%03d", ch); else acl_vstring_sprintf_append(result, "\\%d", ch); } ACL_VSTRING_TERMINATE(result); return (result); }
char * Ns_StrTrimLeft(char *string) { if (string == NULL) { return NULL; } while (isspace(UCHAR(*string))) { ++string; } return string; }
mask_type init_numa_node_affinity_mask( std::size_t num_thread , bool numa_sensitive ) { // {{{ std::size_t num_of_cores = hardware_concurrency(); UCHAR affinity = UCHAR(num_thread % num_of_cores); ULONG numa_nodes = 1; if (GetNumaHighestNodeNumber(&numa_nodes)) ++numa_nodes; ULONGLONG mask = 0; if (numa_sensitive) { UCHAR numa_node = affinity % numa_nodes; if (!GetNumaNodeProcessorMask(numa_node, &mask)) { HPX_THROW_EXCEPTION(kernel_error , "hpx::threads::windows_topology::init_numa_node_affinity_mask" , boost::str(boost::format( "failed to initialize NUMA node affinity mask for " "thread %1%") % num_thread)); } return static_cast<mask_type>(mask); } UCHAR numa_node = UCHAR(get_numa_node_number(num_thread)); if (!GetNumaNodeProcessorMask(numa_node, &mask)) { HPX_THROW_EXCEPTION(kernel_error , "hpx::threads::windows_topology::init_numa_node_affinity_mask" , boost::str(boost::format( "failed to initialize NUMA node affinity mask for " "thread %1%") % num_thread)); } return static_cast<mask_type>(mask); } // }}}
/* * NAME: item->load() * DESCRIPTION: load an item */ static item *it_load(itchunk **c, unsigned short n, char **buf, char *grammar) { char *p; item **ri; item *it; char *ref; unsigned short ruleno; ri = ⁢ p = *buf; do { ref = grammar + (UCHAR(p[0]) << 8) + UCHAR(p[1]); p += 2; ruleno = (UCHAR(p[0]) << 8) + UCHAR(p[1]); p += 2; *ri = it_new(c, ref, ruleno, UCHAR(*p++), (item *) NULL); ri = &(*ri)->next; } while (--n != 0); *buf = p; return it; }
/* * This decrypts using the Cipher Block Chaining mode of DES * msgbuf I/O buffer * fp input file descriptor */ int cbc_decode(char *msgbuf, FILE *fp) { Desbuf tbuf; /* temp buffer for initialization vector */ int n; /* number of bytes actually read */ int c; /* used to test for EOF */ int inverse = 1; /* 0 to encrypt, 1 to decrypt */ if ((n = READ(BUFFER(msgbuf), 8, fp)) == 8) { /* * do the transformation */ MEMCPY(BUFFER(tbuf), BUFFER(msgbuf), 8); DES_XFORM(UBUFFER(msgbuf)); for (c = 0; c < 8; c++) UCHAR(msgbuf, c) ^= UCHAR(ivec, c); MEMCPY(BUFFER(ivec), BUFFER(tbuf), 8); /* * if the last one, handle it specially */ if ((c = fgetc(fp)) == EOF) { n = CHAR(msgbuf, 7); if (n < 0 || n > 7) { des_error("decryption failed (block corrupted)"); return EOF; } } else (void)ungetc(c, fp); return n; } if (n > 0) des_error("decryption failed (incomplete block)"); else if (n < 0) des_error("cannot read file"); return EOF; }