/* * Convert non-negative integer string representation in explicitly given radix * to an integer. * Return number of characters consumed maybe or-ed with overflow bit. * If overflow occurs, result integer (incorrect) is still returned. * * Don't you dare use this function. */ unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *res) { unsigned int rv; int overflow; *res = 0; rv = 0; overflow = 0; while (*s) { unsigned int val; if ('0' <= *s && *s <= '9') val = *s - '0'; else if ('a' <= _tolower(*s) && _tolower(*s) <= 'f') val = _tolower(*s) - 'a' + 10; else break; if (val >= base) break; if (*res > div_u64(ULLONG_MAX - val, base)) overflow = 1; *res = *res * base + val; rv++; s++; } if (overflow) rv |= KSTRTOX_OVERFLOW; return rv; }
/* * Convert non-negative integer string representation in explicitly given radix * to an integer. * Return number of characters consumed maybe or-ed with overflow bit. * If overflow occurs, result integer (incorrect) is still returned. * * Don't you dare use this function. */ unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *p) { unsigned long long res; unsigned int rv; res = 0; rv = 0; while (*s) { unsigned int val; if ('0' <= *s && *s <= '9') val = *s - '0'; else if ('a' <= _tolower(*s) && _tolower(*s) <= 'f') val = _tolower(*s) - 'a' + 10; else break; if (val >= base) break; /* * Check for overflow only if we are within range of * it in the max base we support (16) */ if (unlikely(res & (~0ull << 60))) { if (res > div_u64(ULLONG_MAX - val, base)) rv |= KSTRTOX_OVERFLOW; } res = res * base + val; rv++; s++; } *p = res; return rv; }
static int get_panel_data(char *str, struct panel_s6e8aa0a01_data *panel) { u8 temp_data[(ID_PARAM_SIZE+MTP_PARAM_SIZE)*2]; unsigned int val; int i = 0; while (*str) { if ('0' <= *str && *str <= '9') val = *str - '0'; else if ('a' <= _tolower(*str) && _tolower(*str) <= 'f') val = _tolower(*str) - 'a' + 10; else if (*str == '\n' && *(str + 1) == '\0') break; else return -EINVAL; temp_data[i++] = val; str++; } for (i = 0; i < ID_PARAM_SIZE; i++) { panel->panel_id[i] = ((temp_data[i*2]<<4)&0xF0)|(temp_data[i*2+1]&0x0F); pr_info("panel_id[%d]=0x%02x\n", i, panel->panel_id[i]); } for (i = 0; i < MTP_PARAM_SIZE; i++) { panel->mtp_data[i] = ((temp_data[(i+ID_PARAM_SIZE)*2]<<4)&0xF0)| (temp_data[(i+ID_PARAM_SIZE)*2+1]&0x0F); pr_info("mtp_data[%d]=0x%02x\n", i, panel->mtp_data[i]); } }
int ether_line (const char *line, struct ether_addr *addr, char *hostname) { size_t cnt; char *cp; for (cnt = 0; cnt < 6; ++cnt) { unsigned int number; char ch; ch = _tolower (*line++); if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f')) return -1; number = isdigit (ch) ? (ch - '0') : (ch - 'a' + 10); ch = _tolower (*line); if ((cnt < 5 && ch != ':') || (cnt == 5 && ch != '\0' && !isspace (ch))) { ++line; if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f')) return -1; number <<= 4; number += isdigit (ch) ? (ch - '0') : (ch - 'a' + 10); ch = *line; if (cnt < 5 && ch != ':') return -1; } /* Store result. */ addr->ether_addr_octet[cnt] = (unsigned char) number; /* Skip ':'. */ if (ch != '\0') ++line; } /* Remove trailing white space. */ cp = strchr (line, '#'); if (cp == NULL) cp = line + strlen (line); while (cp > line && isspace (cp[-1])) --cp; if (cp == line) /* No hostname. */ return -1; /* XXX This can cause trouble because the hostname might be too long but we have no possibility to check it here. */ memcpy (hostname, line, cp - line); hostname [cp - line] = '\0'; return 0; }
// // Compare (*left) and (*right), ignoring case // int cmp(const void* left, const void* right) { const unsigned char *s1 = *(const unsigned char **) left, *s2 = *(const unsigned char **) right; for (; _tolower(*s1) == _tolower(*s2); ++s1, ++s2) { if (*s1 == '\0') { return 0; } } return _tolower(*s1) - _tolower(*s2); }
const char *_parse_integer_fixup_radix(const char *s, unsigned int *base) { if (*base == 0) { if (s[0] == '0') { if (_tolower(s[1]) == 'x' && isxdigit(s[2])) *base = 16; else *base = 8; } else *base = 10; } if (*base == 16 && s[0] == '0' && _tolower(s[1]) == 'x') s += 2; return s; }
static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res) { unsigned long long acc; int ok; if (base == 0) { if (s[0] == '0') { if (_tolower(s[1]) == 'x' && isxdigit(s[2])) base = 16; else base = 8; } else base = 10; } if (base == 16 && s[0] == '0' && _tolower(s[1]) == 'x') s += 2; acc = 0; ok = 0; while (*s) { unsigned int val; if ('0' <= *s && *s <= '9') val = *s - '0'; else if ('a' <= _tolower(*s) && _tolower(*s) <= 'f') val = _tolower(*s) - 'a' + 10; else if (*s == '\n') { if (*(s + 1) == '\0') break; else return -EINVAL; } else return -EINVAL; if (val >= base) return -EINVAL; if (acc > div_u64(ULLONG_MAX - val, base)) return -ERANGE; acc = acc * base + val; ok = 1; s++; } if (!ok) return -EINVAL; *res = acc; return 0; }
static void test__tolower (void) { int i, j; for (i = -127; i < 256; ) j = i, printf ("%s: %d -> %d\n", __FUNCTION__, j, _tolower (i++)); }
int main (void) { char c; printf ("Enter the character to test: "); scanf ("%c", &c); printf ("isalpha ('%c') is %s\n", c, isalpha ((int) c) ? "True" : "False"); printf ("isalnum ('%c') is %s\n", c, isalnum ((int) c) ? "True" : "False"); printf ("isascii ('%c') is %s\n", c, isascii ((int) c) ? "True" : "False"); printf ("iscntrl ('%c') is %s\n", c, iscntrl ((int) c) ? "True" : "False"); printf ("isdigit ('%c') is %s\n", c, isdigit ((int) c) ? "True" : "False"); printf ("isgraph ('%c') is %s\n", c, isgraph ((int) c) ? "True" : "False"); printf ("islower ('%c') is %s\n", c, islower ((int) c) ? "True" : "False"); printf ("isprint ('%c') is %s\n", c, isprint ((int) c) ? "True" : "False"); printf ("ispunct ('%c') is %s\n", c, ispunct ((int) c) ? "True" : "False"); printf ("isspace ('%c') is %s\n", c, isspace ((int) c) ? "True" : "False"); printf ("isupper ('%c') is %s\n", c, isupper ((int) c) ? "True" : "False"); printf ("isxdigit ('%c') is %s\n\n", c, isxdigit ((int) c) ? "True" : "False"); printf ("tolower ('%c') gives %c\n", c, tolower ((int) c)); printf ("_tolower ('%c') gives %c\n", c, _tolower ((int) c)); printf ("toupper ('%c') gives %c\n", c, toupper ((int) c)); printf ("_toupper ('%c') gives %c\n", c, _toupper ((int) c)); printf ("toascii ('%c') gives %c\n", c, toascii ((int) c)); return (0); }
int tolower(int c) { #if !CAM_DRYOS return _tolower(c); #else return isupper(c) ? c - 'A' + 'a' : c; #endif }
// Print Shellcode void PrintSc(unsigned char *sc, int len) { int i,j; char *p; char msg[6]; //printf("/* %d bytes */\n", buffsize); // Print general shellcode for(i = 0; i < len; i++) { if((i%16)==0) { if(i!=0) printf("\"\n\""); else printf("\""); } //printf("\\x%.2X", sc[i]); sprintf(msg, "\\x%.2X", sc[i] & 0xff); for( p = msg, j=0; j < 4; p++, j++ ) { if(isupper(*p)) printf("%c", _tolower(*p)); else printf("%c", p[0]); } } printf("\";\n"); }
/* Callback in xscreensaver_function_table, via xlockmore.c. */ Visual * xlockmore_pick_gl_visual (Screen *screen) { /* pick the "best" visual by interrogating the GL library instead of by asking Xlib. GL knows better. */ Visual *v = 0; Display *dpy = DisplayOfScreen (screen); char *string = get_string_resource (dpy, "visualID", "VisualID"); char *s; if (string) for (s = string; *s; s++) if (isupper (*s)) *s = _tolower (*s); if (!string || !*string || !strcmp (string, "gl") || !strcmp (string, "best") || !strcmp (string, "color") || !strcmp (string, "default")) v = get_gl_visual (screen); /* from ../utils/visual-gl.c */ if (string) free (string); return v; }
Bool get_boolean_resource (char *res_name, char *res_class, Bool default_value) { char *tmp, buf [100]; char *s = get_string_resource (res_name, res_class); char *os = s; if (! s) return default_value; for (tmp = buf; *s; s++) *tmp++ = isupper (*s) ? _tolower (*s) : *s; *tmp = 0; free (os); while (*buf && (buf[strlen(buf)-1] == ' ' || buf[strlen(buf)-1] == '\t')) buf[strlen(buf)-1] = 0; if (!strcmp (buf, "on") || !strcmp (buf, "true") || !strcmp (buf, "yes")) return 1; if (!strcmp (buf,"off") || !strcmp (buf, "false") || !strcmp (buf,"no")) return 0; fprintf (stderr, "%s: %s must be boolean, not %s.\n", progname, res_name, buf); return default_value; }
/* * assume that b is lower case and allow plural */ static int specialcmplowerwiths (char *a,char *b) { register char ca, cb; if (!a || !b) return 0; while (1) { ca = *a; cb = *b; if (isascii(ca) && isupper(ca)) { /* lowercasify */ #ifdef _tolower ca = _tolower (ca); #else ca = tolower (ca); #endif } if (ca != cb || ca == '\0') break; /* if not eq else both nul */ a++, b++; } if (cb == '\0' && (ca == '\0' || (ca == 's' && a[1] == '\0'))) return 1; return 0; }
void ShiftAnd::compile(const String &pattern, bool ignoreCase) { m_patternLen = (int)pattern.length(); if(m_patternLen >= 64) { throwException(_T("<%s> too long for shiftand-search. max length is 63"), pattern.cstr()); } memset(m_mask, -1, sizeof(m_mask)); for(int i = 0; i < m_patternLen; i++) { const _TUCHAR ch = pattern[i]; m_mask[ch] &= ~((UINT64)1 << i); if (ignoreCase) { if (_istlower(ch)) { m_mask[_toupper(ch)] &= ~((UINT64)1 << i); } else if(_istupper(ch)) { m_mask[_tolower(ch)] &= ~((UINT64)1 << i); } } } m_s = (UINT64)1 << m_patternLen; #ifdef _TEST_CLASS for(int i = 0; i < ARRAYSIZE(m_mask); i++) { const UINT64 mask = m_mask[i]; if(mask != -1) { _tprintf(_T("mask[%c]:%s\n"), i, sprintbin(mask).cstr()); } } #endif }
void ToggleCase (CString& str) { if (str.GetLength () == 0) return; MakeUpper (str); bool bNewWord = true; int last = str.GetLength (); /*int ext_pos = str.ReverseFind ('.'); if (ext_pos != -1) last = ext_pos;*/ for (int i = 0; i < last; i++) { if (_istalpha (str[i])) { if (bNewWord) { bNewWord = false; str.SetAt (i, _tolower (str[i])); } } else bNewWord = true; } }
//-------------------------------------------------------------------------------- // print shellcode //-------------------------------------------------------------------------------- void PrintSc(char *lpBuff, int buffsize) { int i,j; char *p; char msg[4]; for(i=0;i<buffsize;i++) { if((i%16)==0) { if(i!=0) printf("\"\n\""); else printf("\""); } sprintf(msg, "\\x%.2X", lpBuff[i] & 0xff); for( p = msg, j=0; j < 4; p++, j++ ) { if(isupper(*p)) printf("%c", _tolower(*p)); else printf("%c", p[0]); } } printf("\";\n"); }
static int parse_button(char *s, int *buttonp) { register char *cp; /* lower case name */ for (cp = s; *cp; cp++) { if (isascii (*cp) && isupper (*cp)) { #ifdef _tolower *cp = _tolower (*cp); #else *cp = tolower (*cp); #endif /* _tolower */ } } if (strcmp (s, "any") == 0) { *buttonp = SelectButtonAny; return (1); } /* check for non-numeric input */ for (cp = s; *cp; cp++) { if (!(isascii (*cp) && isdigit (*cp))) return (0); /* bogus name */ } *buttonp = atoi (s); return (1); }
void lower_case( std::string &str ) { for ( unsigned int i = 0; i<str.length(); i++ ) { if ( str[i] >= 'A' && str[i] <= 'Z' ) { str[i] = _tolower( str[i] ); } } }
static int VMS_get_member_info (struct dsc$descriptor_s *module, unsigned long *rfa) { int status, i; long int fnval; time_t val; static struct dsc$descriptor_s bufdesc = { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL }; struct mhddef *mhd; char filename[128]; bufdesc.dsc$a_pointer = filename; bufdesc.dsc$w_length = sizeof (filename); status = lbr$set_module (&VMS_lib_idx, rfa, &bufdesc, &bufdesc.dsc$w_length, 0); if (! (status & 1)) { error (NILF, _("lbr$set_module failed to extract module info, status = %d"), status); lbr$close (&VMS_lib_idx); return 0; } mhd = (struct mhddef *) filename; #ifdef __DECC /* John Fowler <*****@*****.**> writes this is needed in his environment, * but that decc$fix_time() isn't documented to work this way. Let me * know if this causes problems in other VMS environments. */ val = decc$fix_time (&mhd->mhd$l_datim) + timezone - daylight*3600; #endif for (i = 0; i < module->dsc$w_length; i++) filename[i] = _tolower ((unsigned char)module->dsc$a_pointer[i]); filename[i] = '\0'; VMS_member_date = (time_t) -1; fnval = (*VMS_function) (-1, filename, 0, 0, 0, 0, val, 0, 0, 0, VMS_saved_memname); if (fnval) { VMS_member_date = fnval; return 0; } else return 1; }
/* Parse (scan) a number */ bool parse_num (char *s, unsigned long *val, char **es, char *delim) { bool first = true; int radix = 10; char c; unsigned long result = 0; int digit; while (*s == ' ') s++; while (*s) { if (first && (s[0] == '0') && (_tolower (s[1]) == 'x')) { radix = 16; s += 2; } first = false; c = *s++; if (_is_hex (c) && ((digit = _from_hex (c)) < radix)) { /* Valid digit */ #ifdef CYGPKG_HAL_MIPS /* FIXME: tx49 compiler generates 0x2539018 for MUL which */ /* isn't any good. */ if (16 == radix) result = result << 4; else result = 10 * result; result += digit; #else result = (result * radix) + digit; #endif } else { if (delim != (char *) 0) { /* See if this character is one of the delimiters */ char *dp = delim; while (*dp && (c != *dp)) dp++; if (*dp) break; /* Found a good delimiter */ } return false; /* Malformatted number */ } } *val = result; if (es != (char **) 0) { *es = s; } return true; }
int mdsdcl_set_command( /* Return: status */ struct _mdsdcl_ctrl *ctrl /* <m> the control structure */ ) { int sts; void *newTable; static DYNAMIC_DESCRIPTOR(dsc_table); /*------------------------------------------------------ * Get tablename and find its address in shared library ... *-----------------------------------------------------*/ sts = cli_get_value("TABLE",&dsc_table); if (sts & 1) { int i; for (i=0;i<dsc_table.dscW_length;i++) dsc_table.dscA_pointer[i] = _tolower(dsc_table.dscA_pointer[i]); if (!strstr(dsc_table.dscA_pointer,"_commands")) str_concat(&dsc_table,&dsc_table,"_commands",0); sts = LibFindImageSymbol(&dsc_table,&dsc_table,&newTable); if (~sts & 1) return(MdsMsg(sts,"Failed to open table %s", dsc_table.dscA_pointer)); /*------------------------------------------------------ *... add newTable address to "tbladr[]" list *-----------------------------------------------------*/ for (i=0 ; i<ctrl->tables ; i++) if (newTable == ctrl->tbladr[i]) break; if (i == ctrl->tables) { if (ctrl->tables >= MAX_TABLES) { fprintf(stderr,"set_command: *WARN* Max_tables exceeded\n"); return(0); } ctrl->tbladr[ctrl->tables++] = newTable; } } /*------------------------------------------------------ * Check for other qualifiers ... *-----------------------------------------------------*/ if (cli_present("HELPLIB") & 1) cli_get_value("HELPLIB",&ctrl->helplib); if (cli_present("PROMPT") & 1) cli_get_value("PROMPT",&ctrl->prompt); if (cli_present("DEF_FILE") & 1) cli_get_value("DEF_FILE",&ctrl->def_file); return(1); }
void main(void) { char string [] = "Biblia do Programador C/C++, do Jamsa!"; int i; for (i = 0; string [i]; i++) putchar (tolower (string [i])); putchar ('\n'); for (i = 0; string [i]; i++) putchar (_tolower (string [i])); putchar ('\n'); }
LPTSTR strToLower(LPTSTR dest, LPCTSTR src) { LPTSTR start = dest; while (*dest = *src) { if (_istupper(*dest)) *dest = _tolower(*dest); dest++; src++; } return start; }
int _CType tolower( int ch ) { if( ch == -1 ) return( -1 ); if( isupper( (unsigned char)ch) ) { return( _tolower((unsigned char)ch) ); } else { return( (unsigned char)ch ); } }
struct ether_addr * ether_aton_r (const char *asc, struct ether_addr *addr) { size_t cnt; for (cnt = 0; cnt < 6; ++cnt) { unsigned int number; char ch; ch = _tolower (*asc++); if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f')) return NULL; number = isdigit (ch) ? (ch - '0') : (ch - 'a' + 10); ch = _tolower (*asc); if ((cnt < 5 && ch != ':') || (cnt == 5 && ch != '\0' && !isspace (ch))) { ++asc; if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f')) return NULL; number <<= 4; number += isdigit (ch) ? (ch - '0') : (ch - 'a' + 10); ch = *asc; if (cnt < 5 && ch != ':') return NULL; } /* Store result. */ addr->ether_addr_octet[cnt] = (unsigned char) number; /* Skip ':'. */ ++asc; } return addr; }
bool inet_aton(const char *s, in_addr_t *addr) { int i, val, radix, digit; unsigned long res = 0; bool first; char c; for (i = 0; i < 4; i++) { // Parse next digit string first = true; val = 0; radix = 10; while ((c = *s++) != '\0') { if (first && (c == '0') && (_tolower(*s) == 'x')) { radix = 16; s++; // Skip over 0x c = *s++; } first = false; if (_is_hex(c) && ((digit = _from_hex(c)) < radix)) { // Valid digit val = (val * radix) + digit; } else if (c == '.' && i < 3) { // all but last terminate by '.' break; } else { return false; } } // merge result #ifdef __LITTLE_ENDIAN__ res |= val << ((3-i)*8); // 24, 16, 8, 0 #else res = (res << 8) | val; #endif if ('\0' == c) { if (0 == i) { // first field found end of string res = val; // no shifting, use it as the whole thing break; // permit entering a single number } if (3 > i) // we found end of string before getting 4 fields return false; } // after that we check that it was 0..255 only if (val &~0xff) return false; } addr->s_addr = htonl(res); return true; }
/* Parse (scan) a number */ unsigned int parse_num(char *s, unsigned long *val, char **es, char *delim) { unsigned int first = 1; int radix = 10; char c; unsigned long result = 0; int digit; while(*s == ' ') s++; while(*s){ if(first && (s[0] == '0') && (_tolower(s[1]) == 'x')){ radix = 16; s += 2; } first = 0; c = *s++; if(_is_hex(c) && ((digit = _from_hex(c)) < radix)){ /* Valid digit */ result = (result * radix) + digit; } else { if(delim != (char *)0){ /* See if this character is one of the delimiters */ char *dp = delim; while(*dp && (c != *dp)) dp++; /* Found a good delimiter */ if(*dp) break; } /* Malformatted number */ return 0; } } *val = result; if(es != (char **)0){ *es = s; } return 1; }
/* MAC address string <-> byte array from glibc. */ static uint8_t *ether_aton(char *addr_string, uint8_t * addr_bytes) { size_t cnt; for (cnt = 0; cnt < 6; ++cnt) { unsigned int number; char ch; ch = _tolower(*addr_string++); if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f')) return NULL; number = isdigit(ch) ? (ch - '0') : (ch - 'a' + 10); ch = _tolower(*addr_string); if ((cnt < 5 && ch != ':') || (cnt == 5 && ch != '\0' && !isspace(ch))) { ++addr_string; if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f')) return NULL; number <<= 4; number += isdigit(ch) ? (ch - '0') : (ch - 'a' + 10); ch = *addr_string; if (cnt < 5 && ch != ':') return NULL; } /* Store result. */ addr_bytes[cnt] = (unsigned char)number; /* Skip ':'. */ ++addr_string; } return addr_bytes; }
void title_case( std::string &str ) { bool upper = true; for ( unsigned int i = 0; i<str.length(); i++ ) { if (upper) { if ( str[i] >= 'a' && str[i] <= 'z' ) { str[i] = _toupper( str[i] ); } } else { if ( str[i] >= 'A' && str[i] <= 'Z' ) { str[i] = _tolower( str[i] ); } } upper = isspace(str[i]); } }