commit 460798bdb01afb226eb6897c8449fd54406525d8
parent 243bbac5cd5bac9e1147c2dcd4c4614cd8b56b30
Author: Dominik Schmidt <doeme@bastli.ethz.ch>
Date: Tue, 4 Sep 2018 21:19:15 +0200
Update to a more reasonable layout
Diffstat:
13 files changed, 110 insertions(+), 77 deletions(-)
diff --git a/daemon.sh b/daemon.sh
@@ -3,4 +3,4 @@
USERNAME="${1}"
PASSWORD="${2}"
-exec amqp-consume --server=backdoor.bastli.ch "--username=${USERNAME}" "--password=${PASSWORD}" --vhost="/" -q print_queue ./pipeline.sh
+exec ./amqp-consume --server=backdoor.bastli.ch:5672 "--username=${USERNAME}" "--password=${PASSWORD}" --vhost="/" -q print_queue ./pipeline.sh
diff --git a/pipeline.sh b/pipeline.sh
@@ -1,7 +1,8 @@
#!/bin/sh
-cd pipeline
-
-./JSON_to_GROFF ../template.roff \
-| ./GROFF_to_printable \
-| ./print
+if [[ ${#@} -eq 1 ]]
+then
+ exec "$1"
+else
+ exec "${1}" | "$0" "${@:2}"
+fi
diff --git a/pipeline/10_JSON_to_GROFF.d b/pipeline/10_JSON_to_GROFF.d
@@ -0,0 +1,64 @@
+module jsontogroff;
+import std.stdio;
+import std.process;
+import std.json;
+import std.array;
+import std.algorithm;
+import std.regex;
+import std.format;
+import std.conv;
+import std.range;
+import std.datetime : Clock;
+
+void main(string[] argv){
+ auto str=stdin.byChunk(4096).map!(a=>cast(char[])a).joiner();
+ auto j=parseJSON(str);
+
+ string positions(){
+ Appender!string app;
+ app~=".na\n";
+ app~=".TS\n";
+ "llxni\n".repeat(j["articles"].array.length).copy(app);
+ app~="===\n";
+ app~="llxbni\n";
+ app~=".\n";
+ double total=0;
+ foreach(ulong ix,art; j["articles"]){
+ double price=art["price"].str.to!double;
+ string name=art["name"].str;
+ ulong amount=art["amount"].integer;
+ auto esc_name=name.replace("\\","\\\\").replace("\n","\n ");
+ app.formattedWrite!"%d\tT{\n%s\nT}\t%.2f\n"(amount,esc_name,price);
+ total+=price * amount;
+ }
+ app~="\n";
+ app.formattedWrite("\tTOTAL\t%.2f\n", total);
+ app~=".TE\n";
+ app~=".al\n";
+ return app.data;
+ }
+ string delegate()[string] tbl=[
+ "sale_id": (){return j["sale_id"].integer.to!string;},
+ "positions": &positions,
+ "today": (){return Clock.currTime.toISOExtString();},
+ ];
+ auto lookup(Captures!(char[]) cap){
+ auto b=cap[1];
+ auto fct=b in tbl;
+ if(!fct){
+ return "{{"~b~"}}";
+ }
+ else{
+ return cast(const(char)[])(*fct)();
+ }
+ }
+ File tmplate=File(environment.get("GROFF_TEMPLATE"), "r");
+ scope(exit)tmplate.close();
+ auto reg=ctRegex!("\\{\\{([^}]+)\\}\\}");
+ auto sink=stdout.lockingTextWriter;
+
+ foreach(line; tmplate.byLine(KeepTerminator.yes)){
+ replaceAllInto!(lookup)(sink, line, reg);
+ }
+
+}
diff --git a/pipeline/15_iconv.sh b/pipeline/15_iconv.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+LANG=de_CH.UTF-8 exec iconv -f UTF8 -t ASCII//TRANSLIT
diff --git a/pipeline/20_GROFF_to_printable b/pipeline/20_GROFF_to_printable
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+groff -k -Tascii -t | sed 's%\o033\[33m%%g'
+echo
+echo
+echo
+echo
+echo
+echo
+echo
+echo
+echo
diff --git a/pipeline/30_ansifilter b/pipeline/30_ansifilter
@@ -0,0 +1 @@
+/usr/bin/ansifilter+
\ No newline at end of file
diff --git a/pipeline/90_outfilter b/pipeline/90_outfilter
@@ -0,0 +1,3 @@
+#!/bin/sh
+#Filter empty lines at the beginning of the file
+exec awk '/$^/ {if(a==0){next;}} {a=1;print $0}'
diff --git a/pipeline/99_print b/pipeline/99_print
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+cat
+#lp -d NCR_7167_Receipt_-_Slip -o document-format=text/plain -
diff --git a/pipeline/GROFF_to_printable b/pipeline/GROFF_to_printable
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-groff -k -Tutf8 -t
diff --git a/pipeline/JSON_to_GROFF.d b/pipeline/JSON_to_GROFF.d
@@ -1,62 +0,0 @@
-import std.stdio;
-import std.json;
-import std.array;
-import std.algorithm;
-import std.regex;
-import std.format;
-import std.conv;
-import std.range;
-import std.datetime : Clock;
-
-void main(string[] argv){
- auto str=stdin.byChunk(4096).map!(a=>cast(char[])a).joiner();
- auto j=parseJSON(str);
-
- string positions(){
- Appender!string app;
- app~=".na\n";
- app~=".TS\n";
- "llxni\n".repeat(j["articles"].array.length).copy(app);
- app~="===\n";
- app~="llxbni\n";
- app~=".\n";
- double total=0;
- foreach(ulong ix,art; j["articles"]){
- double price=art["price"].str.to!double;
- string name=art["name"].str;
- ulong amount=art["amount"].integer;
- auto esc_name=name.replace("\\","\\\\").replace("\n","\n ");
- app.formattedWrite!"%d\tT{\n%s\nT}\t%.2f\n"(amount,esc_name,price);
- total+=price * amount;
- }
- app~="\n";
- app.formattedWrite("\tTOTAL\t%.2f\n", total);
- app~=".TE\n";
- app~=".al\n";
- return app.data;
- }
- string delegate()[string] tbl=[
- "sale_id": (){return j["sale_id"].integer.to!string;},
- "positions": &positions,
- "today": (){return Clock.currTime.toISOExtString();},
- ];
- auto lookup(Captures!(char[]) cap){
- auto b=cap[1];
- auto fct=b in tbl;
- if(!fct){
- return "{{"~b~"}}";
- }
- else{
- return cast(const(char)[])(*fct)();
- }
- }
- File tmplate=File(argv[1], "r");
- scope(exit)tmplate.close();
- auto reg=ctRegex!("\\{\\{([^}]+)\\}\\}");
- auto sink=stdout.lockingTextWriter;
-
- foreach(line; tmplate.byLine(KeepTerminator.yes)){
- replaceAllInto!(lookup)(sink, line, reg);
- }
-
-}
diff --git a/pipeline/print b/pipeline/print
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-cat
diff --git a/start_pipeline.sh b/start_pipeline.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+cd pipeline
+export GROFF_TEMPLATE="../template.roff"
+EXES=()
+for file in *
+do
+ if [[ -x "$file" ]]
+ then
+ EXES+=("./$file")
+ fi
+done
+exec ../pipeline.sh "${EXES[@]}"
diff --git a/template.roff b/template.roff
@@ -1,5 +1,5 @@
-.ll 7.9c-0.4c
-.po 0.2c
+.ll 9.5c-0.0c
+.po 0.0c
\" Inifinte Page definitions
. de1 ne
. ie \\n[.$] \
@@ -26,7 +26,6 @@
\" Done with infinipage
.ft CR
.po (\n[.ll]-\w' ____')/2
-.br
____
.br
/ __ )