diff --git a/.bin/alldoc b/.bin/alldoc
new file mode 100644
index 0000000..aa8448c
--- /dev/null
+++ b/.bin/alldoc
@@ -0,0 +1,159 @@
+#!/usr/bin/python3
+
+#
+# Copyright(c) 2017 Daniel Knüttel
+#
+
+# This program is free software.
+# Anyways if you think this program is worth it
+# and we meet shout a drink for me.
+
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+# Dieses Programm ist Freie Software: Sie können es unter den Bedingungen
+# der GNU Affero General Public License, wie von der Free Software Foundation,
+# Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
+# veröffentlichten Version, weiterverbreiten und/oder modifizieren.
+#
+# Dieses Programm wird in der Hoffnung, dass es nützlich sein wird, aber
+# OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
+# Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
+# Siehe die GNU Affero General Public License für weitere Details.
+#
+# Sie sollten eine Kopie der GNU Affero General Public License zusammen mit diesem
+# Programm erhalten haben. Wenn nicht, siehe .
+
+
+"""
+alldoc -- extract reStructuredText docstrings from all
+sourcefiles.
+
+This does include non-python files/languages.
+
+Invoke alldoc using
+::
+
+ python3 alldoc.py {}
+
+
+
+"""
+
+import logging
+# logging.basicConfig(level = logging.DEBUG)
+logging.basicConfig()
+
+
+start_alldoc = [ "", "", "startdoc", "SDOC"]
+stop_alldoc = ["", "", "stopdoc", "EDOC"]
+
+def indexof(str_, substr):
+ """
+ This is handy if you want to get the next substr.
+ """
+ try:
+ return str_.index(substr)
+ except:
+ return float("inf")
+
+def extract_docs(str_, start_alldoc = start_alldoc, stop_alldoc = stop_alldoc):
+ """
+ Extract all docstrings starting with ``start_alldoc`` and stopping with
+ ``stop_alldoc``.
+
+ For instance:
+ ::
+
+ /*
+
+ This is a docstring
+
+ */
+
+ """
+ lines_done = 0
+ while(1):
+ next_doc_start, start = min([(indexof(str_, start), start) for start in start_alldoc])
+ if(next_doc_start == float("inf")):
+ logging.debug("no more docstrings found in line "+ str(lines_done))
+ break
+ logging.debug("found docstart " + start)
+ unused, str_ = str_[:next_doc_start], str_[next_doc_start + len(start):]
+ lines_done += unused.count("\n")
+ logging.debug("docstart is in " + str(lines_done))
+ doc_stop, token = min([(indexof(str_, stop), stop) for stop in stop_alldoc])
+ if(doc_stop == float("inf")):
+ raise ExtractException("unterminated docstart: " + start + " in line " + str(lines_done))
+ doc, str_ = str_[:doc_stop], str_[doc_stop + len(token):]
+ logging.debug("found docstop " + token)
+ yield doc
+ lines_done += doc.count("\n")
+ logging.debug("docstop is in " + str(lines_done))
+
+def docs_from_file(path, delim = "\n\n"):
+ """
+ Read all docstrings from one file.
+ """
+ with open(path) as f:
+ logging.debug("reading file " + path)
+ str_ = f.read()
+ docs = delim.join(extract_docs(str_))
+ f.close()
+ return docs
+
+def collect_docs(files, delim = "\n\n"):
+ """
+ Read all docstrings from multiple files
+ """
+ for file_ in files:
+ yield docs_from_file(file_, delim)
+
+def generate_rst_head(str_, underscore = "="):
+ """
+ Generate a rst Heading.
+ """
+ return str_ + "\n" + underscore * len(str_) + "\n"
+
+def generate_docfile(fname, files, delim = "\n\n", add_rst_head = True):
+ """
+ Read all docstrings and output one file.
+
+ FIXME: try to spend less memory.
+ """
+ f = open(fname, "w")
+ f.write("".join(["".join(t) for t in zip([generate_rst_head(file) for file in files] , collect_docs(files))]))
+ f.close()
+
+
+
+class ExtractException(Exception):
+ def __init__(self, *args):
+ Exception.__init__(self, *args)
+
+if __name__ == "__main__":
+ import sys
+ if(len(sys.argv) < 3):
+ print("Usage:", sys.argv[0], "outfile infile {infile}")
+ print("extract docstrings from non-python files")
+ print("start tokens: ", start_alldoc)
+ print("stop tokens: ", stop_alldoc)
+ sys.exit(1)
+ outfile = sys.argv[1]
+ infiles = sys.argv[2:]
+ try:
+ generate_docfile(outfile, infiles)
+ except Exception as e:
+ print("Error:", e)
+ sys.exit(1)
diff --git a/Makefile b/Makefile
index 84a500a..1e416c5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,16 @@
CC=gcc
CFLAG= -O -g -o
+
+alldoc=python3 $(PWD)/.bin/alldoc
+
objects=main.o\
playfield.o\
input_output.o
+headers=conf.h\
+ playfield.h\
+ input_output.h
+
all:main
%.o:%.c
@@ -15,3 +22,12 @@ main: clean $(objects)
clean:
rm $(objects) || true
+
+doc.rst:$(headers)
+ $(alldoc) doc.rst.tmp $(headers)
+ printf "Documentation\n_____________\n\n" > doc.rst
+ cat doc.rst.tmp >> doc.rst
+ rm doc.rst.tmp
+
+doc.pdf:
+ rst2pdf doc.rst
diff --git a/conf.h b/conf.h
index 9ad470c..4609e89 100644
--- a/conf.h
+++ b/conf.h
@@ -1,7 +1,74 @@
+/*
+* Copyright(c) 2017 Daneil Knuettel
+*/
+
+/* This program is free software.
+* Anyways if you think this program is worth it
+* and we meet shout a drink for me.
+*/
+
+
+/* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero 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 Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*
+* Dieses Programm ist Freie Software: Sie können es unter den Bedingungen
+* der GNU Affero General Public License, wie von der Free Software Foundation,
+* Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
+* veröffentlichten Version, weiterverbreiten und/oder modifizieren.
+*
+* Dieses Programm wird in der Hoffnung, dass es nützlich sein wird, aber
+* OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
+* Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
+* Siehe die GNU Affero General Public License für weitere Details.
+*
+* Sie sollten eine Kopie der GNU Affero General Public License zusammen mit diesem
+* Programm erhalten haben. Wenn nicht, siehe .
+*/
+
#ifndef __conf__h_
#define __conf__h_
+/*
+
+This file contains all configuration makros
+used by the game. The default makros are:
+
+::
+
+ #define WIDTH 50
+ #define LINES 20
+
+
+ #define KEY_DEFAULT '_'
+ #define KEY_RIGHT 'd'
+ #define KEY_LEFT 'a'
+ #define KEY_EXIT 'q'
+ #define CHAR_ME '#'
+ #define CHAR_ENEMY '*'
+ #define ESCAPE_RED "\033[31m"
+ #define ESCAPE_GREEN "\033[32m"
+ #define ESCAPE_RESET "\033[0m"
+
+ #define CHRS_TO_CLEAR_ESCAPE 7
+
+They should not be set using the compiler's command line options.
+
+
+
+ */
+
+
#define WIDTH 50
#define LINES 20
diff --git a/input_output.c b/input_output.c
index 0c85233..b08dcdb 100644
--- a/input_output.c
+++ b/input_output.c
@@ -1,3 +1,41 @@
+/*
+* Copyright(c) 2017 Daniel Knuettel
+*/
+
+/* This program is free software.
+* Anyways if you think this program is worth it
+* and we meet shout a drink for me.
+*/
+
+
+/* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero 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 Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*
+* Dieses Programm ist Freie Software: Sie können es unter den Bedingungen
+* der GNU Affero General Public License, wie von der Free Software Foundation,
+* Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
+* veröffentlichten Version, weiterverbreiten und/oder modifizieren.
+*
+* Dieses Programm wird in der Hoffnung, dass es nützlich sein wird, aber
+* OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
+* Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
+* Siehe die GNU Affero General Public License für weitere Details.
+*
+* Sie sollten eine Kopie der GNU Affero General Public License zusammen mit diesem
+* Programm erhalten haben. Wenn nicht, siehe .
+*/
+
+
#include
#include
#include
diff --git a/input_output.h b/input_output.h
index f24bcba..0170221 100644
--- a/input_output.h
+++ b/input_output.h
@@ -1,3 +1,40 @@
+/*
+* Copyright(c) 2017 Daneil Knuettel
+*/
+
+/* This program is free software.
+* Anyways if you think this program is worth it
+* and we meet shout a drink for me.
+*/
+
+
+/* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero 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 Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*
+* Dieses Programm ist Freie Software: Sie können es unter den Bedingungen
+* der GNU Affero General Public License, wie von der Free Software Foundation,
+* Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
+* veröffentlichten Version, weiterverbreiten und/oder modifizieren.
+*
+* Dieses Programm wird in der Hoffnung, dass es nützlich sein wird, aber
+* OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
+* Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
+* Siehe die GNU Affero General Public License für weitere Details.
+*
+* Sie sollten eine Kopie der GNU Affero General Public License zusammen mit diesem
+* Programm erhalten haben. Wenn nicht, siehe .
+*/
+
#ifndef __input_output_h_
#define __input_output_h_
#include
@@ -6,6 +43,58 @@
#include
#include
+/*
+
+This file contains all required input/output functions.
+
+There is a special global flag variable
+
+::
+
+ static volatile char EOF_received = 0;
+
+that will be set to ``1``, if the stdin stream reached ``EOF``.
+This flag will break the mainloop.
+
+The following input functions are defined:
+
+::
+
+ char kb_hit(void);
+
+returns 1, if there is a character on stdin.
+
+::
+
+ char get_last_key_or_default(void);
+
+Returns the last entered character from stdin.
+If there is no character it will return the
+default character defined in ``conf.h``.
+
+If stdin reaches ``EOF`` the flag ``EOF_received`` will
+be set.
+
+The following output functions are defined:
+
+::
+
+ void put_line(char * line);
+
+Puts the given line ``line`` of the horizon or playfield
+on the stdout stream. The line is inside a frame and
+highlights special characters according to ``conf.h``.
+
+::
+
+ void clear_screen(void);
+
+Clears the screen. The number of lines and collumns
+are calculated according to ``conf.h``.
+
+
+ */
+
#include "conf.h"
void put_line(char * line);
void clear_screen(void);
diff --git a/main.c b/main.c
index ddf610b..5ba64a0 100644
--- a/main.c
+++ b/main.c
@@ -1,3 +1,41 @@
+/*
+* Copyright(c) 2017 Daniel Knüttel
+*/
+
+/* This program is free software.
+* Anyways if you think this program is worth it
+* and we meet shout a drink for me.
+*/
+
+
+/* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero 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 Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*
+* Dieses Programm ist Freie Software: Sie können es unter den Bedingungen
+* der GNU Affero General Public License, wie von der Free Software Foundation,
+* Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
+* veröffentlichten Version, weiterverbreiten und/oder modifizieren.
+*
+* Dieses Programm wird in der Hoffnung, dass es nützlich sein wird, aber
+* OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
+* Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
+* Siehe die GNU Affero General Public License für weitere Details.
+*
+* Sie sollten eine Kopie der GNU Affero General Public License zusammen mit diesem
+* Programm erhalten haben. Wenn nicht, siehe .
+*/
+
+
#include
#include
#include
diff --git a/playfield.c b/playfield.c
index 3769ca4..84dab67 100644
--- a/playfield.c
+++ b/playfield.c
@@ -1,3 +1,41 @@
+/*
+* Copyright(c) 2017 Daniel Knüttel
+*/
+
+/* This program is free software.
+* Anyways if you think this program is worth it
+* and we meet shout a drink for me.
+*/
+
+
+/* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero 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 Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*
+* Dieses Programm ist Freie Software: Sie können es unter den Bedingungen
+* der GNU Affero General Public License, wie von der Free Software Foundation,
+* Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
+* veröffentlichten Version, weiterverbreiten und/oder modifizieren.
+*
+* Dieses Programm wird in der Hoffnung, dass es nützlich sein wird, aber
+* OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
+* Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
+* Siehe die GNU Affero General Public License für weitere Details.
+*
+* Sie sollten eine Kopie der GNU Affero General Public License zusammen mit diesem
+* Programm erhalten haben. Wenn nicht, siehe .
+*/
+
+
#include
#include
#include"conf.h"
diff --git a/playfield.h b/playfield.h
index 4957209..37a7df3 100644
--- a/playfield.h
+++ b/playfield.h
@@ -1,6 +1,89 @@
+/*
+* Copyright(c) 2017 Daneil Knuettel
+*/
+
+/* This program is free software.
+* Anyways if you think this program is worth it
+* and we meet shout a drink for me.
+*/
+
+
+/* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero 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 Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*
+* Dieses Programm ist Freie Software: Sie können es unter den Bedingungen
+* der GNU Affero General Public License, wie von der Free Software Foundation,
+* Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
+* veröffentlichten Version, weiterverbreiten und/oder modifizieren.
+*
+* Dieses Programm wird in der Hoffnung, dass es nützlich sein wird, aber
+* OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
+* Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
+* Siehe die GNU Affero General Public License für weitere Details.
+*
+* Sie sollten eine Kopie der GNU Affero General Public License zusammen mit diesem
+* Programm erhalten haben. Wenn nicht, siehe .
+*/
+
#ifndef __playfield_h_
#define __playfield_h_
+/*
+
+This files contains all functions to control the
+playfield and horizon.
+
+The following functions are defined in this file:
+
+::
+
+ void build_horizon(char *** horizon);
+
+Allocates the horizon according to ``conf.h``.
+In addition to this it prints enough newlines to
+make space in the terminal for the playfield.
+
+::
+
+ void horizon_drop_one_line(char ** horizon);
+
+Moves all objects from one line to the next line of the
+horizon. The first line of the horizon is filled with
+blanks.
+
+::
+
+ void print_horizon(char ** horizon);
+
+Prints the entired horizon usinf ``put_line``.
+
+::
+
+ void delete_horizon(char ** horizon);
+
+Frees the horizon.
+
+::
+
+ char * allocate_playfield(size_t width);
+
+Allocates a playfield with the given width
+(The parameter should be set according to ``conf.h``).
+Fills the string with blanks.
+
+
+ */
+
void build_horizon(char *** horizon);
void horizon_drop_one_line(char ** horizon);
void print_horizon(char ** horizon);