1/***************************************************************** 2 3 File : configfile.ll 4 Author : David Corcoran 5 Date : February 12, 1999 modified 7/28/99 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 9 <corcoran@linuxnet.com> 10 11******************************************************************/ 12 13%{ 14 15void tpevalToken( char *pcToken, int tokType ); 16 17static char *pcDesiredKey = 0; 18static char pcKey[200]; 19static char pcValue[200]; 20static char pcFinValue[200]; 21static int valueIndex = 0; 22static int desiredIndex = 0; 23 24void tperrorCheck ( char *pcToken_error ); 25 26%} 27 28%% 29 30#.* {} 31"\n" {} 32\<key\>([A-Z]|[a-z]|[0-9]|[ \t])+\<\/key\> { valueIndex = 0; tpevalToken(yytext, 1); } 33[ \t] {} 34\<string\>([A-Z]|[a-z]|[0-9]|[ \t]|[!@#$%^&*()\-+/_\:?.,=~'"])+\<\/string\> {tpevalToken(yytext, 2); valueIndex += 1;} 35. { tperrorCheck( yytext ); } 36%% 37 38#include <stdio.h> 39#include <string.h> 40#include "debuglog.h" 41#include "config.h" 42 43int yywrap() { 44 return 1; 45} 46 47 48void tpevalToken( char *pcToken, int tokType ) { 49 50 int len; 51 len = 0; 52 53 if ( tokType == 1 ) { 54 for (len=5; pcToken[len] != '<'; len++); 55 strncpy(pcKey, &pcToken[5], len - 5); 56 pcKey[len-5] = 0; 57 } 58 59 if ( tokType == 2 ) { 60 for (len=8; pcToken[len] != '<'; len++); 61 strncpy(pcValue, &pcToken[8], len - 8); 62 pcValue[len-8] = 0; 63 if ( strcmp(pcKey, pcDesiredKey) == 0 ) { 64 if ( desiredIndex == valueIndex ) { 65 strcpy(pcFinValue, pcValue); 66 } 67 } 68 } 69 70 71} 72 73void tperrorCheck ( char *token_error ) { } 74 75int LTPBundleFindValueWithKey(char *fileName, char *tokenKey, 76 char *tokenValue, int tokenIndice) { 77 78 FILE *file; 79 file = 0; 80 81 desiredIndex = tokenIndice; 82 pcDesiredKey = tokenKey; 83 pcFinValue[0] = 0; 84 85 file = fopen(fileName, "r"); 86 87 if (!file) { 88 DebugLogC( "Could not open bundle file : %s\n", fileName ); 89 return 1; 90 } 91 92 yyin = file; 93 94 do { 95 yylex(); 96 } while (!feof(file)); 97 98 if ( pcFinValue[0] == 0 ) { 99 if ( tokenIndice == 0 ) { 100 /* Not defined at all */ 101 DebugLogC( "Value/Key not defined for: %s\n", tokenKey ); 102 } 103 fclose(file); 104 return -1; 105 } else { 106 strcpy(tokenValue, pcFinValue); 107 fclose(file); 108 return 0; 109 } 110 111 fclose(file); 112 return 0; 113} 114 115