/** This function sets all values not specified in the config file to the default values */ int FillRemaining(const CONFENTRY *entrydef, const int entrycount, int *res, unsigned char *config) { int i; for (i=0;i<entrycount;i++) { if (res==NULL) { if (config==NULL) ProcessValue("", (LIST_TYPE*)&entrydef[i], entrydef[i].value); else ProcessValue("", (LIST_TYPE*)&entrydef[i], (void**) &config[entrydef[i].offset]); } else if (res[i]==0) if (config==NULL) ProcessValue("", (LIST_TYPE*)&entrydef[i], entrydef[i].value); else ProcessValue("", (LIST_TYPE*)&entrydef[i], (void**) &config[entrydef[i].offset]); } return 0; }
bool Field::Load(std::ifstream& f, int shift){ S_LOG("Load"); auto current = std::ios_base::cur; if (f.good()){ f.seekg(shift, current); log(logxx::debug) << "Current position: 0x" << std::hex << f.tellg() << std::dec << logxx::endl; uint32_t fieldLength(0); char optionalField[2]; f.read(optionalField, 2); check_error(optionalField); if ( std::strncmp(optionalField, "PN", 2) == 0 || std::strncmp(optionalField, "LO", 2) == 0 || std::strncmp(optionalField, "DA", 2) == 0 ){ uint16_t shortFieldLength(0); fread(shortFieldLength); fieldLength = shortFieldLength; } else{ f.seekg(-2, std::ios_base::cur); fread(fieldLength); } static const decltype(fieldLength) maxLength = 100; if (fieldLength == 0){ log(logxx::warning) << "Field length is zero, nothing to read!" << logxx::endl; return false; } else if (fieldLength > maxLength){ log(logxx::warning) << "Too large field: " << fieldLength << "; maximum allowed is: " << maxLength << logxx::endl; return false; } std::unique_ptr<char[]> cValue(new char[fieldLength]); f.read(cValue.get(), fieldLength); check_error(cValue); try { value.assign(cValue.get(), fieldLength); ProcessValue(); return true; } catch (const std::exception& e){ log(logxx::warning) << "Cought an exception: " << e.what() << logxx::endl; value.assign('%', fieldLength); return true; } } else { log(logxx::error) << "Can't read file" << logxx::endl; return false; } }
void CActiveConsole::ProcessKeyPressL(TChar aChar) { if (aChar == EKeyEscape) { PRINT(_L("CActiveConsole: ESC key pressed -> stopping active scheduler...\n")); CActiveScheduler::Stop(); return; } aChar.UpperCase(); if (iCmdGetValue != 0 && aChar == '\r') { if (iLastChar == 'K') { iValue *= iGetHexValue ? 0x400 : 1000; } if (iLastChar == 'M') { iValue *= iGetHexValue ? 0x10000 : 1000000; } PRINT1(_L("CActiveConsole: Value %d\n"),iValue); ProcessValue(); } if (iCmdGetValue != 0 ) { if (iGetHexValue) { if (aChar.IsDigit()) { iValue = iValue * 16 + aChar.GetNumericValue(); } else { if (aChar.IsHexDigit()) { iValue = iValue * 16 + (TUint)aChar - 'A' + 10; } else { if (aChar != 'K' && aChar != 'M') { PRINT(_L("Illegal hexadecimal character - Enter command\n")); iCmdGetValue = 0; } } } } else { if (aChar.IsDigit()) { iValue = iValue * 10 + aChar.GetNumericValue(); } else { if ((aChar == 'X') && (iLastChar == '0') && (iValue == 0)) iGetHexValue = ETrue; else { if (aChar != 'K' && aChar != 'M') { test.Printf(_L("Illegal decimal character - Enter command\n")); iCmdGetValue = 0; } } } } } else { switch (aChar) { case 'F' : TESTNEXT(_L("Flushing Cache")); test_KErrNone(DPTest::FlushCache()); ShowMemoryUse(); iPrompt = ETrue; break; case 'I' : CacheSize(0,0); ShowMemoryUse(); iPrompt = ETrue; break; case 'Q' : gQuiet = ETrue; iPrompt = ETrue; break; case 'V' : gQuiet = EFalse; iPrompt = ETrue; break; case '?' : ShowHelp(); break; case '=' : iCmdGetValue = iLastChar; iGetHexValue = EFalse; iValue = 0; break; default : if (aChar.IsDigit()) { if (iLastChar == 'R') { if (aChar.GetNumericValue() < (TInt)gNextChunk) { ReadChunk (&gChunk[aChar.GetNumericValue()]); } else { for (TUint i = 0; i < gNextChunk; i++) ReadChunk (&gChunk[i]); } iPrompt = ETrue; } if (iLastChar == 'W') { if (aChar.GetNumericValue() < (TInt)gNextChunk) { WriteChunk (&gChunk[aChar.GetNumericValue()]); } else { for (TUint i = 0; i < gNextChunk; i++) WriteChunk (&gChunk[i]); } iPrompt = ETrue; } if (iLastChar == 'M') { if (aChar.GetNumericValue() == 0) { iActions = (TUint16)(iPeriod < KFlushQuietLimit ? EFlushQuiet : EFlush); } else { iActions = (TUint16)(aChar.GetNumericValue() << 4); } iPrompt = ETrue; } } break; } } iLastChar = aChar; GetCharacter(); return; }
char *ProcessKeyA(const CONFENTRY *entrydef, const int size, int* result, const char *key, char *value, unsigned char* config) { int i; char *ret; int len; int res; void**retval; for (i=0; i< size;i++) { int res; res = strcasecmp((char*)entrydef[i].key, key); if (res==0) { /* process data */ if (entrydef[i].flags & TYPE_STRING || entrydef[i].flags & TYPE_LIST) { ret = strstr(value, ",,#"); if (ret!=NULL) { *ret=0; *(ret+1)=0; *(ret+2)=0; ret+=3; } else return NULL; if (config==NULL) res=ProcessValue(value, (LIST_TYPE*)&entrydef[i], entrydef[i].value); else res=ProcessValue(value, (LIST_TYPE*)&entrydef[i], (void**) &config[entrydef[i].offset]); if (result!=NULL) result[i] = res; } else if (entrydef[i].flags & TYPE_USERDEF) { //TODO Call additionalData //ret = (char*)(FUNCTION_TYPE(entrydef[i].additionaldata))(&entrydef[i], (char*)value, entrydef[i].value); return ret; } else { ret = strchr(value,'#'); if (ret!=NULL) *ret=0; else return NULL; ret+=1; if (config==NULL) res=ProcessValue(value, (LIST_TYPE*)&entrydef[i], entrydef[i].value); else res=ProcessValue(value, (LIST_TYPE*)&entrydef[i], (void**) &config[entrydef[i].offset]); if (result!=NULL) result[i] = res; } return ret; } } return NULL; }