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 evalToken( char *pcToken, int tokType ); 16 17static char *pcDesiredKey = 0; 18static char pcKey[200]; 19static char pcValue[200]; 20static char pcFinValue[200]; 21 22void errorCheck ( char *pcToken_error ); 23 24%} 25 26%% 27 28#.* {} 29"\n" {} 30\<key\>([A-Z]|[a-z]|[0-9]|[ \t])+\<\/key\> { evalToken(bptext, 1); } 31[ \t] {} 32\<string\>([A-Z]|[a-z]|[0-9]|[ \t]|[!@#$%^&*()\-+/_\:?.,=~'"])+\<\/string\> { evalToken(bptext, 2); } 33. { errorCheck( bptext ); } 34%% 35 36#include <stdio.h> 37#include <string.h> 38 39#include "wintypes.h" 40#include "debuglog.h" 41 42int bpwrap() { 43 return 1; 44} 45 46 47void evalToken( char *pcToken, int tokType ) { 48 49 int len; 50 len = 0; 51 52 if ( tokType == 1 ) { 53 for (len=5; pcToken[len] != '<'; len++); 54 strncpy(pcKey, &pcToken[5], len - 5); 55 pcKey[len-5] = 0; 56 } 57 58 if ( tokType == 2 ) { 59 for (len=8; pcToken[len] != '<'; len++); 60 strncpy(pcValue, &pcToken[8], len - 8); 61 pcValue[len-8] = 0; 62 if ( strcmp(pcKey, pcDesiredKey) == 0 ) { 63 strcpy(pcFinValue, pcValue); 64 } 65 } 66 67 68} 69 70void errorCheck ( char *token_error ) { } 71 72int LCFBundleFindValueWithKey(char *fileName, char *tokenKey, 73 char *tokenValue ) { 74 75 FILE *file; 76 file = 0; 77 78 pcDesiredKey = tokenKey; 79 pcFinValue[0] = 0; 80 81 file = fopen(fileName, "r"); 82 83 if (!file) { 84 DebugLogB( "Could not open bundle file : %s", fileName ); 85 return 1; 86 } 87 88 bpin = file; 89 90 do { 91 bplex(); 92 } 93 while (!feof(file)); 94 95 if ( pcFinValue[0] == 0 ) { 96 DebugLogB( "Value/Key not defined for: %s", tokenKey ); 97 fclose(file); 98 return -1; 99 } else { 100 strcpy(tokenValue, pcFinValue); 101 fclose(file); 102 return 0; 103 } 104 105 fclose(file); 106 return 0; 107} 108 109