int RevStrCmp (const my_string* str1, const my_string* str2)
{
    int index1 = (*str1).len;
    int index2 = (*str2).len;
    char letter1 = (char)(0), letter2 = (char)(0);

    while (index1 >= 0 && index2 >= 0)
    {
        if (my_isalpha ((*str1).str[index1]) && my_isalpha ((*str2).str[index2]))
        {
            letter1 = ToCapitalLetter ((*str1).str[index1]);
            letter2 = ToCapitalLetter ((*str2).str[index2]);
            if (letter1 > letter2) return 1;
            else if (letter1 < letter2) return -1;
                 else index1--, index2--;
        }
        else
        {
            if (!my_isalpha ((*str1).str[index1])) index1--;
            else if (!my_isalpha ((*str2).str[index2])) index2--;
                 else index1--, index2--;
        }

    }
    return 0;
}
int main(){  

    printf("%d\n",my_isdigit_1('8'));
    printf("%d\n",my_isdigit_1('a'));
    printf("%d\n",my_isalpha('8'));
    printf("%d\n",my_isalpha('a'));
    
    return 0;
}
示例#3
0
void soundex(CHARSET_INFO * cs,register char * out_pntr, char * in_pntr,
         pbool remove_garbage)
{
  char ch,last_ch;
  reg3 char * end;
  register uchar *map=cs->to_upper;

  if (remove_garbage)
  {
    while (*in_pntr && !my_isalpha(cs,*in_pntr)) /* Skip pre-space */
      in_pntr++;
  }
  *out_pntr++ = map[(uchar)*in_pntr];	/* Copy first letter		 */
  last_ch = get_scode(cs,&in_pntr,0);	/* code of the first letter	 */
                    /* for the first 'double-letter  */
                    /* check.			 */
  end=out_pntr+3;			/* Loop on input letters until	 */
                    /* end of input (null) or output */
                    /* letter code count = 3	 */

  in_pntr++;
  while (out_pntr < end && (ch = get_scode(cs,&in_pntr,remove_garbage)) != 0)
  {
    in_pntr++;
    if ((ch != '0') && (ch != last_ch)) /* if not skipped or double */
    {
      *out_pntr++ = ch;			/* letter, copy to output */
    }					/* for next double-letter check */
    last_ch = ch;			/* save code of last input letter */
  }
  while (out_pntr < end)
    *out_pntr++ = '0';
  *out_pntr=0;				/* end string */
  return;
} /* soundex */
示例#4
0
static my_bool init_state_maps(CHARSET_INFO *cs)
{
  uint i;
  uchar *state_map;
  uchar *ident_map;

  if (!(cs->state_map= state_map= (uchar*) my_once_alloc(256, MYF(MY_WME))))
    return 1;

  if (!(cs->ident_map= ident_map= (uchar*) my_once_alloc(256, MYF(MY_WME))))
    return 1;

  /* Fill state_map with states to get a faster parser */
  for (i=0; i < 256 ; i++)
  {
    if (my_isalpha(cs,i))
      state_map[i]=(uchar) MY_LEX_IDENT;
    else if (my_isdigit(cs,i))
      state_map[i]=(uchar) MY_LEX_NUMBER_IDENT;
    else if (my_ismb1st(cs, i))
      /* To get whether it's a possible leading byte for a charset. */
      state_map[i]=(uchar) MY_LEX_IDENT;
    else if (my_isspace(cs,i))
      state_map[i]=(uchar) MY_LEX_SKIP;
    else
      state_map[i]=(uchar) MY_LEX_CHAR;
  }
  state_map[(uchar)'_']=state_map[(uchar)'$']=(uchar) MY_LEX_IDENT;
  state_map[(uchar)'\'']=(uchar) MY_LEX_STRING;
  state_map[(uchar)'.']=(uchar) MY_LEX_REAL_OR_POINT;
  state_map[(uchar)'>']=state_map[(uchar)'=']=state_map[(uchar)'!']= (uchar) MY_LEX_CMP_OP;
  state_map[(uchar)'<']= (uchar) MY_LEX_LONG_CMP_OP;
  state_map[(uchar)'&']=state_map[(uchar)'|']=(uchar) MY_LEX_BOOL;
  state_map[(uchar)'#']=(uchar) MY_LEX_COMMENT;
  state_map[(uchar)';']=(uchar) MY_LEX_SEMICOLON;
  state_map[(uchar)':']=(uchar) MY_LEX_SET_VAR;
  state_map[0]=(uchar) MY_LEX_EOL;
  state_map[(uchar)'\\']= (uchar) MY_LEX_ESCAPE;
  state_map[(uchar)'/']= (uchar) MY_LEX_LONG_COMMENT;
  state_map[(uchar)'*']= (uchar) MY_LEX_END_LONG_COMMENT;
  state_map[(uchar)'@']= (uchar) MY_LEX_USER_END;
  state_map[(uchar) '`']= (uchar) MY_LEX_USER_VARIABLE_DELIMITER;
  state_map[(uchar)'"']= (uchar) MY_LEX_STRING_OR_DELIMITER;

  /*
    Create a second map to make it faster to find identifiers
  */
  for (i=0; i < 256 ; i++)
  {
    ident_map[i]= (uchar) (state_map[i] == MY_LEX_IDENT ||
			   state_map[i] == MY_LEX_NUMBER_IDENT);
  }

  /* Special handling of hex and binary strings */
  state_map[(uchar)'x']= state_map[(uchar)'X']= (uchar) MY_LEX_IDENT_OR_HEX;
  state_map[(uchar)'b']= state_map[(uchar)'B']= (uchar) MY_LEX_IDENT_OR_BIN;
  state_map[(uchar)'n']= state_map[(uchar)'N']= (uchar) MY_LEX_IDENT_OR_NCHAR;

  return 0;
}
示例#5
0
文件: reginit.c 项目: 0x00xw/mysql-2
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;
}
示例#6
0
static char get_scode(CHARSET_INFO * cs,char **ptr, pbool remove_garbage)
{
  uchar ch;

  if (remove_garbage)
  {
    while (**ptr && !my_isalpha(cs,**ptr))
      (*ptr)++;
  }
  ch=my_toupper(cs,**ptr);
  if (ch < 'A' || ch > 'Z')
  {
    if (my_isalpha(cs,ch))		/* If extended alfa (country spec) */
      return '0';			/* threat as vokal */
    return 0;				/* Can't map */
  }
  return(soundex_map[ch-'A']);
} /* get_scode */
示例#7
0
int	my_strcmp(char *s1, char *s2)
{
  int	i;
  int	j;

  i = 0;
  j = 0;
  while (my_isalpha(s1[i]) == 0 && s1[i] != '\0')
    ++i;
  while (my_isalpha(s2[j]) == 0 && s2[j] != '\0')
    ++j;
  while (to_lower(s1[i]) == to_lower(s2[j]))
  {
    if (s1[i] == '\0' || s2[j] == '\0')
      return (0);
    ++i;
    ++j;
  }
  return (to_lower(s1[i]) - to_lower(s2[j]));
}
示例#8
0
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;
}
示例#9
0
文件: genramvhd.c 项目: abc4tech/ftm
int main(int argc, char **argv) {
  int j, opt, error, i_width;
  long i, elements, size, columns, entry_width;
  char* value_end;
  unsigned char x[16]; /* Up to 128 bit */
  char buf[100];
  FILE* f;
  
  /* Default values */
  program = argv[0];
  package = 0; /* auto-detect */
  width = 4;
  bigendian = 1;
  verbose = 0;
  size = -1; /* file size */
  
  /* Process the command-line */
  while ((opt = getopt(argc, argv, "w:p:s:blvh")) != -1) {
    switch (opt) {
    case 'w':
      width = strtol(optarg, &value_end, 0);
      if (*value_end             || /* bad integer */
          ((width-1)&width) != 0 || /* not a power of 2 */
          width == 0             ||
          width > 16) {
        fprintf(stderr, "%s: invalid value width -- '%s'\n", program, optarg);
        error = 1;
      }
      break;
    case 'p':
      package = optarg;
      break;
    case 's':
      size = strtol(optarg, &value_end, 0);
      if (*value_end) {
        fprintf(stderr, "%s: invalid value size -- '%s'\n", program, optarg);
        error = 1;
      }
      break;
    case 'b':
      bigendian = 1;
      break;
    case 'l':
      bigendian = 0;
      break;
    case 'v':
      verbose = 1;
      break;
    case 'h':
      help();
      return 1;
    case ':':
    case '?':
      error = 1;
      break;
    default:
      fprintf(stderr, "%s: bad getopt result\n", program);
      return 1;
    }
  }
  
  if (optind + 1 != argc) {
    fprintf(stderr, "%s: expecting one non-optional argument: <filename>\n", program);
    return 1;
  }
  
  filename = argv[optind];
  
  /* Confirm the filename exists */
  if ((f = fopen(filename, "r")) == 0) {
    fprintf(stderr, "%s: %s while opening '%s'\n", program, strerror(errno), filename);
    return 1;
  }
  
  /* Deduce if it's aligned */
  fseek(f, 0, SEEK_END);
  elements = ftell(f);
  rewind(f);
  
  if (size == -1) {
    size = elements;
  }
  
  if (size < elements) {
    fprintf(stderr, "%s: length of initialization file '%s' (%ld) exceeds specified size (%ld)\n", program, filename, elements, size);
    return 1;
  }
  
  if (elements % width != 0) {
    fprintf(stderr, "%s: initialization file '%s' is not a multiple of %ld bytes\n", program, filename, width);
    return 1;
  }
  elements /= width;
  
  if (size % width != 0) {
    fprintf(stderr, "%s: specified size '%ld' is not a multiple of %ld bytes\n", program, size, width);
    return 1;
  }
  size /= width;
  
  /* Find a suitable package name */
  if (package == 0) {
    if (strlen(filename) >= sizeof(buf)-5) {
      fprintf(stderr, "%s: filename too long to deduce package name -- '%s'\n", program, filename);
      return 1;
    }
    
    /* Find the first alpha character */
    while (*filename && !my_isalpha(*filename)) ++filename;
    
    /* Start copying the filename to the package */
    for (i = 0; filename[i]; ++i) {
      if (my_isok(filename[i]))
        buf[i] = filename[i];
      else
        buf[i] = '_';
    }
    buf[i] = 0;
    
    if (i == 0) {
      fprintf(stderr, "%s: no appropriate characters in filename to use for package name -- '%s'\n", program, filename);
      return 1;
    }
    
    package = &buf[0];
  } else {
    /* Check for valid VHDL identifier */
    if (!my_isalpha(package[0])) {
      fprintf(stderr, "%s: invalid package name -- '%s'\n", program, package);
      return 1;
    }
    for (i = 1; package[i]; ++i) {
      if (!my_isok(package[i])) {
        fprintf(stderr, "%s: invalid package name -- '%s'\n", program, package);
        return 1;
      }
    }
  }
  
  /* Find how many digits it takes to fit 'size' */
  i_width = 1;
  for (i = 10; i <= size; i *= 10)
    ++i_width;
    
  /* How wide is an entry of the table? */
  entry_width = i_width + 6 + width*2 + 3;
  columns = 76 / entry_width;
  
  printf("-- AUTOGENERATED FILE (from genramvhd.c run on %s) --\n", argv[1]);
  printf("library IEEE;\n");
  printf("use IEEE.std_logic_1164.all;\n");
  printf("use IEEE.numeric_std.all;\n");
  printf("\n");
  printf("library work;\n");
  printf("use work.memory_loader_pkg.all;\n");
  printf("\n");
  
  printf("package %s_pkg is\n", package);
  printf("  constant %s_init : t_meminit_array(%ld downto 0, %ld downto 0) := (\n", package, size-1, (width*8)-1);
  
  for (i = 0; i < size; ++i) {
    if (i % columns == 0) printf("    ");
    
    if (i < elements) {
      if (fread(x, 1, width, f) != width) {
        perror("fread");
        return 1;
      }
    } else {
      memset(x, 0, sizeof(x));
    }
    
    printf("%*ld => x\"", i_width, i);
    if (bigendian) {
      for (j = 0; j < width; ++j)
        printf("%02x", x[j]);
    } else {
      for (j = width-1; j >= 0; --j)
        printf("%02x", x[j]);
    }
    printf("\"");
    
    if ((i+1) == size) printf(");\n");
    else if ((i+1) % columns == 0) printf(",\n");
    else printf(", ");
  }
  fclose(f);
  
  printf("end %s_pkg;\n", package);

  return 0;
}
示例#10
0
文件: genramvhd.c 项目: abc4tech/ftm
inline int my_isok(char c) {
  return c == '_' || my_isalpha(c) ||
         (c >= '0' && c <= '9');
}
示例#11
0
/***************************************************
  next_token.
  
  Get the next word in the corpus.
  
  Try to copy the next word from the line currently held
  in line_buffer to the outbuffer.
  If lin_buffer doesn't have any more words, 
  invoke next_line to replenish it.

  Arguments:	1 outbuffer	the target buffer
				to copy the next word to
		2 curr_pos	the current file location
				in the corpus (will be recorded
				in the wordlist file at
				document breaks)

  Return Values:	-1 if next_line returns -1 
				(i.e., document break)
			 0 if next_line returns 0 
				(i.e., EOF encountered)
			 1 when returning a word.
			 */
int next_token( char *outbuffer, int *curr_pos) {
  int i;
  int in_word = FALSE;
  int my_isalpha( int c) { return valid_chars[c]; };

  while( !in_word) {
    /* Go to the beginning of the next word. */
    while( (buffer_reader[0] != '\0')  &&
	   !(my_isalpha( (int) *buffer_reader))) {

      if( CORPUS_TYPE == ONE_FILE) {

        /* End of a document; return INT_E_DOC_TAG to indicate this. */
        if( !strncmp( buffer_reader, E_DOC_TAG,
		      strlen(E_DOC_TAG))) {
          buffer_reader += strlen( E_DOC_TAG);
          IntIndoc = FALSE;
          return INT_E_DOC_TAG;
        }
        /* End of text */
        if( !strncmp( buffer_reader, E_TEXT_TAG,
		      strlen(E_TEXT_TAG))) {
          buffer_reader += strlen( E_TEXT_TAG);
          IntIntext = FALSE;
          return INT_E_TEXT_TAG;
        }
        /* Beginning of a document; return INT_B_DOC_TAG to indicate this. */
        if( !strncmp( buffer_reader, B_DOC_TAG,
		      strlen(B_DOC_TAG))) {
          buffer_reader += strlen( B_DOC_TAG);
          IntIndoc = TRUE;
          IntDoccntr++;
          return INT_B_DOC_TAG;
        }
        /* Beginning of text */
        if( !strncmp( buffer_reader, B_TEXT_TAG,
		      strlen(B_TEXT_TAG))) {
          buffer_reader += strlen( B_TEXT_TAG);
          IntIntext = TRUE;
          return INT_B_TEXT_TAG;
        }
      }

      buffer_reader++;

    }

    /* Do we have a word? */
    if( IntIntext && my_isalpha( (int) *buffer_reader)) {
      in_word = TRUE;
    }
    
    /* Otherwise we need to read a fresh line. */
    else {
      /* buffer_reader = linebuffer;*/
      if( !next_line( linebuffer, curr_pos))
	return 0;
      buffer_reader = linebuffer;
    }
  }
    
  /* Copy the next word to the return buffer. */
  for( i=0; my_isalpha( (int) *buffer_reader); buffer_reader++) {
    /* Truncate monster words. */
    if( i >= MAXWORDLEN) {
      outbuffer[MAXWORDLEN] = '\0';
      /*fprintf( stderr, "Word near fpos %d exceeding buffer size;"
	       "truncated:\n%s\n",
	       *curr_pos, outbuffer);*/
      return 1;
    }

    /* Copy along. */
    outbuffer[i++] = tolower( *buffer_reader);
    
    /* Use this to keep word-internal apostrophes. */
    if( buffer_reader[1] == '\'' && my_isalpha( (int) buffer_reader[2])) {
      outbuffer[i++] = '\'';
      buffer_reader++;
    }
  } 
  
  outbuffer[i] = '\0';
  return 1;
}
示例#12
0
function (const char *nptr,char **endptr,int base)
{
  int negative;
  register ulongtype cutoff;
  register unsigned int cutlim;
  register ulongtype i;
  register const char *s;
  register uchar c;
  const char *save;
  int overflow;

  if (base < 0 || base == 1 || base > 36)
    base = 10;

  s = nptr;

  /* Skip white space.	*/
  while (my_isspace(&my_charset_latin1, *s))
    ++s;
  if (*s == '\0')
  {
    goto noconv;
  }

  /* Check for a sign.	*/
  negative= 0;
  if (*s == '-')
  {
    negative = 1;
    ++s;
  }
  else if (*s == '+')
  {
    ++s;
  }
    

  if (base == 16 && s[0] == '0' && my_toupper (&my_charset_latin1, s[1]) == 'X')
    s += 2;

  /* If BASE is zero, figure it out ourselves.	*/
  if (base == 0)
  {
    if (*s == '0')
    {
      if (my_toupper (&my_charset_latin1, s[1]) == 'X')
      {
	s += 2;
	base = 16;
      }
      else
	base = 8;
    }
    else
      base = 10;
  }

  /* Save the pointer so we can check later if anything happened.  */
  save = s;

  cutoff = UTYPE_MAX / (unsigned long int) base;
  cutlim = (uint) (UTYPE_MAX % (unsigned long int) base);

  overflow = 0;
  i = 0;
  for (c = *s; c != '\0'; c = *++s)
  {
    if (my_isdigit (&my_charset_latin1, c))
      c -= '0';
    else if (my_isalpha (&my_charset_latin1, c))
      c = my_toupper (&my_charset_latin1, c) - 'A' + 10;
    else
      break;
    if (c >= base)
      break;
    /* Check for overflow.  */
    if (i > cutoff || (i == cutoff && c > cutlim))
      overflow = 1;
    else
    {
      i *= (ulongtype) base;
      i += c;
    }
  }

  /* Check if anything actually happened.  */
  if (s == save)
    goto noconv;

  /* Store in ENDPTR the address of one character
     past the last character we converted.  */
  if (endptr != NULL)
    *endptr = (char *) s;

#ifndef USE_UNSIGNED
  /* Check for a value that is within the range of
     `unsigned long int', but outside the range of `long int'.	*/
  if (negative)
  {
    if (i  > (ulongtype) TYPE_MIN)
      overflow = 1;
  }
  else if (i > (ulongtype) TYPE_MAX)
    overflow = 1;
#endif

  if (overflow)
  {
    my_errno=ERANGE;
#ifdef USE_UNSIGNED
    return UTYPE_MAX;
#else
    return negative ? TYPE_MIN : TYPE_MAX;
#endif
  }

  /* Return the result of the appropriate sign.  */
  return (negative ? -((longtype) i) : (longtype) i);

noconv:
  /* There was no number to convert.  */
  my_errno=EDOM;
  if (endptr != NULL)
    *endptr = (char *) nptr;
  return 0L;
}