From d50ebc7fdf6543faab8c8b02d30730a9991f02b6 Mon Sep 17 00:00:00 2001
From: AlexeyAB <alexeyab84@gmail.com>
Date: Tue, 06 Dec 2016 11:41:18 +0000
Subject: [PATCH] Fixed command line examples
---
src/option_list.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/src/option_list.c b/src/option_list.c
index f5536e1..f935af3 100644
--- a/src/option_list.c
+++ b/src/option_list.c
@@ -2,6 +2,53 @@
#include <stdio.h>
#include <string.h>
#include "option_list.h"
+#include "utils.h"
+
+list *read_data_cfg(char *filename)
+{
+ FILE *file = fopen(filename, "r");
+ if(file == 0) file_error(filename);
+ char *line;
+ int nu = 0;
+ list *options = make_list();
+ while((line=fgetl(file)) != 0){
+ ++ nu;
+ strip(line);
+ switch(line[0]){
+ case '\0':
+ case '#':
+ case ';':
+ free(line);
+ break;
+ default:
+ if(!read_option(line, options)){
+ fprintf(stderr, "Config file error line %d, could parse: %s\n", nu, line);
+ free(line);
+ }
+ break;
+ }
+ }
+ fclose(file);
+ return options;
+}
+
+int read_option(char *s, list *options)
+{
+ size_t i;
+ size_t len = strlen(s);
+ char *val = 0;
+ for(i = 0; i < len; ++i){
+ if(s[i] == '='){
+ s[i] = '\0';
+ val = s+i+1;
+ break;
+ }
+ }
+ if(i == len-1) return 0;
+ char *key = s;
+ option_insert(options, key, val);
+ return 1;
+}
void option_insert(list *l, char *key, char *val)
{
--
Gitblit v1.10.0