/** * Project: Tremstats * File: main.cpp * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @link http://www.dasprids.de/ * @author Ben 'DASPRiD' Scholzen * @package Tremstats * @version 0.9.1 */ // Includes #include #include #include #include #include "includes/iniparser.h" // Namespace to use using namespace std; void get_from_config (const char * section, const char * entity, char ** result); /** * Main function of the program */ int main (int argc, char ** argv[]) { char hostname[60]; get_from_config("mysql", "hostname", &hostname); printf("%s\n", hostname); return 0; } /** * Get a value from the config. The config file itself is only loaded once. * * @param char section * @param char entity * @param char result */ void get_from_config (const char * section, const char * entity, char ** result) { static dictionary * d; if (d == NULL) { d = iniparser_new("./config.cfg"); } char *entry = new char[strlen(section) + strlen(entity) + 2]; sprintf(entry, "%s:%s", section, entity); *result = iniparser_getstr(d, entry); delete [] entry; }