static int match_word_boundary (const char *text, long j) { if ((j == 0) && isalphanum (text[j])) return IMASK_NO_CHAR_MATCH; else if (isalphanum (text[j - 1]) && !isalphanum (text[j])) return IMASK_NO_CHAR_MATCH; else if (isalphanum (text[j]) && !isalphanum (text[j - 1])) return IMASK_NO_CHAR_MATCH; return IMASK_NO_MATCH; }
static int build_token_list_s( char *s, size_t size ) { char curr_char; size_t index; int ident_pos; int current_line; if( !s ) { return -1; } index = 0; curr_char = s[index]; current_line = 1; while( index <= size ) { /* Ident builder */ if( isalpha(curr_char) ) { ident_pos = 0; do { ident_buf[ident_pos] = curr_char; ident_pos++; index++; curr_char = s[index]; } while( index <= size && isalphanum(curr_char) && ident_pos < IDENTBUF_SIZE ); build_token_ident(ident_pos, current_line); continue; } /* Number builder */ else if( isnum(curr_char) || curr_char == '-' ) { ident_pos = 0; do { ident_buf[ident_pos] = curr_char; ident_pos++; index++; curr_char = s[index]; } while( index <= size && isnum(curr_char) && ident_pos < IDENTBUF_SIZE ); build_token_num(ident_pos, current_line); continue; } /* Grab commas */ else if( curr_char == ',' ) { build_token_comma(current_line); } /* Grab semicolons */ else if( curr_char == ':' ) { build_token_colon(current_line); } /* Handle comments */ else if( curr_char == '#' ) { /* Eat everything until EOL */ do { index++; curr_char = s[index]; } while( index <= size && curr_char != '\n' && curr_char != '\r' ); } if( curr_char == '\n' ) { current_line++; } index++; curr_char = s[index]; } return 0; }
int count_word(char *str) { int i; int k; i = 0; k = 0; while (str[i] != '\0') { while (isalphanum(str[i])) i++; if (isalphanum(str[i - 1])) k++; i++; } return (k); }
static int build_token_list_f( FILE *fp ) { int curr_char; int ident_pos; int current_line; if( !fp ) { return -1; } curr_char = get_next_char(fp); current_line = 1; while( curr_char != EOF ) { /* Ident builder */ if( isalpha(curr_char) ) { ident_pos = 0; do { ident_buf[ident_pos] = curr_char; ident_pos++; curr_char = get_next_char(fp); } while( curr_char != EOF && isalphanum(curr_char) && ident_pos < IDENTBUF_SIZE ); build_token_ident(ident_pos, current_line); continue; } /* Number builder */ else if( isnum(curr_char) || curr_char == '-' ) { ident_pos = 0; do { ident_buf[ident_pos] = curr_char; ident_pos++; curr_char = get_next_char(fp); } while( curr_char != EOF && isnum(curr_char) && ident_pos < IDENTBUF_SIZE ); build_token_num(ident_pos, current_line); continue; } /* Grab commas */ else if( curr_char == ',' ) { build_token_comma(current_line); } /* Grab semicolons */ else if( curr_char == ':' ) { build_token_colon(current_line); } /* Handle comments */ else if( curr_char == '#' ) { /* Eat everything until EOL */ do { curr_char = get_next_char(fp); } while( curr_char != EOF && curr_char != '\n' && curr_char != '\r' ); } if( curr_char == '\n' ) { current_line++; } curr_char = get_next_char(fp); } return 0; }
void expand(char s[], char t[]) { int i,j,k, u; i = j = u = 0; while (s[i] != '\0'){ if (i > 0 && s[i] == '-' && s[i-1] != ' ' && s[i+1] != '\0' && isalphanum(s[i-1])){ k = s[i+1]; for (u=1;u<=s[i+1] - s[i-1];u++){ t[j++] = s[i-1] + u; } i++; } else { t[j++] = s[i]; } i++; } t[j] = '\0'; }
static int match_non_alphanum (const char *text, long j) { return (isalphanum (text[j]) || (text[j] == '\0')) ? IMASK_NO_MATCH : IMASK_NORMAL_MATCH; }
static int match_alphanum (const char *text, long j) { return isalphanum (text[j]) ? IMASK_NORMAL_MATCH : IMASK_NO_MATCH; }