Shinichiro Nakamura
/
ConfigFile_TestProgram
A test program for ConfigFile library.
Diff: main.cpp
- Revision:
- 2:1b88311b9f10
- Parent:
- 1:d125bda3cf74
- Child:
- 3:a8ceaaf6c1cf
--- a/main.cpp Sun Sep 12 07:53:39 2010 +0000 +++ b/main.cpp Wed Sep 15 12:23:34 2010 +0000 @@ -12,8 +12,27 @@ LocalFileSystem local("local"); /** + * View the list. + */ +void viewlist(void) { + /* + * If you need to check all parameters. + */ + const int cnt = cfg.getCount(); + char buf_key[BUFSIZ]; + char buf_value[BUFSIZ]; + for (int i = 0; i < cnt; i++) { + if (cfg.getKeyAndValue(i, buf_key, sizeof(buf_key), buf_value, sizeof(buf_value))) { + printf("No.%3d:'%s'='%s'\n", i, buf_key, buf_value); + } else { + printf("No.%3d:Failure to get a configuration.\n", i); + } + } +} + +/** * ================================================== - * Input (input.cfg) + * Input file (input.cfg) * ================================================== * # * # Configuration file for mbed. @@ -24,9 +43,10 @@ * * Message1 = This is a test message no.1 * Message2 = This is a test message no.2 + * Message3 = This is a test message no.2 * * ================================================== - * Output (output1.cfg) + * Output file (output1.cfg) * ================================================== * MyKey1=This is a value for key1. * MyKey2=Value 2 @@ -34,22 +54,28 @@ * Message2 = This is a test message no.2 * * ================================================== - * Output (output2.txt) + * Output file (output2.txt) * ================================================== * # This is a configuration file for my application. * ABC=123 * DEF=456 * * ================================================== - * Output (console) + * Console output * ================================================== * 'MyKey1'='This is a value for key1.' * 'MyKey2'='Value 2' + * 'Message1 '=' This is a test message no.1' + * 'Message2 '=' This is a test message no.2' + * ' Message3 '=' This is a test message no.2' */ int main() { char *key1 = "MyKey1"; char *key2 = "MyKey2"; + char *key3 = "Message1 "; + char *key4 = "Message2 "; + char *key5 = " Message3 "; char value[BUFSIZ]; /* @@ -62,8 +88,18 @@ */ cfg.getValue(key1, &value[0], sizeof(value)); printf("'%s'='%s'\n", key1, value); + cfg.getValue(key2, &value[0], sizeof(value)); printf("'%s'='%s'\n", key2, value); + + cfg.getValue(key3, &value[0], sizeof(value)); + printf("'%s'='%s'\n", key3, value); + + cfg.getValue(key4, &value[0], sizeof(value)); + printf("'%s'='%s'\n", key4, value); + + cfg.getValue(key5, &value[0], sizeof(value)); + printf("'%s'='%s'\n", key5, value); /* * Write a configuration file to a mbed. @@ -85,7 +121,7 @@ * Write a configuration file to a mbed. */ cfg.write("/local/output2.cfg", "# This is a configuration file for my application."); - + while (1) { } }