commit 15d731dae87fe564d86ddbc97468a38058e702d0
Author: Anton Konyahin <me@konyahin.xyz>
Date: Fri, 31 Dec 2021 17:03:11 +0300
first commit
Diffstat:
5 files changed, 84 insertions(+), 0 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -0,0 +1,21 @@
+MIT/X Consortium License
+
+(C)opyright 2021 Anton Konyahin <me@konyahin.xyz>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
diff --git a/Makefile b/Makefile
@@ -0,0 +1,12 @@
+.POSIX:
+.SUFFIXES:
+
+BIN = sttemp
+CC = cc
+CFLAGS = -W -O
+
+all: src/main.c src/config.h
+ $(CC) $(CFLAGS) src/main.c -o $(BIN)
+
+clean:
+ rm $(BIN)
diff --git a/README b/README
@@ -0,0 +1,4 @@
+STTEMP
+-----
+
+Simple template manager.
diff --git a/src/config.h b/src/config.h
@@ -0,0 +1,5 @@
+/* See LICENSE file for copyright and license details. */
+
+char *template_dir = "/Users/antonkonjahin/projects/templates/";
+char *pattern_start = "{";
+char *pattern_end = "}";
diff --git a/src/main.c b/src/main.c
@@ -0,0 +1,42 @@
+#include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+
+void show_usage() {
+ printf("sttemp - simple template manager\n");
+ printf("Usage:\n\tsttemp template_name\n");
+}
+
+int main(int argc, char *argv[]) {
+ if (argc < 2) {
+ show_usage();
+ return 1;
+ }
+
+ char* template_name = argv[1];
+ if (strcmp("-h", template_name) == 0) {
+ show_usage();
+ return 0;
+ }
+
+ printf("Template directory: %s\n", template_dir);
+ printf("Template: %s var %s\n", pattern_start, pattern_end);
+
+ size_t temp_len = strlen(template_name) + strlen(template_dir) + 1;
+ char *temp_path = (char*) malloc(temp_len);
+ strcpy(temp_path, template_dir);
+ strcat(temp_path, template_name);
+
+ FILE *template = fopen(temp_path, "r");
+ if (template == NULL) {
+ fprintf(stderr, "Template doesn't exist: %s", temp_path);
+ return 1;
+ }
+
+ fclose(template);
+ free(temp_path);
+
+ return 0;
+}