Back to index

im-sdk  12.3.91
Classes | Defines | Typedefs | Functions | Variables
txt2bin.c File Reference
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "codetable.h"
#include "ctfile.h"
#include "encode.h"

Go to the source code of this file.

Classes

struct  _dynNode
struct  _str_int

Defines

#define MAX_LINE_LEN   256

Typedefs

typedef struct _dynNode dynNode
typedef struct _str_int string_value_pair

Functions

int str2val (string_value_pair *str_val, char *str)
char * val2str (string_value_pair *str_val, int value)
char * skip_space (char *s)
char * to_space (char *s)
int convert_octnum (buf)
static void Warning (char *str)
static void Error (char *str)
static dynNodeNewNode (unsigned char key, dynNode *son, dynNode *next)
static void InsertNode (char *kptr, char *hzptr)
static int Linearize (unsigned int idxNode, dynNode *tablenode)
static void BuildTableNode ()
void PrintNodeList ()
void PrintNode (dynNode *tptr)
void PrintTableInfo ()
static void InitTable ()
static void ReadInput (FILE *ifile)
void Output (FILE *ofile)
int main (int argc, argv)

Variables

static dynNode rootNode
static dynNoderoot = &rootNode
CodeTableStruct hzCodeTable
tableNodenodeList
unsigned char * hzList
unsigned int pNodeList
unsigned int pHZList
static int totalHZbytes = 0
static int totalTableNode = 1
int lineno = 0
unsigned int clen = 0
char comment [MAX_COMMENT_LEN]
keyPrompt keyprompt [MAX_USEDCODES_NUM]
functionKey functionkey [MAX_FUNCTIONKEY_NUM]
string_value_pair selectkeymode_str_val []

Class Documentation

struct _dynNode

Definition at line 51 of file txt2bin.c.

Collaboration diagram for _dynNode:
Class Members
char * hzptr
unsigned char key
int keycode
int modifier
struct _dynNode * next
struct _dynNode * son
struct _str_int

Definition at line 64 of file bin2txt.c.

Class Members
char * string
int value

Define Documentation

#define MAX_LINE_LEN   256

Definition at line 51 of file txt2bin.c.


Typedef Documentation

typedef struct _dynNode dynNode
typedef struct _str_int string_value_pair

Function Documentation

static void BuildTableNode ( ) [static]

Definition at line 345 of file txt2bin.c.

{
  nodeList = (tableNode *) calloc (totalTableNode, sizeof(tableNode));
  hzList = (unsigned char *) malloc (totalHZbytes);
  if ((! hzList) || (! nodeList)) {
    perror ("BuildTableNode");
    exit (1);
  }

  pNodeList = 1;     /* 0 is the root, start from index 1 */
  pHZList = 0;

  (void) Linearize(0, root);
  nodeList[0].num_HZchoice = 0;    /* no choice for the upmost node */
  nodeList[0].pos_HZidx = 0;

  /* ASSERT: pNodeList = totalTableNode, pHZList = totalHZbytes/2 */
  hzCodeTable.sizeNodeList = pNodeList;
  hzCodeTable.sizeHZList = pHZList;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int convert_octnum ( buf  )

Definition at line 141 of file txt2bin.c.

{
  register char *p1 = buf, *p2 = buf;
  int bCtrlStatus = 0;

  while (*p1) {
    if (isspace(*p1) || (*p1&0x80)) {   
      p1++;
      continue;
    }
    if (*p1 == '^') {
      bCtrlStatus = 1;
      p1++;
      continue;
    }
    if (bCtrlStatus) {
      /*
       printf("Ctrl: %c, upper(%c): %c, 0x%x, 0x%x\n",
       *p1, *p1, toupper(*p1),
       toupper(*p1), toupper(*p1)|0x80); 
      */
      if (*p1 >= 'a' && *p1 <= 'z') {
       *p2++ = toupper(*p1) | 0x80;
      } else if (*p1 >= 'A' && *p1 <= 'Z') {
       *p2++ = *p1 | 0x80;
      } else if (index(",/;'[]-=", *p1)) {
       *p2++ = *p1 | 0x80;
      } else if (*p1 == '?') {
       *p2++ = '/' | 0x80;
      } else if (*p1 == '<') {
       *p2++ = ',' | 0x80;
      } else if (*p1 == '>') {
       *p2++ = '.' | 0x80;
      } else if (*p1 == ':') {
       *p2++ = ';' | 0x80;
      }

      p1++;
      bCtrlStatus = 0;
      continue;
    }
    *p2++ = *p1++;
  }
  *p2 = '\0';

  return(0);
}
static void Error ( char *  str) [static]

Definition at line 196 of file txt2bin.c.

{
  fprintf (stderr, "%s (at line %d)\n", str, lineno);
  exit (1);
}

Here is the caller graph for this function:

static void InitTable ( ) [static]
static void InsertNode ( char *  kptr,
char *  hzptr 
) [static]

Definition at line 224 of file txt2bin.c.

{
  register dynNode *tptr = root;

  while (*kptr) {
    unsigned char key = *kptr++;

    if (tptr->son == NULL) {
      tptr->son = NewNode(key, (dynNode *)NULL, (dynNode *)NULL);
      tptr = tptr->son;
    } else if (tptr->son->key > key) {
      /* new key should be the 1st son, the old one becomes the next */
      tptr->son = NewNode(key, (dynNode *)NULL, tptr->son);
      tptr = tptr->son;
    } else if (tptr->son->key == key) {
      tptr = tptr->son;
    } else {
      /* ASSERT: (tptr->son->key < key) */
      tptr = tptr->son;
      while ((tptr->next != NULL) && (tptr->next->key < key)) {
       tptr = tptr->next;   /* try next */
      }
      /* ASSERT: (tptr->next == NULL) || (tptr->next->key >= key) */
      if ((tptr->next == NULL) || (tptr->next->key > key)) {
       /* add it here (to keep it sorted) */
       tptr->next = NewNode(key, (dynNode *)NULL, tptr->next);
       tptr = tptr->next;
      } else {       /* tptr->next->key == key */
       tptr = tptr->next;
      }
    }
  }

  /* come to the end of the key string kptr */

  if (tptr->son == NULL) {
    tptr->son = NewNode ('\0', (dynNode *)NULL, (dynNode *)NULL);
    tptr->son->hzptr = (char *)malloc (strlen (hzptr) + 1);
    if (tptr->son->hzptr == NULL)
      Error ("Run out of memory");
    strcpy (tptr->son->hzptr, hzptr);
  } else if (tptr->son->key != '\0') {
    /* new key should be the 1st son, the old one becomes the next */
    tptr->son = NewNode('\0', (dynNode *)NULL, tptr->son);
    tptr->son->hzptr = (char *)malloc (strlen (hzptr) + 1);
    if (tptr->son->hzptr == NULL)
      Error ("Run out of memory");
    strcpy (tptr->son->hzptr, hzptr);
  } else {
    tptr->son->hzptr = (char *)realloc (tptr->son->hzptr,
                                   strlen (tptr->son->hzptr) + strlen (hzptr) + 1);
    if (tptr->son->hzptr == NULL)
      Error ("Run out of memory");
    strcat (tptr->son->hzptr, hzptr);
  }
  totalHZbytes += strlen (hzptr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int Linearize ( unsigned int  idxNode,
dynNode tablenode 
) [static]

Definition at line 288 of file txt2bin.c.

{
  register dynNode *tptr = tablenode->son;
  register unsigned int i, hzlen;
  dynNode *tptr2;
  unsigned int bNodeList = pNodeList;
  unsigned int bHZList = pHZList;
  int numChoice = 0;

  /* if leaf node */
  if (tptr->key == '\0') {
    char *hzptr = tptr->hzptr;

    while (*hzptr) {
      if (*hzptr != HZ_PHRASE_TAG) {
       /* a single character */
       hzlen = get_char_len_by_encodeid(hzCodeTable.Encode, hzptr);
      } else {
       /* a phrase:  "PHRASE flag" | length | Phrase String */
       hzlen = *(hzptr+1) + 2;
      }
      for (i = 0; i < hzlen; i++) {
       hzList[pHZList++] = *hzptr++;
      }

      numChoice ++ ;
    }
    tptr = tptr->next;
  }

  tptr2 = tptr;      /* save for second pass */
  while (tptr) {
    nodeList[ pNodeList++ ].key = tptr->key;
    tptr = tptr->next;
  }

  nodeList[ idxNode ].pos_NextKey = bNodeList;
  nodeList[ idxNode ].num_NextKeys = pNodeList - bNodeList;
  nodeList[ idxNode ].pos_HZidx = bHZList;
  nodeList[ idxNode ].num_HZchoice = numChoice;

  /* linearize every sibling node */
  for (tptr = tptr2, i = bNodeList; tptr; i++, tptr = tptr->next) {
    numChoice += Linearize (i, tptr); 
  }

  /*
    printf("%c === num:%d\n", tptr2->key ,numChoice);
  */
  return (numChoice);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
argv   
)

Definition at line 986 of file txt2bin.c.

{
  FILE *ifile, *ofile;
  char *inputfile_name = "wbtest.txt";
  char *outputfile_name = "test.data";

  if (argc != 3)
    {
      printf("%s inputfile outputfile\n", argv[0]);
      exit(0);
    }

  inputfile_name = argv[1];
  outputfile_name = argv[2];

  /*
    printf("inputfile:%s, outputfile:%s\n",inputfile_name, outputfile_name);
  */

  ifile = fopen(inputfile_name, "r");
  if (! ifile) 
    {
      perror(inputfile_name);
      exit(1);
    }

  ofile = fopen(outputfile_name, "w+");
  if (! ofile) 
    {
      fclose(ifile);
      exit(1);
    }

  InitTable();

  ReadInput(ifile);
  fclose(ifile);

  /*
    PrintNode(root);
  */
  BuildTableNode();
  /*
    PrintTableInfo();
    PrintNodeList();
  */
  Output(ofile);
  fclose(ofile);

  exit(0);
}

Here is the call graph for this function:

static dynNode* NewNode ( unsigned char  key,
dynNode son,
dynNode next 
) [static]

Definition at line 203 of file txt2bin.c.

{
  register dynNode *t = (dynNode *) malloc (sizeof(dynNode));

  if (t == NULL)
    Error ("Run out of memory");
  t->hzptr = NULL;
  t->key = key;
  t->son = son;
  t->next = next;
  if (key)
    totalTableNode++ ;
  return (t);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Output ( FILE *  ofile)

Definition at line 913 of file txt2bin.c.

{
  int ver = CODETABLE_VERSION;

  /* write CodeTable File Flag */
  fwrite (CODETABLE_FLAG, strlen(CODETABLE_FLAG), 1, ofile);     

  /* write CodeTable Version Flag */
  fwrite((char *)(&ver), sizeof(int), 1, ofile); 

  /* write CodeTable Header Structure */
  if ((fwrite(&hzCodeTable, sizeof(CodeTableStruct), 1, ofile)) == 0)
    {
      perror ("Writing output file");
      exit (1);
    }

  /* write CodeTable Node List */
  if ((fwrite(nodeList, sizeof(tableNode), hzCodeTable.sizeNodeList, ofile))
      != hzCodeTable.sizeNodeList) 
    {
      perror ("Writing output file");
      exit (1);
    }

  /* write CodeTable HanZi List */
  if ((fwrite(hzList, sizeof(unsigned char), hzCodeTable.sizeHZList, ofile))
      != hzCodeTable.sizeHZList)
    {
      perror ("Writing output file");
      exit (1);
    }

  /* if [Key_Prompt] section exist, write CodeTable Key Prompt List */
  if (GETBIT(hzCodeTable.bSectionsFlag, KEYPROMPT_SECTION))
    {
      if ((fwrite(&(keyprompt[0]), MAX_USEDCODES_NUM, sizeof(keyPrompt), ofile))
         != sizeof(keyPrompt))
       {
         perror ("Writing output file");
         exit (1);
       }
    }

  /* if [Function_Key] section exist, write CodeTable Function Key List */
  if (GETBIT(hzCodeTable.bSectionsFlag, FUNCTIONKEY_SECTION))
    {
      if ((fwrite(&(functionkey[0]),MAX_FUNCTIONKEY_NUM,sizeof(functionKey), ofile))
         != sizeof(functionKey))
       {
         perror ("Writing output file");
         exit (1);
       }
    }
              
  /* if [Comment] section exist, write CodeTable Comment List */
  if (GETBIT(hzCodeTable.bSectionsFlag, COMMENT_SECTION))
    {
      if ((fwrite((char *)(&clen), sizeof(unsigned int), 1, ofile)) == 0) 
       {
         perror ("Writing output file");
         exit (1);
       }

      if ((fwrite(comment, 1, clen, ofile)) != clen)
       {
         perror ("Writing output file");
         exit (1);
       }
    }
}
void PrintNode ( dynNode tptr)

Definition at line 382 of file txt2bin.c.

{
  if (tptr == NULL) return;

  if (tptr->key != '\0')
    printf("%c", tptr->key);

  if (tptr->hzptr)
    printf("%s=\n", tptr->hzptr);

  PrintNode(tptr->son);
  PrintNode(tptr->next);
  printf("\n");

}

Here is the call graph for this function:

void PrintNodeList ( )

Definition at line 366 of file txt2bin.c.

{
  int i;

  for (i=0; i<totalTableNode; i++)
    {
      printf("id :%d\n", i);
      printf("key: %c\n", nodeList[i].key);
      printf("num_NextKeys: %d\n", nodeList[i].num_NextKeys);
      printf("num_HZchoice: %d\n", nodeList[i].num_HZchoice);
      printf("pos_NextKey: %d\n", nodeList[i].pos_NextKey);
      printf("pos_HZidx: %d\n", nodeList[i].pos_HZidx);
      printf("\n");
    }
}
void PrintTableInfo ( )

Definition at line 399 of file txt2bin.c.

{
  int i;

  printf("Lname:%s\n", hzCodeTable.Lname);
  printf("Cname:%s\n", hzCodeTable.Cname);
  printf("WildChar:%s\n", hzCodeTable.WildChar);
  printf("UsedCodes:%s\n", hzCodeTable.UsedCodes);
  printf("MaxCodes:%d\n", hzCodeTable.MaxCodes);
  printf("Encode:%d\n", hzCodeTable.Encode);
  printf("sizeNodeList:%d\n", hzCodeTable.sizeNodeList);
  printf("sizeHZList:%d\n", hzCodeTable.sizeHZList);

  printf("key_prompt\n");
  for (i=0; i<MAX_USEDCODES_NUM; i++)
    {
      if (keyprompt[i].prompt[0])
       printf("%c:  %s\n", i, keyprompt[i].prompt);
    }

  printf("function_key\n");
  for (i=0; i<MAX_FUNCTIONKEY_NUM; i++)
    {
      if (functionkey[i].keylist[0])
       printf("%d:  %d\n", i, functionkey[i].keylist[0]);
    }
  comment[clen] = '\0';
  printf("comment is \n%s\n", comment);
}
static void ReadInput ( FILE *  ifile) [static]

Definition at line 456 of file txt2bin.c.

{

  char line_buf[256], line[MAX_LINE_LEN];
  char keybuf[MAX_LINE_LEN], valuebuf[MAX_LINE_LEN];
  char *key, *value_str, *kptr, *sptr, *vptr;
  register char *ptr;
  int  endofstr, ret, len, line_index;

  int flag_section = DEFAULT_SECTION;

  while(fgets(line_buf, 255, ifile) != NULL) {

    lineno++;

    if((line_buf[0] == '#') && (line_buf[1] == '#')){
      /*
       printf("COMMENTS \n");
      */
      continue;
    }

    value_str = line_buf;
    ptr = skip_space(value_str);

    if (*ptr == '\0') break;

    /* if is space line, get new line */
    if (flag_section != COMMENT_SECTION) {
      if (*ptr == '\n')
       continue;
    }

    line_index = 0;
    while(*ptr != '\n' && *ptr != '\0' && line_index < MAX_LINE_LEN) 
      line[line_index++] = *ptr++;

    /* trim right space */
    while (line_index > 0 && isspace(line[line_index-1])) line_index--;
    line[line_index] = '\0';

    key = line;
    len = strlen(line);
    /*
      printf("len:%d, %s\n", strlen(line), line);
    */
    if (line[0] == '[' && line[len-1] == ']') {

      /* get section name of the item */
      ptr = line + 1;
      while(isspace(*ptr)) ptr++;
      key = ptr;

      ptr = line + len - 2;
      while(isspace(*ptr)) ptr--;
      *(ptr+1) = '\0';

      if (!*key) continue;

      if (!(strncasecmp(key, DESCRIPTION_STR, strlen(DESCRIPTION_STR)))) {

       flag_section = DESCRIPTION_SECTION;
       continue;

      } else if (!(strncasecmp(key, COMMENT_STR, strlen(COMMENT_STR)))) {

       BITSET(hzCodeTable.bSectionsFlag , COMMENT_SECTION);
       flag_section = COMMENT_SECTION;
       continue;

      } else if (!(strncasecmp(key, KEYPROMPT_STR, strlen(KEYPROMPT_STR)))) {

       BITSET(hzCodeTable.bSectionsFlag , KEYPROMPT_SECTION);
       flag_section = KEYPROMPT_SECTION;
       continue;

      } else if (!(strncasecmp(key, FUNCTIONKEY_STR, strlen(FUNCTIONKEY_STR)))) {
       
       BITSET(hzCodeTable.bSectionsFlag , FUNCTIONKEY_SECTION);
       flag_section = FUNCTIONKEY_SECTION;
       continue;

      } else if (!(strncasecmp(key, PHRASE_STR, strlen(PHRASE_STR)))) {

       BITSET(hzCodeTable.bSectionsFlag , PHRASE_SECTION);
       flag_section = PHRASE_SECTION;
       continue;

      } else if (!(strncasecmp(key, SINGLE_STR, strlen(SINGLE_STR)))) {

       BITSET(hzCodeTable.bSectionsFlag , SINGLE_SECTION);
       flag_section = SINGLE_SECTION;
       continue;

      }
      else if (!(strncasecmp(key, OPTIONS_STR, strlen(OPTIONS_STR)))) {

       BITSET(hzCodeTable.bSectionsFlag , OPTIONS_SECTION);
       flag_section = OPTIONS_SECTION;
       continue;

      }
    }

    switch (flag_section) {
              
    case DEFAULT_SECTION:
      break;

    case DESCRIPTION_SECTION:
      if (!(strncasecmp(key, LOCALE_STR, strlen(LOCALE_STR)))) {
       value_str = skip_space(key+strlen(LOCALE_STR));
       if ((*value_str == '\0') || (*value_str == '\n'))
         continue;

       strcpy(hzCodeTable.Lname, value_str);
       break;
      }

      if (!(strncasecmp(key, NAME_STR, strlen(NAME_STR)))) {
       value_str = skip_space(key+strlen(NAME_STR));
       if ((*value_str == '\0') || (*value_str == '\n'))
         continue;

       strcpy(hzCodeTable.Cname, value_str);
       break;
      }

      if (!(strncasecmp(key, ENCODE_STR, strlen(ENCODE_STR)))) {
       value_str = skip_space(key+strlen(ENCODE_STR));
       if ((*value_str == '\0') || (*value_str == '\n'))
         continue;

       hzCodeTable.Encode = get_encodeid_from_name(value_str);
       hzCodeTable.Output_Encode = hzCodeTable.Encode;
       break;
      }

      if (!(strncasecmp(key, USEDCODES_STR, strlen(USEDCODES_STR)))) {
       value_str = skip_space(key+strlen(USEDCODES_STR));
       if ((*value_str == '\0') || (*value_str == '\n'))
         continue;

       strncpy(hzCodeTable.UsedCodes, value_str, MAX_USEDCODES_NUM);
       break;
      }

      if (!(strncasecmp(key, WILDCHAR_STR, strlen(WILDCHAR_STR)))) {
       value_str = skip_space(key+strlen(WILDCHAR_STR));
       if ((*value_str == '\0') || (*value_str == '\n'))
         continue;

       strncpy(hzCodeTable.WildChar, value_str, MAX_WILDCHAR_NUM);
       break;
      }

      if (!(strncasecmp(key, MAXCODES_STR, strlen(MAXCODES_STR)))) {
       value_str = skip_space(key+strlen(MAXCODES_STR));
       if ((*value_str == '\0') || (*value_str == '\n'))
         continue;

       hzCodeTable.MaxCodes = atoi(value_str) & 0xff;
       break;
      }

      break;

    case OPTIONS_SECTION:
      /*
       printf("Options Section ====\n");
       printf("OPTION_OPEN_STR:%s\n", OPTION_OPEN_STR);
      */

      if (!(strncasecmp(key,KEYBYKEY_MODE_STR,strlen(KEYBYKEY_MODE_STR)))){
       value_str = skip_space(key+strlen(KEYBYKEY_MODE_STR));
       if ((*value_str == '\0') || (*value_str == '\n'))
         continue;
       /*
         printf("keybykey: %s\n", value_str);
       */
       if (!(strncasecmp(value_str,OPTION_OPEN_STR, strlen(OPTION_OPEN_STR))))
         hzCodeTable.nKeyByKeyMode = ON_MODE;
       else 
         hzCodeTable.nKeyByKeyMode = OFF_MODE;
       break;
      }

      if (!(strncasecmp(key,HELPINFO_MODE_STR,strlen(HELPINFO_MODE_STR)))){
       value_str = skip_space(key+strlen(HELPINFO_MODE_STR));
       if ((*value_str == '\0') || (*value_str == '\n'))
         continue;
       /*
         printf("HelpInfo: %s\n", value_str);
       */
       if (!(strncasecmp(value_str,OPTION_OPEN_STR, strlen(OPTION_OPEN_STR))))
         hzCodeTable.nHelpInfoMode = ON_MODE;
       else 
         hzCodeTable.nHelpInfoMode = OFF_MODE;
       break;
      }

      if (!(strncasecmp(key,AUTOSELECT_MODE_STR,strlen(AUTOSELECT_MODE_STR)))){
       value_str = skip_space(key+strlen(AUTOSELECT_MODE_STR));
       if ((*value_str == '\0') || (*value_str == '\n'))
         continue;
       /*
         printf("AutoSelect: %s\n", value_str);
       */
       if (!(strncasecmp(value_str,OPTION_OPEN_STR, strlen(OPTION_OPEN_STR))))
         hzCodeTable.nAutoSelectMode = ON_MODE;
       else 
         hzCodeTable.nAutoSelectMode = OFF_MODE;
       break;
      }

      if (!(strncasecmp(key,KEYPROMPT_MODE_STR,strlen(KEYPROMPT_MODE_STR)))){
       value_str = skip_space(key+strlen(KEYPROMPT_MODE_STR));
       if ((*value_str == '\0') || (*value_str == '\n'))
         continue;
       /*
         printf("KeyPromptMode: %s\n", value_str);
       */
       if (!(strncasecmp(value_str,OPTION_OPEN_STR, strlen(OPTION_OPEN_STR))))
         hzCodeTable.nKeyPromptMode = ON_MODE;
       else 
         hzCodeTable.nKeyPromptMode = OFF_MODE;
       break;
      }

      if (!(strncasecmp(key,DISPLAYONSPOT_MODE_STR,strlen(DISPLAYONSPOT_MODE_STR)))){
       value_str = skip_space(key+strlen(DISPLAYONSPOT_MODE_STR));
       if ((*value_str == '\0') || (*value_str == '\n'))
         continue;
       /*
         printf("DisplayOnSpotMode: %s\n", value_str);
       */
       if (!(strncasecmp(value_str,OPTION_OPEN_STR, strlen(OPTION_OPEN_STR))))
         hzCodeTable.nDisplayOnSpotMode = ON_MODE;
       else 
         hzCodeTable.nDisplayOnSpotMode = OFF_MODE;
       break;
      }

      if (!(strncasecmp(key,SELECTKEY_MODE_STR,strlen(SELECTKEY_MODE_STR)))){
       value_str = skip_space(key+strlen(SELECTKEY_MODE_STR));
       if ((*value_str == '\0') || (*value_str == '\n'))
         continue;
       /*
         printf("SelectKeyMode: %s\n", value_str);
       */
       hzCodeTable.nSelectKeyMode = str2val(selectkeymode_str_val, value_str);
       break;
      }

      break;

    case COMMENT_SECTION:
      ptr = line_buf;
      while (*ptr && clen < MAX_COMMENT_LEN)
       comment[clen++] = *ptr++;
      break;
              
    case FUNCTIONKEY_SECTION:
      if (!(strncasecmp(key,PAGEUP_KEY_STR,strlen(PAGEUP_KEY_STR)))){
       value_str = skip_space(key+strlen(PAGEUP_KEY_STR));
       if ((*value_str == '\0') || (*value_str == '\n'))
         continue;

       /*
         printf("pageup: %s\n", value_str);
       */
       ret = convert_octnum(value_str);
       if (ret == -1)
         Error("FunctionKey Error Defination");

       strncpy(functionkey[PAGEUP_KEY_ID].keylist, value_str, MAX_FUNCTIONKEY_LEN);
       break;
      }

      if (!(strncasecmp(key,PAGEDOWN_KEY_STR,strlen(PAGEDOWN_KEY_STR)))){
       value_str = skip_space(key+strlen(PAGEDOWN_KEY_STR));
       if ((*value_str == '\0') || (*value_str == '\n'))
         continue;

       /*
         printf("pagedown: %s\n", value_str);
       */
       ret = convert_octnum(value_str);
       if (ret == -1)
         Error("FunctionKey Error Defination");

       strncpy(functionkey[PAGEDOWN_KEY_ID].keylist, value_str, MAX_FUNCTIONKEY_LEN);
      }

      if (!(strncasecmp(key,BACKSPACE_KEY_STR,strlen(BACKSPACE_KEY_STR)))){
       value_str = skip_space(key+strlen(BACKSPACE_KEY_STR));
       if ((*value_str == '\0') || (*value_str == '\n'))
         continue;

       /*
         printf("backspace: %s\n", value_str);
       */
       ret = convert_octnum(value_str);
       if (ret == -1)
         Error("FunctionKey Error Defination");

       strncpy(functionkey[BACKSPACE_KEY_ID].keylist, value_str, MAX_FUNCTIONKEY_LEN);
       break;
      }
                     
      if (!(strncasecmp(key,CLEARALL_KEY_STR,strlen(CLEARALL_KEY_STR)))){
       value_str = skip_space(key+strlen(CLEARALL_KEY_STR));
       if ((*value_str == '\0') || (*value_str == '\n'))
         continue;

       /*
         printf("deleteall: %s\n", value_str);
       */
       ret = convert_octnum(value_str);
       if (ret == -1)
         Error("FunctionKey Error Defination");

       strncpy(functionkey[CLEARALL_KEY_ID].keylist, value_str, MAX_FUNCTIONKEY_LEN);
      }

      break;

    case KEYPROMPT_SECTION:
      ptr = key;
      kptr = keybuf;

      /* get key string */
      while (*ptr && (*ptr!=' ') && (*ptr!='\t') && (!(*ptr & 0x80))){
       *(kptr++) = *(ptr++);
      }

      *kptr = '\0';

      /* if no key string or no prompt string */
      if (!(*ptr) || !(keybuf[0])) break;

      /* get prompt characters string */
      value_str = skip_space(ptr);
                     
      /* if no single character string */
      if ((*value_str == '\0') || (*value_str == '\n'))
       break;

      /* only get first string */
      vptr = value_str;
      sptr = to_space(vptr);
      *sptr = '\0';
      /*
       printf("key:%s, keyprompt:%s====\n", keybuf, value_str);
      */
      strncpy(keyprompt[(int)keybuf[0]].prompt, value_str, MAX_KEYPROMPT_LEN);
      break;

    case SINGLE_SECTION:
      ptr = key;
      kptr = keybuf;

      /* get key string */
      while (*ptr && (*ptr!=' ') && (*ptr!='\t') && (!(*ptr & 0x80))){
       *(kptr++) = *(ptr++);
      }

      *kptr = '\0';

      /* if no key string or no single string */
      if (!(*ptr) || !(keybuf[0])) break;

      /* get single characters string */
      value_str = skip_space(ptr);
                     
      /* if no single character string */
      if ((*value_str == '\0') || (*value_str == '\n'))
       break;

      /* only get first string */
      vptr = value_str;
      sptr = to_space(vptr);
      *sptr = '\0';
      /*
       printf("key:%s, value:%s====\n", keybuf, value_str);
      */
      InsertNode(keybuf, value_str);      

      break;

    case PHRASE_SECTION:
      /*
       printf("line:%s====\n", key);
      */
      ptr = key;
      kptr = keybuf;

      /* get key string */
      while (*ptr && (*ptr!=' ') && (*ptr!='\t') && (!(*ptr & 0x80))){
       *(kptr++) = *(ptr++);
      }

      *kptr = '\0';

      /* if no key string or no phrase string */
      if (!(*ptr) || !(keybuf[0])) break;

      /* get phrase string */
      value_str = skip_space(ptr);
                     
      /* if no phrase character string */
      if ((*value_str == '\0') || (*value_str == '\n'))
       break;

      /*
       printf("key:%s, value:%s====\n", keybuf, value_str);
      */
      /* seperate the phrase string into single phrase */
      vptr = value_str;
      endofstr = 0;
      while (*vptr)
       {
         sptr = vptr;
         if ((*sptr == '#') && (*sptr++ == '#')){
           /*
             printf("Comment in the phrase line \n");
           */
           break; 
         }

         vptr = to_space(sptr);

         if (*vptr == '\0' || *vptr == '\n')
           endofstr = 1;

         *vptr = '\0';
         valuebuf[0] = HZ_PHRASE_TAG;
         valuebuf[1] = (unsigned char)(strlen(sptr));
         /*
           printf("str:%s, strlen:%d\n", sptr, strlen(sptr));
         */
         strcpy(valuebuf+2, sptr);
         InsertNode(keybuf, valuebuf);
                            
         if (endofstr)
           break;

         vptr = skip_space(vptr + 1);
         if (*vptr == '\n')
           break;
       }
      break;
    }
  } 
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* skip_space ( char *  s)

Definition at line 128 of file txt2bin.c.

{
  while (*s && (*s==' ' || *s=='\t')) s++;
  return s;
}
int str2val ( string_value_pair str_val,
char *  str 
)

Definition at line 105 of file txt2bin.c.

{
  while (str_val->string) {
    /*
      printf("%d: %s\n", str_val->value, str_val->string);
    */
    if (!strncasecmp (str_val->string, str, strlen(str_val->string)))
      return (str_val->value);
    str_val++;
  }
  return (str_val->value);
}
char* to_space ( char *  s)

Definition at line 134 of file txt2bin.c.

{
  while (*s && !isspace(*s)) s++;
  return s;
}
char* val2str ( string_value_pair str_val,
int  value 
)

Definition at line 118 of file txt2bin.c.

{
  while (str_val->string) {
    if (str_val->value == value)
      return (str_val->string);
    str_val++;
  }
  return (str_val->string);
}
static void Warning ( char *  str) [static]

Definition at line 190 of file txt2bin.c.

{
  fprintf (stderr, "Warning: %s (at line %d)\n", str, lineno);
}

Variable Documentation

unsigned int clen = 0

Definition at line 77 of file txt2bin.c.

Definition at line 79 of file txt2bin.c.

Definition at line 81 of file txt2bin.c.

Definition at line 66 of file txt2bin.c.

unsigned char* hzList

Definition at line 69 of file txt2bin.c.

Definition at line 80 of file txt2bin.c.

int lineno = 0

Definition at line 76 of file txt2bin.c.

Definition at line 68 of file txt2bin.c.

unsigned int pHZList

Definition at line 71 of file txt2bin.c.

unsigned int pNodeList

Definition at line 70 of file txt2bin.c.

dynNode* root = &rootNode [static]

Definition at line 64 of file txt2bin.c.

dynNode rootNode [static]
Initial value:
 {
  '\0', NULL, (struct _dynNode *)NULL, (struct _dynNode *)NULL
}

Definition at line 60 of file txt2bin.c.

Initial value:

Definition at line 98 of file txt2bin.c.

int totalHZbytes = 0 [static]

Definition at line 73 of file txt2bin.c.

int totalTableNode = 1 [static]

Definition at line 74 of file txt2bin.c.