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   6

Functions

int main (int argc, char **argv)

Define Documentation

#define MAX_CHAR_LEN   6

Definition at line 45 of file converter.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 47 of file converter.c.

{
       char            *file_name; 
       char          line[256], value1[256];
       unsigned char value2[256];
    
       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;

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

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

              if (*ptr && *ptr != '\n') {
                     unsigned char *vptr = value2;
                     while(*ptr && *ptr != ' ' && *ptr != '\n' && *ptr != '\t') {
                            *vptr++ = *ptr++;
                     }
                     *vptr = 0;
                            
                     printf("%s\t%s\n", value1, value2);
              }
       }
       
       fclose(fd);

       return 0;
}