// ------------------------------- // // -------- Start of File -------- // // ------------------------------- // // ----------------------------------------------------------- // // C++ Source Code File Name: testprog.cpp // Compiler Used: MSVC40, DJGPP 2.7.2.1, egcs-2.90.29, HP CPP 10.24 // Produced By: Doug Gaer // File Creation Date: 02/19/1996 // Date Last Modified: 06/21/2000 // Copyright (c) 2000 Douglas M. Gaer // ----------------------------------------------------------- // // ------------- Program Description and Details ------------- // // ----------------------------------------------------------- // /* The VBS C++ classes are copyright (c) 2000, by Douglas M. Gaer. All those who put this code or its derivatives in a commercial product MUST mention this copyright in their documentation for users of the products in which this code or its derivative classes are used. Otherwise, you have the freedom to redistribute verbatim copies of this source code, adapt it to your specific needs, or improve the code and release your improvements to the public provided that the modified files carry prominent notices stating that you changed the files and the date of any change. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE, YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. This is a test program for the vbvbConfig class. */ // ----------------------------------------------------------- // #include <iostream.h> #include <stdio.h> #include "vbconfig.h" // Data structure use to store program vbConfiguration values struct ProgramvbConfig { ProgramvbConfig() { // Set the default values s_val = "YES"; i_val = 32768; l_val = 2147483647; d_val = 1.12345; } ProgramvbConfig(const ProgramvbConfig &ob) { s_val = ob.s_val; i_val = ob.i_val; l_val = ob.l_val; d_val = ob.d_val; } vbString s_val; int i_val; long l_val; double d_val; }; void pause() { cin.get(); cout << "Press enter to continue..." << endl; cout << endl; } void DisplayConfig(vbConfig *CfgData, ProgramvbConfig *cfg) // Display the program vbConfiguration and load vbConfig values { char *v1 = CfgData->GetStrValue("String"); if(!v1) { cout << "String section missing from vbConfig file" << endl; } else { cout << "String section of vbConfig file = " << v1 << endl; cfg->s_val = v1; } int v2 = CfgData->GetIntValue("Int"); if(!v2) { cout << "Int section missing from vbConfig file" << endl; } else { cout << "Integer section of vbConfig file = " << v2 << endl; cfg->i_val = v2; } double v3 = CfgData->GetFloatValue("Float"); if(!v3) { cout << "Float section missing from vbConfig file" << endl; } else { cout << "Floating Point number section of vbConfig file = " << v3 << endl; cfg->d_val = v3; } long v4 = CfgData->GetLongValue("Long"); if(!v4) { cout << "Long int section missing from vbConfig file" << endl; } else { cout << "Long int section of vbConfig file = " << v4 << endl; cfg->l_val = v4; } cout << endl; } void MultipleRead(vbConfig *CfgData) { char *ServerName = CfgData->GetStrValue("ServerName"); if(!ServerName) { cout << "ServerName value is not set in the vbConfig file" << endl; return; } else cout << "Server name = " << ServerName << endl; char *FullPathName = CfgData->GetStrValue("FullPathName0"); if(!FullPathName) { cout << "No path names are set in the vbConfig file" << endl; return; } char cfgValue[255]; long file_num = -1; while(1) { file_num++; sprintf(cfgValue, "FullPathName%d", file_num); char *buf = CfgData->GetStrValue(cfgValue); if(!buf) break; vbString sbuf(buf); unsigned offset = 0; unsigned index = 0; while(1) { offset = sbuf.Find("/", offset); if(offset != vbString::NoMatch) index = offset; if(offset == vbString::NoMatch) break; offset++; } if(index > 0) sbuf.DeleteAt(0, ++index); if(sbuf.length() == 0) { cout << "Invalid file name for " << cfgValue << endl; return; } cout << "Reading: " << buf << endl; cout << "Copying to: " << sbuf << endl; buf = 0; for(int i = 0; i < 255; i++) cfgValue[i] = 0; } cout << endl; } void NewParmID(vbConfig *CfgData) { CfgData->UnLoad(); CfgData->SetParmID("://"); vbString parmName("http"); CfgData->ReadComments(); CfgData->ReLoad(); vbConfigListNode *ptr = CfgData->GetFront(); while(!CfgData->IsHeader(ptr)) { // Scan until end of list unsigned offset = 0; offset = ptr->Data.Find(parmName); if(offset != vbString::NoMatch) { vbString ServerName(ptr->GetNext()->Data); vbString FullPathName(ptr->GetNext()->Data); unsigned offset = ServerName.Find("/"); if(offset != vbString::NoMatch) { ServerName.DeleteAt(offset, (ServerName.length() - offset)); FullPathName.DeleteAt(0, offset); cout << "Server: " << ServerName << " Path: " << FullPathName << endl; } } ptr = ptr->GetNext(); } } int main() { vbConfig *CfgData = new vbConfig; ProgramvbConfig *cfg = new ProgramvbConfig; int Status; // Test for all three overloads char *fname = "vbconfig.ini"; // const char *fname = "vbConfig.ini"; // vbString fname("vbConfig.ini"); cout << "Loading vbConfig File..." << endl; Status = CfgData->Load(fname); if(!Status) { cout << "vbConfig file not found!" << endl; return 0; } else cout << "Processing file: " << CfgData->GetFileName() << endl; cout << endl; DisplayConfig(CfgData, cfg); ProgramvbConfig org_vbConfig(*cfg); // Record the original values cout << "Testing reload function" << endl; pause(); CfgData->ReLoad(fname); DisplayConfig(CfgData, cfg); cout << "Writing new values to the file" << endl; pause(); CfgData->ChangeConfigValue("String", "NO"); CfgData->ChangeConfigValue("Float", 1.98712); CfgData->ChangeConfigValue("Int", 12345); CfgData->ChangeConfigValue("Long", 23889); DisplayConfig(CfgData, cfg); cout << "Restoring orignal values" << endl; pause(); CfgData->ChangeConfigValue("String", org_vbConfig.s_val); CfgData->ChangeConfigValue("Int", org_vbConfig.i_val); CfgData->ChangeConfigValue("Float", org_vbConfig.d_val); CfgData->ChangeConfigValue("Long", org_vbConfig.l_val); DisplayConfig(CfgData, cfg); cout << "Performing a multiple read and parsing operation" << endl; pause(); MultipleRead(CfgData); cout << "Reloading the file with a new parameter ID string" << endl; pause(); NewParmID(CfgData); CfgData->UnLoad(); return 0; } // ----------------------------------------------------------- // // ------------------------------- // // --------- End of File --------- // // ------------------------------- //