]> jfr.im git - irc/thales.git/commitdiff
Add configuration file routines.
authorDmitry Bogatov <redacted>
Sun, 14 Oct 2012 08:01:07 +0000 (12:01 +0400)
committerDmitry Bogatov <redacted>
Sun, 14 Oct 2012 08:01:07 +0000 (12:01 +0400)
/* Must write documentation */

src/Makefile.am
src/cmd.c
src/cmd.h
src/conf.c [new file with mode: 0644]
src/conf.h [new file with mode: 0644]
src/main.c

index c4c49b6e5a017f8c6dad305eb28f58620ac812ae..fcf40ceb69246842f5b81f712b971b8f93b57988 100644 (file)
@@ -1,2 +1,2 @@
 bin_PROGRAMS = thales
-thales_SOURCES = main.c cmd.h cmd.c
+thales_SOURCES = main.c cmd.h cmd.c conf.h conf.c
index 672e768a12b04bb31b3cd5e3aab270b2dd7f5b0e..9a7029ccb76ce6bd46f35189d6bae5385479b7da 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -50,12 +50,11 @@ void
 parse_cmdopts(struct cmd_options *opts, int argc, char **argv)
 {
   int val;
-  const char *optstr = "hvdC:";
+  const char *optstr = "hvC:";
   struct option longopts[] = {
     {"help", no_argument, NULL, 'h'},
     {"version", no_argument, NULL, 'v'},
     {"config", required_argument, NULL, 'C'},
-    {"debug", no_argument, &opts->debug, 'd'}
   };
   while ((val = getopt_long(argc, argv, optstr, longopts, NULL))!= EOF)
     switch (val)
index 8e146bad2366be4c557d1c45df4bda5b3833e8ae..e05cfe338d2535cfea2d814078e0b33743bc0681 100644 (file)
--- a/src/cmd.h
+++ b/src/cmd.h
@@ -18,7 +18,6 @@ this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #define CMD_H
 struct cmd_options {
   const char *conf_filename;
-  int debug;
 };
 void parse_cmdopts(struct cmd_options *opts, int argc, char **argv);
 
diff --git a/src/conf.c b/src/conf.c
new file mode 100644 (file)
index 0000000..cc51fa7
--- /dev/null
@@ -0,0 +1,38 @@
+/*  Configuration file parsing program of GNU Thales.  Copyright (C)
+2012 Free Software Foundation, Inc.  This file is part of GNU Thales.
+
+GNU Thales 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.
+
+GNU Make 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, see <http://www.gnu.org/licenses/>.  */
+#include <config.h>
+#include "conf.h"
+#include <stdbool.h>
+#include <stdlib.h>
+
+#define countof(x) sizeof(x)/sizeof(0[x])
+FILE*
+default_config_file(void)
+{
+  /* Have to replace hardcoded pathes to
+     Automake generated */
+  const char *filenames[] ={
+    getenv("THALES_CONFIG"),
+    "~/.thales",
+    "/etc/thales"
+  };
+  int index;
+  FILE *config_file;
+  for (index = 0; index != countof(filenames); ++index)
+    if (filenames[index] && (config_file = fopen(filenames[index], "w")))
+      return config_file;
+  return NULL;
+}
diff --git a/src/conf.h b/src/conf.h
new file mode 100644 (file)
index 0000000..09fa766
--- /dev/null
@@ -0,0 +1,23 @@
+/*  Configuration file parsing program of GNU Thales.  Copyright (C)
+2012 Free Software Foundation, Inc.  This file is part of GNU Thales.
+
+GNU Thales 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.
+
+GNU Make 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, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef CONF_H
+#define CONF_H
+#include <stdio.h>
+
+FILE* default_config_file(void);
+
+#endif
index ea7621c73d40273042c61a71adf9788bcabb8419..3f87596c73748d071d0d70390631025bd3a7979d 100644 (file)
@@ -21,8 +21,7 @@ int
 main(int argc, char **argv)
 {
   struct cmd_options opts = {
-    .debug = 0,
-    .conf_filename = NULL;
+    .conf_filename = NULL
   };
   parse_cmdopts(&opts, argc, argv);
   return 0;