A test program for ConfigFile library.

Dependencies:   mbed ConfigFile

main.cpp

Committer:
shintamainjp
Date:
2010-09-12
Revision:
0:78215cbf31b4
Child:
1:d125bda3cf74

File content as of revision 0:78215cbf31b4:

/**
 * Test program for configuration file interface class (Version 0.0.1)
 *
 * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems)
 * http://shinta.main.jp/
 */
#include "mbed.h"

#include "ConfigFile.h"

ConfigFile cfg;
LocalFileSystem local("local");

/**
 * ==================================================
 * Input (input.cfg)
 * ==================================================
 * #
 * # Configuration file for mbed.
 * #
 *
 * 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
 *
 * ==================================================
 * Output (output.cfg)
 * ==================================================
 * 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
 *
 * ==================================================
 * Output (console)
 * ==================================================
 * 'MyKey1'='This is a value for key1.'
 * 'MyKey2'='Value 2'
 */
int main() {

    char *key1 = "MyKey1";
    char *key2 = "MyKey2";
    char value[BUFSIZ];

    /*
     * Read a configuration file from a mbed.
     */
    cfg.read("/local/input.cfg");

    /*
     * Read a configuration value.
     */
    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);

    /*
     * Write a configuration file to a mbed.
     */
    cfg.write("/local/output.cfg");

    while (1) {
    }
}