[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] [grotrin] Add post-processor for groff input.
From: |
Lennart Jablonka |
Subject: |
[PATCH] [grotrin] Add post-processor for groff input. |
Date: |
Sun, 10 Mar 2024 00:13:34 +0000 |
This is useless. And also not what Alejandro wanted, presumably.
Suggested-By: Alejandro Colomar <alx@kernel.org>
---
I don’t wanna wait for April 1st.
.gitignore | 1 +
Makefile.am | 1 +
src/devices/grotrin/.gitignore | 5 ++
src/devices/grotrin/grotrin.1.man | 82 +++++++++++++++++++
src/devices/grotrin/grotrin.am | 14 ++++
src/devices/grotrin/trin.cpp | 129 ++++++++++++++++++++++++++++++
6 files changed, 232 insertions(+)
create mode 100644 src/devices/grotrin/.gitignore
create mode 100644 src/devices/grotrin/grotrin.1.man
create mode 100644 src/devices/grotrin/grotrin.am
create mode 100644 src/devices/grotrin/trin.cpp
diff --git a/.gitignore b/.gitignore
index 2c749f1aa..8b271e54f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,6 +32,7 @@
/grolj4
/gropdf
/grops
+/grotrin
/grotty
/gxditview
/hpftodit
diff --git a/Makefile.am b/Makefile.am
index e15a8ff0f..19c5f6a2c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -653,6 +653,7 @@ include $(top_srcdir)/src/devices/grolbp/grolbp.am
include $(top_srcdir)/src/devices/grolj4/grolj4.am
include $(top_srcdir)/src/devices/gropdf/gropdf.am
include $(top_srcdir)/src/devices/grops/grops.am
+include $(top_srcdir)/src/devices/grotrin/grotrin.am
include $(top_srcdir)/src/devices/grotty/grotty.am
include $(top_srcdir)/src/devices/xditview/xditview.am
include $(top_srcdir)/src/preproc/eqn/eqn.am
diff --git a/src/devices/grotrin/.gitignore b/src/devices/grotrin/.gitignore
new file mode 100644
index 000000000..4bca70d9e
--- /dev/null
+++ b/src/devices/grotrin/.gitignore
@@ -0,0 +1,5 @@
+# build artifacts
+/.deps/
+/.dirstamp
+/grotrin.1
+/trin.o
diff --git a/src/devices/grotrin/grotrin.1.man
b/src/devices/grotrin/grotrin.1.man
new file mode 100644
index 000000000..21e83856e
--- /dev/null
+++ b/src/devices/grotrin/grotrin.1.man
@@ -0,0 +1,82 @@
+.TH grotrin @MAN1EXT@ "@MDATE@" "groff @VERSION@"
+.SH Name
+grotrin \-
+.I groff
+output driver for
+.I groff
+.
+.
+.\" Save and disable compatibility mode (for, e.g., Solaris 10/11).
+.do nr *groff_gropdf_1_man_C \n[.cp]
+.cp 0
+.
+.\" Define fallback for groff 1.23's MR macro if the system lacks it.
+.nr do-fallback 0
+.if !\n(.f .nr do-fallback 1 \" mandoc
+.if \n(.g .if !d MR .nr do-fallback 1 \" older groff
+.if !\n(.g .nr do-fallback 1 \" non-groff *roff
+.if \n[do-fallback] \{\
+. de MR
+. ie \\n(.$=1 \
+. I \%\\$1
+. el \
+. IR \%\\$1 (\\$2)\\$3
+. .
+.\}
+.rr do-fallback
+.
+.
+.\" ====================================================================
+.SH Synopsis
+.\" ====================================================================
+.
+.SY grotrin
+.RI [ file\~ .\|.\|.]
+.YS
+.
+.
+.\" ====================================================================
+.SH Description
+.\" ====================================================================
+.
+This GNU
+.I roff
+output driver translates the output of
+.MR @g@troff @MAN1EXT@
+into input suitable for
+.MR @g@troff @MAN1EXT@ .
+.
+.
+.\" ====================================================================
+.SH Bugs
+.\" ====================================================================
+.
+The output is only correct if the input has an
+.B s
+command before the first text or the text size scaling factor is\~1000.
+.
+.P
+The processed output contains a stray blank page at the end.
+.
+.P
+Both the output of
+.I grotrin
+and documents generated from it are likely much larger than the input.
+.
+.P
+.I grotrin
+does not support drawing commands.
+.
+.P
+There is no reason to use
+.I grotrin.
+.
+.
+.\" ====================================================================
+.SH "See also"
+.\" ====================================================================
+.
+.MR groff @MAN1EXT@ ,
+.MR @g@troff @MAN1EXT@ ,
+.MR groff_out @MAN5EXT@ ,
+.MR groff @MAN7EXT@
diff --git a/src/devices/grotrin/grotrin.am b/src/devices/grotrin/grotrin.am
new file mode 100644
index 000000000..db012985e
--- /dev/null
+++ b/src/devices/grotrin/grotrin.am
@@ -0,0 +1,14 @@
+bin_PROGRAMS += grotrin
+grotrin_SOURCES = src/devices/grotrin/trin.cpp
+grotrin_LDADD = libdriver.a \
+ libgroff.a \
+ lib/libgnu.a
+man1_MANS += src/devices/grotrin/grotrin.1
+EXTRA_DIST += \
+ src/devices/grotrin/grotrin.1.man
+
+# Local Variables:
+# fill-column: 72
+# mode: makefile-automake
+# End:
+# vim: set autoindent filetype=automake textwidth=72:
diff --git a/src/devices/grotrin/trin.cpp b/src/devices/grotrin/trin.cpp
new file mode 100644
index 000000000..5fa84cbc1
--- /dev/null
+++ b/src/devices/grotrin/trin.cpp
@@ -0,0 +1,129 @@
+#include "driver.h"
+
+#if __cplusplus < 201103L
+# define override
+#endif
+
+static void usage(FILE *stream);
+
+class trin_printer : public printer {
+ font *current_font;
+ // in scaled points
+ int current_size;
+ // next output byte is at the beginning of a line
+ bool at_newline;
+public:
+ trin_printer();
+ void begin_page(int) override;
+ void end_page(int) override;
+private:
+ void set_char(glyph *, font *, const environment *, int,
+ const char *) override;
+ void newline();
+};
+
+trin_printer::trin_printer()
+{
+ current_font = NULL;
+ // TODO: don’t depend on a certain scale factor
+ current_size = 10000;
+ at_newline = true;
+
+ puts(
+ ".po 0\n"
+ ".nf\n"
+ ".hy 0\n"
+ ".lg 0\n"
+ ".vs 0");
+}
+
+void trin_printer::begin_page(int)
+{
+}
+
+void trin_printer::end_page(int)
+{
+ newline();
+ puts(".bp");
+}
+
+void trin_printer::set_char(glyph *g, font *f, const environment *env, int w,
const char *)
+{
+ if (current_font != f) {
+ newline();
+ printf(".ft %s\n", f->get_name());
+ current_font = f;
+ }
+
+ if (current_size != env->size) {
+ newline();
+ printf(
+ ".nr s %ds\n"
+ ".ps \\nsu\n",
+ env->size);
+ current_size = env->size;
+ }
+
+ printf("\\v'|%du'\\h'%du-\\n(.ku'", env->vpos, env->hpos);
+
+ int no;
+ const char *name;
+ if ((no = glyph_to_number(g)) != -1)
+ printf("\\N'%d'", no);
+ else if ((name = glyph_to_name(g)) != nullptr) {
+ if (name[0] == '\\')
+ name++;
+ printf("\\[%s]", name);
+ }
+ at_newline = false;
+
+ newline();
+ puts(".br");
+}
+
+/*
+ * Ensure the next byte printed is at the start of a line.
+ */
+void trin_printer::newline()
+{
+ if (!at_newline) {
+ at_newline = true;
+ putchar('\n');
+ }
+}
+
+printer *make_printer()
+{
+ return new trin_printer();
+}
+
+int main(int argc, char **argv)
+{
+ program_name = argv[0];
+ setlocale(LC_CTYPE, "");
+ int c;
+ while ((c = getopt(argc, argv, "")) != -1)
+ switch (c) {
+ case '?':
+ usage(stderr);
+ exit(EXIT_FAILURE);
+ }
+ if (optind == argc)
+ do_file("-");
+ else
+ for (int i = optind; i < argc; i++)
+ do_file(argv[i]);
+}
+
+static void usage(FILE *stream)
+{
+ fprintf(stream,
+"usage: %s [file ...]\n",
+ program_name);
+}
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
--
2.44.0
- [PATCH] [grotrin] Add post-processor for groff input.,
Lennart Jablonka <=