summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile13
-rw-r--r--entangled.dhall99
-rw-r--r--rccat.c38
-rw-r--r--rccat.md2
4 files changed, 149 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 3a1e308..6d8f67e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,14 +1,27 @@
+# ~\~ language=Make filename=Makefile
+# ~\~ begin <<rccat.md|Makefile>>[0]
PREFIX ?= /usr/local
INSTALL ?= install
INSTALL_PROGRAM ?= $(INSTALL)
+# ~\~ begin <<rccat.md|make-all>>[0]
all: build
+# ~\~ end
+# ~\~ begin <<rccat.md|make-build>>[0]
build:
$(CC) -o rccat rccat.c
+# ~\~ end
+# ~\~ begin <<rccat.md|make-clean>>[0]
clean:
$(RM) rccat
+# ~\~ end
+# ~\~ begin <<rccat.md|make-install>>[0]
install:
$(INSTALL_PROGRAM) -d $(PREFIX)/bin
$(INSTALL_PROGRAM) -m755 rccat $(PREFIX)/bin
+# ~\~ end
+# ~\~ begin <<rccat.md|make-uninstall>>[0]
uninstall:
$(RM) $(PREFIX)/bin/rccat
+# ~\~ end
+# ~\~ end
diff --git a/entangled.dhall b/entangled.dhall
new file mode 100644
index 0000000..23afb56
--- /dev/null
+++ b/entangled.dhall
@@ -0,0 +1,99 @@
+{- Entangled configuration file
+ ============================
+
+ This configuration uses the Dhall language, see https://dhall-lang.org/.
+
+ This file represents a record, as can be seen from the `let ... in { ... }`
+ structure. Configuration for the Entangled daemon and command-line utility
+ is stored in the `entangled` member of the record. Other fields are open
+ for use by `pandoc` filters or other tools.
+
+ If you want to check the configuration for correctness, run
+
+ dhall <<< ./entangled.dhall
+ -}
+
+{- Schema
+ ------
+
+ The schema is loaded here. It is recommended to use a schema from a
+ released version of Entangled.
+
+ The hash is not strictly needed, but it ensures that you get the version
+you're
+ expecting to, or raise an error. You can generate the correct hash by running
+
+ dhall hash <<< <location to schema>
+ -}
+let entangled = https://raw.githubusercontent.com/entangled/entangled/v1.0.1/data/config-schema.dhall
+ sha256:9fd18824499379eee53b974ca7570b3bc064fda546348d9b31841afab3b053a7
+
+{- Languages
+ ---------
+
+ Entangled has many programming languages configured by default. If your
+ favourite is not in there you can add them here. The most common commenting
+ patterns are included in `entangled.comments`
+
+ | name | comment pattern |
+ | ------------ | --------------- |
+ | hash | `# ...` |
+ | lispStyle | `; ...` |
+ | mlStyle | `(* ... *)` |
+ | cStyle | `/* ... */` |
+ | cppStyle | `// ...` |
+ | haskellStyle | `-- ...` |
+ | texStyle | `% ...` |
+ | xmlStyle | `<!-- ... -->` |
+
+ The language identifiers are the classes that can be used to identify a code
+ block is in a certain language. So,
+
+ ``` {.c++ #hello}
+ std::cout << "Hello, World!\n";
+ ```
+
+ is recognized as a C++ block, because `c++` is in the identifier list of the C++
+ language. In this example we add some esotheric languages.
+ -}
+let intercalComment = entangled.Comment.Line "PLEASE NOTE: "
+
+let languages = entangled.languages #
+ [ { name = "Unlambda", identifiers = ["unlambda"], comment = entangled.comments.hash }
+ , { name = "Intercal", identifiers = ["intercal"], comment = intercalComment }
+ ]
+
+{- Database
+ --------
+
+ Entangled is powered by SQLite3. This specifies where the database is
+ stored. An entry of `None Text`, which is the default, keeps the database
+ in memory, but this way you cannot insert new files on a running daemon.
+ -}
+let database = Some ".entangled/db.sqlite"
+
+{- Watch list
+ ----------
+
+ List of glob patterns that the daemon needs to watch for changes. The order
+ in which files are listed here matters. If code blocks append on previous
+ blocks in different files, the blocks are concatenated in the same order as
+ the files are listed here. In the case of a glob pattern, this is
+ alpha-numerical order (same as `ls`).
+ -}
+let watchList = [ "lit/*.md" ]
+
+in { entangled = entangled.Config :: { database = database
+ , watchList = watchList
+ , languages = languages }
+
+{- Extra options
+ -------------
+
+ If you are using Entangled filters (https://github.com/entangled/filters),
+ you may want to include some extra configuration here. These settings are
+ ignored by the entangled executable.
+ -}
+ , jupyter = { name = "Python", kernel = "python3" }
+ }
+
diff --git a/rccat.c b/rccat.c
index 9a1d60e..1c31e38 100644
--- a/rccat.c
+++ b/rccat.c
@@ -1,11 +1,17 @@
+/* ~\~ language=C filename=rccat.c */
+/* ~\~ begin <<rccat.md|rccat.c>>[0] */
+/* ~\~ begin <<rccat.md|includes>>[0] */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
+/* ~\~ end */
+/* ~\~ begin <<rccat.md|constants>>[0] */
#define BUF_SIZE 10
+/* ~\~ begin <<rccat.md|colors>>[0] */
#define KNRM "\x1B[0m"
#define KRED "\x1B[31m"
#define KGRN "\x1B[32m"
@@ -15,12 +21,21 @@
#define KWHT "\x1B[37m"
const char *colors[] = {KNRM, KRED, KGRN, KYEL, KMAG, KCYN};
+/* ~\~ end */
+/* ~\~ end */
+/* ~\~ begin <<rccat.md|colors-function>>[0] */
int lastcolor = 0;
void printColors(char *text)
{
-
+ /* ~\~ begin <<rccat.md|colors-notty>>[0] */
+ if (!(isatty(STDOUT_FILENO))) {
+ printf("%s", text);
+ return;
+ }
+ /* ~\~ end */
if (text) {
+ /* ~\~ begin <<rccat.md|colors-normal>>[0] */
for (int i = 0; i < strlen(text); ++i) {
int color = 0;
do {
@@ -29,27 +44,39 @@ void printColors(char *text)
lastcolor = color;
printf("%s%c", colors[color], text[i]);
}
+ /* ~\~ end */
}
+ /* ~\~ begin <<rccat.md|colors-reset>>[0] */
printf("%s", KWHT);
+ /* ~\~ end */
}
+/* ~\~ end */
+/* ~\~ begin <<rccat.md|main-function>>[0] */
int main(int argc, char *argv[])
{
+ /* ~\~ begin <<rccat.md|main-body>>[0] */
srand(time(NULL));
char buffer[BUF_SIZE] = {""};
-
+
for (int i = 0; i < argc; ++i) {
+ /* ~\~ begin <<rccat.md|parse-arg>>[0] */
if (strcmp(argv[i], "-") == 0 || argc == 1) {
+ /* ~\~ begin <<rccat.md|print-from-stdin>>[0] */
while (fgets(buffer, BUF_SIZE, stdin) != NULL) {
printColors(buffer);
}
clearerr(stdin);
+ /* ~\~ end */
} else if (i >= 1) {
+ /* ~\~ begin <<rccat.md|open-file>>[0] */
FILE *fp;
fp = fopen(argv[i], "r");
if (!(fp)) {
fprintf(stderr, "rccat: %s: no such file or directory.\n", argv[i]);
}
+ /* ~\~ end */
+ /* ~\~ begin <<rccat.md|read-file>>[0] */
size_t got;
while ((got = fread(buffer, 1, BUF_SIZE -1, fp))) {
buffer[got] = '\0';
@@ -57,9 +84,16 @@ int main(int argc, char *argv[])
}
if (ferror(fp))
fprintf(stderr, "Error: can't read %s\n", argv[1]);
+ /* ~\~ end */
+ /* ~\~ begin <<rccat.md|close-file>>[0] */
fclose(fp);
+ /* ~\~ end */
}
+ /* ~\~ end */
}
+ /* ~\~ end */
return EXIT_SUCCESS;
}
+/* ~\~ end */
+/* ~\~ end */
diff --git a/rccat.md b/rccat.md
index 72d77cf..ff0a3dd 100644
--- a/rccat.md
+++ b/rccat.md
@@ -59,7 +59,7 @@ These are all the codes for the colors we want, and an array to order them nicel
int lastcolor = 0;
void printColors(char *text)
{
- <<colors=notty>>
+ <<colors-notty>>
if (text) {
<<colors-normal>>
}