1 | /* $Id: $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * The shell instance and it's methods.
|
---|
5 | *
|
---|
6 | * Copyright (c) 2007 knut st. osmundsen <[email protected]>
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * This file is part of kBuild.
|
---|
10 | *
|
---|
11 | * kBuild is free software; you can redistribute it and/or modify
|
---|
12 | * it under the terms of the GNU General Public License as published by
|
---|
13 | * the Free Software Foundation; either version 2 of the License, or
|
---|
14 | * (at your option) any later version.
|
---|
15 | *
|
---|
16 | * kBuild is distributed in the hope that it will be useful,
|
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | * GNU General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with kBuild; if not, write to the Free Software
|
---|
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
24 | *
|
---|
25 | */
|
---|
26 |
|
---|
27 | #include "shtypes.h"
|
---|
28 | #include "shthread.h"
|
---|
29 | #include "shfile.h"
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * A shell instance.
|
---|
33 | *
|
---|
34 | * This is the core structure of the shell, it contains all
|
---|
35 | * the data associated with a shell process except that it's
|
---|
36 | * running in a thread and not a separate process.
|
---|
37 | */
|
---|
38 | typedef struct shinstance
|
---|
39 | {
|
---|
40 | struct shinstance *next; /**< The next shell instance. */
|
---|
41 | struct shinstance *prev; /**< The previous shell instance. */
|
---|
42 | struct shinstance *parent; /**< The parent shell instance. */
|
---|
43 | pid_t pid; /**< The (fake) process id of this shell instance. */
|
---|
44 | shtid tid; /**< The thread identifier of the thread for this shell. */
|
---|
45 | shfdtab fdtab; /**< The file descriptor table. */
|
---|
46 |
|
---|
47 | /* error.h */
|
---|
48 | struct jmploc *handler;
|
---|
49 | int exception;
|
---|
50 | int exerrno;
|
---|
51 | int volatile suppressint;
|
---|
52 | int volatile intpending;
|
---|
53 |
|
---|
54 | /* main.h */
|
---|
55 | int rootpid; /**< pid of main shell. */
|
---|
56 | int rootshell; /**< true if we aren't a child of the main shell. */
|
---|
57 | struct shinstance *psh_rootshell; /**< The root shell pointer. (!rootshell) */
|
---|
58 |
|
---|
59 | /* trap.h */
|
---|
60 | int pendingsigs;
|
---|
61 |
|
---|
62 | /* parse.h */
|
---|
63 | int tokpushback;
|
---|
64 | int whichprompt; /**< 1 == PS1, 2 == PS2 */
|
---|
65 |
|
---|
66 | /* output.h */
|
---|
67 | struct output output;
|
---|
68 | struct output errout;
|
---|
69 | struct output memout;
|
---|
70 | struct output *out1;
|
---|
71 | struct output *out2;
|
---|
72 |
|
---|
73 | /* options.h */
|
---|
74 | struct optent optlist[NOPTS];
|
---|
75 | char *minusc; /**< argument to -c option */
|
---|
76 | char *arg0; /**< $0 */
|
---|
77 | struct shparam shellparam; /**< $@ */
|
---|
78 | char **argptr; /**< argument list for builtin commands */
|
---|
79 | char *optionarg; /**< set by nextopt */
|
---|
80 | char *optptr; /**< used by nextopt */
|
---|
81 |
|
---|
82 | /* var.h */
|
---|
83 | struct localvar *localvars;
|
---|
84 | #if ATTY
|
---|
85 | struct var vatty;
|
---|
86 | #endif
|
---|
87 | struct var vifs;
|
---|
88 | struct var vmail;
|
---|
89 | struct var vmpath;
|
---|
90 | struct var vpath;
|
---|
91 | #ifdef _MSC_VER
|
---|
92 | struct var vpath2;
|
---|
93 | #endif
|
---|
94 | struct var vps1;
|
---|
95 | struct var vps2;
|
---|
96 | struct var vps4;
|
---|
97 | #ifndef SMALL
|
---|
98 | struct var vterm;
|
---|
99 | struct var vtermcap;
|
---|
100 | struct var vhistsize;
|
---|
101 | #endif
|
---|
102 |
|
---|
103 | /* myhistedit.h */
|
---|
104 | int displayhist;
|
---|
105 | #ifndef SMALL
|
---|
106 | History *hist;
|
---|
107 | EditLine *el;
|
---|
108 | #endif
|
---|
109 |
|
---|
110 | /* memalloc.h */
|
---|
111 | char *stacknxt;
|
---|
112 | int stacknleft;
|
---|
113 | int sstrnleft;
|
---|
114 | int herefd;
|
---|
115 |
|
---|
116 | /* jobs.h */
|
---|
117 | pid_t backgndpid; /**< pid of last background process */
|
---|
118 | int job_warning; /**< user was warned about stopped jobs */
|
---|
119 |
|
---|
120 | /* input.h */
|
---|
121 | int plinno;
|
---|
122 | int parsenleft; /**< number of characters left in input buffer */
|
---|
123 | char *parsenextc; /**< next character in input buffer */
|
---|
124 | int init_editline; /**< 0 == not setup, 1 == OK, -1 == failed */
|
---|
125 |
|
---|
126 | /* exec.h */
|
---|
127 | const char *pathopt; /**< set by padvance */
|
---|
128 |
|
---|
129 | /* eval.h */
|
---|
130 | char *commandname; /**< currently executing command */
|
---|
131 | int exitstatus; /**< exit status of last command */
|
---|
132 | int back_exitstatus;/**< exit status of backquoted command */
|
---|
133 | struct strlist *cmdenviron; /**< environment for builtin command */
|
---|
134 | int funcnest;
|
---|
135 | int evalskip;
|
---|
136 |
|
---|
137 | /* builtins.h */
|
---|
138 |
|
---|
139 | } shinstance;
|
---|
140 |
|
---|
141 |
|
---|
142 | extern shinstance *create_root_shell(shinstance *inherit, int argc, char **argv);
|
---|
143 |
|
---|