Statistics
| Branch: | Revision:

root / config.c

History | View | Annotate | Download (1.94 KB)

1 0:3c15de202295 ee11d037
2
#include <stdlib.h>
3
#include <stdio.h>
4
#include <string.h>
5
#include <ctype.h>
6
7
#define VAR_LEN 30
8
#define VAL_LEN 30
9
10
#define MIN_WAIT_TIME 1.0
11
12
#define LABEL "label"
13
#define MODE "mode"
14
15
#define TRUE 1
16
#define FALSE 0
17
18
int read_conf_file (char *);
19
int is_label (char *);
20
int set_label (char *, char *);
21
22
int spell_mode = FALSE; // just making it explicit :)
23
24
int wait_time = 1*1000; // default is one second
25
26
char label[10][6];
27
28
int read_conf_file (char * file_name)
29
{
30
   FILE * fd;
31
   char variable[VAR_LEN], value[VAL_LEN];
32
33
   strcpy (label[0], "ABC");
34
   strcpy (label[1], "DEF");
35
   strcpy (label[2], "GHI");
36
   strcpy (label[3], "JKL");
37
   strcpy (label[4], "MNO");
38
   strcpy (label[5], "PQR");
39
   strcpy (label[6], "STU");
40
   strcpy (label[7], "VWX");
41
   strcpy (label[8], "YZ#");
42
   strcpy (label[9], "123");
43
44
   if ((fd = fopen (file_name, "r")) == NULL)
45
      return -1;
46
47
   while (fscanf (fd, "%s %s", variable, value) != EOF)
48
   {
49
      if (is_label (variable)) // check for label
50
         if (set_label (variable, value) == -1) // if so, set the variable
51
            return -2; // not a valid label definition
52
      if (strcasecmp (variable, MODE) == 0)
53
         if (strcasecmp (value, "spell") == 0)
54
            spell_mode = TRUE;
55
         else
56
         {
57
            if (strcasecmp (value, "word") != 0)
58
               return -3; // not a valid mode of operation
59
         }
60
      if (strcasecmp (variable, "time") == 0)
61
         wait_time = atof(value) < MIN_WAIT_TIME ? ((int)(MIN_WAIT_TIME * 1000)) : (int) (atof (value) * 1000);
62
   }
63
   return 1;
64
}
65
66
int is_label (char * str)
67
{
68
   return (strncasecmp (str, LABEL, strlen(LABEL)) == 0);
69
}
70
71
int set_label (char * var, char * val)
72
{
73
   int index;
74
75
//   if (isdigit (var[strlen(LABEL)]) == 0)
76
//      return -1;
77
78
   index = var[strlen(LABEL)] - '1'; // label[i-1] = val[i]
79
   if(index == -1)
80
   index =9;
81
   strcpy (label[index], val);
82
//   g_print ("the label is %s\t %d\n",label[index],index);
83
   return 1;
84
}
Redmine Appliance - Powered by TurnKey Linux