ref: 3568e27ec8774a212564c8d2bf6b3d9a19d4d571
parent: 699d2e0ed94bd545bb3dd8c64a3922f56f273f0e
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Jan 3 19:19:36 EST 2022
rc: only have single instance of a symbol, extern in header (thanks mcf)
--- a/sys/src/cmd/rc/code.c
+++ b/sys/src/cmd/rc/code.c
@@ -7,7 +7,7 @@
#define c1 t->child[1]
#define c2 t->child[2]
code *codebuf;
-int codep, ncode, codeline;
+static int codep, ncode, codeline;
#define emitf(x) ((codep!=ncode || morecode()), codebuf[codep].f = (x), codep++)
#define emiti(x) ((codep!=ncode || morecode()), codebuf[codep].i = (x), codep++)
#define emits(x) ((codep!=ncode || morecode()), codebuf[codep].s = (x), codep++)
--- a/sys/src/cmd/rc/exec.c
+++ b/sys/src/cmd/rc/exec.c
@@ -4,6 +4,11 @@
#include "io.h"
#include "fns.h"
+char *argv0="rc";
+io *err;
+int mypid;
+thread *runq;
+
/*
* Start executing the given code at the given pc with the given redirection
*/
@@ -216,8 +221,6 @@
* fabricate bootstrap code and start it (*=(argv);. -bq /usr/lib/rcmain $*)
* start interpreting code
*/
-char *argv0="rc";
-
void
main(int argc, char *argv[])
{
--- a/sys/src/cmd/rc/exec.h
+++ b/sys/src/cmd/rc/exec.h
@@ -57,16 +57,17 @@
char *status; /* status for Xpipewait */
thread *ret; /* who continues when this finishes */
};
-
-thread *runq;
+extern thread *runq;
void turfstack(var*);
+extern int mypid;
+extern int ntrap; /* number of outstanding traps */
+extern int trap[NSIG]; /* number of outstanding traps per type */
+
code *codecopy(code*);
-code *codebuf; /* compiler output */
+extern code *codebuf; /* compiler output */
extern int ifnot;
-int ntrap; /* number of outstanding traps */
-int trap[NSIG]; /* number of outstanding traps per type */
struct builtin{
char *name;
void (*fnc)(void);
@@ -82,5 +83,3 @@
char *srcfile(thread*);
char *getstatus(void);
-
-extern char *argv0;
--- a/sys/src/cmd/rc/io.h
+++ b/sys/src/cmd/rc/io.h
@@ -5,7 +5,6 @@
unsigned char *buf, *bufp, *ebuf;
io *next;
};
-io *err;
io *openiofd(int), *openiostr(void), *openiocore(void*, int);
void pchr(io*, int);
--- a/sys/src/cmd/rc/rc.h
+++ b/sys/src/cmd/rc/rc.h
@@ -123,9 +123,8 @@
void setvar(char*, word*), freevar(var*);
#define NVAR 521
+extern var *gvar[NVAR]; /* hash for globals */
-var *gvar[NVAR]; /* hash for globals */
-
#define new(type) ((type *)emalloc(sizeof(type)))
void *emalloc(long);
@@ -132,8 +131,6 @@
void *erealloc(void *, long);
char *estrdup(char*);
-int mypid;
-
/*
* Glob character escape in strings:
* In a string, GLOB must be followed by *?[ or GLOB.
@@ -152,10 +149,10 @@
#define fourbyte(c) (((c)&0xf8)==0xf0)
#define xbyte(c) (((c)&0xc0)==0x80)
-extern char **argp;
-extern char **args;
+extern char *argv0;
extern int nerror; /* number of errors encountered during compilation */
extern int doprompt; /* is it time for a prompt? */
+extern io *err;
/*
* Which fds are the reading/writing end of a pipe?
@@ -166,3 +163,4 @@
#define PRD 0
#define PWR 1
extern char Rcmain[], Fdprefix[];
+extern char *Signame[];
--- a/sys/src/cmd/rc/subr.c
+++ b/sys/src/cmd/rc/subr.c
@@ -1,5 +1,4 @@
#include "rc.h"
-#include "exec.h"
#include "io.h"
#include "fns.h"
--- a/sys/src/cmd/rc/trap.c
+++ b/sys/src/cmd/rc/trap.c
@@ -2,7 +2,9 @@
#include "exec.h"
#include "fns.h"
#include "io.h"
-extern char *Signame[];
+
+int ntrap;
+int trap[NSIG];
void
dotrap(void)
--- a/sys/src/cmd/rc/var.c
+++ b/sys/src/cmd/rc/var.c
@@ -2,6 +2,8 @@
#include "exec.h"
#include "fns.h"
+var *gvar[NVAR];
+
int
hash(char *s, int n)
{