mirror of
https://github.com/lakinduakash/linux-wifi-hotspot.git
synced 2025-02-16 07:30:09 +00:00
c++ implementation of read conf file
(Reason:libconfig error without double quotes)
This commit is contained in:
parent
49c9aed7e4
commit
583dd49f2f
37
src/ui/read_config.cpp
Normal file
37
src/ui/read_config.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
//
|
||||
// Created by lakinduakash on 14/04/19.
|
||||
//
|
||||
|
||||
#include "read_config.h"
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
int read_config_1() {
|
||||
// std::ifstream is RAII, i.e. no need to call close
|
||||
std::ifstream cFile("/home/lakinduakash/wh.config");
|
||||
if (cFile.is_open()) {
|
||||
std::string line;
|
||||
while (getline(cFile, line)) {
|
||||
line.erase(std::remove_if(line.begin(), line.end(), isspace),
|
||||
line.end());
|
||||
if (line[0] == '#' || line.empty())
|
||||
continue;
|
||||
auto delimiterPos = line.find("=");
|
||||
auto name = line.substr(0, delimiterPos);
|
||||
auto value = line.substr(delimiterPos + 1);
|
||||
std::cout << name << " " << value << '\n';
|
||||
}
|
||||
|
||||
} else {
|
||||
std::cerr << "Couldn't open config file for reading.\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
20
src/ui/read_config.h
Normal file
20
src/ui/read_config.h
Normal file
@ -0,0 +1,20 @@
|
||||
//
|
||||
// Created by lakinduakash on 14/04/19.
|
||||
//
|
||||
|
||||
#ifndef WIHOTSPOT_READ_CONFIG_H
|
||||
#define WIHOTSPOT_READ_CONFIG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int read_config_1();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif //WIHOTSPOT_READ_CONFIG_H
|
Loading…
Reference in New Issue
Block a user