summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2018-05-18 08:21:56 -0600
committerAaron Ball <nullspoon@oper.io>2018-05-18 08:24:35 -0600
commit9de9c5bb26bc73a5b45b43b1c55cff67b1be17af (patch)
tree47ad0da7332661836028f339e86e513e6ad37114 /main.c
downloadcini-9de9c5bb26bc73a5b45b43b1c55cff67b1be17af.tar.gz
cini-9de9c5bb26bc73a5b45b43b1c55cff67b1be17af.tar.xz
Initial commitHEADmaster
Will return ini sections, with and without keys (--no-keys). Will also return all lines with matching keys, regardless of section. All source files contain GPLv3 license header
Diffstat (limited to 'main.c')
-rw-r--r--main.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..67a368f
--- /dev/null
+++ b/main.c
@@ -0,0 +1,80 @@
+// Cini is a command line tool to parse ini files
+// Copyright (C) 2018 Aaron Ball <nullspoon@oper.io>
+//
+// 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, see <http://www.gnu.org/licenses/>.
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "str.h"
+#include "ini.h"
+
+
+int main(int argc, char* argv[]) {
+ int i = 1; // Yep, positive 1, skips action arg
+ char* action = "";
+ char* file = "";
+ char* key = "";
+ char* section = "";
+ int hidekeys = 0;
+
+
+ // Parse args
+ for(; i<argc; i++) {
+ if(strcmp(argv[i], "--no-keys") == 0) {
+ hidekeys = 1;
+ } else if(strcmp(argv[i], "-f") == 0 || strcmp(argv[i], "--file") == 0) {
+ i++;
+ file = argv[i];
+ } else if(strcmp(argv[i], "-k") == 0 || strcmp(argv[i], "--key") == 0) {
+ i++;
+ key = argv[i];
+ } else if(strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--section") == 0) {
+ i++;
+ section = argv[i];
+ } else {
+ action = argv[i];
+ }
+ }
+
+ // Ensure action is specified
+ if(action[0] == '\0') {
+ fprintf(stderr, "Action required\n");
+ return 1;
+ }
+
+ // Ensure ini file path is specified
+ if(file[0] == '\0') {
+ fprintf(stderr, "Path to ini file required (-f,--file)\n");
+ return 1;
+ }
+
+ if(strcmp(action, "section") == 0) {
+ if(section[0] == '\0') {
+ printf("Section name required (-s,--section)\n");
+ return 1;
+ }
+ return ini_getsection(file, section, hidekeys);
+ } else if(strcmp(action, "key") == 0) {
+ if(key[0] == '\0') {
+ printf("Key required (-k,--key)\n");
+ return 1;
+ }
+ return ini_getbykey(file, key);
+ }
+
+ fprintf(stderr, "Unknown option '%s'\n", action);
+ return 1;
+}

Generated by cgit