commit df91f017ac504ee6e34a3adf99aa44c13940816c
parent d1c1e49dd00046dbb65470f78f7b7d461e3750e7
Author: kocotian <kocotian@kocotian.pl>
Date: Fri, 6 Aug 2021 12:05:28 +0000
stac script updates; README. Version 1.0
Diffstat:
D | README | | | 33 | --------------------------------- |
A | README.md | | | 60 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
M | config.mk | | | 6 | +++--- |
M | stac | | | 19 | ++++++++++++++++++- |
4 files changed, 81 insertions(+), 37 deletions(-)
diff --git a/README b/README
@@ -1,33 +0,0 @@
-stac
-====
-
-stac is a page generator wrote in C99 initially for my webpage.
-This is a simple "compiler" that takes HTML with nested C code on input, and
-produces HTML on output. Input and nesting C code was inspired by node.c
-created by Tsoding (https://github.com/tsoding/node.c).
-
-Usage
-=====
-generate (generate.c) takes minimum one argument:
-* first argument is a file with content.
-* second, optional argument is a template. Optional, because content can
- contain template variable.
-
-generate is used by Makefile
-
-Structure
-=========
-Content is just content, but it can also contain variables. Variable is
-a line starting with @, followed by variable name (single word) and variable
-content (anything until new line).
-Examples:
- @title My title
- @template blog
-
-Template is HTML code, but can write nested code surrounded by `%` signs.
-For example, this will print "Hello!" 255 times:
-
- <!DOCTYPE html>
- %for (int i = 0; i < 255; ++i) {%
- Hello!
- %}%
diff --git a/README.md b/README.md
@@ -0,0 +1,60 @@
+# stac
+------
+
+stac is a simple programming language which can be used to generate static,
+but also dynamic content - it reads a file with embedded C code onto input
+and writes out compilable C code to output. Finally good alternative to PHP,
+node.js and other bloatware!
+
+Slightly inspired by node.c created by Tsoding:
+ (https://github.com/tsoding/node.c).
+
+## Usage
+--------
+Use `stac` script - just give input (.stac) file and you are ready to go!
+you can also add optional arguments:
+* `[-o OUTPUT]` - give an output file, without that option stac will
+ produce content to stdout
+* `[-t TEMPLATE]` - template file; usable for building more advanced
+ websites
+* `[-CC CC]` - compiler to use (by default gcc)
+* `[-CFLAGS FLAGS]` - additional flags for the compiler
+
+For example:
+```
+% ./stac in/index.stac
+<prints compiled in/index.stac>
+% ./stac -t templates/basic.stac in/index.stac
+<prints compiled in/index.stac inside template templates/basic.stac>
+```
+
+You can also use a `compile` script to just generate C code - syntax is
+just like in `stac` script, but without `[-CFLAGS]` and `[-CC]` options.
+
+## Introduction
+---------------
+stac code is just data. In that data you can embed C code - you must
+surround it by percent signs. Example:
+```
+<html>
+ <body>
+ <p>% echo("Welcome from C-mode!"); %</p>
+ </body>
+</html>
+```
+
+You can also embed plain data inside C code - of course, just by
+surrounding the data by percent signs - for example write:
+```
+<html>
+ <body>
+ % for (int i = 0; i < 32; ++i) {
+ % Hello from <b>data-mode</b>! %
+ } %
+ </body>
+</html>
+```
+and you have loop which will produce data 32 times! Awesome!
+
+Technically, the data-mode chunk is statement, more precisely -
+`write()` function, so it will print text to a file.
diff --git a/config.mk b/config.mk
@@ -1,7 +1,7 @@
# basics
-MAJORVERSION = 0
-SUBVERSION = 2
-PATCHLEVEL = 5
+MAJORVERSION = 1
+SUBVERSION = 0
+PATCHLEVEL = 0
BUILDNAME = vanilla
VERSION = ${MAJORVERSION}.${SUBVERSION}.${PATCHLEVEL}-${BUILDNAME}
diff --git a/stac b/stac
@@ -1,12 +1,29 @@
#!/bin/sh
-CC=gcc
+CC="gcc"
+
+while true; do
+ case $1 in
+ -CC)
+ CC="$2"
+ shift 2
+ ;;
+ -CFLAGS)
+ CFLAGS="$2"
+ shift 2
+ ;;
+ *)
+ break
+ ;;
+ esac
+done
make generator > /dev/null || exit 1
./compile $@ > /tmp/stac.$$.c || exit 1
${CC} /tmp/stac.$$.c -o /tmp/stac.$$ -Iinclude -I. \
+ ${CFLAGS} \
util.o assemble.o str.o libstac/libstac.o || {
rm /tmp/stac.$$.c
exit 1