aboutsummaryrefslogtreecommitdiffstats
path: root/soelim/soelim.c
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2016-10-06 21:30:09 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2016-10-06 21:30:09 +0000
commitaa7798c94fa57f6c00fab4393c9fe91334864371 (patch)
tree61b5a60e9c086b1ba44b4718e7666304a8edab6f /soelim/soelim.c
downloadsrc-aa7798c94fa57f6c00fab4393c9fe91334864371.tar.gz
src-aa7798c94fa57f6c00fab4393c9fe91334864371.zip
Import heirloom doctools snapshot from git as of 161006vendor/heirloom-doctools/20161006
Notes
Notes: svn path=/vendor/heirloom-doctools/dist/; revision=306788 svn path=/vendor/heirloom-doctools/20161006/; revision=306789; tag=vendor/heirloom-doctools/20161006
Diffstat (limited to 'soelim/soelim.c')
-rw-r--r--soelim/soelim.c151
1 files changed, 151 insertions, 0 deletions
diff --git a/soelim/soelim.c b/soelim/soelim.c
new file mode 100644
index 000000000000..2652ba61577f
--- /dev/null
+++ b/soelim/soelim.c
@@ -0,0 +1,151 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/* from OpenSolaris "soelim.c 1.3 05/06/02 SMI" SVr4.0 1.1 */
+
+/*
+ * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
+ */
+#if __GNUC__ >= 3 && __GNUC_MINOR__ >= 4 || __GNUC__ >= 4
+#define USED __attribute__ ((used))
+#elif defined __GNUC__
+#define USED __attribute__ ((unused))
+#else
+#define USED
+#endif
+static const char sccsid[] USED = "@(#)/usr/ucb/soelim.sl 5.1 (gritter) 10/25/05";
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+/*
+ * soelim - a filter to process n/troff input eliminating .so's
+ *
+ * Author: Bill Joy UCB July 8, 1977
+ *
+ * This program eliminates .so's from a n/troff input stream.
+ * It can be used to prepare safe input for submission to the
+ * phototypesetter since the software supporting the operator
+ * doesn't let him do chdir.
+ *
+ * This is a kludge and the operator should be given the
+ * ability to do chdir.
+ *
+ * This program is more generally useful, it turns out, because
+ * the program tbl doesn't understand ".so" directives.
+ */
+#define STDIN_NAME "-"
+
+int process(char *);
+
+int
+main(int argc, char **argv)
+{
+
+ argc--;
+ argv++;
+ if (argc == 0) {
+ process(STDIN_NAME);
+ exit(0);
+ }
+ do {
+ process(argv[0]);
+ argv++;
+ argc--;
+ } while (argc > 0);
+ exit(0);
+}
+
+int process(char *file)
+{
+ register int n;
+ register int c;
+ static char *fname = NULL;
+ static size_t fnsize = 0;
+ FILE *soee;
+ int isfile;
+
+ if (!strcmp(file, STDIN_NAME)) {
+ soee = stdin;
+ } else {
+ soee = fopen(file, "r");
+ if (soee == NULL) {
+ perror(file);
+ return(-1);
+ }
+ }
+ for (;;) {
+ c = getc(soee);
+ if (c == EOF)
+ break;
+ if (c != '.')
+ goto simple;
+ c = getc(soee);
+ if (c != 's') {
+ putchar('.');
+ goto simple;
+ }
+ c = getc(soee);
+ if (c != 'o') {
+ printf(".s");
+ goto simple;
+ }
+ do
+ c = getc(soee);
+ while (c == ' ' || c == '\t');
+ n = 0;
+ isfile = 0;
+ for (;;) {
+ switch (c) {
+
+ case ' ':
+ case '\t':
+ case '\n':
+ case EOF:
+ goto donename;
+
+ default:
+ if (n+1 >= fnsize)
+ fname = realloc(fname, fnsize += 128);
+ fname[n++] = c;
+ c = getc(soee);
+ isfile++;
+ continue;
+ }
+ }
+donename:
+ if (n == 0) {
+ printf(".so");
+ goto simple;
+ }
+ fname[n] = 0;
+ if (process(fname) < 0)
+ if (isfile)
+ printf(".so %s\n", fname);
+ continue;
+simple:
+ if (c == EOF)
+ break;
+ putchar(c);
+ if (c != '\n') {
+ c = getc(soee);
+ goto simple;
+ }
+ }
+ if (soee != stdin) {
+ fclose(soee);
+ }
+ return(0);
+}