/[pcsclite]/trunk/Drivers/ccid/src/tokenparser.l
ViewVC logotype

Contents of /trunk/Drivers/ccid/src/tokenparser.l

Parent Directory Parent Directory | Revision Log Revision Log


Revision 269 - (hide annotations) (download)
Tue Aug 12 12:40:23 2003 UTC (9 years, 9 months ago) by rousseau
File size: 3075 byte(s)
Initial revision
1 rousseau 269 /*****************************************************************
2    
3     File : configfile.ll
4     Author : David Corcoran
5     Date : February 12, 1999, modified 4/6/2003
6     Purpose: Reads lexical config files and updates database.
7     See http://www.linuxnet.com for more information.
8     License: Copyright (C) 1999 David Corcoran, Ludovic Rousseau
9     <corcoran@linuxnet.com>
10     $Id$
11    
12     ******************************************************************/
13    
14     %{
15    
16     #include "parser.h"
17    
18     void tpevalToken(char *pcToken, int tokType);
19    
20     static char *pcDesiredKey = 0;
21     static char pcKey[TOKEN_MAX_KEY_SIZE];
22     static char pcValue[TOKEN_MAX_VALUE_SIZE];
23     static char pcFinValue[TOKEN_MAX_VALUE_SIZE];
24     static int valueIndex = 0;
25     static int desiredIndex = 0;
26    
27     void tperrorCheck (char *pcToken_error);
28    
29     %}
30    
31     %%
32    
33     #.* {}
34     "\n" {}
35     \<key\>([A-Z]|[a-z]|[0-9]|[ \t])+\<\/key\> { valueIndex = 0; tpevalToken(yytext, TOKEN_TYPE_KEY); }
36     [ \t] {}
37     \<string\>([A-Z]|[a-z]|[0-9]|[ \t]|[!@#$%^&*()\-+/_\:?.,=~'"])+\<\/string\> {tpevalToken(yytext, TOKEN_TYPE_STRING); valueIndex += 1;}
38     . { tperrorCheck( yytext ); }
39     %%
40    
41     #include <stdio.h>
42     #include <string.h>
43     #include "config.h"
44     #include "debug.h"
45    
46     int yywrap()
47     {
48     return 1;
49     }
50    
51    
52     void tpevalToken(char *pcToken, int tokType)
53     {
54     int len;
55     len = 0;
56    
57     if (tokType == TOKEN_TYPE_KEY)
58     {
59     for (len=5; pcToken[len] != '<'; len++)
60     ;
61     if (len - 5 > TOKEN_MAX_KEY_SIZE)
62     {
63     strncpy(pcKey, &pcToken[5], TOKEN_MAX_KEY_SIZE);
64     pcKey[TOKEN_MAX_KEY_SIZE - 1] = '\0';
65     }
66     else
67     {
68     strncpy(pcKey, &pcToken[5], len - 5);
69     pcKey[len-5] = 0;
70     }
71     }
72    
73     if (tokType == TOKEN_TYPE_STRING)
74     {
75     for (len=8; pcToken[len] != '<'; len++)
76     ;
77     if (len - 8 > TOKEN_MAX_VALUE_SIZE)
78     {
79     strncpy(pcValue, &pcToken[8], TOKEN_MAX_VALUE_SIZE);
80     pcValue[TOKEN_MAX_VALUE_SIZE - 1] = '\0';
81     }
82     else
83     {
84     strncpy(pcValue, &pcToken[8], len - 8);
85     pcValue[len-8] = 0;
86     }
87     if (strcmp(pcKey, pcDesiredKey) == 0)
88     if (desiredIndex == valueIndex)
89     {
90     strncpy(pcFinValue, pcValue, TOKEN_MAX_VALUE_SIZE);
91     pcFinValue[TOKEN_MAX_VALUE_SIZE - 1] = '\0';
92     }
93     }
94     }
95    
96     void tperrorCheck (char *token_error)
97     {
98     }
99    
100     int LTPBundleFindValueWithKey(char *fileName, char *tokenKey,
101     char *tokenValue, int tokenIndice)
102     {
103     FILE *file = NULL;
104     int ret = 0;
105    
106     desiredIndex = tokenIndice;
107     pcDesiredKey = tokenKey;
108     pcFinValue[0] = '\0';
109    
110     file = fopen(fileName, "r");
111    
112     if (!file)
113     {
114     DEBUG_CRITICAL2("Could not open bundle file : %s", fileName);
115     return 1;
116     }
117    
118     yyin = file;
119    
120     do
121     {
122     yylex();
123     } while (!feof(file));
124    
125     if (pcFinValue[0] == 0)
126     {
127     if (tokenIndice == 0)
128     {
129     /* Not defined at all */
130     DEBUG_CRITICAL3("Value/Key not defined for: %s, indice: %d",
131     tokenKey, tokenIndice);
132     }
133     ret = -1;
134     }
135     else
136     {
137     strncpy(tokenValue, pcFinValue, TOKEN_MAX_VALUE_SIZE);
138     tokenValue[TOKEN_MAX_VALUE_SIZE - 1] = '\0';
139     }
140    
141     fclose(file);
142     return ret;
143     }
144    

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.5