commit 4bb01f6

xplshn  ·  2026-07-07 22:53:32 +0000 UTC
parent b52592b
ninja backend for ninqu | fix warnings in bc.y,wget,make,sh | fmt cmd/extra/yap & others

Signed-off-by: xplshn <anto@xplshn.com.ar>
46 files changed,  +3114, -3113
+5, -0
1@@ -34,3 +34,8 @@ scripts/mk/config.mk
2 scripts/mk/config.kv
3 scripts/mk/rules.mk
4 deps.mk
5+
6+# ninja backend generator output and state
7+build.ninja
8+.ninja_log
9+.ninja_deps
+15, -4
 1@@ -1,5 +1,8 @@
 2 CC       ?= cc -static
 3 CFLAGS   ?= -std=c99 -Wall -Wextra -pedantic
 4+
 5+BACKEND  ?= auto
 6+
 7 CPPFLAGS ?= -Ishared -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L \
 8             -DFEATURE_NOFORK=0 -DFEATURE_NOEXEC=0
 9 # NOEXEC cannot be on the bootstrap compile, but it can
10@@ -13,7 +16,8 @@ NINQU_LIB_SRC =\
11         shared/libutil/strtonum.c\
12         shared/libutil/fshut.c\
13         shared/libutil/mkdirp.c\
14-        shared/libutil/recurse_dir.c
15+        shared/libutil/recurse_dir.c\
16+        shared/libutil/wexec.c
17 
18 NINQU_SRC =\
19         cmd/dev/ninqu/main.c\
20@@ -24,11 +28,13 @@ NINQU_SRC =\
21         cmd/dev/ninqu/registry.c\
22         cmd/dev/ninqu/fs.c\
23         cmd/dev/ninqu/exec.c\
24+        cmd/dev/ninqu/backend.c\
25         cmd/dev/ninqu/parse.c\
26         cmd/dev/ninqu/expand.c\
27         cmd/dev/ninqu/schedule.c\
28         cmd/dev/ninqu/query.c\
29-        cmd/dev/ninqu/resolve.c
30+        cmd/dev/ninqu/resolve.c\
31+        cmd/dev/ninqu/ninja.c
32 
33 # map make's -j to ninqu's -j flag
34 NINQU ?= cmd/dev/ninqu/ninqu
35@@ -45,12 +51,15 @@ $(NINQU): $(NINQU_SRC) cmd/dev/ninqu/ninqu.h scripts/mk/config.set $(NINQU_LIB_S
36 .PHONY: FORCE
37 FORCE:
38 
39+# ninqu generates build.ninja if ninja/samu is available and execs that
40+# instead of running its own backend, but you can use make BACKEND=internal
41+# to force the internal one to be used anyways
42 %: $(NINQU) FORCE
43 	$(NINQU) $(JOBS) $@
44 
45 clean: $(NINQU)
46-	$(NINQU) clean
47-	rm -f $(NINQU)
48+	$(NINQU) -DBACKEND="internal" clean
49+	rm -f $(NINQU) build.ninja
50 
51 scripts/mk/config.set: build.cfg scripts/genconfig.sh
52 	sh scripts/genconfig.sh config
53@@ -68,10 +77,12 @@ cmd/dev/ninqu/gate.c: ;
54 cmd/dev/ninqu/registry.c: ;
55 cmd/dev/ninqu/fs.c: ;
56 cmd/dev/ninqu/exec.c: ;
57+cmd/dev/ninqu/backend.c: ;
58 cmd/dev/ninqu/parse.c: ;
59 cmd/dev/ninqu/expand.c: ;
60 cmd/dev/ninqu/schedule.c: ;
61 cmd/dev/ninqu/query.c: ;
62 cmd/dev/ninqu/resolve.c: ;
63+cmd/dev/ninqu/ninja.c: ;
64 build.cfg: ;
65 scripts/genconfig.sh: ;
+6, -0
 1@@ -154,6 +154,9 @@ for _p in $PRESET_UTILS; do
 2 done
 3 unset _p
 4 
 5+# Stays 0 unless you do build manpages, via `ninqu man`
 6+BUILD_MAN=0
 7+
 8 # --- per-item overrides (after preset expansion) ---
 9 # BUILD_POSIX_SH=0       # disable a tool when its group is active
10 # BUILD_DEV_AS=1         # enable a tool whose group isnt in PRESET_UTILS
11@@ -245,3 +248,6 @@ fi
12 CPPFLAGS_TLS=$(echo "$CPPFLAGS_TLS" | xargs)
13 LDFLAGS_TLS=$(echo "$LDFLAGS_TLS" | xargs)
14 LDLIBS_TLS=$(echo "$LDLIBS_TLS" | xargs)
15+
16+# Makes Ninqu try them in this order:
17+NINJA_TRY="${NINJA_TRY:-samu,ninja}"
+11, -20
 1@@ -1,4 +1,5 @@
 2 #include "ninqu.h"
 3+#include "wexec.h"
 4 
 5 #include <errno.h>
 6 #include <libgen.h>
 7@@ -13,8 +14,7 @@ int jobs_n = 1;
 8 int summary_mode;
 9 int failed_any;
10 
11-/* fork, chdir, redirect, exec. the child _exit on error so the
12- * parent never sees a stale pid */
13+/* child _exit on error so parent never sees a stale pid */
14 pid_t
15 spawn_inst(struct Inst *inst, struct StrList *argv)
16 {
17@@ -37,9 +37,7 @@ spawn_inst(struct Inst *inst, struct StrList *argv)
18   child_execvp(sl_argv(argv));
19 }
20 
21-/* fork a supervisor that chains each stage stdout into the next
22- * stdin. the parent waits on the supervisor, so the whole pipeline
23- * has one exit status */
24+/* parent waits on supervisor so pipeline has one exit status */
25 pid_t
26 spawn_pipe(struct Inst *inst)
27 {
28@@ -91,8 +89,8 @@ spawn_pipe(struct Inst *inst)
29   }
30 }
31 
32-/* mkdir -p the directory an instance writes into, so a rule (out)
33- * can point at a path that does not exist yet */
34+/* mkdir -p the directory an instance writes into, so a rule (out) can point at a path that does not
35+ * exist yet */
36 void
37 mk_out_dir(const char *out)
38 {
39@@ -108,8 +106,7 @@ mk_out_dir(const char *out)
40   mkdirp(dir, 0777, 0777);
41 }
42 
43-/* print the rule line and flush before the child runs, so the
44- * announcement appears before the child own output */
45+/* flush before child runs so announcement appears before its output */
46 void
47 announce_inst(struct Inst *inst)
48 {
49@@ -118,8 +115,7 @@ announce_inst(struct Inst *inst)
50   fflush(stdout);
51 }
52 
53-/* run one instance synchronously. exits on failure since a missing
54- * producer is unrecoverable */
55+/* exits on failure since a missing producer is unrecoverable */
56 void
57 run_inst_sync(int idx)
58 {
59@@ -137,8 +133,7 @@ run_inst_sync(int idx)
60     eprintf("manifest: producer failed (rule %s)\n", rules[inst->rule_idx].name);
61 }
62 
63-/* run a batch of independent instances concurrently, at most jobs_n
64- * at a time. all instances in the batch are at the same kahn level */
65+/* all instances in the batch are at the same kahn level */
66 void
67 run_batch(int *idxs, int n)
68 {
69@@ -189,9 +184,7 @@ run_batch(int *idxs, int n)
70   free(slot);
71 }
72 
73-/* run an instance and all its transitive deps in order, so a
74- * producer like LIBUTIL does not archive .o files that have not
75- * been compiled yet */
76+/* run transitive deps in order so a producer does not archive uncompiled files */
77 void
78 run_inst_with_deps(int idx)
79 {
80@@ -211,8 +204,7 @@ run_inst_with_deps(int idx)
81   run_inst_sync(idx);
82 }
83 
84-/* bootstrap: run the producer for path only if path does not exist.
85- * after that the normal dependency graph takes over */
86+/* run producer for path only if path does not exist */
87 void
88 materialize_if_missing(const char *path)
89 {
90@@ -233,8 +225,7 @@ materialize_if_missing(const char *path)
91   }
92 }
93 
94-/* run argv synchronously, return its stdout as a string. used by
95- * (set NAME (capture (exec ...))) at parse time */
96+/* used by (set NAME (capture (exec ...))) at parse time */
97 char *
98 capture_argv(struct StrList *argv)
99 {
+36, -13
  1@@ -1,5 +1,6 @@
  2 #include "ninqu.h"
  3 
  4+#include <fnmatch.h>
  5 #include <stdio.h>
  6 #include <stdlib.h>
  7 #include <string.h>
  8@@ -52,8 +53,7 @@ inst_stale(struct Inst *inst)
  9   return 0;
 10 }
 11 
 12-/* a pure $(NAME) splits on whitespace so $(CFLAGS) becomes many
 13- * flags, while -I$(INCDIR) stays one token */
 14+/* pure $(NAME) splits on whitespace so $(CFLAGS) becomes many flags, -I$(INCDIR) stays one token */
 15 static int
 16 is_pure_ref(const char *tok)
 17 {
 18@@ -127,9 +127,7 @@ build_cmd(struct Inst *inst, struct Rule *r)
 19   }
 20 }
 21 
 22-/* @NAME resolves to a rule ref. glob:PREFIX goes to glob_expand.
 23- * anything else is a path: if it does not exist, try to find a
 24- * producer and run it first */
 25+/* if path does not exist, try to find a producer and run it first */
 26 static void
 27 resolve_input_token(int inst_idx, const char *raw, int only_dep)
 28 {
 29@@ -198,8 +196,7 @@ setup_inst(struct Inst *inst, struct Rule *r)
 30   }
 31 }
 32 
 33-/* resolve deps, expand (out), populate IN/OUT on the overlay, build
 34- * the cmd. caller must have local_overlay set if needed */
 35+/* caller must have local_overlay set if needed */
 36 static void
 37 finalize_inst(int idx, struct Rule *r, struct KvStore *ov)
 38 {
 39@@ -222,6 +219,27 @@ finalize_inst(int idx, struct Rule *r, struct KvStore *ov)
 40   build_cmd(inst, r);
 41 }
 42 
 43+/* true when deps (out) matches selfs glob. glob_all() needs bytes on disk
 44+ * so dep must run synchronously before enumerating instances */
 45+static int
 46+dep_feeds_glob(struct Rule *self, struct Rule *dep)
 47+{
 48+  int j;
 49+
 50+  if (!dep->out[0])
 51+    return 0;
 52+  for (j = 0; j < self->globs.n; j++) {
 53+    char *pat = kv_expand(self->globs.v[j]);
 54+    char *out = kv_expand(dep->out);
 55+    int   hit = fnmatch(pat, out, 0) == 0;
 56+    free(pat);
 57+    free(out);
 58+    if (hit)
 59+      return 1;
 60+  }
 61+  return 0;
 62+}
 63+
 64 void
 65 expand_rule(const char *name)
 66 {
 67@@ -234,8 +252,7 @@ expand_rule(const char *name)
 68     return;
 69   r->expanded = 1;
 70 
 71-  /* a gate with $(...) is per-instance, a static gate is checked
 72-   * once and if false the rule produces zero instances */
 73+  /* static gate checked once, if false rule produces zero instances */
 74   if (r->gate && !gate_has_dyn(r->gate) && !gate_eval(r->gate))
 75     return;
 76 
 77@@ -252,9 +269,15 @@ expand_rule(const char *name)
 78     int            j;
 79     int            r_literal = rule_is_literal(r);
 80 
 81-    /* run order-only @rule producers before globbing, so a codegen
 82-     * step that generates sources finishes before the glob runs.
 83-     * skipped in summary mode since -S must not execute */
 84+    /* run a codegen producer before globbing only when its own
 85+     * output feeds this rules glob, so a step like POSIX_BC_C
 86+     * (produces cmd/posix/bc.c) finishes before glob_all() looks
 87+     * for cmd/posix/bc.c. anything else in extra_deps (a library to
 88+     * link, a header some other rule includes) never needs to run
 89+     * here, expand_rule() on it just registers its instances so
 90+     * the resolve_input_token() pass in finalize_inst() can wire up
 91+     * dep_rule_names for backend scheduling. skipped in
 92+     * summary mode since -S must not execute */
 93     if (!summary_mode) {
 94       for (j = 0; j < r->extra_deps.n; j++) {
 95         char *tok = kv_expand(r->extra_deps.v[j]);
 96@@ -262,7 +285,7 @@ expand_rule(const char *name)
 97           struct Rule *dep = rule_find(tok + 1);
 98           if (dep) {
 99             expand_rule(dep->name);
100-            if (dep->n_inst > 0) {
101+            if (dep_feeds_glob(r, dep) && dep->n_inst > 0) {
102               int k;
103               for (k = 0; k < dep->n_inst; k++)
104                 run_inst_with_deps(dep->inst_idx[k]);
+6, -14
 1@@ -7,6 +7,7 @@
 2 #include <stdlib.h>
 3 #include <string.h>
 4 #include <sys/stat.h>
 5+#include <unistd.h>
 6 
 7 long
 8 mtime_of(const char *path)
 9@@ -53,8 +54,7 @@ file_contains(const char *path, const char *needle)
10   return found;
11 }
12 
13-/* recurse_dir has no userdata slot, so the pattern and output list
14- * travel through file-scope statics for the span of one call */
15+/* recurse_dir lacks a userdata slot, use statics for one call */
16 static const char     *rg_suffix;
17 static struct StrList *rg_out;
18 
19@@ -81,9 +81,7 @@ recurse_glob(const char *dir, const char *suffix, struct StrList *out)
20   recurse_dir(dir, rg_visit);
21 }
22 
23-/* a double-star-slash pattern recurses from the dir before it,
24- * matching the suffix against each basename. anything else goes to
25- * glob(3) as-is */
26+/* double-star-slash recurses, anything else goes to glob(3) */
27 void
28 glob_expand(const char *pattern, struct StrList *out)
29 {
30@@ -126,8 +124,7 @@ is_wildcard_pattern(const char *pattern)
31   return strpbrk(pattern, "*?[") != NULL;
32 }
33 
34-/* true if every glob on r is a literal path. a rule built entirely
35- * from literals is the override side of path_claimed_elsewhere */
36+/* true if every glob on r is a literal path */
37 int
38 rule_is_literal(struct Rule *r)
39 {
40@@ -140,8 +137,7 @@ rule_is_literal(struct Rule *r)
41   return 1;
42 }
43 
44-/* a broad wildcard rule steps aside for any file another rule names
45- * outright, so a per-file override needs no (skip) on the broad rule */
46+/* broad wildcard steps aside for literal paths so overrides need no (skip) */
47 int
48 path_claimed_elsewhere(const char *path, struct Rule *self)
49 {
50@@ -178,11 +174,7 @@ splitext(const char *base, char *stem, size_t stemsz, char *ext, size_t extsz)
51   }
52 }
53 
54-/* a basestem like sha512-224sum has a hyphen, but a config toggle
55- * cannot. normalize so a gate keying off BASESTEM matches the form
56- * genconfig writes
57- * FIXME: I do not like our current genconfig.sh
58- */
59+/* normalize so a gate keying off BASESTEM matches genconfig output */
60 void
61 to_ident(const char *s, char *out, size_t outsz)
62 {
+28, -2
 1@@ -10,7 +10,8 @@ static void
 2 usage(void)
 3 {
 4   eprintf(
 5-      "usage: %s [-jN] [-f manifest] [-C dir] [-Dvar=val]... [-S] [-F] [target|meta.target ...]\n"
 6+      "usage: %s [-jN] [-f manifest] [-C dir] [-Dvar=val]... [-S] [-F] [-G ninja] "
 7+      "[target|meta.target ...]\n"
 8       "       %s query (features|groups|metas|rules|graph) [arg]\n",
 9       argv0,
10       argv0
11@@ -25,10 +26,11 @@ main(int argc, char *argv[])
12   int            query_mode    = 0;
13   const char    *query_sub     = NULL;
14   const char    *query_arg     = NULL;
15+  const char    *generator     = NULL;
16   int            i;
17   struct StrList wanted = {0};
18 
19-  /* detect `query` before ARGBEGIN so it is not parsed as a target */
20+  /* detect query before ARGBEGIN so it is not parsed as a target */
21   if (argc >= 2 && strcmp(argv[1], "query") == 0) {
22     query_mode = 1;
23     if (argc < 3)
24@@ -78,6 +80,9 @@ main(int argc, char *argv[])
25       case 'F':
26         features_mode = 1;
27         break;
28+      case 'G':
29+        generator = EARGF(usage());
30+        break;
31       default:
32         usage();
33     }
34@@ -106,6 +111,27 @@ main(int argc, char *argv[])
35       resolve_wanted(wanted.v[i]);
36 
37   resolve_deps();
38+
39+  if (generator) {
40+    const struct Backend *be = backend_by_name(generator);
41+    if (!be)
42+      eprintf("ninqu: unknown generator '%s'\n", generator);
43+    be->emit(be->file, &wanted);
44+    return failed_any ? 1 : 0;
45+  }
46+
47+  /* BACKEND=internal forces executor. otherwise generate file and exec backend binary */
48+  if (strcmp(kv_get_or("BACKEND", "auto"), "internal") != 0) {
49+    char                 *bin;
50+    const struct Backend *be = backend_resolve(&bin);
51+    if (be) {
52+      be->emit(be->file, &wanted);
53+      if (failed_any)
54+        return 1;
55+      backend_exec(be, bin, &wanted);
56+    }
57+  }
58+
59   schedule_and_run();
60 
61   return failed_any ? 1 : 0;
+14, -1
 1@@ -10,7 +10,7 @@
 2 #include "arg.h"
 3 #include "util.h"
 4 
 5-/* grow a struct-array when full. n/cap doubles each time */
 6+/* grow a struct-array when full, n/cap doubles each time */
 7 #define GROW(arr, n, cap, init)                                                                    \
 8   do {                                                                                             \
 9     if ((n) >= (cap)) {                                                                            \
10@@ -246,6 +246,19 @@ extern struct StrList files_read;
11 void expand_rule(const char *name);
12 
13 void schedule_and_run(void);
14+void emit_ninja(const char *path, struct StrList *wanted);
15+
16+struct Backend {
17+  const char *name;
18+  const char *try_key;
19+  const char *file;
20+  void (*emit)(const char *path, struct StrList *wanted);
21+};
22+
23+const struct Backend *backend_by_name(const char *name);
24+const struct Backend *backend_resolve(char **bin);
25+void backend_exec(const struct Backend *be, const char *bin, struct StrList *wanted)
26+    __attribute__((noreturn));
27 
28 void do_features(void);
29 void do_query(const char *sub, const char *arg);
+4, -8
 1@@ -1,10 +1,9 @@
 2 #include "ninqu.h"
 3+#include "wexec.h"
 4 
 5 #include <ctype.h>
 6-#include <errno.h>
 7 #include <stdio.h>
 8 #include <string.h>
 9-#include <unistd.h>
10 
11 void
12 sl_push(struct StrList *sl, const char *s)
13@@ -80,7 +79,7 @@ base_of(const char *path)
14   return p ? p + 1 : path;
15 }
16 
17-/* null-terminate the array so execvp stops scanning */
18+/* null-terminate the array so wexecvp stops scanning */
19 char **
20 sl_argv(struct StrList *sl)
21 {
22@@ -92,12 +91,9 @@ sl_argv(struct StrList *sl)
23   return av;
24 }
25 
26-/* noreturn so callers do not need to guard the dead path after the
27- * fork child calls this */
28+/* noreturn so callers do not guard the dead path after fork */
29 void
30 child_execvp(char **av)
31 {
32-  execvp(av[0], av);
33-  fprintf(stderr, "%s: exec %s: %s\n", argv0, av[0], strerror(errno));
34-  _exit(127);
35+  wexecvp_self(av[0], av);
36 }
+50, -51
  1@@ -1,75 +1,74 @@
  2-#include "in_all.h"
  3 #include "ansi.h"
  4+#include "in_all.h"
  5 
  6 static int
  7 consume_csi(const char *s, const char **next, enum ansi_kind *kind)
  8 {
  9-	const unsigned char *p = (const unsigned char *)s + 2;
 10+  const unsigned char *p = (const unsigned char *)s + 2;
 11 
 12-	while (*p >= 0x30 && *p <= 0x3f) {
 13-		p++;
 14-	}
 15-	while (*p >= 0x20 && *p <= 0x2f) {
 16-		p++;
 17-	}
 18-	if (*p >= 0x40 && *p <= 0x7e) {
 19-		*kind = (*p == 'm') ? ANSI_SGR : ANSI_DISCARD;
 20-		*next = (const char *)p + 1;
 21-		return 1;
 22-	}
 23-	return 0;
 24+  while (*p >= 0x30 && *p <= 0x3f) {
 25+    p++;
 26+  }
 27+  while (*p >= 0x20 && *p <= 0x2f) {
 28+    p++;
 29+  }
 30+  if (*p >= 0x40 && *p <= 0x7e) {
 31+    *kind = (*p == 'm') ? ANSI_SGR : ANSI_DISCARD;
 32+    *next = (const char *)p + 1;
 33+    return 1;
 34+  }
 35+  return 0;
 36 }
 37 
 38 static int
 39 consume_string(const char *s, const char **next)
 40 {
 41-	const unsigned char *p = (const unsigned char *)s + 2;
 42+  const unsigned char *p = (const unsigned char *)s + 2;
 43 
 44-	while (*p) {
 45-		if (*p == '\a') {
 46-			*next = (const char *)p + 1;
 47-			return 1;
 48-		}
 49-		if (*p == '\x1b' && p[1] == '\\') {
 50-			*next = (const char *)p + 2;
 51-			return 1;
 52-		}
 53-		p++;
 54-	}
 55-	return 0;
 56+  while (*p) {
 57+    if (*p == '\a') {
 58+      *next = (const char *)p + 1;
 59+      return 1;
 60+    }
 61+    if (*p == '\x1b' && p[1] == '\\') {
 62+      *next = (const char *)p + 2;
 63+      return 1;
 64+    }
 65+    p++;
 66+  }
 67+  return 0;
 68 }
 69 
 70 static int
 71 consume_esc(const char *s, const char **next)
 72 {
 73-	const unsigned char *p = (const unsigned char *)s + 1;
 74+  const unsigned char *p = (const unsigned char *)s + 1;
 75 
 76-	while (*p >= 0x20 && *p <= 0x2f) {
 77-		p++;
 78-	}
 79-	if (*p >= 0x30 && *p <= 0x7e) {
 80-		*next = (const char *)p + 1;
 81-		return 1;
 82-	}
 83-	return 0;
 84+  while (*p >= 0x20 && *p <= 0x2f) {
 85+    p++;
 86+  }
 87+  if (*p >= 0x30 && *p <= 0x7e) {
 88+    *next = (const char *)p + 1;
 89+    return 1;
 90+  }
 91+  return 0;
 92 }
 93 
 94 int
 95 ansi_escape(const char *s, const char **next, enum ansi_kind *kind)
 96 {
 97-	*kind = ANSI_NONE;
 98-	*next = s;
 99-	if ((unsigned char)s[0] != 0x1b || s[1] == '\0') {
100-		return 0;
101-	}
102-	if (s[1] == '[') {
103-		return consume_csi(s, next, kind);
104-	}
105-	if (s[1] == ']' || s[1] == 'P' || s[1] == 'X' || s[1] == '^' ||
106-	    s[1] == '_') {
107-		*kind = ANSI_DISCARD;
108-		return consume_string(s, next);
109-	}
110-	*kind = ANSI_DISCARD;
111-	return consume_esc(s, next);
112+  *kind = ANSI_NONE;
113+  *next = s;
114+  if ((unsigned char)s[0] != 0x1b || s[1] == '\0') {
115+    return 0;
116+  }
117+  if (s[1] == '[') {
118+    return consume_csi(s, next, kind);
119+  }
120+  if (s[1] == ']' || s[1] == 'P' || s[1] == 'X' || s[1] == '^' || s[1] == '_') {
121+    *kind = ANSI_DISCARD;
122+    return consume_string(s, next);
123+  }
124+  *kind = ANSI_DISCARD;
125+  return consume_esc(s, next);
126 }
+3, -3
 1@@ -2,9 +2,9 @@
 2 #define ANSI_H
 3 
 4 enum ansi_kind {
 5-	ANSI_NONE = 0,
 6-	ANSI_SGR,
 7-	ANSI_DISCARD,
 8+  ANSI_NONE = 0,
 9+  ANSI_SGR,
10+  ANSI_DISCARD,
11 };
12 
13 int ansi_escape(const char *s, const char **next, enum ansi_kind *kind);
+502, -509
   1@@ -1,82 +1,82 @@
   2 /* Copyright (c) 1985 Ceriel J.H. Jacobs */
   3 
   4-#include "in_all.h"
   5 #include "commands.h"
   6-#include "output.h"
   7-#include "process.h"
   8-#include "help.h"
   9-#include "term.h"
  10-#include "prompt.h"
  11-#include "getline.h"
  12-#include "getcomm.h"
  13-#include "pattern.h"
  14+#include "assert.h"
  15 #include "display.h"
  16-#include "options.h"
  17-#include "machine.h"
  18+#include "getcomm.h"
  19+#include "getline.h"
  20+#include "help.h"
  21+#include "in_all.h"
  22 #include "keys.h"
  23+#include "machine.h"
  24 #include "main.h"
  25-#include "assert.h"
  26+#include "options.h"
  27+#include "output.h"
  28+#include "pattern.h"
  29+#include "process.h"
  30+#include "prompt.h"
  31+#include "term.h"
  32 
  33 static long lastcount; /* Save last count for '.' command */
  34-static int lastcomm;   /* Save last command for '.' command */
  35-static int searchdir;  /* Direction of last search */
  36+static int  lastcomm;  /* Save last command for '.' command */
  37+static int  searchdir; /* Direction of last search */
  38 
  39-static int do_nocomm(long cnt);
  40+static int  do_nocomm(long cnt);
  41 static void do_search(char *str, long cnt, int dir);
  42-static int do_fsearch(long cnt);
  43-static int do_bsearch(long cnt);
  44-static int n_or_rn_search(long cnt, int dir);
  45-static int do_nsearch(long cnt);
  46-static int do_rnsearch(long cnt);
  47-static int shell_command(int esc_ch, long cnt);
  48-static int do_shell(long cnt);
  49-static int do_pipe(long cnt);
  50-static int do_writefile(long cnt);
  51-static int do_absolute(long cnt);
  52-static int do_visit(long cnt);
  53-static int do_error(long cnt);
  54-static int prev_screen(int sz, int really);
  55-static int next_screen(int sz, int really);
  56-static int do_redraw(long cnt);
  57-static int page_size(unsigned cnt);
  58-static int do_forward(long cnt);
  59-static int do_backward(long cnt);
  60-static int do_firstline(long cnt);
  61-static int do_lline(long cnt);
  62-static int do_lf(long cnt);
  63-static int do_upline(long cnt);
  64-static int do_skiplines(long cnt);
  65-static int do_bskiplines(long cnt);
  66-static int do_fscreens(long cnt);
  67-static int do_bscreens(long cnt);
  68-static int scro_size(unsigned cnt);
  69-static int do_f_scroll(long cnt);
  70-static int do_b_scroll(long cnt);
  71-static int do_previousfile(long cnt);
  72-static int do_nextfile(long cnt);
  73-static int do_lcomm(long cnt);
  74-static int do_quit(long cnt);
  75+static int  do_fsearch(long cnt);
  76+static int  do_bsearch(long cnt);
  77+static int  n_or_rn_search(long cnt, int dir);
  78+static int  do_nsearch(long cnt);
  79+static int  do_rnsearch(long cnt);
  80+static int  shell_command(int esc_ch, long cnt);
  81+static int  do_shell(long cnt);
  82+static int  do_pipe(long cnt);
  83+static int  do_writefile(long cnt);
  84+static int  do_absolute(long cnt);
  85+static int  do_visit(long cnt);
  86+static int  do_error(long cnt);
  87+static int  prev_screen(int sz, int really);
  88+static int  next_screen(int sz, int really);
  89+static int  do_redraw(long cnt);
  90+static int  page_size(unsigned cnt);
  91+static int  do_forward(long cnt);
  92+static int  do_backward(long cnt);
  93+static int  do_firstline(long cnt);
  94+static int  do_lline(long cnt);
  95+static int  do_lf(long cnt);
  96+static int  do_upline(long cnt);
  97+static int  do_skiplines(long cnt);
  98+static int  do_bskiplines(long cnt);
  99+static int  do_fscreens(long cnt);
 100+static int  do_bscreens(long cnt);
 101+static int  scro_size(unsigned cnt);
 102+static int  do_f_scroll(long cnt);
 103+static int  do_b_scroll(long cnt);
 104+static int  do_previousfile(long cnt);
 105+static int  do_nextfile(long cnt);
 106+static int  do_lcomm(long cnt);
 107+static int  do_quit(long cnt);
 108 
 109 static int
 110 do_nocomm(long cnt)
 111 { /* Do nothing */
 112-	(void)cnt;
 113-	return 0;
 114+  (void)cnt;
 115+  return 0;
 116 }
 117 
 118 int
 119 do_chkm(long cnt)
 120 { /* Change key map */
 121-	struct keymap *p;
 122-	(void)cnt;
 123+  struct keymap *p;
 124+  (void)cnt;
 125 
 126-	if (!(p = othermap)) {
 127-		error("No other keymap");
 128-		return 0;
 129-	}
 130-	othermap = currmap;
 131-	currmap = p;
 132-	return 0;
 133+  if (!(p = othermap)) {
 134+    error("No other keymap");
 135+    return 0;
 136+  }
 137+  othermap = currmap;
 138+  currmap  = p;
 139+  return 0;
 140 }
 141 
 142 /*
 143@@ -86,71 +86,71 @@ do_chkm(long cnt)
 144 static void
 145 do_search(char *str, long cnt, int dir)
 146 {
 147-	char *p;
 148-	long lineno;
 149-
 150-	if (str) {
 151-		/*
 152-		 * We have to get a pattern, which we have to prompt for
 153-		 * with the string "str".
 154-		 */
 155-		if ((p = readline(str)) == 0) {
 156-			/*
 157-			 * User cancelled command
 158-			 */
 159-			return;
 160-		}
 161-		if ((p = re_comp(p))) {
 162-			/*
 163-			 * There was an error in the pattern
 164-			 */
 165-			error(p);
 166-			return;
 167-		}
 168-		searchdir = dir;
 169-	}
 170-	if (dir < 0)
 171-		lineno = scr_info.firstline;
 172-	else
 173-		lineno = scr_info.lastline;
 174-	for (;;) {
 175-		p = 0;
 176-		if ((lineno += dir) > 0)
 177-			p = getline(lineno, 0);
 178-		if (interrupt)
 179-			return;
 180-		if (!p) { /* End of file reached */
 181-			error("pattern not found");
 182-			return;
 183-		}
 184-		if (re_exec(p) && --cnt <= 0) {
 185-			/*
 186-			 * We found the pattern, and we found it often enough.
 187-			 * Pity that we still don't know where the match is.
 188-			 * We only know the linenumber. So, we just hope the
 189-			 * following will at least bring it on the screen ...
 190-			 */
 191-			(void)display(lineno, 0, pagesize, 0);
 192-			(void)scrollb(2, 0);
 193-			redraw(0);
 194-			return;
 195-		}
 196-	}
 197-	/* NOTREACHED */
 198+  char *p;
 199+  long  lineno;
 200+
 201+  if (str) {
 202+    /*
 203+     * We have to get a pattern, which we have to prompt for
 204+     * with the string "str".
 205+     */
 206+    if ((p = readline(str)) == 0) {
 207+      /*
 208+       * User cancelled command
 209+       */
 210+      return;
 211+    }
 212+    if ((p = re_comp(p))) {
 213+      /*
 214+       * There was an error in the pattern
 215+       */
 216+      error(p);
 217+      return;
 218+    }
 219+    searchdir = dir;
 220+  }
 221+  if (dir < 0)
 222+    lineno = scr_info.firstline;
 223+  else
 224+    lineno = scr_info.lastline;
 225+  for (;;) {
 226+    p = 0;
 227+    if ((lineno += dir) > 0)
 228+      p = getline(lineno, 0);
 229+    if (interrupt)
 230+      return;
 231+    if (!p) { /* End of file reached */
 232+      error("pattern not found");
 233+      return;
 234+    }
 235+    if (re_exec(p) && --cnt <= 0) {
 236+      /*
 237+       * We found the pattern, and we found it often enough.
 238+       * Pity that we still don't know where the match is.
 239+       * We only know the linenumber. So, we just hope the
 240+       * following will at least bring it on the screen ...
 241+       */
 242+      (void)display(lineno, 0, pagesize, 0);
 243+      (void)scrollb(2, 0);
 244+      redraw(0);
 245+      return;
 246+    }
 247+  }
 248+  /* NOTREACHED */
 249 }
 250 
 251 static int
 252 do_fsearch(long cnt)
 253 { /* Forward search */
 254-	do_search("/", cnt, 1);
 255-	return 0;
 256+  do_search("/", cnt, 1);
 257+  return 0;
 258 }
 259 
 260 static int
 261 do_bsearch(long cnt)
 262 { /* Backward search */
 263-	do_search("?", cnt, -1);
 264-	return 0;
 265+  do_search("?", cnt, -1);
 266+  return 0;
 267 }
 268 
 269 /*
 270@@ -160,178 +160,178 @@ do_bsearch(long cnt)
 271 static int
 272 n_or_rn_search(long cnt, int dir)
 273 {
 274-	char *p;
 275+  char *p;
 276 
 277-	if (dir == 1) {
 278-		p = "/\r";
 279-	} else if (dir == -1) {
 280-		p = "?\r";
 281-	} else {
 282-		error("No previous pattern");
 283-		return 0;
 284-	}
 285-	if (!stupid)
 286-		clrbline();
 287-	putline(p);
 288-	flush();
 289-	do_search((char *)0, cnt, dir);
 290-	return 0;
 291+  if (dir == 1) {
 292+    p = "/\r";
 293+  } else if (dir == -1) {
 294+    p = "?\r";
 295+  } else {
 296+    error("No previous pattern");
 297+    return 0;
 298+  }
 299+  if (!stupid)
 300+    clrbline();
 301+  putline(p);
 302+  flush();
 303+  do_search((char *)0, cnt, dir);
 304+  return 0;
 305 }
 306 
 307 static int
 308 do_nsearch(long cnt)
 309 { /* Repeat search in same direction */
 310-	n_or_rn_search(cnt, searchdir);
 311-	return 0;
 312+  n_or_rn_search(cnt, searchdir);
 313+  return 0;
 314 }
 315 
 316 static int
 317 do_rnsearch(long cnt)
 318 { /* Repeat search in opposite direction */
 319-	n_or_rn_search(cnt, -searchdir);
 320-	return 0;
 321+  n_or_rn_search(cnt, -searchdir);
 322+  return 0;
 323 }
 324 
 325 static int
 326 shell_command(int esc_ch, long cnt)
 327 {
 328-	char *p;
 329-	static char buf[2];
 330-
 331-	buf[0] = esc_ch;
 332-	buf[1] = '\0';
 333-	if ((p = readline(buf)) != 0) {
 334-		shellescape(p, esc_ch);
 335-		if (cnt >= 0 && !hardcopy) {
 336-			p = startcomm;
 337-			startcomm = 0;
 338-			ret_to_continue();
 339-			putline(TI);
 340-			if (!p) {
 341-				/*
 342-				 * Avoid double redraw.
 343-				 * After a "startcomm", a redraw will
 344-				 * take place anyway.
 345-				 */
 346-				redraw(1);
 347-			}
 348-		}
 349-	}
 350-	return 0;
 351+  char       *p;
 352+  static char buf[2];
 353+
 354+  buf[0] = esc_ch;
 355+  buf[1] = '\0';
 356+  if ((p = readline(buf)) != 0) {
 357+    shellescape(p, esc_ch);
 358+    if (cnt >= 0 && !hardcopy) {
 359+      p         = startcomm;
 360+      startcomm = 0;
 361+      ret_to_continue();
 362+      putline(TI);
 363+      if (!p) {
 364+        /*
 365+         * Avoid double redraw.
 366+         * After a "startcomm", a redraw will
 367+         * take place anyway.
 368+         */
 369+        redraw(1);
 370+      }
 371+    }
 372+  }
 373+  return 0;
 374 }
 375 
 376 static int
 377 do_shell(long cnt)
 378 { /* Execute a shell escape */
 379-	return shell_command('!', cnt);
 380+  return shell_command('!', cnt);
 381 }
 382 
 383 static int
 384 do_pipe(long cnt)
 385 { /* Execute a shell escape */
 386-	return shell_command('|', cnt);
 387+  return shell_command('|', cnt);
 388 }
 389 
 390 static int
 391 do_writefile(long cnt)
 392 { /* Write input to a file */
 393-	char *p;
 394-	int fd;
 395-	(void)cnt;
 396-
 397-	if ((p = readline("Filename: ")) == 0 || !*p) {
 398-		/*
 399-		 * No file name given
 400-		 */
 401-		return 0;
 402-	}
 403-	if ((fd = open(p, O_CREAT | O_EXCL | O_WRONLY, 0644)) < 0) {
 404-		if (errno == EEXIST) {
 405-			error("File exists");
 406-			return 0;
 407-		}
 408-		error("Could not open file");
 409-		return 0;
 410-	}
 411-	wrt_fd(fd);
 412-	(void)close(fd);
 413-	return 0;
 414+  char *p;
 415+  int   fd;
 416+  (void)cnt;
 417+
 418+  if ((p = readline("Filename: ")) == 0 || !*p) {
 419+    /*
 420+     * No file name given
 421+     */
 422+    return 0;
 423+  }
 424+  if ((fd = open(p, O_CREAT | O_EXCL | O_WRONLY, 0644)) < 0) {
 425+    if (errno == EEXIST) {
 426+      error("File exists");
 427+      return 0;
 428+    }
 429+    error("Could not open file");
 430+    return 0;
 431+  }
 432+  wrt_fd(fd);
 433+  (void)close(fd);
 434+  return 0;
 435 }
 436 
 437 void
 438 wrt_fd(int fd)
 439 {
 440-	long l = 1;
 441-	char *p = getline(l, 0), *pbuf;
 442-	char buf[1024];
 443-
 444-	while (p) {
 445-		pbuf = buf;
 446-		while (p && pbuf < &buf[1024]) {
 447-			if (!*p) {
 448-				*pbuf++ = '\n';
 449-				p = getline(++l, 0);
 450-			} else
 451-				*pbuf++ = *p++;
 452-		}
 453-		if (write(fd, buf, pbuf - buf) < 0) {
 454-			error("Write failed");
 455-			break;
 456-		}
 457-	}
 458+  long  l = 1;
 459+  char *p = getline(l, 0), *pbuf;
 460+  char  buf[1024];
 461+
 462+  while (p) {
 463+    pbuf = buf;
 464+    while (p && pbuf < &buf[1024]) {
 465+      if (!*p) {
 466+        *pbuf++ = '\n';
 467+        p       = getline(++l, 0);
 468+      } else
 469+        *pbuf++ = *p++;
 470+    }
 471+    if (write(fd, buf, pbuf - buf) < 0) {
 472+      error("Write failed");
 473+      break;
 474+    }
 475+  }
 476 }
 477 
 478 static int
 479 do_absolute(long cnt)
 480 { /* Go to linenumber "cnt" */
 481 
 482-	if (!getline(cnt, 0)) { /* Not there or interrupt */
 483-		if (!interrupt) {
 484-			/*
 485-			 * User did'nt give an interrupt, so the line number
 486-			 * was too high. Go to the last line.
 487-			 */
 488-			do_lline(cnt);
 489-		}
 490-		return 0;
 491-	}
 492-	(void)display(cnt, 0, pagesize, 1);
 493-	return 0;
 494+  if (!getline(cnt, 0)) { /* Not there or interrupt */
 495+    if (!interrupt) {
 496+      /*
 497+       * User did'nt give an interrupt, so the line number
 498+       * was too high. Go to the last line.
 499+       */
 500+      do_lline(cnt);
 501+    }
 502+    return 0;
 503+  }
 504+  (void)display(cnt, 0, pagesize, 1);
 505+  return 0;
 506 }
 507 
 508 static int
 509 do_visit(long cnt)
 510 { /* Visit a file */
 511-	char *p;
 512-	static char fn[128]; /* Keep file name */
 513-	(void)cnt;
 514-
 515-	if ((p = readline("Filename: ")) == 0) {
 516-		return 0;
 517-	}
 518-	if (*p) {
 519-		(void)strcpy(fn, p);
 520-		visitfile(fn);
 521-	} else {
 522-		/*
 523-		 * User typed a return. Visit the current file
 524-		 */
 525-		if (!(p = filenames[filecount])) {
 526-			error("No current file");
 527-			return 0;
 528-		}
 529-		visitfile(p);
 530-	}
 531-	(void)display(1L, 0, pagesize, 1);
 532-	return 0;
 533+  char       *p;
 534+  static char fn[128]; /* Keep file name */
 535+  (void)cnt;
 536+
 537+  if ((p = readline("Filename: ")) == 0) {
 538+    return 0;
 539+  }
 540+  if (*p) {
 541+    (void)strcpy(fn, p);
 542+    visitfile(fn);
 543+  } else {
 544+    /*
 545+     * User typed a return. Visit the current file
 546+     */
 547+    if (!(p = filenames[filecount])) {
 548+      error("No current file");
 549+      return 0;
 550+    }
 551+    visitfile(p);
 552+  }
 553+  (void)display(1L, 0, pagesize, 1);
 554+  return 0;
 555 }
 556 
 557 static int
 558 do_error(long cnt)
 559 { /* Called when user types wrong key sequence */
 560-	(void)cnt;
 561-	error(currmap->k_help);
 562-	return 0;
 563+  (void)cnt;
 564+  error(currmap->k_help);
 565+  return 0;
 566 }
 567 
 568 /*
 569@@ -342,17 +342,17 @@ do_error(long cnt)
 570 static int
 571 prev_screen(int sz, int really)
 572 {
 573-	int retval;
 574+  int retval;
 575 
 576-	retval = scrollb(sz - 1, really && cflag);
 577-	if (really && !cflag) {
 578-		/*
 579-		 * The previous call did not display anything, but at least we
 580-		 * know where to start
 581-		 */
 582-		return display(scr_info.firstline, scr_info.nf, sz, 1);
 583-	}
 584-	return retval;
 585+  retval = scrollb(sz - 1, really && cflag);
 586+  if (really && !cflag) {
 587+    /*
 588+     * The previous call did not display anything, but at least we
 589+     * know where to start
 590+     */
 591+    return display(scr_info.firstline, scr_info.nf, sz, 1);
 592+  }
 593+  return retval;
 594 }
 595 
 596 /*
 597@@ -363,245 +363,243 @@ prev_screen(int sz, int really)
 598 static int
 599 next_screen(int sz, int really)
 600 {
 601-	int t;
 602-	struct scr_info *p = &scr_info;
 603+  int              t;
 604+  struct scr_info *p = &scr_info;
 605 
 606-	if (cflag) {
 607-		return scrollf(sz - 1, really);
 608-	}
 609-	t = p->tail->cnt - 1;
 610-	if (p->lastline == p->firstline) {
 611-		t += p->nf;
 612-	}
 613-	return display(p->lastline, t, sz, really);
 614+  if (cflag) {
 615+    return scrollf(sz - 1, really);
 616+  }
 617+  t = p->tail->cnt - 1;
 618+  if (p->lastline == p->firstline) {
 619+    t += p->nf;
 620+  }
 621+  return display(p->lastline, t, sz, really);
 622 }
 623 
 624 static int
 625 do_redraw(long cnt)
 626 {
 627-	(void)cnt;
 628-	redraw(1);
 629-	return 0;
 630+  (void)cnt;
 631+  redraw(1);
 632+  return 0;
 633 }
 634 
 635 static int
 636 page_size(unsigned cnt)
 637 {
 638-
 639-	if (cnt) {
 640-		if (cnt > (unsigned)maxpagesize)
 641-			return maxpagesize;
 642-		if (cnt < MINPAGESIZE)
 643-			return MINPAGESIZE;
 644-		return (int)cnt;
 645-	}
 646-	return pagesize;
 647+  if (cnt) {
 648+    if (cnt > (unsigned)maxpagesize)
 649+      return maxpagesize;
 650+    if (cnt < MINPAGESIZE)
 651+      return MINPAGESIZE;
 652+    return (int)cnt;
 653+  }
 654+  return pagesize;
 655 }
 656 
 657 static int
 658 do_forward(long cnt)
 659 { /* Display next page */
 660-	int i;
 661+  int i;
 662 
 663-	i = page_size((unsigned)cnt);
 664-	if (status & EOFILE) {
 665-		/*
 666-		 * May seem strange, but actually a visit to the next file
 667-		 * has already been done here
 668-		 */
 669-		(void)display(1L, 0, i, 1);
 670-		return 0;
 671-	}
 672-	(void)next_screen(i, 1);
 673-	return 0;
 674+  i = page_size((unsigned)cnt);
 675+  if (status & EOFILE) {
 676+    /*
 677+     * May seem strange, but actually a visit to the next file
 678+     * has already been done here
 679+     */
 680+    (void)display(1L, 0, i, 1);
 681+    return 0;
 682+  }
 683+  (void)next_screen(i, 1);
 684+  return 0;
 685 }
 686 
 687 static int
 688 do_backward(long cnt)
 689 {
 690-	int i, temp;
 691-
 692-	i = page_size((unsigned)cnt);
 693-	if (!(status & START)) {
 694-		(void)prev_screen(i, 1);
 695-		return 0;
 696-	}
 697-	if (stdf < 0) {
 698-		(void)display(1L, 0, i, 1);
 699-		return 0;
 700-	}
 701-	/*
 702-	 * The next part is a bit clumsy.
 703-	 * We want to display the last page of the previous file (for which
 704-	 * a visit has already been done), but the pagesize may temporarily
 705-	 * be different because the command had a count
 706-	 */
 707-	temp = pagesize;
 708-	pagesize = i;
 709-	do_lline(cnt);
 710-	pagesize = temp;
 711-	return 0;
 712+  int i, temp;
 713+
 714+  i = page_size((unsigned)cnt);
 715+  if (!(status & START)) {
 716+    (void)prev_screen(i, 1);
 717+    return 0;
 718+  }
 719+  if (stdf < 0) {
 720+    (void)display(1L, 0, i, 1);
 721+    return 0;
 722+  }
 723+  /*
 724+   * The next part is a bit clumsy.
 725+   * We want to display the last page of the previous file (for which
 726+   * a visit has already been done), but the pagesize may temporarily
 727+   * be different because the command had a count
 728+   */
 729+  temp     = pagesize;
 730+  pagesize = i;
 731+  do_lline(cnt);
 732+  pagesize = temp;
 733+  return 0;
 734 }
 735 
 736 static int
 737 do_firstline(long cnt)
 738 { /* Go to start of input */
 739-	(void)cnt;
 740-	do_absolute(1L);
 741-	return 0;
 742+  (void)cnt;
 743+  do_absolute(1L);
 744+  return 0;
 745 }
 746 
 747 static int
 748 do_lline(long cnt)
 749 { /* Go to end of input */
 750-	int i = 0;
 751-	int j = pagesize - 1;
 752-
 753-	if ((cnt = to_lastline()) < 0) {
 754-		/*
 755-		 * Interrupted by the user
 756-		 */
 757-		return 0;
 758-	}
 759-	/*
 760-	 * Display the page such that only the last line of the page is
 761-	 * a "~", independant of the pagesize
 762-	 */
 763-	while (!(display(cnt, i, j, 0) & EOFILE)) {
 764-		/*
 765-		 * The last line could of course be very long ...
 766-		 */
 767-		i += j;
 768-	}
 769-	(void)scrollb(j - scr_info.tail->cnt, 0);
 770-	redraw(0);
 771-	return 0;
 772+  int i = 0;
 773+  int j = pagesize - 1;
 774+
 775+  if ((cnt = to_lastline()) < 0) {
 776+    /*
 777+     * Interrupted by the user
 778+     */
 779+    return 0;
 780+  }
 781+  /*
 782+   * Display the page such that only the last line of the page is
 783+   * a "~", independant of the pagesize
 784+   */
 785+  while (!(display(cnt, i, j, 0) & EOFILE)) {
 786+    /*
 787+     * The last line could of course be very long ...
 788+     */
 789+    i += j;
 790+  }
 791+  (void)scrollb(j - scr_info.tail->cnt, 0);
 792+  redraw(0);
 793+  return 0;
 794 }
 795 
 796 static int
 797 do_lf(long cnt)
 798 { /* Display next line, or go to line */
 799 
 800-	if (cnt) { /* Go to line */
 801-		do_absolute(cnt);
 802-		return 0;
 803-	}
 804-	(void)scrollf(1, 1);
 805-	return 0;
 806+  if (cnt) { /* Go to line */
 807+    do_absolute(cnt);
 808+    return 0;
 809+  }
 810+  (void)scrollf(1, 1);
 811+  return 0;
 812 }
 813 
 814 static int
 815 do_upline(long cnt)
 816 { /* Display previous line, or go to line */
 817 
 818-	if (cnt) { /* Go to line */
 819-		do_absolute(cnt);
 820-		return 0;
 821-	}
 822-	(void)scrollb(1, 1);
 823-	return 0;
 824+  if (cnt) { /* Go to line */
 825+    do_absolute(cnt);
 826+    return 0;
 827+  }
 828+  (void)scrollb(1, 1);
 829+  return 0;
 830 }
 831 
 832 static int
 833 do_skiplines(long cnt)
 834 { /* Skip lines forwards */
 835 
 836-	/* Should be interruptable ... */
 837-	(void)scrollf((int)(cnt + maxpagesize - 1), 0);
 838-	redraw(0);
 839-	return 0;
 840+  /* Should be interruptable ... */
 841+  (void)scrollf((int)(cnt + maxpagesize - 1), 0);
 842+  redraw(0);
 843+  return 0;
 844 }
 845 
 846 static int
 847 do_bskiplines(long cnt)
 848 { /* Skip lines backwards */
 849 
 850-	/* Should be interruptable ... */
 851-	(void)scrollb((int)(cnt + pagesize - 1), 0);
 852-	redraw(0);
 853-	return 0;
 854+  /* Should be interruptable ... */
 855+  (void)scrollb((int)(cnt + pagesize - 1), 0);
 856+  redraw(0);
 857+  return 0;
 858 }
 859 
 860 static int
 861 do_fscreens(long cnt)
 862 { /* Skip screens forwards */
 863 
 864-	do {
 865-		if ((next_screen(pagesize, 0) & EOFILE) || interrupt)
 866-			break;
 867-	} while (--cnt >= 0);
 868-	redraw(0);
 869-	return 0;
 870+  do {
 871+    if ((next_screen(pagesize, 0) & EOFILE) || interrupt)
 872+      break;
 873+  } while (--cnt >= 0);
 874+  redraw(0);
 875+  return 0;
 876 }
 877 
 878 static int
 879 do_bscreens(long cnt)
 880 { /* Skip screens backwards */
 881 
 882-	do {
 883-		if ((prev_screen(pagesize, 0) & START) || interrupt)
 884-			break;
 885-	} while (--cnt >= 0);
 886-	redraw(0);
 887-	return 0;
 888+  do {
 889+    if ((prev_screen(pagesize, 0) & START) || interrupt)
 890+      break;
 891+  } while (--cnt >= 0);
 892+  redraw(0);
 893+  return 0;
 894 }
 895 
 896 static int
 897 scro_size(unsigned cnt)
 898 {
 899-
 900-	if (cnt >= (unsigned)maxpagesize)
 901-		return maxpagesize;
 902-	if (cnt)
 903-		return (int)cnt;
 904-	return scrollsize;
 905+  if (cnt >= (unsigned)maxpagesize)
 906+    return maxpagesize;
 907+  if (cnt)
 908+    return (int)cnt;
 909+  return scrollsize;
 910 }
 911 
 912 static int
 913 do_f_scroll(long cnt)
 914 { /* Scroll forwards */
 915 
 916-	(void)scrollf(scro_size((unsigned)cnt), 1);
 917-	return 0;
 918+  (void)scrollf(scro_size((unsigned)cnt), 1);
 919+  return 0;
 920 }
 921 
 922 static int
 923 do_b_scroll(long cnt)
 924 { /* Scroll backwards */
 925 
 926-	(void)scrollb(scro_size((unsigned)cnt), 1);
 927-	return 0;
 928+  (void)scrollb(scro_size((unsigned)cnt), 1);
 929+  return 0;
 930 }
 931 
 932 static int
 933 do_previousfile(long cnt)
 934 { /* Visit previous file */
 935 
 936-	if (nextfile(-(int)cnt)) {
 937-		error("No (Nth) previous file");
 938-		return 0;
 939-	}
 940-	redraw(0);
 941-	return 0;
 942+  if (nextfile(-(int)cnt)) {
 943+    error("No (Nth) previous file");
 944+    return 0;
 945+  }
 946+  redraw(0);
 947+  return 0;
 948 }
 949 
 950 static int
 951 do_nextfile(long cnt)
 952 { /* Visit next file */
 953 
 954-	if (nextfile((int)cnt)) {
 955-		error("No (Nth) next file");
 956-		return 0;
 957-	}
 958-	redraw(0);
 959-	return 0;
 960+  if (nextfile((int)cnt)) {
 961+    error("No (Nth) next file");
 962+    return 0;
 963+  }
 964+  redraw(0);
 965+  return 0;
 966 }
 967 
 968 static int
 969 do_quit(long cnt)
 970 {
 971-	(void)cnt;
 972-	return quit();
 973+  (void)cnt;
 974+  return quit();
 975 }
 976 
 977 /*
 978@@ -611,44 +609,39 @@ do_quit(long cnt)
 979 struct commands commands[] = {
 980     {"", 0, do_error, ""},
 981     {"", 0, do_nocomm, ""},
 982-    {"bf", STICKY | NEEDS_COUNT,
 983-     do_previousfile, "Visit previous file"},
 984-    {"bl", NEEDS_SCREEN | STICKY,
 985-     do_upline, "Scroll one line up, or go to line"},
 986-    {"bot", STICKY,
 987-     do_lline, "Go to last line of the input"},
 988-    {"bp", BACK | NEEDS_SCREEN | TOPREVFILE | STICKY,
 989-     do_backward, "display previous page"},
 990-    {"bps", SCREENSIZE_ADAPT | BACK | NEEDS_SCREEN | TOPREVFILE | STICKY,
 991-     do_backward, "Display previous page, set pagesize"},
 992-    {"bs", BACK | NEEDS_SCREEN | STICKY,
 993-     do_b_scroll, "Scroll backwards"},
 994+    {"bf", STICKY | NEEDS_COUNT, do_previousfile, "Visit previous file"},
 995+    {"bl", NEEDS_SCREEN | STICKY, do_upline, "Scroll one line up, or go to line"},
 996+    {"bot", STICKY, do_lline, "Go to last line of the input"},
 997+    {"bp", BACK | NEEDS_SCREEN | TOPREVFILE | STICKY, do_backward, "display previous page"},
 998+    {"bps",
 999+     SCREENSIZE_ADAPT | BACK | NEEDS_SCREEN | TOPREVFILE | STICKY,
1000+     do_backward,
1001+     "Display previous page, set pagesize"},
1002+    {"bs", BACK | NEEDS_SCREEN | STICKY, do_b_scroll, "Scroll backwards"},
1003     {"bse", 0, do_bsearch, "Search backwards for pattern"},
1004-    {"bsl", BACK | NEEDS_SCREEN | STICKY | NEEDS_COUNT,
1005-     do_bskiplines, "Skip lines backwards"},
1006-    {"bsp", BACK | NEEDS_SCREEN | STICKY | NEEDS_COUNT,
1007-     do_bscreens, "Skip screens backwards"},
1008-    {"bss", SCROLLSIZE_ADAPT | BACK | NEEDS_SCREEN | STICKY,
1009-     do_b_scroll, "Scroll backwards, set scrollsize"},
1010+    {"bsl", BACK | NEEDS_SCREEN | STICKY | NEEDS_COUNT, do_bskiplines, "Skip lines backwards"},
1011+    {"bsp", BACK | NEEDS_SCREEN | STICKY | NEEDS_COUNT, do_bscreens, "Skip screens backwards"},
1012+    {"bss",
1013+     SCROLLSIZE_ADAPT | BACK | NEEDS_SCREEN | STICKY,
1014+     do_b_scroll,
1015+     "Scroll backwards, set scrollsize"},
1016     {"chm", 0, do_chkm, "Switch to other keymap"},
1017     {"exg", STICKY, exgmark, "Exchange current page with mark"},
1018-    {"ff", STICKY | NEEDS_COUNT,
1019-     do_nextfile, "Visit next file"},
1020-    {"fl", NEEDS_SCREEN | STICKY,
1021-     do_lf, "Scroll one line down, or go to line"},
1022-    {"fp", TONEXTFILE | AHEAD | STICKY,
1023-     do_forward, "Display next page"},
1024-    {"fps", SCREENSIZE_ADAPT | TONEXTFILE | AHEAD | STICKY,
1025-     do_forward, "Display next page, set pagesize"},
1026-    {"fs", AHEAD | NEEDS_SCREEN | STICKY,
1027-     do_f_scroll, "Scroll forwards"},
1028+    {"ff", STICKY | NEEDS_COUNT, do_nextfile, "Visit next file"},
1029+    {"fl", NEEDS_SCREEN | STICKY, do_lf, "Scroll one line down, or go to line"},
1030+    {"fp", TONEXTFILE | AHEAD | STICKY, do_forward, "Display next page"},
1031+    {"fps",
1032+     SCREENSIZE_ADAPT | TONEXTFILE | AHEAD | STICKY,
1033+     do_forward,
1034+     "Display next page, set pagesize"},
1035+    {"fs", AHEAD | NEEDS_SCREEN | STICKY, do_f_scroll, "Scroll forwards"},
1036     {"fse", 0, do_fsearch, "Search forwards for pattern"},
1037-    {"fsl", AHEAD | NEEDS_SCREEN | STICKY | NEEDS_COUNT,
1038-     do_skiplines, "Skip lines forwards"},
1039-    {"fsp", AHEAD | NEEDS_SCREEN | STICKY | NEEDS_COUNT,
1040-     do_fscreens, "Skip screens forwards"},
1041-    {"fss", SCROLLSIZE_ADAPT | AHEAD | NEEDS_SCREEN | STICKY,
1042-     do_f_scroll, "Scroll forwards, set scrollsize"},
1043+    {"fsl", AHEAD | NEEDS_SCREEN | STICKY | NEEDS_COUNT, do_skiplines, "Skip lines forwards"},
1044+    {"fsp", AHEAD | NEEDS_SCREEN | STICKY | NEEDS_COUNT, do_fscreens, "Skip screens forwards"},
1045+    {"fss",
1046+     SCROLLSIZE_ADAPT | AHEAD | NEEDS_SCREEN | STICKY,
1047+     do_f_scroll,
1048+     "Scroll forwards, set scrollsize"},
1049     {"hlp", 0, do_help, "Give description of all commands"},
1050     {"mar", 0, setmark, "Set a mark on the current page"},
1051     {"nse", STICKY, do_nsearch, "Repeat the last search"},
1052@@ -672,37 +665,37 @@ struct commands commands[] = {
1053 int
1054 lookup(char *s)
1055 {
1056-	struct commands *l, *u, *m;
1057-
1058-	l = &commands[2];
1059-	u = &commands[sizeof(commands) / sizeof(*u) - 1];
1060-	do {
1061-		/*
1062-		 * Perform binary search
1063-		 */
1064-		m = l + (u - l) / 2;
1065-		if (strcmp(s, m->c_cmd) > 0)
1066-			l = m + 1;
1067-		else
1068-			u = m;
1069-	} while (l < u);
1070-	if (!strcmp(s, u->c_cmd))
1071-		return u - commands;
1072-	return 0;
1073+  struct commands *l, *u, *m;
1074+
1075+  l = &commands[2];
1076+  u = &commands[sizeof(commands) / sizeof(*u) - 1];
1077+  do {
1078+    /*
1079+     * Perform binary search
1080+     */
1081+    m = l + (u - l) / 2;
1082+    if (strcmp(s, m->c_cmd) > 0)
1083+      l = m + 1;
1084+    else
1085+      u = m;
1086+  } while (l < u);
1087+  if (!strcmp(s, u->c_cmd))
1088+    return u - commands;
1089+  return 0;
1090 }
1091 
1092 /*ARGSUSED*/
1093 static int
1094 do_lcomm(long cnt)
1095 { /* Repeat last command */
1096-	(void)cnt;
1097+  (void)cnt;
1098 
1099-	if (!lastcomm) {
1100-		error("No previous command");
1101-		return 0;
1102-	}
1103-	do_comm(lastcomm, lastcount);
1104-	return 0;
1105+  if (!lastcomm) {
1106+    error("No previous command");
1107+    return 0;
1108+  }
1109+  do_comm(lastcomm, lastcount);
1110+  return 0;
1111 }
1112 
1113 /*
1114@@ -712,74 +705,74 @@ do_lcomm(long cnt)
1115 void
1116 do_comm(int comm, long count)
1117 {
1118-	struct commands *pcomm;
1119-	int temp;
1120-	int flags;
1121-
1122-	pcomm = &commands[comm];
1123-	flags = pcomm->c_flags;
1124-
1125-	/*
1126-	 * Check the command.
1127-	 * If the last line of the file is displayed and the command goes
1128-	 * forwards and does'nt have the ability to go to the next file, it
1129-	 * is an error.
1130-	 * If the first line of the file is displayed and the command goes
1131-	 * backwards and does'nt have the ability to go to the previous file,
1132-	 * it is an error.
1133-	 * Also check wether we need the next or previous file. If so, get it.
1134-	 */
1135-	if ((status & EOFILE) && (flags & AHEAD)) {
1136-		if (qflag || !(flags & TONEXTFILE))
1137-			return;
1138-		if (nextfile(1))
1139-			quit();
1140-	}
1141-	if ((status & START) && (flags & BACK)) {
1142-		if (qflag || !(flags & TOPREVFILE))
1143-			return;
1144-		if (nextfile(-1))
1145-			quit();
1146-	}
1147-	/*
1148-	 * Does the command stick around for LASTCOMM?
1149-	 */
1150-	if (flags & STICKY) {
1151-		lastcomm = comm;
1152-		lastcount = count;
1153-	}
1154-	if (!count) {
1155-		if (flags & NEEDS_COUNT)
1156-			count = 1;
1157-	} else {
1158-		/*
1159-		 * Does the command adapt the screensize?
1160-		 */
1161-		if (flags & SCREENSIZE_ADAPT) {
1162-			temp = maxpagesize;
1163-			if ((unsigned)count < (unsigned)temp) {
1164-				temp = (int)count;
1165-			}
1166-			if (temp < MINPAGESIZE) {
1167-				temp = MINPAGESIZE;
1168-			}
1169-			count = 0;
1170-			pagesize = temp;
1171-		}
1172-		/*
1173-		 * Does the command adapt the scrollsize?
1174-		 */
1175-		if (flags & SCROLLSIZE_ADAPT) {
1176-			temp = maxpagesize - 1;
1177-			if ((unsigned)count < (unsigned)temp) {
1178-				temp = (int)count;
1179-			}
1180-			scrollsize = temp;
1181-			count = 0;
1182-		}
1183-	}
1184-	/*
1185-	 * Now execute the command.
1186-	 */
1187-	(*(pcomm->c_func))(count);
1188+  struct commands *pcomm;
1189+  int              temp;
1190+  int              flags;
1191+
1192+  pcomm = &commands[comm];
1193+  flags = pcomm->c_flags;
1194+
1195+  /*
1196+   * Check the command.
1197+   * If the last line of the file is displayed and the command goes
1198+   * forwards and does'nt have the ability to go to the next file, it
1199+   * is an error.
1200+   * If the first line of the file is displayed and the command goes
1201+   * backwards and does'nt have the ability to go to the previous file,
1202+   * it is an error.
1203+   * Also check wether we need the next or previous file. If so, get it.
1204+   */
1205+  if ((status & EOFILE) && (flags & AHEAD)) {
1206+    if (qflag || !(flags & TONEXTFILE))
1207+      return;
1208+    if (nextfile(1))
1209+      quit();
1210+  }
1211+  if ((status & START) && (flags & BACK)) {
1212+    if (qflag || !(flags & TOPREVFILE))
1213+      return;
1214+    if (nextfile(-1))
1215+      quit();
1216+  }
1217+  /*
1218+   * Does the command stick around for LASTCOMM?
1219+   */
1220+  if (flags & STICKY) {
1221+    lastcomm  = comm;
1222+    lastcount = count;
1223+  }
1224+  if (!count) {
1225+    if (flags & NEEDS_COUNT)
1226+      count = 1;
1227+  } else {
1228+    /*
1229+     * Does the command adapt the screensize?
1230+     */
1231+    if (flags & SCREENSIZE_ADAPT) {
1232+      temp = maxpagesize;
1233+      if ((unsigned)count < (unsigned)temp) {
1234+        temp = (int)count;
1235+      }
1236+      if (temp < MINPAGESIZE) {
1237+        temp = MINPAGESIZE;
1238+      }
1239+      count    = 0;
1240+      pagesize = temp;
1241+    }
1242+    /*
1243+     * Does the command adapt the scrollsize?
1244+     */
1245+    if (flags & SCROLLSIZE_ADAPT) {
1246+      temp = maxpagesize - 1;
1247+      if ((unsigned)count < (unsigned)temp) {
1248+        temp = (int)count;
1249+      }
1250+      scrollsize = temp;
1251+      count      = 0;
1252+    }
1253+  }
1254+  /*
1255+   * Now execute the command.
1256+   */
1257+  (*(pcomm->c_func))(count);
1258 }
+14, -14
 1@@ -3,25 +3,25 @@
 2 
 3 #define SCREENSIZE_ADAPT 01
 4 #define SCROLLSIZE_ADAPT 02
 5-#define TONEXTFILE 04
 6-#define AHEAD 010
 7-#define BACK 020
 8-#define NEEDS_SCREEN 040
 9-#define TOPREVFILE 0100
10-#define STICKY 0200
11-#define NEEDS_COUNT 0400
12-#define ESC 01000
13+#define TONEXTFILE       04
14+#define AHEAD            010
15+#define BACK             020
16+#define NEEDS_SCREEN     040
17+#define TOPREVFILE       0100
18+#define STICKY           0200
19+#define NEEDS_COUNT      0400
20+#define ESC              01000
21 
22 extern struct commands {
23-	char *c_cmd;
24-	int c_flags;
25-	int (*c_func)(long);
26-	char *c_descr;
27+  char *c_cmd;
28+  int   c_flags;
29+  int (*c_func)(long);
30+  char *c_descr;
31 } commands[];
32 
33-int do_chkm(long cnt);
34+int  do_chkm(long cnt);
35 void do_comm(int command, long count);
36-int lookup(char *str);
37+int  lookup(char *str);
38 void wrt_fd(int fd);
39 
40 #endif
+540, -554
   1@@ -1,32 +1,31 @@
   2 /* Copyright (c) 1985 Ceriel J.H. Jacobs */
   3 
   4-#include "in_all.h"
   5 #include "display.h"
   6 #include "assert.h"
   7+#include "getline.h"
   8+#include "in_all.h"
   9 #include "machine.h"
  10-#include "term.h"
  11-#include "output.h"
  12+#include "main.h"
  13 #include "options.h"
  14+#include "output.h"
  15 #include "process.h"
  16-#include "getline.h"
  17-#include "main.h"
  18+#include "term.h"
  19 #define getline yap_getline
  20 #include "utf.h"
  21 #undef getline
  22 #include "ansi.h"
  23 
  24-int pagesize;
  25-int maxpagesize;
  26-int scrollsize;
  27+int             pagesize;
  28+int             maxpagesize;
  29+int             scrollsize;
  30 struct scr_info scr_info;
  31-int status;
  32+int             status;
  33 
  34 static char *do_line(char *str, int reallydispl);
  35-static void flush_display_buffer(char *buf, char **p);
  36-static int rune_width(Rune r);
  37-static int decode_cell(const char *s, const char **next, int *width,
  38-                       int *is_underscore);
  39-int wcwidth(wchar_t wc);
  40+static void  flush_display_buffer(char *buf, char **p);
  41+static int   rune_width(Rune r);
  42+static int   decode_cell(const char *s, const char **next, int *width, int *is_underscore);
  43+int          wcwidth(wchar_t wc);
  44 
  45 /*
  46  * Fill n lines of the screen, each with "str".
  47@@ -35,10 +34,9 @@ int wcwidth(wchar_t wc);
  48 static void
  49 fillscr(char *str, int n)
  50 {
  51-
  52-	while (n-- > 0) {
  53-		putline(str);
  54-	}
  55+  while (n-- > 0) {
  56+    putline(str);
  57+  }
  58 }
  59 
  60 /*
  61@@ -48,12 +46,11 @@ fillscr(char *str, int n)
  62 static char *
  63 skiplines(char *p, int n)
  64 {
  65-
  66-	while (n-- > 0) {
  67-		p = do_line(p, 0);
  68-		scr_info.currentpos--;
  69-	}
  70-	return p;
  71+  while (n-- > 0) {
  72+    p = do_line(p, 0);
  73+    scr_info.currentpos--;
  74+  }
  75+  return p;
  76 }
  77 
  78 /*
  79@@ -65,14 +62,14 @@ skiplines(char *p, int n)
  80 void
  81 redraw(int n)
  82 {
  83-	struct scr_info *p = &scr_info;
  84-	int i;
  85-
  86-	i = pagesize;
  87-	if (n && p->currentpos) {
  88-		i = p->currentpos;
  89-	}
  90-	(void)display(p->firstline, p->nf, i, 1);
  91+  struct scr_info *p = &scr_info;
  92+  int              i;
  93+
  94+  i = pagesize;
  95+  if (n && p->currentpos) {
  96+    i = p->currentpos;
  97+  }
  98+  (void)display(p->firstline, p->nf, i, 1);
  99 }
 100 
 101 /*
 102@@ -85,18 +82,18 @@ redraw(int n)
 103 static int
 104 compretval(const char *s)
 105 {
 106-	int i;
 107-	struct scr_info *p = &scr_info;
 108-
 109-	i = 0;
 110-	if (!s || (!*s && !getline(p->lastline + 1, 1))) {
 111-		i = EOFILE;
 112-	}
 113-	if (p->firstline == 1 && !p->nf) {
 114-		i |= START;
 115-	}
 116-	status = i;
 117-	return i;
 118+  int              i;
 119+  struct scr_info *p = &scr_info;
 120+
 121+  i = 0;
 122+  if (!s || (!*s && !getline(p->lastline + 1, 1))) {
 123+    i = EOFILE;
 124+  }
 125+  if (p->firstline == 1 && !p->nf) {
 126+    i |= START;
 127+  }
 128+  status = i;
 129+  return i;
 130 }
 131 
 132 /*
 133@@ -109,71 +106,70 @@ compretval(const char *s)
 134 int
 135 display(long n, int nd, int nlines, int reallydispl)
 136 {
 137-
 138-	struct scr_info *s = &scr_info;
 139-	char *p; /* pointer to line to be displayed */
 140-
 141-	if (startcomm) { /* No displaying on a command from the
 142-		          * yap command line. In this case, displaying
 143-		          * will be done after executing the command,
 144-		          * by a redraw.
 145-		          */
 146-		reallydispl = 0;
 147-	}
 148-	if (!n) {
 149-		n = 1L;
 150-		nd = 0;
 151-	}
 152-	if (reallydispl) { /* move cursor to starting point */
 153-		if (stupid) {
 154-			putline(currentfile);
 155-			putline(", line ");
 156-			prnum(n);
 157-			nlines--;
 158-		}
 159-		if (cflag) {
 160-			putline("\r\n");
 161-		} else {
 162-			home();
 163-			clrscreen();
 164-		}
 165-	}
 166-	/*
 167-	 * Now, do computations and display
 168-	 */
 169-	s->currentpos = 0;
 170-	s->nf = nd;
 171-	s->head = s->tail;
 172-	s->tail->cnt = 0;
 173-	s->tail->line = n;
 174-	p = skiplines(getline(n, 1), nd);
 175-	while (nlines && p) {
 176-		/*
 177-		 * While there is room,
 178-		 * and there is something left to display ...
 179-		 */
 180-		(s->tail->cnt)++;
 181-		nlines--;
 182-		if (*(p = do_line(p, reallydispl)) == '\0') {
 183-			/*
 184-			 * File-line finished, get next one ...
 185-			 */
 186-			p = getline(++n, 1);
 187-			if (nlines && p) {
 188-				s->tail = s->tail->next;
 189-				s->tail->cnt = 0;
 190-				s->tail->line = n;
 191-			}
 192-		}
 193-	}
 194-	if (!stupid) {
 195-		s->currentpos += nlines;
 196-		if (reallydispl) {
 197-			fillscr("~\r\n", nlines);
 198-			fillscr("\r\n", maxpagesize - s->currentpos);
 199-		}
 200-	}
 201-	return compretval(p);
 202+  struct scr_info *s = &scr_info;
 203+  char            *p; /* pointer to line to be displayed */
 204+
 205+  if (startcomm) { /* No displaying on a command from the
 206+                    * yap command line. In this case, displaying
 207+                    * will be done after executing the command,
 208+                    * by a redraw.
 209+                    */
 210+    reallydispl = 0;
 211+  }
 212+  if (!n) {
 213+    n  = 1L;
 214+    nd = 0;
 215+  }
 216+  if (reallydispl) { /* move cursor to starting point */
 217+    if (stupid) {
 218+      putline(currentfile);
 219+      putline(", line ");
 220+      prnum(n);
 221+      nlines--;
 222+    }
 223+    if (cflag) {
 224+      putline("\r\n");
 225+    } else {
 226+      home();
 227+      clrscreen();
 228+    }
 229+  }
 230+  /*
 231+   * Now, do computations and display
 232+   */
 233+  s->currentpos = 0;
 234+  s->nf         = nd;
 235+  s->head       = s->tail;
 236+  s->tail->cnt  = 0;
 237+  s->tail->line = n;
 238+  p             = skiplines(getline(n, 1), nd);
 239+  while (nlines && p) {
 240+    /*
 241+     * While there is room,
 242+     * and there is something left to display ...
 243+     */
 244+    (s->tail->cnt)++;
 245+    nlines--;
 246+    if (*(p = do_line(p, reallydispl)) == '\0') {
 247+      /*
 248+       * File-line finished, get next one ...
 249+       */
 250+      p = getline(++n, 1);
 251+      if (nlines && p) {
 252+        s->tail       = s->tail->next;
 253+        s->tail->cnt  = 0;
 254+        s->tail->line = n;
 255+      }
 256+    }
 257+  }
 258+  if (!stupid) {
 259+    s->currentpos += nlines;
 260+    if (reallydispl) {
 261+      fillscr("~\r\n", nlines);
 262+      fillscr("\r\n", maxpagesize - s->currentpos);
 263+    }
 264+  }
 265+  return compretval(p);
 266 }
 267 
 268 /*
 269@@ -183,71 +179,70 @@ display(long n, int nd, int nlines, int reallydispl)
 270 int
 271 scrollf(int n, int reallydispl)
 272 {
 273-
 274-	struct scr_info *s = &scr_info;
 275-	char *p;
 276-	long ll;
 277-	int i;
 278-
 279-	/*
 280-	 * First, find out how many screenlines of the last line were already
 281-	 * on the screen, and possibly above it.
 282-	 */
 283-
 284-	if (n <= 0 || (status & EOFILE))
 285-		return status;
 286-	if (startcomm)
 287-		reallydispl = 0;
 288-	/*
 289-	 * Find out where to begin displaying
 290-	 */
 291-	i = s->tail->cnt;
 292-	if ((ll = s->lastline) == s->firstline)
 293-		i += s->nf;
 294-	p = skiplines(getline(ll, 1), i);
 295-	/*
 296-	 * Now, place the cursor at the first free line
 297-	 */
 298-	if (reallydispl && !stupid) {
 299-		clrbline();
 300-		mgoto(s->currentpos);
 301-	}
 302-	/*
 303-	 * Now display lines, keeping track of which lines are on the screen.
 304-	 */
 305-	while (n-- > 0) {  /* There are still rows to be displayed */
 306-		if (!*p) { /* End of line, get next one */
 307-			if (!(p = getline(++ll, 1))) {
 308-				/*
 309-				 * No lines left. At end of file
 310-				 */
 311-				break;
 312-			}
 313-			s->tail = s->tail->next;
 314-			s->tail->cnt = 0;
 315-			s->tail->line = ll;
 316-		}
 317-		if (s->currentpos >= maxpagesize) {
 318-			/*
 319-			 * No room, delete first screen-line
 320-			 */
 321-			s->currentpos--;
 322-			s->nf++;
 323-			if (--(s->head->cnt) == 0) {
 324-				/*
 325-				 * The first file-line on the screen is wiped
 326-				 * out completely; update administration
 327-				 * accordingly.
 328-				 */
 329-				s->nf = 0;
 330-				s->head = s->head->next;
 331-				assert(s->head->cnt > 0);
 332-			}
 333-		}
 334-		s->tail->cnt++;
 335-		p = do_line(p, reallydispl);
 336-	}
 337-	return compretval(p);
 338+  struct scr_info *s = &scr_info;
 339+  char            *p;
 340+  long             ll;
 341+  int              i;
 342+
 343+  /*
 344+   * First, find out how many screenlines of the last line were already
 345+   * on the screen, and possibly above it.
 346+   */
 347+
 348+  if (n <= 0 || (status & EOFILE))
 349+    return status;
 350+  if (startcomm)
 351+    reallydispl = 0;
 352+  /*
 353+   * Find out where to begin displaying
 354+   */
 355+  i = s->tail->cnt;
 356+  if ((ll = s->lastline) == s->firstline)
 357+    i += s->nf;
 358+  p = skiplines(getline(ll, 1), i);
 359+  /*
 360+   * Now, place the cursor at the first free line
 361+   */
 362+  if (reallydispl && !stupid) {
 363+    clrbline();
 364+    mgoto(s->currentpos);
 365+  }
 366+  /*
 367+   * Now display lines, keeping track of which lines are on the screen.
 368+   */
 369+  while (n-- > 0) { /* There are still rows to be displayed */
 370+    if (!*p) {      /* End of line, get next one */
 371+      if (!(p = getline(++ll, 1))) {
 372+        /*
 373+         * No lines left. At end of file
 374+         */
 375+        break;
 376+      }
 377+      s->tail       = s->tail->next;
 378+      s->tail->cnt  = 0;
 379+      s->tail->line = ll;
 380+    }
 381+    if (s->currentpos >= maxpagesize) {
 382+      /*
 383+       * No room, delete first screen-line
 384+       */
 385+      s->currentpos--;
 386+      s->nf++;
 387+      if (--(s->head->cnt) == 0) {
 388+        /*
 389+         * The first file-line on the screen is wiped
 390+         * out completely; update administration
 391+         * accordingly.
 392+         */
 393+        s->nf   = 0;
 394+        s->head = s->head->next;
 395+        assert(s->head->cnt > 0);
 396+      }
 397+    }
 398+    s->tail->cnt++;
 399+    p = do_line(p, reallydispl);
 400+  }
 401+  return compretval(p);
 402 }
 403 
 404 /*
 405@@ -257,109 +252,105 @@ scrollf(int n, int reallydispl)
 406 int
 407 scrollb(int n, int reallydispl)
 408 {
 409-
 410-	struct scr_info *s = &scr_info;
 411-	char *p; /* Holds string to be displayed */
 412-	int i;
 413-	int count;
 414-	long ln; /* a line number */
 415-	int nodispl;
 416-	int cannotscroll; /* stupid or no insert-line */
 417-
 418-	/*
 419-	 * First, find out where to start
 420-	 */
 421-	if ((count = n) <= 0 || (status & START))
 422-		return status;
 423-	if (startcomm)
 424-		reallydispl = 0;
 425-	cannotscroll = stupid || (!*AL && !*SR);
 426-	ln = s->firstline;
 427-	nodispl = s->nf;
 428-	while (count) { /* While scrolling back ... */
 429-		i = nodispl;
 430-		if (i) {
 431-			/*
 432-			 * There were screen-lines of s->firstline that were not
 433-			 * displayed.
 434-			 * We can use them now, but only "count" of them.
 435-			 */
 436-			if (i > count)
 437-				i = count;
 438-			s->currentpos += i;
 439-			nodispl -= i;
 440-			count -= i;
 441-		} else { /* Get previous line */
 442-			if (ln == 1)
 443-				break; /* isn't there ... */
 444-			p = getline(--ln, 1);
 445-			/*
 446-			 * Make it the first line of the screen and compute
 447-			 * how many screenlines it takes. These lines are not
 448-			 * displayed, but nodispl is set to this count, so
 449-			 * that it will be nonzero next time around
 450-			 */
 451-			nodispl = 0;
 452-			do { /* Find out how many screenlines */
 453-				nodispl++;
 454-				p = skiplines(p, 1);
 455-			} while (*p);
 456-		}
 457-	}
 458-	n -= count;
 459-	if ((i = s->currentpos) > maxpagesize)
 460-		i = maxpagesize;
 461-	if (reallydispl && hardcopy)
 462-		i = n;
 463-	/*
 464-	 * Now that we know where to start, we can use "display" to do the
 465-	 * rest of the computing for us, and maybe even the displaying ...
 466-	 */
 467-	i = display(ln,
 468-	            nodispl,
 469-	            i,
 470-	            reallydispl && cannotscroll);
 471-	if (cannotscroll || !reallydispl) {
 472-		/*
 473-		 * Yes, "display" did the displaying, or we did'nt have to
 474-		 * display at all.
 475-		 * I like it, but the user obviously does not.
 476-		 * Let him buy another (smarter) terminal ...
 477-		 */
 478-		return i;
 479-	}
 480-	/*
 481-	 * Now, all we have to do is the displaying. And we are dealing with
 482-	 * a smart terminal (it can insert lines or scroll back).
 483-	 */
 484-	home();
 485-	/*
 486-	 * Insert lines all at once
 487-	 */
 488-	for (i = n; i; i--) {
 489-		if (DB && *CE) {
 490-			/*
 491-			 * Grumble..., terminal retains lines below, so we have
 492-			 * to clear the lines that we push off the screen
 493-			 */
 494-			clrbline();
 495-			home();
 496-		}
 497-		if (*SR) {
 498-			scrollreverse();
 499-		} else {
 500-			insert_line(0);
 501-		}
 502-	}
 503-	p = skiplines(getline(ln = s->firstline, 1), s->nf);
 504-	for (i = 0; i < n; i++) {
 505-		p = do_line(p, 1);
 506-		s->currentpos--;
 507-		if (!*p) {
 508-			p = getline(++ln, 1);
 509-		}
 510-	}
 511-	return count;
 512+  struct scr_info *s = &scr_info;
 513+  char            *p; /* Holds string to be displayed */
 514+  int              i;
 515+  int              count;
 516+  long             ln; /* a line number */
 517+  int              nodispl;
 518+  int              cannotscroll; /* stupid or no insert-line */
 519+
 520+  /*
 521+   * First, find out where to start
 522+   */
 523+  if ((count = n) <= 0 || (status & START))
 524+    return status;
 525+  if (startcomm)
 526+    reallydispl = 0;
 527+  cannotscroll = stupid || (!*AL && !*SR);
 528+  ln           = s->firstline;
 529+  nodispl      = s->nf;
 530+  while (count) { /* While scrolling back ... */
 531+    i = nodispl;
 532+    if (i) {
 533+      /*
 534+       * There were screen-lines of s->firstline that were not
 535+       * displayed.
 536+       * We can use them now, but only "count" of them.
 537+       */
 538+      if (i > count)
 539+        i = count;
 540+      s->currentpos += i;
 541+      nodispl -= i;
 542+      count -= i;
 543+    } else { /* Get previous line */
 544+      if (ln == 1)
 545+        break; /* isn't there ... */
 546+      p = getline(--ln, 1);
 547+      /*
 548+       * Make it the first line of the screen and compute
 549+       * how many screenlines it takes. These lines are not
 550+       * displayed, but nodispl is set to this count, so
 551+       * that it will be nonzero next time around
 552+       */
 553+      nodispl = 0;
 554+      do { /* Find out how many screenlines */
 555+        nodispl++;
 556+        p = skiplines(p, 1);
 557+      } while (*p);
 558+    }
 559+  }
 560+  n -= count;
 561+  if ((i = s->currentpos) > maxpagesize)
 562+    i = maxpagesize;
 563+  if (reallydispl && hardcopy)
 564+    i = n;
 565+  /*
 566+   * Now that we know where to start, we can use "display" to do the
 567+   * rest of the computing for us, and maybe even the displaying ...
 568+   */
 569+  i = display(ln, nodispl, i, reallydispl && cannotscroll);
 570+  if (cannotscroll || !reallydispl) {
 571+    /*
 572+     * Yes, "display" did the displaying, or we did'nt have to
 573+     * display at all.
 574+     * I like it, but the user obviously does not.
 575+     * Let him buy another (smarter) terminal ...
 576+     */
 577+    return i;
 578+  }
 579+  /*
 580+   * Now, all we have to do is the displaying. And we are dealing with
 581+   * a smart terminal (it can insert lines or scroll back).
 582+   */
 583+  home();
 584+  /*
 585+   * Insert lines all at once
 586+   */
 587+  for (i = n; i; i--) {
 588+    if (DB && *CE) {
 589+      /*
 590+       * Grumble..., terminal retains lines below, so we have
 591+       * to clear the lines that we push off the screen
 592+       */
 593+      clrbline();
 594+      home();
 595+    }
 596+    if (*SR) {
 597+      scrollreverse();
 598+    } else {
 599+      insert_line(0);
 600+    }
 601+  }
 602+  p = skiplines(getline(ln = s->firstline, 1), s->nf);
 603+  for (i = 0; i < n; i++) {
 604+    p = do_line(p, 1);
 605+    s->currentpos--;
 606+    if (!*p) {
 607+      p = getline(++ln, 1);
 608+    }
 609+  }
 610+  return count;
 611 }
 612 
 613 /*
 614@@ -370,323 +361,318 @@ scrollb(int n, int reallydispl)
 615 static char *
 616 do_line(char *str, int reallydispl)
 617 {
 618-	char buf[1024];
 619-	char *p = buf;
 620-	int pos = COLS;
 621-	int do_ul = 0, do_hl = 0;
 622-	int lastmode = 0, lasthlmode = 0;
 623-	int c2;
 624-	int cell_width;
 625-	int tab_width;
 626-	int is_underscore;
 627-	int cell_len;
 628-	int next_len;
 629-	int next_is_underscore;
 630-	unsigned char uc;
 631-	const char *cell_start;
 632-	const char *cursor;
 633-	const char *next;
 634-	enum ansi_kind ansi_kind;
 635-
 636-	while (*str && pos > 0) {
 637-		uc = (unsigned char)*str;
 638-		if (uc == 0x1b && ansi_escape(str, &next, &ansi_kind)) {
 639-			if (ansi_kind == ANSI_SGR) {
 640-				cell_len = next - str;
 641-				if (reallydispl &&
 642-				    p + cell_len >= &buf[sizeof(buf) - 1]) {
 643-					flush_display_buffer(buf, &p);
 644-				}
 645-				if (reallydispl) {
 646-					(void)memcpy(p, str, (size_t)cell_len);
 647-					p += cell_len;
 648-				}
 649-			}
 650-			str = (char *)next;
 651-			continue;
 652-		}
 653-		if (uc < ' ' && (cell_len = match(str, &c2, sppat)) > 0) {
 654-			/*
 655-			 * We found a string that matches, and thus must be
 656-			 * echoed literally
 657-			 */
 658-			if ((pos - c2) <= 0) {
 659-				/*
 660-				 * It did not fit
 661-				 */
 662-				break;
 663-			}
 664-			pos -= c2;
 665-			if (reallydispl) {
 666-				flush_display_buffer(buf, &p);
 667-				cell_start = str;
 668-				str += cell_len;
 669-				uc = (unsigned char)*str;
 670-				*str = '\0';
 671-				putline((char *)cell_start);
 672-				*str = (char)uc;
 673-			} else {
 674-				str += cell_len;
 675-			}
 676-			continue;
 677-		}
 678-
 679-		cell_start = str;
 680-		cell_len = decode_cell(str, &next, &cell_width, &is_underscore);
 681-		cursor = next;
 682-		do_hl = 0;
 683-		if (*cursor == '\b' && *(cursor + 1) != '\0') {
 684-			next_len = decode_cell(cursor + 1, &next, &tab_width,
 685-			                       &next_is_underscore);
 686-			if (!(is_underscore && *(cursor + 1 + next_len) != '\b')) {
 687-				while (*cursor == '\b' && *(cursor + 1) != '\0') {
 688-					cell_start = cursor + 1;
 689-					cell_len = decode_cell(cell_start, &next, &cell_width,
 690-					                       &is_underscore);
 691-					cursor = next;
 692-					do_hl = 1;
 693-				}
 694-			}
 695-		}
 696-		do_ul = 1;
 697-		/*
 698-		 * Find underline sequences ...
 699-		 */
 700-		if (is_underscore && *cursor == '\b' && *(cursor + 1) != '\0') {
 701-			cell_start = cursor + 1;
 702-			cell_len = decode_cell(cell_start, &next, &cell_width,
 703-			                       &is_underscore);
 704-			cursor = next;
 705-		} else {
 706-			if (*cursor == '\b' && *(cursor + 1) == '_') {
 707-				cursor += 2;
 708-			} else {
 709-				do_ul = 0;
 710-			}
 711-		}
 712-		if (cell_width == -1) {
 713-			tab_width = 8 - ((COLS - pos) & 0x07);
 714-			if (pos - tab_width < 0) {
 715-				break;
 716-			}
 717-		} else if (cell_width == -2) {
 718-			if (pos <= 1) {
 719-				break;
 720-			}
 721-		} else if (cell_width > pos) {
 722-			break;
 723-		}
 724-		if (reallydispl && do_hl != lasthlmode) {
 725-			flush_display_buffer(buf, &p);
 726-			if (do_hl) {
 727-				bold();
 728-			} else {
 729-				end_bold();
 730-			}
 731-		}
 732-		lasthlmode = do_hl;
 733-		if (reallydispl && do_ul != lastmode) {
 734-			flush_display_buffer(buf, &p);
 735-			if (do_ul) {
 736-				underline();
 737-			} else {
 738-				end_underline();
 739-			}
 740-		}
 741-		lastmode = do_ul;
 742-		if (cell_width == -1) {
 743-			pos -= tab_width;
 744-			if (reallydispl) {
 745-				if (expandtabs) {
 746-					while (tab_width-- > 0) {
 747-						*p++ = ' ';
 748-					}
 749-				} else {
 750-					flush_display_buffer(buf, &p);
 751-					givetab();
 752-				}
 753-			}
 754-			str = (char *)cursor;
 755-			continue;
 756-		}
 757-		if (reallydispl && p + cell_len >= &buf[sizeof(buf) - 1]) {
 758-			flush_display_buffer(buf, &p);
 759-		}
 760-		if (cell_width == -2) {
 761-			if (reallydispl) {
 762-				if (p + 2 >= &buf[sizeof(buf) - 1]) {
 763-					flush_display_buffer(buf, &p);
 764-				}
 765-				*p++ = '^';
 766-				*p++ = *cell_start ^ 0x40;
 767-			}
 768-			pos -= 2;
 769-			str = (char *)cursor;
 770-			continue;
 771-		}
 772-		if (reallydispl) {
 773-			(void)memcpy(p, cell_start, (size_t)cell_len);
 774-			p += cell_len;
 775-		}
 776-		if (cell_width >= 0) {
 777-			pos -= cell_width;
 778-			if (reallydispl && do_ul && *UC && cell_width == 1 && pos > 0) {
 779-				/*
 780-				 * Underlining apparently is done one
 781-				 * character at a time.
 782-				 */
 783-				flush_display_buffer(buf, &p);
 784-				backspace();
 785-				underchar();
 786-			}
 787-			str = (char *)cursor;
 788-			continue;
 789-		}
 790-		str = (char *)cursor;
 791-	}
 792-	if (reallydispl) {
 793-		flush_display_buffer(buf, &p);
 794-		if (pos > 0 || (pos <= 0 && (!AM || XN))) {
 795-			putline("\r\n");
 796-		}
 797-		/*
 798-		 * The next should be here! I.e. it may not be before printing
 799-		 * the newline. This has to do with XN. We don't know exactly
 800-		 * WHEN the terminal will stop ignoring the newline.
 801-		 * I have for example a terminal (Ampex a230) that will
 802-		 * continue to ignore the newline after a clear to end of line
 803-		 * sequence, but not after an end_underline sequence.
 804-		 */
 805-		if (lastmode) {
 806-			end_underline();
 807-		}
 808-		if (lasthlmode) {
 809-			end_bold();
 810-		}
 811-	}
 812-	scr_info.currentpos++;
 813-	return str;
 814+  char           buf[1024];
 815+  char          *p     = buf;
 816+  int            pos   = COLS;
 817+  int            do_ul = 0, do_hl = 0;
 818+  int            lastmode = 0, lasthlmode = 0;
 819+  int            c2;
 820+  int            cell_width;
 821+  int            tab_width;
 822+  int            is_underscore;
 823+  int            cell_len;
 824+  int            next_len;
 825+  int            next_is_underscore;
 826+  unsigned char  uc;
 827+  const char    *cell_start;
 828+  const char    *cursor;
 829+  const char    *next;
 830+  enum ansi_kind ansi_kind;
 831+
 832+  while (*str && pos > 0) {
 833+    uc = (unsigned char)*str;
 834+    if (uc == 0x1b && ansi_escape(str, &next, &ansi_kind)) {
 835+      if (ansi_kind == ANSI_SGR) {
 836+        cell_len = next - str;
 837+        if (reallydispl && p + cell_len >= &buf[sizeof(buf) - 1]) {
 838+          flush_display_buffer(buf, &p);
 839+        }
 840+        if (reallydispl) {
 841+          (void)memcpy(p, str, (size_t)cell_len);
 842+          p += cell_len;
 843+        }
 844+      }
 845+      str = (char *)next;
 846+      continue;
 847+    }
 848+    if (uc < ' ' && (cell_len = match(str, &c2, sppat)) > 0) {
 849+      /*
 850+       * We found a string that matches, and thus must be
 851+       * echoed literally
 852+       */
 853+      if ((pos - c2) <= 0) {
 854+        /*
 855+         * It did not fit
 856+         */
 857+        break;
 858+      }
 859+      pos -= c2;
 860+      if (reallydispl) {
 861+        flush_display_buffer(buf, &p);
 862+        cell_start = str;
 863+        str += cell_len;
 864+        uc   = (unsigned char)*str;
 865+        *str = '\0';
 866+        putline((char *)cell_start);
 867+        *str = (char)uc;
 868+      } else {
 869+        str += cell_len;
 870+      }
 871+      continue;
 872+    }
 873+
 874+    cell_start = str;
 875+    cell_len   = decode_cell(str, &next, &cell_width, &is_underscore);
 876+    cursor     = next;
 877+    do_hl      = 0;
 878+    if (*cursor == '\b' && *(cursor + 1) != '\0') {
 879+      next_len = decode_cell(cursor + 1, &next, &tab_width, &next_is_underscore);
 880+      if (!(is_underscore && *(cursor + 1 + next_len) != '\b')) {
 881+        while (*cursor == '\b' && *(cursor + 1) != '\0') {
 882+          cell_start = cursor + 1;
 883+          cell_len   = decode_cell(cell_start, &next, &cell_width, &is_underscore);
 884+          cursor     = next;
 885+          do_hl      = 1;
 886+        }
 887+      }
 888+    }
 889+    do_ul = 1;
 890+    /*
 891+     * Find underline sequences ...
 892+     */
 893+    if (is_underscore && *cursor == '\b' && *(cursor + 1) != '\0') {
 894+      cell_start = cursor + 1;
 895+      cell_len   = decode_cell(cell_start, &next, &cell_width, &is_underscore);
 896+      cursor     = next;
 897+    } else {
 898+      if (*cursor == '\b' && *(cursor + 1) == '_') {
 899+        cursor += 2;
 900+      } else {
 901+        do_ul = 0;
 902+      }
 903+    }
 904+    if (cell_width == -1) {
 905+      tab_width = 8 - ((COLS - pos) & 0x07);
 906+      if (pos - tab_width < 0) {
 907+        break;
 908+      }
 909+    } else if (cell_width == -2) {
 910+      if (pos <= 1) {
 911+        break;
 912+      }
 913+    } else if (cell_width > pos) {
 914+      break;
 915+    }
 916+    if (reallydispl && do_hl != lasthlmode) {
 917+      flush_display_buffer(buf, &p);
 918+      if (do_hl) {
 919+        bold();
 920+      } else {
 921+        end_bold();
 922+      }
 923+    }
 924+    lasthlmode = do_hl;
 925+    if (reallydispl && do_ul != lastmode) {
 926+      flush_display_buffer(buf, &p);
 927+      if (do_ul) {
 928+        underline();
 929+      } else {
 930+        end_underline();
 931+      }
 932+    }
 933+    lastmode = do_ul;
 934+    if (cell_width == -1) {
 935+      pos -= tab_width;
 936+      if (reallydispl) {
 937+        if (expandtabs) {
 938+          while (tab_width-- > 0) {
 939+            *p++ = ' ';
 940+          }
 941+        } else {
 942+          flush_display_buffer(buf, &p);
 943+          givetab();
 944+        }
 945+      }
 946+      str = (char *)cursor;
 947+      continue;
 948+    }
 949+    if (reallydispl && p + cell_len >= &buf[sizeof(buf) - 1]) {
 950+      flush_display_buffer(buf, &p);
 951+    }
 952+    if (cell_width == -2) {
 953+      if (reallydispl) {
 954+        if (p + 2 >= &buf[sizeof(buf) - 1]) {
 955+          flush_display_buffer(buf, &p);
 956+        }
 957+        *p++ = '^';
 958+        *p++ = *cell_start ^ 0x40;
 959+      }
 960+      pos -= 2;
 961+      str = (char *)cursor;
 962+      continue;
 963+    }
 964+    if (reallydispl) {
 965+      (void)memcpy(p, cell_start, (size_t)cell_len);
 966+      p += cell_len;
 967+    }
 968+    if (cell_width >= 0) {
 969+      pos -= cell_width;
 970+      if (reallydispl && do_ul && *UC && cell_width == 1 && pos > 0) {
 971+        /*
 972+         * Underlining apparently is done one
 973+         * character at a time.
 974+         */
 975+        flush_display_buffer(buf, &p);
 976+        backspace();
 977+        underchar();
 978+      }
 979+      str = (char *)cursor;
 980+      continue;
 981+    }
 982+    str = (char *)cursor;
 983+  }
 984+  if (reallydispl) {
 985+    flush_display_buffer(buf, &p);
 986+    if (pos > 0 || (pos <= 0 && (!AM || XN))) {
 987+      putline("\r\n");
 988+    }
 989+    /*
 990+     * The next should be here! I.e. it may not be before printing
 991+     * the newline. This has to do with XN. We don't know exactly
 992+     * WHEN the terminal will stop ignoring the newline.
 993+     * I have for example a terminal (Ampex a230) that will
 994+     * continue to ignore the newline after a clear to end of line
 995+     * sequence, but not after an end_underline sequence.
 996+     */
 997+    if (lastmode) {
 998+      end_underline();
 999+    }
1000+    if (lasthlmode) {
1001+      end_bold();
1002+    }
1003+  }
1004+  scr_info.currentpos++;
1005+  return str;
1006 }
1007 
1008 static void
1009 flush_display_buffer(char *buf, char **p)
1010 {
1011-	if (*p == buf) {
1012-		return;
1013-	}
1014-	**p = '\0';
1015-	putline(buf);
1016-	*p = buf;
1017+  if (*p == buf) {
1018+    return;
1019+  }
1020+  **p = '\0';
1021+  putline(buf);
1022+  *p = buf;
1023 }
1024 
1025 static int
1026 rune_width(Rune r)
1027 {
1028-	int width;
1029+  int width;
1030 
1031-	width = wcwidth((wchar_t)r);
1032-	if (width < 0) {
1033-		return 1;
1034-	}
1035-	return width;
1036+  width = wcwidth((wchar_t)r);
1037+  if (width < 0) {
1038+    return 1;
1039+  }
1040+  return width;
1041 }
1042 
1043 static int
1044 decode_cell(const char *s, const char **next, int *width, int *is_underscore)
1045 {
1046-	const char *p;
1047-	Rune r;
1048-	Rune mark;
1049-	int len;
1050-	int mark_len;
1051-	int mark_width;
1052-
1053-	len = chartorune(&r, s);
1054-	if (len <= 0) {
1055-		len = 1;
1056-		r = Runeerror;
1057-	}
1058-	*is_underscore = (len == 1 && *s == '_');
1059-	if (*s == '\t') {
1060-		*width = -1;
1061-		*next = s + 1;
1062-		return 1;
1063-	}
1064-	if ((unsigned char)*s < ' ' || (unsigned char)*s == 0x7f) {
1065-		*width = -2;
1066-		*next = s + 1;
1067-		return 1;
1068-	}
1069-	*width = rune_width(r);
1070-	p = s + len;
1071-	while (*p) {
1072-		if (*p == '\b' || *p == '\t' || (unsigned char)*p < ' ' ||
1073-		    (unsigned char)*p == 0x7f) {
1074-			break;
1075-		}
1076-		mark_len = chartorune(&mark, p);
1077-		if (mark_len <= 0) {
1078-			break;
1079-		}
1080-		mark_width = rune_width(mark);
1081-		if (mark_width != 0) {
1082-			break;
1083-		}
1084-		p += mark_len;
1085-		len += mark_len;
1086-	}
1087-	*next = p;
1088-	return len;
1089+  const char *p;
1090+  Rune        r;
1091+  Rune        mark;
1092+  int         len;
1093+  int         mark_len;
1094+  int         mark_width;
1095+
1096+  len = chartorune(&r, s);
1097+  if (len <= 0) {
1098+    len = 1;
1099+    r   = Runeerror;
1100+  }
1101+  *is_underscore = (len == 1 && *s == '_');
1102+  if (*s == '\t') {
1103+    *width = -1;
1104+    *next  = s + 1;
1105+    return 1;
1106+  }
1107+  if ((unsigned char)*s < ' ' || (unsigned char)*s == 0x7f) {
1108+    *width = -2;
1109+    *next  = s + 1;
1110+    return 1;
1111+  }
1112+  *width = rune_width(r);
1113+  p      = s + len;
1114+  while (*p) {
1115+    if (*p == '\b' || *p == '\t' || (unsigned char)*p < ' ' || (unsigned char)*p == 0x7f) {
1116+      break;
1117+    }
1118+    mark_len = chartorune(&mark, p);
1119+    if (mark_len <= 0) {
1120+      break;
1121+    }
1122+    mark_width = rune_width(mark);
1123+    if (mark_width != 0) {
1124+      break;
1125+    }
1126+    p += mark_len;
1127+    len += mark_len;
1128+  }
1129+  *next = p;
1130+  return len;
1131 }
1132 
1133 /* ARGSUSED */
1134 int
1135 setmark(long cnt)
1136 { /* Set a mark on the current page */
1137-	struct scr_info *p = &scr_info;
1138-	(void)cnt;
1139+  struct scr_info *p = &scr_info;
1140+  (void)cnt;
1141 
1142-	p->savfirst = p->firstline;
1143-	p->savnf = p->nf;
1144-	return 0;
1145+  p->savfirst = p->firstline;
1146+  p->savnf    = p->nf;
1147+  return 0;
1148 }
1149 
1150 /* ARGSUSED */
1151 int
1152 tomark(long cnt)
1153 { /* Go to the mark */
1154-	struct scr_info *p = &scr_info;
1155-	(void)cnt;
1156+  struct scr_info *p = &scr_info;
1157+  (void)cnt;
1158 
1159-	(void)display(p->savfirst, p->savnf, pagesize, 1);
1160-	return 0;
1161+  (void)display(p->savfirst, p->savnf, pagesize, 1);
1162+  return 0;
1163 }
1164 
1165 /* ARGSUSED */
1166 int
1167 exgmark(long cnt)
1168 { /* Exchange mark and current page */
1169-	struct scr_info *p = &scr_info;
1170-	long svfirst;
1171-	int svnf;
1172-	(void)cnt;
1173-
1174-	svfirst = p->firstline;
1175-	svnf = p->nf;
1176-	tomark(0L);
1177-	p->savfirst = svfirst;
1178-	p->savnf = svnf;
1179-	return 0;
1180+  struct scr_info *p = &scr_info;
1181+  long             svfirst;
1182+  int              svnf;
1183+  (void)cnt;
1184+
1185+  svfirst = p->firstline;
1186+  svnf    = p->nf;
1187+  tomark(0L);
1188+  p->savfirst = svfirst;
1189+  p->savnf    = svnf;
1190+  return 0;
1191 }
1192 
1193 void
1194 d_clean()
1195 { /* Clean up */
1196-	struct scr_info *p = &scr_info;
1197+  struct scr_info *p = &scr_info;
1198 
1199-	p->savnf = 0;
1200-	p->savfirst = 0;
1201-	p->head = p->tail;
1202-	p->head->line = 0;
1203-	p->currentpos = 0;
1204+  p->savnf      = 0;
1205+  p->savfirst   = 0;
1206+  p->head       = p->tail;
1207+  p->head->line = 0;
1208+  p->currentpos = 0;
1209 }
+19, -19
 1@@ -8,34 +8,34 @@ extern int maxpagesize;
 2 extern int scrollsize;
 3 
 4 struct scr_info {
 5-	struct linelist {
 6-		int cnt;
 7-		long line;
 8+  struct linelist {
 9+    int  cnt;
10+    long line;
11 #define firstline head->line
12-#define lastline tail->line
13-		struct linelist *next;
14-		struct linelist *prev;
15-	} *tail, *head;
16-	int nf;
17-	int currentpos;
18-	struct linelist ssaavv;
19+#define lastline  tail->line
20+    struct linelist *next;
21+    struct linelist *prev;
22+  }              *tail, *head;
23+  int             nf;
24+  int             currentpos;
25+  struct linelist ssaavv;
26 #define savfirst ssaavv.line
27-#define savnf ssaavv.cnt
28+#define savnf    ssaavv.cnt
29 };
30 
31 extern struct scr_info scr_info;
32-extern int status;
33+extern int             status;
34 
35 #define EOFILE 01
36-#define START 02
37+#define START  02
38 
39 void redraw(int flag);
40-int display(long first_line, int nodispl, int nlines, int really);
41-int scrollf(int nlines, int really);
42-int scrollb(int nlines, int really);
43-int tomark(long cnt);
44-int setmark(long cnt);
45-int exgmark(long cnt);
46+int  display(long first_line, int nodispl, int nlines, int really);
47+int  scrollf(int nlines, int really);
48+int  scrollb(int nlines, int really);
49+int  tomark(long cnt);
50+int  setmark(long cnt);
51+int  exgmark(long cnt);
52 void d_clean(void);
53 
54 #endif
+238, -240
  1@@ -4,22 +4,22 @@
  2  * Command reader, also executes shell escapes
  3  */
  4 
  5-#include <ctype.h>
  6-#include "in_all.h"
  7-#include "term.h"
  8-#include "process.h"
  9 #include "getcomm.h"
 10+#include "assert.h"
 11 #include "commands.h"
 12-#include "prompt.h"
 13-#include "main.h"
 14-#include "output.h"
 15+#include "display.h"
 16 #include "getline.h"
 17-#include "machine.h"
 18+#include "in_all.h"
 19 #include "keys.h"
 20-#include "display.h"
 21-#include "assert.h"
 22+#include "machine.h"
 23+#include "main.h"
 24+#include "output.h"
 25+#include "process.h"
 26+#include "prompt.h"
 27+#include "term.h"
 28+#include <ctype.h>
 29 
 30-static int killchar(int c);
 31+static int  killchar(int c);
 32 static void sigquit(int signo);
 33 
 34 /*
 35@@ -30,69 +30,68 @@ static void sigquit(int signo);
 36 char *
 37 readline(char *s)
 38 {
 39+  static char buf[80];
 40+  char       *p = buf;
 41+  int         ch;
 42+  int         pos;
 43 
 44-	static char buf[80];
 45-	char *p = buf;
 46-	int ch;
 47-	int pos;
 48-
 49-	clrbline();
 50-	putline(s);
 51-	pos = strlen(s);
 52-	while ((ch = getch()) != '\n' && ch != '\r') {
 53-		if (ch == -1) {
 54-			/*
 55-			 * Can only occur because of an interrupted read.
 56-			 */
 57-			ch = erasech;
 58-			interrupt = 0;
 59-		}
 60-		if (ch == erasech) {
 61-			/*
 62-			 * Erase last char
 63-			 */
 64-			if (p == buf) {
 65-				/*
 66-				 * There was none, so return
 67-				 */
 68-				return (char *)0;
 69-			}
 70-			pos -= killchar(*--p);
 71-			if (*p != '\\')
 72-				continue;
 73-		}
 74-		if (ch == killch) {
 75-			/*
 76-			 * Erase the whole line
 77-			 */
 78-			if (!(p > buf && *(p - 1) == '\\')) {
 79-				while (p > buf) {
 80-					pos -= killchar(*--p);
 81-				}
 82-				continue;
 83-			}
 84-			pos -= killchar(*--p);
 85-		}
 86-		if (p > &buf[78] || pos >= COLS - 2) {
 87-			/*
 88-			 * Line does not fit.
 89-			 * Simply refuse to make it any longer
 90-			 */
 91-			pos -= killchar(*--p);
 92-		}
 93-		*p++ = ch;
 94-		if (ch < ' ' || ch >= 0177) {
 95-			fputch('^');
 96-			pos++;
 97-			ch ^= 0100;
 98-		}
 99-		fputch(ch);
100-		pos++;
101-	}
102-	fputch('\r');
103-	*p++ = '\0';
104-	flush();
105-	return buf;
106+  clrbline();
107+  putline(s);
108+  pos = strlen(s);
109+  while ((ch = getch()) != '\n' && ch != '\r') {
110+    if (ch == -1) {
111+      /*
112+       * Can only occur because of an interrupted read.
113+       */
114+      ch        = erasech;
115+      interrupt = 0;
116+    }
117+    if (ch == erasech) {
118+      /*
119+       * Erase last char
120+       */
121+      if (p == buf) {
122+        /*
123+         * There was none, so return
124+         */
125+        return (char *)0;
126+      }
127+      pos -= killchar(*--p);
128+      if (*p != '\\')
129+        continue;
130+    }
131+    if (ch == killch) {
132+      /*
133+       * Erase the whole line
134+       */
135+      if (!(p > buf && *(p - 1) == '\\')) {
136+        while (p > buf) {
137+          pos -= killchar(*--p);
138+        }
139+        continue;
140+      }
141+      pos -= killchar(*--p);
142+    }
143+    if (p > &buf[78] || pos >= COLS - 2) {
144+      /*
145+       * Line does not fit.
146+       * Simply refuse to make it any longer
147+       */
148+      pos -= killchar(*--p);
149+    }
150+    *p++ = ch;
151+    if (ch < ' ' || ch >= 0177) {
152+      fputch('^');
153+      pos++;
154+      ch ^= 0100;
155+    }
156+    fputch(ch);
157+    pos++;
158+  }
159+  fputch('\r');
160+  *p++ = '\0';
161+  flush();
162+  return buf;
163 }
164 
165 /*
166@@ -102,15 +101,14 @@ readline(char *s)
167 static int
168 killchar(int c)
169 {
170-
171-	backspace();
172-	putch(' ');
173-	backspace();
174-	if (c < ' ' || c >= 0177) {
175-		(void)killchar(' ');
176-		return 2;
177-	}
178-	return 1;
179+  backspace();
180+  putch(' ');
181+  backspace();
182+  if (c < ' ' || c >= 0177) {
183+    (void)killchar(' ');
184+    return 2;
185+  }
186+  return 1;
187 }
188 
189 /*
190@@ -120,129 +118,129 @@ killchar(int c)
191 void
192 shellescape(char *p, int esc_char)
193 {
194-	char *p2;      /* walks through command */
195-	int id;        /* procid of child */
196-	int cnt;       /* prevent array bound errors */
197-	int lastc = 0; /* will contain the previous char */
198+  char *p2;        /* walks through command */
199+  int   id;        /* procid of child */
200+  int   cnt;       /* prevent array bound errors */
201+  int   lastc = 0; /* will contain the previous char */
202 #ifdef SIGTSTP
203-	void (*savetstp)(int);
204+  void (*savetstp)(int);
205 #endif
206-	static char previous[256]; /* previous command */
207-	char comm[256];            /* space for command */
208-	int piped[2];
209+  static char previous[256]; /* previous command */
210+  char        comm[256];     /* space for command */
211+  int         piped[2];
212 
213-	p2 = comm;
214-	*p2++ = esc_char;
215-	cnt = 253;
216-	while (*p) {
217-		/*
218-		 * expand command
219-		 */
220-		switch (*p++) {
221-		case '!':
222-			/*
223-			 * An unescaped ! expands to the previous
224-			 * command, but disappears if there is none
225-			 */
226-			if (lastc != '\\') {
227-				if (*previous) {
228-					id = strlen(previous);
229-					if ((cnt -= id) <= 0)
230-						break;
231-					(void)strcpy(p2, previous);
232-					p2 += id;
233-				}
234-			} else {
235-				*(p2 - 1) = '!';
236-			}
237-			continue;
238-		case '%':
239-			/*
240-			 * An unescaped % will expand to the current
241-			 * filename, but disappears is there is none
242-			 */
243-			if (lastc != '\\') {
244-				if (nopipe) {
245-					id = strlen(currentfile);
246-					if ((cnt -= id) <= 0)
247-						break;
248-					(void)strcpy(p2, currentfile);
249-					p2 += id;
250-				}
251-			} else {
252-				*(p2 - 1) = '%';
253-			}
254-			continue;
255-		default:
256-			lastc = *(p - 1);
257-			if (cnt-- <= 0)
258-				break;
259-			*p2++ = lastc;
260-			continue;
261-		}
262-		break;
263-	}
264-	clrbline();
265-	*p2 = '\0';
266-	if (!stupid) {
267-		/*
268-		 * Display expanded command
269-		 */
270-		cputline(comm);
271-		putline("\r\n");
272-	}
273-	flush();
274-	(void)strcpy(previous, comm + 1);
275-	resettty();
276-	if (esc_char == '|' && pipe(piped) < 0) {
277-		error("Cannot create pipe");
278-		return;
279-	}
280-	if ((id = fork()) < 0) {
281-		error("Cannot fork");
282-		return;
283-	}
284-	if (id == 0) {
285-		if (esc_char == '|') {
286-			close(piped[1]);
287-			close(0);
288-			fcntl(piped[0], F_DUPFD, 0);
289-			close(piped[0]);
290-		}
291-		execl("/bin/sh", "sh", "-c", comm + 1, (char *)0);
292-		exit(1);
293-	}
294-	(void)signal(SIGINT, SIG_IGN);
295-	(void)signal(SIGQUIT, SIG_IGN);
296+  p2    = comm;
297+  *p2++ = esc_char;
298+  cnt   = 253;
299+  while (*p) {
300+    /*
301+     * expand command
302+     */
303+    switch (*p++) {
304+      case '!':
305+        /*
306+         * An unescaped ! expands to the previous
307+         * command, but disappears if there is none
308+         */
309+        if (lastc != '\\') {
310+          if (*previous) {
311+            id = strlen(previous);
312+            if ((cnt -= id) <= 0)
313+              break;
314+            (void)strcpy(p2, previous);
315+            p2 += id;
316+          }
317+        } else {
318+          *(p2 - 1) = '!';
319+        }
320+        continue;
321+      case '%':
322+        /*
323+         * An unescaped % will expand to the current
324+         * filename, but disappears is there is none
325+         */
326+        if (lastc != '\\') {
327+          if (nopipe) {
328+            id = strlen(currentfile);
329+            if ((cnt -= id) <= 0)
330+              break;
331+            (void)strcpy(p2, currentfile);
332+            p2 += id;
333+          }
334+        } else {
335+          *(p2 - 1) = '%';
336+        }
337+        continue;
338+      default:
339+        lastc = *(p - 1);
340+        if (cnt-- <= 0)
341+          break;
342+        *p2++ = lastc;
343+        continue;
344+    }
345+    break;
346+  }
347+  clrbline();
348+  *p2 = '\0';
349+  if (!stupid) {
350+    /*
351+     * Display expanded command
352+     */
353+    cputline(comm);
354+    putline("\r\n");
355+  }
356+  flush();
357+  (void)strcpy(previous, comm + 1);
358+  resettty();
359+  if (esc_char == '|' && pipe(piped) < 0) {
360+    error("Cannot create pipe");
361+    return;
362+  }
363+  if ((id = fork()) < 0) {
364+    error("Cannot fork");
365+    return;
366+  }
367+  if (id == 0) {
368+    if (esc_char == '|') {
369+      close(piped[1]);
370+      close(0);
371+      fcntl(piped[0], F_DUPFD, 0);
372+      close(piped[0]);
373+    }
374+    execl("/bin/sh", "sh", "-c", comm + 1, (char *)0);
375+    exit(1);
376+  }
377+  (void)signal(SIGINT, SIG_IGN);
378+  (void)signal(SIGQUIT, SIG_IGN);
379 #ifdef SIGTSTP
380-	if ((savetstp = signal(SIGTSTP, SIG_IGN)) != SIG_IGN) {
381-		(void)signal(SIGTSTP, SIG_DFL);
382-	}
383+  if ((savetstp = signal(SIGTSTP, SIG_IGN)) != SIG_IGN) {
384+    (void)signal(SIGTSTP, SIG_DFL);
385+  }
386 #endif
387-	if (esc_char == '|') {
388-		(void)close(piped[0]);
389-		(void)signal(SIGPIPE, SIG_IGN);
390-		wrt_fd(piped[1]);
391-		(void)close(piped[1]);
392-	}
393-	while ((lastc = wait((int *)0)) != id && lastc >= 0) {
394-		/*
395-		 * Wait for child, making sure it is the one we expected ...
396-		 */
397-	}
398-	(void)signal(SIGINT, catchdel);
399-	(void)signal(SIGQUIT, sigquit);
400+  if (esc_char == '|') {
401+    (void)close(piped[0]);
402+    (void)signal(SIGPIPE, SIG_IGN);
403+    wrt_fd(piped[1]);
404+    (void)close(piped[1]);
405+  }
406+  while ((lastc = wait((int *)0)) != id && lastc >= 0) {
407+    /*
408+     * Wait for child, making sure it is the one we expected ...
409+     */
410+  }
411+  (void)signal(SIGINT, catchdel);
412+  (void)signal(SIGQUIT, sigquit);
413 #ifdef SIGTSTP
414-	(void)signal(SIGTSTP, savetstp);
415+  (void)signal(SIGTSTP, savetstp);
416 #endif
417-	inittty();
418+  inittty();
419 }
420 
421 static void
422 sigquit(int signo)
423 {
424-	(void)signo;
425-	quit();
426+  (void)signo;
427+  quit();
428 }
429 
430 /*
431@@ -252,52 +250,52 @@ sigquit(int signo)
432 int
433 getcomm(long *plong)
434 {
435-	int c;
436-	long count;
437-	char *p;
438-	int i;
439-	int j;
440-	char buf[10];
441+  int   c;
442+  long  count;
443+  char *p;
444+  int   i;
445+  int   j;
446+  char  buf[10];
447 
448-	for (;;) {
449-		count = 0;
450-		give_prompt();
451-		while (isdigit((c = getch()))) {
452-			count = count * 10 + (c - '0');
453-		}
454-		*plong = count;
455-		p = buf;
456-		for (;;) {
457-			if (c == -1) {
458-				/*
459-				 * This should never happen, but it does,
460-				 * when the user gives a TSTP signal (^Z) or
461-				 * an interrupt while the program is trying
462-				 * to read a character from the terminal.
463-				 * In this case, the read is interrupted, so
464-				 * we end up here.
465-				 * Right, we will have to read again.
466-				 */
467-				if (interrupt)
468-					return 1;
469-				break;
470-			}
471-			*p++ = c;
472-			*p = 0;
473-			if ((i = match(buf, &j, currmap->k_mach)) > 0) {
474-				/*
475-				 * The key sequence matched. We have a command
476-				 */
477-				return j;
478-			}
479-			if (i == 0)
480-				return 0;
481-			/*
482-			 * We have a prefix of a command.
483-			 */
484-			assert(i == FSM_ISPREFIX);
485-			c = getch();
486-		}
487-	}
488-	/* NOTREACHED */
489+  for (;;) {
490+    count = 0;
491+    give_prompt();
492+    while (isdigit((c = getch()))) {
493+      count = count * 10 + (c - '0');
494+    }
495+    *plong = count;
496+    p      = buf;
497+    for (;;) {
498+      if (c == -1) {
499+        /*
500+         * This should never happen, but it does,
501+         * when the user gives a TSTP signal (^Z) or
502+         * an interrupt while the program is trying
503+         * to read a character from the terminal.
504+         * In this case, the read is interrupted, so
505+         * we end up here.
506+         * Right, we will have to read again.
507+         */
508+        if (interrupt)
509+          return 1;
510+        break;
511+      }
512+      *p++ = c;
513+      *p   = 0;
514+      if ((i = match(buf, &j, currmap->k_mach)) > 0) {
515+        /*
516+         * The key sequence matched. We have a command
517+         */
518+        return j;
519+      }
520+      if (i == 0)
521+        return 0;
522+      /*
523+       * We have a prefix of a command.
524+       */
525+      assert(i == FSM_ISPREFIX);
526+      c = getch();
527+    }
528+  }
529+  /* NOTREACHED */
530 }
+2, -2
 1@@ -1,8 +1,8 @@
 2 #ifndef GETCOMM_H
 3 #define GETCOMM_H
 4 
 5-int getcomm(long *arg);
 6-void shellescape(char *command, int esc_char);
 7+int   getcomm(long *arg);
 8+void  shellescape(char *command, int esc_char);
 9 char *readline(char *prompt);
10 
11 #endif
+348, -355
  1@@ -1,18 +1,18 @@
  2 /* Copyright (c) 1985 Ceriel J.H. Jacobs */
  3 
  4-#include "in_all.h"
  5 #include "getline.h"
  6-#include "options.h"
  7-#include "process.h"
  8-#include "term.h"
  9-#include "main.h"
 10+#include "assert.h"
 11 #include "display.h"
 12+#include "in_all.h"
 13+#include "main.h"
 14+#include "options.h"
 15 #include "output.h"
 16+#include "process.h"
 17 #include "prompt.h"
 18-#include "assert.h"
 19+#include "term.h"
 20 
 21 #define BLOCKSIZE 2048 /* size of blocks */
 22-#define CHUNK 50       /* # of blockheaders allocated at a time */
 23+#define CHUNK     50   /* # of blockheaders allocated at a time */
 24 
 25 /*
 26  * Blocks are kept in an array in line-number order. Each block stores the raw
 27@@ -20,63 +20,62 @@
 28  */
 29 
 30 struct block {
 31-	int b_flags;  /* Contains the following flags: */
 32-#define PARTLY 02     /* block not filled completely (eof) */
 33-	long b_end;   /* line number of last line in block */
 34-	char *b_info; /* the block */
 35-	int *b_offs;  /* line offsets within the block */
 36+  int b_flags;    /* Contains the following flags: */
 37+#define PARTLY 02 /* block not filled completely (eof) */
 38+  long  b_end;    /* line number of last line in block */
 39+  char *b_info;   /* the block */
 40+  int  *b_offs;   /* line offsets within the block */
 41 };
 42 
 43 static struct block *blocklist, /* beginning of the list of blocks */
 44     *maxblocklist,              /* first free entry in the list */
 45     *topblocklist;              /* end of allocated core for the list */
 46-static long lastreadline; /* lineno of last line read */
 47-static int ENDseen;
 48+static long lastreadline;       /* lineno of last line read */
 49+static int  ENDseen;
 50 
 51-static void nextblock(struct block *pblock);
 52-static char *re_alloc(char *ptr, unsigned newsize);
 53+static void          nextblock(struct block *pblock);
 54+static char         *re_alloc(char *ptr, unsigned newsize);
 55 static struct block *getblock(long n, int disable_interrupt);
 56 
 57 static struct block *
 58 new_block()
 59 {
 60-	struct block *pblock = maxblocklist - 1;
 61-
 62-	if (!maxblocklist || !(pblock->b_flags & PARTLY)) {
 63-		/*
 64-		 * There is no last block, or it was filled completely,
 65-		 * so allocate a new blockheader.
 66-		 */
 67-		int siz;
 68-
 69-		pblock = blocklist;
 70-		if (maxblocklist == topblocklist) {
 71-			/*
 72-			 * No blockheaders left. Allocate new ones
 73-			 */
 74-			siz = topblocklist - pblock;
 75-			blocklist = pblock = (struct block *)
 76-			    re_alloc((char *)pblock,
 77-			             (unsigned)((siz + CHUNK) * sizeof(*pblock)));
 78-			pblock += siz;
 79-			topblocklist = pblock + CHUNK;
 80-			maxblocklist = pblock;
 81-			for (; pblock < topblocklist; pblock++) {
 82-				pblock->b_end = 0;
 83-				pblock->b_info = 0;
 84-				pblock->b_flags = 0;
 85-			}
 86-			if (!siz) {
 87-				/*
 88-				 * Create dummy header cell.
 89-				 */
 90-				maxblocklist++;
 91-			}
 92-		}
 93-		pblock = maxblocklist++;
 94-	}
 95-	nextblock(pblock);
 96-	return pblock;
 97+  struct block *pblock = maxblocklist - 1;
 98+
 99+  if (!maxblocklist || !(pblock->b_flags & PARTLY)) {
100+    /*
101+     * There is no last block, or it was filled completely,
102+     * so allocate a new blockheader.
103+     */
104+    int siz;
105+
106+    pblock = blocklist;
107+    if (maxblocklist == topblocklist) {
108+      /*
109+       * No blockheaders left. Allocate new ones
110+       */
111+      siz       = topblocklist - pblock;
112+      blocklist = pblock =
113+          (struct block *)re_alloc((char *)pblock, (unsigned)((siz + CHUNK) * sizeof(*pblock)));
114+      pblock += siz;
115+      topblocklist = pblock + CHUNK;
116+      maxblocklist = pblock;
117+      for (; pblock < topblocklist; pblock++) {
118+        pblock->b_end   = 0;
119+        pblock->b_info  = 0;
120+        pblock->b_flags = 0;
121+      }
122+      if (!siz) {
123+        /*
124+         * Create dummy header cell.
125+         */
126+        maxblocklist++;
127+      }
128+    }
129+    pblock = maxblocklist++;
130+  }
131+  nextblock(pblock);
132+  return pblock;
133 }
134 
135 /*
136@@ -88,66 +87,65 @@ new_block()
137 static struct block *
138 getblock(long n, int disable_interrupt)
139 {
140-	struct block *pblock;
141-
142-	if (stdf < 0) {
143-		/*
144-		 * Not file descriptor, so return end of file
145-		 */
146-		return 0;
147-	}
148-	pblock = maxblocklist - 1;
149-	if (n < lastreadline ||
150-	    (n == lastreadline && !(pblock->b_flags & PARTLY))) {
151-		/*
152-		 * The line asked for has been read already.
153-		 * Perform binary search in the blocklist to find the block
154-		 * where it's in.
155-		 */
156-		struct block *min, *mid;
157-
158-		min = blocklist + 1;
159-		do {
160-			mid = min + (pblock - min) / 2;
161-			if (n > mid->b_end) {
162-				min = mid + 1;
163-			} else
164-				pblock = mid;
165-		} while (min < pblock);
166-		/* Found, pblock is now a reference to the block wanted */
167-		return pblock;
168-	}
169-
170-	/*
171-	 * The line was'nt read yet, so read blocks until found
172-	 */
173-	for (;;) {
174-		if (interrupt && !disable_interrupt)
175-			return 0;
176-		pblock = new_block();
177-		if (pblock->b_end >= n) {
178-			return pblock;
179-		}
180-		if (pblock->b_flags & PARTLY) {
181-			/*
182-			 * We did not find it, and the last block could not be
183-			 * read completely, so return 0;
184-			 */
185-			return 0;
186-		}
187-	}
188-	/* NOTREACHED */
189+  struct block *pblock;
190+
191+  if (stdf < 0) {
192+    /*
193+     * Not file descriptor, so return end of file
194+     */
195+    return 0;
196+  }
197+  pblock = maxblocklist - 1;
198+  if (n < lastreadline || (n == lastreadline && !(pblock->b_flags & PARTLY))) {
199+    /*
200+     * The line asked for has been read already.
201+     * Perform binary search in the blocklist to find the block
202+     * where it's in.
203+     */
204+    struct block *min, *mid;
205+
206+    min = blocklist + 1;
207+    do {
208+      mid = min + (pblock - min) / 2;
209+      if (n > mid->b_end) {
210+        min = mid + 1;
211+      } else
212+        pblock = mid;
213+    } while (min < pblock);
214+    /* Found, pblock is now a reference to the block wanted */
215+    return pblock;
216+  }
217+
218+  /*
219+   * The line was'nt read yet, so read blocks until found
220+   */
221+  for (;;) {
222+    if (interrupt && !disable_interrupt)
223+      return 0;
224+    pblock = new_block();
225+    if (pblock->b_end >= n) {
226+      return pblock;
227+    }
228+    if (pblock->b_flags & PARTLY) {
229+      /*
230+       * We did not find it, and the last block could not be
231+       * read completely, so return 0;
232+       */
233+      return 0;
234+    }
235+  }
236+  /* NOTREACHED */
237 }
238 
239 char *
240 getline(long n, int disable_interrupt)
241 {
242-	struct block *pblock;
243+  struct block *pblock;
244 
245-	if (!(pblock = getblock(n, disable_interrupt))) {
246-		return (char *)0;
247-	}
248-	return pblock->b_info + pblock->b_offs[n - ((pblock - 1)->b_end + 1)];
249+  if (!(pblock = getblock(n, disable_interrupt))) {
250+    return (char *)0;
251+  }
252+  return pblock->b_info + pblock->b_offs[n - ((pblock - 1)->b_end + 1)];
253 }
254 
255 /*
256@@ -157,32 +155,31 @@ getline(long n, int disable_interrupt)
257 long
258 to_lastline()
259 {
260-
261-	for (;;) {
262-		if (!getline(lastreadline + 1, 0)) {
263-			/*
264-			 * "lastreadline" always contains the linenumber of
265-			 * the last line read. So, if the call to getline
266-			 * succeeds, "lastreadline" is affected
267-			 */
268-			if (interrupt)
269-				return -1L;
270-			return lastreadline;
271-		}
272-	}
273-	/* NOTREACHED */
274+  for (;;) {
275+    if (!getline(lastreadline + 1, 0)) {
276+      /*
277+       * "lastreadline" always contains the linenumber of
278+       * the last line read. So, if the call to getline
279+       * succeeds, "lastreadline" is affected
280+       */
281+      if (interrupt)
282+        return -1L;
283+      return lastreadline;
284+    }
285+  }
286+  /* NOTREACHED */
287 }
288 
289 char *
290 alloc(unsigned size)
291 {
292-	char *pmem;
293+  char *pmem;
294 
295-	pmem = malloc(size);
296-	if (!pmem && size != 0) {
297-		panic("No core");
298-	}
299-	return pmem;
300+  pmem = malloc(size);
301+  if (!pmem && size != 0) {
302+    panic("No core");
303+  }
304+  return pmem;
305 }
306 
307 /*
308@@ -193,17 +190,17 @@ alloc(unsigned size)
309 static char *
310 re_alloc(char *ptr, unsigned newsize)
311 {
312-	char *pmem;
313+  char *pmem;
314 
315-	pmem = realloc(ptr, newsize);
316-	if (!pmem && newsize != 0) {
317-		panic("No core");
318-	}
319-	return pmem;
320+  pmem = realloc(ptr, newsize);
321+  if (!pmem && newsize != 0) {
322+    panic("No core");
323+  }
324+  return pmem;
325 }
326 
327 static char *saved;
328-static long filldegree;
329+static long  filldegree;
330 
331 /*
332  * Try to read the block indicated by pblock
333@@ -212,143 +209,141 @@ static long filldegree;
334 static void
335 nextblock(struct block *pblock)
336 {
337-	char *c,         /* Run through pblock->b_info */
338-	    *c1;                  /* indicate end of pblock->b_info */
339-	int *poff;       /* pointer in line-offset list */
340-	int cnt;         /* # of characters read */
341-	unsigned siz;    /* Size of allocated line-offset list */
342-	static unsigned savedsiz; /* saved "siz" */
343-	static int *savedpoff;    /* saved "poff" */
344-	static char *savedc1;     /* saved "c1" */
345-
346-	if (pblock->b_flags & PARTLY) {
347-		/*
348-		 * The block was already partly filled. Initialize locals
349-		 * accordingly
350-		 */
351-		poff = savedpoff;
352-		siz = savedsiz;
353-		pblock->b_flags = 0;
354-		c1 = savedc1;
355-		if (c1 == pblock->b_info || *(c1 - 1)) {
356-			/*
357-			 * We had incremented "lastreadline" temporarily,
358-			 * because the last line could not be completely read
359-			 * last time we tried. Undo this increment
360-			 */
361-			poff--;
362-			--lastreadline;
363-		}
364-	} else {
365-		if (saved) {
366-			/*
367-			 * There were leftovers from the previous block
368-			 */
369-			pblock->b_info = saved;
370-			c1 = savedc1;
371-			saved = 0;
372-		} else { /* Allocate new block */
373-			pblock->b_info = c1 = alloc(BLOCKSIZE + 1);
374-		}
375-		/*
376-		 * Allocate some space for line-offsets
377-		 */
378-		pblock->b_offs = poff = (int *)
379-		    alloc((unsigned)(100 * sizeof(int)));
380-		siz = 99;
381-		*poff++ = 0;
382-	}
383-	c = c1;
384-	for (;;) {
385-		/*
386-		 * Read loop
387-		 */
388-		cnt = read(stdf, c1, BLOCKSIZE - (c1 - pblock->b_info));
389-		if (cnt < 0) {
390-			/*
391-			 * Interrupted read
392-			 */
393-			if (errno == EINTR)
394-				continue;
395-			error("Could not read input file");
396-			cnt = 0;
397-		}
398-		c1 += cnt;
399-		if (c1 != pblock->b_info + BLOCKSIZE) {
400-			ENDseen = 1;
401-			pblock->b_flags |= PARTLY;
402-		}
403-		break;
404-	}
405-	assert(c <= c1);
406-	while (c < c1) {
407-		/*
408-		 * Now process the block
409-		 */
410-		if (*c == '\n') {
411-			/*
412-			 * Newlines are replaced by '\0', so that "getline"
413-			 * can deliver one line at a time
414-			 */
415-			*c = 0;
416-			lastreadline++;
417-			/*
418-			 * Remember the line-offset
419-			 */
420-			if (poff == pblock->b_offs + siz) {
421-				/*
422-				 * No space for it, allocate some more
423-				 */
424-				pblock->b_offs = (int *)
425-				    re_alloc((char *)pblock->b_offs,
426-				             (unsigned)((siz + 51) * sizeof(int)));
427-				poff = pblock->b_offs + siz;
428-				siz += 50;
429-			}
430-			*poff++ = c - pblock->b_info + 1;
431-		}
432-		c++;
433-	}
434-	assert(c == c1);
435-	*c = 0;
436-	if (c != pblock->b_info && *(c - 1) != 0) {
437-		/*
438-		 * The last line read does not end with a newline, so add one
439-		 */
440-		lastreadline++;
441-		*poff++ = c - pblock->b_info + 1;
442-		if (!(pblock->b_flags & PARTLY) && *(poff - 2) != 0) {
443-			/*
444-			 * Save the started line; it will be in the next block.
445-			 * Remove the newline we added just now.
446-			 */
447-			saved = c1 = alloc(BLOCKSIZE + 1);
448-			c = pblock->b_info + *(--poff - 1);
449-			while (*c)
450-				*c1++ = *c++;
451-			c = pblock->b_info + *(poff - 1);
452-			savedc1 = c1;
453-			--lastreadline;
454-		}
455-	}
456-	pblock->b_end = lastreadline;
457-	if (pblock->b_flags & PARTLY) {
458-		/*
459-		 * Take care, that we can call "nextblock" again, to fill in
460-		 * the rest of this block
461-		 */
462-		savedsiz = siz;
463-		savedpoff = poff;
464-		savedc1 = c;
465-		if (c == pblock->b_info) {
466-			lastreadline++;
467-			pblock->b_end = 0;
468-		}
469-	} else {
470-		cnt = pblock - blocklist;
471-		filldegree = ((c - pblock->b_info) + (cnt - 1) * filldegree) / cnt;
472-	}
473-	assert(pblock->b_end - (pblock - 1)->b_end <= poff - pblock->b_offs);
474+  char *c,                   /* Run through pblock->b_info */
475+      *c1;                   /* indicate end of pblock->b_info */
476+  int            *poff;      /* pointer in line-offset list */
477+  int             cnt;       /* # of characters read */
478+  unsigned        siz;       /* Size of allocated line-offset list */
479+  static unsigned savedsiz;  /* saved "siz" */
480+  static int     *savedpoff; /* saved "poff" */
481+  static char    *savedc1;   /* saved "c1" */
482+
483+  if (pblock->b_flags & PARTLY) {
484+    /*
485+     * The block was already partly filled. Initialize locals
486+     * accordingly
487+     */
488+    poff            = savedpoff;
489+    siz             = savedsiz;
490+    pblock->b_flags = 0;
491+    c1              = savedc1;
492+    if (c1 == pblock->b_info || *(c1 - 1)) {
493+      /*
494+       * We had incremented "lastreadline" temporarily,
495+       * because the last line could not be completely read
496+       * last time we tried. Undo this increment
497+       */
498+      poff--;
499+      --lastreadline;
500+    }
501+  } else {
502+    if (saved) {
503+      /*
504+       * There were leftovers from the previous block
505+       */
506+      pblock->b_info = saved;
507+      c1             = savedc1;
508+      saved          = 0;
509+    } else { /* Allocate new block */
510+      pblock->b_info = c1 = alloc(BLOCKSIZE + 1);
511+    }
512+    /*
513+     * Allocate some space for line-offsets
514+     */
515+    pblock->b_offs = poff = (int *)alloc((unsigned)(100 * sizeof(int)));
516+    siz                   = 99;
517+    *poff++               = 0;
518+  }
519+  c = c1;
520+  for (;;) {
521+    /*
522+     * Read loop
523+     */
524+    cnt = read(stdf, c1, BLOCKSIZE - (c1 - pblock->b_info));
525+    if (cnt < 0) {
526+      /*
527+       * Interrupted read
528+       */
529+      if (errno == EINTR)
530+        continue;
531+      error("Could not read input file");
532+      cnt = 0;
533+    }
534+    c1 += cnt;
535+    if (c1 != pblock->b_info + BLOCKSIZE) {
536+      ENDseen = 1;
537+      pblock->b_flags |= PARTLY;
538+    }
539+    break;
540+  }
541+  assert(c <= c1);
542+  while (c < c1) {
543+    /*
544+     * Now process the block
545+     */
546+    if (*c == '\n') {
547+      /*
548+       * Newlines are replaced by '\0', so that "getline"
549+       * can deliver one line at a time
550+       */
551+      *c = 0;
552+      lastreadline++;
553+      /*
554+       * Remember the line-offset
555+       */
556+      if (poff == pblock->b_offs + siz) {
557+        /*
558+         * No space for it, allocate some more
559+         */
560+        pblock->b_offs =
561+            (int *)re_alloc((char *)pblock->b_offs, (unsigned)((siz + 51) * sizeof(int)));
562+        poff = pblock->b_offs + siz;
563+        siz += 50;
564+      }
565+      *poff++ = c - pblock->b_info + 1;
566+    }
567+    c++;
568+  }
569+  assert(c == c1);
570+  *c = 0;
571+  if (c != pblock->b_info && *(c - 1) != 0) {
572+    /*
573+     * The last line read does not end with a newline, so add one
574+     */
575+    lastreadline++;
576+    *poff++ = c - pblock->b_info + 1;
577+    if (!(pblock->b_flags & PARTLY) && *(poff - 2) != 0) {
578+      /*
579+       * Save the started line; it will be in the next block.
580+       * Remove the newline we added just now.
581+       */
582+      saved = c1 = alloc(BLOCKSIZE + 1);
583+      c          = pblock->b_info + *(--poff - 1);
584+      while (*c)
585+        *c1++ = *c++;
586+      c       = pblock->b_info + *(poff - 1);
587+      savedc1 = c1;
588+      --lastreadline;
589+    }
590+  }
591+  pblock->b_end = lastreadline;
592+  if (pblock->b_flags & PARTLY) {
593+    /*
594+     * Take care, that we can call "nextblock" again, to fill in
595+     * the rest of this block
596+     */
597+    savedsiz  = siz;
598+    savedpoff = poff;
599+    savedc1   = c;
600+    if (c == pblock->b_info) {
601+      lastreadline++;
602+      pblock->b_end = 0;
603+    }
604+  } else {
605+    cnt        = pblock - blocklist;
606+    filldegree = ((c - pblock->b_info) + (cnt - 1) * filldegree) / cnt;
607+  }
608+  assert(pblock->b_end - (pblock - 1)->b_end <= poff - pblock->b_offs);
609 }
610 
611 /*
612@@ -359,28 +354,27 @@ nextblock(struct block *pblock)
613 void
614 do_clean()
615 {
616-
617-	struct block *pblock;
618-	char *p;
619-
620-	for (pblock = blocklist; pblock < maxblocklist; pblock++) {
621-		if ((p = pblock->b_info) != 0) {
622-			free(p);
623-			free((char *)pblock->b_offs);
624-		}
625-	}
626-	if ((p = (char *)blocklist) != 0) {
627-		free(p);
628-	}
629-	blocklist = 0;
630-	maxblocklist = 0;
631-	topblocklist = 0;
632-	lastreadline = 0;
633-	filldegree = 0;
634-	ENDseen = 0;
635-	if ((p = saved) != 0)
636-		free(p);
637-	saved = 0;
638+  struct block *pblock;
639+  char         *p;
640+
641+  for (pblock = blocklist; pblock < maxblocklist; pblock++) {
642+    if ((p = pblock->b_info) != 0) {
643+      free(p);
644+      free((char *)pblock->b_offs);
645+    }
646+  }
647+  if ((p = (char *)blocklist) != 0) {
648+    free(p);
649+  }
650+  blocklist    = 0;
651+  maxblocklist = 0;
652+  topblocklist = 0;
653+  lastreadline = 0;
654+  filldegree   = 0;
655+  ENDseen      = 0;
656+  if ((p = saved) != 0)
657+    free(p);
658+  saved = 0;
659 }
660 
661 /*
662@@ -390,28 +384,28 @@ do_clean()
663 int
664 getch()
665 {
666-	int flags, bytes_ready, bytes_read;
667-	struct stat buf;
668-	char c;
669-
670-	flush();
671-	if (startcomm) {
672-		/*
673-		 * Command line option command
674-		 */
675-		if (*startcomm)
676-			return *startcomm++;
677-		return '\n';
678-	}
679-	if (stdf >= 0) {
680-		/*
681-		 * Make reads from the terminal non-blocking, so that
682-		 * we can see if the user typed something
683-		 */
684-		flags = fcntl(0, F_GETFL, 0);
685-		if (flags != -1 && fcntl(0, F_SETFL, flags | O_NONBLOCK) != -1) {
686-			bytes_read = 0;
687-			while (!ENDseen &&
688+  int         flags, bytes_ready, bytes_read;
689+  struct stat buf;
690+  char        c;
691+
692+  flush();
693+  if (startcomm) {
694+    /*
695+     * Command line option command
696+     */
697+    if (*startcomm)
698+      return *startcomm++;
699+    return '\n';
700+  }
701+  if (stdf >= 0) {
702+    /*
703+     * Make reads from the terminal non-blocking, so that
704+     * we can see if the user typed something
705+     */
706+    flags = fcntl(0, F_GETFL, 0);
707+    if (flags != -1 && fcntl(0, F_SETFL, flags | O_NONBLOCK) != -1) {
708+      bytes_read = 0;
709+      while (!ENDseen &&
710 			       ((bytes_read = read(0, &c, 1)) == 0
711 #ifdef EWOULDBLOCK
712 			        || (bytes_read < 0 && errno == EWOULDBLOCK)
713@@ -422,40 +416,39 @@ getch()
714 			            ) &&
715 			       (nopipe ||
716 			        (fstat(stdf, &buf) >= 0 && buf.st_size > 0))) {
717-				/*
718-				 * Do some read ahead, after making sure there
719-				 * is input and the user did not type a command
720-				 */
721-				new_block();
722-			}
723-			(void)fcntl(0, F_SETFL, flags);
724-			if (bytes_read < 0) {
725-				/*
726-				 * Could this have happened?
727-				 * I'm not sure, because the read is
728-				 * nonblocking. Can it be interrupted then?
729-				 */
730-				return -1;
731-			}
732-			if (bytes_read > 0)
733-				return c & 0x7f;
734-		}
735-	}
736-	if (ioctl(0, FIONREAD, (char *)&bytes_ready) >= 0 && stdf >= 0) {
737-		while (!ENDseen &&
738-		       bytes_ready == 0 &&
739-		       (nopipe || (fstat(stdf, &buf) >= 0 && buf.st_size > 0))) {
740-			if (interrupt)
741-				return -1;
742-			new_block();
743-			if (ioctl(0, FIONREAD, (char *)&bytes_ready) < 0) {
744-				break;
745-			}
746-		}
747-	}
748-	if (read(0, &c, 1) <= 0)
749-		return -1;
750-	return c & 0x7f;
751+        /*
752+         * Do some read ahead, after making sure there
753+         * is input and the user did not type a command
754+         */
755+        new_block();
756+      }
757+      (void)fcntl(0, F_SETFL, flags);
758+      if (bytes_read < 0) {
759+        /*
760+         * Could this have happened?
761+         * I'm not sure, because the read is
762+         * nonblocking. Can it be interrupted then?
763+         */
764+        return -1;
765+      }
766+      if (bytes_read > 0)
767+        return c & 0x7f;
768+    }
769+  }
770+  if (ioctl(0, FIONREAD, (char *)&bytes_ready) >= 0 && stdf >= 0) {
771+    while (!ENDseen && bytes_ready == 0
772+           && (nopipe || (fstat(stdf, &buf) >= 0 && buf.st_size > 0))) {
773+      if (interrupt)
774+        return -1;
775+      new_block();
776+      if (ioctl(0, FIONREAD, (char *)&bytes_ready) < 0) {
777+        break;
778+      }
779+    }
780+  }
781+  if (read(0, &c, 1) <= 0)
782+    return -1;
783+  return c & 0x7f;
784 }
785 
786 /*
787@@ -465,11 +458,11 @@ getch()
788 long
789 getpos(long ln)
790 {
791-	struct block *pblock;
792-	long i;
793+  struct block *pblock;
794+  long          i;
795 
796-	pblock = getblock(ln, 1);
797-	assert(pblock != 0);
798-	i = filldegree * (pblock - blocklist);
799-	return i - (filldegree - pblock->b_offs[ln - (pblock - 1)->b_end]);
800+  pblock = getblock(ln, 1);
801+  assert(pblock != 0);
802+  i = filldegree * (pblock - blocklist);
803+  return i - (filldegree - pblock->b_offs[ln - (pblock - 1)->b_end]);
804 }
+4, -4
 1@@ -3,9 +3,9 @@
 2 
 3 char *getline(long ln, int disable_interrupt);
 4 char *alloc(unsigned size);
 5-void do_clean(void);
 6-int getch(void);
 7-long to_lastline(void);
 8-long getpos(long line);
 9+void  do_clean(void);
10+int   getch(void);
11+long  to_lastline(void);
12+long  getpos(long line);
13 
14 #endif
+70, -70
  1@@ -1,18 +1,18 @@
  2 /* Copyright (c) 1985 Ceriel J.H. Jacobs */
  3 
  4-#include "in_all.h"
  5 #include "help.h"
  6-#include "machine.h"
  7 #include "commands.h"
  8+#include "display.h"
  9+#include "in_all.h"
 10 #include "keys.h"
 11+#include "machine.h"
 12+#include "main.h"
 13+#include "options.h"
 14 #include "output.h"
 15 #include "prompt.h"
 16-#include "main.h"
 17-#include "display.h"
 18 #include "term.h"
 19-#include "options.h"
 20 
 21-static int h_cnt;            /* Count # of lines */
 22+static int           h_cnt;  /* Count # of lines */
 23 static struct state *origin; /* Keep track of startstate */
 24 
 25 /*
 26@@ -25,32 +25,32 @@ static struct state *origin; /* Keep track of startstate */
 27 static void
 28 pr_comm()
 29 {
 30-	struct state *p = origin;
 31-	char *pb;
 32-	int c;
 33-	char buf[30];
 34-	int i = 0; /* How many characters printed? */
 35+  struct state *p = origin;
 36+  char         *pb;
 37+  int           c;
 38+  char          buf[30];
 39+  int           i = 0; /* How many characters printed? */
 40 
 41-	pb = buf;
 42-	for (;;) {
 43-		c = p->s_char & 0177;
 44-		if (c < ' ' || c == 0177) {
 45-			/*
 46-			 * Will take an extra position
 47-			 */
 48-			i++;
 49-		}
 50-		*pb++ = c;
 51-		i++;
 52-		if (!p->s_match)
 53-			break;
 54-		p = p->s_next;
 55-	}
 56-	do {
 57-		*pb++ = ' ';
 58-	} while (++i < 12);
 59-	*pb = 0;
 60-	cputline(buf);
 61+  pb = buf;
 62+  for (;;) {
 63+    c = p->s_char & 0177;
 64+    if (c < ' ' || c == 0177) {
 65+      /*
 66+       * Will take an extra position
 67+       */
 68+      i++;
 69+    }
 70+    *pb++ = c;
 71+    i++;
 72+    if (!p->s_match)
 73+      break;
 74+    p = p->s_next;
 75+  }
 76+  do {
 77+    *pb++ = ' ';
 78+  } while (++i < 12);
 79+  *pb = 0;
 80+  cputline(buf);
 81 }
 82 
 83 /*
 84@@ -62,51 +62,51 @@ pr_comm()
 85 static void
 86 pr_mach(struct state *currstate, struct state *back)
 87 {
 88-	struct state *save;
 89+  struct state *save;
 90 
 91-	while (currstate) {
 92-		if (interrupt)
 93-			break;
 94-		if (back) {
 95-			save = back->s_next; /* Save original link */
 96-			back->s_next = currstate;
 97-		}
 98-		if (!currstate->s_match) {
 99-			/*
100-			 * End state, print command
101-			 */
102-			pr_comm();
103-			putline(commands[currstate->s_cnt].c_descr);
104-			putline("\r\n");
105-			if (++h_cnt >= maxpagesize) {
106-				ret_to_continue();
107-				h_cnt = 0;
108-			}
109-		} else
110-			pr_mach(currstate->s_match, currstate);
111-		currstate = currstate->s_next;
112-		if (back)
113-			back->s_next = save; /* restore */
114-		else
115-			origin = currstate;
116-	}
117+  while (currstate) {
118+    if (interrupt)
119+      break;
120+    if (back) {
121+      save         = back->s_next; /* Save original link */
122+      back->s_next = currstate;
123+    }
124+    if (!currstate->s_match) {
125+      /*
126+       * End state, print command
127+       */
128+      pr_comm();
129+      putline(commands[currstate->s_cnt].c_descr);
130+      putline("\r\n");
131+      if (++h_cnt >= maxpagesize) {
132+        ret_to_continue();
133+        h_cnt = 0;
134+      }
135+    } else
136+      pr_mach(currstate->s_match, currstate);
137+    currstate = currstate->s_next;
138+    if (back)
139+      back->s_next = save; /* restore */
140+    else
141+      origin = currstate;
142+  }
143 }
144 
145 /*ARGSUSED*/
146 int
147 do_help(long i)
148 { /* The help command */
149-	(void)i;
150+  (void)i;
151 
152-	startcomm = 0;
153-	h_cnt = 2;
154-	putline("\r\nSummary of yap commands:\r\n");
155-	origin = currmap->k_mach;
156-	pr_mach(currmap->k_mach, (struct state *)0);
157-	if (h_cnt) {
158-		ret_to_continue();
159-	}
160-	if (!hardcopy && scr_info.currentpos)
161-		redraw(1);
162-	return 0;
163+  startcomm = 0;
164+  h_cnt     = 2;
165+  putline("\r\nSummary of yap commands:\r\n");
166+  origin = currmap->k_mach;
167+  pr_mach(currmap->k_mach, (struct state *)0);
168+  if (h_cnt) {
169+    ret_to_continue();
170+  }
171+  if (!hardcopy && scr_info.currentpos)
172+    redraw(1);
173+  return 0;
174 }
+116, -118
  1@@ -1,12 +1,12 @@
  2 /* Copyright (c) 1985 Ceriel J.H. Jacobs */
  3 
  4-#include <ctype.h>
  5-#include "in_all.h"
  6-#include "machine.h"
  7 #include "keys.h"
  8+#include "assert.h"
  9 #include "commands.h"
 10+#include "in_all.h"
 11+#include "machine.h"
 12 #include "prompt.h"
 13-#include "assert.h"
 14+#include <ctype.h>
 15 
 16 struct keymap *currmap, *othermap;
 17 
 18@@ -23,11 +23,11 @@ wrf=w:qui=q:qui=Q:mar=m:pip=|";
 19 static char *
 20 kerror(char *key, char *emess)
 21 {
 22-	static char ebuf[80]; /* Room for the error message */
 23+  static char ebuf[80]; /* Room for the error message */
 24 
 25-	(void)strcpy(ebuf, key);
 26-	(void)strcat(ebuf, emess);
 27-	return ebuf;
 28+  (void)strcpy(ebuf, key);
 29+  (void)strcat(ebuf, emess);
 30+  return ebuf;
 31 }
 32 
 33 /*
 34@@ -38,87 +38,87 @@ kerror(char *key, char *emess)
 35 static char *
 36 compile(char *map, struct keymap *commtable)
 37 {
 38-	char *mark; /* Indicates start of mnemonic */
 39-	char *c;    /* Runs through buf */
 40-	int temp;
 41-	char *escapes = commtable->k_esc;
 42-	char buf[10]; /* Will hold key sequence */
 43-
 44-	(void)strcpy(commtable->k_help, "Illegal command");
 45-	while (*map) {
 46-		c = buf;
 47-		mark = map; /* Start of mnemonic */
 48-		while (*map && *map != '=') {
 49-			map++;
 50-		}
 51-		if (!*map) {
 52-			/*
 53-			 * Mnemonic should end with '='
 54-			 */
 55-			return kerror(mark, ": Syntax error");
 56-		}
 57-		*map++ = 0;
 58-		while (*map) {
 59-			/*
 60-			 * Get key sequence
 61-			 */
 62-			if (*map == ':') {
 63-				/*
 64-				 * end of key sequence
 65-				 */
 66-				map++;
 67-				break;
 68-			}
 69-			*c = *map++ & 0x7f;
 70-			if (*c == '^' || *c == '\\') {
 71-				if (!(temp = *map++)) {
 72-					/*
 73-					 * Escape not followed by a character
 74-					 */
 75-					return kerror(mark, ": Syntax error");
 76-				}
 77-				if (*c == '^') {
 78-					if (temp == '?')
 79-						*c = 0x7f;
 80-					else
 81-						*c = temp & 0x1f;
 82-				} else
 83-					*c = temp & 0x7f;
 84-			}
 85-			setused(*c);
 86-			c++;
 87-			if (c >= &buf[9]) {
 88-				return kerror(mark, ": Key sequence too long");
 89-			}
 90-		}
 91-		*c = 0;
 92-		if (!(temp = lookup(mark))) {
 93-			return kerror(mark, ": Nonexistent function");
 94-		}
 95-		if (c == &buf[1] && (commands[temp].c_flags & ESC) &&
 96-		    escapes < &(commtable->k_esc[sizeof(commtable->k_esc) - 1])) {
 97-			*escapes++ = buf[0] & 0x7f;
 98-		}
 99-		temp = addstring(buf, temp, &(commtable->k_mach));
100-		if (temp == FSM_ISPREFIX) {
101-			return kerror(mark, ": Prefix of other key sequence");
102-		}
103-		if (temp == FSM_HASPREFIX) {
104-			return kerror(mark, ": Other key sequence is prefix");
105-		}
106-		assert(temp == FSM_OKE);
107-		if (!strcmp(mark, "hlp")) {
108-			/*
109-			 * Create an error message to be given when the user
110-			 * types an illegal command
111-			 */
112-			(void)strcpy(commtable->k_help, "Type ");
113-			(void)strcat(commtable->k_help, buf);
114-			(void)strcat(commtable->k_help, " for help");
115-		}
116-	}
117-	*escapes = 0;
118-	return (char *)0;
119+  char *mark; /* Indicates start of mnemonic */
120+  char *c;    /* Runs through buf */
121+  int   temp;
122+  char *escapes = commtable->k_esc;
123+  char  buf[10]; /* Will hold key sequence */
124+
125+  (void)strcpy(commtable->k_help, "Illegal command");
126+  while (*map) {
127+    c    = buf;
128+    mark = map; /* Start of mnemonic */
129+    while (*map && *map != '=') {
130+      map++;
131+    }
132+    if (!*map) {
133+      /*
134+       * Mnemonic should end with '='
135+       */
136+      return kerror(mark, ": Syntax error");
137+    }
138+    *map++ = 0;
139+    while (*map) {
140+      /*
141+       * Get key sequence
142+       */
143+      if (*map == ':') {
144+        /*
145+         * end of key sequence
146+         */
147+        map++;
148+        break;
149+      }
150+      *c = *map++ & 0x7f;
151+      if (*c == '^' || *c == '\\') {
152+        if (!(temp = *map++)) {
153+          /*
154+           * Escape not followed by a character
155+           */
156+          return kerror(mark, ": Syntax error");
157+        }
158+        if (*c == '^') {
159+          if (temp == '?')
160+            *c = 0x7f;
161+          else
162+            *c = temp & 0x1f;
163+        } else
164+          *c = temp & 0x7f;
165+      }
166+      setused(*c);
167+      c++;
168+      if (c >= &buf[9]) {
169+        return kerror(mark, ": Key sequence too long");
170+      }
171+    }
172+    *c = 0;
173+    if (!(temp = lookup(mark))) {
174+      return kerror(mark, ": Nonexistent function");
175+    }
176+    if (c == &buf[1] && (commands[temp].c_flags & ESC)
177+        && escapes < &(commtable->k_esc[sizeof(commtable->k_esc) - 1])) {
178+      *escapes++ = buf[0] & 0x7f;
179+    }
180+    temp = addstring(buf, temp, &(commtable->k_mach));
181+    if (temp == FSM_ISPREFIX) {
182+      return kerror(mark, ": Prefix of other key sequence");
183+    }
184+    if (temp == FSM_HASPREFIX) {
185+      return kerror(mark, ": Other key sequence is prefix");
186+    }
187+    assert(temp == FSM_OKE);
188+    if (!strcmp(mark, "hlp")) {
189+      /*
190+       * Create an error message to be given when the user
191+       * types an illegal command
192+       */
193+      (void)strcpy(commtable->k_help, "Type ");
194+      (void)strcat(commtable->k_help, buf);
195+      (void)strcat(commtable->k_help, " for help");
196+    }
197+  }
198+  *escapes = 0;
199+  return (char *)0;
200 }
201 
202 /*
203@@ -128,37 +128,37 @@ compile(char *map, struct keymap *commtable)
204 void
205 initkeys()
206 {
207-	char *p;
208-	static struct keymap xx[2];
209-
210-	currmap = &xx[0];
211-	othermap = &xx[1];
212-	p = compile(defaultmap, currmap); /* Compile default map */
213-	assert(p == (char *)0);
214-	p = getenv("YAPKEYS");
215-	if (p) {
216-		if (!(p = compile(p, othermap))) {
217-			/*
218-			 * No errors in user defined keymap. So, use it
219-			 */
220-			do_chkm(0L);
221-			return;
222-		}
223-		error(p);
224-	}
225-	othermap = 0; /* No other keymap */
226+  char                *p;
227+  static struct keymap xx[2];
228+
229+  currmap  = &xx[0];
230+  othermap = &xx[1];
231+  p        = compile(defaultmap, currmap); /* Compile default map */
232+  assert(p == (char *)0);
233+  p = getenv("YAPKEYS");
234+  if (p) {
235+    if (!(p = compile(p, othermap))) {
236+      /*
237+       * No errors in user defined keymap. So, use it
238+       */
239+      do_chkm(0L);
240+      return;
241+    }
242+    error(p);
243+  }
244+  othermap = 0; /* No other keymap */
245 }
246 
247 int
248 is_escape(int c)
249 {
250-	char *p = currmap->k_esc;
251+  char *p = currmap->k_esc;
252 
253-	while (*p) {
254-		if (c == *p++)
255-			return 1;
256-	}
257-	return 0;
258+  while (*p) {
259+    if (c == *p++)
260+      return 1;
261+  }
262+  return 0;
263 }
264 
265 static char keyset[16]; /* bitset indicating which keys are
266@@ -171,8 +171,7 @@ static char keyset[16]; /* bitset indicating which keys are
267 void
268 setused(int key)
269 {
270-
271-	keyset[(key & 0x7f) >> 3] |= (1 << (key & 0x07));
272+  keyset[(key & 0x7f) >> 3] |= (1 << (key & 0x07));
273 }
274 
275 /*
276@@ -182,6 +181,5 @@ setused(int key)
277 int
278 isused(int key)
279 {
280-
281-	return keyset[(key & 0x7f) >> 3] & (1 << (key & 0x07));
282+  return keyset[(key & 0x7f) >> 3] & (1 << (key & 0x07));
283 }
+5, -5
 1@@ -2,14 +2,14 @@
 2 #define KEYS_H
 3 
 4 extern struct keymap {
 5-	char k_help[80];
 6-	struct state *k_mach;
 7-	char k_esc[10];
 8+  char          k_help[80];
 9+  struct state *k_mach;
10+  char          k_esc[10];
11 } *currmap, *othermap;
12 
13 void initkeys(void);
14 void setused(int key);
15-int isused(int key);
16-int is_escape(int c);
17+int  isused(int key);
18+int  is_escape(int c);
19 
20 #endif
+94, -97
  1@@ -1,10 +1,10 @@
  2 /* Copyright (c) 1985 Ceriel J.H. Jacobs */
  3 
  4-#include <ctype.h>
  5-#include "in_all.h"
  6 #include "machine.h"
  7-#include "getline.h"
  8 #include "assert.h"
  9+#include "getline.h"
 10+#include "in_all.h"
 11+#include <ctype.h>
 12 
 13 /*
 14  * Add part of finite state machine to recognize the string s.
 15@@ -13,59 +13,58 @@
 16 static int
 17 addtomach(char *s, int cnt, struct state **list)
 18 {
 19+  struct state *l;
 20+  int           i = FSM_OKE; /* Return value */
 21+  int           j;
 22 
 23-	struct state *l;
 24-	int i = FSM_OKE; /* Return value */
 25-	int j;
 26-
 27-	for (;;) {
 28-		l = *list;
 29-		if (!l) {
 30-			/*
 31-			 * Create new list element
 32-			 */
 33-			*list = l = (struct state *)alloc(sizeof(*l));
 34-			l->s_char = *s;
 35-			l->s_endstate = 0;
 36-			l->s_match = 0;
 37-			l->s_next = 0;
 38-		}
 39-		if (l->s_char == *s) {
 40-			/*
 41-			 * Continue with next character
 42-			 */
 43-			if (!*++s) {
 44-				/*
 45-				 * No next character
 46-				 */
 47-				j = l->s_endstate;
 48-				l->s_endstate = 1;
 49-				if (l->s_match || j) {
 50-					/*
 51-					 * If the state already was an endstate,
 52-					 * or has a successor, the currently
 53-					 * added string is a prefix of an
 54-					 * already recognized string
 55-					 */
 56-					return FSM_ISPREFIX;
 57-				}
 58-				l->s_cnt = cnt;
 59-				return i;
 60-			}
 61-			if (l->s_endstate) {
 62-				/*
 63-				 * In this case, the currently added string has
 64-				 * a prefix that is an already recognized
 65-				 * string.
 66-				 */
 67-				i = FSM_HASPREFIX;
 68-			}
 69-			list = &(l->s_match);
 70-			continue;
 71-		}
 72-		list = &(l->s_next);
 73-	}
 74-	/* NOTREACHED */
 75+  for (;;) {
 76+    l = *list;
 77+    if (!l) {
 78+      /*
 79+       * Create new list element
 80+       */
 81+      *list = l     = (struct state *)alloc(sizeof(*l));
 82+      l->s_char     = *s;
 83+      l->s_endstate = 0;
 84+      l->s_match    = 0;
 85+      l->s_next     = 0;
 86+    }
 87+    if (l->s_char == *s) {
 88+      /*
 89+       * Continue with next character
 90+       */
 91+      if (!*++s) {
 92+        /*
 93+         * No next character
 94+         */
 95+        j             = l->s_endstate;
 96+        l->s_endstate = 1;
 97+        if (l->s_match || j) {
 98+          /*
 99+           * If the state already was an endstate,
100+           * or has a successor, the currently
101+           * added string is a prefix of an
102+           * already recognized string
103+           */
104+          return FSM_ISPREFIX;
105+        }
106+        l->s_cnt = cnt;
107+        return i;
108+      }
109+      if (l->s_endstate) {
110+        /*
111+         * In this case, the currently added string has
112+         * a prefix that is an already recognized
113+         * string.
114+         */
115+        i = FSM_HASPREFIX;
116+      }
117+      list = &(l->s_match);
118+      continue;
119+    }
120+    list = &(l->s_next);
121+  }
122+  /* NOTREACHED */
123 }
124 
125 /*
126@@ -75,11 +74,10 @@ addtomach(char *s, int cnt, struct state **list)
127 int
128 addstring(char *s, int cnt, struct state **machine)
129 {
130-
131-	if (!s || !*s) {
132-		return FSM_ISPREFIX;
133-	}
134-	return addtomach(s, cnt, machine);
135+  if (!s || !*s) {
136+    return FSM_ISPREFIX;
137+  }
138+  return addtomach(s, cnt, machine);
139 }
140 
141 /*
142@@ -93,42 +91,41 @@ addstring(char *s, int cnt, struct state **machine)
143 int
144 match(char *s, int *i, struct state *mach)
145 {
146+  char         *s1    = s; /* Walk through string */
147+  struct state *mach1 = 0;
148+  /* Keep track of previous state */
149 
150-	char *s1 = s; /* Walk through string */
151-	struct state *mach1 = 0;
152-	/* Keep track of previous state */
153-
154-	while (mach && *s1) {
155-		if (mach->s_char == *s1) {
156-			/*
157-			 * Current character matches. Carry on with next
158-			 * character and next state
159-			 */
160-			mach1 = mach;
161-			mach = mach->s_match;
162-			s1++;
163-			continue;
164-		}
165-		mach = mach->s_next;
166-	}
167-	if (!mach1) {
168-		/*
169-		 * No characters matched
170-		 */
171-		return 0;
172-	}
173-	if (mach1->s_endstate) {
174-		/*
175-		 * The string matched
176-		 */
177-		*i = mach1->s_cnt;
178-		return s1 - s;
179-	}
180-	if (!*s1) {
181-		/*
182-		 * The string matched a prefix
183-		 */
184-		return FSM_ISPREFIX;
185-	}
186-	return 0;
187+  while (mach && *s1) {
188+    if (mach->s_char == *s1) {
189+      /*
190+       * Current character matches. Carry on with next
191+       * character and next state
192+       */
193+      mach1 = mach;
194+      mach  = mach->s_match;
195+      s1++;
196+      continue;
197+    }
198+    mach = mach->s_next;
199+  }
200+  if (!mach1) {
201+    /*
202+     * No characters matched
203+     */
204+    return 0;
205+  }
206+  if (mach1->s_endstate) {
207+    /*
208+     * The string matched
209+     */
210+    *i = mach1->s_cnt;
211+    return s1 - s;
212+  }
213+  if (!*s1) {
214+    /*
215+     * The string matched a prefix
216+     */
217+    return FSM_ISPREFIX;
218+  }
219+  return 0;
220 }
+7, -7
 1@@ -2,15 +2,15 @@
 2 #define MACHINE_H
 3 
 4 struct state {
 5-	char s_char;
 6-	char s_endstate;
 7-	struct state *s_match;
 8-	struct state *s_next;
 9-	short s_cnt;
10+  char          s_char;
11+  char          s_endstate;
12+  struct state *s_match;
13+  struct state *s_next;
14+  short         s_cnt;
15 };
16 
17-#define FSM_OKE 0
18-#define FSM_ISPREFIX -1
19+#define FSM_OKE       0
20+#define FSM_ISPREFIX  -1
21 #define FSM_HASPREFIX 1
22 
23 int addstring(char *str, int cnt, struct state **mach);
+100, -106
  1@@ -1,21 +1,21 @@
  2 /* Copyright (c) 1985 Ceriel J.H. Jacobs */
  3 
  4-#include "in_all.h"
  5 #include "main.h"
  6-#include "term.h"
  7+#include "commands.h"
  8+#include "display.h"
  9+#include "in_all.h"
 10 #include "options.h"
 11 #include "output.h"
 12 #include "process.h"
 13-#include "commands.h"
 14-#include "display.h"
 15 #include "prompt.h"
 16+#include "term.h"
 17 
 18-int nopipe;
 19+int   nopipe;
 20 char *progname;
 21-int interrupt;
 22-int no_tty;
 23+int   interrupt;
 24+int   no_tty;
 25 
 26-static int initialize(int x);
 27+static int  initialize(int x);
 28 static void sigquit(int signo);
 29 #ifdef SIGTSTP
 30 static void suspsig(int signo);
 31@@ -24,34 +24,32 @@ static void suspsig(int signo);
 32 int
 33 main(int argc, char **argv)
 34 {
 35-	char **av;
 36-
 37-	(void)setlocale(LC_CTYPE, "");
 38-	if (!isatty(1)) {
 39-		no_tty = 1;
 40-	}
 41-	argv[argc] = 0;
 42-	progname = argv[0];
 43-	if ((av = readoptions(argv)) == (char **)0 ||
 44-	    initialize(*av ? 1 : 0)) {
 45-		if (no_tty) {
 46-			close(1);
 47-			(void)dup(2);
 48-		}
 49-		putline("Usage: ");
 50-		putline(argv[0]);
 51-		putline(
 52-		    " [-c] [-u] [-n] [-q] [-number] [+command] [file ... ]\n");
 53-		flush();
 54-		exit(1);
 55-	}
 56-	if (no_tty) {
 57-		*--av = "cat";
 58-		execve("/bin/cat", av, (char *const[]){NULL});
 59-	} else
 60-		processfiles(argc - (av - argv), av);
 61-	(void)quit();
 62-	/* NOTREACHED */
 63+  char **av;
 64+
 65+  (void)setlocale(LC_CTYPE, "");
 66+  if (!isatty(1)) {
 67+    no_tty = 1;
 68+  }
 69+  argv[argc] = 0;
 70+  progname   = argv[0];
 71+  if ((av = readoptions(argv)) == (char **)0 || initialize(*av ? 1 : 0)) {
 72+    if (no_tty) {
 73+      close(1);
 74+      (void)dup(2);
 75+    }
 76+    putline("Usage: ");
 77+    putline(argv[0]);
 78+    putline(" [-c] [-u] [-n] [-q] [-number] [+command] [file ... ]\n");
 79+    flush();
 80+    exit(1);
 81+  }
 82+  if (no_tty) {
 83+    *--av = "cat";
 84+    execve("/bin/cat", av, (char *const[]){NULL});
 85+  } else
 86+    processfiles(argc - (av - argv), av);
 87+  (void)quit();
 88+  /* NOTREACHED */
 89 }
 90 
 91 /*
 92@@ -66,58 +64,57 @@ main(int argc, char **argv)
 93 static int
 94 initialize(int x)
 95 {
 96-
 97-	if (!(nopipe = x)) {
 98-		/*
 99-		 * Reading from pipe
100-		 */
101-		if (isatty(0)) {
102-			return 1;
103-		}
104-		stdf = dup(0); /* Duplicate file descriptor of input */
105-		if (no_tty)
106-			return 0;
107-		/*
108-		 * Make sure standard input is from the terminal.
109-		 */
110-		(void)close(0);
111-		if (open("/dev/tty", O_RDONLY, 0) != 0) {
112-			putline("Couldn't open terminal\n");
113-			flush();
114-			exit(1);
115-		}
116-	}
117-	if (no_tty)
118-		return 0;
119-	/*
120-	 * Handle signals.
121-	 * Catch QUIT, DELETE and ^Z
122-	 */
123-	(void)signal(SIGQUIT, SIG_IGN);
124-	(void)signal(SIGINT, catchdel);
125-	ini_terminal();
126+  if (!(nopipe = x)) {
127+    /*
128+     * Reading from pipe
129+     */
130+    if (isatty(0)) {
131+      return 1;
132+    }
133+    stdf = dup(0); /* Duplicate file descriptor of input */
134+    if (no_tty)
135+      return 0;
136+    /*
137+     * Make sure standard input is from the terminal.
138+     */
139+    (void)close(0);
140+    if (open("/dev/tty", O_RDONLY, 0) != 0) {
141+      putline("Couldn't open terminal\n");
142+      flush();
143+      exit(1);
144+    }
145+  }
146+  if (no_tty)
147+    return 0;
148+  /*
149+   * Handle signals.
150+   * Catch QUIT, DELETE and ^Z
151+   */
152+  (void)signal(SIGQUIT, SIG_IGN);
153+  (void)signal(SIGINT, catchdel);
154+  ini_terminal();
155 #ifdef SIGTSTP
156-	if (signal(SIGTSTP, SIG_IGN) == SIG_DFL) {
157-		(void)signal(SIGTSTP, suspsig);
158-	}
159+  if (signal(SIGTSTP, SIG_IGN) == SIG_DFL) {
160+    (void)signal(SIGTSTP, suspsig);
161+  }
162 #endif
163-	(void)signal(SIGQUIT, sigquit);
164-	return 0;
165+  (void)signal(SIGQUIT, sigquit);
166+  return 0;
167 }
168 
169 void
170 catchdel(int signo)
171 {
172-	(void)signo;
173-	(void)signal(SIGINT, catchdel);
174-	interrupt = 1;
175+  (void)signo;
176+  (void)signal(SIGINT, catchdel);
177+  interrupt = 1;
178 }
179 
180 static void
181 sigquit(int signo)
182 {
183-	(void)signo;
184-	quit();
185+  (void)signo;
186+  quit();
187 }
188 
189 #ifdef SIGTSTP
190@@ -130,22 +127,21 @@ sigquit(int signo)
191 void
192 suspend()
193 {
194-
195-	nflush();
196-	resettty();
197-	(void)signal(SIGTSTP, SIG_DFL);
198-	(void)kill(0, SIGTSTP);
199-	/*
200-	 * We are not here anymore ...
201-	 *
202-
203-	 *
204-	 * But we arive here ...
205-	 */
206-	inittty();
207-	putline(TI);
208-	flush();
209-	(void)signal(SIGTSTP, suspsig);
210+  nflush();
211+  resettty();
212+  (void)signal(SIGTSTP, SIG_DFL);
213+  (void)kill(0, SIGTSTP);
214+  /*
215+   * We are not here anymore ...
216+   *
217+
218+   *
219+   * But we arive here ...
220+   */
221+  inittty();
222+  putline(TI);
223+  flush();
224+  (void)signal(SIGTSTP, suspsig);
225 }
226 
227 /*
228@@ -156,11 +152,11 @@ suspend()
229 static void
230 suspsig(int signo)
231 {
232-	(void)signo;
233+  (void)signo;
234 
235-	suspend();
236-	if (DoneSetJmp)
237-		longjmp(SetJmpBuf, 1);
238+  suspend();
239+  if (DoneSetJmp)
240+    longjmp(SetJmpBuf, 1);
241 }
242 #endif
243 
244@@ -172,11 +168,10 @@ suspsig(int signo)
245 int
246 quit()
247 {
248-
249-	clrbline();
250-	resettty();
251-	flush();
252-	exit(0);
253+  clrbline();
254+  resettty();
255+  flush();
256+  exit(0);
257 }
258 
259 /*
260@@ -187,9 +182,8 @@ quit()
261 void
262 panic(char *s)
263 {
264-
265-	putline("\a\a\a\r\n");
266-	putline(s);
267-	putline("\r\n");
268-	quit();
269+  putline("\a\a\a\r\n");
270+  putline(s);
271+  putline("\r\n");
272+  quit();
273 }
+5, -5
 1@@ -1,14 +1,14 @@
 2 #ifndef MAIN_H
 3 #define MAIN_H
 4 
 5-extern int nopipe;
 6+extern int   nopipe;
 7 extern char *progname;
 8-extern int interrupt;
 9-extern int no_tty;
10+extern int   interrupt;
11+extern int   no_tty;
12 
13-int main(int argc, char **argv);
14+int  main(int argc, char **argv);
15 void catchdel(int signo);
16-int quit(void);
17+int  quit(void);
18 void panic(char *s);
19 
20 #ifdef SIGTSTP
+64, -65
  1@@ -1,15 +1,15 @@
  2 /* Copyright (c) 1985 Ceriel J.H. Jacobs */
  3 
  4-#include "in_all.h"
  5 #include "options.h"
  6-#include "output.h"
  7 #include "display.h"
  8+#include "in_all.h"
  9+#include "output.h"
 10 #include <ctype.h>
 11 
 12-int cflag;
 13-int uflag;
 14-int nflag;
 15-int qflag;
 16+int   cflag;
 17+int   uflag;
 18+int   nflag;
 19+int   qflag;
 20 char *startcomm;
 21 
 22 static int parsopt(char *s);
 23@@ -22,70 +22,69 @@ static int parsopt(char *s);
 24 char **
 25 readoptions(char **argv)
 26 {
 27+  char **av = argv + 1;
 28+  char  *p;
 29 
 30-	char **av = argv + 1;
 31-	char *p;
 32-
 33-	if ((p = getenv("YAP")) != 0) {
 34-		(void)parsopt(p);
 35-	}
 36-	while (*av && **av == '-') {
 37-		if (parsopt(*av)) {
 38-			/*
 39-			 * Error in option
 40-			 */
 41-			putline(*av);
 42-			putline(": illegal option\n");
 43-			return (char **)0;
 44-		}
 45-		av++;
 46-	}
 47-	if (*av && **av == '+') {
 48-		/*
 49-		 * Command in command line
 50-		 */
 51-		startcomm = *av + 1;
 52-		av++;
 53-	}
 54-	return av;
 55+  if ((p = getenv("YAP")) != 0) {
 56+    (void)parsopt(p);
 57+  }
 58+  while (*av && **av == '-') {
 59+    if (parsopt(*av)) {
 60+      /*
 61+       * Error in option
 62+       */
 63+      putline(*av);
 64+      putline(": illegal option\n");
 65+      return (char **)0;
 66+    }
 67+    av++;
 68+  }
 69+  if (*av && **av == '+') {
 70+    /*
 71+     * Command in command line
 72+     */
 73+    startcomm = *av + 1;
 74+    av++;
 75+  }
 76+  return av;
 77 }
 78 
 79 static int
 80 parsopt(char *s)
 81 {
 82-	int i;
 83+  int i;
 84 
 85-	if (*s == '-')
 86-		s++;
 87-	if (isdigit(*s)) {
 88-		/*
 89-		 * pagesize option
 90-		 */
 91-		i = 0;
 92-		do {
 93-			i = i * 10 + *s++ - '0';
 94-		} while (isdigit(*s));
 95-		if (i < MINPAGESIZE)
 96-			i = MINPAGESIZE;
 97-		pagesize = i;
 98-	}
 99-	while (*s) {
100-		switch (*s++) {
101-		case 'c':
102-			cflag++;
103-			break;
104-		case 'n':
105-			nflag++;
106-			break;
107-		case 'u':
108-			uflag++;
109-			break;
110-		case 'q':
111-			qflag++;
112-			break;
113-		default:
114-			return 1;
115-		}
116-	}
117-	return 0;
118+  if (*s == '-')
119+    s++;
120+  if (isdigit(*s)) {
121+    /*
122+     * pagesize option
123+     */
124+    i = 0;
125+    do {
126+      i = i * 10 + *s++ - '0';
127+    } while (isdigit(*s));
128+    if (i < MINPAGESIZE)
129+      i = MINPAGESIZE;
130+    pagesize = i;
131+  }
132+  while (*s) {
133+    switch (*s++) {
134+      case 'c':
135+        cflag++;
136+        break;
137+      case 'n':
138+        nflag++;
139+        break;
140+      case 'u':
141+        uflag++;
142+        break;
143+      case 'q':
144+        qflag++;
145+        break;
146+      default:
147+        return 1;
148+    }
149+  }
150+  return 0;
151 }
+4, -4
 1@@ -1,10 +1,10 @@
 2 #ifndef OPTIONS_H
 3 #define OPTIONS_H
 4 
 5-extern int cflag;
 6-extern int uflag;
 7-extern int nflag;
 8-extern int qflag;
 9+extern int   cflag;
10+extern int   uflag;
11+extern int   nflag;
12+extern int   qflag;
13 extern char *startcomm;
14 
15 char **readoptions(char **argv);
+35, -36
  1@@ -4,11 +4,11 @@
  2  * Handle output to screen
  3  */
  4 
  5-#include "in_all.h"
  6 #include "output.h"
  7+#include "in_all.h"
  8 #include "main.h"
  9 
 10-int _ocnt;
 11+int   _ocnt;
 12 char *_optr;
 13 
 14 #define OBUFSIZ 64 * 128
 15@@ -18,38 +18,38 @@ static char _outbuf[OBUFSIZ];
 16 void
 17 flush()
 18 { /* Flush output buffer, by writing it */
 19-	char *p = _outbuf;
 20+  char *p = _outbuf;
 21 
 22-	_ocnt = OBUFSIZ;
 23-	if (_optr)
 24-		(void)write(1, p, _optr - p);
 25-	_optr = p;
 26+  _ocnt = OBUFSIZ;
 27+  if (_optr)
 28+    (void)write(1, p, _optr - p);
 29+  _optr = p;
 30 }
 31 
 32 void
 33 nflush()
 34 { /* Flush output buffer, ignoring it */
 35 
 36-	_ocnt = OBUFSIZ;
 37-	_optr = _outbuf;
 38+  _ocnt = OBUFSIZ;
 39+  _optr = _outbuf;
 40 }
 41 
 42 int
 43 fputch(int ch)
 44 { /* print a character */
 45-	putch(ch);
 46-	return ch;
 47+  putch(ch);
 48+  return ch;
 49 }
 50 
 51 void
 52 putline(char *s)
 53 { /* Print string s */
 54 
 55-	if (!s)
 56-		return;
 57-	while (*s) {
 58-		putch(*s++);
 59-	}
 60+  if (!s)
 61+    return;
 62+  while (*s) {
 63+    putch(*s++);
 64+  }
 65 }
 66 
 67 /*
 68@@ -59,15 +59,15 @@ putline(char *s)
 69 void
 70 cputline(char *s)
 71 {
 72-	int c;
 73-
 74-	while ((c = *s++) != 0) {
 75-		if ((unsigned char)c < ' ' || (unsigned char)c == 0x7f) {
 76-			putch('^');
 77-			c ^= 0x40;
 78-		}
 79-		putch(c);
 80-	}
 81+  int c;
 82+
 83+  while ((c = *s++) != 0) {
 84+    if ((unsigned char)c < ' ' || (unsigned char)c == 0x7f) {
 85+      putch('^');
 86+      c ^= 0x40;
 87+    }
 88+    putch(c);
 89+  }
 90 }
 91 
 92 /*
 93@@ -77,26 +77,25 @@ cputline(char *s)
 94 void
 95 prnum(long n)
 96 {
 97-
 98-	putline(getnum(n));
 99+  putline(getnum(n));
100 }
101 
102 static char *
103 fillnum(long n, char *p)
104 {
105-	if (n >= 10) {
106-		p = fillnum(n / 10, p);
107-	}
108-	*p++ = (int)(n % 10) + '0';
109-	*p = '\0';
110-	return p;
111+  if (n >= 10) {
112+    p = fillnum(n / 10, p);
113+  }
114+  *p++ = (int)(n % 10) + '0';
115+  *p   = '\0';
116+  return p;
117 }
118 
119 char *
120 getnum(long n)
121 {
122-	static char buf[20];
123+  static char buf[20];
124 
125-	fillnum(n, buf);
126-	return buf;
127+  fillnum(n, buf);
128+  return buf;
129 }
+13, -13
 1@@ -1,22 +1,22 @@
 2 #ifndef OUTPUT_H
 3 #define OUTPUT_H
 4 
 5-extern int _ocnt;
 6+extern int   _ocnt;
 7 extern char *_optr;
 8 
 9-#define putch(ch) \
10-	do { \
11-		if (--_ocnt <= 0) \
12-			flush(); \
13-		*_optr++ = (ch); \
14-	} while (0)
15+#define putch(ch)                                                                                  \
16+  do {                                                                                             \
17+    if (--_ocnt <= 0)                                                                              \
18+      flush();                                                                                     \
19+    *_optr++ = (ch);                                                                               \
20+  } while (0)
21 
22-void flush(void);
23-void nflush(void);
24-int fputch(int c);
25-void putline(char *s);
26-void cputline(char *s);
27-void prnum(long n);
28+void  flush(void);
29+void  nflush(void);
30+int   fputch(int c);
31+void  putline(char *s);
32+void  cputline(char *s);
33+void  prnum(long n);
34 char *getnum(long n);
35 
36 #endif
+15, -16
 1@@ -1,5 +1,5 @@
 2-#include "in_all.h"
 3 #include "pattern.h"
 4+#include "in_all.h"
 5 #include <regex.h>
 6 
 7 /*
 8@@ -7,28 +7,27 @@
 9  */
10 
11 static regex_t pattern;
12-static int pattern_valid;
13+static int     pattern_valid;
14 
15 char *
16 re_comp(char *s)
17 {
18-
19-	if (!*s) {
20-		return (char *)0;
21-	}
22-	if (pattern_valid) {
23-		regfree(&pattern);
24-		pattern_valid = 0;
25-	}
26-	if (regcomp(&pattern, s, 0) == 0) {
27-		pattern_valid = 1;
28-		return (char *)0;
29-	}
30-	return "Error in pattern";
31+  if (!*s) {
32+    return (char *)0;
33+  }
34+  if (pattern_valid) {
35+    regfree(&pattern);
36+    pattern_valid = 0;
37+  }
38+  if (regcomp(&pattern, s, 0) == 0) {
39+    pattern_valid = 1;
40+    return (char *)0;
41+  }
42+  return "Error in pattern";
43 }
44 
45 int
46 re_exec(char *s)
47 {
48-	return pattern_valid && regexec(&pattern, s, 0, (regmatch_t *)0, 0) == 0;
49+  return pattern_valid && regexec(&pattern, s, 0, (regmatch_t *)0, 0) == 0;
50 }
+1, -1
1@@ -2,6 +2,6 @@
2 #define PATTERN_H
3 
4 char *re_comp(char *s);
5-int re_exec(char *s);
6+int   re_exec(char *s);
7 
8 #endif
+70, -71
  1@@ -1,23 +1,23 @@
  2 /* Copyright (c) 1985 Ceriel J.H. Jacobs */
  3 
  4-#include "in_all.h"
  5 #include "process.h"
  6 #include "commands.h"
  7 #include "display.h"
  8-#include "prompt.h"
  9-#include "getline.h"
 10 #include "getcomm.h"
 11+#include "getline.h"
 12+#include "in_all.h"
 13 #include "main.h"
 14 #include "options.h"
 15 #include "output.h"
 16+#include "prompt.h"
 17 
 18 jmp_buf SetJmpBuf;
 19-int DoneSetJmp;
 20-int stdf;
 21-int filecount;
 22-char **filenames;
 23-char *currentfile;
 24-long maxpos;
 25+int     DoneSetJmp;
 26+int     stdf;
 27+int     filecount;
 28+char  **filenames;
 29+char   *currentfile;
 30+long    maxpos;
 31 
 32 static int nfiles; /* Number of filenames on command line */
 33 
 34@@ -28,24 +28,24 @@ static int nfiles; /* Number of filenames on command line */
 35 void
 36 visitfile(char *fn)
 37 {
 38-	struct stat statbuf;
 39+  struct stat statbuf;
 40 
 41-	if (stdf > 0) {
 42-		/*
 43-		 * Close old input file
 44-		 */
 45-		(void)close(stdf);
 46-	}
 47-	currentfile = fn;
 48-	if ((stdf = open(fn, O_RDONLY, 0)) < 0) {
 49-		error(": could not open");
 50-		maxpos = 0;
 51-	} else { /* Get size for percentage in prompt */
 52-		(void)fstat(stdf, &statbuf);
 53-		maxpos = statbuf.st_size;
 54-	}
 55-	do_clean();
 56-	d_clean();
 57+  if (stdf > 0) {
 58+    /*
 59+     * Close old input file
 60+     */
 61+    (void)close(stdf);
 62+  }
 63+  currentfile = fn;
 64+  if ((stdf = open(fn, O_RDONLY, 0)) < 0) {
 65+    error(": could not open");
 66+    maxpos = 0;
 67+  } else { /* Get size for percentage in prompt */
 68+    (void)fstat(stdf, &statbuf);
 69+    maxpos = statbuf.st_size;
 70+  }
 71+  do_clean();
 72+  d_clean();
 73 }
 74 
 75 /*
 76@@ -56,45 +56,44 @@ visitfile(char *fn)
 77 void
 78 processfiles(int n, char **argv)
 79 {
 80+  static char *dummies[3];
 81+  long         arg;
 82 
 83-	static char *dummies[3];
 84-	long arg;
 85-
 86-	if (!(nfiles = n)) {
 87-		/*
 88-		 * Input from pipe
 89-		 */
 90-		currentfile = "standard-input";
 91-		/*
 92-		 * Take care that *(filenames - 1) and *(filenames + 1) are 0
 93-		 */
 94-		filenames = &dummies[1];
 95-		d_clean();
 96-		do_clean();
 97-	} else {
 98-		filenames = argv;
 99-		(void)nextfile(0);
100-	}
101-	*--argv = 0;
102-	if (startcomm) {
103-		n = getcomm(&arg);
104-		if (commands[n].c_flags & NEEDS_SCREEN) {
105-			redraw(0);
106-		}
107-		do_comm(n, arg);
108-		startcomm = 0;
109-	}
110-	redraw(1);
111-	if (setjmp(SetJmpBuf)) {
112-		nflush();
113-		redraw(1);
114-	}
115-	DoneSetJmp = 1;
116-	for (;;) {
117-		interrupt = 0;
118-		n = getcomm(&arg);
119-		do_comm(n, arg);
120-	}
121+  if (!(nfiles = n)) {
122+    /*
123+     * Input from pipe
124+     */
125+    currentfile = "standard-input";
126+    /*
127+     * Take care that *(filenames - 1) and *(filenames + 1) are 0
128+     */
129+    filenames = &dummies[1];
130+    d_clean();
131+    do_clean();
132+  } else {
133+    filenames = argv;
134+    (void)nextfile(0);
135+  }
136+  *--argv = 0;
137+  if (startcomm) {
138+    n = getcomm(&arg);
139+    if (commands[n].c_flags & NEEDS_SCREEN) {
140+      redraw(0);
141+    }
142+    do_comm(n, arg);
143+    startcomm = 0;
144+  }
145+  redraw(1);
146+  if (setjmp(SetJmpBuf)) {
147+    nflush();
148+    redraw(1);
149+  }
150+  DoneSetJmp = 1;
151+  for (;;) {
152+    interrupt = 0;
153+    n         = getcomm(&arg);
154+    do_comm(n, arg);
155+  }
156 }
157 
158 /*
159@@ -104,12 +103,12 @@ processfiles(int n, char **argv)
160 int
161 nextfile(int n)
162 {
163-	int i;
164+  int i;
165 
166-	if ((i = filecount + n) >= nfiles || i < 0) {
167-		return 1;
168-	}
169-	filecount = i;
170-	visitfile(filenames[i]);
171-	return 0;
172+  if ((i = filecount + n) >= nfiles || i < 0) {
173+    return 1;
174+  }
175+  filecount = i;
176+  visitfile(filenames[i]);
177+  return 0;
178 }
+6, -6
 1@@ -4,16 +4,16 @@
 2 #include <setjmp.h>
 3 
 4 extern jmp_buf SetJmpBuf;
 5-extern int DoneSetJmp;
 6+extern int     DoneSetJmp;
 7 
 8-extern int stdf;
 9-extern int filecount;
10+extern int    stdf;
11+extern int    filecount;
12 extern char **filenames;
13-extern char *currentfile;
14-extern long maxpos;
15+extern char  *currentfile;
16+extern long   maxpos;
17 
18 void visitfile(char *fn);
19 void processfiles(int n, char **argv);
20-int nextfile(int n);
21+int  nextfile(int n);
22 
23 #endif
+121, -128
  1@@ -1,19 +1,19 @@
  2 /* Copyright (c) 1985 Ceriel J.H. Jacobs */
  3 
  4-#include "in_all.h"
  5 #include "prompt.h"
  6-#include "term.h"
  7-#include "output.h"
  8-#include "options.h"
  9+#include "assert.h"
 10+#include "commands.h"
 11 #include "display.h"
 12-#include "process.h"
 13-#include "getline.h"
 14-#include "main.h"
 15 #include "getcomm.h"
 16-#include "machine.h"
 17+#include "getline.h"
 18+#include "in_all.h"
 19 #include "keys.h"
 20-#include "assert.h"
 21-#include "commands.h"
 22+#include "machine.h"
 23+#include "main.h"
 24+#include "options.h"
 25+#include "output.h"
 26+#include "process.h"
 27+#include "term.h"
 28 
 29 static char *errorgiven; /* Set to error message, if there is one */
 30 
 31@@ -22,10 +22,10 @@ static char *display_basename(char *path, char *scratch, size_t scratch_size);
 32 char *
 33 copy(char *p, const char *ep, char *s)
 34 {
 35-	while (p < ep && *s) {
 36-		*p++ = *s++;
 37-	}
 38-	return p;
 39+  while (p < ep && *s) {
 40+    *p++ = *s++;
 41+  }
 42+  return p;
 43 }
 44 
 45 /*
 46@@ -35,104 +35,98 @@ copy(char *p, const char *ep, char *s)
 47 void
 48 give_prompt()
 49 {
 50+  char           **name;
 51+  struct scr_info *p = &scr_info;
 52+  char             buf[256];
 53+  char             filebuf[256];
 54+  char            *pb = buf;
 55 
 56-	char **name;
 57-	struct scr_info *p = &scr_info;
 58-	char buf[256];
 59-	char filebuf[256];
 60-	char *pb = buf;
 61-
 62-	if (startcomm)
 63-		return;
 64-	flush();
 65-	if (window()) {
 66-		redraw(0);
 67-		flush();
 68-	}
 69-	if (!stupid) {
 70-		/*
 71-		 * fancy prompt
 72-		 */
 73-		clrbline();
 74-		standout();
 75-		pb = copy(pb, &buf[255],
 76-		          display_basename(currentfile, filebuf, sizeof(filebuf)));
 77-		if (stdf >= 0) {
 78-			pb = copy(pb, &buf[255], ", ");
 79-			pb = copy(pb, &buf[255], getnum(p->firstline));
 80-			pb = copy(pb, &buf[255], "-");
 81-			pb = copy(pb, &buf[255], getnum(p->lastline));
 82-		}
 83-	} else {
 84-		*pb++ = '\007'; /* Stupid terminal, stupid prompt */
 85-	}
 86-	if (errorgiven) {
 87-		/*
 88-		 * display error message
 89-		 */
 90-		pb = copy(pb, &buf[255], " ");
 91-		pb = copy(pb, &buf[255], errorgiven);
 92-		if (stupid) {
 93-			pb = copy(pb, &buf[255], "\r\n");
 94-		}
 95-		errorgiven = 0;
 96-	} else if (!stupid && (status || maxpos)) {
 97-		pb = copy(pb, &buf[255], " (");
 98-		name = &filenames[filecount];
 99-		if (status) {
100-			/*
101-			 * indicate top and/or bottom
102-			 */
103-			if (status & START) {
104-				if (!*(name - 1)) {
105-					pb = copy(pb, &buf[255], "Top");
106-				} else {
107-					pb = copy(pb, &buf[255], "Previous: ");
108-					pb = copy(pb, &buf[255], display_basename(*(name - 1),
109-					                                         filebuf,
110-					                                         sizeof(filebuf)));
111-				}
112-				if (status & EOFILE) {
113-					pb = copy(pb, &buf[255], ", ");
114-				}
115-			}
116-			if (status & EOFILE) {
117-				if (!*(name + 1)) {
118-					pb = copy(pb, &buf[255], "Bottom");
119-				} else {
120-					pb = copy(pb, &buf[255], "Next: ");
121-					pb = copy(pb, &buf[255], display_basename(*(name + 1),
122-					                                         filebuf,
123-					                                         sizeof(filebuf)));
124-				}
125-			}
126-		} else { /* display percentage */
127-			pb = copy(pb, &buf[255], getnum((100 * getpos(p->lastline)) / maxpos));
128-			pb = copy(pb, &buf[255], "%");
129-		}
130-		pb = copy(pb, &buf[255], ")");
131-	}
132-	*pb = '\0';
133-	if (!stupid) {
134-		buf[COLS - 1] = 0;
135-		putline(buf);
136-		standend();
137-	} else
138-		putline(buf);
139+  if (startcomm)
140+    return;
141+  flush();
142+  if (window()) {
143+    redraw(0);
144+    flush();
145+  }
146+  if (!stupid) {
147+    /*
148+     * fancy prompt
149+     */
150+    clrbline();
151+    standout();
152+    pb = copy(pb, &buf[255], display_basename(currentfile, filebuf, sizeof(filebuf)));
153+    if (stdf >= 0) {
154+      pb = copy(pb, &buf[255], ", ");
155+      pb = copy(pb, &buf[255], getnum(p->firstline));
156+      pb = copy(pb, &buf[255], "-");
157+      pb = copy(pb, &buf[255], getnum(p->lastline));
158+    }
159+  } else {
160+    *pb++ = '\007'; /* Stupid terminal, stupid prompt */
161+  }
162+  if (errorgiven) {
163+    /*
164+     * display error message
165+     */
166+    pb = copy(pb, &buf[255], " ");
167+    pb = copy(pb, &buf[255], errorgiven);
168+    if (stupid) {
169+      pb = copy(pb, &buf[255], "\r\n");
170+    }
171+    errorgiven = 0;
172+  } else if (!stupid && (status || maxpos)) {
173+    pb   = copy(pb, &buf[255], " (");
174+    name = &filenames[filecount];
175+    if (status) {
176+      /*
177+       * indicate top and/or bottom
178+       */
179+      if (status & START) {
180+        if (!*(name - 1)) {
181+          pb = copy(pb, &buf[255], "Top");
182+        } else {
183+          pb = copy(pb, &buf[255], "Previous: ");
184+          pb = copy(pb, &buf[255], display_basename(*(name - 1), filebuf, sizeof(filebuf)));
185+        }
186+        if (status & EOFILE) {
187+          pb = copy(pb, &buf[255], ", ");
188+        }
189+      }
190+      if (status & EOFILE) {
191+        if (!*(name + 1)) {
192+          pb = copy(pb, &buf[255], "Bottom");
193+        } else {
194+          pb = copy(pb, &buf[255], "Next: ");
195+          pb = copy(pb, &buf[255], display_basename(*(name + 1), filebuf, sizeof(filebuf)));
196+        }
197+      }
198+    } else { /* display percentage */
199+      pb = copy(pb, &buf[255], getnum((100 * getpos(p->lastline)) / maxpos));
200+      pb = copy(pb, &buf[255], "%");
201+    }
202+    pb = copy(pb, &buf[255], ")");
203+  }
204+  *pb = '\0';
205+  if (!stupid) {
206+    buf[COLS - 1] = 0;
207+    putline(buf);
208+    standend();
209+  } else
210+    putline(buf);
211 }
212 
213 static char *
214 display_basename(char *path, char *scratch, size_t scratch_size)
215 {
216-	char *base;
217+  char *base;
218 
219-	if (!path || scratch_size == 0) {
220-		return "";
221-	}
222-	(void)strncpy(scratch, path, scratch_size - 1);
223-	scratch[scratch_size - 1] = '\0';
224-	base = basename(scratch);
225-	return base ? base : scratch;
226+  if (!path || scratch_size == 0) {
227+    return "";
228+  }
229+  (void)strncpy(scratch, path, scratch_size - 1);
230+  scratch[scratch_size - 1] = '\0';
231+  base                      = basename(scratch);
232+  return base ? base : scratch;
233 }
234 
235 /*
236@@ -142,33 +136,32 @@ display_basename(char *path, char *scratch, size_t scratch_size)
237 void
238 error(char *str)
239 {
240-
241-	errorgiven = str;
242+  errorgiven = str;
243 }
244 
245 void
246 ret_to_continue()
247 { /* Obvious */
248-	int c;
249-	static char buf[2];
250+  int         c;
251+  static char buf[2];
252 
253-	for (;;) {
254-		clrbline();
255-		standout();
256-		if (errorgiven) {
257-			putline(errorgiven);
258-			putline(" ");
259-			errorgiven = 0;
260-		}
261-		putline("[Type anything to continue]");
262-		standend();
263-		if (is_escape(c = getch())) {
264-			buf[0] = c;
265-			(void)match(buf, &c, currmap->k_mach);
266-			assert(c > 0);
267-			do_comm(c, -1L);
268-		} else
269-			break;
270-	}
271-	clrbline();
272+  for (;;) {
273+    clrbline();
274+    standout();
275+    if (errorgiven) {
276+      putline(errorgiven);
277+      putline(" ");
278+      errorgiven = 0;
279+    }
280+    putline("[Type anything to continue]");
281+    standend();
282+    if (is_escape(c = getch())) {
283+      buf[0] = c;
284+      (void)match(buf, &c, currmap->k_mach);
285+      assert(c > 0);
286+      do_comm(c, -1L);
287+    } else
288+      break;
289+  }
290+  clrbline();
291 }
+263, -268
  1@@ -4,31 +4,31 @@
  2  * Terminal handling routines, mostly initializing.
  3  */
  4 
  5-#include "in_all.h"
  6 #include "term.h"
  7-#include "machine.h"
  8-#include "output.h"
  9 #include "display.h"
 10-#include "options.h"
 11 #include "getline.h"
 12+#include "in_all.h"
 13 #include "keys.h"
 14+#include "machine.h"
 15 #include "main.h"
 16+#include "options.h"
 17+#include "output.h"
 18 #define getline yap_getline
 19-#define getch yap_getch
 20+#define getch   yap_getch
 21 #include <term.h>
 22 #undef getch
 23 #undef getline
 24 #undef insert_line
 25 
 26-int expandtabs;
 27-int stupid;
 28-int hardcopy;
 29-char *CE, *CL, *SO, *SE, *US, *UE, *UC, *MD, *ME, *TI, *TE, *CM, *TA, *SR, *AL;
 30-char *UP, *HO, *BO;
 31-int LINES, COLS, AM, XN, DB;
 32-int erasech, killch;
 33+int           expandtabs;
 34+int           stupid;
 35+int           hardcopy;
 36+char         *CE, *CL, *SO, *SE, *US, *UE, *UC, *MD, *ME, *TI, *TE, *CM, *TA, *SR, *AL;
 37+char         *UP, *HO, *BO;
 38+int           LINES, COLS, AM, XN, DB;
 39+int           erasech, killch;
 40 struct state *sppat;
 41-char *BC;
 42+char         *BC;
 43 
 44 #ifdef TIOCGWINSZ
 45 static struct winsize w;
 46@@ -48,8 +48,8 @@ static void
 47 handle(cc_t *c)
 48 { /* if character *c is used, set it to undefined */
 49 
 50-	if (isused(*c))
 51-		*c = 0xff;
 52+  if (isused(*c))
 53+    *c = 0xff;
 54 }
 55 
 56 /*
 57@@ -60,93 +60,93 @@ handle(cc_t *c)
 58 void
 59 inittty()
 60 {
 61-	struct termios *p = &_tty;
 62-
 63-	tcgetattr(0, p);
 64-	_svtty = *p;
 65-	p->c_oflag &= ~OPOST;
 66-	p->c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON);
 67-	if (isused('S' & 0x1f) || isused('Q' & 0x1f))
 68-		p->c_iflag &= ~IXON;
 69-	handle(&p->c_cc[VINTR]);
 70-	handle(&p->c_cc[VQUIT]);
 71-	erasech = p->c_cc[VERASE];
 72-	killch = p->c_cc[VKILL];
 73-	p->c_cc[VMIN] = 1; /* Just wait for one character */
 74-	p->c_cc[VTIME] = 0;
 75-	tcsetattr(0, TCSANOW, p);
 76+  struct termios *p = &_tty;
 77+
 78+  tcgetattr(0, p);
 79+  _svtty = *p;
 80+  p->c_oflag &= ~OPOST;
 81+  p->c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON);
 82+  if (isused('S' & 0x1f) || isused('Q' & 0x1f))
 83+    p->c_iflag &= ~IXON;
 84+  handle(&p->c_cc[VINTR]);
 85+  handle(&p->c_cc[VQUIT]);
 86+  erasech        = p->c_cc[VERASE];
 87+  killch         = p->c_cc[VKILL];
 88+  p->c_cc[VMIN]  = 1; /* Just wait for one character */
 89+  p->c_cc[VTIME] = 0;
 90+  tcsetattr(0, TCSANOW, p);
 91 }
 92 
 93 void
 94 backspace()
 95 {
 96-	putline(BC);
 97+  putline(BC);
 98 }
 99 
100 void
101 clrscreen()
102 {
103-	tputs(CL, LINES, fputch);
104+  tputs(CL, LINES, fputch);
105 }
106 
107 void
108 clrtoeol()
109 {
110-	tputs(CE, 1, fputch);
111+  tputs(CE, 1, fputch);
112 }
113 
114 void
115 scrollreverse()
116 {
117-	tputs(SR, LINES, fputch);
118+  tputs(SR, LINES, fputch);
119 }
120 
121 void
122 standout()
123 {
124-	tputs(SO, 1, fputch);
125+  tputs(SO, 1, fputch);
126 }
127 
128 void
129 standend()
130 {
131-	tputs(SE, 1, fputch);
132+  tputs(SE, 1, fputch);
133 }
134 
135 void
136 underline()
137 {
138-	tputs(US, 1, fputch);
139+  tputs(US, 1, fputch);
140 }
141 
142 void
143 end_underline()
144 {
145-	tputs(UE, 1, fputch);
146+  tputs(UE, 1, fputch);
147 }
148 
149 void
150 bold()
151 {
152-	tputs(MD, 1, fputch);
153+  tputs(MD, 1, fputch);
154 }
155 
156 void
157 end_bold()
158 {
159-	tputs(ME, 1, fputch);
160+  tputs(ME, 1, fputch);
161 }
162 
163 void
164 underchar()
165 {
166-	tputs(UC, 1, fputch);
167+  tputs(UC, 1, fputch);
168 }
169 
170 void
171 givetab()
172 {
173-	tputs(TA, 1, fputch);
174+  tputs(TA, 1, fputch);
175 }
176 
177 /*
178@@ -156,9 +156,9 @@ givetab()
179 void
180 resettty()
181 {
182-	tcsetattr(0, TCSANOW, &_svtty);
183-	putline(TE);
184-	flush();
185+  tcsetattr(0, TCSANOW, &_svtty);
186+  putline(TE);
187+  flush();
188 }
189 
190 /*
191@@ -169,30 +169,30 @@ resettty()
192 static char *
193 getcap(char *cap)
194 {
195-	char *s;
196+  char *s;
197 
198-	s = tigetstr(cap);
199-	if (!s || s == (char *)-1)
200-		return "";
201-	return s;
202+  s = tigetstr(cap);
203+  if (!s || s == (char *)-1)
204+    return "";
205+  return s;
206 }
207 
208 static int
209 getflag(char *cap)
210 {
211-	int value;
212+  int value;
213 
214-	value = tigetflag(cap);
215-	return value < 0 ? 0 : value;
216+  value = tigetflag(cap);
217+  return value < 0 ? 0 : value;
218 }
219 
220 static int
221 getnumcap(char *cap)
222 {
223-	int value;
224+  int value;
225 
226-	value = tigetnum(cap);
227-	return value < 0 ? -1 : value;
228+  value = tigetnum(cap);
229+  return value < 0 ? -1 : value;
230 }
231 
232 /*
233@@ -202,156 +202,155 @@ getnumcap(char *cap)
234 void
235 ini_terminal()
236 {
237-
238-	char *s;
239-	struct linelist *lp, *lp1;
240-	int i;
241-	int UG, SG;
242-	char tempbuf[20];
243-	char *mb, *mh, *mr; /* attributes */
244-	int err;
245-
246-	initkeys();
247+  char            *s;
248+  struct linelist *lp, *lp1;
249+  int              i;
250+  int              UG, SG;
251+  char             tempbuf[20];
252+  char            *mb, *mh, *mr; /* attributes */
253+  int              err;
254+
255+  initkeys();
256 #ifdef TIOCSPGRP
257-	proc_id = getpid();
258-	ioctl(0, TIOCGPGRP, (char *)&saved_pgrpid);
259+  proc_id = getpid();
260+  ioctl(0, TIOCGPGRP, (char *)&saved_pgrpid);
261 #endif
262-	inittty();
263-	stupid = 1;
264-	BC = "\b";
265-	TA = "\t";
266-	if (!(s = getenv("TERM")))
267-		s = "dumb";
268-	if (setupterm(s, 1, &err) != 0) {
269-		panic("No terminfo entry");
270-	}
271-	stupid = 0;
272-	hardcopy = getflag("hc"); /* Hard copy terminal?*/
273-	if (*(s = getcap("cub1"))) {
274-		/*
275-		 * Backspace if not ^H
276-		 */
277-		BC = s;
278-	}
279-	UP = getcap("cuu1");   /* move up a line */
280-	CE = getcap("el");     /* clear to end of line */
281-	CL = getcap("clear");  /* clear screen */
282-	if (!*CL)
283-		cflag = 1;
284-	TI = getcap("smcup");  /* Initialization for CM */
285-	TE = getcap("rmcup");  /* end for CM */
286-	CM = getcap("cup");    /* cursor addressing */
287-	SR = getcap("ri");     /* scroll reverse */
288-	AL = getcap("il");     /* Insert line */
289-	SO = getcap("smso");   /* standout */
290-	SE = getcap("rmso");   /* standend */
291-	SG = getnumcap("xmc"); /* blanks left by attributes */
292-	if (SG < 0)
293-		SG = 0;
294-	US = getcap("smul"); /* underline */
295-	UE = getcap("rmul"); /* end underline */
296-	UG = getnumcap("xmc"); /* blanks left by attributes */
297-	if (UG < 0)
298-		UG = 0;
299-	UC = getcap("uc");   /* underline a character */
300-	mb = getcap("blink"); /* blinking attribute */
301-	MD = getcap("bold");  /* bold attribute */
302-	ME = getcap("sgr0");  /* turn off attributes */
303-	mh = getcap("dim");   /* half bright attribute */
304-	mr = getcap("rev");   /* reversed video attribute */
305-	if (!nflag) {
306-		/*
307-		 * Recognize special strings
308-		 */
309-		(void)addstring(SO, SG, &sppat);
310-		(void)addstring(SE, SG, &sppat);
311-		(void)addstring(US, UG, &sppat);
312-		(void)addstring(UE, UG, &sppat);
313-		(void)addstring(mb, 0, &sppat);
314-		(void)addstring(MD, 0, &sppat);
315-		(void)addstring(ME, 0, &sppat);
316-		(void)addstring(mh, 0, &sppat);
317-		(void)addstring(mr, 0, &sppat);
318-		if (*UC) {
319-			(void)strcpy(tempbuf, BC);
320-			(void)strcat(tempbuf, UC);
321-			(void)addstring(tempbuf, 0, &sppat);
322-		}
323-	}
324-	if (UG > 0 || uflag) {
325-		US = "";
326-		UE = "";
327-	}
328-	if (*US || uflag)
329-		UC = "";
330-	COLS = getnumcap("cols"); /* columns on page */
331-	i = getnumcap("lines");   /* Lines on page */
332-	AM = getflag("am");       /* terminal wraps automatically? */
333-	XN = getflag("xenl");     /* and then ignores next newline? */
334-	DB = getflag("db");       /* terminal retains lines below */
335-	HO = getcap("home");
336-	if (!*HO && *CM) {
337-		HO = tiparm(CM, 0, 0); /* Another way of getting home */
338-	}
339-	if ((!*CE && !*AL) || !*HO || hardcopy) {
340-		cflag = stupid = 1;
341-	}
342-	if (*(s = getcap("ht"))) {
343-		/*
344-		 * Tab (other than ^I or padding)
345-		 */
346-		TA = s;
347-	}
348-	if (!*(ll = getcap("ll")) && *CM && i > 0) {
349-		/*
350-		 * Lower left hand corner
351-		 */
352-		BO = tiparm(CM, i - 1, 0);
353-	} else
354-		BO = ll;
355-	if (COLS <= 0 || COLS > 256) {
356-		if ((unsigned)COLS >= 65409) {
357-			/* SUN bug */
358-			COLS &= 0xffff;
359-			COLS -= (65409 - 128);
360-		}
361-		if (COLS <= 0 || COLS > 256)
362-			COLS = 80;
363-	}
364-	if (i <= 0) {
365-		i = 24;
366-		cflag = stupid = 1;
367-	}
368-	LINES = i;
369-	maxpagesize = i - 1;
370-	scrollsize = maxpagesize / 2;
371-	if (scrollsize <= 0)
372-		scrollsize = 1;
373-	if (!pagesize || pagesize >= i) {
374-		pagesize = maxpagesize;
375-	}
376-
377-	/*
378-	 * The next part does not really belong here, but there it is ...
379-	 * Initialize a circular list for the screenlines.
380-	 */
381-
382-	scr_info.tail = lp = _X;
383-	lp1 = lp + (100 - 1);
384-	for (; lp <= lp1; lp++) {
385-		/*
386-		 * Circular doubly linked list
387-		 */
388-		lp->next = lp + 1;
389-		lp->prev = lp - 1;
390-	}
391-	lp1->next = scr_info.tail;
392-	lp1->next->prev = lp1;
393-	if (stupid) {
394-		BO = "\r\n";
395-	}
396-	putline(TI);
397-	window();
398+  inittty();
399+  stupid = 1;
400+  BC     = "\b";
401+  TA     = "\t";
402+  if (!(s = getenv("TERM")))
403+    s = "dumb";
404+  if (setupterm(s, 1, &err) != 0) {
405+    panic("No terminfo entry");
406+  }
407+  stupid   = 0;
408+  hardcopy = getflag("hc"); /* Hard copy terminal?*/
409+  if (*(s = getcap("cub1"))) {
410+    /*
411+     * Backspace if not ^H
412+     */
413+    BC = s;
414+  }
415+  UP = getcap("cuu1");  /* move up a line */
416+  CE = getcap("el");    /* clear to end of line */
417+  CL = getcap("clear"); /* clear screen */
418+  if (!*CL)
419+    cflag = 1;
420+  TI = getcap("smcup");  /* Initialization for CM */
421+  TE = getcap("rmcup");  /* end for CM */
422+  CM = getcap("cup");    /* cursor addressing */
423+  SR = getcap("ri");     /* scroll reverse */
424+  AL = getcap("il");     /* Insert line */
425+  SO = getcap("smso");   /* standout */
426+  SE = getcap("rmso");   /* standend */
427+  SG = getnumcap("xmc"); /* blanks left by attributes */
428+  if (SG < 0)
429+    SG = 0;
430+  US = getcap("smul");   /* underline */
431+  UE = getcap("rmul");   /* end underline */
432+  UG = getnumcap("xmc"); /* blanks left by attributes */
433+  if (UG < 0)
434+    UG = 0;
435+  UC = getcap("uc");    /* underline a character */
436+  mb = getcap("blink"); /* blinking attribute */
437+  MD = getcap("bold");  /* bold attribute */
438+  ME = getcap("sgr0");  /* turn off attributes */
439+  mh = getcap("dim");   /* half bright attribute */
440+  mr = getcap("rev");   /* reversed video attribute */
441+  if (!nflag) {
442+    /*
443+     * Recognize special strings
444+     */
445+    (void)addstring(SO, SG, &sppat);
446+    (void)addstring(SE, SG, &sppat);
447+    (void)addstring(US, UG, &sppat);
448+    (void)addstring(UE, UG, &sppat);
449+    (void)addstring(mb, 0, &sppat);
450+    (void)addstring(MD, 0, &sppat);
451+    (void)addstring(ME, 0, &sppat);
452+    (void)addstring(mh, 0, &sppat);
453+    (void)addstring(mr, 0, &sppat);
454+    if (*UC) {
455+      (void)strcpy(tempbuf, BC);
456+      (void)strcat(tempbuf, UC);
457+      (void)addstring(tempbuf, 0, &sppat);
458+    }
459+  }
460+  if (UG > 0 || uflag) {
461+    US = "";
462+    UE = "";
463+  }
464+  if (*US || uflag)
465+    UC = "";
466+  COLS = getnumcap("cols");  /* columns on page */
467+  i    = getnumcap("lines"); /* Lines on page */
468+  AM   = getflag("am");      /* terminal wraps automatically? */
469+  XN   = getflag("xenl");    /* and then ignores next newline? */
470+  DB   = getflag("db");      /* terminal retains lines below */
471+  HO   = getcap("home");
472+  if (!*HO && *CM) {
473+    HO = tiparm(CM, 0, 0); /* Another way of getting home */
474+  }
475+  if ((!*CE && !*AL) || !*HO || hardcopy) {
476+    cflag = stupid = 1;
477+  }
478+  if (*(s = getcap("ht"))) {
479+    /*
480+     * Tab (other than ^I or padding)
481+     */
482+    TA = s;
483+  }
484+  if (!*(ll = getcap("ll")) && *CM && i > 0) {
485+    /*
486+     * Lower left hand corner
487+     */
488+    BO = tiparm(CM, i - 1, 0);
489+  } else
490+    BO = ll;
491+  if (COLS <= 0 || COLS > 256) {
492+    if ((unsigned)COLS >= 65409) {
493+      /* SUN bug */
494+      COLS &= 0xffff;
495+      COLS -= (65409 - 128);
496+    }
497+    if (COLS <= 0 || COLS > 256)
498+      COLS = 80;
499+  }
500+  if (i <= 0) {
501+    i     = 24;
502+    cflag = stupid = 1;
503+  }
504+  LINES       = i;
505+  maxpagesize = i - 1;
506+  scrollsize  = maxpagesize / 2;
507+  if (scrollsize <= 0)
508+    scrollsize = 1;
509+  if (!pagesize || pagesize >= i) {
510+    pagesize = maxpagesize;
511+  }
512+
513+  /*
514+   * The next part does not really belong here, but there it is ...
515+   * Initialize a circular list for the screenlines.
516+   */
517+
518+  scr_info.tail = lp = _X;
519+  lp1                = lp + (100 - 1);
520+  for (; lp <= lp1; lp++) {
521+    /*
522+     * Circular doubly linked list
523+     */
524+    lp->next = lp + 1;
525+    lp->prev = lp - 1;
526+  }
527+  lp1->next       = scr_info.tail;
528+  lp1->next->prev = lp1;
529+  if (stupid) {
530+    BO = "\r\n";
531+  }
532+  putline(TI);
533+  window();
534 }
535 
536 /*
537@@ -361,28 +360,27 @@ ini_terminal()
538 void
539 mgoto(int n)
540 {
541-
542-	if (n == 0)
543-		home();
544-	else if (n == maxpagesize && *BO)
545-		bottom();
546-	else if (*CM) {
547-		/*
548-		 * Cursor addressing
549-		 */
550-		tputs(tiparm(CM, n, 0), 1, fputch);
551-	} else if (*BO && *UP && n >= (maxpagesize >> 1)) {
552-		/*
553-		 * Bottom and then up
554-		 */
555-		bottom();
556-		while (n++ < maxpagesize)
557-			putline(UP);
558-	} else { /* Home, and then down */
559-		home();
560-		while (n--)
561-			putline("\r\n");
562-	}
563+  if (n == 0)
564+    home();
565+  else if (n == maxpagesize && *BO)
566+    bottom();
567+  else if (*CM) {
568+    /*
569+     * Cursor addressing
570+     */
571+    tputs(tiparm(CM, n, 0), 1, fputch);
572+  } else if (*BO && *UP && n >= (maxpagesize >> 1)) {
573+    /*
574+     * Bottom and then up
575+     */
576+    bottom();
577+    while (n++ < maxpagesize)
578+      putline(UP);
579+  } else { /* Home, and then down */
580+    home();
581+    while (n--)
582+      putline("\r\n");
583+  }
584 }
585 
586 /*
587@@ -392,68 +390,65 @@ mgoto(int n)
588 void
589 clrbline()
590 {
591-
592-	if (stupid) {
593-		putline("\r\n");
594-		return;
595-	}
596-	bottom();
597-	if (*CE) {
598-		/*
599-		 * We can clear to end of line
600-		 */
601-		clrtoeol();
602-		return;
603-	}
604-	ins_line(maxpagesize);
605+  if (stupid) {
606+    putline("\r\n");
607+    return;
608+  }
609+  bottom();
610+  if (*CE) {
611+    /*
612+     * We can clear to end of line
613+     */
614+    clrtoeol();
615+    return;
616+  }
617+  ins_line(maxpagesize);
618 }
619 
620 void
621 ins_line(int l)
622 {
623-	tputs(tiparm(AL, l), maxpagesize - l, fputch);
624+  tputs(tiparm(AL, l), maxpagesize - l, fputch);
625 }
626 
627 void
628 home()
629 {
630-
631-	tputs(HO, 1, fputch);
632+  tputs(HO, 1, fputch);
633 }
634 
635 void
636 bottom()
637 {
638-
639-	tputs(BO, 1, fputch);
640-	if (!*BO)
641-		mgoto(maxpagesize);
642+  tputs(BO, 1, fputch);
643+  if (!*BO)
644+    mgoto(maxpagesize);
645 }
646 
647 int
648 window()
649 {
650 #ifdef TIOCGWINSZ
651-	if (ioctl(1, TIOCGWINSZ, &w) < 0)
652-		return 0;
653-
654-	if (w.ws_col == 0)
655-		w.ws_col = COLS;
656-	if (w.ws_row == 0)
657-		w.ws_row = LINES;
658-	if (w.ws_col != COLS || w.ws_row != LINES) {
659-		COLS = w.ws_col;
660-		LINES = w.ws_row;
661-		maxpagesize = LINES - 1;
662-		pagesize = maxpagesize;
663-		if (!*ll)
664-			BO = tiparm(CM, maxpagesize, 0);
665-		scr_info.currentpos = 0;
666-		scrollsize = maxpagesize / 2;
667-		if (scrollsize <= 0)
668-			scrollsize = 1;
669-		return 1;
670-	}
671+  if (ioctl(1, TIOCGWINSZ, &w) < 0)
672+    return 0;
673+
674+  if (w.ws_col == 0)
675+    w.ws_col = COLS;
676+  if (w.ws_row == 0)
677+    w.ws_row = LINES;
678+  if (w.ws_col != COLS || w.ws_row != LINES) {
679+    COLS        = w.ws_col;
680+    LINES       = w.ws_row;
681+    maxpagesize = LINES - 1;
682+    pagesize    = maxpagesize;
683+    if (!*ll)
684+      BO = tiparm(CM, maxpagesize, 0);
685+    scr_info.currentpos = 0;
686+    scrollsize          = maxpagesize / 2;
687+    if (scrollsize <= 0)
688+      scrollsize = 1;
689+    return 1;
690+  }
691 #endif
692-	return 0;
693+  return 0;
694 }
+4, -4
 1@@ -30,10 +30,10 @@ extern int AM;
 2 extern int XN;
 3 extern int DB;
 4 
 5-extern int erasech;
 6-extern int killch;
 7+extern int           erasech;
 8+extern int           killch;
 9 extern struct state *sppat;
10-extern char *BC;
11+extern char         *BC;
12 
13 void inittty(void);
14 void resettty(void);
15@@ -54,7 +54,7 @@ void mgoto(int n);
16 void clrbline(void);
17 void home(void);
18 void bottom(void);
19-int window(void);
20+int  window(void);
21 void ins_line(int l);
22 #define insert_line(l) ins_line(l)
23 
+11, -11
 1@@ -176,7 +176,7 @@ stream_getc(struct Stream *s)
 2     return (unsigned char)s->buf[s->idx++];
 3   }
 4   s->idx = 0;
 5-  r      = tls_read(s->ts, s->buf, sizeof(s->buf));
 6+  r      = tlss_read(s->ts, s->buf, sizeof(s->buf));
 7   if (r <= 0) {
 8     s->len = 0;
 9     return EOF;
10@@ -201,7 +201,7 @@ stream_read(struct Stream *s, void *ptr, size_t size)
11       total += n;
12     } else {
13       s->idx = 0;
14-      r      = tls_read(s->ts, s->buf, sizeof(s->buf));
15+      r      = tlss_read(s->ts, s->buf, sizeof(s->buf));
16       if (r <= 0) {
17         s->len = 0;
18         break;
19@@ -299,7 +299,7 @@ req_printf(struct TlsSocket *ts, const char *fmt, ...)
20   len = vsnprintf(buf, sizeof(buf), fmt, ap);
21   va_end(ap);
22   if (len > 0)
23-    tls_write(ts, buf, len);
24+    tlss_write(ts, buf, len);
25 }
26 
27 // ?man wget: retrieve files from the web
28@@ -469,7 +469,7 @@ main(int argc, char *argv[])
29     if (sock_fd < 0)
30       eprintf("failed to connect to %s:%s\n", host, port);
31 
32-    tls_sock = tls_connect(sock_fd, host, !no_check_certificate, is_tls);
33+    tls_sock = tlss_connect(sock_fd, host, !no_check_certificate, is_tls);
34     if (!tls_sock) {
35       close(sock_fd);
36       eprintf("failed to establish TLS connection with %s\n", host);
37@@ -512,12 +512,12 @@ main(int argc, char *argv[])
38     req_printf(tls_sock, "\r\n");
39 
40     if (post_data) {
41-      tls_write(tls_sock, post_data, strlen(post_data));
42+      tlss_write(tls_sock, post_data, strlen(post_data));
43     } else if (post_file) {
44       char    io_buf[8192];
45       ssize_t r;
46       while ((r = read(post_fd, io_buf, sizeof(io_buf))) > 0) {
47-        if (tls_write(tls_sock, io_buf, r) < 0) {
48+        if (tlss_write(tls_sock, io_buf, r) < 0) {
49           eprintf("failed to write post data:\n");
50         }
51       }
52@@ -530,7 +530,7 @@ main(int argc, char *argv[])
53     header_end = NULL;
54     memset(s.buf, 0, sizeof(s.buf));
55     while (total_read < sizeof(s.buf) - 1) {
56-      n = tls_read(tls_sock, s.buf + total_read, sizeof(s.buf) - 1 - total_read);
57+      n = tlss_read(tls_sock, s.buf + total_read, sizeof(s.buf) - 1 - total_read);
58       if (n <= 0) {
59         if (n < 0)
60           eprintf("read socket:\n");
61@@ -592,7 +592,7 @@ main(int argc, char *argv[])
62       free(loc);
63       free(url);
64       url = new_url;
65-      tls_close(tls_sock, 1);
66+      tlss_close(tls_sock, 1);
67       tls_sock = NULL;
68       redirects++;
69     } else if (status == 206) {
70@@ -605,7 +605,7 @@ main(int argc, char *argv[])
71             "file already fully retrieved or "
72             "range invalid\n"
73         );
74-      tls_close(tls_sock, 1);
75+      tlss_close(tls_sock, 1);
76       free(url);
77       free(host);
78       free(port);
79@@ -621,7 +621,7 @@ main(int argc, char *argv[])
80   }
81 
82   if (spider) {
83-    tls_close(tls_sock, 1);
84+    tlss_close(tls_sock, 1);
85     free(url);
86     return 0;
87   }
88@@ -652,7 +652,7 @@ main(int argc, char *argv[])
89   else
90     read_non_chunked(&s, out_fd, content_len);
91 
92-  tls_close(tls_sock, 1);
93+  tlss_close(tls_sock, 1);
94   if (out_fd != 1)
95     close(out_fd);
96   if (Oflag != out_name && Pflag)
+2, -6
 1@@ -41,7 +41,6 @@ static char *whilecode(Macro *, char *, char *);
 2 static char *ifcode(Macro *, char *, char *);
 3 static char *funcode(Macro *, char *, char *, char *);
 4 static char *param(char *, char *), *local(char *, char *);
 5-static Macro *define(char *, char *);
 6 static char *retcode(char *);
 7 static char *brkcode(void);
 8 static Macro *macro(int);
 9@@ -513,8 +512,6 @@ ifcode(Macro *d, char *cmp, char *body)
10 static char *
11 retcode(char *expr)
12 {
13-	char *s;
14-
15 	if (nested < 2 || macros[1].op != DEF)
16 		yyerror("return must be in a function");
17 	return code("%s %s %dQ", expr, estrdup(unwind), nested - 1);
18@@ -643,7 +640,6 @@ digits(char *bp)
19 static int
20 number(int ch)
21 {
22-	int d;
23 	char *bp;
24 
25 	ungetc(ch, filep);
26@@ -753,6 +749,7 @@ operand(int ch)
27 	case '!':
28 		if (getc(filep) == '=')
29 			return NE;
30+		/* fallthrough */
31 	default:
32 		yyerror("invalid operand");
33 		return 0;
34@@ -820,6 +817,7 @@ spawn(void)
35 	switch (fork()) {
36 	case -1:
37 		eprintf("forking dc:");
38+		/* fallthrough */
39 	case 0:
40 		close(1);
41 		dup(fds[1]);
42@@ -854,8 +852,6 @@ run(void)
43 static void
44 bc(char *fname)
45 {
46-	Macro *d;
47-
48 	lineno = 1;
49 	nested = 0;
50 
+1, -1
1@@ -534,7 +534,7 @@ repeat:
2     /* copy and strip trailing whitespace/newline so strcmp works */
3     strncpy(d, input->buf + 1, sizeof(d) - 1);
4     d[sizeof(d) - 1] = '\0';
5-    dl = strlen(d);
6+    dl               = strlen(d);
7     while (dl > 0 && isspace((unsigned char)d[dl - 1]))
8       d[--dl] = '\0';
9     if (strncmp(d, "include", 7) == 0 && isblank(d[7])) {
+127, -134
  1@@ -11,7 +11,7 @@
  2 #include <unistd.h>
  3 
  4 enum {
  5-  COMMENT_C,       /* line // and block /* */
  6+  COMMENT_C,       /* line // and block comments */
  7   COMMENT_HASH,    /* line # only */
  8   COMMENT_PERCENT, /* line % only */
  9   COMMENT_SEMI,    /* line ; only */
 10@@ -61,9 +61,9 @@ struct CommentSpec {
 11 
 12 static const struct CommentSpec comment_specs[] = {
 13     [COMMENT_C]       = {"//", "/*", "*/"},
 14-    [COMMENT_HASH]    = {"#",  NULL, NULL},
 15-    [COMMENT_PERCENT] = {"%",  NULL, NULL},
 16-    [COMMENT_SEMI]    = {";",  NULL, NULL},
 17+    [COMMENT_HASH]    = {"#", NULL, NULL},
 18+    [COMMENT_PERCENT] = {"%", NULL, NULL},
 19+    [COMMENT_SEMI]    = {";", NULL, NULL},
 20     [COMMENT_DASH]    = {"--", NULL, NULL},
 21     [COMMENT_HASKELL] = {"--", "{-", "-}"},
 22     [COMMENT_PAREN]   = {NULL, "(*", "*)"},
 23@@ -77,35 +77,35 @@ struct LangDef {
 24 };
 25 
 26 static const struct LangDef lang_defs[LANG_COUNT] = {
 27-    [LANG_C]       = {"C",       1,    COMMENT_C      },
 28-    [LANG_CPP]     = {"C++",     300,  COMMENT_C      },
 29-    [LANG_SH]      = {"Shell",   6,    COMMENT_HASH   },
 30-    [LANG_AWK]     = {"Awk",     6,    COMMENT_HASH   },
 31-    [LANG_MAKE]    = {"Make",    10,    COMMENT_HASH   },
 32-    [LANG_M4]      = {"M4",      25,   COMMENT_HASH   },
 33-    [LANG_LUA]     = {"Lua",     25,   COMMENT_DASH   },
 34-    [LANG_PERL]    = {"Perl",    500,  COMMENT_HASH   },
 35-    [LANG_PYTHON]  = {"Python",  80,   COMMENT_HASH   },
 36-    [LANG_RUBY]    = {"Ruby",    90,   COMMENT_HASH   },
 37-    [LANG_PHP]     = {"PHP",     110,  COMMENT_C      },
 38-    [LANG_JS]      = {"JS",      100,  COMMENT_C      },
 39-    [LANG_TS]      = {"TS",      140,  COMMENT_C      },
 40-    [LANG_JAVA]    = {"Java",    150,  COMMENT_C      },
 41-    [LANG_KOTLIN]  = {"Kotlin",  160,  COMMENT_C      },
 42-    [LANG_SCALA]   = {"Scala",   180,  COMMENT_C      },
 43-    [LANG_CS]      = {"C#",      140,  COMMENT_C      },
 44-    [LANG_GO]      = {"Go",      3,   COMMENT_C      },
 45-    [LANG_SWIFT]   = {"Swift",   70,   COMMENT_C      },
 46-    [LANG_ZIG]     = {"Zig",     65,   COMMENT_C      },
 47-    [LANG_DART]    = {"Dart",    55,   COMMENT_C      },
 48-    [LANG_ELIXIR]  = {"Elixir",  50,   COMMENT_HASH   },
 49-    [LANG_ERLANG]  = {"Erlang",  55,   COMMENT_PERCENT},
 50-    [LANG_HASKELL] = {"Haskell", 200,  COMMENT_HASKELL},
 51-    [LANG_OCAML]   = {"OCaml",   45,   COMMENT_PAREN  },
 52-    [LANG_CLOJURE] = {"Clojure", 85,   COMMENT_SEMI   },
 53-    [LANG_RUST]    = {"Rust",    3000, COMMENT_C      },
 54-    [LANG_ADA]     = {"Ada",     15,   COMMENT_DASH   },
 55-    [LANG_R]       = {"R",       40,   COMMENT_HASH   },
 56+    [LANG_C]       = {"C", 1, COMMENT_C},
 57+    [LANG_CPP]     = {"C++", 300, COMMENT_C},
 58+    [LANG_SH]      = {"Shell", 6, COMMENT_HASH},
 59+    [LANG_AWK]     = {"Awk", 6, COMMENT_HASH},
 60+    [LANG_MAKE]    = {"Make", 10, COMMENT_HASH},
 61+    [LANG_M4]      = {"M4", 25, COMMENT_HASH},
 62+    [LANG_LUA]     = {"Lua", 25, COMMENT_DASH},
 63+    [LANG_PERL]    = {"Perl", 500, COMMENT_HASH},
 64+    [LANG_PYTHON]  = {"Python", 80, COMMENT_HASH},
 65+    [LANG_RUBY]    = {"Ruby", 90, COMMENT_HASH},
 66+    [LANG_PHP]     = {"PHP", 110, COMMENT_C},
 67+    [LANG_JS]      = {"JS", 100, COMMENT_C},
 68+    [LANG_TS]      = {"TS", 140, COMMENT_C},
 69+    [LANG_JAVA]    = {"Java", 150, COMMENT_C},
 70+    [LANG_KOTLIN]  = {"Kotlin", 160, COMMENT_C},
 71+    [LANG_SCALA]   = {"Scala", 180, COMMENT_C},
 72+    [LANG_CS]      = {"C#", 140, COMMENT_C},
 73+    [LANG_GO]      = {"Go", 3, COMMENT_C},
 74+    [LANG_SWIFT]   = {"Swift", 70, COMMENT_C},
 75+    [LANG_ZIG]     = {"Zig", 65, COMMENT_C},
 76+    [LANG_DART]    = {"Dart", 55, COMMENT_C},
 77+    [LANG_ELIXIR]  = {"Elixir", 50, COMMENT_HASH},
 78+    [LANG_ERLANG]  = {"Erlang", 55, COMMENT_PERCENT},
 79+    [LANG_HASKELL] = {"Haskell", 200, COMMENT_HASKELL},
 80+    [LANG_OCAML]   = {"OCaml", 45, COMMENT_PAREN},
 81+    [LANG_CLOJURE] = {"Clojure", 85, COMMENT_SEMI},
 82+    [LANG_RUST]    = {"Rust", 3000, COMMENT_C},
 83+    [LANG_ADA]     = {"Ada", 15, COMMENT_DASH},
 84+    [LANG_R]       = {"R", 40, COMMENT_HASH},
 85 };
 86 
 87 struct ExtMap {
 88@@ -114,51 +114,18 @@ struct ExtMap {
 89 };
 90 
 91 static const struct ExtMap ext_map[] = {
 92-    {".c",     LANG_C      },
 93-    {".cc",    LANG_CPP    },
 94-    {".cpp",   LANG_CPP    },
 95-    {".cxx",   LANG_CPP    },
 96-    {".hpp",   LANG_CPP    },
 97-    {".sh",    LANG_SH     },
 98-    {".awk",   LANG_AWK    },
 99-    {".mk",    LANG_MAKE   },
100-    {".m4",    LANG_M4     },
101-    {".lua",   LANG_LUA    },
102-    {".pl",    LANG_PERL   },
103-    {".pm",    LANG_PERL   },
104-    {".py",    LANG_PYTHON },
105-    {".pyw",   LANG_PYTHON },
106-    {".rb",    LANG_RUBY   },
107-    {".php",   LANG_PHP    },
108-    {".js",    LANG_JS     },
109-    {".mjs",   LANG_JS     },
110-    {".cjs",   LANG_JS     },
111-    {".ts",    LANG_TS     },
112-    {".tsx",   LANG_TS     },
113-    {".java",  LANG_JAVA   },
114-    {".kt",    LANG_KOTLIN },
115-    {".kts",   LANG_KOTLIN },
116-    {".scala", LANG_SCALA  },
117-    {".cs",    LANG_CS     },
118-    {".go",    LANG_GO     },
119-    {".swift", LANG_SWIFT  },
120-    {".zig",   LANG_ZIG    },
121-    {".dart",  LANG_DART   },
122-    {".ex",    LANG_ELIXIR },
123-    {".exs",   LANG_ELIXIR },
124-    {".erl",   LANG_ERLANG },
125-    {".hrl",   LANG_ERLANG },
126-    {".hs",    LANG_HASKELL},
127-    {".lhs",   LANG_HASKELL},
128-    {".ml",    LANG_OCAML  },
129-    {".mli",   LANG_OCAML  },
130-    {".clj",   LANG_CLOJURE},
131-    {".cljs",  LANG_CLOJURE},
132-    {".rs",    LANG_RUST   },
133-    {".adb",   LANG_ADA    },
134-    {".ads",   LANG_ADA    },
135-    {".r",     LANG_R      },
136-    {".R",     LANG_R      },
137+    {".c", LANG_C},         {".cc", LANG_CPP},     {".cpp", LANG_CPP},     {".cxx", LANG_CPP},
138+    {".hpp", LANG_CPP},     {".sh", LANG_SH},      {".awk", LANG_AWK},     {".mk", LANG_MAKE},
139+    {".m4", LANG_M4},       {".lua", LANG_LUA},    {".pl", LANG_PERL},     {".pm", LANG_PERL},
140+    {".py", LANG_PYTHON},   {".pyw", LANG_PYTHON}, {".rb", LANG_RUBY},     {".php", LANG_PHP},
141+    {".js", LANG_JS},       {".mjs", LANG_JS},     {".cjs", LANG_JS},      {".ts", LANG_TS},
142+    {".tsx", LANG_TS},      {".java", LANG_JAVA},  {".kt", LANG_KOTLIN},   {".kts", LANG_KOTLIN},
143+    {".scala", LANG_SCALA}, {".cs", LANG_CS},      {".go", LANG_GO},       {".swift", LANG_SWIFT},
144+    {".zig", LANG_ZIG},     {".dart", LANG_DART},  {".ex", LANG_ELIXIR},   {".exs", LANG_ELIXIR},
145+    {".erl", LANG_ERLANG},  {".hrl", LANG_ERLANG}, {".hs", LANG_HASKELL},  {".lhs", LANG_HASKELL},
146+    {".ml", LANG_OCAML},    {".mli", LANG_OCAML},  {".clj", LANG_CLOJURE}, {".cljs", LANG_CLOJURE},
147+    {".rs", LANG_RUST},     {".adb", LANG_ADA},    {".ads", LANG_ADA},     {".r", LANG_R},
148+    {".R", LANG_R},
149 };
150 
151 struct NameMap {
152@@ -167,24 +134,37 @@ struct NameMap {
153 };
154 
155 static const struct NameMap name_map[] = {
156-    {"Makefile",       LANG_MAKE},
157-    {"GNUmakefile",    LANG_MAKE},
158-    {".profile",       LANG_SH  },
159-    {"profile",        LANG_SH  },
160-    {".bashrc",        LANG_SH  },
161-    {".bash_profile",  LANG_SH  },
162-    {".shrc",          LANG_SH  },
163-    {".kshrc",         LANG_SH  },
164-    {".zshrc",         LANG_SH  },
165-    {".cshrc",         LANG_SH  },
166-    {".login",         LANG_SH  },
167+    {"Makefile", LANG_MAKE},
168+    {"GNUmakefile", LANG_MAKE},
169+    {".profile", LANG_SH},
170+    {"profile", LANG_SH},
171+    {".bashrc", LANG_SH},
172+    {".bash_profile", LANG_SH},
173+    {".shrc", LANG_SH},
174+    {".kshrc", LANG_SH},
175+    {".zshrc", LANG_SH},
176+    {".cshrc", LANG_SH},
177+    {".login", LANG_SH},
178 };
179 
180 /* not scanned for lines, but still checked against markers below */
181 static const char *const skip_dirs[] = {
182-    ".git", ".hg", ".svn", "node_modules", "vendor", "__pycache__",
183-    ".venv", "venv", "target", "build", "dist", ".cache",
184-    ".next", ".idea", ".vscode", NULL,
185+    ".git",
186+    ".hg",
187+    ".svn",
188+    "node_modules",
189+    "vendor",
190+    "__pycache__",
191+    ".venv",
192+    "venv",
193+    "target",
194+    "build",
195+    "dist",
196+    ".cache",
197+    ".next",
198+    ".idea",
199+    ".vscode",
200+    NULL,
201 };
202 
203 struct Marker {
204@@ -195,14 +175,14 @@ struct Marker {
205 };
206 
207 static const struct Marker markers[] = {
208-    {"node_modules",   1, 150.0, "skipping bullshit / malware"                          },
209-    {"Cargo.toml",     0, 80.0,  "I challenge you to bootstrapping this shitty lang"    },
210-    {"package.json",   0, 60.0,  "js. Self-explanatory"                                 },
211-    {"go.mod",         0, 20.0,  "Not C. But still good. Minor penalty"                 },
212-    {"Dockerfile",     0, 20.0,  "containerization crutch"                              },
213-    {"Gemfile",        0, 55.0,  "shitty language baseline"                             },
214-    {"CMakeLists.txt", 0, 55.0,  "shitty build system"                                  },
215-    {"tsconfig.json",  0, 60.0,  "a language with a configuration file. Degenerate."    },
216+    {"node_modules", 1, 150.0, "skipping bullshit / malware"},
217+    {"Cargo.toml", 0, 80.0, "I challenge you to bootstrapping this shitty lang"},
218+    {"package.json", 0, 60.0, "js. Self-explanatory"},
219+    {"go.mod", 0, 20.0, "Not C. But still good. Minor penalty"},
220+    {"Dockerfile", 0, 20.0, "containerization crutch"},
221+    {"Gemfile", 0, 55.0, "shitty language baseline"},
222+    {"CMakeLists.txt", 0, 55.0, "shitty build system"},
223+    {"tsconfig.json", 0, 60.0, "a language with a configuration file. Degenerate."},
224 };
225 
226 struct ComboPenalty {
227@@ -214,9 +194,9 @@ struct ComboPenalty {
228 
229 static const struct ComboPenalty combos[] = {
230     {LANG_RUST, LANG_CPP, 4000.0, "MAXIMUM BOGUSNESS, rust and c++ sharing a tree"},
231-    {LANG_RUST, LANG_C,   400.0,  "comical bogusness, rust apologizing to the c it links against"},
232-    {LANG_JS,   LANG_TS,  150.0,  "half the codebase does not trust the other half"},
233-    {LANG_C,    LANG_CPP, 120.0,  "abi boundary between two compilers of the same language"},
234+    {LANG_RUST, LANG_C, 400.0, "comical bogusness, rust apologizing to the c it links against"},
235+    {LANG_JS, LANG_TS, 150.0, "half the codebase does not trust the other half"},
236+    {LANG_C, LANG_CPP, 120.0, "abi boundary between two compilers of the same language"},
237 };
238 
239 struct LangStat {
240@@ -314,10 +294,10 @@ static void
241 scan_file(int dirfd, const char *name, int lang, struct LangStat *lp)
242 {
243   const struct CommentSpec *cs;
244-  char                       buf[8192];
245-  char                      *p, *bufend;
246-  ssize_t                    nread;
247-  int fd, in_block, leading_ws, checked, line_has_content, line_is_comment;
248+  char                      buf[8192];
249+  char                     *p, *bufend;
250+  ssize_t                   nread;
251+  int                       fd, in_block, leading_ws, checked, line_has_content, line_is_comment;
252 
253   fd = openat(dirfd, name, O_RDONLY);
254   if (fd < 0)
255@@ -388,7 +368,7 @@ static void
256 scan(int dirfd, const char *name, struct stat *st, void *data, struct recursor *r)
257 {
258   struct ScanState *scanst = data;
259-  int                lang;
260+  int               lang;
261 
262   check_marker(name, S_ISDIR(st->st_mode), scanst);
263 
264@@ -431,9 +411,14 @@ bogometercmd(int argc, char **argv)
265   for (i = 0; i < LANG_COUNT; i++) {
266     if (st.stats[i].files == 0)
267       continue;
268-    printf("%-10s %10ld %10ld %10ld %10ld\n",
269-        lang_defs[i].name, st.stats[i].files, st.stats[i].blank, st.stats[i].comment,
270-        st.stats[i].code);
271+    printf(
272+        "%-10s %10ld %10ld %10ld %10ld\n",
273+        lang_defs[i].name,
274+        st.stats[i].files,
275+        st.stats[i].blank,
276+        st.stats[i].comment,
277+        st.stats[i].code
278+    );
279     total_code += st.stats[i].code;
280   }
281 
282@@ -443,41 +428,49 @@ bogometercmd(int argc, char **argv)
283   }
284 
285   printf("---------------------------------------------------------\n");
286-    modern_langs = 0;
287-    for (i = 0; i < LANG_COUNT; i++) {
288-      if (st.stats[i].code == 0)
289-        continue;
290-      pct = ((double)st.stats[i].code / total_code) * 100.0;
291-      score += pct * lang_defs[i].weight;
292-      printf("Distribution: %-6s is %5.2f%% of targeted language lines\n", lang_defs[i].name, pct);
293-      if (!is_classic(i))
294-        modern_langs++;
295-    }
296+  modern_langs = 0;
297+  for (i = 0; i < LANG_COUNT; i++) {
298+    if (st.stats[i].code == 0)
299+      continue;
300+    pct = ((double)st.stats[i].code / total_code) * 100.0;
301+    score += pct * lang_defs[i].weight;
302+    printf("Distribution: %-6s is %5.2f%% of targeted language lines\n", lang_defs[i].name, pct);
303+    if (!is_classic(i))
304+      modern_langs++;
305+  }
306 
307-    if (modern_langs >= BABEL_THRESHOLD) {
308+  if (modern_langs >= BABEL_THRESHOLD) {
309     score *= BABEL_MULT;
310-    fprintf(stderr,
311-        "note: %d languages in one tree: babel tower, no two files agree on what tongue they speak\n",
312-        modern_langs);
313+    fprintf(
314+        stderr,
315+        "note: %d languages in one tree: babel tower, no two files agree on what tongue they "
316+        "speak\n",
317+        modern_langs
318+    );
319   }
320 
321   fflush(stdout);
322-    for (i = 0; i < (int)LEN(combos); i++) {
323-      if (st.stats[combos[i].lang_a].code > 0 && st.stats[combos[i].lang_b].code > 0) {
324-        score += combos[i].penalty;
325-        fprintf(stderr, "note: %s + %s: %s\n", lang_defs[combos[i].lang_a].name,
326-            lang_defs[combos[i].lang_b].name, combos[i].remark);
327-        fflush(stderr);
328-      }
329+  for (i = 0; i < (int)LEN(combos); i++) {
330+    if (st.stats[combos[i].lang_a].code > 0 && st.stats[combos[i].lang_b].code > 0) {
331+      score += combos[i].penalty;
332+      fprintf(
333+          stderr,
334+          "note: %s + %s: %s\n",
335+          lang_defs[combos[i].lang_a].name,
336+          lang_defs[combos[i].lang_b].name,
337+          combos[i].remark
338+      );
339+      fflush(stderr);
340     }
341+  }
342 
343   if (st.stats[LANG_RUST].code > 0 && st.stats[LANG_CPP].code == 0 && st.stats[LANG_C].code == 0)
344     fprintf(stderr, "note: rust: enormous magnitudes of bogus\n");
345 
346   score += st.bonus;
347 
348-  if (modern_langs == 0 && st.stats[LANG_C].code > 0 && st.stats[LANG_SH].code > 0 &&
349-      st.stats[LANG_AWK].code > 0)
350+  if (modern_langs == 0 && st.stats[LANG_C].code > 0 && st.stats[LANG_SH].code > 0
351+      && st.stats[LANG_AWK].code > 0)
352     printf("note: sh + awk + c only: peak codebase\n");
353 
354   printf("---------------------------------------------------------\n");
+82, -79
  1@@ -1,6 +1,6 @@
  2 ; genconfig.sh config produces four files from build.cfg:
  3-; config.set (read by ninqu), config.kv (sourced by genbox.sh),
  4-; nofork_list.h (included by wexec.c), and features.h (-include'd
  5+; config.set (read by ninqu), config.kv (read by mkman),
  6+; nofork_list.h (included by wexec.c), and features.h (-included
  7 ; into every compile). each gets its own rule so ninqu can find a
  8 ; producer for any of them
  9 ;
 10@@ -75,21 +75,21 @@
 11   (diff "-lm")
 12   (wget $(LDLIBS_TLS)))
 13 
 14-; Every .c file in a category builds into its own binary. PERFILE captures
 15-; that shared rule. Only EXTRA_AFTER differs cuz POSIX waits for GETCONF_H
 16-; the rest pass "". cmd/posix/bc.c overrides this with its own yacc-based
 17-; rule, so no need for PERFILE to have that as a special case
 18+; Every .c file in a category builds into its own binary. (PERFILE)
 19+; Only EXTRA_AFTER differs cuz POSIX waits for GETCONF_H, the rest pass "".
 20+; cmd/posix/bc.c overrides this with its own yacc-based rule, so no need for
 21+; PERFILE to have that as a special case
 22 ;
 23 (template PERFILE (NAME CATEGORY DESC EXTRA_AFTER)
 24   (rule $(NAME)
 25     (glob "cmd/$(CATEGORY)/*.c")
 26     (gate build_$(CATEGORY)_$(IDENT))
 27-    (dep $(MATCH))
 28-    (after LIBUTIL LIBUTF $(EXTRA_AFTER))
 29+    (dep $(MATCH) LIBUTIL LIBUTF)
 30+    (after $(EXTRA_AFTER))
 31     (out $(STEM))
 32     (description $(DESC))
 33     (feature perfile)
 34-    (exec $(CC) $(CPPFLAGS) $(CFLAGS) -o $(OUT) $(MATCH) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS) $(EXTRA_LIBS:$(BASESTEM)))))
 35+    (exec $(CC) $(CPPFLAGS) $(CFLAGS) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) $(EXTRA_LIBS:$(BASESTEM)))))
 36 
 37 (use PERFILE POSIX_BIN posix "one POSIX2024 utility per source file under cmd/posix" GETCONF_H)
 38 (use PERFILE LINUX_BIN linux "Linux-only utility, one source file per binary under cmd/linux" "")
 39@@ -106,8 +106,8 @@
 40 (group extra lib EXTRA_BIN EXTRA_YAP)
 41 
 42 ; codegen: generate sources consumed by the build rules below. Ungated
 43-; generators always run; conditional ones use (req) so they only run
 44-; when their inputs exist in this checkout
 45+; ones always run. conditional ones use (req) so they only run when
 46+; their inputs exists in this checkout
 47 ;
 48 (rule GETCONF_H
 49   (gate build_posix_getconf)
 50@@ -158,10 +158,9 @@
 51 (rule POSIX_BC
 52   (gate build_posix_bc)
 53   (member posix bc)
 54-  (dep POSIX_BC_OBJ)
 55-  (after LIBUTIL LIBUTF)
 56+  (dep POSIX_BC_OBJ LIBUTIL LIBUTF)
 57   (out "cmd/posix/bc")
 58-  (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS) -lm))
 59+  (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) -lm))
 60 
 61 (rule POSIX_AWK_OBJ
 62   (glob "cmd/posix/awk/*.c")
 63@@ -175,10 +174,9 @@
 64 (rule POSIX_AWK
 65   (gate build_posix_awk)
 66   (member posix awk)
 67-  (dep POSIX_AWK_OBJ)
 68-  (after LIBUTIL LIBUTF)
 69+  (dep POSIX_AWK_OBJ LIBUTIL LIBUTF)
 70   (out "cmd/posix/awk/awk")
 71-  (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS) -lm))
 72+  (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) -lm))
 73 
 74 (rule POSIX_SH_OBJ
 75   (glob "cmd/posix/sh/*.c")
 76@@ -192,10 +190,9 @@
 77 (rule POSIX_SH
 78   (gate build_posix_sh)
 79   (member posix sh)
 80-  (dep POSIX_SH_OBJ)
 81-  (after LIBUTIL LIBUTF LIBREDLINE)
 82+  (dep POSIX_SH_OBJ LIBUTIL LIBUTF LIBREDLINE)
 83   (out "cmd/posix/sh/sh")
 84-  (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a shared/libredline/libredline.a $(LDFLAGS) $(LDLIBS)))
 85+  (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS)))
 86 
 87 (rule POSIX_MAKE_OBJ
 88   (glob "cmd/posix/make/*.c")
 89@@ -207,10 +204,9 @@
 90 (rule POSIX_MAKE
 91   (gate build_posix_make)
 92   (member posix make)
 93-  (dep POSIX_MAKE_OBJ)
 94-  (after LIBUTIL LIBUTF)
 95+  (dep POSIX_MAKE_OBJ LIBUTIL LIBUTF)
 96   (out "cmd/posix/make/make")
 97-  (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS)))
 98+  (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS)))
 99 
100 (rule EXTRA_YAP_OBJ
101   (glob "cmd/extra/yap/*.c")
102@@ -222,10 +218,9 @@
103 (rule EXTRA_YAP
104   (gate build_extra_yap)
105   (member extra yap)
106-  (dep EXTRA_YAP_OBJ)
107-  (after LIBUTIL LIBUTF)
108+  (dep EXTRA_YAP_OBJ LIBUTIL LIBUTF)
109   (out "cmd/extra/yap/yap")
110-  (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS) -ltinfo))
111+  (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) -ltinfo))
112 
113 ; (member GROUP ALIAS) gives a rule a qualified user-facing name
114 ; (e.g. posix/bc) while keeping its internal name (POSIX_BC) for deps,
115@@ -245,10 +240,9 @@
116 
117 (rule AR
118   (gate build_dev_ar)
119-  (dep AR_OBJ)
120-  (after LIBUTIL LIBUTF)
121+  (dep AR_OBJ LIBUTIL LIBUTF)
122   (out "cmd/dev/ar/ar")
123-  (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS)))
124+  (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS)))
125 
126 (rule XCUTIL_OBJ
127   (glob "cmd/dev/xcutil/*.c")
128@@ -266,10 +260,10 @@
129 
130 (rule AS
131   (gate build_dev_cc)
132-  (dep AS_OBJ)
133-  (after XCUTIL_OBJ LIBUTIL LIBUTF)
134+  (dep AS_OBJ LIBUTIL LIBUTF)
135+  (after XCUTIL_OBJ)
136   (out "cmd/dev/as/as")
137-  (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS)))
138+  (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS)))
139 
140 (rule LD_OBJ
141   (glob "cmd/dev/ld/*.c")
142@@ -280,13 +274,13 @@
143 
144 (rule LD
145   (gate build_dev_ld)
146-  (dep LD_OBJ)
147-  (after XCUTIL_OBJ LIBUTIL LIBUTF)
148+  (dep LD_OBJ LIBUTIL LIBUTF)
149+  (after XCUTIL_OBJ)
150   (out "cmd/dev/ld/ld")
151-  (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS)))
152+  (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS)))
153 
154 ; CCPOOL_OBJ globs the whole directory. The entry points below use
155-; literal globs, so the override mechanism excludes them automatically
156+; literal globs, so the override excludes them automatically
157 (rule CCPOOL_OBJ
158   (glob "cmd/dev/cc/*.c")
159   (gate build_dev_cc)
160@@ -303,10 +297,9 @@
161 
162 (rule CC1
163   (gate build_dev_cc)
164-  (dep CC1_OBJ CCPOOL_OBJ)
165-  (after LIBUTIL LIBUTF)
166+  (dep CC1_OBJ CCPOOL_OBJ LIBUTIL LIBUTF)
167   (out "cmd/dev/cc/cc1")
168-  (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS)))
169+  (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS)))
170 
171 (rule CPP_OBJ
172   (glob "cmd/dev/cc/cpp.c")
173@@ -317,10 +310,9 @@
174 
175 (rule CPP
176   (gate build_dev_cc)
177-  (dep CPP_OBJ CCPOOL_OBJ)
178-  (after LIBUTIL LIBUTF)
179+  (dep CPP_OBJ CCPOOL_OBJ LIBUTIL LIBUTF)
180   (out "cmd/dev/cc/cpp")
181-  (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS)))
182+  (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS)))
183 
184 (rule CCDRV_OBJ
185   (glob "cmd/dev/cc/driver.c" "cmd/dev/cc/util.c")
186@@ -331,16 +323,10 @@
187 
188 (rule CCDRV
189   (gate build_dev_cc)
190-  (dep CCDRV_OBJ)
191-  (after LIBUTIL LIBUTF)
192+  (dep CCDRV_OBJ LIBUTIL LIBUTF)
193   (out "cmd/dev/cc/cc")
194-  (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS)))
195+  (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS)))
196 
197-; ninqu itself lives at cmd/dev/ninqu/ninqu and is built by the
198-; Makefile directly, since it has to exist before this file can be
199-; parsed. a rule here producing the same path would just race that
200-; bootstrap compile, so only the box variant below belongs to ninqu
201-;
202 ; Like BOX_OBJ: rename main and hide other globals so ninqu can link
203 ; into aruu-box. It is still not reentrant, so it stays out of
204 ; NOFORK_LIST
205@@ -361,6 +347,7 @@
206 ;
207 (rule MKMAN
208   (dir "scripts/mkman")
209+  (gate build_man)
210   (dep "glob:scripts/mkman/*.go")
211   (out "scripts/mkman/mkman")
212   (exec go build -o mkman .))
213@@ -368,6 +355,7 @@
214 (rule MAN_MDOC
215   (glob "cmd/**/*.c")
216   (mark "?man")
217+  (gate build_man)
218   (dep (after MKMAN))
219   (out "man/man$(SEC_OF:$(DIR))/$(BASESTEM).$(SEC_OF:$(DIR))")
220   (exec scripts/mkman/mkman -fmt mdoc -config scripts/mk/config.kv -src $(MATCH))
221@@ -376,6 +364,7 @@
222 (rule MAN_TXT
223   (glob "cmd/**/*.c")
224   (mark "?man")
225+  (gate build_man)
226   (dep (after MKMAN))
227   (out "man/man$(SEC_OF:$(DIR))/$(BASESTEM).$(SEC_OF:$(DIR)).txt")
228   (exec scripts/mkman/mkman -fmt txt -config scripts/mk/config.kv -src $(MATCH))
229@@ -418,6 +407,7 @@
230     printf '  CLEAN misc\n'
231     rm -rf man/man1 man/man8
232     rm -rf aruu-box .box
233+    rm -rf .ninja_log .ninja_deps
234 
235     printf '  CLEAN done\n'
236   "))
237@@ -468,16 +458,38 @@
238 (group remove REMOVE)
239 (group uninstall REMOVE)
240 
241-; box: the multi-call binary containing every enabled tool in a single executable
242-; with a dispatch table. This includes multi-file tools like POSIX_BC, POSIX_AWK,
243-; POSIX_SH, POSIX_MAKE, and EXTRA_YAP. A single-file tool has its main function
244-; renamed directly by BOX_OBJ. The multi-file tools use a partial link (ld -r)
245-; in their respective rules to combine their objects before renaming main,
246-; preventing helper symbols from colliding. This replaces scripts/mkbox
247+(rule FMT
248+  (phony)
249+  (shell "
250+    printf '  FMT cmd and shared (skipping dir tools)\n'
251+    find cmd shared -type f \( -name '*.c' -o -name '*.h' \) \
252+      ! -path 'cmd/posix/awk/*' \
253+      ! -path 'cmd/posix/sh/*' \
254+      ! -path 'cmd/posix/make/*' \
255+      ! -path 'cmd/extra/yap/*' \
256+      ! -path 'cmd/posix/bc.c' \
257+      -print | xargs -r clang-format -i
258+  "))
259+
260+(rule FMT_ALL
261+  (phony)
262+  (shell "
263+    printf '  FMT cmd and shared (including dir tools)\n'
264+    find cmd shared -type f \( -name '*.c' -o -name '*.h' \) -print \
265+      | xargs -r clang-format -i
266+  "))
267+
268+(group fmt FMT)
269+(group fmt-all FMT_ALL)
270+
271+; box: one executable containing every enabled tool, dispatched through
272+; a table. a single-file tool just gets its main renamed by BOX_OBJ.
273+; multi-file tools (POSIX_BC, POSIX_AWK, POSIX_SH, POSIX_MAKE, EXTRA_YAP)
274+; go through a partial link (ld -r) first, merging their objects into
275+; one before main gets renamed and helper symbols hidden. replaces
276+; scripts/mkbox
277 ;
278-; Object files are stored under .box/ to mirror the cmd/ layout and prevent
279-; collisions with standalone objects. Since standalone and box objects use
280-; different symbol names, they cannot share a path
281+; object files live under .box/, mirroring the cmd/ layout
282 ;
283 ; Ninqu determines which tools enter the box using the gate on BOX_OBJ.
284 ; BOX_DISPATCH reads the object paths passed on argv rather than consulting
285@@ -506,9 +518,9 @@
286 ; genbox.sh only receives paths via argv
287 ;
288 
289-; The match directory determines the gate and output path, allowing one rule
290-; to handle six categories. The multi-file tool bc.c inside cmd/posix is
291-; automatically excluded via the literal-glob override mechanism
292+; the match directory picks the gate and output path, so one rule covers
293+; all six categories. bc.c inside cmd/posix is excluded automatically by
294+; the literal-glob override mechanism
295 ;
296 (rule BOX_OBJ
297   (glob "cmd/posix/*.c" "cmd/linux/*.c" "cmd/net/*.c" "cmd/pseudo/*.c"
298@@ -521,11 +533,10 @@
299   (shell "$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(OUT) $(MATCH) && sym=`echo $(BASESTEM) | tr '.-' '__'`_main && $(OBJCOPY) --redefine-sym main=$sym $(OUT) && $(OBJCOPY) --keep-global-symbol=$sym $(OUT)")
300   (group box))
301 
302-; Multi-file tools like POSIX_BC, POSIX_AWK, POSIX_SH, POSIX_MAKE, and
303-; EXTRA_YAP cannot use the single-file objcopy step because their global helper
304-; symbols would collide when linked into a single binary. Combining these
305-; objects first with a partial link (ld -r) resolves internal references, making
306-; it safe to isolate the renamed main function and hide remaining symbols
307+; POSIX_BC, POSIX_AWK, POSIX_SH, POSIX_MAKE, and EXTRA_YAP cant go through
308+; the single-file objcopy step, their global helper symbols would collide
309+; once linked into one binary. a partial link (ld -r) resolves those
310+; internal references first, then main gets renamed and the rest hidden
311 ;
312 ; Combined objects use the layout .box/cmd/<category>/<tool>.o so genbox.sh
313 ; can parse them without structural modifications
314@@ -630,12 +641,10 @@
315 ; based on whether yap is enabled
316 ;
317 (rule BOX
318-  (dep BOX_DISPATCH BOX_OBJ POSIX_BC_BOX POSIX_AWK_BOX POSIX_SH_BOX POSIX_MAKE_BOX EXTRA_YAP_BOX NINQU_BOX_OBJ)
319-  (after LIBUTIL LIBUTF LIBREDLINE)
320+  (dep BOX_DISPATCH BOX_OBJ POSIX_BC_BOX POSIX_AWK_BOX POSIX_SH_BOX POSIX_MAKE_BOX EXTRA_YAP_BOX NINQU_BOX_OBJ LIBUTIL LIBUTF LIBREDLINE)
321   (out "aruu-box")
322   (description "single multi-call binary, one dispatch table for every enabled tool")
323-;  (shell "$(CC) $(CPPFLAGS) $(CFLAGS) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a shared/libredline/libredline.a $(LDFLAGS) $(LDLIBS) -lm $(BOX_EXTRA_LIBS)")
324-  (shell "$(CC) $(CPPFLAGS) $(CFLAGS) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a shared/libredline/libredline.a $(LDFLAGS) $(LDLIBS) $(BOX_EXTRA_LIBS)")
325+  (shell "$(CC) $(CPPFLAGS) $(CFLAGS) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) $(BOX_EXTRA_LIBS)")
326   (group box))
327 
328 (group box BOX)
329@@ -661,16 +670,10 @@
330 
331 (group default all)
332 
333-; -------------------------------------------------------------------
334 ; meta-targets: apply an override, then build a normal target under
335 ; it. invoke as `ninqu META.TARGET` (`ninqu debug.posix`) or bare
336-; `ninqu META` to apply the override and build (group default). the
337-; $(CFLAGS) inside each value is expanded against whatever CFLAGS
338-; already holds (the config.set default, or a -DCFLAGS=... override)
339-; at the moment the meta is applied, so these only append, they
340-; never have to repeat -std=c99 -Wall -Wextra -pedantic themselves
341-; -------------------------------------------------------------------
342-
343+; `ninqu META` to apply the override and build (group default)
344+;
345 (meta debug
346   (set CFLAGS "$(CFLAGS) -g -O0"))
347 
+9, -5
 1@@ -158,6 +158,7 @@ clean() {
 2         rm -f cmd/posix/awk/awkgram.tab.c cmd/posix/awk/awkgram.tab.h cmd/posix/awk/proctab.c cmd/posix/awk/maketab
 3         rm -f cmd/posix/sh/mknodes cmd/posix/sh/mksyntax cmd/posix/sh/token.h cmd/posix/sh/syntax.c cmd/posix/sh/syntax.h cmd/posix/sh/nodes.c cmd/posix/sh/nodes.h cmd/posix/sh/builtins.c cmd/posix/sh/builtins.h
 4         rm -f scripts/mk/config.set scripts/mk/config.kv scripts/mk/features.h shared/libutil/nofork_list.h
 5+        rm -f scripts/mk/ninja-bin.cache
 6 }
 7 
 8 # config: generate config.set, config.kv, nofork_list.h
 9@@ -200,14 +201,17 @@ config() {
10         emit LDFLAGS_TLS  "${LDFLAGS_TLS:-}"
11         emit LDLIBS_TLS   "${LDLIBS_TLS:-}"
12 
13+        # For when ninqu builds itself, otherwise it won't have this value
14+        emit NINJA_TRY "${NINJA_TRY:-samu,ninja}"
15+
16+        emit BUILD_MAN "${BUILD_MAN:-0}"
17+        echo "build_man=${BUILD_MAN:-0}" >> "${set_file}"
18+
19         # these seven are only consulted per-tool below (build_CATEGORY_TOOL,
20-        # build_CATEGORY_$(BASESTEM)), the bare category toggle has no gate
21-        # anywhere in ninqu.rules, (group CATEGORY ...) already does that
22-        # job. config.kv still gets the uppercase copy since genbox.sh
23-        # and mkbox source it directly
24+        # build_CATEGORY_$(BASESTEM)).
25         for g in BUILD_POSIX BUILD_XSI BUILD_NET BUILD_PSEUDO BUILD_EXTRA BUILD_LINUX BUILD_DEV; do
26                 eval "val=\${$g:-0}"
27-                echo "${g}=\"${val}\"" >> "${kv_file}"
28+                [ "${BUILD_MAN:-0}" = 1 ] && echo "${g}=\"${val}\"" >> "${kv_file}"
29         done
30 
31         # per-tool toggles: scan cmd/<category>/ for tools. a tool is
+37, -37
  1@@ -22,18 +22,18 @@ struct TlsSocket {
  2 #elif FEATURE_USE_BEARSSL
  3 #include <bearssl.h>
  4 
  5-struct my_x509_context {
  6+struct x509_noverify_ctx {
  7   const br_x509_class    *vtable;
  8   br_x509_minimal_context minimal;
  9 };
 10 
 11 struct TlsSocket {
 12-  int                    fd;
 13-  int                    is_tls;
 14-  br_ssl_client_context  sc;
 15-  struct my_x509_context my_x509;
 16-  unsigned char          iobuf[BR_SSL_BUFSIZE_BIDI];
 17-  br_sslio_context       ioc;
 18+  int                      fd;
 19+  int                      is_tls;
 20+  br_ssl_client_context    sc;
 21+  struct x509_noverify_ctx x509_noverify;
 22+  unsigned char            iobuf[BR_SSL_BUFSIZE_BIDI];
 23+  br_sslio_context         ioc;
 24 };
 25 
 26 struct dn_accum {
 27@@ -55,57 +55,57 @@ append_dn_callback(void *dn_ctx, const void *src, size_t len)
 28 }
 29 
 30 static void
 31-my_start_chain(const br_x509_class **ctx, const char *server_name)
 32+x509_noverify_start_chain(const br_x509_class **ctx, const char *server_name)
 33 {
 34-  struct my_x509_context *t = (struct my_x509_context *)ctx;
 35+  struct x509_noverify_ctx *t = (struct x509_noverify_ctx *)ctx;
 36   br_x509_minimal_vtable.start_chain((const br_x509_class **)&t->minimal, server_name);
 37 }
 38 
 39 static void
 40-my_start_cert(const br_x509_class **ctx, uint32_t length)
 41+x509_noverify_start_cert(const br_x509_class **ctx, uint32_t length)
 42 {
 43-  struct my_x509_context *t = (struct my_x509_context *)ctx;
 44+  struct x509_noverify_ctx *t = (struct x509_noverify_ctx *)ctx;
 45   br_x509_minimal_vtable.start_cert((const br_x509_class **)&t->minimal, length);
 46 }
 47 
 48 static void
 49-my_append(const br_x509_class **ctx, const unsigned char *buf, size_t len)
 50+x509_noverify_append(const br_x509_class **ctx, const unsigned char *buf, size_t len)
 51 {
 52-  struct my_x509_context *t = (struct my_x509_context *)ctx;
 53+  struct x509_noverify_ctx *t = (struct x509_noverify_ctx *)ctx;
 54   br_x509_minimal_vtable.append((const br_x509_class **)&t->minimal, buf, len);
 55 }
 56 
 57 static void
 58-my_end_cert(const br_x509_class **ctx)
 59+x509_noverify_end_cert(const br_x509_class **ctx)
 60 {
 61-  struct my_x509_context *t = (struct my_x509_context *)ctx;
 62+  struct x509_noverify_ctx *t = (struct x509_noverify_ctx *)ctx;
 63   br_x509_minimal_vtable.end_cert((const br_x509_class **)&t->minimal);
 64 }
 65 
 66 static unsigned
 67-my_end_chain(const br_x509_class **ctx)
 68+x509_noverify_end_chain(const br_x509_class **ctx)
 69 {
 70-  struct my_x509_context *t = (struct my_x509_context *)ctx;
 71+  struct x509_noverify_ctx *t = (struct x509_noverify_ctx *)ctx;
 72   (void)br_x509_minimal_vtable.end_chain((const br_x509_class **)&t->minimal);
 73   /* always succeed and accept certificate when check_cert is 0 */
 74   return 0;
 75 }
 76 
 77 static const br_x509_pkey *
 78-my_get_pkey(const br_x509_class *const *ctx, unsigned *usages)
 79+x509_noverify_get_pkey(const br_x509_class *const *ctx, unsigned *usages)
 80 {
 81-  const struct my_x509_context *t = (const struct my_x509_context *)ctx;
 82+  const struct x509_noverify_ctx *t = (const struct x509_noverify_ctx *)ctx;
 83   return br_x509_minimal_vtable.get_pkey((const br_x509_class *const *)&t->minimal, usages);
 84 }
 85 
 86-static const br_x509_class my_x509_vtable = {
 87-    sizeof(struct my_x509_context),
 88-    my_start_chain,
 89-    my_start_cert,
 90-    my_append,
 91-    my_end_cert,
 92-    my_end_chain,
 93-    my_get_pkey
 94+static const br_x509_class x509_noverify_vtable = {
 95+    sizeof(struct x509_noverify_ctx),
 96+    x509_noverify_start_chain,
 97+    x509_noverify_start_cert,
 98+    x509_noverify_append,
 99+    x509_noverify_end_cert,
100+    x509_noverify_end_chain,
101+    x509_noverify_get_pkey
102 };
103 
104 static int
105@@ -288,7 +288,7 @@ struct TlsSocket {
106 #endif
107 
108 struct TlsSocket *
109-tls_connect(int fd, const char *host, int check_cert, int is_tls)
110+tlss_connect(int fd, const char *host, int check_cert, int is_tls)
111 {
112   struct TlsSocket *s;
113 
114@@ -298,10 +298,10 @@ tls_connect(int fd, const char *host, int check_cert, int is_tls)
115 
116   if (!is_tls)
117     return s;
118-
119-  /* not every backend below uses these */
120+#if !FEATURE_USE_LIBTLS && !FEATURE_USE_BEARSSL && !FEATURE_USE_OPENSSL
121   (void)host;
122   (void)check_cert;
123+#endif
124 
125 #if FEATURE_USE_LIBTLS
126   {
127@@ -350,11 +350,11 @@ tls_connect(int fd, const char *host, int check_cert, int is_tls)
128         load_ca_certs();
129         ca_loaded = 1;
130       }
131-      br_ssl_client_init_full(&s->sc, &s->my_x509.minimal, tas, tas_num);
132+      br_ssl_client_init_full(&s->sc, &s->x509_noverify.minimal, tas, tas_num);
133     } else {
134-      br_ssl_client_init_full(&s->sc, &s->my_x509.minimal, NULL, 0);
135-      s->my_x509.vtable = &my_x509_vtable;
136-      br_ssl_engine_set_x509(&s->sc.eng, &s->my_x509.vtable);
137+      br_ssl_client_init_full(&s->sc, &s->x509_noverify.minimal, NULL, 0);
138+      s->x509_noverify.vtable = &x509_noverify_vtable;
139+      br_ssl_engine_set_x509(&s->sc.eng, &s->x509_noverify.vtable);
140     }
141 
142     br_ssl_engine_set_buffer(&s->sc.eng, s->iobuf, sizeof(s->iobuf), 1);
143@@ -380,7 +380,7 @@ tls_connect(int fd, const char *host, int check_cert, int is_tls)
144 }
145 
146 ssize_t
147-tls_read(struct TlsSocket *s, void *buf, size_t len)
148+tlss_read(struct TlsSocket *s, void *buf, size_t len)
149 {
150   if (!s->is_tls) {
151     for (;;) {
152@@ -405,7 +405,7 @@ tls_read(struct TlsSocket *s, void *buf, size_t len)
153 }
154 
155 ssize_t
156-tls_write(struct TlsSocket *s, const void *buf, size_t len)
157+tlss_write(struct TlsSocket *s, const void *buf, size_t len)
158 {
159   if (!s->is_tls) {
160     for (;;) {
161@@ -437,7 +437,7 @@ tls_write(struct TlsSocket *s, const void *buf, size_t len)
162 }
163 
164 void
165-tls_close(struct TlsSocket *s, int close_fd)
166+tlss_close(struct TlsSocket *s, int close_fd)
167 {
168   if (s->is_tls) {
169 #if FEATURE_USE_LIBTLS
+5, -5
 1@@ -6,16 +6,16 @@
 2 
 3 struct TlsSocket;
 4 
 5-/* tlssock_connect takes an already connected socket fd and upgrades it to tls
 6+/* tls_connect takes an already connected socket fd and upgrades it to tls
 7    if check_cert is 0 certificate validation is bypassed
 8    returns a new tls socket or null on error */
 9-struct TlsSocket *tls_connect(int fd, const char *host, int check_cert, int is_tls);
10+struct TlsSocket *tlss_connect(int fd, const char *host, int check_cert, int is_tls);
11 
12 /* standard read and write wrapping either libtls, bearssl or plain fallback */
13-ssize_t tls_read(struct TlsSocket *s, void *buf, size_t len);
14-ssize_t tls_write(struct TlsSocket *s, const void *buf, size_t len);
15+ssize_t tlss_read(struct TlsSocket *s, void *buf, size_t len);
16+ssize_t tlss_write(struct TlsSocket *s, const void *buf, size_t len);
17 
18 /* closes the tls connection and optionally closes the socket fd */
19-void tls_close(struct TlsSocket *s, int close_fd);
20+void tlss_close(struct TlsSocket *s, int close_fd);
21 
22 #endif /* tls_h_ */
+2, -2
 1@@ -44,8 +44,8 @@ int   wpclose(FILE *fp);
 2 
 3 int wsystem(const char *cmd);
 4 
 5-void wexecvp_self(const char *name, char *const *argv);
 6-void wexecv_self(const char *path, char *const *argv);
 7+void wexecvp_self(const char *name, char *const *argv) __attribute__((noreturn));
 8+void wexecv_self(const char *path, char *const *argv) __attribute__((noreturn));
 9 
10 int   wpopen_track(FILE *fp, pid_t pid);
11 pid_t wpopen_untrack(FILE *fp);