Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | bab9d03 | 1992-04-05 14:26:55 +0000 | [diff] [blame] | 2 | Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 3 | Netherlands. |
| 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 25 | /* Python interpreter main program */ |
| 26 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 27 | #include "allobjects.h" |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 28 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 29 | #include "grammar.h" |
| 30 | #include "node.h" |
| 31 | #include "parsetok.h" |
| 32 | #include "graminit.h" |
| 33 | #include "errcode.h" |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 34 | #include "sysmodule.h" |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 35 | #include "compile.h" |
| 36 | #include "ceval.h" |
| 37 | #include "pythonrun.h" |
| 38 | #include "import.h" |
| 39 | |
| 40 | extern char *getpythonpath(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 41 | |
| 42 | extern grammar gram; /* From graminit.c */ |
| 43 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 44 | int debugging; /* Needed by parser.c */ |
Guido van Rossum | e3d7045 | 1992-03-27 17:21:30 +0000 | [diff] [blame] | 45 | int verbose; /* Needed by import.c */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 46 | |
Guido van Rossum | 689e701 | 1991-06-07 13:59:53 +0000 | [diff] [blame] | 47 | /* Interface to getopt(): */ |
| 48 | extern int optind; |
| 49 | extern char *optarg; |
| 50 | extern int getopt PROTO((int, char **, char *)); |
| 51 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 52 | main(argc, argv) |
| 53 | int argc; |
| 54 | char **argv; |
| 55 | { |
Guido van Rossum | 689e701 | 1991-06-07 13:59:53 +0000 | [diff] [blame] | 56 | int c; |
| 57 | int sts; |
| 58 | char *command = NULL; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 59 | char *filename = NULL; |
| 60 | FILE *fp = stdin; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 61 | |
Guido van Rossum | 689e701 | 1991-06-07 13:59:53 +0000 | [diff] [blame] | 62 | initargs(&argc, &argv); /* Defined in config*.c */ |
| 63 | |
Guido van Rossum | e3d7045 | 1992-03-27 17:21:30 +0000 | [diff] [blame] | 64 | while ((c = getopt(argc, argv, "c:dv")) != EOF) { |
Guido van Rossum | 46b1638 | 1992-01-02 16:16:18 +0000 | [diff] [blame] | 65 | if (c == 'c') { |
| 66 | /* -c is the last option; following arguments |
| 67 | that look like options are left for the |
| 68 | the command to interpret. */ |
| 69 | command = malloc(strlen(optarg) + 2); |
| 70 | /* Ignore malloc errors this early... */ |
| 71 | strcpy(command, optarg); |
| 72 | strcat(command, "\n"); |
| 73 | break; |
| 74 | } |
| 75 | |
Guido van Rossum | 689e701 | 1991-06-07 13:59:53 +0000 | [diff] [blame] | 76 | switch (c) { |
| 77 | |
Guido van Rossum | 8401e56 | 1992-01-19 16:48:36 +0000 | [diff] [blame] | 78 | case 'd': |
| 79 | debugging++; |
| 80 | break; |
| 81 | |
Guido van Rossum | e3d7045 | 1992-03-27 17:21:30 +0000 | [diff] [blame] | 82 | case 'v': |
| 83 | verbose++; |
| 84 | break; |
| 85 | |
Guido van Rossum | 46b1638 | 1992-01-02 16:16:18 +0000 | [diff] [blame] | 86 | /* This space reserved for other options */ |
| 87 | |
Guido van Rossum | 689e701 | 1991-06-07 13:59:53 +0000 | [diff] [blame] | 88 | default: |
| 89 | fprintf(stderr, |
| 90 | "usage: %s [-c cmd | file | -] [arg] ...\n", |
| 91 | argv[0]); |
| 92 | exit(2); |
| 93 | /*NOTREACHED*/ |
| 94 | |
Guido van Rossum | 689e701 | 1991-06-07 13:59:53 +0000 | [diff] [blame] | 95 | } |
| 96 | } |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 97 | |
Guido van Rossum | 689e701 | 1991-06-07 13:59:53 +0000 | [diff] [blame] | 98 | if (command == NULL && optind < argc && strcmp(argv[optind], "-") != 0) |
| 99 | filename = argv[optind]; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 100 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 101 | if (filename != NULL) { |
| 102 | if ((fp = fopen(filename, "r")) == NULL) { |
Guido van Rossum | 689e701 | 1991-06-07 13:59:53 +0000 | [diff] [blame] | 103 | fprintf(stderr, "%s: can't open file '%s'\n", |
| 104 | argv[0], filename); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 105 | exit(2); |
| 106 | } |
| 107 | } |
| 108 | |
Guido van Rossum | 138e6bf | 1992-06-03 17:08:15 +0000 | [diff] [blame] | 109 | initall(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 110 | |
Guido van Rossum | da0c6bd | 1990-11-18 17:28:24 +0000 | [diff] [blame] | 111 | setpythonpath(getpythonpath()); |
Guido van Rossum | 689e701 | 1991-06-07 13:59:53 +0000 | [diff] [blame] | 112 | if (command != NULL) { |
| 113 | /* Backup optind and force sys.argv[0] = '-c' */ |
| 114 | optind--; |
| 115 | argv[optind] = "-c"; |
| 116 | } |
| 117 | setpythonargv(argc-optind, argv+optind); |
| 118 | |
| 119 | if (command) { |
| 120 | sts = run_command(command) != 0; |
| 121 | } |
| 122 | else { |
| 123 | sts = run(fp, filename == NULL ? "<stdin>" : filename) != 0; |
| 124 | } |
| 125 | |
| 126 | goaway(sts); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 127 | /*NOTREACHED*/ |
| 128 | } |
| 129 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 130 | /* Initialize all */ |
| 131 | |
| 132 | void |
| 133 | initall() |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 134 | { |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 135 | static int inited; |
| 136 | |
| 137 | if (inited) |
| 138 | return; |
Guido van Rossum | 6c4f4a9 | 1990-12-20 23:11:33 +0000 | [diff] [blame] | 139 | inited = 1; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 140 | |
| 141 | initimport(); |
| 142 | |
Guido van Rossum | 6c4f4a9 | 1990-12-20 23:11:33 +0000 | [diff] [blame] | 143 | /* Modules 'builtin' and 'sys' are initialized here, |
| 144 | they are needed by random bits of the interpreter. |
| 145 | All other modules are optional and should be initialized |
| 146 | by the initcalls() of a specific configuration. */ |
| 147 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 148 | initbuiltin(); /* Also initializes builtin exceptions */ |
| 149 | initsys(); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 150 | |
| 151 | initcalls(); /* Configuration-dependent initializations */ |
| 152 | |
| 153 | initintr(); /* For intrcheck() */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | /* Parse input from a file and execute it */ |
| 157 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 158 | int |
| 159 | run(fp, filename) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 160 | FILE *fp; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 161 | char *filename; |
| 162 | { |
| 163 | if (filename == NULL) |
| 164 | filename = "???"; |
Guido van Rossum | e3d7045 | 1992-03-27 17:21:30 +0000 | [diff] [blame] | 165 | if (isatty((int)fileno(fp))) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 166 | return run_tty_loop(fp, filename); |
| 167 | else |
| 168 | return run_script(fp, filename); |
| 169 | } |
| 170 | |
| 171 | int |
| 172 | run_tty_loop(fp, filename) |
| 173 | FILE *fp; |
| 174 | char *filename; |
| 175 | { |
| 176 | object *v; |
| 177 | int ret; |
| 178 | v = sysget("ps1"); |
| 179 | if (v == NULL) { |
| 180 | sysset("ps1", v = newstringobject(">>> ")); |
| 181 | XDECREF(v); |
| 182 | } |
| 183 | v = sysget("ps2"); |
| 184 | if (v == NULL) { |
| 185 | sysset("ps2", v = newstringobject("... ")); |
| 186 | XDECREF(v); |
| 187 | } |
| 188 | for (;;) { |
| 189 | ret = run_tty_1(fp, filename); |
| 190 | #ifdef REF_DEBUG |
| 191 | fprintf(stderr, "[%ld refs]\n", ref_total); |
| 192 | #endif |
| 193 | if (ret == E_EOF) |
| 194 | return 0; |
| 195 | /* |
| 196 | if (ret == E_NOMEM) |
| 197 | return -1; |
| 198 | */ |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | int |
| 203 | run_tty_1(fp, filename) |
| 204 | FILE *fp; |
| 205 | char *filename; |
| 206 | { |
| 207 | object *m, *d, *v, *w; |
| 208 | node *n; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 209 | char *ps1, *ps2; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 210 | int err; |
| 211 | v = sysget("ps1"); |
| 212 | w = sysget("ps2"); |
| 213 | if (v != NULL && is_stringobject(v)) { |
| 214 | INCREF(v); |
| 215 | ps1 = getstringvalue(v); |
| 216 | } |
| 217 | else { |
| 218 | v = NULL; |
| 219 | ps1 = ""; |
| 220 | } |
| 221 | if (w != NULL && is_stringobject(w)) { |
| 222 | INCREF(w); |
| 223 | ps2 = getstringvalue(w); |
| 224 | } |
| 225 | else { |
| 226 | w = NULL; |
| 227 | ps2 = ""; |
| 228 | } |
| 229 | err = parsefile(fp, filename, &gram, single_input, ps1, ps2, &n); |
| 230 | XDECREF(v); |
| 231 | XDECREF(w); |
| 232 | if (err == E_EOF) |
| 233 | return E_EOF; |
| 234 | if (err != E_DONE) { |
| 235 | err_input(err); |
| 236 | print_error(); |
| 237 | return err; |
| 238 | } |
| 239 | m = add_module("__main__"); |
| 240 | if (m == NULL) |
| 241 | return -1; |
| 242 | d = getmoduledict(m); |
| 243 | v = run_node(n, filename, d, d); |
| 244 | flushline(); |
| 245 | if (v == NULL) { |
| 246 | print_error(); |
| 247 | return -1; |
| 248 | } |
| 249 | DECREF(v); |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | int |
| 254 | run_script(fp, filename) |
| 255 | FILE *fp; |
| 256 | char *filename; |
| 257 | { |
| 258 | object *m, *d, *v; |
| 259 | m = add_module("__main__"); |
| 260 | if (m == NULL) |
| 261 | return -1; |
| 262 | d = getmoduledict(m); |
| 263 | v = run_file(fp, filename, file_input, d, d); |
| 264 | flushline(); |
| 265 | if (v == NULL) { |
| 266 | print_error(); |
| 267 | return -1; |
| 268 | } |
| 269 | DECREF(v); |
| 270 | return 0; |
| 271 | } |
| 272 | |
Guido van Rossum | 689e701 | 1991-06-07 13:59:53 +0000 | [diff] [blame] | 273 | int |
| 274 | run_command(command) |
| 275 | char *command; |
| 276 | { |
| 277 | object *m, *d, *v; |
| 278 | m = add_module("__main__"); |
| 279 | if (m == NULL) |
| 280 | return -1; |
| 281 | d = getmoduledict(m); |
| 282 | v = run_string(command, file_input, d, d); |
| 283 | flushline(); |
| 284 | if (v == NULL) { |
| 285 | print_error(); |
| 286 | return -1; |
| 287 | } |
| 288 | DECREF(v); |
| 289 | return 0; |
| 290 | } |
| 291 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 292 | void |
| 293 | print_error() |
| 294 | { |
| 295 | object *exception, *v; |
| 296 | err_get(&exception, &v); |
Guido van Rossum | a534ed3 | 1991-12-31 13:14:48 +0000 | [diff] [blame] | 297 | if (exception == SystemExit) { |
| 298 | if (v == NULL || v == None) |
| 299 | goaway(0); |
| 300 | if (is_intobject(v)) |
| 301 | goaway((int)getintvalue(v)); |
| 302 | else { |
| 303 | printobject(v, stderr, PRINT_RAW); |
| 304 | fprintf(stderr, "\n"); |
| 305 | goaway(1); |
| 306 | } |
| 307 | } |
Guido van Rossum | c4adc83 | 1992-03-04 16:39:39 +0000 | [diff] [blame] | 308 | sysset("last_type", exception); |
| 309 | sysset("last_value", v); |
Guido van Rossum | d783a46 | 1991-06-07 22:35:42 +0000 | [diff] [blame] | 310 | if (printobject(exception, stderr, PRINT_RAW) != 0) |
| 311 | err_clear(); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 312 | if (v != NULL && v != None) { |
| 313 | fprintf(stderr, ": "); |
Guido van Rossum | d783a46 | 1991-06-07 22:35:42 +0000 | [diff] [blame] | 314 | if (printobject(v, stderr, PRINT_RAW) != 0) |
| 315 | err_clear(); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 316 | } |
| 317 | fprintf(stderr, "\n"); |
| 318 | XDECREF(exception); |
| 319 | XDECREF(v); |
| 320 | printtraceback(stderr); |
| 321 | } |
| 322 | |
| 323 | object * |
| 324 | run_string(str, start, globals, locals) |
| 325 | char *str; |
| 326 | int start; |
| 327 | /*dict*/object *globals, *locals; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 328 | { |
| 329 | node *n; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 330 | int err; |
| 331 | err = parse_string(str, start, &n); |
| 332 | return run_err_node(err, n, "<string>", globals, locals); |
| 333 | } |
| 334 | |
| 335 | object * |
| 336 | run_file(fp, filename, start, globals, locals) |
| 337 | FILE *fp; |
| 338 | char *filename; |
| 339 | int start; |
| 340 | /*dict*/object *globals, *locals; |
| 341 | { |
| 342 | node *n; |
| 343 | int err; |
| 344 | err = parse_file(fp, filename, start, &n); |
| 345 | return run_err_node(err, n, filename, globals, locals); |
| 346 | } |
| 347 | |
| 348 | object * |
| 349 | run_err_node(err, n, filename, globals, locals) |
| 350 | int err; |
| 351 | node *n; |
| 352 | char *filename; |
| 353 | /*dict*/object *globals, *locals; |
| 354 | { |
| 355 | if (err != E_DONE) { |
| 356 | err_input(err); |
| 357 | return NULL; |
| 358 | } |
| 359 | return run_node(n, filename, globals, locals); |
| 360 | } |
| 361 | |
| 362 | object * |
| 363 | run_node(n, filename, globals, locals) |
| 364 | node *n; |
| 365 | char *filename; |
| 366 | /*dict*/object *globals, *locals; |
| 367 | { |
| 368 | if (globals == NULL) { |
| 369 | globals = getglobals(); |
| 370 | if (locals == NULL) |
| 371 | locals = getlocals(); |
| 372 | } |
| 373 | else { |
| 374 | if (locals == NULL) |
| 375 | locals = globals; |
| 376 | } |
| 377 | return eval_node(n, filename, globals, locals); |
| 378 | } |
| 379 | |
| 380 | object * |
| 381 | eval_node(n, filename, globals, locals) |
| 382 | node *n; |
| 383 | char *filename; |
| 384 | object *globals; |
| 385 | object *locals; |
| 386 | { |
| 387 | codeobject *co; |
| 388 | object *v; |
| 389 | co = compile(n, filename); |
| 390 | freetree(n); |
| 391 | if (co == NULL) |
| 392 | return NULL; |
| 393 | v = eval_code(co, globals, locals, (object *)NULL); |
| 394 | DECREF(co); |
| 395 | return v; |
| 396 | } |
| 397 | |
| 398 | /* Simplified interface to parsefile */ |
| 399 | |
| 400 | int |
| 401 | parse_file(fp, filename, start, n_ret) |
| 402 | FILE *fp; |
| 403 | char *filename; |
| 404 | int start; |
| 405 | node **n_ret; |
| 406 | { |
| 407 | return parsefile(fp, filename, &gram, start, |
| 408 | (char *)0, (char *)0, n_ret); |
| 409 | } |
| 410 | |
| 411 | /* Simplified interface to parsestring */ |
| 412 | |
| 413 | int |
| 414 | parse_string(str, start, n_ret) |
| 415 | char *str; |
| 416 | int start; |
| 417 | node **n_ret; |
| 418 | { |
| 419 | int err = parsestring(str, &gram, start, n_ret); |
| 420 | /* Don't confuse early end of string with early end of input */ |
| 421 | if (err == E_EOF) |
| 422 | err = E_SYNTAX; |
| 423 | return err; |
| 424 | } |
| 425 | |
| 426 | /* Print fatal error message and abort */ |
| 427 | |
| 428 | void |
| 429 | fatal(msg) |
| 430 | char *msg; |
| 431 | { |
| 432 | fprintf(stderr, "Fatal error: %s\n", msg); |
| 433 | abort(); |
| 434 | } |
| 435 | |
| 436 | /* Clean up and exit */ |
| 437 | |
| 438 | void |
| 439 | goaway(sts) |
| 440 | int sts; |
| 441 | { |
| 442 | flushline(); |
| 443 | |
| 444 | /* XXX Call doneimport() before donecalls(), since donecalls() |
| 445 | calls wdone(), and doneimport() may close windows */ |
| 446 | doneimport(); |
| 447 | donecalls(); |
| 448 | |
| 449 | err_clear(); |
| 450 | |
| 451 | #ifdef REF_DEBUG |
| 452 | fprintf(stderr, "[%ld refs]\n", ref_total); |
| 453 | #endif |
| 454 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 455 | #ifdef TRACE_REFS |
| 456 | if (askyesno("Print left references?")) { |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 457 | printrefs(stderr); |
| 458 | } |
| 459 | #endif /* TRACE_REFS */ |
| 460 | |
| 461 | exit(sts); |
| 462 | /*NOTREACHED*/ |
| 463 | } |
| 464 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 465 | #ifdef TRACE_REFS |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 466 | /* Ask a yes/no question */ |
| 467 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 468 | static int |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 469 | askyesno(prompt) |
| 470 | char *prompt; |
| 471 | { |
| 472 | char buf[256]; |
| 473 | |
| 474 | printf("%s [ny] ", prompt); |
| 475 | if (fgets(buf, sizeof buf, stdin) == NULL) |
| 476 | return 0; |
| 477 | return buf[0] == 'y' || buf[0] == 'Y'; |
| 478 | } |
Guido van Rossum | e3d7045 | 1992-03-27 17:21:30 +0000 | [diff] [blame] | 479 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 480 | |
Guido van Rossum | 2cfd356 | 1991-06-04 19:38:58 +0000 | [diff] [blame] | 481 | #ifdef applec /* MPW (also usable for Think C 3.0) */ |
Guido van Rossum | da0c6bd | 1990-11-18 17:28:24 +0000 | [diff] [blame] | 482 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 483 | /* Check for file descriptor connected to interactive device. |
| 484 | Pretend that stdin is always interactive, other files never. */ |
| 485 | |
| 486 | int |
| 487 | isatty(fd) |
| 488 | int fd; |
| 489 | { |
| 490 | return fd == fileno(stdin); |
| 491 | } |
| 492 | |
Guido van Rossum | e6c67a7 | 1991-04-04 10:47:59 +0000 | [diff] [blame] | 493 | #endif |