summaryrefslogtreecommitdiff
path: root/support/lgrind/source/v2lg.c
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/lgrind/source/v2lg.c
Initial commit
Diffstat (limited to 'support/lgrind/source/v2lg.c')
-rw-r--r--support/lgrind/source/v2lg.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/support/lgrind/source/v2lg.c b/support/lgrind/source/v2lg.c
new file mode 100644
index 0000000000..5aa5df206f
--- /dev/null
+++ b/support/lgrind/source/v2lg.c
@@ -0,0 +1,78 @@
+/*
+ * Filter a LaTeX file into an lgrind file. Convert
+ * \begin{verbatim}-\end{verbatim} pairs into %[ - %] pairs. Tabify
+ * the former verbatim environments. Convert \verb|stuff| into @stuff@.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)v2lg.c 1.1 20/3/85";
+static char rcsid[] =
+ "$Id: v2lg.c,v 1.2 1999/05/25 17:01:36 mike Exp $";
+#endif
+
+
+#include <stdio.h>
+#include <string.h>
+
+#define FALSE 0
+#define TRUE 1
+
+#define STREQ(s,t) ((*(s) == *(t)) && (!*(s) || !strcmp((s),(t))))
+
+
+int main(int argc, char **argv)
+{
+ int in_verbatim = FALSE, col, start_col;
+ char in[256], out[256], *ic, *oc, *verb, delim;
+
+ while (fgets(in, sizeof(in), stdin) != NULL) {
+ if (in_verbatim) {
+ if (STREQ(in, "\\end{verbatim}\n")) {
+ fputs("%]\n", stdout);
+ in_verbatim = FALSE;
+ continue;
+ }
+ for (col = 0, ic = in, oc = out; *ic != '\n'; ) {
+ if (*ic != ' ' && *ic != '\t') {
+ *oc++ = *ic++; col++;
+ } else { /* \t == ' ' in a verbatim environment */
+ start_col = col;
+ while (*ic == ' ' || *ic == '\t') {
+ if (((++col) & 7) == 0) {
+ *oc++ = '\t'; start_col = col;
+ }
+ ic++;
+ }
+ if ((col & 7) != 0)
+ for ( ; start_col < col; start_col++)
+ *oc++ = ' ';
+ }
+ }
+ *oc++ = '\n'; *oc++ = '\0';
+ fputs(out, stdout);
+ continue;
+ }
+ if (STREQ(in, "\\begin{verbatim}\n")) {
+ fputs("%[\n", stdout);
+ in_verbatim = TRUE;
+ continue;
+ }
+ for (ic = in; (verb = strstr(ic, "\\verb")) != NULL; ) {
+ for ( ; ic < verb; ic++)
+ putchar(*ic);
+ ic += 5; /* Skip over \verb */
+ if (*ic == '*') /* \verb* => funny-looking spaces */
+ ic++;
+ delim = *ic++; /* the delimiter char */
+ putchar('@');
+ while (*ic != delim) {
+ putchar(*ic); ic++;
+ }
+ ic++; /* Skip the other delimiter */
+ putchar('@');
+ }
+ fputs(ic, stdout);
+ }
+ return 0;
+}
+