Back to index

im-sdk  12.3.91
Defines | Functions
converter.c File Reference
#include <stdio.h>

Go to the source code of this file.

Defines

#define MAX_CHAR_LEN   4

Functions

int convert_to_hex_code (char high_code, char low_code)
int convert_to_cns11643_code (unsigned char *qu_str, unsigned char *hex_str)
int main (int argc, char **argv)

Define Documentation

#define MAX_CHAR_LEN   4

Definition at line 45 of file converter.c.


Function Documentation

int convert_to_cns11643_code ( unsigned char *  qu_str,
unsigned char *  hex_str 
)

Definition at line 69 of file converter.c.

{
       int qu_code;
       int cur_pos = 0;

       qu_code = toupper(qu_str[0]);
       if (qu_code >= '2' && qu_code <= '7') {
              hex_str[cur_pos++] = 0x8e;
              hex_str[cur_pos++] = 0xa1 + (qu_code - '1');
       } else if (qu_code >= 'A' && qu_code <= 'F') {
              hex_str[cur_pos++] = 0x8e;
              hex_str[cur_pos++] = 0xaa + (qu_code - 'A');
       }
       hex_str[cur_pos++] = convert_to_hex_code(qu_str[1], qu_str[2]);
       hex_str[cur_pos++] = convert_to_hex_code(qu_str[3], qu_str[4]);
       hex_str[cur_pos] = 0;

       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int convert_to_hex_code ( char  high_code,
char  low_code 
)

Definition at line 47 of file converter.c.

{
       unsigned char high, low;

       high = toupper(high_code);
       if (high >= '0' && high <= '9') {
              high = high - '0' + 0x8;
       } else if (high >= 'A' && high <= 'F') {
              high = high - 'A' + 0xa;
       }
       high <<= 4;

       low = toupper(low_code);
       if (low >= '0' && low <= '9') {
              low = low - '0' + 0x0;
       } else if (low >= 'A' && low <= 'F') {
              low = low - 'A' + 0xa;
       }

       return((high | low) & 0x00ff);
}

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 89 of file converter.c.

{
       char            *file_name; 
       char          line[256];
       unsigned char value1[256], value2[256], hex_str[5];
    
       register char        *ptr;
       FILE          *fd;
       int           i;

       if (argc != 2) {
              printf("usage: %s file_name\n", argv[0]);
              exit(0);
       }

       /* read profile from file to memory buffer  */ 
       file_name = argv[1];

       fd = fopen(file_name, "r");
       if (! fd)
              return -1;

       while (fgets(line, 255, fd) != NULL) {
              ptr = line;

              /* skip space */
              while (*ptr == ' ' || *ptr == '\t') ptr++;

              /* check null line or comment line */
              if ((*ptr == '\0') || (*ptr == '\n') || (*ptr == '#'))
                     continue;

/*
              sscanf(ptr, "%s %s", &value1, &value2);
*/
              memset(value1, 0, 256);
              memset(value2, 0, 256);
              for (i=0; i<5; i++) {
                     value1[i] = *ptr++;
              }
              value1[5] ='\0';

              /* skip space */
              while (*ptr==' ' || *ptr=='\t') ptr++;

              if (*ptr && *ptr != '\n') {
                     for (i=0; i<MAX_CHAR_LEN; i++) {
                            if (*ptr == 0 || *ptr==' ' || *ptr=='\t' || *ptr=='\n') {
                                   value2[i] = 0;
                                   break;
                            }
                            value2[i] = tolower(*ptr++);
                     }

                     convert_to_cns11643_code(value1, hex_str);
                     printf("%s\t%s\n", value2, hex_str);
              }
       }
       
       fclose(fd);

       return 0;
}

Here is the call graph for this function: