Remove boost as a dependency

This commit is contained in:
dokutan 2020-02-10 15:24:46 +01:00
parent 1a20302c28
commit a31cd2c48b
3 changed files with 127 additions and 8 deletions

View file

@ -10,7 +10,6 @@ As a result there will be no changes to this program, unless I overlooked some f
### Linux
- Install the dependencies:
- libusb
- boost
- Clone this repo or download a release and run
``
sudo make install
@ -27,10 +26,10 @@ sudo make uninstall
### OpenBSD
- Install dependencies: libusb1 and boost
- Install dependencies: libusb1
- Clone this repo and compile with
```
c++ mouse_m908.cpp -o mouse_m908 -Wall -O2 -I/usr/local/include/libusb-1.0 -L/usr/local/lib -lusb-1.0 -I /usr/local/include/
c++ mouse_m908.cpp -o mouse_m908 -Wall -O2 -I/usr/local/include/libusb-1.0 -L/usr/local/lib -lusb-1.0
```
- The --kernel-driver option is required

117
include/load_config.cpp Normal file
View file

@ -0,0 +1,117 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
/*
* This is a standalone .ini parser, written to replace boost property
* tree in the mouse_m908 project. It is not intended to be a general
* purpose replacement.
*
*/
#include <iostream>
#include <fstream>
#include <regex>
#include <string>
#include <map>
class simple_ini_parser{
private:
std::map< std::string, std::string > _ini_values;
public:
// read and parse ini file
int read_ini( std::string path );
// get values
std::string get( std::string key, std::string default_value );
// print all key-value pairs
int print_all();
};
// read and parse ini file
int simple_ini_parser::read_ini( std::string path ){
// open file
std::ifstream inifile;
inifile.open( path );
if( !inifile.is_open() )
return 1;
// go through each line
std::string line, current_section = "";
while( std::getline( inifile, line ) ){
// empty line ?
if( line.length() == 0 )
continue;
// comment ?
if( line[0] == ';' || line[0] == '#' )
continue;
// remove whitespace
line = std::regex_replace( line, std::regex("[[:space:]]"), "" );
// section header?
if( std::regex_match( line, std::regex("\\[[[:print:]]+\\]") ) ){
current_section = std::regex_replace( line, std::regex("[\\[\\]]"), "" ) + ".";
continue;
}
// key=value ?
if( std::regex_match( line, std::regex("[[:print:]]+=[[:print:]]+") ) ){
_ini_values.emplace( current_section + std::regex_replace( line, std::regex("=[[:print:]]+"), "" ),
std::regex_replace( line, std::regex("[[:print:]]+="), "" ) );
}
}
// close file
inifile.close();
return 0;
}
// get values
std::string simple_ini_parser::get( std::string key, std::string default_value ){
// check if key exists
if( _ini_values.find( key ) != _ini_values.end() ){
return _ini_values.at( key );
} else{
return default_value;
}
}
// print all key-value pairs
int simple_ini_parser::print_all(){
for( auto i : _ini_values ){
std::cout << i.first << "=" << i.second << "\n";
}
return 0;
}

View file

@ -24,12 +24,11 @@
#include <iostream>
#include <exception>
#include <regex>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <getopt.h>
#include "include/mouse_m908.h"
#include "include/print_help.cpp"
#include "include/load_config.cpp"
int main( int argc, char **argv ){
@ -114,8 +113,12 @@ int main( int argc, char **argv ){
//load and write config
if( flag_config ){
try{
boost::property_tree::ptree pt;
boost::property_tree::ini_parser::read_ini(string_config, pt);
simple_ini_parser pt;
if( pt.read_ini( string_config ) != 0 ){
std::cout << "Could not open configuration file.\n";
return 1;
}
//parse config file
//profile 1
@ -522,7 +525,7 @@ int main( int argc, char **argv ){
if( std::regex_match( string_number, std::regex("[0-9]+") ) ){
number = (int)stoi(string_number);
} else{
std::cout << "aWrong argument, expected 1-15.\n";
std::cout << "Wrong argument, expected 1-15.\n";
return 1;
}