0001-Avoid-multiple-definitions-of-global-variables.patch (5732B)
1 From 8d15541e85b391c1cd86907089d33f70d7ca0f65 Mon Sep 17 00:00:00 2001 2 From: Michael Forney <mforney@mforney.org> 3 Date: Mon, 4 Nov 2019 20:50:08 -0800 4 Subject: [PATCH] Avoid multiple definitions of global variables 5 6 --- 7 exec.c | 9 ++++++++- 8 exec.h | 12 ++++++------ 9 io.c | 1 + 10 io.h | 2 +- 11 lex.c | 3 +++ 12 rc.h | 30 +++++++++++++++--------------- 13 simple.c | 2 ++ 14 subr.c | 1 + 15 var.c | 1 + 16 9 files changed, 38 insertions(+), 23 deletions(-) 17 18 diff --git a/exec.c b/exec.c 19 index 3ad8a0d..268f429 100644 20 --- a/exec.c 21 +++ b/exec.c 22 @@ -3,10 +3,17 @@ 23 #include "exec.h" 24 #include "io.h" 25 #include "fns.h" 26 +int mypid; 27 +thread *runq; 28 +code *codebuf; 29 +int ntrap; 30 +int trap[NSIG]; 31 +int eflagok; 32 + 33 /* 34 * Start executing the given code at the given pc with the given redirection 35 */ 36 -char *argv0="rc"; 37 +char *argv0 = "rc"; 38 39 void 40 start(code *c, int pc, var *local) 41 diff --git a/exec.h b/exec.h 42 index 06d2991..ab0bfb4 100644 43 --- a/exec.h 44 +++ b/exec.h 45 @@ -56,18 +56,18 @@ struct thread{ 46 tree *treenodes; /* tree nodes created by this process */ 47 thread *ret; /* who continues when this finishes */ 48 }; 49 -thread *runq; 50 +extern thread *runq; 51 code *codecopy(code*); 52 -code *codebuf; /* compiler output */ 53 -int ntrap; /* number of outstanding traps */ 54 -int trap[NSIG]; /* number of outstanding traps per type */ 55 +extern code *codebuf; /* compiler output */ 56 +extern int ntrap; /* number of outstanding traps */ 57 +extern int trap[NSIG]; /* number of outstanding traps per type */ 58 struct builtin{ 59 char *name; 60 void (*fnc)(void); 61 }; 62 extern struct builtin Builtin[]; 63 -int eflagok; /* kludge flag so that -e doesn't exit in startup */ 64 -int havefork; 65 +extern int eflagok; /* kludge flag so that -e doesn't exit in startup */ 66 +extern int havefork; 67 68 void execcd(void), execwhatis(void), execeval(void), execexec(void); 69 int execforkexec(void); 70 diff --git a/io.c b/io.c 71 index bb8af4a..228ec56 100644 72 --- a/io.c 73 +++ b/io.c 74 @@ -3,6 +3,7 @@ 75 #include "exec.h" 76 #include "io.h" 77 #include "fns.h" 78 +io *err; 79 int pfmtnest = 0; 80 81 void 82 diff --git a/io.h b/io.h 83 index 21cc6b8..68b9e89 100644 84 --- a/io.h 85 +++ b/io.h 86 @@ -10,7 +10,7 @@ struct io{ 87 int fd; 88 char *bufp, *ebuf, *strp, buf[NBUF]; 89 }; 90 -io *err; 91 +extern io *err; 92 io *openfd(int), *openstr(void), *opencore(char *, int); 93 int emptybuf(io*); 94 void pchr(io*, int); 95 diff --git a/lex.c b/lex.c 96 index d2bef32..943112a 100644 97 --- a/lex.c 98 +++ b/lex.c 99 @@ -22,6 +22,7 @@ idchr(int c) 100 return c>' ' && !strchr("!\"#$%&'()+,-./:;<=>?@[\\]^`{|}~", c); 101 } 102 int future = EOF; 103 +char *promptstr; 104 int doprompt = 1; 105 int inquote; 106 int incomm; 107 @@ -36,6 +37,7 @@ nextc(void) 108 future = getnext(); 109 return future; 110 } 111 +int lastc; 112 /* 113 * Consume the lookahead character. 114 */ 115 @@ -131,6 +133,7 @@ nextis(int c) 116 } 117 return 0; 118 } 119 +char tok[NTOK]; 120 121 char* 122 addtok(char *p, int val) 123 diff --git a/rc.h b/rc.h 124 index 8a6a5bb..cbec275 100644 125 --- a/rc.h 126 +++ b/rc.h 127 @@ -53,7 +53,7 @@ tree *mung1(tree*, tree*), *mung2(tree*, tree*, tree*); 128 tree *mung3(tree*, tree*, tree*, tree*), *epimung(tree*, tree*); 129 tree *simplemung(tree*), *heredoc(tree*); 130 void freetree(tree*); 131 -tree *cmdtree; 132 +extern tree *cmdtree; 133 /* 134 * The first word of any code vector is a reference count. 135 * Always create a new reference to a code vector by calling codecopy(.). 136 @@ -64,10 +64,10 @@ union code{ 137 int i; 138 char *s; 139 }; 140 -char *promptstr; 141 -int doprompt; 142 +extern char *promptstr; 143 +extern int doprompt; 144 #define NTOK 8192 145 -char tok[NTOK]; 146 +extern char tok[NTOK]; 147 #define APPEND 1 148 #define WRITE 2 149 #define READ 3 150 @@ -87,7 +87,7 @@ struct var{ 151 }; 152 var *vlook(char*), *gvlook(char*), *newvar(char*, var*); 153 #define NVAR 521 154 -var *gvar[NVAR]; /* hash for globals */ 155 +extern var *gvar[NVAR]; /* hash for globals */ 156 #define new(type) ((type *)emalloc(sizeof(type))) 157 void *emalloc(long); 158 void *Malloc(ulong); 159 @@ -98,7 +98,7 @@ struct here{ 160 char *name; 161 struct here *next; 162 }; 163 -int mypid; 164 +extern int mypid; 165 /* 166 * Glob character escape in strings: 167 * In a string, GLOB must be followed by *?[ or GLOB. 168 @@ -117,10 +117,10 @@ int mypid; 169 #define threebyte(c) ((c&0xf0)==0xe0) 170 #define fourbyte(c) ((c&0xf8)==0xf0) 171 172 -char **argp; 173 -char **args; 174 -int nerror; /* number of errors encountered during compilation */ 175 -int doprompt; /* is it time for a prompt? */ 176 +extern char **argp; 177 +extern char **args; 178 +extern int nerror; /* number of errors encountered during compilation */ 179 +extern int doprompt; /* is it time for a prompt? */ 180 /* 181 * Which fds are the reading/writing end of a pipe? 182 * Unfortunately, this can vary from system to system. 183 @@ -129,14 +129,14 @@ int doprompt; /* is it time for a prompt? */ 184 */ 185 #define PRD 0 186 #define PWR 1 187 -char *Rcmain, *Fdprefix; 188 +extern char *Rcmain, *Fdprefix; 189 #define register 190 /* 191 * How many dot commands have we executed? 192 * Used to ensure that -v flag doesn't print rcmain. 193 */ 194 -int ndot; 195 +extern int ndot; 196 char *getstatus(void); 197 -int lastc; 198 -int lastword; 199 -int kidpid; 200 +extern int lastc; 201 +extern int lastword; 202 +extern int kidpid; 203 diff --git a/simple.c b/simple.c 204 index d587227..7f1ee12 100644 205 --- a/simple.c 206 +++ b/simple.c 207 @@ -6,6 +6,8 @@ 208 #include "exec.h" 209 #include "io.h" 210 #include "fns.h" 211 +int ndot; 212 + 213 /* 214 * Search through the following code to see if we're just going to exit. 215 */ 216 diff --git a/subr.c b/subr.c 217 index a2d8a18..f031be5 100644 218 --- a/subr.c 219 +++ b/subr.c 220 @@ -23,6 +23,7 @@ efree(void *p) 221 else pfmt(err, "free 0\n"); 222 } 223 extern int lastword, lastdol; 224 +int nerror; 225 226 void 227 yyerror(char *m) 228 diff --git a/var.c b/var.c 229 index 2564ba2..b4a3ef5 100644 230 --- a/var.c 231 +++ b/var.c 232 @@ -1,6 +1,7 @@ 233 #include "rc.h" 234 #include "exec.h" 235 #include "fns.h" 236 +var *gvar[NVAR]; 237 238 int 239 hash(char *s, int n) 240 -- 241 2.24.0 242