ref: 67c0977e162f7addd6a3a260205675bd7f949015
parent: 3d2b7a569065bc43c32a7d58f6f73bbe114f6c5b
author: cinap_lenrek <[email protected]>
date: Mon Jan 3 19:21:44 EST 2022
rc: only have single instance of a symbol, extern in header (thanks mcf)
--- a/code.c
+++ b/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/exec.c
+++ b/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/exec.h
+++ b/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/io.h
+++ b/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/rc.h
+++ b/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/subr.c
+++ b/subr.c
@@ -1,5 +1,4 @@
#include "rc.h"
-#include "exec.h"
#include "io.h"
#include "fns.h"
--- a/trap.c
+++ b/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/var.c
+++ b/var.c
@@ -2,6 +2,8 @@
#include "exec.h"
#include "fns.h"
+var *gvar[NVAR];
+
int
hash(char *s, int n)
{