| 1 |
/*****************************************************************
|
| 2 |
|
| 3 |
File : configfile.ll
|
| 4 |
Author : David Corcoran, Ludovic Rousseau
|
| 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 = NULL;
|
| 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 |
%option nounput
|
| 32 |
|
| 33 |
%%
|
| 34 |
|
| 35 |
#.* {}
|
| 36 |
"\n" {}
|
| 37 |
\<key\>([A-Z]|[a-z]|[0-9]|[ \t])+\<\/key\> { valueIndex = 0; tpevalToken(yytext, TOKEN_TYPE_KEY); }
|
| 38 |
[ \t] {}
|
| 39 |
\<string\>([A-Z]|[a-z]|[0-9]|[ \t]|[!@#$%^&*()\-+/_\:?.,=~'"])+\<\/string\> {tpevalToken(yytext, TOKEN_TYPE_STRING); valueIndex += 1;}
|
| 40 |
. { tperrorCheck( yytext ); }
|
| 41 |
%%
|
| 42 |
|
| 43 |
#include <stdio.h>
|
| 44 |
#include <string.h>
|
| 45 |
#include "config.h"
|
| 46 |
#include "debug.h"
|
| 47 |
|
| 48 |
int yywrap()
|
| 49 |
{
|
| 50 |
return 1;
|
| 51 |
}
|
| 52 |
|
| 53 |
|
| 54 |
void tpevalToken(char *pcToken, int tokType)
|
| 55 |
{
|
| 56 |
int len;
|
| 57 |
len = 0;
|
| 58 |
|
| 59 |
if (tokType == TOKEN_TYPE_KEY)
|
| 60 |
{
|
| 61 |
for (len=5; pcToken[len] != '<'; len++)
|
| 62 |
;
|
| 63 |
if (len - 5 > TOKEN_MAX_KEY_SIZE)
|
| 64 |
{
|
| 65 |
strncpy(pcKey, &pcToken[5], TOKEN_MAX_KEY_SIZE);
|
| 66 |
pcKey[TOKEN_MAX_KEY_SIZE - 1] = '\0';
|
| 67 |
}
|
| 68 |
else
|
| 69 |
{
|
| 70 |
strncpy(pcKey, &pcToken[5], len - 5);
|
| 71 |
pcKey[len-5] = 0;
|
| 72 |
}
|
| 73 |
}
|
| 74 |
|
| 75 |
if (tokType == TOKEN_TYPE_STRING)
|
| 76 |
{
|
| 77 |
for (len=8; pcToken[len] != '<'; len++)
|
| 78 |
;
|
| 79 |
if (len - 8 > TOKEN_MAX_VALUE_SIZE)
|
| 80 |
{
|
| 81 |
strncpy(pcValue, &pcToken[8], TOKEN_MAX_VALUE_SIZE);
|
| 82 |
pcValue[TOKEN_MAX_VALUE_SIZE - 1] = '\0';
|
| 83 |
}
|
| 84 |
else
|
| 85 |
{
|
| 86 |
strncpy(pcValue, &pcToken[8], len - 8);
|
| 87 |
pcValue[len-8] = 0;
|
| 88 |
}
|
| 89 |
if (strcmp(pcKey, pcDesiredKey) == 0)
|
| 90 |
if (desiredIndex == valueIndex)
|
| 91 |
{
|
| 92 |
strncpy(pcFinValue, pcValue, TOKEN_MAX_VALUE_SIZE);
|
| 93 |
pcFinValue[TOKEN_MAX_VALUE_SIZE - 1] = '\0';
|
| 94 |
}
|
| 95 |
}
|
| 96 |
}
|
| 97 |
|
| 98 |
void tperrorCheck (char *token_error)
|
| 99 |
{
|
| 100 |
}
|
| 101 |
|
| 102 |
int LTPBundleFindValueWithKey(char *fileName, char *tokenKey,
|
| 103 |
char *tokenValue, int tokenIndice)
|
| 104 |
{
|
| 105 |
FILE *file = NULL;
|
| 106 |
int ret = 0;
|
| 107 |
|
| 108 |
desiredIndex = tokenIndice;
|
| 109 |
pcDesiredKey = tokenKey;
|
| 110 |
pcFinValue[0] = '\0';
|
| 111 |
|
| 112 |
file = fopen(fileName, "r");
|
| 113 |
|
| 114 |
if (!file)
|
| 115 |
{
|
| 116 |
DEBUG_CRITICAL2("Could not open bundle file : %s", fileName);
|
| 117 |
return 1;
|
| 118 |
}
|
| 119 |
|
| 120 |
yyin = file;
|
| 121 |
|
| 122 |
do
|
| 123 |
{
|
| 124 |
yylex();
|
| 125 |
} while (!feof(file));
|
| 126 |
|
| 127 |
if (pcFinValue[0] == 0)
|
| 128 |
{
|
| 129 |
if (tokenIndice == 0)
|
| 130 |
{
|
| 131 |
/* Not defined at all */
|
| 132 |
DEBUG_CRITICAL3("Value/Key not defined for: %s, indice: %d",
|
| 133 |
tokenKey, tokenIndice);
|
| 134 |
}
|
| 135 |
ret = -1;
|
| 136 |
}
|
| 137 |
else
|
| 138 |
{
|
| 139 |
strncpy(tokenValue, pcFinValue, TOKEN_MAX_VALUE_SIZE);
|
| 140 |
tokenValue[TOKEN_MAX_VALUE_SIZE - 1] = '\0';
|
| 141 |
}
|
| 142 |
|
| 143 |
fclose(file);
|
| 144 |
return ret;
|
| 145 |
}
|
| 146 |
|