1 /*
2  * $Id: shell.h,v 1.4 2002/07/06 08:51:42 isizaka Exp isizaka $
3  *
4  * This file is part of "Ngraph for X11".
5  *
6  * Copyright (C) 2002, Satoshi ISHIZAKA. isizaka@msa.biglobe.ne.jp
7  *
8  * "Ngraph for X11" is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * "Ngraph for X11" is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  */
23 
24 /**
25  *
26  * $Log: shell.h,v $
27  * Revision 1.4  2002/07/06 08:51:42  isizaka
28  * change to GPL.
29  *
30  * Revision 1.3  2002/06/29 03:20:42  isizaka
31  * add kbhit
32  *
33  * Revision 1.2  1999/04/15 12:15:27  isizaka
34  * for release 6.03.01
35  *
36  * Revision 1.1  1999/03/17 13:46:09  isizaka
37  * Initial revision
38  *
39  *
40  **/
41 
42 extern char **mainenviron;
43 extern int security;
44 
45 #define SHELLBUFSIZE 4096
46 
47 #define ERRUEXPEOF 100
48 #define ERRBADSUB  101
49 #define ERRSYNTAX  102
50 #define ERRUEXPTOK 103
51 #define ERRIDENT   104
52 #define ERRCFOUND  105
53 #define ERRSYSTEM  106
54 #define ERREXTARG  107
55 #define ERRSMLARG  108
56 #define ERRMANYARG 109
57 #define ERRNOFILE  110
58 #define ERREOF     111
59 #define ERRNOFIL   112
60 #define ERRREAD    113
61 #define ERROPEN    114
62 #define ERROBJARG  115
63 #define ERRINSTARG 116
64 #define ERRNEWINST 117
65 #define ERRCMFIELD 118
66 #define ERRVALUE   119
67 #define ERRTWOINST 120
68 #define ERRNONEINST 121
69 #define ERRNOFIELD 122
70 #define ERRNUMERIC 123
71 #define ERROPTION  124
72 #define ERRILOPS   125
73 #define ERRUNSET   126
74 #define ERRNODIR   127
75 #define ERRMSYNTAX 128
76 #define ERRMILLEGAL 129
77 #define ERRMNEST   130
78 #define ERRMARG    131
79 #define ERRMFAT    132
80 #define ERRTESTNEST 133
81 #define ERRTESTSYNTAX 134
82 #define ERRSECURITY 135
83 
84 struct prmlist;
85 struct prmlist {
86   struct prmlist *next;
87   char *str;
88   int prmno;
89   int quoted;
90 };
91 
92 struct cmdlist;
93 struct cmdlist {
94   struct cmdlist *next;
95   int cmdno;
96   int cmdend;
97   struct prmlist *prm;
98   void *done;
99   char *pipefile;
100 };
101 
102 struct vallist;
103 struct vallist {
104   struct vallist *next;
105   char *name;
106   void *val;
107   int func;
108   int arg;
109 };
110 
111 struct explist;
112 struct explist {
113   char *val;
114   struct explist *next;
115 };
116 
117 struct nshell {
118   struct objlist *obj;
119   struct vallist *valroot;
120   struct explist *exproot;
121   int argc;
122   char **argv;
123   int cmdexec;
124   int status;
125   int quit;
126   int options;
127   int optionf;
128   int optione;
129   int optionv;
130   int optionx;
131   HANDLE fd;
132   char *readbuf;
133   int readpo;
134   int readbyte;
135   int (*sgetstdin)();
136   int (*sputstdout)(char *s);
137   int (*sprintfstdout)(char *fmt,...);
138 };
139 
140 #define CMDNUM 34
141 
142 struct cmdtabletype {
143   char *name;
144   int (*proc)(struct nshell *nshell,int argc,char **argv);
145 };
146 extern struct cmdtabletype cmdtable[CMDNUM];
147 
148 #define CPCMDNUM 15
149 extern char *cpcmdtable[CPCMDNUM];
150 
151 char *gettok(char **s,int *len,int *quote,int *bquote,int *cend,int *escape);
152 char *unquotation(char *s,int *quoted);
153 char *addval(struct nshell *nshell,char *name,char *val);
154 char *addexp(struct nshell *nshell,char *name);
155 int delval(struct nshell *nshell,char *name);
156 char *getval(struct nshell *nshell,char *name);
157 int getexp(struct nshell *nshell,char *name);
158 struct cmdlist *getfunc(struct nshell *nshell,char *name);
159 void cmdfree(struct cmdlist *cmdroot);
160 void setshhandle(struct nshell *shell,HANDLE fd);
161 HANDLE storeshhandle(struct nshell *nshell,HANDLE fd,
162                      char **readbuf,int *readbyte,int *readpo);
163 void restoreshhandle(struct nshell *nshell,HANDLE fd,
164                      char *readbuf,int readbyte,int readpo);
165 HANDLE getshhandle(struct nshell *shell);
166 int cmdexecute(struct nshell *nshell,char *cline);
167 struct nshell *newshell(void);
168 void delshell(struct nshell *nshell);
169 void sherror(int code);
170 void sherror2(int code,char *mes);
171 void sherror3(char *cmd,int code,char *mes);
172 void sherror4(char *cmd,int code);
173 void shellsavestdio(struct nshell *nshell);
174 void shellrestorestdio(struct nshell *nshell);
175 int setshelloption(struct nshell *nshell,char *opt);
176 int getshelloption(struct nshell *nshell,char opt);
177 void setshellargument(struct nshell *nshell,int argc,char **argv);
178 int printfconsole(char *fmt,...);
179 void ngraphenvironment(struct nshell *nshell);
180