Simple utilities sink - stuff that doesn't fit anywhere else / objects in plain C Snapshot
Classes | Typedefs | Functions | Variables
TOKENDEF

take a string and check if it any one in list of tokens. The entry TOKENDEF defines pair of token string and its integer value that identifies the token. Parsing of string is done by comparing the input token in sequence against each entry in the table. Not very fast, but very convenient. More...

Classes

struct  tagTOKENDEF

Typedefs

typedef struct tagTOKENDEF TOKENDEF

Functions

int parse_token (const char *token, TOKENDEF *tkdef)
const char * token_string_for_int (int value, TOKENDEF *tkdef)
char * token_possible_values (TOKENDEF *tkdef)

Variables

const char * tagTOKENDEF::type

Detailed Description

take a string and check if it any one in list of tokens. The entry TOKENDEF defines pair of token string and its integer value that identifies the token. Parsing of string is done by comparing the input token in sequence against each entry in the table. Not very fast, but very convenient.


Typedef Documentation

typedef struct tagTOKENDEF TOKENDEF

Function Documentation

int parse_token ( const char *  token,
TOKENDEF tkdef 
)

Definition at line 5 of file tokparser.c.

{
  int i;
  for(i=0 ; tkdef[i].token_type != -1 ; i++) {
    if ( strcmp(token, tkdef[i].type) == 0 ) {
      return tkdef[i].token_type;
    }
  }
  return -1;
} 
char* token_possible_values ( TOKENDEF tkdef)

Definition at line 16 of file tokparser.c.

{
  int i;
  int len = 0;
  char *ret;

  for(i=0 ; tkdef[i].token_type != -1 ; i++) {
    len += strlen( tkdef[i].type ) + 1;
  }

  ret = (char *) malloc( len + 1 );
  if (!ret) {
    return 0;
  }

  strcpy(ret, "" );

  for(i=0 ; tkdef[i].token_type != -1 ; i++) {
    strcat( ret, tkdef[i].type);
    strcat( ret, " " );
  }

  return ret;
}
const char* token_string_for_int ( int  value,
TOKENDEF tkdef 
)

Definition at line 41 of file tokparser.c.

{
  int i;

  for(i=0 ; tkdef[i].token_type != -1 ; i++) {
    if ( tkdef[i].token_type == value ) {
      return tkdef[i].type;  
    }  
  }
  return "";
}

Variable Documentation

const char* tagTOKENDEF::type

Definition at line 16 of file tokparser.h.