aruu

[MIRROR] Actual replacement for Busybox | suckless
git clone https://git.daat.foo/aruu.git
Log | Files | Refs | README | LICENSE

commit 4bb01f64ae6984bebb498adb074d29fa978a1d4c
parent b52592bb4524cc67434b0323c96352f9fbc141a7
Author: xplshn <anto@xplshn.com.ar>
Date:   Tue,  7 Jul 2026 19:53:32 -0300

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>

Diffstat:
M.gitignore | 5+++++
MMakefile | 19+++++++++++++++----
Mbuild.cfg | 6++++++
Mcmd/dev/ninqu/exec.c | 31+++++++++++--------------------
Mcmd/dev/ninqu/expand.c | 49++++++++++++++++++++++++++++++++++++-------------
Mcmd/dev/ninqu/fs.c | 20++++++--------------
Mcmd/dev/ninqu/main.c | 30++++++++++++++++++++++++++++--
Mcmd/dev/ninqu/ninqu.h | 15++++++++++++++-
Mcmd/dev/ninqu/strlist.c | 12++++--------
Mcmd/extra/yap/ansi.c | 101+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mcmd/extra/yap/ansi.h | 6+++---
Mcmd/extra/yap/commands.c | 1011+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mcmd/extra/yap/commands.h | 28++++++++++++++--------------
Mcmd/extra/yap/display.c | 1094+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mcmd/extra/yap/display.h | 38+++++++++++++++++++-------------------
Mcmd/extra/yap/getcomm.c | 478+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mcmd/extra/yap/getcomm.h | 4++--
Mcmd/extra/yap/getline.c | 703+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mcmd/extra/yap/getline.h | 8++++----
Mcmd/extra/yap/help.c | 140++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mcmd/extra/yap/keys.c | 234+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mcmd/extra/yap/keys.h | 10+++++-----
Mcmd/extra/yap/machine.c | 191+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mcmd/extra/yap/machine.h | 14+++++++-------
Mcmd/extra/yap/main.c | 206++++++++++++++++++++++++++++++++++++++-----------------------------------------
Mcmd/extra/yap/main.h | 10+++++-----
Mcmd/extra/yap/options.c | 129+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mcmd/extra/yap/options.h | 8++++----
Mcmd/extra/yap/output.c | 71+++++++++++++++++++++++++++++++++++------------------------------------
Mcmd/extra/yap/output.h | 26+++++++++++++-------------
Mcmd/extra/yap/pattern.c | 31+++++++++++++++----------------
Mcmd/extra/yap/pattern.h | 2+-
Mcmd/extra/yap/process.c | 141+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mcmd/extra/yap/process.h | 12++++++------
Mcmd/extra/yap/prompt.c | 249++++++++++++++++++++++++++++++++++++++-----------------------------------------
Mcmd/extra/yap/term.c | 531+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mcmd/extra/yap/term.h | 8++++----
Mcmd/net/wget.c | 22+++++++++++-----------
Mcmd/posix/bc.y | 8++------
Mcmd/posix/make/parser.c | 2+-
Mcmd/posix/sh/easter.c | 261++++++++++++++++++++++++++++++++++++++-----------------------------------------
Mninqu.rules | 161++++++++++++++++++++++++++++++++++++++++---------------------------------------
Mscripts/genconfig.sh | 14+++++++++-----
Mshared/libutil/tls.c | 74+++++++++++++++++++++++++++++++++++++-------------------------------------
Mshared/tls.h | 10+++++-----
Mshared/wexec.h | 4++--
46 files changed, 3114 insertions(+), 3113 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -34,3 +34,8 @@ scripts/mk/config.mk scripts/mk/config.kv scripts/mk/rules.mk deps.mk + +# ninja backend generator output and state +build.ninja +.ninja_log +.ninja_deps diff --git a/Makefile b/Makefile @@ -1,5 +1,8 @@ CC ?= cc -static CFLAGS ?= -std=c99 -Wall -Wextra -pedantic + +BACKEND ?= auto + CPPFLAGS ?= -Ishared -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L \ -DFEATURE_NOFORK=0 -DFEATURE_NOEXEC=0 # NOEXEC cannot be on the bootstrap compile, but it can @@ -13,7 +16,8 @@ NINQU_LIB_SRC =\ shared/libutil/strtonum.c\ shared/libutil/fshut.c\ shared/libutil/mkdirp.c\ - shared/libutil/recurse_dir.c + shared/libutil/recurse_dir.c\ + shared/libutil/wexec.c NINQU_SRC =\ cmd/dev/ninqu/main.c\ @@ -24,11 +28,13 @@ NINQU_SRC =\ cmd/dev/ninqu/registry.c\ cmd/dev/ninqu/fs.c\ cmd/dev/ninqu/exec.c\ + cmd/dev/ninqu/backend.c\ cmd/dev/ninqu/parse.c\ cmd/dev/ninqu/expand.c\ cmd/dev/ninqu/schedule.c\ cmd/dev/ninqu/query.c\ - cmd/dev/ninqu/resolve.c + cmd/dev/ninqu/resolve.c\ + cmd/dev/ninqu/ninja.c # map make's -j to ninqu's -j flag NINQU ?= cmd/dev/ninqu/ninqu @@ -45,12 +51,15 @@ $(NINQU): $(NINQU_SRC) cmd/dev/ninqu/ninqu.h scripts/mk/config.set $(NINQU_LIB_S .PHONY: FORCE FORCE: +# ninqu generates build.ninja if ninja/samu is available and execs that +# instead of running its own backend, but you can use make BACKEND=internal +# to force the internal one to be used anyways %: $(NINQU) FORCE $(NINQU) $(JOBS) $@ clean: $(NINQU) - $(NINQU) clean - rm -f $(NINQU) + $(NINQU) -DBACKEND="internal" clean + rm -f $(NINQU) build.ninja scripts/mk/config.set: build.cfg scripts/genconfig.sh sh scripts/genconfig.sh config @@ -68,10 +77,12 @@ cmd/dev/ninqu/gate.c: ; cmd/dev/ninqu/registry.c: ; cmd/dev/ninqu/fs.c: ; cmd/dev/ninqu/exec.c: ; +cmd/dev/ninqu/backend.c: ; cmd/dev/ninqu/parse.c: ; cmd/dev/ninqu/expand.c: ; cmd/dev/ninqu/schedule.c: ; cmd/dev/ninqu/query.c: ; cmd/dev/ninqu/resolve.c: ; +cmd/dev/ninqu/ninja.c: ; build.cfg: ; scripts/genconfig.sh: ; diff --git a/build.cfg b/build.cfg @@ -154,6 +154,9 @@ for _p in $PRESET_UTILS; do done unset _p +# Stays 0 unless you do build manpages, via `ninqu man` +BUILD_MAN=0 + # --- per-item overrides (after preset expansion) --- # BUILD_POSIX_SH=0 # disable a tool when its group is active # BUILD_DEV_AS=1 # enable a tool whose group isnt in PRESET_UTILS @@ -245,3 +248,6 @@ fi CPPFLAGS_TLS=$(echo "$CPPFLAGS_TLS" | xargs) LDFLAGS_TLS=$(echo "$LDFLAGS_TLS" | xargs) LDLIBS_TLS=$(echo "$LDLIBS_TLS" | xargs) + +# Makes Ninqu try them in this order: +NINJA_TRY="${NINJA_TRY:-samu,ninja}" diff --git a/cmd/dev/ninqu/exec.c b/cmd/dev/ninqu/exec.c @@ -1,4 +1,5 @@ #include "ninqu.h" +#include "wexec.h" #include <errno.h> #include <libgen.h> @@ -13,8 +14,7 @@ int jobs_n = 1; int summary_mode; int failed_any; -/* fork, chdir, redirect, exec. the child _exit on error so the - * parent never sees a stale pid */ +/* child _exit on error so parent never sees a stale pid */ pid_t spawn_inst(struct Inst *inst, struct StrList *argv) { @@ -37,9 +37,7 @@ spawn_inst(struct Inst *inst, struct StrList *argv) child_execvp(sl_argv(argv)); } -/* fork a supervisor that chains each stage stdout into the next - * stdin. the parent waits on the supervisor, so the whole pipeline - * has one exit status */ +/* parent waits on supervisor so pipeline has one exit status */ pid_t spawn_pipe(struct Inst *inst) { @@ -91,8 +89,8 @@ spawn_pipe(struct Inst *inst) } } -/* mkdir -p the directory an instance writes into, so a rule (out) - * can point at a path that does not exist yet */ +/* mkdir -p the directory an instance writes into, so a rule (out) can point at a path that does not + * exist yet */ void mk_out_dir(const char *out) { @@ -108,8 +106,7 @@ mk_out_dir(const char *out) mkdirp(dir, 0777, 0777); } -/* print the rule line and flush before the child runs, so the - * announcement appears before the child own output */ +/* flush before child runs so announcement appears before its output */ void announce_inst(struct Inst *inst) { @@ -118,8 +115,7 @@ announce_inst(struct Inst *inst) fflush(stdout); } -/* run one instance synchronously. exits on failure since a missing - * producer is unrecoverable */ +/* exits on failure since a missing producer is unrecoverable */ void run_inst_sync(int idx) { @@ -137,8 +133,7 @@ run_inst_sync(int idx) eprintf("manifest: producer failed (rule %s)\n", rules[inst->rule_idx].name); } -/* run a batch of independent instances concurrently, at most jobs_n - * at a time. all instances in the batch are at the same kahn level */ +/* all instances in the batch are at the same kahn level */ void run_batch(int *idxs, int n) { @@ -189,9 +184,7 @@ run_batch(int *idxs, int n) free(slot); } -/* run an instance and all its transitive deps in order, so a - * producer like LIBUTIL does not archive .o files that have not - * been compiled yet */ +/* run transitive deps in order so a producer does not archive uncompiled files */ void run_inst_with_deps(int idx) { @@ -211,8 +204,7 @@ run_inst_with_deps(int idx) run_inst_sync(idx); } -/* bootstrap: run the producer for path only if path does not exist. - * after that the normal dependency graph takes over */ +/* run producer for path only if path does not exist */ void materialize_if_missing(const char *path) { @@ -233,8 +225,7 @@ materialize_if_missing(const char *path) } } -/* run argv synchronously, return its stdout as a string. used by - * (set NAME (capture (exec ...))) at parse time */ +/* used by (set NAME (capture (exec ...))) at parse time */ char * capture_argv(struct StrList *argv) { diff --git a/cmd/dev/ninqu/expand.c b/cmd/dev/ninqu/expand.c @@ -1,5 +1,6 @@ #include "ninqu.h" +#include <fnmatch.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -52,8 +53,7 @@ inst_stale(struct Inst *inst) return 0; } -/* a pure $(NAME) splits on whitespace so $(CFLAGS) becomes many - * flags, while -I$(INCDIR) stays one token */ +/* pure $(NAME) splits on whitespace so $(CFLAGS) becomes many flags, -I$(INCDIR) stays one token */ static int is_pure_ref(const char *tok) { @@ -127,9 +127,7 @@ build_cmd(struct Inst *inst, struct Rule *r) } } -/* @NAME resolves to a rule ref. glob:PREFIX goes to glob_expand. - * anything else is a path: if it does not exist, try to find a - * producer and run it first */ +/* if path does not exist, try to find a producer and run it first */ static void resolve_input_token(int inst_idx, const char *raw, int only_dep) { @@ -198,8 +196,7 @@ setup_inst(struct Inst *inst, struct Rule *r) } } -/* resolve deps, expand (out), populate IN/OUT on the overlay, build - * the cmd. caller must have local_overlay set if needed */ +/* caller must have local_overlay set if needed */ static void finalize_inst(int idx, struct Rule *r, struct KvStore *ov) { @@ -222,6 +219,27 @@ finalize_inst(int idx, struct Rule *r, struct KvStore *ov) build_cmd(inst, r); } +/* true when deps (out) matches selfs glob. glob_all() needs bytes on disk + * so dep must run synchronously before enumerating instances */ +static int +dep_feeds_glob(struct Rule *self, struct Rule *dep) +{ + int j; + + if (!dep->out[0]) + return 0; + for (j = 0; j < self->globs.n; j++) { + char *pat = kv_expand(self->globs.v[j]); + char *out = kv_expand(dep->out); + int hit = fnmatch(pat, out, 0) == 0; + free(pat); + free(out); + if (hit) + return 1; + } + return 0; +} + void expand_rule(const char *name) { @@ -234,8 +252,7 @@ expand_rule(const char *name) return; r->expanded = 1; - /* a gate with $(...) is per-instance, a static gate is checked - * once and if false the rule produces zero instances */ + /* static gate checked once, if false rule produces zero instances */ if (r->gate && !gate_has_dyn(r->gate) && !gate_eval(r->gate)) return; @@ -252,9 +269,15 @@ expand_rule(const char *name) int j; int r_literal = rule_is_literal(r); - /* run order-only @rule producers before globbing, so a codegen - * step that generates sources finishes before the glob runs. - * skipped in summary mode since -S must not execute */ + /* run a codegen producer before globbing only when its own + * output feeds this rules glob, so a step like POSIX_BC_C + * (produces cmd/posix/bc.c) finishes before glob_all() looks + * for cmd/posix/bc.c. anything else in extra_deps (a library to + * link, a header some other rule includes) never needs to run + * here, expand_rule() on it just registers its instances so + * the resolve_input_token() pass in finalize_inst() can wire up + * dep_rule_names for backend scheduling. skipped in + * summary mode since -S must not execute */ if (!summary_mode) { for (j = 0; j < r->extra_deps.n; j++) { char *tok = kv_expand(r->extra_deps.v[j]); @@ -262,7 +285,7 @@ expand_rule(const char *name) struct Rule *dep = rule_find(tok + 1); if (dep) { expand_rule(dep->name); - if (dep->n_inst > 0) { + if (dep_feeds_glob(r, dep) && dep->n_inst > 0) { int k; for (k = 0; k < dep->n_inst; k++) run_inst_with_deps(dep->inst_idx[k]); diff --git a/cmd/dev/ninqu/fs.c b/cmd/dev/ninqu/fs.c @@ -7,6 +7,7 @@ #include <stdlib.h> #include <string.h> #include <sys/stat.h> +#include <unistd.h> long mtime_of(const char *path) @@ -53,8 +54,7 @@ file_contains(const char *path, const char *needle) return found; } -/* recurse_dir has no userdata slot, so the pattern and output list - * travel through file-scope statics for the span of one call */ +/* recurse_dir lacks a userdata slot, use statics for one call */ static const char *rg_suffix; static struct StrList *rg_out; @@ -81,9 +81,7 @@ recurse_glob(const char *dir, const char *suffix, struct StrList *out) recurse_dir(dir, rg_visit); } -/* a double-star-slash pattern recurses from the dir before it, - * matching the suffix against each basename. anything else goes to - * glob(3) as-is */ +/* double-star-slash recurses, anything else goes to glob(3) */ void glob_expand(const char *pattern, struct StrList *out) { @@ -126,8 +124,7 @@ is_wildcard_pattern(const char *pattern) return strpbrk(pattern, "*?[") != NULL; } -/* true if every glob on r is a literal path. a rule built entirely - * from literals is the override side of path_claimed_elsewhere */ +/* true if every glob on r is a literal path */ int rule_is_literal(struct Rule *r) { @@ -140,8 +137,7 @@ rule_is_literal(struct Rule *r) return 1; } -/* a broad wildcard rule steps aside for any file another rule names - * outright, so a per-file override needs no (skip) on the broad rule */ +/* broad wildcard steps aside for literal paths so overrides need no (skip) */ int path_claimed_elsewhere(const char *path, struct Rule *self) { @@ -178,11 +174,7 @@ splitext(const char *base, char *stem, size_t stemsz, char *ext, size_t extsz) } } -/* a basestem like sha512-224sum has a hyphen, but a config toggle - * cannot. normalize so a gate keying off BASESTEM matches the form - * genconfig writes - * FIXME: I do not like our current genconfig.sh - */ +/* normalize so a gate keying off BASESTEM matches genconfig output */ void to_ident(const char *s, char *out, size_t outsz) { diff --git a/cmd/dev/ninqu/main.c b/cmd/dev/ninqu/main.c @@ -10,7 +10,8 @@ static void usage(void) { eprintf( - "usage: %s [-jN] [-f manifest] [-C dir] [-Dvar=val]... [-S] [-F] [target|meta.target ...]\n" + "usage: %s [-jN] [-f manifest] [-C dir] [-Dvar=val]... [-S] [-F] [-G ninja] " + "[target|meta.target ...]\n" " %s query (features|groups|metas|rules|graph) [arg]\n", argv0, argv0 @@ -25,10 +26,11 @@ main(int argc, char *argv[]) int query_mode = 0; const char *query_sub = NULL; const char *query_arg = NULL; + const char *generator = NULL; int i; struct StrList wanted = {0}; - /* detect `query` before ARGBEGIN so it is not parsed as a target */ + /* detect query before ARGBEGIN so it is not parsed as a target */ if (argc >= 2 && strcmp(argv[1], "query") == 0) { query_mode = 1; if (argc < 3) @@ -78,6 +80,9 @@ main(int argc, char *argv[]) case 'F': features_mode = 1; break; + case 'G': + generator = EARGF(usage()); + break; default: usage(); } @@ -106,6 +111,27 @@ main(int argc, char *argv[]) resolve_wanted(wanted.v[i]); resolve_deps(); + + if (generator) { + const struct Backend *be = backend_by_name(generator); + if (!be) + eprintf("ninqu: unknown generator '%s'\n", generator); + be->emit(be->file, &wanted); + return failed_any ? 1 : 0; + } + + /* BACKEND=internal forces executor. otherwise generate file and exec backend binary */ + if (strcmp(kv_get_or("BACKEND", "auto"), "internal") != 0) { + char *bin; + const struct Backend *be = backend_resolve(&bin); + if (be) { + be->emit(be->file, &wanted); + if (failed_any) + return 1; + backend_exec(be, bin, &wanted); + } + } + schedule_and_run(); return failed_any ? 1 : 0; diff --git a/cmd/dev/ninqu/ninqu.h b/cmd/dev/ninqu/ninqu.h @@ -10,7 +10,7 @@ #include "arg.h" #include "util.h" -/* grow a struct-array when full. n/cap doubles each time */ +/* grow a struct-array when full, n/cap doubles each time */ #define GROW(arr, n, cap, init) \ do { \ if ((n) >= (cap)) { \ @@ -246,6 +246,19 @@ extern struct StrList files_read; void expand_rule(const char *name); void schedule_and_run(void); +void emit_ninja(const char *path, struct StrList *wanted); + +struct Backend { + const char *name; + const char *try_key; + const char *file; + void (*emit)(const char *path, struct StrList *wanted); +}; + +const struct Backend *backend_by_name(const char *name); +const struct Backend *backend_resolve(char **bin); +void backend_exec(const struct Backend *be, const char *bin, struct StrList *wanted) + __attribute__((noreturn)); void do_features(void); void do_query(const char *sub, const char *arg); diff --git a/cmd/dev/ninqu/strlist.c b/cmd/dev/ninqu/strlist.c @@ -1,10 +1,9 @@ #include "ninqu.h" +#include "wexec.h" #include <ctype.h> -#include <errno.h> #include <stdio.h> #include <string.h> -#include <unistd.h> void sl_push(struct StrList *sl, const char *s) @@ -80,7 +79,7 @@ base_of(const char *path) return p ? p + 1 : path; } -/* null-terminate the array so execvp stops scanning */ +/* null-terminate the array so wexecvp stops scanning */ char ** sl_argv(struct StrList *sl) { @@ -92,12 +91,9 @@ sl_argv(struct StrList *sl) return av; } -/* noreturn so callers do not need to guard the dead path after the - * fork child calls this */ +/* noreturn so callers do not guard the dead path after fork */ void child_execvp(char **av) { - execvp(av[0], av); - fprintf(stderr, "%s: exec %s: %s\n", argv0, av[0], strerror(errno)); - _exit(127); + wexecvp_self(av[0], av); } diff --git a/cmd/extra/yap/ansi.c b/cmd/extra/yap/ansi.c @@ -1,75 +1,74 @@ -#include "in_all.h" #include "ansi.h" +#include "in_all.h" static int consume_csi(const char *s, const char **next, enum ansi_kind *kind) { - const unsigned char *p = (const unsigned char *)s + 2; + const unsigned char *p = (const unsigned char *)s + 2; - while (*p >= 0x30 && *p <= 0x3f) { - p++; - } - while (*p >= 0x20 && *p <= 0x2f) { - p++; - } - if (*p >= 0x40 && *p <= 0x7e) { - *kind = (*p == 'm') ? ANSI_SGR : ANSI_DISCARD; - *next = (const char *)p + 1; - return 1; - } - return 0; + while (*p >= 0x30 && *p <= 0x3f) { + p++; + } + while (*p >= 0x20 && *p <= 0x2f) { + p++; + } + if (*p >= 0x40 && *p <= 0x7e) { + *kind = (*p == 'm') ? ANSI_SGR : ANSI_DISCARD; + *next = (const char *)p + 1; + return 1; + } + return 0; } static int consume_string(const char *s, const char **next) { - const unsigned char *p = (const unsigned char *)s + 2; + const unsigned char *p = (const unsigned char *)s + 2; - while (*p) { - if (*p == '\a') { - *next = (const char *)p + 1; - return 1; - } - if (*p == '\x1b' && p[1] == '\\') { - *next = (const char *)p + 2; - return 1; - } - p++; - } - return 0; + while (*p) { + if (*p == '\a') { + *next = (const char *)p + 1; + return 1; + } + if (*p == '\x1b' && p[1] == '\\') { + *next = (const char *)p + 2; + return 1; + } + p++; + } + return 0; } static int consume_esc(const char *s, const char **next) { - const unsigned char *p = (const unsigned char *)s + 1; + const unsigned char *p = (const unsigned char *)s + 1; - while (*p >= 0x20 && *p <= 0x2f) { - p++; - } - if (*p >= 0x30 && *p <= 0x7e) { - *next = (const char *)p + 1; - return 1; - } - return 0; + while (*p >= 0x20 && *p <= 0x2f) { + p++; + } + if (*p >= 0x30 && *p <= 0x7e) { + *next = (const char *)p + 1; + return 1; + } + return 0; } int ansi_escape(const char *s, const char **next, enum ansi_kind *kind) { - *kind = ANSI_NONE; - *next = s; - if ((unsigned char)s[0] != 0x1b || s[1] == '\0') { - return 0; - } - if (s[1] == '[') { - return consume_csi(s, next, kind); - } - if (s[1] == ']' || s[1] == 'P' || s[1] == 'X' || s[1] == '^' || - s[1] == '_') { - *kind = ANSI_DISCARD; - return consume_string(s, next); - } - *kind = ANSI_DISCARD; - return consume_esc(s, next); + *kind = ANSI_NONE; + *next = s; + if ((unsigned char)s[0] != 0x1b || s[1] == '\0') { + return 0; + } + if (s[1] == '[') { + return consume_csi(s, next, kind); + } + if (s[1] == ']' || s[1] == 'P' || s[1] == 'X' || s[1] == '^' || s[1] == '_') { + *kind = ANSI_DISCARD; + return consume_string(s, next); + } + *kind = ANSI_DISCARD; + return consume_esc(s, next); } diff --git a/cmd/extra/yap/ansi.h b/cmd/extra/yap/ansi.h @@ -2,9 +2,9 @@ #define ANSI_H enum ansi_kind { - ANSI_NONE = 0, - ANSI_SGR, - ANSI_DISCARD, + ANSI_NONE = 0, + ANSI_SGR, + ANSI_DISCARD, }; int ansi_escape(const char *s, const char **next, enum ansi_kind *kind); diff --git a/cmd/extra/yap/commands.c b/cmd/extra/yap/commands.c @@ -1,82 +1,82 @@ /* Copyright (c) 1985 Ceriel J.H. Jacobs */ -#include "in_all.h" #include "commands.h" -#include "output.h" -#include "process.h" -#include "help.h" -#include "term.h" -#include "prompt.h" -#include "getline.h" -#include "getcomm.h" -#include "pattern.h" +#include "assert.h" #include "display.h" -#include "options.h" -#include "machine.h" +#include "getcomm.h" +#include "getline.h" +#include "help.h" +#include "in_all.h" #include "keys.h" +#include "machine.h" #include "main.h" -#include "assert.h" +#include "options.h" +#include "output.h" +#include "pattern.h" +#include "process.h" +#include "prompt.h" +#include "term.h" static long lastcount; /* Save last count for '.' command */ -static int lastcomm; /* Save last command for '.' command */ -static int searchdir; /* Direction of last search */ +static int lastcomm; /* Save last command for '.' command */ +static int searchdir; /* Direction of last search */ -static int do_nocomm(long cnt); +static int do_nocomm(long cnt); static void do_search(char *str, long cnt, int dir); -static int do_fsearch(long cnt); -static int do_bsearch(long cnt); -static int n_or_rn_search(long cnt, int dir); -static int do_nsearch(long cnt); -static int do_rnsearch(long cnt); -static int shell_command(int esc_ch, long cnt); -static int do_shell(long cnt); -static int do_pipe(long cnt); -static int do_writefile(long cnt); -static int do_absolute(long cnt); -static int do_visit(long cnt); -static int do_error(long cnt); -static int prev_screen(int sz, int really); -static int next_screen(int sz, int really); -static int do_redraw(long cnt); -static int page_size(unsigned cnt); -static int do_forward(long cnt); -static int do_backward(long cnt); -static int do_firstline(long cnt); -static int do_lline(long cnt); -static int do_lf(long cnt); -static int do_upline(long cnt); -static int do_skiplines(long cnt); -static int do_bskiplines(long cnt); -static int do_fscreens(long cnt); -static int do_bscreens(long cnt); -static int scro_size(unsigned cnt); -static int do_f_scroll(long cnt); -static int do_b_scroll(long cnt); -static int do_previousfile(long cnt); -static int do_nextfile(long cnt); -static int do_lcomm(long cnt); -static int do_quit(long cnt); +static int do_fsearch(long cnt); +static int do_bsearch(long cnt); +static int n_or_rn_search(long cnt, int dir); +static int do_nsearch(long cnt); +static int do_rnsearch(long cnt); +static int shell_command(int esc_ch, long cnt); +static int do_shell(long cnt); +static int do_pipe(long cnt); +static int do_writefile(long cnt); +static int do_absolute(long cnt); +static int do_visit(long cnt); +static int do_error(long cnt); +static int prev_screen(int sz, int really); +static int next_screen(int sz, int really); +static int do_redraw(long cnt); +static int page_size(unsigned cnt); +static int do_forward(long cnt); +static int do_backward(long cnt); +static int do_firstline(long cnt); +static int do_lline(long cnt); +static int do_lf(long cnt); +static int do_upline(long cnt); +static int do_skiplines(long cnt); +static int do_bskiplines(long cnt); +static int do_fscreens(long cnt); +static int do_bscreens(long cnt); +static int scro_size(unsigned cnt); +static int do_f_scroll(long cnt); +static int do_b_scroll(long cnt); +static int do_previousfile(long cnt); +static int do_nextfile(long cnt); +static int do_lcomm(long cnt); +static int do_quit(long cnt); static int do_nocomm(long cnt) { /* Do nothing */ - (void)cnt; - return 0; + (void)cnt; + return 0; } int do_chkm(long cnt) { /* Change key map */ - struct keymap *p; - (void)cnt; + struct keymap *p; + (void)cnt; - if (!(p = othermap)) { - error("No other keymap"); - return 0; - } - othermap = currmap; - currmap = p; - return 0; + if (!(p = othermap)) { + error("No other keymap"); + return 0; + } + othermap = currmap; + currmap = p; + return 0; } /* @@ -86,71 +86,71 @@ do_chkm(long cnt) static void do_search(char *str, long cnt, int dir) { - char *p; - long lineno; - - if (str) { - /* - * We have to get a pattern, which we have to prompt for - * with the string "str". - */ - if ((p = readline(str)) == 0) { - /* - * User cancelled command - */ - return; - } - if ((p = re_comp(p))) { - /* - * There was an error in the pattern - */ - error(p); - return; - } - searchdir = dir; - } - if (dir < 0) - lineno = scr_info.firstline; - else - lineno = scr_info.lastline; - for (;;) { - p = 0; - if ((lineno += dir) > 0) - p = getline(lineno, 0); - if (interrupt) - return; - if (!p) { /* End of file reached */ - error("pattern not found"); - return; - } - if (re_exec(p) && --cnt <= 0) { - /* - * We found the pattern, and we found it often enough. - * Pity that we still don't know where the match is. - * We only know the linenumber. So, we just hope the - * following will at least bring it on the screen ... - */ - (void)display(lineno, 0, pagesize, 0); - (void)scrollb(2, 0); - redraw(0); - return; - } - } - /* NOTREACHED */ + char *p; + long lineno; + + if (str) { + /* + * We have to get a pattern, which we have to prompt for + * with the string "str". + */ + if ((p = readline(str)) == 0) { + /* + * User cancelled command + */ + return; + } + if ((p = re_comp(p))) { + /* + * There was an error in the pattern + */ + error(p); + return; + } + searchdir = dir; + } + if (dir < 0) + lineno = scr_info.firstline; + else + lineno = scr_info.lastline; + for (;;) { + p = 0; + if ((lineno += dir) > 0) + p = getline(lineno, 0); + if (interrupt) + return; + if (!p) { /* End of file reached */ + error("pattern not found"); + return; + } + if (re_exec(p) && --cnt <= 0) { + /* + * We found the pattern, and we found it often enough. + * Pity that we still don't know where the match is. + * We only know the linenumber. So, we just hope the + * following will at least bring it on the screen ... + */ + (void)display(lineno, 0, pagesize, 0); + (void)scrollb(2, 0); + redraw(0); + return; + } + } + /* NOTREACHED */ } static int do_fsearch(long cnt) { /* Forward search */ - do_search("/", cnt, 1); - return 0; + do_search("/", cnt, 1); + return 0; } static int do_bsearch(long cnt) { /* Backward search */ - do_search("?", cnt, -1); - return 0; + do_search("?", cnt, -1); + return 0; } /* @@ -160,178 +160,178 @@ do_bsearch(long cnt) static int n_or_rn_search(long cnt, int dir) { - char *p; + char *p; - if (dir == 1) { - p = "/\r"; - } else if (dir == -1) { - p = "?\r"; - } else { - error("No previous pattern"); - return 0; - } - if (!stupid) - clrbline(); - putline(p); - flush(); - do_search((char *)0, cnt, dir); - return 0; + if (dir == 1) { + p = "/\r"; + } else if (dir == -1) { + p = "?\r"; + } else { + error("No previous pattern"); + return 0; + } + if (!stupid) + clrbline(); + putline(p); + flush(); + do_search((char *)0, cnt, dir); + return 0; } static int do_nsearch(long cnt) { /* Repeat search in same direction */ - n_or_rn_search(cnt, searchdir); - return 0; + n_or_rn_search(cnt, searchdir); + return 0; } static int do_rnsearch(long cnt) { /* Repeat search in opposite direction */ - n_or_rn_search(cnt, -searchdir); - return 0; + n_or_rn_search(cnt, -searchdir); + return 0; } static int shell_command(int esc_ch, long cnt) { - char *p; - static char buf[2]; - - buf[0] = esc_ch; - buf[1] = '\0'; - if ((p = readline(buf)) != 0) { - shellescape(p, esc_ch); - if (cnt >= 0 && !hardcopy) { - p = startcomm; - startcomm = 0; - ret_to_continue(); - putline(TI); - if (!p) { - /* - * Avoid double redraw. - * After a "startcomm", a redraw will - * take place anyway. - */ - redraw(1); - } - } - } - return 0; + char *p; + static char buf[2]; + + buf[0] = esc_ch; + buf[1] = '\0'; + if ((p = readline(buf)) != 0) { + shellescape(p, esc_ch); + if (cnt >= 0 && !hardcopy) { + p = startcomm; + startcomm = 0; + ret_to_continue(); + putline(TI); + if (!p) { + /* + * Avoid double redraw. + * After a "startcomm", a redraw will + * take place anyway. + */ + redraw(1); + } + } + } + return 0; } static int do_shell(long cnt) { /* Execute a shell escape */ - return shell_command('!', cnt); + return shell_command('!', cnt); } static int do_pipe(long cnt) { /* Execute a shell escape */ - return shell_command('|', cnt); + return shell_command('|', cnt); } static int do_writefile(long cnt) { /* Write input to a file */ - char *p; - int fd; - (void)cnt; - - if ((p = readline("Filename: ")) == 0 || !*p) { - /* - * No file name given - */ - return 0; - } - if ((fd = open(p, O_CREAT | O_EXCL | O_WRONLY, 0644)) < 0) { - if (errno == EEXIST) { - error("File exists"); - return 0; - } - error("Could not open file"); - return 0; - } - wrt_fd(fd); - (void)close(fd); - return 0; + char *p; + int fd; + (void)cnt; + + if ((p = readline("Filename: ")) == 0 || !*p) { + /* + * No file name given + */ + return 0; + } + if ((fd = open(p, O_CREAT | O_EXCL | O_WRONLY, 0644)) < 0) { + if (errno == EEXIST) { + error("File exists"); + return 0; + } + error("Could not open file"); + return 0; + } + wrt_fd(fd); + (void)close(fd); + return 0; } void wrt_fd(int fd) { - long l = 1; - char *p = getline(l, 0), *pbuf; - char buf[1024]; - - while (p) { - pbuf = buf; - while (p && pbuf < &buf[1024]) { - if (!*p) { - *pbuf++ = '\n'; - p = getline(++l, 0); - } else - *pbuf++ = *p++; - } - if (write(fd, buf, pbuf - buf) < 0) { - error("Write failed"); - break; - } - } + long l = 1; + char *p = getline(l, 0), *pbuf; + char buf[1024]; + + while (p) { + pbuf = buf; + while (p && pbuf < &buf[1024]) { + if (!*p) { + *pbuf++ = '\n'; + p = getline(++l, 0); + } else + *pbuf++ = *p++; + } + if (write(fd, buf, pbuf - buf) < 0) { + error("Write failed"); + break; + } + } } static int do_absolute(long cnt) { /* Go to linenumber "cnt" */ - if (!getline(cnt, 0)) { /* Not there or interrupt */ - if (!interrupt) { - /* - * User did'nt give an interrupt, so the line number - * was too high. Go to the last line. - */ - do_lline(cnt); - } - return 0; - } - (void)display(cnt, 0, pagesize, 1); - return 0; + if (!getline(cnt, 0)) { /* Not there or interrupt */ + if (!interrupt) { + /* + * User did'nt give an interrupt, so the line number + * was too high. Go to the last line. + */ + do_lline(cnt); + } + return 0; + } + (void)display(cnt, 0, pagesize, 1); + return 0; } static int do_visit(long cnt) { /* Visit a file */ - char *p; - static char fn[128]; /* Keep file name */ - (void)cnt; - - if ((p = readline("Filename: ")) == 0) { - return 0; - } - if (*p) { - (void)strcpy(fn, p); - visitfile(fn); - } else { - /* - * User typed a return. Visit the current file - */ - if (!(p = filenames[filecount])) { - error("No current file"); - return 0; - } - visitfile(p); - } - (void)display(1L, 0, pagesize, 1); - return 0; + char *p; + static char fn[128]; /* Keep file name */ + (void)cnt; + + if ((p = readline("Filename: ")) == 0) { + return 0; + } + if (*p) { + (void)strcpy(fn, p); + visitfile(fn); + } else { + /* + * User typed a return. Visit the current file + */ + if (!(p = filenames[filecount])) { + error("No current file"); + return 0; + } + visitfile(p); + } + (void)display(1L, 0, pagesize, 1); + return 0; } static int do_error(long cnt) { /* Called when user types wrong key sequence */ - (void)cnt; - error(currmap->k_help); - return 0; + (void)cnt; + error(currmap->k_help); + return 0; } /* @@ -342,17 +342,17 @@ do_error(long cnt) static int prev_screen(int sz, int really) { - int retval; + int retval; - retval = scrollb(sz - 1, really && cflag); - if (really && !cflag) { - /* - * The previous call did not display anything, but at least we - * know where to start - */ - return display(scr_info.firstline, scr_info.nf, sz, 1); - } - return retval; + retval = scrollb(sz - 1, really && cflag); + if (really && !cflag) { + /* + * The previous call did not display anything, but at least we + * know where to start + */ + return display(scr_info.firstline, scr_info.nf, sz, 1); + } + return retval; } /* @@ -363,245 +363,243 @@ prev_screen(int sz, int really) static int next_screen(int sz, int really) { - int t; - struct scr_info *p = &scr_info; + int t; + struct scr_info *p = &scr_info; - if (cflag) { - return scrollf(sz - 1, really); - } - t = p->tail->cnt - 1; - if (p->lastline == p->firstline) { - t += p->nf; - } - return display(p->lastline, t, sz, really); + if (cflag) { + return scrollf(sz - 1, really); + } + t = p->tail->cnt - 1; + if (p->lastline == p->firstline) { + t += p->nf; + } + return display(p->lastline, t, sz, really); } static int do_redraw(long cnt) { - (void)cnt; - redraw(1); - return 0; + (void)cnt; + redraw(1); + return 0; } static int page_size(unsigned cnt) { - - if (cnt) { - if (cnt > (unsigned)maxpagesize) - return maxpagesize; - if (cnt < MINPAGESIZE) - return MINPAGESIZE; - return (int)cnt; - } - return pagesize; + if (cnt) { + if (cnt > (unsigned)maxpagesize) + return maxpagesize; + if (cnt < MINPAGESIZE) + return MINPAGESIZE; + return (int)cnt; + } + return pagesize; } static int do_forward(long cnt) { /* Display next page */ - int i; + int i; - i = page_size((unsigned)cnt); - if (status & EOFILE) { - /* - * May seem strange, but actually a visit to the next file - * has already been done here - */ - (void)display(1L, 0, i, 1); - return 0; - } - (void)next_screen(i, 1); - return 0; + i = page_size((unsigned)cnt); + if (status & EOFILE) { + /* + * May seem strange, but actually a visit to the next file + * has already been done here + */ + (void)display(1L, 0, i, 1); + return 0; + } + (void)next_screen(i, 1); + return 0; } static int do_backward(long cnt) { - int i, temp; - - i = page_size((unsigned)cnt); - if (!(status & START)) { - (void)prev_screen(i, 1); - return 0; - } - if (stdf < 0) { - (void)display(1L, 0, i, 1); - return 0; - } - /* - * The next part is a bit clumsy. - * We want to display the last page of the previous file (for which - * a visit has already been done), but the pagesize may temporarily - * be different because the command had a count - */ - temp = pagesize; - pagesize = i; - do_lline(cnt); - pagesize = temp; - return 0; + int i, temp; + + i = page_size((unsigned)cnt); + if (!(status & START)) { + (void)prev_screen(i, 1); + return 0; + } + if (stdf < 0) { + (void)display(1L, 0, i, 1); + return 0; + } + /* + * The next part is a bit clumsy. + * We want to display the last page of the previous file (for which + * a visit has already been done), but the pagesize may temporarily + * be different because the command had a count + */ + temp = pagesize; + pagesize = i; + do_lline(cnt); + pagesize = temp; + return 0; } static int do_firstline(long cnt) { /* Go to start of input */ - (void)cnt; - do_absolute(1L); - return 0; + (void)cnt; + do_absolute(1L); + return 0; } static int do_lline(long cnt) { /* Go to end of input */ - int i = 0; - int j = pagesize - 1; - - if ((cnt = to_lastline()) < 0) { - /* - * Interrupted by the user - */ - return 0; - } - /* - * Display the page such that only the last line of the page is - * a "~", independant of the pagesize - */ - while (!(display(cnt, i, j, 0) & EOFILE)) { - /* - * The last line could of course be very long ... - */ - i += j; - } - (void)scrollb(j - scr_info.tail->cnt, 0); - redraw(0); - return 0; + int i = 0; + int j = pagesize - 1; + + if ((cnt = to_lastline()) < 0) { + /* + * Interrupted by the user + */ + return 0; + } + /* + * Display the page such that only the last line of the page is + * a "~", independant of the pagesize + */ + while (!(display(cnt, i, j, 0) & EOFILE)) { + /* + * The last line could of course be very long ... + */ + i += j; + } + (void)scrollb(j - scr_info.tail->cnt, 0); + redraw(0); + return 0; } static int do_lf(long cnt) { /* Display next line, or go to line */ - if (cnt) { /* Go to line */ - do_absolute(cnt); - return 0; - } - (void)scrollf(1, 1); - return 0; + if (cnt) { /* Go to line */ + do_absolute(cnt); + return 0; + } + (void)scrollf(1, 1); + return 0; } static int do_upline(long cnt) { /* Display previous line, or go to line */ - if (cnt) { /* Go to line */ - do_absolute(cnt); - return 0; - } - (void)scrollb(1, 1); - return 0; + if (cnt) { /* Go to line */ + do_absolute(cnt); + return 0; + } + (void)scrollb(1, 1); + return 0; } static int do_skiplines(long cnt) { /* Skip lines forwards */ - /* Should be interruptable ... */ - (void)scrollf((int)(cnt + maxpagesize - 1), 0); - redraw(0); - return 0; + /* Should be interruptable ... */ + (void)scrollf((int)(cnt + maxpagesize - 1), 0); + redraw(0); + return 0; } static int do_bskiplines(long cnt) { /* Skip lines backwards */ - /* Should be interruptable ... */ - (void)scrollb((int)(cnt + pagesize - 1), 0); - redraw(0); - return 0; + /* Should be interruptable ... */ + (void)scrollb((int)(cnt + pagesize - 1), 0); + redraw(0); + return 0; } static int do_fscreens(long cnt) { /* Skip screens forwards */ - do { - if ((next_screen(pagesize, 0) & EOFILE) || interrupt) - break; - } while (--cnt >= 0); - redraw(0); - return 0; + do { + if ((next_screen(pagesize, 0) & EOFILE) || interrupt) + break; + } while (--cnt >= 0); + redraw(0); + return 0; } static int do_bscreens(long cnt) { /* Skip screens backwards */ - do { - if ((prev_screen(pagesize, 0) & START) || interrupt) - break; - } while (--cnt >= 0); - redraw(0); - return 0; + do { + if ((prev_screen(pagesize, 0) & START) || interrupt) + break; + } while (--cnt >= 0); + redraw(0); + return 0; } static int scro_size(unsigned cnt) { - - if (cnt >= (unsigned)maxpagesize) - return maxpagesize; - if (cnt) - return (int)cnt; - return scrollsize; + if (cnt >= (unsigned)maxpagesize) + return maxpagesize; + if (cnt) + return (int)cnt; + return scrollsize; } static int do_f_scroll(long cnt) { /* Scroll forwards */ - (void)scrollf(scro_size((unsigned)cnt), 1); - return 0; + (void)scrollf(scro_size((unsigned)cnt), 1); + return 0; } static int do_b_scroll(long cnt) { /* Scroll backwards */ - (void)scrollb(scro_size((unsigned)cnt), 1); - return 0; + (void)scrollb(scro_size((unsigned)cnt), 1); + return 0; } static int do_previousfile(long cnt) { /* Visit previous file */ - if (nextfile(-(int)cnt)) { - error("No (Nth) previous file"); - return 0; - } - redraw(0); - return 0; + if (nextfile(-(int)cnt)) { + error("No (Nth) previous file"); + return 0; + } + redraw(0); + return 0; } static int do_nextfile(long cnt) { /* Visit next file */ - if (nextfile((int)cnt)) { - error("No (Nth) next file"); - return 0; - } - redraw(0); - return 0; + if (nextfile((int)cnt)) { + error("No (Nth) next file"); + return 0; + } + redraw(0); + return 0; } static int do_quit(long cnt) { - (void)cnt; - return quit(); + (void)cnt; + return quit(); } /* @@ -611,44 +609,39 @@ do_quit(long cnt) struct commands commands[] = { {"", 0, do_error, ""}, {"", 0, do_nocomm, ""}, - {"bf", STICKY | NEEDS_COUNT, - do_previousfile, "Visit previous file"}, - {"bl", NEEDS_SCREEN | STICKY, - do_upline, "Scroll one line up, or go to line"}, - {"bot", STICKY, - do_lline, "Go to last line of the input"}, - {"bp", BACK | NEEDS_SCREEN | TOPREVFILE | STICKY, - do_backward, "display previous page"}, - {"bps", SCREENSIZE_ADAPT | BACK | NEEDS_SCREEN | TOPREVFILE | STICKY, - do_backward, "Display previous page, set pagesize"}, - {"bs", BACK | NEEDS_SCREEN | STICKY, - do_b_scroll, "Scroll backwards"}, + {"bf", STICKY | NEEDS_COUNT, do_previousfile, "Visit previous file"}, + {"bl", NEEDS_SCREEN | STICKY, do_upline, "Scroll one line up, or go to line"}, + {"bot", STICKY, do_lline, "Go to last line of the input"}, + {"bp", BACK | NEEDS_SCREEN | TOPREVFILE | STICKY, do_backward, "display previous page"}, + {"bps", + SCREENSIZE_ADAPT | BACK | NEEDS_SCREEN | TOPREVFILE | STICKY, + do_backward, + "Display previous page, set pagesize"}, + {"bs", BACK | NEEDS_SCREEN | STICKY, do_b_scroll, "Scroll backwards"}, {"bse", 0, do_bsearch, "Search backwards for pattern"}, - {"bsl", BACK | NEEDS_SCREEN | STICKY | NEEDS_COUNT, - do_bskiplines, "Skip lines backwards"}, - {"bsp", BACK | NEEDS_SCREEN | STICKY | NEEDS_COUNT, - do_bscreens, "Skip screens backwards"}, - {"bss", SCROLLSIZE_ADAPT | BACK | NEEDS_SCREEN | STICKY, - do_b_scroll, "Scroll backwards, set scrollsize"}, + {"bsl", BACK | NEEDS_SCREEN | STICKY | NEEDS_COUNT, do_bskiplines, "Skip lines backwards"}, + {"bsp", BACK | NEEDS_SCREEN | STICKY | NEEDS_COUNT, do_bscreens, "Skip screens backwards"}, + {"bss", + SCROLLSIZE_ADAPT | BACK | NEEDS_SCREEN | STICKY, + do_b_scroll, + "Scroll backwards, set scrollsize"}, {"chm", 0, do_chkm, "Switch to other keymap"}, {"exg", STICKY, exgmark, "Exchange current page with mark"}, - {"ff", STICKY | NEEDS_COUNT, - do_nextfile, "Visit next file"}, - {"fl", NEEDS_SCREEN | STICKY, - do_lf, "Scroll one line down, or go to line"}, - {"fp", TONEXTFILE | AHEAD | STICKY, - do_forward, "Display next page"}, - {"fps", SCREENSIZE_ADAPT | TONEXTFILE | AHEAD | STICKY, - do_forward, "Display next page, set pagesize"}, - {"fs", AHEAD | NEEDS_SCREEN | STICKY, - do_f_scroll, "Scroll forwards"}, + {"ff", STICKY | NEEDS_COUNT, do_nextfile, "Visit next file"}, + {"fl", NEEDS_SCREEN | STICKY, do_lf, "Scroll one line down, or go to line"}, + {"fp", TONEXTFILE | AHEAD | STICKY, do_forward, "Display next page"}, + {"fps", + SCREENSIZE_ADAPT | TONEXTFILE | AHEAD | STICKY, + do_forward, + "Display next page, set pagesize"}, + {"fs", AHEAD | NEEDS_SCREEN | STICKY, do_f_scroll, "Scroll forwards"}, {"fse", 0, do_fsearch, "Search forwards for pattern"}, - {"fsl", AHEAD | NEEDS_SCREEN | STICKY | NEEDS_COUNT, - do_skiplines, "Skip lines forwards"}, - {"fsp", AHEAD | NEEDS_SCREEN | STICKY | NEEDS_COUNT, - do_fscreens, "Skip screens forwards"}, - {"fss", SCROLLSIZE_ADAPT | AHEAD | NEEDS_SCREEN | STICKY, - do_f_scroll, "Scroll forwards, set scrollsize"}, + {"fsl", AHEAD | NEEDS_SCREEN | STICKY | NEEDS_COUNT, do_skiplines, "Skip lines forwards"}, + {"fsp", AHEAD | NEEDS_SCREEN | STICKY | NEEDS_COUNT, do_fscreens, "Skip screens forwards"}, + {"fss", + SCROLLSIZE_ADAPT | AHEAD | NEEDS_SCREEN | STICKY, + do_f_scroll, + "Scroll forwards, set scrollsize"}, {"hlp", 0, do_help, "Give description of all commands"}, {"mar", 0, setmark, "Set a mark on the current page"}, {"nse", STICKY, do_nsearch, "Repeat the last search"}, @@ -672,37 +665,37 @@ struct commands commands[] = { int lookup(char *s) { - struct commands *l, *u, *m; - - l = &commands[2]; - u = &commands[sizeof(commands) / sizeof(*u) - 1]; - do { - /* - * Perform binary search - */ - m = l + (u - l) / 2; - if (strcmp(s, m->c_cmd) > 0) - l = m + 1; - else - u = m; - } while (l < u); - if (!strcmp(s, u->c_cmd)) - return u - commands; - return 0; + struct commands *l, *u, *m; + + l = &commands[2]; + u = &commands[sizeof(commands) / sizeof(*u) - 1]; + do { + /* + * Perform binary search + */ + m = l + (u - l) / 2; + if (strcmp(s, m->c_cmd) > 0) + l = m + 1; + else + u = m; + } while (l < u); + if (!strcmp(s, u->c_cmd)) + return u - commands; + return 0; } /*ARGSUSED*/ static int do_lcomm(long cnt) { /* Repeat last command */ - (void)cnt; + (void)cnt; - if (!lastcomm) { - error("No previous command"); - return 0; - } - do_comm(lastcomm, lastcount); - return 0; + if (!lastcomm) { + error("No previous command"); + return 0; + } + do_comm(lastcomm, lastcount); + return 0; } /* @@ -712,74 +705,74 @@ do_lcomm(long cnt) void do_comm(int comm, long count) { - struct commands *pcomm; - int temp; - int flags; - - pcomm = &commands[comm]; - flags = pcomm->c_flags; - - /* - * Check the command. - * If the last line of the file is displayed and the command goes - * forwards and does'nt have the ability to go to the next file, it - * is an error. - * If the first line of the file is displayed and the command goes - * backwards and does'nt have the ability to go to the previous file, - * it is an error. - * Also check wether we need the next or previous file. If so, get it. - */ - if ((status & EOFILE) && (flags & AHEAD)) { - if (qflag || !(flags & TONEXTFILE)) - return; - if (nextfile(1)) - quit(); - } - if ((status & START) && (flags & BACK)) { - if (qflag || !(flags & TOPREVFILE)) - return; - if (nextfile(-1)) - quit(); - } - /* - * Does the command stick around for LASTCOMM? - */ - if (flags & STICKY) { - lastcomm = comm; - lastcount = count; - } - if (!count) { - if (flags & NEEDS_COUNT) - count = 1; - } else { - /* - * Does the command adapt the screensize? - */ - if (flags & SCREENSIZE_ADAPT) { - temp = maxpagesize; - if ((unsigned)count < (unsigned)temp) { - temp = (int)count; - } - if (temp < MINPAGESIZE) { - temp = MINPAGESIZE; - } - count = 0; - pagesize = temp; - } - /* - * Does the command adapt the scrollsize? - */ - if (flags & SCROLLSIZE_ADAPT) { - temp = maxpagesize - 1; - if ((unsigned)count < (unsigned)temp) { - temp = (int)count; - } - scrollsize = temp; - count = 0; - } - } - /* - * Now execute the command. - */ - (*(pcomm->c_func))(count); + struct commands *pcomm; + int temp; + int flags; + + pcomm = &commands[comm]; + flags = pcomm->c_flags; + + /* + * Check the command. + * If the last line of the file is displayed and the command goes + * forwards and does'nt have the ability to go to the next file, it + * is an error. + * If the first line of the file is displayed and the command goes + * backwards and does'nt have the ability to go to the previous file, + * it is an error. + * Also check wether we need the next or previous file. If so, get it. + */ + if ((status & EOFILE) && (flags & AHEAD)) { + if (qflag || !(flags & TONEXTFILE)) + return; + if (nextfile(1)) + quit(); + } + if ((status & START) && (flags & BACK)) { + if (qflag || !(flags & TOPREVFILE)) + return; + if (nextfile(-1)) + quit(); + } + /* + * Does the command stick around for LASTCOMM? + */ + if (flags & STICKY) { + lastcomm = comm; + lastcount = count; + } + if (!count) { + if (flags & NEEDS_COUNT) + count = 1; + } else { + /* + * Does the command adapt the screensize? + */ + if (flags & SCREENSIZE_ADAPT) { + temp = maxpagesize; + if ((unsigned)count < (unsigned)temp) { + temp = (int)count; + } + if (temp < MINPAGESIZE) { + temp = MINPAGESIZE; + } + count = 0; + pagesize = temp; + } + /* + * Does the command adapt the scrollsize? + */ + if (flags & SCROLLSIZE_ADAPT) { + temp = maxpagesize - 1; + if ((unsigned)count < (unsigned)temp) { + temp = (int)count; + } + scrollsize = temp; + count = 0; + } + } + /* + * Now execute the command. + */ + (*(pcomm->c_func))(count); } diff --git a/cmd/extra/yap/commands.h b/cmd/extra/yap/commands.h @@ -3,25 +3,25 @@ #define SCREENSIZE_ADAPT 01 #define SCROLLSIZE_ADAPT 02 -#define TONEXTFILE 04 -#define AHEAD 010 -#define BACK 020 -#define NEEDS_SCREEN 040 -#define TOPREVFILE 0100 -#define STICKY 0200 -#define NEEDS_COUNT 0400 -#define ESC 01000 +#define TONEXTFILE 04 +#define AHEAD 010 +#define BACK 020 +#define NEEDS_SCREEN 040 +#define TOPREVFILE 0100 +#define STICKY 0200 +#define NEEDS_COUNT 0400 +#define ESC 01000 extern struct commands { - char *c_cmd; - int c_flags; - int (*c_func)(long); - char *c_descr; + char *c_cmd; + int c_flags; + int (*c_func)(long); + char *c_descr; } commands[]; -int do_chkm(long cnt); +int do_chkm(long cnt); void do_comm(int command, long count); -int lookup(char *str); +int lookup(char *str); void wrt_fd(int fd); #endif diff --git a/cmd/extra/yap/display.c b/cmd/extra/yap/display.c @@ -1,32 +1,31 @@ /* Copyright (c) 1985 Ceriel J.H. Jacobs */ -#include "in_all.h" #include "display.h" #include "assert.h" +#include "getline.h" +#include "in_all.h" #include "machine.h" -#include "term.h" -#include "output.h" +#include "main.h" #include "options.h" +#include "output.h" #include "process.h" -#include "getline.h" -#include "main.h" +#include "term.h" #define getline yap_getline #include "utf.h" #undef getline #include "ansi.h" -int pagesize; -int maxpagesize; -int scrollsize; +int pagesize; +int maxpagesize; +int scrollsize; struct scr_info scr_info; -int status; +int status; static char *do_line(char *str, int reallydispl); -static void flush_display_buffer(char *buf, char **p); -static int rune_width(Rune r); -static int decode_cell(const char *s, const char **next, int *width, - int *is_underscore); -int wcwidth(wchar_t wc); +static void flush_display_buffer(char *buf, char **p); +static int rune_width(Rune r); +static int decode_cell(const char *s, const char **next, int *width, int *is_underscore); +int wcwidth(wchar_t wc); /* * Fill n lines of the screen, each with "str". @@ -35,10 +34,9 @@ int wcwidth(wchar_t wc); static void fillscr(char *str, int n) { - - while (n-- > 0) { - putline(str); - } + while (n-- > 0) { + putline(str); + } } /* @@ -48,12 +46,11 @@ fillscr(char *str, int n) static char * skiplines(char *p, int n) { - - while (n-- > 0) { - p = do_line(p, 0); - scr_info.currentpos--; - } - return p; + while (n-- > 0) { + p = do_line(p, 0); + scr_info.currentpos--; + } + return p; } /* @@ -65,14 +62,14 @@ skiplines(char *p, int n) void redraw(int n) { - struct scr_info *p = &scr_info; - int i; - - i = pagesize; - if (n && p->currentpos) { - i = p->currentpos; - } - (void)display(p->firstline, p->nf, i, 1); + struct scr_info *p = &scr_info; + int i; + + i = pagesize; + if (n && p->currentpos) { + i = p->currentpos; + } + (void)display(p->firstline, p->nf, i, 1); } /* @@ -85,18 +82,18 @@ redraw(int n) static int compretval(const char *s) { - int i; - struct scr_info *p = &scr_info; - - i = 0; - if (!s || (!*s && !getline(p->lastline + 1, 1))) { - i = EOFILE; - } - if (p->firstline == 1 && !p->nf) { - i |= START; - } - status = i; - return i; + int i; + struct scr_info *p = &scr_info; + + i = 0; + if (!s || (!*s && !getline(p->lastline + 1, 1))) { + i = EOFILE; + } + if (p->firstline == 1 && !p->nf) { + i |= START; + } + status = i; + return i; } /* @@ -109,71 +106,70 @@ compretval(const char *s) int display(long n, int nd, int nlines, int reallydispl) { - - struct scr_info *s = &scr_info; - char *p; /* pointer to line to be displayed */ - - if (startcomm) { /* No displaying on a command from the - * yap command line. In this case, displaying - * will be done after executing the command, - * by a redraw. - */ - reallydispl = 0; - } - if (!n) { - n = 1L; - nd = 0; - } - if (reallydispl) { /* move cursor to starting point */ - if (stupid) { - putline(currentfile); - putline(", line "); - prnum(n); - nlines--; - } - if (cflag) { - putline("\r\n"); - } else { - home(); - clrscreen(); - } - } - /* - * Now, do computations and display - */ - s->currentpos = 0; - s->nf = nd; - s->head = s->tail; - s->tail->cnt = 0; - s->tail->line = n; - p = skiplines(getline(n, 1), nd); - while (nlines && p) { - /* - * While there is room, - * and there is something left to display ... - */ - (s->tail->cnt)++; - nlines--; - if (*(p = do_line(p, reallydispl)) == '\0') { - /* - * File-line finished, get next one ... - */ - p = getline(++n, 1); - if (nlines && p) { - s->tail = s->tail->next; - s->tail->cnt = 0; - s->tail->line = n; - } - } - } - if (!stupid) { - s->currentpos += nlines; - if (reallydispl) { - fillscr("~\r\n", nlines); - fillscr("\r\n", maxpagesize - s->currentpos); - } - } - return compretval(p); + struct scr_info *s = &scr_info; + char *p; /* pointer to line to be displayed */ + + if (startcomm) { /* No displaying on a command from the + * yap command line. In this case, displaying + * will be done after executing the command, + * by a redraw. + */ + reallydispl = 0; + } + if (!n) { + n = 1L; + nd = 0; + } + if (reallydispl) { /* move cursor to starting point */ + if (stupid) { + putline(currentfile); + putline(", line "); + prnum(n); + nlines--; + } + if (cflag) { + putline("\r\n"); + } else { + home(); + clrscreen(); + } + } + /* + * Now, do computations and display + */ + s->currentpos = 0; + s->nf = nd; + s->head = s->tail; + s->tail->cnt = 0; + s->tail->line = n; + p = skiplines(getline(n, 1), nd); + while (nlines && p) { + /* + * While there is room, + * and there is something left to display ... + */ + (s->tail->cnt)++; + nlines--; + if (*(p = do_line(p, reallydispl)) == '\0') { + /* + * File-line finished, get next one ... + */ + p = getline(++n, 1); + if (nlines && p) { + s->tail = s->tail->next; + s->tail->cnt = 0; + s->tail->line = n; + } + } + } + if (!stupid) { + s->currentpos += nlines; + if (reallydispl) { + fillscr("~\r\n", nlines); + fillscr("\r\n", maxpagesize - s->currentpos); + } + } + return compretval(p); } /* @@ -183,71 +179,70 @@ display(long n, int nd, int nlines, int reallydispl) int scrollf(int n, int reallydispl) { - - struct scr_info *s = &scr_info; - char *p; - long ll; - int i; - - /* - * First, find out how many screenlines of the last line were already - * on the screen, and possibly above it. - */ - - if (n <= 0 || (status & EOFILE)) - return status; - if (startcomm) - reallydispl = 0; - /* - * Find out where to begin displaying - */ - i = s->tail->cnt; - if ((ll = s->lastline) == s->firstline) - i += s->nf; - p = skiplines(getline(ll, 1), i); - /* - * Now, place the cursor at the first free line - */ - if (reallydispl && !stupid) { - clrbline(); - mgoto(s->currentpos); - } - /* - * Now display lines, keeping track of which lines are on the screen. - */ - while (n-- > 0) { /* There are still rows to be displayed */ - if (!*p) { /* End of line, get next one */ - if (!(p = getline(++ll, 1))) { - /* - * No lines left. At end of file - */ - break; - } - s->tail = s->tail->next; - s->tail->cnt = 0; - s->tail->line = ll; - } - if (s->currentpos >= maxpagesize) { - /* - * No room, delete first screen-line - */ - s->currentpos--; - s->nf++; - if (--(s->head->cnt) == 0) { - /* - * The first file-line on the screen is wiped - * out completely; update administration - * accordingly. - */ - s->nf = 0; - s->head = s->head->next; - assert(s->head->cnt > 0); - } - } - s->tail->cnt++; - p = do_line(p, reallydispl); - } - return compretval(p); + struct scr_info *s = &scr_info; + char *p; + long ll; + int i; + + /* + * First, find out how many screenlines of the last line were already + * on the screen, and possibly above it. + */ + + if (n <= 0 || (status & EOFILE)) + return status; + if (startcomm) + reallydispl = 0; + /* + * Find out where to begin displaying + */ + i = s->tail->cnt; + if ((ll = s->lastline) == s->firstline) + i += s->nf; + p = skiplines(getline(ll, 1), i); + /* + * Now, place the cursor at the first free line + */ + if (reallydispl && !stupid) { + clrbline(); + mgoto(s->currentpos); + } + /* + * Now display lines, keeping track of which lines are on the screen. + */ + while (n-- > 0) { /* There are still rows to be displayed */ + if (!*p) { /* End of line, get next one */ + if (!(p = getline(++ll, 1))) { + /* + * No lines left. At end of file + */ + break; + } + s->tail = s->tail->next; + s->tail->cnt = 0; + s->tail->line = ll; + } + if (s->currentpos >= maxpagesize) { + /* + * No room, delete first screen-line + */ + s->currentpos--; + s->nf++; + if (--(s->head->cnt) == 0) { + /* + * The first file-line on the screen is wiped + * out completely; update administration + * accordingly. + */ + s->nf = 0; + s->head = s->head->next; + assert(s->head->cnt > 0); + } + } + s->tail->cnt++; + p = do_line(p, reallydispl); + } + return compretval(p); } /* @@ -257,109 +252,105 @@ scrollf(int n, int reallydispl) int scrollb(int n, int reallydispl) { - - struct scr_info *s = &scr_info; - char *p; /* Holds string to be displayed */ - int i; - int count; - long ln; /* a line number */ - int nodispl; - int cannotscroll; /* stupid or no insert-line */ - - /* - * First, find out where to start - */ - if ((count = n) <= 0 || (status & START)) - return status; - if (startcomm) - reallydispl = 0; - cannotscroll = stupid || (!*AL && !*SR); - ln = s->firstline; - nodispl = s->nf; - while (count) { /* While scrolling back ... */ - i = nodispl; - if (i) { - /* - * There were screen-lines of s->firstline that were not - * displayed. - * We can use them now, but only "count" of them. - */ - if (i > count) - i = count; - s->currentpos += i; - nodispl -= i; - count -= i; - } else { /* Get previous line */ - if (ln == 1) - break; /* isn't there ... */ - p = getline(--ln, 1); - /* - * Make it the first line of the screen and compute - * how many screenlines it takes. These lines are not - * displayed, but nodispl is set to this count, so - * that it will be nonzero next time around - */ - nodispl = 0; - do { /* Find out how many screenlines */ - nodispl++; - p = skiplines(p, 1); - } while (*p); - } - } - n -= count; - if ((i = s->currentpos) > maxpagesize) - i = maxpagesize; - if (reallydispl && hardcopy) - i = n; - /* - * Now that we know where to start, we can use "display" to do the - * rest of the computing for us, and maybe even the displaying ... - */ - i = display(ln, - nodispl, - i, - reallydispl && cannotscroll); - if (cannotscroll || !reallydispl) { - /* - * Yes, "display" did the displaying, or we did'nt have to - * display at all. - * I like it, but the user obviously does not. - * Let him buy another (smarter) terminal ... - */ - return i; - } - /* - * Now, all we have to do is the displaying. And we are dealing with - * a smart terminal (it can insert lines or scroll back). - */ - home(); - /* - * Insert lines all at once - */ - for (i = n; i; i--) { - if (DB && *CE) { - /* - * Grumble..., terminal retains lines below, so we have - * to clear the lines that we push off the screen - */ - clrbline(); - home(); - } - if (*SR) { - scrollreverse(); - } else { - insert_line(0); - } - } - p = skiplines(getline(ln = s->firstline, 1), s->nf); - for (i = 0; i < n; i++) { - p = do_line(p, 1); - s->currentpos--; - if (!*p) { - p = getline(++ln, 1); - } - } - return count; + struct scr_info *s = &scr_info; + char *p; /* Holds string to be displayed */ + int i; + int count; + long ln; /* a line number */ + int nodispl; + int cannotscroll; /* stupid or no insert-line */ + + /* + * First, find out where to start + */ + if ((count = n) <= 0 || (status & START)) + return status; + if (startcomm) + reallydispl = 0; + cannotscroll = stupid || (!*AL && !*SR); + ln = s->firstline; + nodispl = s->nf; + while (count) { /* While scrolling back ... */ + i = nodispl; + if (i) { + /* + * There were screen-lines of s->firstline that were not + * displayed. + * We can use them now, but only "count" of them. + */ + if (i > count) + i = count; + s->currentpos += i; + nodispl -= i; + count -= i; + } else { /* Get previous line */ + if (ln == 1) + break; /* isn't there ... */ + p = getline(--ln, 1); + /* + * Make it the first line of the screen and compute + * how many screenlines it takes. These lines are not + * displayed, but nodispl is set to this count, so + * that it will be nonzero next time around + */ + nodispl = 0; + do { /* Find out how many screenlines */ + nodispl++; + p = skiplines(p, 1); + } while (*p); + } + } + n -= count; + if ((i = s->currentpos) > maxpagesize) + i = maxpagesize; + if (reallydispl && hardcopy) + i = n; + /* + * Now that we know where to start, we can use "display" to do the + * rest of the computing for us, and maybe even the displaying ... + */ + i = display(ln, nodispl, i, reallydispl && cannotscroll); + if (cannotscroll || !reallydispl) { + /* + * Yes, "display" did the displaying, or we did'nt have to + * display at all. + * I like it, but the user obviously does not. + * Let him buy another (smarter) terminal ... + */ + return i; + } + /* + * Now, all we have to do is the displaying. And we are dealing with + * a smart terminal (it can insert lines or scroll back). + */ + home(); + /* + * Insert lines all at once + */ + for (i = n; i; i--) { + if (DB && *CE) { + /* + * Grumble..., terminal retains lines below, so we have + * to clear the lines that we push off the screen + */ + clrbline(); + home(); + } + if (*SR) { + scrollreverse(); + } else { + insert_line(0); + } + } + p = skiplines(getline(ln = s->firstline, 1), s->nf); + for (i = 0; i < n; i++) { + p = do_line(p, 1); + s->currentpos--; + if (!*p) { + p = getline(++ln, 1); + } + } + return count; } /* @@ -370,323 +361,318 @@ scrollb(int n, int reallydispl) static char * do_line(char *str, int reallydispl) { - char buf[1024]; - char *p = buf; - int pos = COLS; - int do_ul = 0, do_hl = 0; - int lastmode = 0, lasthlmode = 0; - int c2; - int cell_width; - int tab_width; - int is_underscore; - int cell_len; - int next_len; - int next_is_underscore; - unsigned char uc; - const char *cell_start; - const char *cursor; - const char *next; - enum ansi_kind ansi_kind; - - while (*str && pos > 0) { - uc = (unsigned char)*str; - if (uc == 0x1b && ansi_escape(str, &next, &ansi_kind)) { - if (ansi_kind == ANSI_SGR) { - cell_len = next - str; - if (reallydispl && - p + cell_len >= &buf[sizeof(buf) - 1]) { - flush_display_buffer(buf, &p); - } - if (reallydispl) { - (void)memcpy(p, str, (size_t)cell_len); - p += cell_len; - } - } - str = (char *)next; - continue; - } - if (uc < ' ' && (cell_len = match(str, &c2, sppat)) > 0) { - /* - * We found a string that matches, and thus must be - * echoed literally - */ - if ((pos - c2) <= 0) { - /* - * It did not fit - */ - break; - } - pos -= c2; - if (reallydispl) { - flush_display_buffer(buf, &p); - cell_start = str; - str += cell_len; - uc = (unsigned char)*str; - *str = '\0'; - putline((char *)cell_start); - *str = (char)uc; - } else { - str += cell_len; - } - continue; - } - - cell_start = str; - cell_len = decode_cell(str, &next, &cell_width, &is_underscore); - cursor = next; - do_hl = 0; - if (*cursor == '\b' && *(cursor + 1) != '\0') { - next_len = decode_cell(cursor + 1, &next, &tab_width, - &next_is_underscore); - if (!(is_underscore && *(cursor + 1 + next_len) != '\b')) { - while (*cursor == '\b' && *(cursor + 1) != '\0') { - cell_start = cursor + 1; - cell_len = decode_cell(cell_start, &next, &cell_width, - &is_underscore); - cursor = next; - do_hl = 1; - } - } - } - do_ul = 1; - /* - * Find underline sequences ... - */ - if (is_underscore && *cursor == '\b' && *(cursor + 1) != '\0') { - cell_start = cursor + 1; - cell_len = decode_cell(cell_start, &next, &cell_width, - &is_underscore); - cursor = next; - } else { - if (*cursor == '\b' && *(cursor + 1) == '_') { - cursor += 2; - } else { - do_ul = 0; - } - } - if (cell_width == -1) { - tab_width = 8 - ((COLS - pos) & 0x07); - if (pos - tab_width < 0) { - break; - } - } else if (cell_width == -2) { - if (pos <= 1) { - break; - } - } else if (cell_width > pos) { - break; - } - if (reallydispl && do_hl != lasthlmode) { - flush_display_buffer(buf, &p); - if (do_hl) { - bold(); - } else { - end_bold(); - } - } - lasthlmode = do_hl; - if (reallydispl && do_ul != lastmode) { - flush_display_buffer(buf, &p); - if (do_ul) { - underline(); - } else { - end_underline(); - } - } - lastmode = do_ul; - if (cell_width == -1) { - pos -= tab_width; - if (reallydispl) { - if (expandtabs) { - while (tab_width-- > 0) { - *p++ = ' '; - } - } else { - flush_display_buffer(buf, &p); - givetab(); - } - } - str = (char *)cursor; - continue; - } - if (reallydispl && p + cell_len >= &buf[sizeof(buf) - 1]) { - flush_display_buffer(buf, &p); - } - if (cell_width == -2) { - if (reallydispl) { - if (p + 2 >= &buf[sizeof(buf) - 1]) { - flush_display_buffer(buf, &p); - } - *p++ = '^'; - *p++ = *cell_start ^ 0x40; - } - pos -= 2; - str = (char *)cursor; - continue; - } - if (reallydispl) { - (void)memcpy(p, cell_start, (size_t)cell_len); - p += cell_len; - } - if (cell_width >= 0) { - pos -= cell_width; - if (reallydispl && do_ul && *UC && cell_width == 1 && pos > 0) { - /* - * Underlining apparently is done one - * character at a time. - */ - flush_display_buffer(buf, &p); - backspace(); - underchar(); - } - str = (char *)cursor; - continue; - } - str = (char *)cursor; - } - if (reallydispl) { - flush_display_buffer(buf, &p); - if (pos > 0 || (pos <= 0 && (!AM || XN))) { - putline("\r\n"); - } - /* - * The next should be here! I.e. it may not be before printing - * the newline. This has to do with XN. We don't know exactly - * WHEN the terminal will stop ignoring the newline. - * I have for example a terminal (Ampex a230) that will - * continue to ignore the newline after a clear to end of line - * sequence, but not after an end_underline sequence. - */ - if (lastmode) { - end_underline(); - } - if (lasthlmode) { - end_bold(); - } - } - scr_info.currentpos++; - return str; + char buf[1024]; + char *p = buf; + int pos = COLS; + int do_ul = 0, do_hl = 0; + int lastmode = 0, lasthlmode = 0; + int c2; + int cell_width; + int tab_width; + int is_underscore; + int cell_len; + int next_len; + int next_is_underscore; + unsigned char uc; + const char *cell_start; + const char *cursor; + const char *next; + enum ansi_kind ansi_kind; + + while (*str && pos > 0) { + uc = (unsigned char)*str; + if (uc == 0x1b && ansi_escape(str, &next, &ansi_kind)) { + if (ansi_kind == ANSI_SGR) { + cell_len = next - str; + if (reallydispl && p + cell_len >= &buf[sizeof(buf) - 1]) { + flush_display_buffer(buf, &p); + } + if (reallydispl) { + (void)memcpy(p, str, (size_t)cell_len); + p += cell_len; + } + } + str = (char *)next; + continue; + } + if (uc < ' ' && (cell_len = match(str, &c2, sppat)) > 0) { + /* + * We found a string that matches, and thus must be + * echoed literally + */ + if ((pos - c2) <= 0) { + /* + * It did not fit + */ + break; + } + pos -= c2; + if (reallydispl) { + flush_display_buffer(buf, &p); + cell_start = str; + str += cell_len; + uc = (unsigned char)*str; + *str = '\0'; + putline((char *)cell_start); + *str = (char)uc; + } else { + str += cell_len; + } + continue; + } + + cell_start = str; + cell_len = decode_cell(str, &next, &cell_width, &is_underscore); + cursor = next; + do_hl = 0; + if (*cursor == '\b' && *(cursor + 1) != '\0') { + next_len = decode_cell(cursor + 1, &next, &tab_width, &next_is_underscore); + if (!(is_underscore && *(cursor + 1 + next_len) != '\b')) { + while (*cursor == '\b' && *(cursor + 1) != '\0') { + cell_start = cursor + 1; + cell_len = decode_cell(cell_start, &next, &cell_width, &is_underscore); + cursor = next; + do_hl = 1; + } + } + } + do_ul = 1; + /* + * Find underline sequences ... + */ + if (is_underscore && *cursor == '\b' && *(cursor + 1) != '\0') { + cell_start = cursor + 1; + cell_len = decode_cell(cell_start, &next, &cell_width, &is_underscore); + cursor = next; + } else { + if (*cursor == '\b' && *(cursor + 1) == '_') { + cursor += 2; + } else { + do_ul = 0; + } + } + if (cell_width == -1) { + tab_width = 8 - ((COLS - pos) & 0x07); + if (pos - tab_width < 0) { + break; + } + } else if (cell_width == -2) { + if (pos <= 1) { + break; + } + } else if (cell_width > pos) { + break; + } + if (reallydispl && do_hl != lasthlmode) { + flush_display_buffer(buf, &p); + if (do_hl) { + bold(); + } else { + end_bold(); + } + } + lasthlmode = do_hl; + if (reallydispl && do_ul != lastmode) { + flush_display_buffer(buf, &p); + if (do_ul) { + underline(); + } else { + end_underline(); + } + } + lastmode = do_ul; + if (cell_width == -1) { + pos -= tab_width; + if (reallydispl) { + if (expandtabs) { + while (tab_width-- > 0) { + *p++ = ' '; + } + } else { + flush_display_buffer(buf, &p); + givetab(); + } + } + str = (char *)cursor; + continue; + } + if (reallydispl && p + cell_len >= &buf[sizeof(buf) - 1]) { + flush_display_buffer(buf, &p); + } + if (cell_width == -2) { + if (reallydispl) { + if (p + 2 >= &buf[sizeof(buf) - 1]) { + flush_display_buffer(buf, &p); + } + *p++ = '^'; + *p++ = *cell_start ^ 0x40; + } + pos -= 2; + str = (char *)cursor; + continue; + } + if (reallydispl) { + (void)memcpy(p, cell_start, (size_t)cell_len); + p += cell_len; + } + if (cell_width >= 0) { + pos -= cell_width; + if (reallydispl && do_ul && *UC && cell_width == 1 && pos > 0) { + /* + * Underlining apparently is done one + * character at a time. + */ + flush_display_buffer(buf, &p); + backspace(); + underchar(); + } + str = (char *)cursor; + continue; + } + str = (char *)cursor; + } + if (reallydispl) { + flush_display_buffer(buf, &p); + if (pos > 0 || (pos <= 0 && (!AM || XN))) { + putline("\r\n"); + } + /* + * The next should be here! I.e. it may not be before printing + * the newline. This has to do with XN. We don't know exactly + * WHEN the terminal will stop ignoring the newline. + * I have for example a terminal (Ampex a230) that will + * continue to ignore the newline after a clear to end of line + * sequence, but not after an end_underline sequence. + */ + if (lastmode) { + end_underline(); + } + if (lasthlmode) { + end_bold(); + } + } + scr_info.currentpos++; + return str; } static void flush_display_buffer(char *buf, char **p) { - if (*p == buf) { - return; - } - **p = '\0'; - putline(buf); - *p = buf; + if (*p == buf) { + return; + } + **p = '\0'; + putline(buf); + *p = buf; } static int rune_width(Rune r) { - int width; + int width; - width = wcwidth((wchar_t)r); - if (width < 0) { - return 1; - } - return width; + width = wcwidth((wchar_t)r); + if (width < 0) { + return 1; + } + return width; } static int decode_cell(const char *s, const char **next, int *width, int *is_underscore) { - const char *p; - Rune r; - Rune mark; - int len; - int mark_len; - int mark_width; - - len = chartorune(&r, s); - if (len <= 0) { - len = 1; - r = Runeerror; - } - *is_underscore = (len == 1 && *s == '_'); - if (*s == '\t') { - *width = -1; - *next = s + 1; - return 1; - } - if ((unsigned char)*s < ' ' || (unsigned char)*s == 0x7f) { - *width = -2; - *next = s + 1; - return 1; - } - *width = rune_width(r); - p = s + len; - while (*p) { - if (*p == '\b' || *p == '\t' || (unsigned char)*p < ' ' || - (unsigned char)*p == 0x7f) { - break; - } - mark_len = chartorune(&mark, p); - if (mark_len <= 0) { - break; - } - mark_width = rune_width(mark); - if (mark_width != 0) { - break; - } - p += mark_len; - len += mark_len; - } - *next = p; - return len; + const char *p; + Rune r; + Rune mark; + int len; + int mark_len; + int mark_width; + + len = chartorune(&r, s); + if (len <= 0) { + len = 1; + r = Runeerror; + } + *is_underscore = (len == 1 && *s == '_'); + if (*s == '\t') { + *width = -1; + *next = s + 1; + return 1; + } + if ((unsigned char)*s < ' ' || (unsigned char)*s == 0x7f) { + *width = -2; + *next = s + 1; + return 1; + } + *width = rune_width(r); + p = s + len; + while (*p) { + if (*p == '\b' || *p == '\t' || (unsigned char)*p < ' ' || (unsigned char)*p == 0x7f) { + break; + } + mark_len = chartorune(&mark, p); + if (mark_len <= 0) { + break; + } + mark_width = rune_width(mark); + if (mark_width != 0) { + break; + } + p += mark_len; + len += mark_len; + } + *next = p; + return len; } /* ARGSUSED */ int setmark(long cnt) { /* Set a mark on the current page */ - struct scr_info *p = &scr_info; - (void)cnt; + struct scr_info *p = &scr_info; + (void)cnt; - p->savfirst = p->firstline; - p->savnf = p->nf; - return 0; + p->savfirst = p->firstline; + p->savnf = p->nf; + return 0; } /* ARGSUSED */ int tomark(long cnt) { /* Go to the mark */ - struct scr_info *p = &scr_info; - (void)cnt; + struct scr_info *p = &scr_info; + (void)cnt; - (void)display(p->savfirst, p->savnf, pagesize, 1); - return 0; + (void)display(p->savfirst, p->savnf, pagesize, 1); + return 0; } /* ARGSUSED */ int exgmark(long cnt) { /* Exchange mark and current page */ - struct scr_info *p = &scr_info; - long svfirst; - int svnf; - (void)cnt; - - svfirst = p->firstline; - svnf = p->nf; - tomark(0L); - p->savfirst = svfirst; - p->savnf = svnf; - return 0; + struct scr_info *p = &scr_info; + long svfirst; + int svnf; + (void)cnt; + + svfirst = p->firstline; + svnf = p->nf; + tomark(0L); + p->savfirst = svfirst; + p->savnf = svnf; + return 0; } void d_clean() { /* Clean up */ - struct scr_info *p = &scr_info; + struct scr_info *p = &scr_info; - p->savnf = 0; - p->savfirst = 0; - p->head = p->tail; - p->head->line = 0; - p->currentpos = 0; + p->savnf = 0; + p->savfirst = 0; + p->head = p->tail; + p->head->line = 0; + p->currentpos = 0; } diff --git a/cmd/extra/yap/display.h b/cmd/extra/yap/display.h @@ -8,34 +8,34 @@ extern int maxpagesize; extern int scrollsize; struct scr_info { - struct linelist { - int cnt; - long line; + struct linelist { + int cnt; + long line; #define firstline head->line -#define lastline tail->line - struct linelist *next; - struct linelist *prev; - } *tail, *head; - int nf; - int currentpos; - struct linelist ssaavv; +#define lastline tail->line + struct linelist *next; + struct linelist *prev; + } *tail, *head; + int nf; + int currentpos; + struct linelist ssaavv; #define savfirst ssaavv.line -#define savnf ssaavv.cnt +#define savnf ssaavv.cnt }; extern struct scr_info scr_info; -extern int status; +extern int status; #define EOFILE 01 -#define START 02 +#define START 02 void redraw(int flag); -int display(long first_line, int nodispl, int nlines, int really); -int scrollf(int nlines, int really); -int scrollb(int nlines, int really); -int tomark(long cnt); -int setmark(long cnt); -int exgmark(long cnt); +int display(long first_line, int nodispl, int nlines, int really); +int scrollf(int nlines, int really); +int scrollb(int nlines, int really); +int tomark(long cnt); +int setmark(long cnt); +int exgmark(long cnt); void d_clean(void); #endif diff --git a/cmd/extra/yap/getcomm.c b/cmd/extra/yap/getcomm.c @@ -4,22 +4,22 @@ * Command reader, also executes shell escapes */ -#include <ctype.h> -#include "in_all.h" -#include "term.h" -#include "process.h" #include "getcomm.h" +#include "assert.h" #include "commands.h" -#include "prompt.h" -#include "main.h" -#include "output.h" +#include "display.h" #include "getline.h" -#include "machine.h" +#include "in_all.h" #include "keys.h" -#include "display.h" -#include "assert.h" +#include "machine.h" +#include "main.h" +#include "output.h" +#include "process.h" +#include "prompt.h" +#include "term.h" +#include <ctype.h> -static int killchar(int c); +static int killchar(int c); static void sigquit(int signo); /* @@ -30,69 +30,68 @@ static void sigquit(int signo); char * readline(char *s) { + static char buf[80]; + char *p = buf; + int ch; + int pos; - static char buf[80]; - char *p = buf; - int ch; - int pos; - - clrbline(); - putline(s); - pos = strlen(s); - while ((ch = getch()) != '\n' && ch != '\r') { - if (ch == -1) { - /* - * Can only occur because of an interrupted read. - */ - ch = erasech; - interrupt = 0; - } - if (ch == erasech) { - /* - * Erase last char - */ - if (p == buf) { - /* - * There was none, so return - */ - return (char *)0; - } - pos -= killchar(*--p); - if (*p != '\\') - continue; - } - if (ch == killch) { - /* - * Erase the whole line - */ - if (!(p > buf && *(p - 1) == '\\')) { - while (p > buf) { - pos -= killchar(*--p); - } - continue; - } - pos -= killchar(*--p); - } - if (p > &buf[78] || pos >= COLS - 2) { - /* - * Line does not fit. - * Simply refuse to make it any longer - */ - pos -= killchar(*--p); - } - *p++ = ch; - if (ch < ' ' || ch >= 0177) { - fputch('^'); - pos++; - ch ^= 0100; - } - fputch(ch); - pos++; - } - fputch('\r'); - *p++ = '\0'; - flush(); - return buf; + clrbline(); + putline(s); + pos = strlen(s); + while ((ch = getch()) != '\n' && ch != '\r') { + if (ch == -1) { + /* + * Can only occur because of an interrupted read. + */ + ch = erasech; + interrupt = 0; + } + if (ch == erasech) { + /* + * Erase last char + */ + if (p == buf) { + /* + * There was none, so return + */ + return (char *)0; + } + pos -= killchar(*--p); + if (*p != '\\') + continue; + } + if (ch == killch) { + /* + * Erase the whole line + */ + if (!(p > buf && *(p - 1) == '\\')) { + while (p > buf) { + pos -= killchar(*--p); + } + continue; + } + pos -= killchar(*--p); + } + if (p > &buf[78] || pos >= COLS - 2) { + /* + * Line does not fit. + * Simply refuse to make it any longer + */ + pos -= killchar(*--p); + } + *p++ = ch; + if (ch < ' ' || ch >= 0177) { + fputch('^'); + pos++; + ch ^= 0100; + } + fputch(ch); + pos++; + } + fputch('\r'); + *p++ = '\0'; + flush(); + return buf; } /* @@ -102,15 +101,14 @@ readline(char *s) static int killchar(int c) { - - backspace(); - putch(' '); - backspace(); - if (c < ' ' || c >= 0177) { - (void)killchar(' '); - return 2; - } - return 1; + backspace(); + putch(' '); + backspace(); + if (c < ' ' || c >= 0177) { + (void)killchar(' '); + return 2; + } + return 1; } /* @@ -120,129 +118,129 @@ killchar(int c) void shellescape(char *p, int esc_char) { - char *p2; /* walks through command */ - int id; /* procid of child */ - int cnt; /* prevent array bound errors */ - int lastc = 0; /* will contain the previous char */ + char *p2; /* walks through command */ + int id; /* procid of child */ + int cnt; /* prevent array bound errors */ + int lastc = 0; /* will contain the previous char */ #ifdef SIGTSTP - void (*savetstp)(int); + void (*savetstp)(int); #endif - static char previous[256]; /* previous command */ - char comm[256]; /* space for command */ - int piped[2]; + static char previous[256]; /* previous command */ + char comm[256]; /* space for command */ + int piped[2]; - p2 = comm; - *p2++ = esc_char; - cnt = 253; - while (*p) { - /* - * expand command - */ - switch (*p++) { - case '!': - /* - * An unescaped ! expands to the previous - * command, but disappears if there is none - */ - if (lastc != '\\') { - if (*previous) { - id = strlen(previous); - if ((cnt -= id) <= 0) - break; - (void)strcpy(p2, previous); - p2 += id; - } - } else { - *(p2 - 1) = '!'; - } - continue; - case '%': - /* - * An unescaped % will expand to the current - * filename, but disappears is there is none - */ - if (lastc != '\\') { - if (nopipe) { - id = strlen(currentfile); - if ((cnt -= id) <= 0) - break; - (void)strcpy(p2, currentfile); - p2 += id; - } - } else { - *(p2 - 1) = '%'; - } - continue; - default: - lastc = *(p - 1); - if (cnt-- <= 0) - break; - *p2++ = lastc; - continue; - } - break; - } - clrbline(); - *p2 = '\0'; - if (!stupid) { - /* - * Display expanded command - */ - cputline(comm); - putline("\r\n"); - } - flush(); - (void)strcpy(previous, comm + 1); - resettty(); - if (esc_char == '|' && pipe(piped) < 0) { - error("Cannot create pipe"); - return; - } - if ((id = fork()) < 0) { - error("Cannot fork"); - return; - } - if (id == 0) { - if (esc_char == '|') { - close(piped[1]); - close(0); - fcntl(piped[0], F_DUPFD, 0); - close(piped[0]); - } - execl("/bin/sh", "sh", "-c", comm + 1, (char *)0); - exit(1); - } - (void)signal(SIGINT, SIG_IGN); - (void)signal(SIGQUIT, SIG_IGN); + p2 = comm; + *p2++ = esc_char; + cnt = 253; + while (*p) { + /* + * expand command + */ + switch (*p++) { + case '!': + /* + * An unescaped ! expands to the previous + * command, but disappears if there is none + */ + if (lastc != '\\') { + if (*previous) { + id = strlen(previous); + if ((cnt -= id) <= 0) + break; + (void)strcpy(p2, previous); + p2 += id; + } + } else { + *(p2 - 1) = '!'; + } + continue; + case '%': + /* + * An unescaped % will expand to the current + * filename, but disappears is there is none + */ + if (lastc != '\\') { + if (nopipe) { + id = strlen(currentfile); + if ((cnt -= id) <= 0) + break; + (void)strcpy(p2, currentfile); + p2 += id; + } + } else { + *(p2 - 1) = '%'; + } + continue; + default: + lastc = *(p - 1); + if (cnt-- <= 0) + break; + *p2++ = lastc; + continue; + } + break; + } + clrbline(); + *p2 = '\0'; + if (!stupid) { + /* + * Display expanded command + */ + cputline(comm); + putline("\r\n"); + } + flush(); + (void)strcpy(previous, comm + 1); + resettty(); + if (esc_char == '|' && pipe(piped) < 0) { + error("Cannot create pipe"); + return; + } + if ((id = fork()) < 0) { + error("Cannot fork"); + return; + } + if (id == 0) { + if (esc_char == '|') { + close(piped[1]); + close(0); + fcntl(piped[0], F_DUPFD, 0); + close(piped[0]); + } + execl("/bin/sh", "sh", "-c", comm + 1, (char *)0); + exit(1); + } + (void)signal(SIGINT, SIG_IGN); + (void)signal(SIGQUIT, SIG_IGN); #ifdef SIGTSTP - if ((savetstp = signal(SIGTSTP, SIG_IGN)) != SIG_IGN) { - (void)signal(SIGTSTP, SIG_DFL); - } + if ((savetstp = signal(SIGTSTP, SIG_IGN)) != SIG_IGN) { + (void)signal(SIGTSTP, SIG_DFL); + } #endif - if (esc_char == '|') { - (void)close(piped[0]); - (void)signal(SIGPIPE, SIG_IGN); - wrt_fd(piped[1]); - (void)close(piped[1]); - } - while ((lastc = wait((int *)0)) != id && lastc >= 0) { - /* - * Wait for child, making sure it is the one we expected ... - */ - } - (void)signal(SIGINT, catchdel); - (void)signal(SIGQUIT, sigquit); + if (esc_char == '|') { + (void)close(piped[0]); + (void)signal(SIGPIPE, SIG_IGN); + wrt_fd(piped[1]); + (void)close(piped[1]); + } + while ((lastc = wait((int *)0)) != id && lastc >= 0) { + /* + * Wait for child, making sure it is the one we expected ... + */ + } + (void)signal(SIGINT, catchdel); + (void)signal(SIGQUIT, sigquit); #ifdef SIGTSTP - (void)signal(SIGTSTP, savetstp); + (void)signal(SIGTSTP, savetstp); #endif - inittty(); + inittty(); } static void sigquit(int signo) { - (void)signo; - quit(); + (void)signo; + quit(); } /* @@ -252,52 +250,52 @@ sigquit(int signo) int getcomm(long *plong) { - int c; - long count; - char *p; - int i; - int j; - char buf[10]; + int c; + long count; + char *p; + int i; + int j; + char buf[10]; - for (;;) { - count = 0; - give_prompt(); - while (isdigit((c = getch()))) { - count = count * 10 + (c - '0'); - } - *plong = count; - p = buf; - for (;;) { - if (c == -1) { - /* - * This should never happen, but it does, - * when the user gives a TSTP signal (^Z) or - * an interrupt while the program is trying - * to read a character from the terminal. - * In this case, the read is interrupted, so - * we end up here. - * Right, we will have to read again. - */ - if (interrupt) - return 1; - break; - } - *p++ = c; - *p = 0; - if ((i = match(buf, &j, currmap->k_mach)) > 0) { - /* - * The key sequence matched. We have a command - */ - return j; - } - if (i == 0) - return 0; - /* - * We have a prefix of a command. - */ - assert(i == FSM_ISPREFIX); - c = getch(); - } - } - /* NOTREACHED */ + for (;;) { + count = 0; + give_prompt(); + while (isdigit((c = getch()))) { + count = count * 10 + (c - '0'); + } + *plong = count; + p = buf; + for (;;) { + if (c == -1) { + /* + * This should never happen, but it does, + * when the user gives a TSTP signal (^Z) or + * an interrupt while the program is trying + * to read a character from the terminal. + * In this case, the read is interrupted, so + * we end up here. + * Right, we will have to read again. + */ + if (interrupt) + return 1; + break; + } + *p++ = c; + *p = 0; + if ((i = match(buf, &j, currmap->k_mach)) > 0) { + /* + * The key sequence matched. We have a command + */ + return j; + } + if (i == 0) + return 0; + /* + * We have a prefix of a command. + */ + assert(i == FSM_ISPREFIX); + c = getch(); + } + } + /* NOTREACHED */ } diff --git a/cmd/extra/yap/getcomm.h b/cmd/extra/yap/getcomm.h @@ -1,8 +1,8 @@ #ifndef GETCOMM_H #define GETCOMM_H -int getcomm(long *arg); -void shellescape(char *command, int esc_char); +int getcomm(long *arg); +void shellescape(char *command, int esc_char); char *readline(char *prompt); #endif diff --git a/cmd/extra/yap/getline.c b/cmd/extra/yap/getline.c @@ -1,18 +1,18 @@ /* Copyright (c) 1985 Ceriel J.H. Jacobs */ -#include "in_all.h" #include "getline.h" -#include "options.h" -#include "process.h" -#include "term.h" -#include "main.h" +#include "assert.h" #include "display.h" +#include "in_all.h" +#include "main.h" +#include "options.h" #include "output.h" +#include "process.h" #include "prompt.h" -#include "assert.h" +#include "term.h" #define BLOCKSIZE 2048 /* size of blocks */ -#define CHUNK 50 /* # of blockheaders allocated at a time */ +#define CHUNK 50 /* # of blockheaders allocated at a time */ /* * Blocks are kept in an array in line-number order. Each block stores the raw @@ -20,63 +20,62 @@ */ struct block { - int b_flags; /* Contains the following flags: */ -#define PARTLY 02 /* block not filled completely (eof) */ - long b_end; /* line number of last line in block */ - char *b_info; /* the block */ - int *b_offs; /* line offsets within the block */ + int b_flags; /* Contains the following flags: */ +#define PARTLY 02 /* block not filled completely (eof) */ + long b_end; /* line number of last line in block */ + char *b_info; /* the block */ + int *b_offs; /* line offsets within the block */ }; static struct block *blocklist, /* beginning of the list of blocks */ *maxblocklist, /* first free entry in the list */ *topblocklist; /* end of allocated core for the list */ -static long lastreadline; /* lineno of last line read */ -static int ENDseen; +static long lastreadline; /* lineno of last line read */ +static int ENDseen; -static void nextblock(struct block *pblock); -static char *re_alloc(char *ptr, unsigned newsize); +static void nextblock(struct block *pblock); +static char *re_alloc(char *ptr, unsigned newsize); static struct block *getblock(long n, int disable_interrupt); static struct block * new_block() { - struct block *pblock = maxblocklist - 1; - - if (!maxblocklist || !(pblock->b_flags & PARTLY)) { - /* - * There is no last block, or it was filled completely, - * so allocate a new blockheader. - */ - int siz; - - pblock = blocklist; - if (maxblocklist == topblocklist) { - /* - * No blockheaders left. Allocate new ones - */ - siz = topblocklist - pblock; - blocklist = pblock = (struct block *) - re_alloc((char *)pblock, - (unsigned)((siz + CHUNK) * sizeof(*pblock))); - pblock += siz; - topblocklist = pblock + CHUNK; - maxblocklist = pblock; - for (; pblock < topblocklist; pblock++) { - pblock->b_end = 0; - pblock->b_info = 0; - pblock->b_flags = 0; - } - if (!siz) { - /* - * Create dummy header cell. - */ - maxblocklist++; - } - } - pblock = maxblocklist++; - } - nextblock(pblock); - return pblock; + struct block *pblock = maxblocklist - 1; + + if (!maxblocklist || !(pblock->b_flags & PARTLY)) { + /* + * There is no last block, or it was filled completely, + * so allocate a new blockheader. + */ + int siz; + + pblock = blocklist; + if (maxblocklist == topblocklist) { + /* + * No blockheaders left. Allocate new ones + */ + siz = topblocklist - pblock; + blocklist = pblock = + (struct block *)re_alloc((char *)pblock, (unsigned)((siz + CHUNK) * sizeof(*pblock))); + pblock += siz; + topblocklist = pblock + CHUNK; + maxblocklist = pblock; + for (; pblock < topblocklist; pblock++) { + pblock->b_end = 0; + pblock->b_info = 0; + pblock->b_flags = 0; + } + if (!siz) { + /* + * Create dummy header cell. + */ + maxblocklist++; + } + } + pblock = maxblocklist++; + } + nextblock(pblock); + return pblock; } /* @@ -88,66 +87,65 @@ new_block() static struct block * getblock(long n, int disable_interrupt) { - struct block *pblock; - - if (stdf < 0) { - /* - * Not file descriptor, so return end of file - */ - return 0; - } - pblock = maxblocklist - 1; - if (n < lastreadline || - (n == lastreadline && !(pblock->b_flags & PARTLY))) { - /* - * The line asked for has been read already. - * Perform binary search in the blocklist to find the block - * where it's in. - */ - struct block *min, *mid; - - min = blocklist + 1; - do { - mid = min + (pblock - min) / 2; - if (n > mid->b_end) { - min = mid + 1; - } else - pblock = mid; - } while (min < pblock); - /* Found, pblock is now a reference to the block wanted */ - return pblock; - } - - /* - * The line was'nt read yet, so read blocks until found - */ - for (;;) { - if (interrupt && !disable_interrupt) - return 0; - pblock = new_block(); - if (pblock->b_end >= n) { - return pblock; - } - if (pblock->b_flags & PARTLY) { - /* - * We did not find it, and the last block could not be - * read completely, so return 0; - */ - return 0; - } - } - /* NOTREACHED */ + struct block *pblock; + + if (stdf < 0) { + /* + * Not file descriptor, so return end of file + */ + return 0; + } + pblock = maxblocklist - 1; + if (n < lastreadline || (n == lastreadline && !(pblock->b_flags & PARTLY))) { + /* + * The line asked for has been read already. + * Perform binary search in the blocklist to find the block + * where it's in. + */ + struct block *min, *mid; + + min = blocklist + 1; + do { + mid = min + (pblock - min) / 2; + if (n > mid->b_end) { + min = mid + 1; + } else + pblock = mid; + } while (min < pblock); + /* Found, pblock is now a reference to the block wanted */ + return pblock; + } + + /* + * The line was'nt read yet, so read blocks until found + */ + for (;;) { + if (interrupt && !disable_interrupt) + return 0; + pblock = new_block(); + if (pblock->b_end >= n) { + return pblock; + } + if (pblock->b_flags & PARTLY) { + /* + * We did not find it, and the last block could not be + * read completely, so return 0; + */ + return 0; + } + } + /* NOTREACHED */ } char * getline(long n, int disable_interrupt) { - struct block *pblock; + struct block *pblock; - if (!(pblock = getblock(n, disable_interrupt))) { - return (char *)0; - } - return pblock->b_info + pblock->b_offs[n - ((pblock - 1)->b_end + 1)]; + if (!(pblock = getblock(n, disable_interrupt))) { + return (char *)0; + } + return pblock->b_info + pblock->b_offs[n - ((pblock - 1)->b_end + 1)]; } /* @@ -157,32 +155,31 @@ getline(long n, int disable_interrupt) long to_lastline() { - - for (;;) { - if (!getline(lastreadline + 1, 0)) { - /* - * "lastreadline" always contains the linenumber of - * the last line read. So, if the call to getline - * succeeds, "lastreadline" is affected - */ - if (interrupt) - return -1L; - return lastreadline; - } - } - /* NOTREACHED */ + for (;;) { + if (!getline(lastreadline + 1, 0)) { + /* + * "lastreadline" always contains the linenumber of + * the last line read. So, if the call to getline + * succeeds, "lastreadline" is affected + */ + if (interrupt) + return -1L; + return lastreadline; + } + } + /* NOTREACHED */ } char * alloc(unsigned size) { - char *pmem; + char *pmem; - pmem = malloc(size); - if (!pmem && size != 0) { - panic("No core"); - } - return pmem; + pmem = malloc(size); + if (!pmem && size != 0) { + panic("No core"); + } + return pmem; } /* @@ -193,17 +190,17 @@ alloc(unsigned size) static char * re_alloc(char *ptr, unsigned newsize) { - char *pmem; + char *pmem; - pmem = realloc(ptr, newsize); - if (!pmem && newsize != 0) { - panic("No core"); - } - return pmem; + pmem = realloc(ptr, newsize); + if (!pmem && newsize != 0) { + panic("No core"); + } + return pmem; } static char *saved; -static long filldegree; +static long filldegree; /* * Try to read the block indicated by pblock @@ -212,143 +209,141 @@ static long filldegree; static void nextblock(struct block *pblock) { - char *c, /* Run through pblock->b_info */ - *c1; /* indicate end of pblock->b_info */ - int *poff; /* pointer in line-offset list */ - int cnt; /* # of characters read */ - unsigned siz; /* Size of allocated line-offset list */ - static unsigned savedsiz; /* saved "siz" */ - static int *savedpoff; /* saved "poff" */ - static char *savedc1; /* saved "c1" */ - - if (pblock->b_flags & PARTLY) { - /* - * The block was already partly filled. Initialize locals - * accordingly - */ - poff = savedpoff; - siz = savedsiz; - pblock->b_flags = 0; - c1 = savedc1; - if (c1 == pblock->b_info || *(c1 - 1)) { - /* - * We had incremented "lastreadline" temporarily, - * because the last line could not be completely read - * last time we tried. Undo this increment - */ - poff--; - --lastreadline; - } - } else { - if (saved) { - /* - * There were leftovers from the previous block - */ - pblock->b_info = saved; - c1 = savedc1; - saved = 0; - } else { /* Allocate new block */ - pblock->b_info = c1 = alloc(BLOCKSIZE + 1); - } - /* - * Allocate some space for line-offsets - */ - pblock->b_offs = poff = (int *) - alloc((unsigned)(100 * sizeof(int))); - siz = 99; - *poff++ = 0; - } - c = c1; - for (;;) { - /* - * Read loop - */ - cnt = read(stdf, c1, BLOCKSIZE - (c1 - pblock->b_info)); - if (cnt < 0) { - /* - * Interrupted read - */ - if (errno == EINTR) - continue; - error("Could not read input file"); - cnt = 0; - } - c1 += cnt; - if (c1 != pblock->b_info + BLOCKSIZE) { - ENDseen = 1; - pblock->b_flags |= PARTLY; - } - break; - } - assert(c <= c1); - while (c < c1) { - /* - * Now process the block - */ - if (*c == '\n') { - /* - * Newlines are replaced by '\0', so that "getline" - * can deliver one line at a time - */ - *c = 0; - lastreadline++; - /* - * Remember the line-offset - */ - if (poff == pblock->b_offs + siz) { - /* - * No space for it, allocate some more - */ - pblock->b_offs = (int *) - re_alloc((char *)pblock->b_offs, - (unsigned)((siz + 51) * sizeof(int))); - poff = pblock->b_offs + siz; - siz += 50; - } - *poff++ = c - pblock->b_info + 1; - } - c++; - } - assert(c == c1); - *c = 0; - if (c != pblock->b_info && *(c - 1) != 0) { - /* - * The last line read does not end with a newline, so add one - */ - lastreadline++; - *poff++ = c - pblock->b_info + 1; - if (!(pblock->b_flags & PARTLY) && *(poff - 2) != 0) { - /* - * Save the started line; it will be in the next block. - * Remove the newline we added just now. - */ - saved = c1 = alloc(BLOCKSIZE + 1); - c = pblock->b_info + *(--poff - 1); - while (*c) - *c1++ = *c++; - c = pblock->b_info + *(poff - 1); - savedc1 = c1; - --lastreadline; - } - } - pblock->b_end = lastreadline; - if (pblock->b_flags & PARTLY) { - /* - * Take care, that we can call "nextblock" again, to fill in - * the rest of this block - */ - savedsiz = siz; - savedpoff = poff; - savedc1 = c; - if (c == pblock->b_info) { - lastreadline++; - pblock->b_end = 0; - } - } else { - cnt = pblock - blocklist; - filldegree = ((c - pblock->b_info) + (cnt - 1) * filldegree) / cnt; - } - assert(pblock->b_end - (pblock - 1)->b_end <= poff - pblock->b_offs); + char *c, /* Run through pblock->b_info */ + *c1; /* indicate end of pblock->b_info */ + int *poff; /* pointer in line-offset list */ + int cnt; /* # of characters read */ + unsigned siz; /* Size of allocated line-offset list */ + static unsigned savedsiz; /* saved "siz" */ + static int *savedpoff; /* saved "poff" */ + static char *savedc1; /* saved "c1" */ + + if (pblock->b_flags & PARTLY) { + /* + * The block was already partly filled. Initialize locals + * accordingly + */ + poff = savedpoff; + siz = savedsiz; + pblock->b_flags = 0; + c1 = savedc1; + if (c1 == pblock->b_info || *(c1 - 1)) { + /* + * We had incremented "lastreadline" temporarily, + * because the last line could not be completely read + * last time we tried. Undo this increment + */ + poff--; + --lastreadline; + } + } else { + if (saved) { + /* + * There were leftovers from the previous block + */ + pblock->b_info = saved; + c1 = savedc1; + saved = 0; + } else { /* Allocate new block */ + pblock->b_info = c1 = alloc(BLOCKSIZE + 1); + } + /* + * Allocate some space for line-offsets + */ + pblock->b_offs = poff = (int *)alloc((unsigned)(100 * sizeof(int))); + siz = 99; + *poff++ = 0; + } + c = c1; + for (;;) { + /* + * Read loop + */ + cnt = read(stdf, c1, BLOCKSIZE - (c1 - pblock->b_info)); + if (cnt < 0) { + /* + * Interrupted read + */ + if (errno == EINTR) + continue; + error("Could not read input file"); + cnt = 0; + } + c1 += cnt; + if (c1 != pblock->b_info + BLOCKSIZE) { + ENDseen = 1; + pblock->b_flags |= PARTLY; + } + break; + } + assert(c <= c1); + while (c < c1) { + /* + * Now process the block + */ + if (*c == '\n') { + /* + * Newlines are replaced by '\0', so that "getline" + * can deliver one line at a time + */ + *c = 0; + lastreadline++; + /* + * Remember the line-offset + */ + if (poff == pblock->b_offs + siz) { + /* + * No space for it, allocate some more + */ + pblock->b_offs = + (int *)re_alloc((char *)pblock->b_offs, (unsigned)((siz + 51) * sizeof(int))); + poff = pblock->b_offs + siz; + siz += 50; + } + *poff++ = c - pblock->b_info + 1; + } + c++; + } + assert(c == c1); + *c = 0; + if (c != pblock->b_info && *(c - 1) != 0) { + /* + * The last line read does not end with a newline, so add one + */ + lastreadline++; + *poff++ = c - pblock->b_info + 1; + if (!(pblock->b_flags & PARTLY) && *(poff - 2) != 0) { + /* + * Save the started line; it will be in the next block. + * Remove the newline we added just now. + */ + saved = c1 = alloc(BLOCKSIZE + 1); + c = pblock->b_info + *(--poff - 1); + while (*c) + *c1++ = *c++; + c = pblock->b_info + *(poff - 1); + savedc1 = c1; + --lastreadline; + } + } + pblock->b_end = lastreadline; + if (pblock->b_flags & PARTLY) { + /* + * Take care, that we can call "nextblock" again, to fill in + * the rest of this block + */ + savedsiz = siz; + savedpoff = poff; + savedc1 = c; + if (c == pblock->b_info) { + lastreadline++; + pblock->b_end = 0; + } + } else { + cnt = pblock - blocklist; + filldegree = ((c - pblock->b_info) + (cnt - 1) * filldegree) / cnt; + } + assert(pblock->b_end - (pblock - 1)->b_end <= poff - pblock->b_offs); } /* @@ -359,28 +354,27 @@ nextblock(struct block *pblock) void do_clean() { - - struct block *pblock; - char *p; - - for (pblock = blocklist; pblock < maxblocklist; pblock++) { - if ((p = pblock->b_info) != 0) { - free(p); - free((char *)pblock->b_offs); - } - } - if ((p = (char *)blocklist) != 0) { - free(p); - } - blocklist = 0; - maxblocklist = 0; - topblocklist = 0; - lastreadline = 0; - filldegree = 0; - ENDseen = 0; - if ((p = saved) != 0) - free(p); - saved = 0; + struct block *pblock; + char *p; + + for (pblock = blocklist; pblock < maxblocklist; pblock++) { + if ((p = pblock->b_info) != 0) { + free(p); + free((char *)pblock->b_offs); + } + } + if ((p = (char *)blocklist) != 0) { + free(p); + } + blocklist = 0; + maxblocklist = 0; + topblocklist = 0; + lastreadline = 0; + filldegree = 0; + ENDseen = 0; + if ((p = saved) != 0) + free(p); + saved = 0; } /* @@ -390,28 +384,28 @@ do_clean() int getch() { - int flags, bytes_ready, bytes_read; - struct stat buf; - char c; - - flush(); - if (startcomm) { - /* - * Command line option command - */ - if (*startcomm) - return *startcomm++; - return '\n'; - } - if (stdf >= 0) { - /* - * Make reads from the terminal non-blocking, so that - * we can see if the user typed something - */ - flags = fcntl(0, F_GETFL, 0); - if (flags != -1 && fcntl(0, F_SETFL, flags | O_NONBLOCK) != -1) { - bytes_read = 0; - while (!ENDseen && + int flags, bytes_ready, bytes_read; + struct stat buf; + char c; + + flush(); + if (startcomm) { + /* + * Command line option command + */ + if (*startcomm) + return *startcomm++; + return '\n'; + } + if (stdf >= 0) { + /* + * Make reads from the terminal non-blocking, so that + * we can see if the user typed something + */ + flags = fcntl(0, F_GETFL, 0); + if (flags != -1 && fcntl(0, F_SETFL, flags | O_NONBLOCK) != -1) { + bytes_read = 0; + while (!ENDseen && ((bytes_read = read(0, &c, 1)) == 0 #ifdef EWOULDBLOCK || (bytes_read < 0 && errno == EWOULDBLOCK) @@ -422,40 +416,39 @@ getch() ) && (nopipe || (fstat(stdf, &buf) >= 0 && buf.st_size > 0))) { - /* - * Do some read ahead, after making sure there - * is input and the user did not type a command - */ - new_block(); - } - (void)fcntl(0, F_SETFL, flags); - if (bytes_read < 0) { - /* - * Could this have happened? - * I'm not sure, because the read is - * nonblocking. Can it be interrupted then? - */ - return -1; - } - if (bytes_read > 0) - return c & 0x7f; - } - } - if (ioctl(0, FIONREAD, (char *)&bytes_ready) >= 0 && stdf >= 0) { - while (!ENDseen && - bytes_ready == 0 && - (nopipe || (fstat(stdf, &buf) >= 0 && buf.st_size > 0))) { - if (interrupt) - return -1; - new_block(); - if (ioctl(0, FIONREAD, (char *)&bytes_ready) < 0) { - break; - } - } - } - if (read(0, &c, 1) <= 0) - return -1; - return c & 0x7f; + /* + * Do some read ahead, after making sure there + * is input and the user did not type a command + */ + new_block(); + } + (void)fcntl(0, F_SETFL, flags); + if (bytes_read < 0) { + /* + * Could this have happened? + * I'm not sure, because the read is + * nonblocking. Can it be interrupted then? + */ + return -1; + } + if (bytes_read > 0) + return c & 0x7f; + } + } + if (ioctl(0, FIONREAD, (char *)&bytes_ready) >= 0 && stdf >= 0) { + while (!ENDseen && bytes_ready == 0 + && (nopipe || (fstat(stdf, &buf) >= 0 && buf.st_size > 0))) { + if (interrupt) + return -1; + new_block(); + if (ioctl(0, FIONREAD, (char *)&bytes_ready) < 0) { + break; + } + } + } + if (read(0, &c, 1) <= 0) + return -1; + return c & 0x7f; } /* @@ -465,11 +458,11 @@ getch() long getpos(long ln) { - struct block *pblock; - long i; + struct block *pblock; + long i; - pblock = getblock(ln, 1); - assert(pblock != 0); - i = filldegree * (pblock - blocklist); - return i - (filldegree - pblock->b_offs[ln - (pblock - 1)->b_end]); + pblock = getblock(ln, 1); + assert(pblock != 0); + i = filldegree * (pblock - blocklist); + return i - (filldegree - pblock->b_offs[ln - (pblock - 1)->b_end]); } diff --git a/cmd/extra/yap/getline.h b/cmd/extra/yap/getline.h @@ -3,9 +3,9 @@ char *getline(long ln, int disable_interrupt); char *alloc(unsigned size); -void do_clean(void); -int getch(void); -long to_lastline(void); -long getpos(long line); +void do_clean(void); +int getch(void); +long to_lastline(void); +long getpos(long line); #endif diff --git a/cmd/extra/yap/help.c b/cmd/extra/yap/help.c @@ -1,18 +1,18 @@ /* Copyright (c) 1985 Ceriel J.H. Jacobs */ -#include "in_all.h" #include "help.h" -#include "machine.h" #include "commands.h" +#include "display.h" +#include "in_all.h" #include "keys.h" +#include "machine.h" +#include "main.h" +#include "options.h" #include "output.h" #include "prompt.h" -#include "main.h" -#include "display.h" #include "term.h" -#include "options.h" -static int h_cnt; /* Count # of lines */ +static int h_cnt; /* Count # of lines */ static struct state *origin; /* Keep track of startstate */ /* @@ -25,32 +25,32 @@ static struct state *origin; /* Keep track of startstate */ static void pr_comm() { - struct state *p = origin; - char *pb; - int c; - char buf[30]; - int i = 0; /* How many characters printed? */ + struct state *p = origin; + char *pb; + int c; + char buf[30]; + int i = 0; /* How many characters printed? */ - pb = buf; - for (;;) { - c = p->s_char & 0177; - if (c < ' ' || c == 0177) { - /* - * Will take an extra position - */ - i++; - } - *pb++ = c; - i++; - if (!p->s_match) - break; - p = p->s_next; - } - do { - *pb++ = ' '; - } while (++i < 12); - *pb = 0; - cputline(buf); + pb = buf; + for (;;) { + c = p->s_char & 0177; + if (c < ' ' || c == 0177) { + /* + * Will take an extra position + */ + i++; + } + *pb++ = c; + i++; + if (!p->s_match) + break; + p = p->s_next; + } + do { + *pb++ = ' '; + } while (++i < 12); + *pb = 0; + cputline(buf); } /* @@ -62,51 +62,51 @@ pr_comm() static void pr_mach(struct state *currstate, struct state *back) { - struct state *save; + struct state *save; - while (currstate) { - if (interrupt) - break; - if (back) { - save = back->s_next; /* Save original link */ - back->s_next = currstate; - } - if (!currstate->s_match) { - /* - * End state, print command - */ - pr_comm(); - putline(commands[currstate->s_cnt].c_descr); - putline("\r\n"); - if (++h_cnt >= maxpagesize) { - ret_to_continue(); - h_cnt = 0; - } - } else - pr_mach(currstate->s_match, currstate); - currstate = currstate->s_next; - if (back) - back->s_next = save; /* restore */ - else - origin = currstate; - } + while (currstate) { + if (interrupt) + break; + if (back) { + save = back->s_next; /* Save original link */ + back->s_next = currstate; + } + if (!currstate->s_match) { + /* + * End state, print command + */ + pr_comm(); + putline(commands[currstate->s_cnt].c_descr); + putline("\r\n"); + if (++h_cnt >= maxpagesize) { + ret_to_continue(); + h_cnt = 0; + } + } else + pr_mach(currstate->s_match, currstate); + currstate = currstate->s_next; + if (back) + back->s_next = save; /* restore */ + else + origin = currstate; + } } /*ARGSUSED*/ int do_help(long i) { /* The help command */ - (void)i; + (void)i; - startcomm = 0; - h_cnt = 2; - putline("\r\nSummary of yap commands:\r\n"); - origin = currmap->k_mach; - pr_mach(currmap->k_mach, (struct state *)0); - if (h_cnt) { - ret_to_continue(); - } - if (!hardcopy && scr_info.currentpos) - redraw(1); - return 0; + startcomm = 0; + h_cnt = 2; + putline("\r\nSummary of yap commands:\r\n"); + origin = currmap->k_mach; + pr_mach(currmap->k_mach, (struct state *)0); + if (h_cnt) { + ret_to_continue(); + } + if (!hardcopy && scr_info.currentpos) + redraw(1); + return 0; } diff --git a/cmd/extra/yap/keys.c b/cmd/extra/yap/keys.c @@ -1,12 +1,12 @@ /* Copyright (c) 1985 Ceriel J.H. Jacobs */ -#include <ctype.h> -#include "in_all.h" -#include "machine.h" #include "keys.h" +#include "assert.h" #include "commands.h" +#include "in_all.h" +#include "machine.h" #include "prompt.h" -#include "assert.h" +#include <ctype.h> struct keymap *currmap, *othermap; @@ -23,11 +23,11 @@ wrf=w:qui=q:qui=Q:mar=m:pip=|"; static char * kerror(char *key, char *emess) { - static char ebuf[80]; /* Room for the error message */ + static char ebuf[80]; /* Room for the error message */ - (void)strcpy(ebuf, key); - (void)strcat(ebuf, emess); - return ebuf; + (void)strcpy(ebuf, key); + (void)strcat(ebuf, emess); + return ebuf; } /* @@ -38,87 +38,87 @@ kerror(char *key, char *emess) static char * compile(char *map, struct keymap *commtable) { - char *mark; /* Indicates start of mnemonic */ - char *c; /* Runs through buf */ - int temp; - char *escapes = commtable->k_esc; - char buf[10]; /* Will hold key sequence */ - - (void)strcpy(commtable->k_help, "Illegal command"); - while (*map) { - c = buf; - mark = map; /* Start of mnemonic */ - while (*map && *map != '=') { - map++; - } - if (!*map) { - /* - * Mnemonic should end with '=' - */ - return kerror(mark, ": Syntax error"); - } - *map++ = 0; - while (*map) { - /* - * Get key sequence - */ - if (*map == ':') { - /* - * end of key sequence - */ - map++; - break; - } - *c = *map++ & 0x7f; - if (*c == '^' || *c == '\\') { - if (!(temp = *map++)) { - /* - * Escape not followed by a character - */ - return kerror(mark, ": Syntax error"); - } - if (*c == '^') { - if (temp == '?') - *c = 0x7f; - else - *c = temp & 0x1f; - } else - *c = temp & 0x7f; - } - setused(*c); - c++; - if (c >= &buf[9]) { - return kerror(mark, ": Key sequence too long"); - } - } - *c = 0; - if (!(temp = lookup(mark))) { - return kerror(mark, ": Nonexistent function"); - } - if (c == &buf[1] && (commands[temp].c_flags & ESC) && - escapes < &(commtable->k_esc[sizeof(commtable->k_esc) - 1])) { - *escapes++ = buf[0] & 0x7f; - } - temp = addstring(buf, temp, &(commtable->k_mach)); - if (temp == FSM_ISPREFIX) { - return kerror(mark, ": Prefix of other key sequence"); - } - if (temp == FSM_HASPREFIX) { - return kerror(mark, ": Other key sequence is prefix"); - } - assert(temp == FSM_OKE); - if (!strcmp(mark, "hlp")) { - /* - * Create an error message to be given when the user - * types an illegal command - */ - (void)strcpy(commtable->k_help, "Type "); - (void)strcat(commtable->k_help, buf); - (void)strcat(commtable->k_help, " for help"); - } - } - *escapes = 0; - return (char *)0; + char *mark; /* Indicates start of mnemonic */ + char *c; /* Runs through buf */ + int temp; + char *escapes = commtable->k_esc; + char buf[10]; /* Will hold key sequence */ + + (void)strcpy(commtable->k_help, "Illegal command"); + while (*map) { + c = buf; + mark = map; /* Start of mnemonic */ + while (*map && *map != '=') { + map++; + } + if (!*map) { + /* + * Mnemonic should end with '=' + */ + return kerror(mark, ": Syntax error"); + } + *map++ = 0; + while (*map) { + /* + * Get key sequence + */ + if (*map == ':') { + /* + * end of key sequence + */ + map++; + break; + } + *c = *map++ & 0x7f; + if (*c == '^' || *c == '\\') { + if (!(temp = *map++)) { + /* + * Escape not followed by a character + */ + return kerror(mark, ": Syntax error"); + } + if (*c == '^') { + if (temp == '?') + *c = 0x7f; + else + *c = temp & 0x1f; + } else + *c = temp & 0x7f; + } + setused(*c); + c++; + if (c >= &buf[9]) { + return kerror(mark, ": Key sequence too long"); + } + } + *c = 0; + if (!(temp = lookup(mark))) { + return kerror(mark, ": Nonexistent function"); + } + if (c == &buf[1] && (commands[temp].c_flags & ESC) + && escapes < &(commtable->k_esc[sizeof(commtable->k_esc) - 1])) { + *escapes++ = buf[0] & 0x7f; + } + temp = addstring(buf, temp, &(commtable->k_mach)); + if (temp == FSM_ISPREFIX) { + return kerror(mark, ": Prefix of other key sequence"); + } + if (temp == FSM_HASPREFIX) { + return kerror(mark, ": Other key sequence is prefix"); + } + assert(temp == FSM_OKE); + if (!strcmp(mark, "hlp")) { + /* + * Create an error message to be given when the user + * types an illegal command + */ + (void)strcpy(commtable->k_help, "Type "); + (void)strcat(commtable->k_help, buf); + (void)strcat(commtable->k_help, " for help"); + } + } + *escapes = 0; + return (char *)0; } /* @@ -128,37 +128,37 @@ compile(char *map, struct keymap *commtable) void initkeys() { - char *p; - static struct keymap xx[2]; - - currmap = &xx[0]; - othermap = &xx[1]; - p = compile(defaultmap, currmap); /* Compile default map */ - assert(p == (char *)0); - p = getenv("YAPKEYS"); - if (p) { - if (!(p = compile(p, othermap))) { - /* - * No errors in user defined keymap. So, use it - */ - do_chkm(0L); - return; - } - error(p); - } - othermap = 0; /* No other keymap */ + char *p; + static struct keymap xx[2]; + + currmap = &xx[0]; + othermap = &xx[1]; + p = compile(defaultmap, currmap); /* Compile default map */ + assert(p == (char *)0); + p = getenv("YAPKEYS"); + if (p) { + if (!(p = compile(p, othermap))) { + /* + * No errors in user defined keymap. So, use it + */ + do_chkm(0L); + return; + } + error(p); + } + othermap = 0; /* No other keymap */ } int is_escape(int c) { - char *p = currmap->k_esc; + char *p = currmap->k_esc; - while (*p) { - if (c == *p++) - return 1; - } - return 0; + while (*p) { + if (c == *p++) + return 1; + } + return 0; } static char keyset[16]; /* bitset indicating which keys are @@ -171,8 +171,7 @@ static char keyset[16]; /* bitset indicating which keys are void setused(int key) { - - keyset[(key & 0x7f) >> 3] |= (1 << (key & 0x07)); + keyset[(key & 0x7f) >> 3] |= (1 << (key & 0x07)); } /* @@ -182,6 +181,5 @@ setused(int key) int isused(int key) { - - return keyset[(key & 0x7f) >> 3] & (1 << (key & 0x07)); + return keyset[(key & 0x7f) >> 3] & (1 << (key & 0x07)); } diff --git a/cmd/extra/yap/keys.h b/cmd/extra/yap/keys.h @@ -2,14 +2,14 @@ #define KEYS_H extern struct keymap { - char k_help[80]; - struct state *k_mach; - char k_esc[10]; + char k_help[80]; + struct state *k_mach; + char k_esc[10]; } *currmap, *othermap; void initkeys(void); void setused(int key); -int isused(int key); -int is_escape(int c); +int isused(int key); +int is_escape(int c); #endif diff --git a/cmd/extra/yap/machine.c b/cmd/extra/yap/machine.c @@ -1,10 +1,10 @@ /* Copyright (c) 1985 Ceriel J.H. Jacobs */ -#include <ctype.h> -#include "in_all.h" #include "machine.h" -#include "getline.h" #include "assert.h" +#include "getline.h" +#include "in_all.h" +#include <ctype.h> /* * Add part of finite state machine to recognize the string s. @@ -13,59 +13,58 @@ static int addtomach(char *s, int cnt, struct state **list) { + struct state *l; + int i = FSM_OKE; /* Return value */ + int j; - struct state *l; - int i = FSM_OKE; /* Return value */ - int j; - - for (;;) { - l = *list; - if (!l) { - /* - * Create new list element - */ - *list = l = (struct state *)alloc(sizeof(*l)); - l->s_char = *s; - l->s_endstate = 0; - l->s_match = 0; - l->s_next = 0; - } - if (l->s_char == *s) { - /* - * Continue with next character - */ - if (!*++s) { - /* - * No next character - */ - j = l->s_endstate; - l->s_endstate = 1; - if (l->s_match || j) { - /* - * If the state already was an endstate, - * or has a successor, the currently - * added string is a prefix of an - * already recognized string - */ - return FSM_ISPREFIX; - } - l->s_cnt = cnt; - return i; - } - if (l->s_endstate) { - /* - * In this case, the currently added string has - * a prefix that is an already recognized - * string. - */ - i = FSM_HASPREFIX; - } - list = &(l->s_match); - continue; - } - list = &(l->s_next); - } - /* NOTREACHED */ + for (;;) { + l = *list; + if (!l) { + /* + * Create new list element + */ + *list = l = (struct state *)alloc(sizeof(*l)); + l->s_char = *s; + l->s_endstate = 0; + l->s_match = 0; + l->s_next = 0; + } + if (l->s_char == *s) { + /* + * Continue with next character + */ + if (!*++s) { + /* + * No next character + */ + j = l->s_endstate; + l->s_endstate = 1; + if (l->s_match || j) { + /* + * If the state already was an endstate, + * or has a successor, the currently + * added string is a prefix of an + * already recognized string + */ + return FSM_ISPREFIX; + } + l->s_cnt = cnt; + return i; + } + if (l->s_endstate) { + /* + * In this case, the currently added string has + * a prefix that is an already recognized + * string. + */ + i = FSM_HASPREFIX; + } + list = &(l->s_match); + continue; + } + list = &(l->s_next); + } + /* NOTREACHED */ } /* @@ -75,11 +74,10 @@ addtomach(char *s, int cnt, struct state **list) int addstring(char *s, int cnt, struct state **machine) { - - if (!s || !*s) { - return FSM_ISPREFIX; - } - return addtomach(s, cnt, machine); + if (!s || !*s) { + return FSM_ISPREFIX; + } + return addtomach(s, cnt, machine); } /* @@ -93,42 +91,41 @@ addstring(char *s, int cnt, struct state **machine) int match(char *s, int *i, struct state *mach) { + char *s1 = s; /* Walk through string */ + struct state *mach1 = 0; + /* Keep track of previous state */ - char *s1 = s; /* Walk through string */ - struct state *mach1 = 0; - /* Keep track of previous state */ - - while (mach && *s1) { - if (mach->s_char == *s1) { - /* - * Current character matches. Carry on with next - * character and next state - */ - mach1 = mach; - mach = mach->s_match; - s1++; - continue; - } - mach = mach->s_next; - } - if (!mach1) { - /* - * No characters matched - */ - return 0; - } - if (mach1->s_endstate) { - /* - * The string matched - */ - *i = mach1->s_cnt; - return s1 - s; - } - if (!*s1) { - /* - * The string matched a prefix - */ - return FSM_ISPREFIX; - } - return 0; + while (mach && *s1) { + if (mach->s_char == *s1) { + /* + * Current character matches. Carry on with next + * character and next state + */ + mach1 = mach; + mach = mach->s_match; + s1++; + continue; + } + mach = mach->s_next; + } + if (!mach1) { + /* + * No characters matched + */ + return 0; + } + if (mach1->s_endstate) { + /* + * The string matched + */ + *i = mach1->s_cnt; + return s1 - s; + } + if (!*s1) { + /* + * The string matched a prefix + */ + return FSM_ISPREFIX; + } + return 0; } diff --git a/cmd/extra/yap/machine.h b/cmd/extra/yap/machine.h @@ -2,15 +2,15 @@ #define MACHINE_H struct state { - char s_char; - char s_endstate; - struct state *s_match; - struct state *s_next; - short s_cnt; + char s_char; + char s_endstate; + struct state *s_match; + struct state *s_next; + short s_cnt; }; -#define FSM_OKE 0 -#define FSM_ISPREFIX -1 +#define FSM_OKE 0 +#define FSM_ISPREFIX -1 #define FSM_HASPREFIX 1 int addstring(char *str, int cnt, struct state **mach); diff --git a/cmd/extra/yap/main.c b/cmd/extra/yap/main.c @@ -1,21 +1,21 @@ /* Copyright (c) 1985 Ceriel J.H. Jacobs */ -#include "in_all.h" #include "main.h" -#include "term.h" +#include "commands.h" +#include "display.h" +#include "in_all.h" #include "options.h" #include "output.h" #include "process.h" -#include "commands.h" -#include "display.h" #include "prompt.h" +#include "term.h" -int nopipe; +int nopipe; char *progname; -int interrupt; -int no_tty; +int interrupt; +int no_tty; -static int initialize(int x); +static int initialize(int x); static void sigquit(int signo); #ifdef SIGTSTP static void suspsig(int signo); @@ -24,34 +24,32 @@ static void suspsig(int signo); int main(int argc, char **argv) { - char **av; - - (void)setlocale(LC_CTYPE, ""); - if (!isatty(1)) { - no_tty = 1; - } - argv[argc] = 0; - progname = argv[0]; - if ((av = readoptions(argv)) == (char **)0 || - initialize(*av ? 1 : 0)) { - if (no_tty) { - close(1); - (void)dup(2); - } - putline("Usage: "); - putline(argv[0]); - putline( - " [-c] [-u] [-n] [-q] [-number] [+command] [file ... ]\n"); - flush(); - exit(1); - } - if (no_tty) { - *--av = "cat"; - execve("/bin/cat", av, (char *const[]){NULL}); - } else - processfiles(argc - (av - argv), av); - (void)quit(); - /* NOTREACHED */ + char **av; + + (void)setlocale(LC_CTYPE, ""); + if (!isatty(1)) { + no_tty = 1; + } + argv[argc] = 0; + progname = argv[0]; + if ((av = readoptions(argv)) == (char **)0 || initialize(*av ? 1 : 0)) { + if (no_tty) { + close(1); + (void)dup(2); + } + putline("Usage: "); + putline(argv[0]); + putline(" [-c] [-u] [-n] [-q] [-number] [+command] [file ... ]\n"); + flush(); + exit(1); + } + if (no_tty) { + *--av = "cat"; + execve("/bin/cat", av, (char *const[]){NULL}); + } else + processfiles(argc - (av - argv), av); + (void)quit(); + /* NOTREACHED */ } /* @@ -66,58 +64,57 @@ main(int argc, char **argv) static int initialize(int x) { - - if (!(nopipe = x)) { - /* - * Reading from pipe - */ - if (isatty(0)) { - return 1; - } - stdf = dup(0); /* Duplicate file descriptor of input */ - if (no_tty) - return 0; - /* - * Make sure standard input is from the terminal. - */ - (void)close(0); - if (open("/dev/tty", O_RDONLY, 0) != 0) { - putline("Couldn't open terminal\n"); - flush(); - exit(1); - } - } - if (no_tty) - return 0; - /* - * Handle signals. - * Catch QUIT, DELETE and ^Z - */ - (void)signal(SIGQUIT, SIG_IGN); - (void)signal(SIGINT, catchdel); - ini_terminal(); + if (!(nopipe = x)) { + /* + * Reading from pipe + */ + if (isatty(0)) { + return 1; + } + stdf = dup(0); /* Duplicate file descriptor of input */ + if (no_tty) + return 0; + /* + * Make sure standard input is from the terminal. + */ + (void)close(0); + if (open("/dev/tty", O_RDONLY, 0) != 0) { + putline("Couldn't open terminal\n"); + flush(); + exit(1); + } + } + if (no_tty) + return 0; + /* + * Handle signals. + * Catch QUIT, DELETE and ^Z + */ + (void)signal(SIGQUIT, SIG_IGN); + (void)signal(SIGINT, catchdel); + ini_terminal(); #ifdef SIGTSTP - if (signal(SIGTSTP, SIG_IGN) == SIG_DFL) { - (void)signal(SIGTSTP, suspsig); - } + if (signal(SIGTSTP, SIG_IGN) == SIG_DFL) { + (void)signal(SIGTSTP, suspsig); + } #endif - (void)signal(SIGQUIT, sigquit); - return 0; + (void)signal(SIGQUIT, sigquit); + return 0; } void catchdel(int signo) { - (void)signo; - (void)signal(SIGINT, catchdel); - interrupt = 1; + (void)signo; + (void)signal(SIGINT, catchdel); + interrupt = 1; } static void sigquit(int signo) { - (void)signo; - quit(); + (void)signo; + quit(); } #ifdef SIGTSTP @@ -130,22 +127,21 @@ sigquit(int signo) void suspend() { - - nflush(); - resettty(); - (void)signal(SIGTSTP, SIG_DFL); - (void)kill(0, SIGTSTP); - /* - * We are not here anymore ... - * - - * - * But we arive here ... - */ - inittty(); - putline(TI); - flush(); - (void)signal(SIGTSTP, suspsig); + nflush(); + resettty(); + (void)signal(SIGTSTP, SIG_DFL); + (void)kill(0, SIGTSTP); + /* + * We are not here anymore ... + * + + * + * But we arive here ... + */ + inittty(); + putline(TI); + flush(); + (void)signal(SIGTSTP, suspsig); } /* @@ -156,11 +152,11 @@ suspend() static void suspsig(int signo) { - (void)signo; + (void)signo; - suspend(); - if (DoneSetJmp) - longjmp(SetJmpBuf, 1); + suspend(); + if (DoneSetJmp) + longjmp(SetJmpBuf, 1); } #endif @@ -172,11 +168,10 @@ suspsig(int signo) int quit() { - - clrbline(); - resettty(); - flush(); - exit(0); + clrbline(); + resettty(); + flush(); + exit(0); } /* @@ -187,9 +182,8 @@ quit() void panic(char *s) { - - putline("\a\a\a\r\n"); - putline(s); - putline("\r\n"); - quit(); + putline("\a\a\a\r\n"); + putline(s); + putline("\r\n"); + quit(); } diff --git a/cmd/extra/yap/main.h b/cmd/extra/yap/main.h @@ -1,14 +1,14 @@ #ifndef MAIN_H #define MAIN_H -extern int nopipe; +extern int nopipe; extern char *progname; -extern int interrupt; -extern int no_tty; +extern int interrupt; +extern int no_tty; -int main(int argc, char **argv); +int main(int argc, char **argv); void catchdel(int signo); -int quit(void); +int quit(void); void panic(char *s); #ifdef SIGTSTP diff --git a/cmd/extra/yap/options.c b/cmd/extra/yap/options.c @@ -1,15 +1,15 @@ /* Copyright (c) 1985 Ceriel J.H. Jacobs */ -#include "in_all.h" #include "options.h" -#include "output.h" #include "display.h" +#include "in_all.h" +#include "output.h" #include <ctype.h> -int cflag; -int uflag; -int nflag; -int qflag; +int cflag; +int uflag; +int nflag; +int qflag; char *startcomm; static int parsopt(char *s); @@ -22,70 +22,69 @@ static int parsopt(char *s); char ** readoptions(char **argv) { + char **av = argv + 1; + char *p; - char **av = argv + 1; - char *p; - - if ((p = getenv("YAP")) != 0) { - (void)parsopt(p); - } - while (*av && **av == '-') { - if (parsopt(*av)) { - /* - * Error in option - */ - putline(*av); - putline(": illegal option\n"); - return (char **)0; - } - av++; - } - if (*av && **av == '+') { - /* - * Command in command line - */ - startcomm = *av + 1; - av++; - } - return av; + if ((p = getenv("YAP")) != 0) { + (void)parsopt(p); + } + while (*av && **av == '-') { + if (parsopt(*av)) { + /* + * Error in option + */ + putline(*av); + putline(": illegal option\n"); + return (char **)0; + } + av++; + } + if (*av && **av == '+') { + /* + * Command in command line + */ + startcomm = *av + 1; + av++; + } + return av; } static int parsopt(char *s) { - int i; + int i; - if (*s == '-') - s++; - if (isdigit(*s)) { - /* - * pagesize option - */ - i = 0; - do { - i = i * 10 + *s++ - '0'; - } while (isdigit(*s)); - if (i < MINPAGESIZE) - i = MINPAGESIZE; - pagesize = i; - } - while (*s) { - switch (*s++) { - case 'c': - cflag++; - break; - case 'n': - nflag++; - break; - case 'u': - uflag++; - break; - case 'q': - qflag++; - break; - default: - return 1; - } - } - return 0; + if (*s == '-') + s++; + if (isdigit(*s)) { + /* + * pagesize option + */ + i = 0; + do { + i = i * 10 + *s++ - '0'; + } while (isdigit(*s)); + if (i < MINPAGESIZE) + i = MINPAGESIZE; + pagesize = i; + } + while (*s) { + switch (*s++) { + case 'c': + cflag++; + break; + case 'n': + nflag++; + break; + case 'u': + uflag++; + break; + case 'q': + qflag++; + break; + default: + return 1; + } + } + return 0; } diff --git a/cmd/extra/yap/options.h b/cmd/extra/yap/options.h @@ -1,10 +1,10 @@ #ifndef OPTIONS_H #define OPTIONS_H -extern int cflag; -extern int uflag; -extern int nflag; -extern int qflag; +extern int cflag; +extern int uflag; +extern int nflag; +extern int qflag; extern char *startcomm; char **readoptions(char **argv); diff --git a/cmd/extra/yap/output.c b/cmd/extra/yap/output.c @@ -4,11 +4,11 @@ * Handle output to screen */ -#include "in_all.h" #include "output.h" +#include "in_all.h" #include "main.h" -int _ocnt; +int _ocnt; char *_optr; #define OBUFSIZ 64 * 128 @@ -18,38 +18,38 @@ static char _outbuf[OBUFSIZ]; void flush() { /* Flush output buffer, by writing it */ - char *p = _outbuf; + char *p = _outbuf; - _ocnt = OBUFSIZ; - if (_optr) - (void)write(1, p, _optr - p); - _optr = p; + _ocnt = OBUFSIZ; + if (_optr) + (void)write(1, p, _optr - p); + _optr = p; } void nflush() { /* Flush output buffer, ignoring it */ - _ocnt = OBUFSIZ; - _optr = _outbuf; + _ocnt = OBUFSIZ; + _optr = _outbuf; } int fputch(int ch) { /* print a character */ - putch(ch); - return ch; + putch(ch); + return ch; } void putline(char *s) { /* Print string s */ - if (!s) - return; - while (*s) { - putch(*s++); - } + if (!s) + return; + while (*s) { + putch(*s++); + } } /* @@ -59,15 +59,15 @@ putline(char *s) void cputline(char *s) { - int c; - - while ((c = *s++) != 0) { - if ((unsigned char)c < ' ' || (unsigned char)c == 0x7f) { - putch('^'); - c ^= 0x40; - } - putch(c); - } + int c; + + while ((c = *s++) != 0) { + if ((unsigned char)c < ' ' || (unsigned char)c == 0x7f) { + putch('^'); + c ^= 0x40; + } + putch(c); + } } /* @@ -77,26 +77,25 @@ cputline(char *s) void prnum(long n) { - - putline(getnum(n)); + putline(getnum(n)); } static char * fillnum(long n, char *p) { - if (n >= 10) { - p = fillnum(n / 10, p); - } - *p++ = (int)(n % 10) + '0'; - *p = '\0'; - return p; + if (n >= 10) { + p = fillnum(n / 10, p); + } + *p++ = (int)(n % 10) + '0'; + *p = '\0'; + return p; } char * getnum(long n) { - static char buf[20]; + static char buf[20]; - fillnum(n, buf); - return buf; + fillnum(n, buf); + return buf; } diff --git a/cmd/extra/yap/output.h b/cmd/extra/yap/output.h @@ -1,22 +1,22 @@ #ifndef OUTPUT_H #define OUTPUT_H -extern int _ocnt; +extern int _ocnt; extern char *_optr; -#define putch(ch) \ - do { \ - if (--_ocnt <= 0) \ - flush(); \ - *_optr++ = (ch); \ - } while (0) +#define putch(ch) \ + do { \ + if (--_ocnt <= 0) \ + flush(); \ + *_optr++ = (ch); \ + } while (0) -void flush(void); -void nflush(void); -int fputch(int c); -void putline(char *s); -void cputline(char *s); -void prnum(long n); +void flush(void); +void nflush(void); +int fputch(int c); +void putline(char *s); +void cputline(char *s); +void prnum(long n); char *getnum(long n); #endif diff --git a/cmd/extra/yap/pattern.c b/cmd/extra/yap/pattern.c @@ -1,5 +1,5 @@ -#include "in_all.h" #include "pattern.h" +#include "in_all.h" #include <regex.h> /* @@ -7,28 +7,27 @@ */ static regex_t pattern; -static int pattern_valid; +static int pattern_valid; char * re_comp(char *s) { - - if (!*s) { - return (char *)0; - } - if (pattern_valid) { - regfree(&pattern); - pattern_valid = 0; - } - if (regcomp(&pattern, s, 0) == 0) { - pattern_valid = 1; - return (char *)0; - } - return "Error in pattern"; + if (!*s) { + return (char *)0; + } + if (pattern_valid) { + regfree(&pattern); + pattern_valid = 0; + } + if (regcomp(&pattern, s, 0) == 0) { + pattern_valid = 1; + return (char *)0; + } + return "Error in pattern"; } int re_exec(char *s) { - return pattern_valid && regexec(&pattern, s, 0, (regmatch_t *)0, 0) == 0; + return pattern_valid && regexec(&pattern, s, 0, (regmatch_t *)0, 0) == 0; } diff --git a/cmd/extra/yap/pattern.h b/cmd/extra/yap/pattern.h @@ -2,6 +2,6 @@ #define PATTERN_H char *re_comp(char *s); -int re_exec(char *s); +int re_exec(char *s); #endif diff --git a/cmd/extra/yap/process.c b/cmd/extra/yap/process.c @@ -1,23 +1,23 @@ /* Copyright (c) 1985 Ceriel J.H. Jacobs */ -#include "in_all.h" #include "process.h" #include "commands.h" #include "display.h" -#include "prompt.h" -#include "getline.h" #include "getcomm.h" +#include "getline.h" +#include "in_all.h" #include "main.h" #include "options.h" #include "output.h" +#include "prompt.h" jmp_buf SetJmpBuf; -int DoneSetJmp; -int stdf; -int filecount; -char **filenames; -char *currentfile; -long maxpos; +int DoneSetJmp; +int stdf; +int filecount; +char **filenames; +char *currentfile; +long maxpos; static int nfiles; /* Number of filenames on command line */ @@ -28,24 +28,24 @@ static int nfiles; /* Number of filenames on command line */ void visitfile(char *fn) { - struct stat statbuf; + struct stat statbuf; - if (stdf > 0) { - /* - * Close old input file - */ - (void)close(stdf); - } - currentfile = fn; - if ((stdf = open(fn, O_RDONLY, 0)) < 0) { - error(": could not open"); - maxpos = 0; - } else { /* Get size for percentage in prompt */ - (void)fstat(stdf, &statbuf); - maxpos = statbuf.st_size; - } - do_clean(); - d_clean(); + if (stdf > 0) { + /* + * Close old input file + */ + (void)close(stdf); + } + currentfile = fn; + if ((stdf = open(fn, O_RDONLY, 0)) < 0) { + error(": could not open"); + maxpos = 0; + } else { /* Get size for percentage in prompt */ + (void)fstat(stdf, &statbuf); + maxpos = statbuf.st_size; + } + do_clean(); + d_clean(); } /* @@ -56,45 +56,44 @@ visitfile(char *fn) void processfiles(int n, char **argv) { + static char *dummies[3]; + long arg; - static char *dummies[3]; - long arg; - - if (!(nfiles = n)) { - /* - * Input from pipe - */ - currentfile = "standard-input"; - /* - * Take care that *(filenames - 1) and *(filenames + 1) are 0 - */ - filenames = &dummies[1]; - d_clean(); - do_clean(); - } else { - filenames = argv; - (void)nextfile(0); - } - *--argv = 0; - if (startcomm) { - n = getcomm(&arg); - if (commands[n].c_flags & NEEDS_SCREEN) { - redraw(0); - } - do_comm(n, arg); - startcomm = 0; - } - redraw(1); - if (setjmp(SetJmpBuf)) { - nflush(); - redraw(1); - } - DoneSetJmp = 1; - for (;;) { - interrupt = 0; - n = getcomm(&arg); - do_comm(n, arg); - } + if (!(nfiles = n)) { + /* + * Input from pipe + */ + currentfile = "standard-input"; + /* + * Take care that *(filenames - 1) and *(filenames + 1) are 0 + */ + filenames = &dummies[1]; + d_clean(); + do_clean(); + } else { + filenames = argv; + (void)nextfile(0); + } + *--argv = 0; + if (startcomm) { + n = getcomm(&arg); + if (commands[n].c_flags & NEEDS_SCREEN) { + redraw(0); + } + do_comm(n, arg); + startcomm = 0; + } + redraw(1); + if (setjmp(SetJmpBuf)) { + nflush(); + redraw(1); + } + DoneSetJmp = 1; + for (;;) { + interrupt = 0; + n = getcomm(&arg); + do_comm(n, arg); + } } /* @@ -104,12 +103,12 @@ processfiles(int n, char **argv) int nextfile(int n) { - int i; + int i; - if ((i = filecount + n) >= nfiles || i < 0) { - return 1; - } - filecount = i; - visitfile(filenames[i]); - return 0; + if ((i = filecount + n) >= nfiles || i < 0) { + return 1; + } + filecount = i; + visitfile(filenames[i]); + return 0; } diff --git a/cmd/extra/yap/process.h b/cmd/extra/yap/process.h @@ -4,16 +4,16 @@ #include <setjmp.h> extern jmp_buf SetJmpBuf; -extern int DoneSetJmp; +extern int DoneSetJmp; -extern int stdf; -extern int filecount; +extern int stdf; +extern int filecount; extern char **filenames; -extern char *currentfile; -extern long maxpos; +extern char *currentfile; +extern long maxpos; void visitfile(char *fn); void processfiles(int n, char **argv); -int nextfile(int n); +int nextfile(int n); #endif diff --git a/cmd/extra/yap/prompt.c b/cmd/extra/yap/prompt.c @@ -1,19 +1,19 @@ /* Copyright (c) 1985 Ceriel J.H. Jacobs */ -#include "in_all.h" #include "prompt.h" -#include "term.h" -#include "output.h" -#include "options.h" +#include "assert.h" +#include "commands.h" #include "display.h" -#include "process.h" -#include "getline.h" -#include "main.h" #include "getcomm.h" -#include "machine.h" +#include "getline.h" +#include "in_all.h" #include "keys.h" -#include "assert.h" -#include "commands.h" +#include "machine.h" +#include "main.h" +#include "options.h" +#include "output.h" +#include "process.h" +#include "term.h" static char *errorgiven; /* Set to error message, if there is one */ @@ -22,10 +22,10 @@ static char *display_basename(char *path, char *scratch, size_t scratch_size); char * copy(char *p, const char *ep, char *s) { - while (p < ep && *s) { - *p++ = *s++; - } - return p; + while (p < ep && *s) { + *p++ = *s++; + } + return p; } /* @@ -35,104 +35,98 @@ copy(char *p, const char *ep, char *s) void give_prompt() { + char **name; + struct scr_info *p = &scr_info; + char buf[256]; + char filebuf[256]; + char *pb = buf; - char **name; - struct scr_info *p = &scr_info; - char buf[256]; - char filebuf[256]; - char *pb = buf; - - if (startcomm) - return; - flush(); - if (window()) { - redraw(0); - flush(); - } - if (!stupid) { - /* - * fancy prompt - */ - clrbline(); - standout(); - pb = copy(pb, &buf[255], - display_basename(currentfile, filebuf, sizeof(filebuf))); - if (stdf >= 0) { - pb = copy(pb, &buf[255], ", "); - pb = copy(pb, &buf[255], getnum(p->firstline)); - pb = copy(pb, &buf[255], "-"); - pb = copy(pb, &buf[255], getnum(p->lastline)); - } - } else { - *pb++ = '\007'; /* Stupid terminal, stupid prompt */ - } - if (errorgiven) { - /* - * display error message - */ - pb = copy(pb, &buf[255], " "); - pb = copy(pb, &buf[255], errorgiven); - if (stupid) { - pb = copy(pb, &buf[255], "\r\n"); - } - errorgiven = 0; - } else if (!stupid && (status || maxpos)) { - pb = copy(pb, &buf[255], " ("); - name = &filenames[filecount]; - if (status) { - /* - * indicate top and/or bottom - */ - if (status & START) { - if (!*(name - 1)) { - pb = copy(pb, &buf[255], "Top"); - } else { - pb = copy(pb, &buf[255], "Previous: "); - pb = copy(pb, &buf[255], display_basename(*(name - 1), - filebuf, - sizeof(filebuf))); - } - if (status & EOFILE) { - pb = copy(pb, &buf[255], ", "); - } - } - if (status & EOFILE) { - if (!*(name + 1)) { - pb = copy(pb, &buf[255], "Bottom"); - } else { - pb = copy(pb, &buf[255], "Next: "); - pb = copy(pb, &buf[255], display_basename(*(name + 1), - filebuf, - sizeof(filebuf))); - } - } - } else { /* display percentage */ - pb = copy(pb, &buf[255], getnum((100 * getpos(p->lastline)) / maxpos)); - pb = copy(pb, &buf[255], "%"); - } - pb = copy(pb, &buf[255], ")"); - } - *pb = '\0'; - if (!stupid) { - buf[COLS - 1] = 0; - putline(buf); - standend(); - } else - putline(buf); + if (startcomm) + return; + flush(); + if (window()) { + redraw(0); + flush(); + } + if (!stupid) { + /* + * fancy prompt + */ + clrbline(); + standout(); + pb = copy(pb, &buf[255], display_basename(currentfile, filebuf, sizeof(filebuf))); + if (stdf >= 0) { + pb = copy(pb, &buf[255], ", "); + pb = copy(pb, &buf[255], getnum(p->firstline)); + pb = copy(pb, &buf[255], "-"); + pb = copy(pb, &buf[255], getnum(p->lastline)); + } + } else { + *pb++ = '\007'; /* Stupid terminal, stupid prompt */ + } + if (errorgiven) { + /* + * display error message + */ + pb = copy(pb, &buf[255], " "); + pb = copy(pb, &buf[255], errorgiven); + if (stupid) { + pb = copy(pb, &buf[255], "\r\n"); + } + errorgiven = 0; + } else if (!stupid && (status || maxpos)) { + pb = copy(pb, &buf[255], " ("); + name = &filenames[filecount]; + if (status) { + /* + * indicate top and/or bottom + */ + if (status & START) { + if (!*(name - 1)) { + pb = copy(pb, &buf[255], "Top"); + } else { + pb = copy(pb, &buf[255], "Previous: "); + pb = copy(pb, &buf[255], display_basename(*(name - 1), filebuf, sizeof(filebuf))); + } + if (status & EOFILE) { + pb = copy(pb, &buf[255], ", "); + } + } + if (status & EOFILE) { + if (!*(name + 1)) { + pb = copy(pb, &buf[255], "Bottom"); + } else { + pb = copy(pb, &buf[255], "Next: "); + pb = copy(pb, &buf[255], display_basename(*(name + 1), filebuf, sizeof(filebuf))); + } + } + } else { /* display percentage */ + pb = copy(pb, &buf[255], getnum((100 * getpos(p->lastline)) / maxpos)); + pb = copy(pb, &buf[255], "%"); + } + pb = copy(pb, &buf[255], ")"); + } + *pb = '\0'; + if (!stupid) { + buf[COLS - 1] = 0; + putline(buf); + standend(); + } else + putline(buf); } static char * display_basename(char *path, char *scratch, size_t scratch_size) { - char *base; + char *base; - if (!path || scratch_size == 0) { - return ""; - } - (void)strncpy(scratch, path, scratch_size - 1); - scratch[scratch_size - 1] = '\0'; - base = basename(scratch); - return base ? base : scratch; + if (!path || scratch_size == 0) { + return ""; + } + (void)strncpy(scratch, path, scratch_size - 1); + scratch[scratch_size - 1] = '\0'; + base = basename(scratch); + return base ? base : scratch; } /* @@ -142,33 +136,32 @@ display_basename(char *path, char *scratch, size_t scratch_size) void error(char *str) { - - errorgiven = str; + errorgiven = str; } void ret_to_continue() { /* Obvious */ - int c; - static char buf[2]; + int c; + static char buf[2]; - for (;;) { - clrbline(); - standout(); - if (errorgiven) { - putline(errorgiven); - putline(" "); - errorgiven = 0; - } - putline("[Type anything to continue]"); - standend(); - if (is_escape(c = getch())) { - buf[0] = c; - (void)match(buf, &c, currmap->k_mach); - assert(c > 0); - do_comm(c, -1L); - } else - break; - } - clrbline(); + for (;;) { + clrbline(); + standout(); + if (errorgiven) { + putline(errorgiven); + putline(" "); + errorgiven = 0; + } + putline("[Type anything to continue]"); + standend(); + if (is_escape(c = getch())) { + buf[0] = c; + (void)match(buf, &c, currmap->k_mach); + assert(c > 0); + do_comm(c, -1L); + } else + break; + } + clrbline(); } diff --git a/cmd/extra/yap/term.c b/cmd/extra/yap/term.c @@ -4,31 +4,31 @@ * Terminal handling routines, mostly initializing. */ -#include "in_all.h" #include "term.h" -#include "machine.h" -#include "output.h" #include "display.h" -#include "options.h" #include "getline.h" +#include "in_all.h" #include "keys.h" +#include "machine.h" #include "main.h" +#include "options.h" +#include "output.h" #define getline yap_getline -#define getch yap_getch +#define getch yap_getch #include <term.h> #undef getch #undef getline #undef insert_line -int expandtabs; -int stupid; -int hardcopy; -char *CE, *CL, *SO, *SE, *US, *UE, *UC, *MD, *ME, *TI, *TE, *CM, *TA, *SR, *AL; -char *UP, *HO, *BO; -int LINES, COLS, AM, XN, DB; -int erasech, killch; +int expandtabs; +int stupid; +int hardcopy; +char *CE, *CL, *SO, *SE, *US, *UE, *UC, *MD, *ME, *TI, *TE, *CM, *TA, *SR, *AL; +char *UP, *HO, *BO; +int LINES, COLS, AM, XN, DB; +int erasech, killch; struct state *sppat; -char *BC; +char *BC; #ifdef TIOCGWINSZ static struct winsize w; @@ -48,8 +48,8 @@ static void handle(cc_t *c) { /* if character *c is used, set it to undefined */ - if (isused(*c)) - *c = 0xff; + if (isused(*c)) + *c = 0xff; } /* @@ -60,93 +60,93 @@ handle(cc_t *c) void inittty() { - struct termios *p = &_tty; - - tcgetattr(0, p); - _svtty = *p; - p->c_oflag &= ~OPOST; - p->c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON); - if (isused('S' & 0x1f) || isused('Q' & 0x1f)) - p->c_iflag &= ~IXON; - handle(&p->c_cc[VINTR]); - handle(&p->c_cc[VQUIT]); - erasech = p->c_cc[VERASE]; - killch = p->c_cc[VKILL]; - p->c_cc[VMIN] = 1; /* Just wait for one character */ - p->c_cc[VTIME] = 0; - tcsetattr(0, TCSANOW, p); + struct termios *p = &_tty; + + tcgetattr(0, p); + _svtty = *p; + p->c_oflag &= ~OPOST; + p->c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON); + if (isused('S' & 0x1f) || isused('Q' & 0x1f)) + p->c_iflag &= ~IXON; + handle(&p->c_cc[VINTR]); + handle(&p->c_cc[VQUIT]); + erasech = p->c_cc[VERASE]; + killch = p->c_cc[VKILL]; + p->c_cc[VMIN] = 1; /* Just wait for one character */ + p->c_cc[VTIME] = 0; + tcsetattr(0, TCSANOW, p); } void backspace() { - putline(BC); + putline(BC); } void clrscreen() { - tputs(CL, LINES, fputch); + tputs(CL, LINES, fputch); } void clrtoeol() { - tputs(CE, 1, fputch); + tputs(CE, 1, fputch); } void scrollreverse() { - tputs(SR, LINES, fputch); + tputs(SR, LINES, fputch); } void standout() { - tputs(SO, 1, fputch); + tputs(SO, 1, fputch); } void standend() { - tputs(SE, 1, fputch); + tputs(SE, 1, fputch); } void underline() { - tputs(US, 1, fputch); + tputs(US, 1, fputch); } void end_underline() { - tputs(UE, 1, fputch); + tputs(UE, 1, fputch); } void bold() { - tputs(MD, 1, fputch); + tputs(MD, 1, fputch); } void end_bold() { - tputs(ME, 1, fputch); + tputs(ME, 1, fputch); } void underchar() { - tputs(UC, 1, fputch); + tputs(UC, 1, fputch); } void givetab() { - tputs(TA, 1, fputch); + tputs(TA, 1, fputch); } /* @@ -156,9 +156,9 @@ givetab() void resettty() { - tcsetattr(0, TCSANOW, &_svtty); - putline(TE); - flush(); + tcsetattr(0, TCSANOW, &_svtty); + putline(TE); + flush(); } /* @@ -169,30 +169,30 @@ resettty() static char * getcap(char *cap) { - char *s; + char *s; - s = tigetstr(cap); - if (!s || s == (char *)-1) - return ""; - return s; + s = tigetstr(cap); + if (!s || s == (char *)-1) + return ""; + return s; } static int getflag(char *cap) { - int value; + int value; - value = tigetflag(cap); - return value < 0 ? 0 : value; + value = tigetflag(cap); + return value < 0 ? 0 : value; } static int getnumcap(char *cap) { - int value; + int value; - value = tigetnum(cap); - return value < 0 ? -1 : value; + value = tigetnum(cap); + return value < 0 ? -1 : value; } /* @@ -202,156 +202,155 @@ getnumcap(char *cap) void ini_terminal() { - - char *s; - struct linelist *lp, *lp1; - int i; - int UG, SG; - char tempbuf[20]; - char *mb, *mh, *mr; /* attributes */ - int err; - - initkeys(); + char *s; + struct linelist *lp, *lp1; + int i; + int UG, SG; + char tempbuf[20]; + char *mb, *mh, *mr; /* attributes */ + int err; + + initkeys(); #ifdef TIOCSPGRP - proc_id = getpid(); - ioctl(0, TIOCGPGRP, (char *)&saved_pgrpid); + proc_id = getpid(); + ioctl(0, TIOCGPGRP, (char *)&saved_pgrpid); #endif - inittty(); - stupid = 1; - BC = "\b"; - TA = "\t"; - if (!(s = getenv("TERM"))) - s = "dumb"; - if (setupterm(s, 1, &err) != 0) { - panic("No terminfo entry"); - } - stupid = 0; - hardcopy = getflag("hc"); /* Hard copy terminal?*/ - if (*(s = getcap("cub1"))) { - /* - * Backspace if not ^H - */ - BC = s; - } - UP = getcap("cuu1"); /* move up a line */ - CE = getcap("el"); /* clear to end of line */ - CL = getcap("clear"); /* clear screen */ - if (!*CL) - cflag = 1; - TI = getcap("smcup"); /* Initialization for CM */ - TE = getcap("rmcup"); /* end for CM */ - CM = getcap("cup"); /* cursor addressing */ - SR = getcap("ri"); /* scroll reverse */ - AL = getcap("il"); /* Insert line */ - SO = getcap("smso"); /* standout */ - SE = getcap("rmso"); /* standend */ - SG = getnumcap("xmc"); /* blanks left by attributes */ - if (SG < 0) - SG = 0; - US = getcap("smul"); /* underline */ - UE = getcap("rmul"); /* end underline */ - UG = getnumcap("xmc"); /* blanks left by attributes */ - if (UG < 0) - UG = 0; - UC = getcap("uc"); /* underline a character */ - mb = getcap("blink"); /* blinking attribute */ - MD = getcap("bold"); /* bold attribute */ - ME = getcap("sgr0"); /* turn off attributes */ - mh = getcap("dim"); /* half bright attribute */ - mr = getcap("rev"); /* reversed video attribute */ - if (!nflag) { - /* - * Recognize special strings - */ - (void)addstring(SO, SG, &sppat); - (void)addstring(SE, SG, &sppat); - (void)addstring(US, UG, &sppat); - (void)addstring(UE, UG, &sppat); - (void)addstring(mb, 0, &sppat); - (void)addstring(MD, 0, &sppat); - (void)addstring(ME, 0, &sppat); - (void)addstring(mh, 0, &sppat); - (void)addstring(mr, 0, &sppat); - if (*UC) { - (void)strcpy(tempbuf, BC); - (void)strcat(tempbuf, UC); - (void)addstring(tempbuf, 0, &sppat); - } - } - if (UG > 0 || uflag) { - US = ""; - UE = ""; - } - if (*US || uflag) - UC = ""; - COLS = getnumcap("cols"); /* columns on page */ - i = getnumcap("lines"); /* Lines on page */ - AM = getflag("am"); /* terminal wraps automatically? */ - XN = getflag("xenl"); /* and then ignores next newline? */ - DB = getflag("db"); /* terminal retains lines below */ - HO = getcap("home"); - if (!*HO && *CM) { - HO = tiparm(CM, 0, 0); /* Another way of getting home */ - } - if ((!*CE && !*AL) || !*HO || hardcopy) { - cflag = stupid = 1; - } - if (*(s = getcap("ht"))) { - /* - * Tab (other than ^I or padding) - */ - TA = s; - } - if (!*(ll = getcap("ll")) && *CM && i > 0) { - /* - * Lower left hand corner - */ - BO = tiparm(CM, i - 1, 0); - } else - BO = ll; - if (COLS <= 0 || COLS > 256) { - if ((unsigned)COLS >= 65409) { - /* SUN bug */ - COLS &= 0xffff; - COLS -= (65409 - 128); - } - if (COLS <= 0 || COLS > 256) - COLS = 80; - } - if (i <= 0) { - i = 24; - cflag = stupid = 1; - } - LINES = i; - maxpagesize = i - 1; - scrollsize = maxpagesize / 2; - if (scrollsize <= 0) - scrollsize = 1; - if (!pagesize || pagesize >= i) { - pagesize = maxpagesize; - } - - /* - * The next part does not really belong here, but there it is ... - * Initialize a circular list for the screenlines. - */ - - scr_info.tail = lp = _X; - lp1 = lp + (100 - 1); - for (; lp <= lp1; lp++) { - /* - * Circular doubly linked list - */ - lp->next = lp + 1; - lp->prev = lp - 1; - } - lp1->next = scr_info.tail; - lp1->next->prev = lp1; - if (stupid) { - BO = "\r\n"; - } - putline(TI); - window(); + inittty(); + stupid = 1; + BC = "\b"; + TA = "\t"; + if (!(s = getenv("TERM"))) + s = "dumb"; + if (setupterm(s, 1, &err) != 0) { + panic("No terminfo entry"); + } + stupid = 0; + hardcopy = getflag("hc"); /* Hard copy terminal?*/ + if (*(s = getcap("cub1"))) { + /* + * Backspace if not ^H + */ + BC = s; + } + UP = getcap("cuu1"); /* move up a line */ + CE = getcap("el"); /* clear to end of line */ + CL = getcap("clear"); /* clear screen */ + if (!*CL) + cflag = 1; + TI = getcap("smcup"); /* Initialization for CM */ + TE = getcap("rmcup"); /* end for CM */ + CM = getcap("cup"); /* cursor addressing */ + SR = getcap("ri"); /* scroll reverse */ + AL = getcap("il"); /* Insert line */ + SO = getcap("smso"); /* standout */ + SE = getcap("rmso"); /* standend */ + SG = getnumcap("xmc"); /* blanks left by attributes */ + if (SG < 0) + SG = 0; + US = getcap("smul"); /* underline */ + UE = getcap("rmul"); /* end underline */ + UG = getnumcap("xmc"); /* blanks left by attributes */ + if (UG < 0) + UG = 0; + UC = getcap("uc"); /* underline a character */ + mb = getcap("blink"); /* blinking attribute */ + MD = getcap("bold"); /* bold attribute */ + ME = getcap("sgr0"); /* turn off attributes */ + mh = getcap("dim"); /* half bright attribute */ + mr = getcap("rev"); /* reversed video attribute */ + if (!nflag) { + /* + * Recognize special strings + */ + (void)addstring(SO, SG, &sppat); + (void)addstring(SE, SG, &sppat); + (void)addstring(US, UG, &sppat); + (void)addstring(UE, UG, &sppat); + (void)addstring(mb, 0, &sppat); + (void)addstring(MD, 0, &sppat); + (void)addstring(ME, 0, &sppat); + (void)addstring(mh, 0, &sppat); + (void)addstring(mr, 0, &sppat); + if (*UC) { + (void)strcpy(tempbuf, BC); + (void)strcat(tempbuf, UC); + (void)addstring(tempbuf, 0, &sppat); + } + } + if (UG > 0 || uflag) { + US = ""; + UE = ""; + } + if (*US || uflag) + UC = ""; + COLS = getnumcap("cols"); /* columns on page */ + i = getnumcap("lines"); /* Lines on page */ + AM = getflag("am"); /* terminal wraps automatically? */ + XN = getflag("xenl"); /* and then ignores next newline? */ + DB = getflag("db"); /* terminal retains lines below */ + HO = getcap("home"); + if (!*HO && *CM) { + HO = tiparm(CM, 0, 0); /* Another way of getting home */ + } + if ((!*CE && !*AL) || !*HO || hardcopy) { + cflag = stupid = 1; + } + if (*(s = getcap("ht"))) { + /* + * Tab (other than ^I or padding) + */ + TA = s; + } + if (!*(ll = getcap("ll")) && *CM && i > 0) { + /* + * Lower left hand corner + */ + BO = tiparm(CM, i - 1, 0); + } else + BO = ll; + if (COLS <= 0 || COLS > 256) { + if ((unsigned)COLS >= 65409) { + /* SUN bug */ + COLS &= 0xffff; + COLS -= (65409 - 128); + } + if (COLS <= 0 || COLS > 256) + COLS = 80; + } + if (i <= 0) { + i = 24; + cflag = stupid = 1; + } + LINES = i; + maxpagesize = i - 1; + scrollsize = maxpagesize / 2; + if (scrollsize <= 0) + scrollsize = 1; + if (!pagesize || pagesize >= i) { + pagesize = maxpagesize; + } + + /* + * The next part does not really belong here, but there it is ... + * Initialize a circular list for the screenlines. + */ + + scr_info.tail = lp = _X; + lp1 = lp + (100 - 1); + for (; lp <= lp1; lp++) { + /* + * Circular doubly linked list + */ + lp->next = lp + 1; + lp->prev = lp - 1; + } + lp1->next = scr_info.tail; + lp1->next->prev = lp1; + if (stupid) { + BO = "\r\n"; + } + putline(TI); + window(); } /* @@ -361,28 +360,27 @@ ini_terminal() void mgoto(int n) { - - if (n == 0) - home(); - else if (n == maxpagesize && *BO) - bottom(); - else if (*CM) { - /* - * Cursor addressing - */ - tputs(tiparm(CM, n, 0), 1, fputch); - } else if (*BO && *UP && n >= (maxpagesize >> 1)) { - /* - * Bottom and then up - */ - bottom(); - while (n++ < maxpagesize) - putline(UP); - } else { /* Home, and then down */ - home(); - while (n--) - putline("\r\n"); - } + if (n == 0) + home(); + else if (n == maxpagesize && *BO) + bottom(); + else if (*CM) { + /* + * Cursor addressing + */ + tputs(tiparm(CM, n, 0), 1, fputch); + } else if (*BO && *UP && n >= (maxpagesize >> 1)) { + /* + * Bottom and then up + */ + bottom(); + while (n++ < maxpagesize) + putline(UP); + } else { /* Home, and then down */ + home(); + while (n--) + putline("\r\n"); + } } /* @@ -392,68 +390,65 @@ mgoto(int n) void clrbline() { - - if (stupid) { - putline("\r\n"); - return; - } - bottom(); - if (*CE) { - /* - * We can clear to end of line - */ - clrtoeol(); - return; - } - ins_line(maxpagesize); + if (stupid) { + putline("\r\n"); + return; + } + bottom(); + if (*CE) { + /* + * We can clear to end of line + */ + clrtoeol(); + return; + } + ins_line(maxpagesize); } void ins_line(int l) { - tputs(tiparm(AL, l), maxpagesize - l, fputch); + tputs(tiparm(AL, l), maxpagesize - l, fputch); } void home() { - - tputs(HO, 1, fputch); + tputs(HO, 1, fputch); } void bottom() { - - tputs(BO, 1, fputch); - if (!*BO) - mgoto(maxpagesize); + tputs(BO, 1, fputch); + if (!*BO) + mgoto(maxpagesize); } int window() { #ifdef TIOCGWINSZ - if (ioctl(1, TIOCGWINSZ, &w) < 0) - return 0; - - if (w.ws_col == 0) - w.ws_col = COLS; - if (w.ws_row == 0) - w.ws_row = LINES; - if (w.ws_col != COLS || w.ws_row != LINES) { - COLS = w.ws_col; - LINES = w.ws_row; - maxpagesize = LINES - 1; - pagesize = maxpagesize; - if (!*ll) - BO = tiparm(CM, maxpagesize, 0); - scr_info.currentpos = 0; - scrollsize = maxpagesize / 2; - if (scrollsize <= 0) - scrollsize = 1; - return 1; - } + if (ioctl(1, TIOCGWINSZ, &w) < 0) + return 0; + + if (w.ws_col == 0) + w.ws_col = COLS; + if (w.ws_row == 0) + w.ws_row = LINES; + if (w.ws_col != COLS || w.ws_row != LINES) { + COLS = w.ws_col; + LINES = w.ws_row; + maxpagesize = LINES - 1; + pagesize = maxpagesize; + if (!*ll) + BO = tiparm(CM, maxpagesize, 0); + scr_info.currentpos = 0; + scrollsize = maxpagesize / 2; + if (scrollsize <= 0) + scrollsize = 1; + return 1; + } #endif - return 0; + return 0; } diff --git a/cmd/extra/yap/term.h b/cmd/extra/yap/term.h @@ -30,10 +30,10 @@ extern int AM; extern int XN; extern int DB; -extern int erasech; -extern int killch; +extern int erasech; +extern int killch; extern struct state *sppat; -extern char *BC; +extern char *BC; void inittty(void); void resettty(void); @@ -54,7 +54,7 @@ void mgoto(int n); void clrbline(void); void home(void); void bottom(void); -int window(void); +int window(void); void ins_line(int l); #define insert_line(l) ins_line(l) diff --git a/cmd/net/wget.c b/cmd/net/wget.c @@ -176,7 +176,7 @@ stream_getc(struct Stream *s) return (unsigned char)s->buf[s->idx++]; } s->idx = 0; - r = tls_read(s->ts, s->buf, sizeof(s->buf)); + r = tlss_read(s->ts, s->buf, sizeof(s->buf)); if (r <= 0) { s->len = 0; return EOF; @@ -201,7 +201,7 @@ stream_read(struct Stream *s, void *ptr, size_t size) total += n; } else { s->idx = 0; - r = tls_read(s->ts, s->buf, sizeof(s->buf)); + r = tlss_read(s->ts, s->buf, sizeof(s->buf)); if (r <= 0) { s->len = 0; break; @@ -299,7 +299,7 @@ req_printf(struct TlsSocket *ts, const char *fmt, ...) len = vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); if (len > 0) - tls_write(ts, buf, len); + tlss_write(ts, buf, len); } // ?man wget: retrieve files from the web @@ -469,7 +469,7 @@ main(int argc, char *argv[]) if (sock_fd < 0) eprintf("failed to connect to %s:%s\n", host, port); - tls_sock = tls_connect(sock_fd, host, !no_check_certificate, is_tls); + tls_sock = tlss_connect(sock_fd, host, !no_check_certificate, is_tls); if (!tls_sock) { close(sock_fd); eprintf("failed to establish TLS connection with %s\n", host); @@ -512,12 +512,12 @@ main(int argc, char *argv[]) req_printf(tls_sock, "\r\n"); if (post_data) { - tls_write(tls_sock, post_data, strlen(post_data)); + tlss_write(tls_sock, post_data, strlen(post_data)); } else if (post_file) { char io_buf[8192]; ssize_t r; while ((r = read(post_fd, io_buf, sizeof(io_buf))) > 0) { - if (tls_write(tls_sock, io_buf, r) < 0) { + if (tlss_write(tls_sock, io_buf, r) < 0) { eprintf("failed to write post data:\n"); } } @@ -530,7 +530,7 @@ main(int argc, char *argv[]) header_end = NULL; memset(s.buf, 0, sizeof(s.buf)); while (total_read < sizeof(s.buf) - 1) { - n = tls_read(tls_sock, s.buf + total_read, sizeof(s.buf) - 1 - total_read); + n = tlss_read(tls_sock, s.buf + total_read, sizeof(s.buf) - 1 - total_read); if (n <= 0) { if (n < 0) eprintf("read socket:\n"); @@ -592,7 +592,7 @@ main(int argc, char *argv[]) free(loc); free(url); url = new_url; - tls_close(tls_sock, 1); + tlss_close(tls_sock, 1); tls_sock = NULL; redirects++; } else if (status == 206) { @@ -605,7 +605,7 @@ main(int argc, char *argv[]) "file already fully retrieved or " "range invalid\n" ); - tls_close(tls_sock, 1); + tlss_close(tls_sock, 1); free(url); free(host); free(port); @@ -621,7 +621,7 @@ main(int argc, char *argv[]) } if (spider) { - tls_close(tls_sock, 1); + tlss_close(tls_sock, 1); free(url); return 0; } @@ -652,7 +652,7 @@ main(int argc, char *argv[]) else read_non_chunked(&s, out_fd, content_len); - tls_close(tls_sock, 1); + tlss_close(tls_sock, 1); if (out_fd != 1) close(out_fd); if (Oflag != out_name && Pflag) diff --git a/cmd/posix/bc.y b/cmd/posix/bc.y @@ -41,7 +41,6 @@ static char *whilecode(Macro *, char *, char *); static char *ifcode(Macro *, char *, char *); static char *funcode(Macro *, char *, char *, char *); static char *param(char *, char *), *local(char *, char *); -static Macro *define(char *, char *); static char *retcode(char *); static char *brkcode(void); static Macro *macro(int); @@ -513,8 +512,6 @@ ifcode(Macro *d, char *cmp, char *body) static char * retcode(char *expr) { - char *s; - if (nested < 2 || macros[1].op != DEF) yyerror("return must be in a function"); return code("%s %s %dQ", expr, estrdup(unwind), nested - 1); @@ -643,7 +640,6 @@ digits(char *bp) static int number(int ch) { - int d; char *bp; ungetc(ch, filep); @@ -753,6 +749,7 @@ operand(int ch) case '!': if (getc(filep) == '=') return NE; + /* fallthrough */ default: yyerror("invalid operand"); return 0; @@ -820,6 +817,7 @@ spawn(void) switch (fork()) { case -1: eprintf("forking dc:"); + /* fallthrough */ case 0: close(1); dup(fds[1]); @@ -854,8 +852,6 @@ run(void) static void bc(char *fname) { - Macro *d; - lineno = 1; nested = 0; diff --git a/cmd/posix/make/parser.c b/cmd/posix/make/parser.c @@ -534,7 +534,7 @@ repeat: /* copy and strip trailing whitespace/newline so strcmp works */ strncpy(d, input->buf + 1, sizeof(d) - 1); d[sizeof(d) - 1] = '\0'; - dl = strlen(d); + dl = strlen(d); while (dl > 0 && isspace((unsigned char)d[dl - 1])) d[--dl] = '\0'; if (strncmp(d, "include", 7) == 0 && isblank(d[7])) { diff --git a/cmd/posix/sh/easter.c b/cmd/posix/sh/easter.c @@ -11,7 +11,7 @@ #include <unistd.h> enum { - COMMENT_C, /* line // and block /* */ + COMMENT_C, /* line // and block comments */ COMMENT_HASH, /* line # only */ COMMENT_PERCENT, /* line % only */ COMMENT_SEMI, /* line ; only */ @@ -61,9 +61,9 @@ struct CommentSpec { static const struct CommentSpec comment_specs[] = { [COMMENT_C] = {"//", "/*", "*/"}, - [COMMENT_HASH] = {"#", NULL, NULL}, - [COMMENT_PERCENT] = {"%", NULL, NULL}, - [COMMENT_SEMI] = {";", NULL, NULL}, + [COMMENT_HASH] = {"#", NULL, NULL}, + [COMMENT_PERCENT] = {"%", NULL, NULL}, + [COMMENT_SEMI] = {";", NULL, NULL}, [COMMENT_DASH] = {"--", NULL, NULL}, [COMMENT_HASKELL] = {"--", "{-", "-}"}, [COMMENT_PAREN] = {NULL, "(*", "*)"}, @@ -77,35 +77,35 @@ struct LangDef { }; static const struct LangDef lang_defs[LANG_COUNT] = { - [LANG_C] = {"C", 1, COMMENT_C }, - [LANG_CPP] = {"C++", 300, COMMENT_C }, - [LANG_SH] = {"Shell", 6, COMMENT_HASH }, - [LANG_AWK] = {"Awk", 6, COMMENT_HASH }, - [LANG_MAKE] = {"Make", 10, COMMENT_HASH }, - [LANG_M4] = {"M4", 25, COMMENT_HASH }, - [LANG_LUA] = {"Lua", 25, COMMENT_DASH }, - [LANG_PERL] = {"Perl", 500, COMMENT_HASH }, - [LANG_PYTHON] = {"Python", 80, COMMENT_HASH }, - [LANG_RUBY] = {"Ruby", 90, COMMENT_HASH }, - [LANG_PHP] = {"PHP", 110, COMMENT_C }, - [LANG_JS] = {"JS", 100, COMMENT_C }, - [LANG_TS] = {"TS", 140, COMMENT_C }, - [LANG_JAVA] = {"Java", 150, COMMENT_C }, - [LANG_KOTLIN] = {"Kotlin", 160, COMMENT_C }, - [LANG_SCALA] = {"Scala", 180, COMMENT_C }, - [LANG_CS] = {"C#", 140, COMMENT_C }, - [LANG_GO] = {"Go", 3, COMMENT_C }, - [LANG_SWIFT] = {"Swift", 70, COMMENT_C }, - [LANG_ZIG] = {"Zig", 65, COMMENT_C }, - [LANG_DART] = {"Dart", 55, COMMENT_C }, - [LANG_ELIXIR] = {"Elixir", 50, COMMENT_HASH }, - [LANG_ERLANG] = {"Erlang", 55, COMMENT_PERCENT}, - [LANG_HASKELL] = {"Haskell", 200, COMMENT_HASKELL}, - [LANG_OCAML] = {"OCaml", 45, COMMENT_PAREN }, - [LANG_CLOJURE] = {"Clojure", 85, COMMENT_SEMI }, - [LANG_RUST] = {"Rust", 3000, COMMENT_C }, - [LANG_ADA] = {"Ada", 15, COMMENT_DASH }, - [LANG_R] = {"R", 40, COMMENT_HASH }, + [LANG_C] = {"C", 1, COMMENT_C}, + [LANG_CPP] = {"C++", 300, COMMENT_C}, + [LANG_SH] = {"Shell", 6, COMMENT_HASH}, + [LANG_AWK] = {"Awk", 6, COMMENT_HASH}, + [LANG_MAKE] = {"Make", 10, COMMENT_HASH}, + [LANG_M4] = {"M4", 25, COMMENT_HASH}, + [LANG_LUA] = {"Lua", 25, COMMENT_DASH}, + [LANG_PERL] = {"Perl", 500, COMMENT_HASH}, + [LANG_PYTHON] = {"Python", 80, COMMENT_HASH}, + [LANG_RUBY] = {"Ruby", 90, COMMENT_HASH}, + [LANG_PHP] = {"PHP", 110, COMMENT_C}, + [LANG_JS] = {"JS", 100, COMMENT_C}, + [LANG_TS] = {"TS", 140, COMMENT_C}, + [LANG_JAVA] = {"Java", 150, COMMENT_C}, + [LANG_KOTLIN] = {"Kotlin", 160, COMMENT_C}, + [LANG_SCALA] = {"Scala", 180, COMMENT_C}, + [LANG_CS] = {"C#", 140, COMMENT_C}, + [LANG_GO] = {"Go", 3, COMMENT_C}, + [LANG_SWIFT] = {"Swift", 70, COMMENT_C}, + [LANG_ZIG] = {"Zig", 65, COMMENT_C}, + [LANG_DART] = {"Dart", 55, COMMENT_C}, + [LANG_ELIXIR] = {"Elixir", 50, COMMENT_HASH}, + [LANG_ERLANG] = {"Erlang", 55, COMMENT_PERCENT}, + [LANG_HASKELL] = {"Haskell", 200, COMMENT_HASKELL}, + [LANG_OCAML] = {"OCaml", 45, COMMENT_PAREN}, + [LANG_CLOJURE] = {"Clojure", 85, COMMENT_SEMI}, + [LANG_RUST] = {"Rust", 3000, COMMENT_C}, + [LANG_ADA] = {"Ada", 15, COMMENT_DASH}, + [LANG_R] = {"R", 40, COMMENT_HASH}, }; struct ExtMap { @@ -114,51 +114,18 @@ struct ExtMap { }; static const struct ExtMap ext_map[] = { - {".c", LANG_C }, - {".cc", LANG_CPP }, - {".cpp", LANG_CPP }, - {".cxx", LANG_CPP }, - {".hpp", LANG_CPP }, - {".sh", LANG_SH }, - {".awk", LANG_AWK }, - {".mk", LANG_MAKE }, - {".m4", LANG_M4 }, - {".lua", LANG_LUA }, - {".pl", LANG_PERL }, - {".pm", LANG_PERL }, - {".py", LANG_PYTHON }, - {".pyw", LANG_PYTHON }, - {".rb", LANG_RUBY }, - {".php", LANG_PHP }, - {".js", LANG_JS }, - {".mjs", LANG_JS }, - {".cjs", LANG_JS }, - {".ts", LANG_TS }, - {".tsx", LANG_TS }, - {".java", LANG_JAVA }, - {".kt", LANG_KOTLIN }, - {".kts", LANG_KOTLIN }, - {".scala", LANG_SCALA }, - {".cs", LANG_CS }, - {".go", LANG_GO }, - {".swift", LANG_SWIFT }, - {".zig", LANG_ZIG }, - {".dart", LANG_DART }, - {".ex", LANG_ELIXIR }, - {".exs", LANG_ELIXIR }, - {".erl", LANG_ERLANG }, - {".hrl", LANG_ERLANG }, - {".hs", LANG_HASKELL}, - {".lhs", LANG_HASKELL}, - {".ml", LANG_OCAML }, - {".mli", LANG_OCAML }, - {".clj", LANG_CLOJURE}, - {".cljs", LANG_CLOJURE}, - {".rs", LANG_RUST }, - {".adb", LANG_ADA }, - {".ads", LANG_ADA }, - {".r", LANG_R }, - {".R", LANG_R }, + {".c", LANG_C}, {".cc", LANG_CPP}, {".cpp", LANG_CPP}, {".cxx", LANG_CPP}, + {".hpp", LANG_CPP}, {".sh", LANG_SH}, {".awk", LANG_AWK}, {".mk", LANG_MAKE}, + {".m4", LANG_M4}, {".lua", LANG_LUA}, {".pl", LANG_PERL}, {".pm", LANG_PERL}, + {".py", LANG_PYTHON}, {".pyw", LANG_PYTHON}, {".rb", LANG_RUBY}, {".php", LANG_PHP}, + {".js", LANG_JS}, {".mjs", LANG_JS}, {".cjs", LANG_JS}, {".ts", LANG_TS}, + {".tsx", LANG_TS}, {".java", LANG_JAVA}, {".kt", LANG_KOTLIN}, {".kts", LANG_KOTLIN}, + {".scala", LANG_SCALA}, {".cs", LANG_CS}, {".go", LANG_GO}, {".swift", LANG_SWIFT}, + {".zig", LANG_ZIG}, {".dart", LANG_DART}, {".ex", LANG_ELIXIR}, {".exs", LANG_ELIXIR}, + {".erl", LANG_ERLANG}, {".hrl", LANG_ERLANG}, {".hs", LANG_HASKELL}, {".lhs", LANG_HASKELL}, + {".ml", LANG_OCAML}, {".mli", LANG_OCAML}, {".clj", LANG_CLOJURE}, {".cljs", LANG_CLOJURE}, + {".rs", LANG_RUST}, {".adb", LANG_ADA}, {".ads", LANG_ADA}, {".r", LANG_R}, + {".R", LANG_R}, }; struct NameMap { @@ -167,24 +134,37 @@ struct NameMap { }; static const struct NameMap name_map[] = { - {"Makefile", LANG_MAKE}, - {"GNUmakefile", LANG_MAKE}, - {".profile", LANG_SH }, - {"profile", LANG_SH }, - {".bashrc", LANG_SH }, - {".bash_profile", LANG_SH }, - {".shrc", LANG_SH }, - {".kshrc", LANG_SH }, - {".zshrc", LANG_SH }, - {".cshrc", LANG_SH }, - {".login", LANG_SH }, + {"Makefile", LANG_MAKE}, + {"GNUmakefile", LANG_MAKE}, + {".profile", LANG_SH}, + {"profile", LANG_SH}, + {".bashrc", LANG_SH}, + {".bash_profile", LANG_SH}, + {".shrc", LANG_SH}, + {".kshrc", LANG_SH}, + {".zshrc", LANG_SH}, + {".cshrc", LANG_SH}, + {".login", LANG_SH}, }; /* not scanned for lines, but still checked against markers below */ static const char *const skip_dirs[] = { - ".git", ".hg", ".svn", "node_modules", "vendor", "__pycache__", - ".venv", "venv", "target", "build", "dist", ".cache", - ".next", ".idea", ".vscode", NULL, + ".git", + ".hg", + ".svn", + "node_modules", + "vendor", + "__pycache__", + ".venv", + "venv", + "target", + "build", + "dist", + ".cache", + ".next", + ".idea", + ".vscode", + NULL, }; struct Marker { @@ -195,14 +175,14 @@ struct Marker { }; static const struct Marker markers[] = { - {"node_modules", 1, 150.0, "skipping bullshit / malware" }, - {"Cargo.toml", 0, 80.0, "I challenge you to bootstrapping this shitty lang" }, - {"package.json", 0, 60.0, "js. Self-explanatory" }, - {"go.mod", 0, 20.0, "Not C. But still good. Minor penalty" }, - {"Dockerfile", 0, 20.0, "containerization crutch" }, - {"Gemfile", 0, 55.0, "shitty language baseline" }, - {"CMakeLists.txt", 0, 55.0, "shitty build system" }, - {"tsconfig.json", 0, 60.0, "a language with a configuration file. Degenerate." }, + {"node_modules", 1, 150.0, "skipping bullshit / malware"}, + {"Cargo.toml", 0, 80.0, "I challenge you to bootstrapping this shitty lang"}, + {"package.json", 0, 60.0, "js. Self-explanatory"}, + {"go.mod", 0, 20.0, "Not C. But still good. Minor penalty"}, + {"Dockerfile", 0, 20.0, "containerization crutch"}, + {"Gemfile", 0, 55.0, "shitty language baseline"}, + {"CMakeLists.txt", 0, 55.0, "shitty build system"}, + {"tsconfig.json", 0, 60.0, "a language with a configuration file. Degenerate."}, }; struct ComboPenalty { @@ -214,9 +194,9 @@ struct ComboPenalty { static const struct ComboPenalty combos[] = { {LANG_RUST, LANG_CPP, 4000.0, "MAXIMUM BOGUSNESS, rust and c++ sharing a tree"}, - {LANG_RUST, LANG_C, 400.0, "comical bogusness, rust apologizing to the c it links against"}, - {LANG_JS, LANG_TS, 150.0, "half the codebase does not trust the other half"}, - {LANG_C, LANG_CPP, 120.0, "abi boundary between two compilers of the same language"}, + {LANG_RUST, LANG_C, 400.0, "comical bogusness, rust apologizing to the c it links against"}, + {LANG_JS, LANG_TS, 150.0, "half the codebase does not trust the other half"}, + {LANG_C, LANG_CPP, 120.0, "abi boundary between two compilers of the same language"}, }; struct LangStat { @@ -314,10 +294,10 @@ static void scan_file(int dirfd, const char *name, int lang, struct LangStat *lp) { const struct CommentSpec *cs; - char buf[8192]; - char *p, *bufend; - ssize_t nread; - int fd, in_block, leading_ws, checked, line_has_content, line_is_comment; + char buf[8192]; + char *p, *bufend; + ssize_t nread; + int fd, in_block, leading_ws, checked, line_has_content, line_is_comment; fd = openat(dirfd, name, O_RDONLY); if (fd < 0) @@ -388,7 +368,7 @@ static void scan(int dirfd, const char *name, struct stat *st, void *data, struct recursor *r) { struct ScanState *scanst = data; - int lang; + int lang; check_marker(name, S_ISDIR(st->st_mode), scanst); @@ -431,9 +411,14 @@ bogometercmd(int argc, char **argv) for (i = 0; i < LANG_COUNT; i++) { if (st.stats[i].files == 0) continue; - printf("%-10s %10ld %10ld %10ld %10ld\n", - lang_defs[i].name, st.stats[i].files, st.stats[i].blank, st.stats[i].comment, - st.stats[i].code); + printf( + "%-10s %10ld %10ld %10ld %10ld\n", + lang_defs[i].name, + st.stats[i].files, + st.stats[i].blank, + st.stats[i].comment, + st.stats[i].code + ); total_code += st.stats[i].code; } @@ -443,41 +428,49 @@ bogometercmd(int argc, char **argv) } printf("---------------------------------------------------------\n"); - modern_langs = 0; - for (i = 0; i < LANG_COUNT; i++) { - if (st.stats[i].code == 0) - continue; - pct = ((double)st.stats[i].code / total_code) * 100.0; - score += pct * lang_defs[i].weight; - printf("Distribution: %-6s is %5.2f%% of targeted language lines\n", lang_defs[i].name, pct); - if (!is_classic(i)) - modern_langs++; - } + modern_langs = 0; + for (i = 0; i < LANG_COUNT; i++) { + if (st.stats[i].code == 0) + continue; + pct = ((double)st.stats[i].code / total_code) * 100.0; + score += pct * lang_defs[i].weight; + printf("Distribution: %-6s is %5.2f%% of targeted language lines\n", lang_defs[i].name, pct); + if (!is_classic(i)) + modern_langs++; + } - if (modern_langs >= BABEL_THRESHOLD) { + if (modern_langs >= BABEL_THRESHOLD) { score *= BABEL_MULT; - fprintf(stderr, - "note: %d languages in one tree: babel tower, no two files agree on what tongue they speak\n", - modern_langs); + fprintf( + stderr, + "note: %d languages in one tree: babel tower, no two files agree on what tongue they " + "speak\n", + modern_langs + ); } fflush(stdout); - for (i = 0; i < (int)LEN(combos); i++) { - if (st.stats[combos[i].lang_a].code > 0 && st.stats[combos[i].lang_b].code > 0) { - score += combos[i].penalty; - fprintf(stderr, "note: %s + %s: %s\n", lang_defs[combos[i].lang_a].name, - lang_defs[combos[i].lang_b].name, combos[i].remark); - fflush(stderr); - } + for (i = 0; i < (int)LEN(combos); i++) { + if (st.stats[combos[i].lang_a].code > 0 && st.stats[combos[i].lang_b].code > 0) { + score += combos[i].penalty; + fprintf( + stderr, + "note: %s + %s: %s\n", + lang_defs[combos[i].lang_a].name, + lang_defs[combos[i].lang_b].name, + combos[i].remark + ); + fflush(stderr); } + } if (st.stats[LANG_RUST].code > 0 && st.stats[LANG_CPP].code == 0 && st.stats[LANG_C].code == 0) fprintf(stderr, "note: rust: enormous magnitudes of bogus\n"); score += st.bonus; - if (modern_langs == 0 && st.stats[LANG_C].code > 0 && st.stats[LANG_SH].code > 0 && - st.stats[LANG_AWK].code > 0) + if (modern_langs == 0 && st.stats[LANG_C].code > 0 && st.stats[LANG_SH].code > 0 + && st.stats[LANG_AWK].code > 0) printf("note: sh + awk + c only: peak codebase\n"); printf("---------------------------------------------------------\n"); diff --git a/ninqu.rules b/ninqu.rules @@ -1,6 +1,6 @@ ; genconfig.sh config produces four files from build.cfg: -; config.set (read by ninqu), config.kv (sourced by genbox.sh), -; nofork_list.h (included by wexec.c), and features.h (-include'd +; config.set (read by ninqu), config.kv (read by mkman), +; nofork_list.h (included by wexec.c), and features.h (-included ; into every compile). each gets its own rule so ninqu can find a ; producer for any of them ; @@ -75,21 +75,21 @@ (diff "-lm") (wget $(LDLIBS_TLS))) -; Every .c file in a category builds into its own binary. PERFILE captures -; that shared rule. Only EXTRA_AFTER differs cuz POSIX waits for GETCONF_H -; the rest pass "". cmd/posix/bc.c overrides this with its own yacc-based -; rule, so no need for PERFILE to have that as a special case +; Every .c file in a category builds into its own binary. (PERFILE) +; Only EXTRA_AFTER differs cuz POSIX waits for GETCONF_H, the rest pass "". +; cmd/posix/bc.c overrides this with its own yacc-based rule, so no need for +; PERFILE to have that as a special case ; (template PERFILE (NAME CATEGORY DESC EXTRA_AFTER) (rule $(NAME) (glob "cmd/$(CATEGORY)/*.c") (gate build_$(CATEGORY)_$(IDENT)) - (dep $(MATCH)) - (after LIBUTIL LIBUTF $(EXTRA_AFTER)) + (dep $(MATCH) LIBUTIL LIBUTF) + (after $(EXTRA_AFTER)) (out $(STEM)) (description $(DESC)) (feature perfile) - (exec $(CC) $(CPPFLAGS) $(CFLAGS) -o $(OUT) $(MATCH) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS) $(EXTRA_LIBS:$(BASESTEM))))) + (exec $(CC) $(CPPFLAGS) $(CFLAGS) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) $(EXTRA_LIBS:$(BASESTEM))))) (use PERFILE POSIX_BIN posix "one POSIX2024 utility per source file under cmd/posix" GETCONF_H) (use PERFILE LINUX_BIN linux "Linux-only utility, one source file per binary under cmd/linux" "") @@ -106,8 +106,8 @@ (group extra lib EXTRA_BIN EXTRA_YAP) ; codegen: generate sources consumed by the build rules below. Ungated -; generators always run; conditional ones use (req) so they only run -; when their inputs exist in this checkout +; ones always run. conditional ones use (req) so they only run when +; their inputs exists in this checkout ; (rule GETCONF_H (gate build_posix_getconf) @@ -158,10 +158,9 @@ (rule POSIX_BC (gate build_posix_bc) (member posix bc) - (dep POSIX_BC_OBJ) - (after LIBUTIL LIBUTF) + (dep POSIX_BC_OBJ LIBUTIL LIBUTF) (out "cmd/posix/bc") - (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS) -lm)) + (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) -lm)) (rule POSIX_AWK_OBJ (glob "cmd/posix/awk/*.c") @@ -175,10 +174,9 @@ (rule POSIX_AWK (gate build_posix_awk) (member posix awk) - (dep POSIX_AWK_OBJ) - (after LIBUTIL LIBUTF) + (dep POSIX_AWK_OBJ LIBUTIL LIBUTF) (out "cmd/posix/awk/awk") - (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS) -lm)) + (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) -lm)) (rule POSIX_SH_OBJ (glob "cmd/posix/sh/*.c") @@ -192,10 +190,9 @@ (rule POSIX_SH (gate build_posix_sh) (member posix sh) - (dep POSIX_SH_OBJ) - (after LIBUTIL LIBUTF LIBREDLINE) + (dep POSIX_SH_OBJ LIBUTIL LIBUTF LIBREDLINE) (out "cmd/posix/sh/sh") - (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a shared/libredline/libredline.a $(LDFLAGS) $(LDLIBS))) + (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS))) (rule POSIX_MAKE_OBJ (glob "cmd/posix/make/*.c") @@ -207,10 +204,9 @@ (rule POSIX_MAKE (gate build_posix_make) (member posix make) - (dep POSIX_MAKE_OBJ) - (after LIBUTIL LIBUTF) + (dep POSIX_MAKE_OBJ LIBUTIL LIBUTF) (out "cmd/posix/make/make") - (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS))) + (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS))) (rule EXTRA_YAP_OBJ (glob "cmd/extra/yap/*.c") @@ -222,10 +218,9 @@ (rule EXTRA_YAP (gate build_extra_yap) (member extra yap) - (dep EXTRA_YAP_OBJ) - (after LIBUTIL LIBUTF) + (dep EXTRA_YAP_OBJ LIBUTIL LIBUTF) (out "cmd/extra/yap/yap") - (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS) -ltinfo)) + (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) -ltinfo)) ; (member GROUP ALIAS) gives a rule a qualified user-facing name ; (e.g. posix/bc) while keeping its internal name (POSIX_BC) for deps, @@ -245,10 +240,9 @@ (rule AR (gate build_dev_ar) - (dep AR_OBJ) - (after LIBUTIL LIBUTF) + (dep AR_OBJ LIBUTIL LIBUTF) (out "cmd/dev/ar/ar") - (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS))) + (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS))) (rule XCUTIL_OBJ (glob "cmd/dev/xcutil/*.c") @@ -266,10 +260,10 @@ (rule AS (gate build_dev_cc) - (dep AS_OBJ) - (after XCUTIL_OBJ LIBUTIL LIBUTF) + (dep AS_OBJ LIBUTIL LIBUTF) + (after XCUTIL_OBJ) (out "cmd/dev/as/as") - (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS))) + (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS))) (rule LD_OBJ (glob "cmd/dev/ld/*.c") @@ -280,13 +274,13 @@ (rule LD (gate build_dev_ld) - (dep LD_OBJ) - (after XCUTIL_OBJ LIBUTIL LIBUTF) + (dep LD_OBJ LIBUTIL LIBUTF) + (after XCUTIL_OBJ) (out "cmd/dev/ld/ld") - (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS))) + (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS))) ; CCPOOL_OBJ globs the whole directory. The entry points below use -; literal globs, so the override mechanism excludes them automatically +; literal globs, so the override excludes them automatically (rule CCPOOL_OBJ (glob "cmd/dev/cc/*.c") (gate build_dev_cc) @@ -303,10 +297,9 @@ (rule CC1 (gate build_dev_cc) - (dep CC1_OBJ CCPOOL_OBJ) - (after LIBUTIL LIBUTF) + (dep CC1_OBJ CCPOOL_OBJ LIBUTIL LIBUTF) (out "cmd/dev/cc/cc1") - (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS))) + (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS))) (rule CPP_OBJ (glob "cmd/dev/cc/cpp.c") @@ -317,10 +310,9 @@ (rule CPP (gate build_dev_cc) - (dep CPP_OBJ CCPOOL_OBJ) - (after LIBUTIL LIBUTF) + (dep CPP_OBJ CCPOOL_OBJ LIBUTIL LIBUTF) (out "cmd/dev/cc/cpp") - (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS))) + (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS))) (rule CCDRV_OBJ (glob "cmd/dev/cc/driver.c" "cmd/dev/cc/util.c") @@ -331,16 +323,10 @@ (rule CCDRV (gate build_dev_cc) - (dep CCDRV_OBJ) - (after LIBUTIL LIBUTF) + (dep CCDRV_OBJ LIBUTIL LIBUTF) (out "cmd/dev/cc/cc") - (exec $(CC) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a $(LDFLAGS) $(LDLIBS))) + (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS))) -; ninqu itself lives at cmd/dev/ninqu/ninqu and is built by the -; Makefile directly, since it has to exist before this file can be -; parsed. a rule here producing the same path would just race that -; bootstrap compile, so only the box variant below belongs to ninqu -; ; Like BOX_OBJ: rename main and hide other globals so ninqu can link ; into aruu-box. It is still not reentrant, so it stays out of ; NOFORK_LIST @@ -361,6 +347,7 @@ ; (rule MKMAN (dir "scripts/mkman") + (gate build_man) (dep "glob:scripts/mkman/*.go") (out "scripts/mkman/mkman") (exec go build -o mkman .)) @@ -368,6 +355,7 @@ (rule MAN_MDOC (glob "cmd/**/*.c") (mark "?man") + (gate build_man) (dep (after MKMAN)) (out "man/man$(SEC_OF:$(DIR))/$(BASESTEM).$(SEC_OF:$(DIR))") (exec scripts/mkman/mkman -fmt mdoc -config scripts/mk/config.kv -src $(MATCH)) @@ -376,6 +364,7 @@ (rule MAN_TXT (glob "cmd/**/*.c") (mark "?man") + (gate build_man) (dep (after MKMAN)) (out "man/man$(SEC_OF:$(DIR))/$(BASESTEM).$(SEC_OF:$(DIR)).txt") (exec scripts/mkman/mkman -fmt txt -config scripts/mk/config.kv -src $(MATCH)) @@ -418,6 +407,7 @@ printf ' CLEAN misc\n' rm -rf man/man1 man/man8 rm -rf aruu-box .box + rm -rf .ninja_log .ninja_deps printf ' CLEAN done\n' ")) @@ -468,16 +458,38 @@ (group remove REMOVE) (group uninstall REMOVE) -; box: the multi-call binary containing every enabled tool in a single executable -; with a dispatch table. This includes multi-file tools like POSIX_BC, POSIX_AWK, -; POSIX_SH, POSIX_MAKE, and EXTRA_YAP. A single-file tool has its main function -; renamed directly by BOX_OBJ. The multi-file tools use a partial link (ld -r) -; in their respective rules to combine their objects before renaming main, -; preventing helper symbols from colliding. This replaces scripts/mkbox +(rule FMT + (phony) + (shell " + printf ' FMT cmd and shared (skipping dir tools)\n' + find cmd shared -type f \( -name '*.c' -o -name '*.h' \) \ + ! -path 'cmd/posix/awk/*' \ + ! -path 'cmd/posix/sh/*' \ + ! -path 'cmd/posix/make/*' \ + ! -path 'cmd/extra/yap/*' \ + ! -path 'cmd/posix/bc.c' \ + -print | xargs -r clang-format -i + ")) + +(rule FMT_ALL + (phony) + (shell " + printf ' FMT cmd and shared (including dir tools)\n' + find cmd shared -type f \( -name '*.c' -o -name '*.h' \) -print \ + | xargs -r clang-format -i + ")) + +(group fmt FMT) +(group fmt-all FMT_ALL) + +; box: one executable containing every enabled tool, dispatched through +; a table. a single-file tool just gets its main renamed by BOX_OBJ. +; multi-file tools (POSIX_BC, POSIX_AWK, POSIX_SH, POSIX_MAKE, EXTRA_YAP) +; go through a partial link (ld -r) first, merging their objects into +; one before main gets renamed and helper symbols hidden. replaces +; scripts/mkbox ; -; Object files are stored under .box/ to mirror the cmd/ layout and prevent -; collisions with standalone objects. Since standalone and box objects use -; different symbol names, they cannot share a path +; object files live under .box/, mirroring the cmd/ layout ; ; Ninqu determines which tools enter the box using the gate on BOX_OBJ. ; BOX_DISPATCH reads the object paths passed on argv rather than consulting @@ -506,9 +518,9 @@ ; genbox.sh only receives paths via argv ; -; The match directory determines the gate and output path, allowing one rule -; to handle six categories. The multi-file tool bc.c inside cmd/posix is -; automatically excluded via the literal-glob override mechanism +; the match directory picks the gate and output path, so one rule covers +; all six categories. bc.c inside cmd/posix is excluded automatically by +; the literal-glob override mechanism ; (rule BOX_OBJ (glob "cmd/posix/*.c" "cmd/linux/*.c" "cmd/net/*.c" "cmd/pseudo/*.c" @@ -521,11 +533,10 @@ (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)") (group box)) -; Multi-file tools like POSIX_BC, POSIX_AWK, POSIX_SH, POSIX_MAKE, and -; EXTRA_YAP cannot use the single-file objcopy step because their global helper -; symbols would collide when linked into a single binary. Combining these -; objects first with a partial link (ld -r) resolves internal references, making -; it safe to isolate the renamed main function and hide remaining symbols +; POSIX_BC, POSIX_AWK, POSIX_SH, POSIX_MAKE, and EXTRA_YAP cant go through +; the single-file objcopy step, their global helper symbols would collide +; once linked into one binary. a partial link (ld -r) resolves those +; internal references first, then main gets renamed and the rest hidden ; ; Combined objects use the layout .box/cmd/<category>/<tool>.o so genbox.sh ; can parse them without structural modifications @@ -630,12 +641,10 @@ ; based on whether yap is enabled ; (rule BOX - (dep BOX_DISPATCH BOX_OBJ POSIX_BC_BOX POSIX_AWK_BOX POSIX_SH_BOX POSIX_MAKE_BOX EXTRA_YAP_BOX NINQU_BOX_OBJ) - (after LIBUTIL LIBUTF LIBREDLINE) + (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) (out "aruu-box") (description "single multi-call binary, one dispatch table for every enabled tool") -; (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)") - (shell "$(CC) $(CPPFLAGS) $(CFLAGS) -o $(OUT) $(IN) shared/libutil/libutil.a shared/libutf/libutf.a shared/libredline/libredline.a $(LDFLAGS) $(LDLIBS) $(BOX_EXTRA_LIBS)") + (shell "$(CC) $(CPPFLAGS) $(CFLAGS) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) $(BOX_EXTRA_LIBS)") (group box)) (group box BOX) @@ -661,16 +670,10 @@ (group default all) -; ------------------------------------------------------------------- ; meta-targets: apply an override, then build a normal target under ; it. invoke as `ninqu META.TARGET` (`ninqu debug.posix`) or bare -; `ninqu META` to apply the override and build (group default). the -; $(CFLAGS) inside each value is expanded against whatever CFLAGS -; already holds (the config.set default, or a -DCFLAGS=... override) -; at the moment the meta is applied, so these only append, they -; never have to repeat -std=c99 -Wall -Wextra -pedantic themselves -; ------------------------------------------------------------------- - +; `ninqu META` to apply the override and build (group default) +; (meta debug (set CFLAGS "$(CFLAGS) -g -O0")) diff --git a/scripts/genconfig.sh b/scripts/genconfig.sh @@ -158,6 +158,7 @@ clean() { rm -f cmd/posix/awk/awkgram.tab.c cmd/posix/awk/awkgram.tab.h cmd/posix/awk/proctab.c cmd/posix/awk/maketab 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 rm -f scripts/mk/config.set scripts/mk/config.kv scripts/mk/features.h shared/libutil/nofork_list.h + rm -f scripts/mk/ninja-bin.cache } # config: generate config.set, config.kv, nofork_list.h @@ -200,14 +201,17 @@ config() { emit LDFLAGS_TLS "${LDFLAGS_TLS:-}" emit LDLIBS_TLS "${LDLIBS_TLS:-}" + # For when ninqu builds itself, otherwise it won't have this value + emit NINJA_TRY "${NINJA_TRY:-samu,ninja}" + + emit BUILD_MAN "${BUILD_MAN:-0}" + echo "build_man=${BUILD_MAN:-0}" >> "${set_file}" + # these seven are only consulted per-tool below (build_CATEGORY_TOOL, - # build_CATEGORY_$(BASESTEM)), the bare category toggle has no gate - # anywhere in ninqu.rules, (group CATEGORY ...) already does that - # job. config.kv still gets the uppercase copy since genbox.sh - # and mkbox source it directly + # build_CATEGORY_$(BASESTEM)). for g in BUILD_POSIX BUILD_XSI BUILD_NET BUILD_PSEUDO BUILD_EXTRA BUILD_LINUX BUILD_DEV; do eval "val=\${$g:-0}" - echo "${g}=\"${val}\"" >> "${kv_file}" + [ "${BUILD_MAN:-0}" = 1 ] && echo "${g}=\"${val}\"" >> "${kv_file}" done # per-tool toggles: scan cmd/<category>/ for tools. a tool is diff --git a/shared/libutil/tls.c b/shared/libutil/tls.c @@ -22,18 +22,18 @@ struct TlsSocket { #elif FEATURE_USE_BEARSSL #include <bearssl.h> -struct my_x509_context { +struct x509_noverify_ctx { const br_x509_class *vtable; br_x509_minimal_context minimal; }; struct TlsSocket { - int fd; - int is_tls; - br_ssl_client_context sc; - struct my_x509_context my_x509; - unsigned char iobuf[BR_SSL_BUFSIZE_BIDI]; - br_sslio_context ioc; + int fd; + int is_tls; + br_ssl_client_context sc; + struct x509_noverify_ctx x509_noverify; + unsigned char iobuf[BR_SSL_BUFSIZE_BIDI]; + br_sslio_context ioc; }; struct dn_accum { @@ -55,57 +55,57 @@ append_dn_callback(void *dn_ctx, const void *src, size_t len) } static void -my_start_chain(const br_x509_class **ctx, const char *server_name) +x509_noverify_start_chain(const br_x509_class **ctx, const char *server_name) { - struct my_x509_context *t = (struct my_x509_context *)ctx; + struct x509_noverify_ctx *t = (struct x509_noverify_ctx *)ctx; br_x509_minimal_vtable.start_chain((const br_x509_class **)&t->minimal, server_name); } static void -my_start_cert(const br_x509_class **ctx, uint32_t length) +x509_noverify_start_cert(const br_x509_class **ctx, uint32_t length) { - struct my_x509_context *t = (struct my_x509_context *)ctx; + struct x509_noverify_ctx *t = (struct x509_noverify_ctx *)ctx; br_x509_minimal_vtable.start_cert((const br_x509_class **)&t->minimal, length); } static void -my_append(const br_x509_class **ctx, const unsigned char *buf, size_t len) +x509_noverify_append(const br_x509_class **ctx, const unsigned char *buf, size_t len) { - struct my_x509_context *t = (struct my_x509_context *)ctx; + struct x509_noverify_ctx *t = (struct x509_noverify_ctx *)ctx; br_x509_minimal_vtable.append((const br_x509_class **)&t->minimal, buf, len); } static void -my_end_cert(const br_x509_class **ctx) +x509_noverify_end_cert(const br_x509_class **ctx) { - struct my_x509_context *t = (struct my_x509_context *)ctx; + struct x509_noverify_ctx *t = (struct x509_noverify_ctx *)ctx; br_x509_minimal_vtable.end_cert((const br_x509_class **)&t->minimal); } static unsigned -my_end_chain(const br_x509_class **ctx) +x509_noverify_end_chain(const br_x509_class **ctx) { - struct my_x509_context *t = (struct my_x509_context *)ctx; + struct x509_noverify_ctx *t = (struct x509_noverify_ctx *)ctx; (void)br_x509_minimal_vtable.end_chain((const br_x509_class **)&t->minimal); /* always succeed and accept certificate when check_cert is 0 */ return 0; } static const br_x509_pkey * -my_get_pkey(const br_x509_class *const *ctx, unsigned *usages) +x509_noverify_get_pkey(const br_x509_class *const *ctx, unsigned *usages) { - const struct my_x509_context *t = (const struct my_x509_context *)ctx; + const struct x509_noverify_ctx *t = (const struct x509_noverify_ctx *)ctx; return br_x509_minimal_vtable.get_pkey((const br_x509_class *const *)&t->minimal, usages); } -static const br_x509_class my_x509_vtable = { - sizeof(struct my_x509_context), - my_start_chain, - my_start_cert, - my_append, - my_end_cert, - my_end_chain, - my_get_pkey +static const br_x509_class x509_noverify_vtable = { + sizeof(struct x509_noverify_ctx), + x509_noverify_start_chain, + x509_noverify_start_cert, + x509_noverify_append, + x509_noverify_end_cert, + x509_noverify_end_chain, + x509_noverify_get_pkey }; static int @@ -288,7 +288,7 @@ struct TlsSocket { #endif struct TlsSocket * -tls_connect(int fd, const char *host, int check_cert, int is_tls) +tlss_connect(int fd, const char *host, int check_cert, int is_tls) { struct TlsSocket *s; @@ -298,10 +298,10 @@ tls_connect(int fd, const char *host, int check_cert, int is_tls) if (!is_tls) return s; - - /* not every backend below uses these */ +#if !FEATURE_USE_LIBTLS && !FEATURE_USE_BEARSSL && !FEATURE_USE_OPENSSL (void)host; (void)check_cert; +#endif #if FEATURE_USE_LIBTLS { @@ -350,11 +350,11 @@ tls_connect(int fd, const char *host, int check_cert, int is_tls) load_ca_certs(); ca_loaded = 1; } - br_ssl_client_init_full(&s->sc, &s->my_x509.minimal, tas, tas_num); + br_ssl_client_init_full(&s->sc, &s->x509_noverify.minimal, tas, tas_num); } else { - br_ssl_client_init_full(&s->sc, &s->my_x509.minimal, NULL, 0); - s->my_x509.vtable = &my_x509_vtable; - br_ssl_engine_set_x509(&s->sc.eng, &s->my_x509.vtable); + br_ssl_client_init_full(&s->sc, &s->x509_noverify.minimal, NULL, 0); + s->x509_noverify.vtable = &x509_noverify_vtable; + br_ssl_engine_set_x509(&s->sc.eng, &s->x509_noverify.vtable); } br_ssl_engine_set_buffer(&s->sc.eng, s->iobuf, sizeof(s->iobuf), 1); @@ -380,7 +380,7 @@ tls_connect(int fd, const char *host, int check_cert, int is_tls) } ssize_t -tls_read(struct TlsSocket *s, void *buf, size_t len) +tlss_read(struct TlsSocket *s, void *buf, size_t len) { if (!s->is_tls) { for (;;) { @@ -405,7 +405,7 @@ tls_read(struct TlsSocket *s, void *buf, size_t len) } ssize_t -tls_write(struct TlsSocket *s, const void *buf, size_t len) +tlss_write(struct TlsSocket *s, const void *buf, size_t len) { if (!s->is_tls) { for (;;) { @@ -437,7 +437,7 @@ tls_write(struct TlsSocket *s, const void *buf, size_t len) } void -tls_close(struct TlsSocket *s, int close_fd) +tlss_close(struct TlsSocket *s, int close_fd) { if (s->is_tls) { #if FEATURE_USE_LIBTLS diff --git a/shared/tls.h b/shared/tls.h @@ -6,16 +6,16 @@ struct TlsSocket; -/* tlssock_connect takes an already connected socket fd and upgrades it to tls +/* tls_connect takes an already connected socket fd and upgrades it to tls if check_cert is 0 certificate validation is bypassed returns a new tls socket or null on error */ -struct TlsSocket *tls_connect(int fd, const char *host, int check_cert, int is_tls); +struct TlsSocket *tlss_connect(int fd, const char *host, int check_cert, int is_tls); /* standard read and write wrapping either libtls, bearssl or plain fallback */ -ssize_t tls_read(struct TlsSocket *s, void *buf, size_t len); -ssize_t tls_write(struct TlsSocket *s, const void *buf, size_t len); +ssize_t tlss_read(struct TlsSocket *s, void *buf, size_t len); +ssize_t tlss_write(struct TlsSocket *s, const void *buf, size_t len); /* closes the tls connection and optionally closes the socket fd */ -void tls_close(struct TlsSocket *s, int close_fd); +void tlss_close(struct TlsSocket *s, int close_fd); #endif /* tls_h_ */ diff --git a/shared/wexec.h b/shared/wexec.h @@ -44,8 +44,8 @@ int wpclose(FILE *fp); int wsystem(const char *cmd); -void wexecvp_self(const char *name, char *const *argv); -void wexecv_self(const char *path, char *const *argv); +void wexecvp_self(const char *name, char *const *argv) __attribute__((noreturn)); +void wexecv_self(const char *path, char *const *argv) __attribute__((noreturn)); int wpopen_track(FILE *fp, pid_t pid); pid_t wpopen_untrack(FILE *fp);