void my_regex_init(CHARSET_INFO *cs, my_regex_stack_check_t func) { char buff[CCLASS_LAST][256]; int count[CCLASS_LAST]; uint i; if (!regex_inited) { regex_inited=1; my_regex_enough_mem_in_stack= func; bzero((uchar*) &count,sizeof(count)); for (i=1 ; i<= 255; i++) { if (my_isalnum(cs,i)) buff[CCLASS_ALNUM][count[CCLASS_ALNUM]++]=(char) i; if (my_isalpha(cs,i)) buff[CCLASS_ALPHA][count[CCLASS_ALPHA]++]=(char) i; if (my_iscntrl(cs,i)) buff[CCLASS_CNTRL][count[CCLASS_CNTRL]++]=(char) i; if (my_isdigit(cs,i)) buff[CCLASS_DIGIT][count[CCLASS_DIGIT]++]=(char) i; if (my_isgraph(cs,i)) buff[CCLASS_GRAPH][count[CCLASS_GRAPH]++]=(char) i; if (my_islower(cs,i)) buff[CCLASS_LOWER][count[CCLASS_LOWER]++]=(char) i; if (my_isprint(cs,i)) buff[CCLASS_PRINT][count[CCLASS_PRINT]++]=(char) i; if (my_ispunct(cs,i)) buff[CCLASS_PUNCT][count[CCLASS_PUNCT]++]=(char) i; if (my_isspace(cs,i)) buff[CCLASS_SPACE][count[CCLASS_SPACE]++]=(char) i; if (my_isupper(cs,i)) buff[CCLASS_UPPER][count[CCLASS_UPPER]++]=(char) i; if (my_isxdigit(cs,i)) buff[CCLASS_XDIGIT][count[CCLASS_XDIGIT]++]=(char) i; } buff[CCLASS_BLANK][0]=' '; buff[CCLASS_BLANK][1]='\t'; count[CCLASS_BLANK]=2; for (i=0; i < CCLASS_LAST ; i++) { char *tmp=(char*) malloc(count[i]+1); if (!tmp) { /* This is very unlikely to happen as this function is called once at program startup */ fprintf(stderr, "Fatal error: Can't allocate memory in regex_init\n"); exit(1); } memcpy(tmp,buff[i],count[i]*sizeof(char)); tmp[count[i]]=0; cclasses[i].chars=tmp; } } return; }
static int my_atoi(char *s) { int n=0; while (*s == ' ' || *s == '\t') s++; while (my_isalnum(*s)) n = n * 10 + (*s++ - '0'); return n; }
my_bool ft_boolean_check_syntax_string(const uchar *str) { uint i, j; if (!str || (strlen((char*) str)+1 != sizeof(DEFAULT_FTB_SYNTAX)) || (str[0] != ' ' && str[1] != ' ')) return 1; for (i=0; i<sizeof(DEFAULT_FTB_SYNTAX); i++) { /* limiting to 7-bit ascii only */ if ((unsigned char)(str[i]) > 127 || my_isalnum(default_charset_info, str[i])) return 1; for (j=0; j<i; j++) if (str[i] == str[j] && (i != 11 || j != 10)) return 1; } return 0; }
static unsigned long my_atou_x(char *s) { unsigned radix=10, c; unsigned long n=0; while (*s == ' ' || *s == '\t') s++; if (s[0] == '0' && s[1] == 'x') { radix = 16; s += 2; } while (my_isalnum(*s)) { c = my_tolower(*s); s++; if (my_isdigit(c)) c=c-'0'; else c=c-'A'+10; if (c >= radix) break; n = n * radix + c; } return n; }
int main() { char givenCharacter; char option; do { /* Read a character from user */ printf("Enter a character: "); scanf("\n%c", &givenCharacter); /* Test for int my_isalpha(int var) function by passing givenCharacter */ my_isalpha(givenCharacter) ? printf("my_isalpha: Success\n"):printf("my_isalpha: Failed\n"); /* Test for int my_isalnum(int var) function by passing givenCharacter */ my_isalnum(givenCharacter) ? printf("my_isalnum: Success\n"):printf("my_isalnum: Failed\n"); /* Test for int my_isxdigit(int var) function by passing givenCharacter */ my_isdigit(givenCharacter) ? printf("my_isdigit: Success\n"):printf("my_isdigit: Failed\n"); /* Test for int my_iscntrl(int var) function by passing givenCharacter */ my_iscntrl(givenCharacter) ? printf("my_iscntrl: Success\n"):printf("my_iscntrl: Failed\n"); /* Prompt for Continue option */ printf("Continue (y/n): "); scanf("\n%c", &option); if ( option == 'y' ) { continue; } else { break; } } while (1); return 0; }