comparison Python/pythonmain.c @ 70:a36c348a8e1a legacy-trunk

Moved configuration-dependent initializations (etc.) to config_*.c
author Guido van Rossum <guido@python.org>
date Sun, 18 Nov 1990 17:28:24 +0000
parents 0808e5ab743a
children de34f4a4d353
comparison
equal deleted inserted replaced
69:cccd534f2280 70:a36c348a8e1a
1 /* Python interpreter main program */ 1 /* Python interpreter main program */
2
3 /* XXX This is still a mess */
4
5 #ifdef THINK_C
6 #define USE_STDWIN
7 #endif
8 2
9 #include <stdio.h> 3 #include <stdio.h>
10 #include <ctype.h> 4 #include <ctype.h>
11 #include "string.h" 5 #include "string.h"
12 6
13 #ifdef USE_STDWIN 7 extern char *getpythonpath();
14 #include "stdwin.h"
15 int use_stdwin;
16 #endif
17
18 #ifdef USE_AUDIO
19 #include "asa.h"
20 #endif
21
22 extern char *getenv();
23 8
24 #include "PROTO.h" 9 #include "PROTO.h"
25 #include "grammar.h" 10 #include "grammar.h"
26 #include "node.h" 11 #include "node.h"
27 #include "parsetok.h" 12 #include "parsetok.h"
31 #include "stringobject.h" 16 #include "stringobject.h"
32 #include "sysmodule.h" 17 #include "sysmodule.h"
33 18
34 extern grammar gram; /* From graminit.c */ 19 extern grammar gram; /* From graminit.c */
35 20
36 #ifndef PYTHONPATH
37
38 #ifdef THINK_C
39
40 #define PYTHONPATH ": :mod"
41
42 #else /* !THINK_C */
43
44 #ifdef AMOEBA
45 #define PYTHONPATH ".:/profile/module/python"
46 #else /* !AMOEBA */
47 #define PYTHONPATH ".:/usr/local/lib/python"
48 #endif /* !AMOEBA */
49
50 #endif /* !THINK_C */
51
52 #endif /* !PYTHONPATH */
53
54 int debugging; 21 int debugging;
55 22
56 main(argc, argv) 23 main(argc, argv)
57 int argc; 24 int argc;
58 char **argv; 25 char **argv;
59 { 26 {
60 char *path;
61 char *filename = NULL; 27 char *filename = NULL;
62 FILE *fp = stdin; 28 FILE *fp = stdin;
63 int ret; 29 int ret;
64 30
65 #ifdef USE_STDWIN 31 initargs(&argc, &argv);
66 #ifdef THINK_C
67 wsetstdio(1);
68 #else THINK_C
69 /* Must use "python -s" now to get stdwin support */
70 if (argc > 1 && strcmp(argv[1], "-s") == 0)
71 argv[1] = argv[0],
72 argc--, argv++,
73 #endif /* !THINK_C */
74 use_stdwin = 1;
75 if (use_stdwin)
76 winitargs(&argc, &argv);
77 #endif /* USE_STDWIN */
78
79 #ifdef THINK_C_not_today
80 printf("argc = %d, argv[0] = '%s'\n", argc, argv[0]);
81 if (argc <= 1)
82 askargs(&argc, &argv);
83 #endif
84 32
85 initintr(); /* For intrcheck() */ 33 initintr(); /* For intrcheck() */
86 34
87 if (argc > 1 && strcmp(argv[1], "-") != 0) 35 if (argc > 1 && strcmp(argv[1], "-") != 0)
88 filename = argv[1]; 36 filename = argv[1];
99 47
100 initsys(argc-1, argv+1); 48 initsys(argc-1, argv+1);
101 inittime(); 49 inittime();
102 initmath(); 50 initmath();
103 51
104 #ifndef THINK_C 52 setpythonpath(getpythonpath());
105 path = getenv("PYTHONPATH");
106 if (path == NULL)
107 #endif
108 path = PYTHONPATH;
109 setpythonpath(path);
110 53
111 initrun(); 54 initrun();
112 55 initcalls();
113 #ifdef USE_POSIX
114 initposix();
115 #endif
116
117 #ifdef THINK_C
118 initmac();
119 #endif
120
121 #ifdef USE_AUDIO
122 initaudio();
123 #endif
124
125 #ifdef USE_AMOEBA
126 initamoeba();
127 #endif
128
129 #ifdef USE_STDWIN
130 if (use_stdwin)
131 initstdwin();
132 #endif
133
134 #ifdef USE_GL
135 initgl();
136 #endif
137
138 #ifdef USE_PANEL
139 initpanel();
140 #endif
141 56
142 if (!isatty(fileno(fp))) { 57 if (!isatty(fileno(fp))) {
143 ret = runfile(fp, file_input, (char *)NULL, (char *)NULL); 58 ret = runfile(fp, file_input, (char *)NULL, (char *)NULL);
144 } 59 }
145 else { 60 else {
174 } 89 }
175 90
176 goaway(sts) 91 goaway(sts)
177 int sts; 92 int sts;
178 { 93 {
179 closerun();
180 #ifdef USE_STDWIN
181 if (use_stdwin)
182 wdone();
183 #endif
184 #ifdef USE_AUDIO
185 asa_done();
186 #endif
187 #ifdef THINK_C 94 #ifdef THINK_C
188 #ifndef TRACE_REFS
189 /* Avoid 'click mouse to continue' in Lightspeed C */
190 if (sts == 0) 95 if (sts == 0)
191 Click_On(0); 96 Click_On(0);
192 #endif 97 #endif
193 #endif 98 closerun();
99 donecalls();
194 exit(sts); 100 exit(sts);
195 /*NOTREACHED*/ 101 /*NOTREACHED*/
196 } 102 }
197 103
198 /* Parse input from a file and execute it */ 104 /* Parse input from a file and execute it */
209 if (ret != E_DONE) 115 if (ret != E_DONE)
210 return ret; 116 return ret;
211 return execute(n) == 0 ? E_DONE : E_ERROR; 117 return execute(n) == 0 ? E_DONE : E_ERROR;
212 } 118 }
213 119
214 #ifdef THINK_C
215
216 /* Ask a yes/no question */ 120 /* Ask a yes/no question */
217 121
218 int 122 int
219 askyesno(prompt) 123 askyesno(prompt)
220 char *prompt; 124 char *prompt;
225 if (fgets(buf, sizeof buf, stdin) == NULL) 129 if (fgets(buf, sizeof buf, stdin) == NULL)
226 return 0; 130 return 0;
227 return buf[0] == 'y' || buf[0] == 'Y'; 131 return buf[0] == 'y' || buf[0] == 'Y';
228 } 132 }
229 133
134 #ifdef THINK_C
135
230 /* Check for file descriptor connected to interactive device. 136 /* Check for file descriptor connected to interactive device.
231 Pretend that stdin is always interactive, other files never. */ 137 Pretend that stdin is always interactive, other files never. */
232 138
233 int 139 int
234 isatty(fd) 140 isatty(fd)
235 int fd; 141 int fd;
236 { 142 {
237 return fd == fileno(stdin); 143 return fd == fileno(stdin);
238 }
239
240 /* Kludge to get arguments on the Mac */
241
242 #define MAXARGS 20
243
244 static char *
245 nextarg(pnext)
246 char **pnext;
247 {
248 char *ret;
249 char *p = *pnext;
250 while (isspace(*p))
251 p++;
252 if (*p == '\0')
253 return NULL;
254 ret = p;
255 while (!isspace(*p))
256 p++;
257 if (*p != '\0')
258 *p++ = '\0';
259 *pnext = p;
260 return ret;
261 }
262
263 static
264 askargs(pargc, pargv)
265 int *pargc;
266 char ***pargv; /* sic */
267 {
268 static char buf[256];
269 static char *argv[MAXARGS];
270 int argc;
271 char *p, *next;
272 fprintf(stderr, "Args: ");
273 if (fgets(buf, sizeof buf, stdin) == NULL)
274 return;
275 next = buf;
276 if ((p = nextarg(&next)) == NULL)
277 return;
278 if (*pargc > 0)
279 argv[0] = (*pargv)[0];
280 else
281 argv[0] = "PYTHON";
282 argc = 1;
283 argv[argc++] = p;
284 while (argc+1 < MAXARGS && (p = nextarg(&next)) != NULL)
285 argv[argc++] = p;
286 argv[argc] = NULL;
287 *pargc = argc;
288 *pargv = argv;
289 } 144 }
290 145
291 #endif 146 #endif
292 147
293 /* WISH LIST 148 /* WISH LIST