Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 13658:f79434ee41fa legacy-trunk
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
declarations yet, those come later.
| author | Thomas Wouters <thomas@python.org> |
|---|---|
| date | Sat, 22 Jul 2000 18:47:25 +0000 |
| parents | 5b727ab37092 |
| children | 97f5388a6dce |
comparison
equal
deleted
inserted
replaced
| 13657:6a5314a6c2c2 | 13658:f79434ee41fa |
|---|---|
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 #ifdef macintosh | 37 #ifdef macintosh |
| 38 #include "macglue.h" | 38 #include "macglue.h" |
| 39 #endif | 39 #endif |
| 40 extern char *Py_GetPath(); | 40 extern char *Py_GetPath(void); |
| 41 | 41 |
| 42 extern grammar _PyParser_Grammar; /* From graminit.c */ | 42 extern grammar _PyParser_Grammar; /* From graminit.c */ |
| 43 | 43 |
| 44 /* Forward */ | 44 /* Forward */ |
| 45 static void initmain(void); | 45 static void initmain(void); |
| 57 | 57 |
| 58 #ifdef Py_TRACE_REFS | 58 #ifdef Py_TRACE_REFS |
| 59 int _Py_AskYesNo(char *prompt); | 59 int _Py_AskYesNo(char *prompt); |
| 60 #endif | 60 #endif |
| 61 | 61 |
| 62 extern void _PyUnicode_Init(); | 62 extern void _PyUnicode_Init(void); |
| 63 extern void _PyUnicode_Fini(); | 63 extern void _PyUnicode_Fini(void); |
| 64 extern void _PyCodecRegistry_Init(); | 64 extern void _PyCodecRegistry_Init(void); |
| 65 extern void _PyCodecRegistry_Fini(); | 65 extern void _PyCodecRegistry_Fini(void); |
| 66 | 66 |
| 67 | 67 |
| 68 int Py_DebugFlag; /* Needed by parser.c */ | 68 int Py_DebugFlag; /* Needed by parser.c */ |
| 69 int Py_VerboseFlag; /* Needed by import.c */ | 69 int Py_VerboseFlag; /* Needed by import.c */ |
| 70 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */ | 70 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */ |
| 76 static int initialized = 0; | 76 static int initialized = 0; |
| 77 | 77 |
| 78 /* API to access the initialized flag -- useful for esoteric use */ | 78 /* API to access the initialized flag -- useful for esoteric use */ |
| 79 | 79 |
| 80 int | 80 int |
| 81 Py_IsInitialized() | 81 Py_IsInitialized(void) |
| 82 { | 82 { |
| 83 return initialized; | 83 return initialized; |
| 84 } | 84 } |
| 85 | 85 |
| 86 /* Global initializations. Can be undone by Py_Finalize(). Don't | 86 /* Global initializations. Can be undone by Py_Finalize(). Don't |
| 94 having the lock, but you cannot use multiple threads.) | 94 having the lock, but you cannot use multiple threads.) |
| 95 | 95 |
| 96 */ | 96 */ |
| 97 | 97 |
| 98 void | 98 void |
| 99 Py_Initialize() | 99 Py_Initialize(void) |
| 100 { | 100 { |
| 101 PyInterpreterState *interp; | 101 PyInterpreterState *interp; |
| 102 PyThreadState *tstate; | 102 PyThreadState *tstate; |
| 103 PyObject *bimod, *sysmod; | 103 PyObject *bimod, *sysmod; |
| 104 char *p; | 104 char *p; |
| 183 Locking: as above. | 183 Locking: as above. |
| 184 | 184 |
| 185 */ | 185 */ |
| 186 | 186 |
| 187 void | 187 void |
| 188 Py_Finalize() | 188 Py_Finalize(void) |
| 189 { | 189 { |
| 190 PyInterpreterState *interp; | 190 PyInterpreterState *interp; |
| 191 PyThreadState *tstate; | 191 PyThreadState *tstate; |
| 192 | 192 |
| 193 if (!initialized) | 193 if (!initialized) |
| 281 Locking: as above. | 281 Locking: as above. |
| 282 | 282 |
| 283 */ | 283 */ |
| 284 | 284 |
| 285 PyThreadState * | 285 PyThreadState * |
| 286 Py_NewInterpreter() | 286 Py_NewInterpreter(void) |
| 287 { | 287 { |
| 288 PyInterpreterState *interp; | 288 PyInterpreterState *interp; |
| 289 PyThreadState *tstate, *save_tstate; | 289 PyThreadState *tstate, *save_tstate; |
| 290 PyObject *bimod, *sysmod; | 290 PyObject *bimod, *sysmod; |
| 291 | 291 |
| 350 Locking: as above. | 350 Locking: as above. |
| 351 | 351 |
| 352 */ | 352 */ |
| 353 | 353 |
| 354 void | 354 void |
| 355 Py_EndInterpreter(tstate) | 355 Py_EndInterpreter(PyThreadState *tstate) |
| 356 PyThreadState *tstate; | |
| 357 { | 356 { |
| 358 PyInterpreterState *interp = tstate->interp; | 357 PyInterpreterState *interp = tstate->interp; |
| 359 | 358 |
| 360 if (tstate != PyThreadState_Get()) | 359 if (tstate != PyThreadState_Get()) |
| 361 Py_FatalError("Py_EndInterpreter: thread is not current"); | 360 Py_FatalError("Py_EndInterpreter: thread is not current"); |
| 371 } | 370 } |
| 372 | 371 |
| 373 static char *progname = "python"; | 372 static char *progname = "python"; |
| 374 | 373 |
| 375 void | 374 void |
| 376 Py_SetProgramName(pn) | 375 Py_SetProgramName(char *pn) |
| 377 char *pn; | |
| 378 { | 376 { |
| 379 if (pn && *pn) | 377 if (pn && *pn) |
| 380 progname = pn; | 378 progname = pn; |
| 381 } | 379 } |
| 382 | 380 |
| 383 char * | 381 char * |
| 384 Py_GetProgramName() | 382 Py_GetProgramName(void) |
| 385 { | 383 { |
| 386 return progname; | 384 return progname; |
| 387 } | 385 } |
| 388 | 386 |
| 389 static char *default_home = NULL; | 387 static char *default_home = NULL; |
| 390 | 388 |
| 391 void | 389 void |
| 392 Py_SetPythonHome(home) | 390 Py_SetPythonHome(char *home) |
| 393 char *home; | |
| 394 { | 391 { |
| 395 default_home = home; | 392 default_home = home; |
| 396 } | 393 } |
| 397 | 394 |
| 398 char * | 395 char * |
| 399 Py_GetPythonHome() | 396 Py_GetPythonHome(void) |
| 400 { | 397 { |
| 401 char *home = default_home; | 398 char *home = default_home; |
| 402 if (home == NULL) | 399 if (home == NULL) |
| 403 home = getenv("PYTHONHOME"); | 400 home = getenv("PYTHONHOME"); |
| 404 return home; | 401 return home; |
| 405 } | 402 } |
| 406 | 403 |
| 407 /* Create __main__ module */ | 404 /* Create __main__ module */ |
| 408 | 405 |
| 409 static void | 406 static void |
| 410 initmain() | 407 initmain(void) |
| 411 { | 408 { |
| 412 PyObject *m, *d; | 409 PyObject *m, *d; |
| 413 m = PyImport_AddModule("__main__"); | 410 m = PyImport_AddModule("__main__"); |
| 414 if (m == NULL) | 411 if (m == NULL) |
| 415 Py_FatalError("can't create __main__ module"); | 412 Py_FatalError("can't create __main__ module"); |
| 424 } | 421 } |
| 425 | 422 |
| 426 /* Import the site module (not into __main__ though) */ | 423 /* Import the site module (not into __main__ though) */ |
| 427 | 424 |
| 428 static void | 425 static void |
| 429 initsite() | 426 initsite(void) |
| 430 { | 427 { |
| 431 PyObject *m, *f; | 428 PyObject *m, *f; |
| 432 m = PyImport_ImportModule("site"); | 429 m = PyImport_ImportModule("site"); |
| 433 if (m == NULL) { | 430 if (m == NULL) { |
| 434 f = PySys_GetObject("stderr"); | 431 f = PySys_GetObject("stderr"); |
| 449 } | 446 } |
| 450 | 447 |
| 451 /* Parse input from a file and execute it */ | 448 /* Parse input from a file and execute it */ |
| 452 | 449 |
| 453 int | 450 int |
| 454 PyRun_AnyFile(fp, filename) | 451 PyRun_AnyFile(FILE *fp, char *filename) |
| 455 FILE *fp; | |
| 456 char *filename; | |
| 457 { | 452 { |
| 458 if (filename == NULL) | 453 if (filename == NULL) |
| 459 filename = "???"; | 454 filename = "???"; |
| 460 if (Py_FdIsInteractive(fp, filename)) | 455 if (Py_FdIsInteractive(fp, filename)) |
| 461 return PyRun_InteractiveLoop(fp, filename); | 456 return PyRun_InteractiveLoop(fp, filename); |
| 462 else | 457 else |
| 463 return PyRun_SimpleFile(fp, filename); | 458 return PyRun_SimpleFile(fp, filename); |
| 464 } | 459 } |
| 465 | 460 |
| 466 int | 461 int |
| 467 PyRun_InteractiveLoop(fp, filename) | 462 PyRun_InteractiveLoop(FILE *fp, char *filename) |
| 468 FILE *fp; | |
| 469 char *filename; | |
| 470 { | 463 { |
| 471 PyObject *v; | 464 PyObject *v; |
| 472 int ret; | 465 int ret; |
| 473 v = PySys_GetObject("ps1"); | 466 v = PySys_GetObject("ps1"); |
| 474 if (v == NULL) { | 467 if (v == NULL) { |
| 493 */ | 486 */ |
| 494 } | 487 } |
| 495 } | 488 } |
| 496 | 489 |
| 497 int | 490 int |
| 498 PyRun_InteractiveOne(fp, filename) | 491 PyRun_InteractiveOne(FILE *fp, char *filename) |
| 499 FILE *fp; | |
| 500 char *filename; | |
| 501 { | 492 { |
| 502 PyObject *m, *d, *v, *w; | 493 PyObject *m, *d, *v, *w; |
| 503 node *n; | 494 node *n; |
| 504 perrdetail err; | 495 perrdetail err; |
| 505 char *ps1 = "", *ps2 = ""; | 496 char *ps1 = "", *ps2 = ""; |
| 547 PyErr_Clear(); | 538 PyErr_Clear(); |
| 548 return 0; | 539 return 0; |
| 549 } | 540 } |
| 550 | 541 |
| 551 int | 542 int |
| 552 PyRun_SimpleFile(fp, filename) | 543 PyRun_SimpleFile(FILE *fp, char *filename) |
| 553 FILE *fp; | |
| 554 char *filename; | |
| 555 { | 544 { |
| 556 PyObject *m, *d, *v; | 545 PyObject *m, *d, *v; |
| 557 char *ext; | 546 char *ext; |
| 558 | 547 |
| 559 m = PyImport_AddModule("__main__"); | 548 m = PyImport_AddModule("__main__"); |
| 590 PyErr_Clear(); | 579 PyErr_Clear(); |
| 591 return 0; | 580 return 0; |
| 592 } | 581 } |
| 593 | 582 |
| 594 int | 583 int |
| 595 PyRun_SimpleString(command) | 584 PyRun_SimpleString(char *command) |
| 596 char *command; | |
| 597 { | 585 { |
| 598 PyObject *m, *d, *v; | 586 PyObject *m, *d, *v; |
| 599 m = PyImport_AddModule("__main__"); | 587 m = PyImport_AddModule("__main__"); |
| 600 if (m == NULL) | 588 if (m == NULL) |
| 601 return -1; | 589 return -1; |
| 610 PyErr_Clear(); | 598 PyErr_Clear(); |
| 611 return 0; | 599 return 0; |
| 612 } | 600 } |
| 613 | 601 |
| 614 static int | 602 static int |
| 615 parse_syntax_error(err, message, filename, lineno, offset, text) | 603 parse_syntax_error(PyObject *err, PyObject **message, char **filename, |
| 616 PyObject* err; | 604 int *lineno, int *offset, char **text) |
| 617 PyObject** message; | |
| 618 char** filename; | |
| 619 int* lineno; | |
| 620 int* offset; | |
| 621 char** text; | |
| 622 { | 605 { |
| 623 long hold; | 606 long hold; |
| 624 PyObject *v; | 607 PyObject *v; |
| 625 | 608 |
| 626 /* old style errors */ | 609 /* old style errors */ |
| 673 Py_XDECREF(v); | 656 Py_XDECREF(v); |
| 674 return 0; | 657 return 0; |
| 675 } | 658 } |
| 676 | 659 |
| 677 void | 660 void |
| 678 PyErr_Print() | 661 PyErr_Print(void) |
| 679 { | 662 { |
| 680 PyErr_PrintEx(1); | 663 PyErr_PrintEx(1); |
| 681 } | 664 } |
| 682 | 665 |
| 683 void | 666 void |
| 684 PyErr_PrintEx(set_sys_last_vars) | 667 PyErr_PrintEx(int set_sys_last_vars) |
| 685 int set_sys_last_vars; | |
| 686 { | 668 { |
| 687 int err = 0; | 669 int err = 0; |
| 688 PyObject *exception, *v, *tb, *f; | 670 PyObject *exception, *v, *tb, *f; |
| 689 PyErr_Fetch(&exception, &v, &tb); | 671 PyErr_Fetch(&exception, &v, &tb); |
| 690 PyErr_NormalizeException(&exception, &v, &tb); | 672 PyErr_NormalizeException(&exception, &v, &tb); |
| 851 if (err != 0) | 833 if (err != 0) |
| 852 PyErr_Clear(); | 834 PyErr_Clear(); |
| 853 } | 835 } |
| 854 | 836 |
| 855 PyObject * | 837 PyObject * |
| 856 PyRun_String(str, start, globals, locals) | 838 PyRun_String(char *str, int start, PyObject *globals, PyObject *locals) |
| 857 char *str; | |
| 858 int start; | |
| 859 PyObject *globals, *locals; | |
| 860 { | 839 { |
| 861 return run_err_node(PyParser_SimpleParseString(str, start), | 840 return run_err_node(PyParser_SimpleParseString(str, start), |
| 862 "<string>", globals, locals); | 841 "<string>", globals, locals); |
| 863 } | 842 } |
| 864 | 843 |
| 865 PyObject * | 844 PyObject * |
| 866 PyRun_File(fp, filename, start, globals, locals) | 845 PyRun_File(FILE *fp, char *filename, int start, PyObject *globals, |
| 867 FILE *fp; | 846 PyObject *locals) |
| 868 char *filename; | |
| 869 int start; | |
| 870 PyObject *globals, *locals; | |
| 871 { | 847 { |
| 872 return run_err_node(PyParser_SimpleParseFile(fp, filename, start), | 848 return run_err_node(PyParser_SimpleParseFile(fp, filename, start), |
| 873 filename, globals, locals); | 849 filename, globals, locals); |
| 874 } | 850 } |
| 875 | 851 |
| 876 static PyObject * | 852 static PyObject * |
| 877 run_err_node(n, filename, globals, locals) | 853 run_err_node(node *n, char *filename, PyObject *globals, PyObject *locals) |
| 878 node *n; | |
| 879 char *filename; | |
| 880 PyObject *globals, *locals; | |
| 881 { | 854 { |
| 882 if (n == NULL) | 855 if (n == NULL) |
| 883 return NULL; | 856 return NULL; |
| 884 return run_node(n, filename, globals, locals); | 857 return run_node(n, filename, globals, locals); |
| 885 } | 858 } |
| 886 | 859 |
| 887 static PyObject * | 860 static PyObject * |
| 888 run_node(n, filename, globals, locals) | 861 run_node(node *n, char *filename, PyObject *globals, PyObject *locals) |
| 889 node *n; | |
| 890 char *filename; | |
| 891 PyObject *globals, *locals; | |
| 892 { | 862 { |
| 893 PyCodeObject *co; | 863 PyCodeObject *co; |
| 894 PyObject *v; | 864 PyObject *v; |
| 895 co = PyNode_Compile(n, filename); | 865 co = PyNode_Compile(n, filename); |
| 896 PyNode_Free(n); | 866 PyNode_Free(n); |
| 900 Py_DECREF(co); | 870 Py_DECREF(co); |
| 901 return v; | 871 return v; |
| 902 } | 872 } |
| 903 | 873 |
| 904 static PyObject * | 874 static PyObject * |
| 905 run_pyc_file(fp, filename, globals, locals) | 875 run_pyc_file(FILE *fp, char *filename, PyObject *globals, PyObject *locals) |
| 906 FILE *fp; | |
| 907 char *filename; | |
| 908 PyObject *globals, *locals; | |
| 909 { | 876 { |
| 910 PyCodeObject *co; | 877 PyCodeObject *co; |
| 911 PyObject *v; | 878 PyObject *v; |
| 912 long magic; | 879 long magic; |
| 913 long PyImport_GetMagicNumber(); | 880 long PyImport_GetMagicNumber(); |
| 932 Py_DECREF(co); | 899 Py_DECREF(co); |
| 933 return v; | 900 return v; |
| 934 } | 901 } |
| 935 | 902 |
| 936 PyObject * | 903 PyObject * |
| 937 Py_CompileString(str, filename, start) | 904 Py_CompileString(char *str, char *filename, int start) |
| 938 char *str; | |
| 939 char *filename; | |
| 940 int start; | |
| 941 { | 905 { |
| 942 node *n; | 906 node *n; |
| 943 PyCodeObject *co; | 907 PyCodeObject *co; |
| 944 n = PyParser_SimpleParseString(str, start); | 908 n = PyParser_SimpleParseString(str, start); |
| 945 if (n == NULL) | 909 if (n == NULL) |
| 950 } | 914 } |
| 951 | 915 |
| 952 /* Simplified interface to parsefile -- return node or set exception */ | 916 /* Simplified interface to parsefile -- return node or set exception */ |
| 953 | 917 |
| 954 node * | 918 node * |
| 955 PyParser_SimpleParseFile(fp, filename, start) | 919 PyParser_SimpleParseFile(FILE *fp, char *filename, int start) |
| 956 FILE *fp; | |
| 957 char *filename; | |
| 958 int start; | |
| 959 { | 920 { |
| 960 node *n; | 921 node *n; |
| 961 perrdetail err; | 922 perrdetail err; |
| 962 n = PyParser_ParseFile(fp, filename, &_PyParser_Grammar, start, | 923 n = PyParser_ParseFile(fp, filename, &_PyParser_Grammar, start, |
| 963 (char *)0, (char *)0, &err); | 924 (char *)0, (char *)0, &err); |
| 967 } | 928 } |
| 968 | 929 |
| 969 /* Simplified interface to parsestring -- return node or set exception */ | 930 /* Simplified interface to parsestring -- return node or set exception */ |
| 970 | 931 |
| 971 node * | 932 node * |
| 972 PyParser_SimpleParseString(str, start) | 933 PyParser_SimpleParseString(char *str, int start) |
| 973 char *str; | |
| 974 int start; | |
| 975 { | 934 { |
| 976 node *n; | 935 node *n; |
| 977 perrdetail err; | 936 perrdetail err; |
| 978 n = PyParser_ParseString(str, &_PyParser_Grammar, start, &err); | 937 n = PyParser_ParseString(str, &_PyParser_Grammar, start, &err); |
| 979 if (n == NULL) | 938 if (n == NULL) |
| 982 } | 941 } |
| 983 | 942 |
| 984 /* Set the error appropriate to the given input error code (see errcode.h) */ | 943 /* Set the error appropriate to the given input error code (see errcode.h) */ |
| 985 | 944 |
| 986 static void | 945 static void |
| 987 err_input(err) | 946 err_input(perrdetail *err) |
| 988 perrdetail *err; | |
| 989 { | 947 { |
| 990 PyObject *v, *w, *errtype; | 948 PyObject *v, *w, *errtype; |
| 991 char *msg = NULL; | 949 char *msg = NULL; |
| 992 errtype = PyExc_SyntaxError; | 950 errtype = PyExc_SyntaxError; |
| 993 v = Py_BuildValue("(ziiz)", err->filename, | 951 v = Py_BuildValue("(ziiz)", err->filename, |
| 1051 } | 1009 } |
| 1052 | 1010 |
| 1053 /* Print fatal error message and abort */ | 1011 /* Print fatal error message and abort */ |
| 1054 | 1012 |
| 1055 void | 1013 void |
| 1056 Py_FatalError(msg) | 1014 Py_FatalError(char *msg) |
| 1057 char *msg; | |
| 1058 { | 1015 { |
| 1059 fprintf(stderr, "Fatal Python error: %s\n", msg); | 1016 fprintf(stderr, "Fatal Python error: %s\n", msg); |
| 1060 #ifdef macintosh | 1017 #ifdef macintosh |
| 1061 for (;;); | 1018 for (;;); |
| 1062 #endif | 1019 #endif |
| 1077 #include "pythread.h" | 1034 #include "pythread.h" |
| 1078 int _PyThread_Started = 0; /* Set by threadmodule.c and maybe others */ | 1035 int _PyThread_Started = 0; /* Set by threadmodule.c and maybe others */ |
| 1079 #endif | 1036 #endif |
| 1080 | 1037 |
| 1081 #define NEXITFUNCS 32 | 1038 #define NEXITFUNCS 32 |
| 1082 static void (*exitfuncs[NEXITFUNCS])(); | 1039 static void (*exitfuncs[NEXITFUNCS])(void); |
| 1083 static int nexitfuncs = 0; | 1040 static int nexitfuncs = 0; |
| 1084 | 1041 |
| 1085 int Py_AtExit(func) | 1042 int Py_AtExit(void (*func)(void)) |
| 1086 void (*func)(void); | |
| 1087 { | 1043 { |
| 1088 if (nexitfuncs >= NEXITFUNCS) | 1044 if (nexitfuncs >= NEXITFUNCS) |
| 1089 return -1; | 1045 return -1; |
| 1090 exitfuncs[nexitfuncs++] = func; | 1046 exitfuncs[nexitfuncs++] = func; |
| 1091 return 0; | 1047 return 0; |
| 1092 } | 1048 } |
| 1093 | 1049 |
| 1094 static void | 1050 static void |
| 1095 call_sys_exitfunc() | 1051 call_sys_exitfunc(void) |
| 1096 { | 1052 { |
| 1097 PyObject *exitfunc = PySys_GetObject("exitfunc"); | 1053 PyObject *exitfunc = PySys_GetObject("exitfunc"); |
| 1098 | 1054 |
| 1099 if (exitfunc) { | 1055 if (exitfunc) { |
| 1100 PyObject *res, *f; | 1056 PyObject *res, *f; |
| 1113 if (Py_FlushLine()) | 1069 if (Py_FlushLine()) |
| 1114 PyErr_Clear(); | 1070 PyErr_Clear(); |
| 1115 } | 1071 } |
| 1116 | 1072 |
| 1117 static void | 1073 static void |
| 1118 call_ll_exitfuncs() | 1074 call_ll_exitfuncs(void) |
| 1119 { | 1075 { |
| 1120 while (nexitfuncs > 0) | 1076 while (nexitfuncs > 0) |
| 1121 (*exitfuncs[--nexitfuncs])(); | 1077 (*exitfuncs[--nexitfuncs])(); |
| 1122 | 1078 |
| 1123 fflush(stdout); | 1079 fflush(stdout); |
| 1124 fflush(stderr); | 1080 fflush(stderr); |
| 1125 } | 1081 } |
| 1126 | 1082 |
| 1127 void | 1083 void |
| 1128 Py_Exit(sts) | 1084 Py_Exit(int sts) |
| 1129 int sts; | |
| 1130 { | 1085 { |
| 1131 Py_Finalize(); | 1086 Py_Finalize(); |
| 1132 | 1087 |
| 1133 #ifdef macintosh | 1088 #ifdef macintosh |
| 1134 PyMac_Exit(sts); | 1089 PyMac_Exit(sts); |
| 1136 exit(sts); | 1091 exit(sts); |
| 1137 #endif | 1092 #endif |
| 1138 } | 1093 } |
| 1139 | 1094 |
| 1140 static void | 1095 static void |
| 1141 initsigs() | 1096 initsigs(void) |
| 1142 { | 1097 { |
| 1143 #ifdef HAVE_SIGNAL_H | 1098 #ifdef HAVE_SIGNAL_H |
| 1144 #ifdef SIGPIPE | 1099 #ifdef SIGPIPE |
| 1145 signal(SIGPIPE, SIG_IGN); | 1100 signal(SIGPIPE, SIG_IGN); |
| 1146 #endif | 1101 #endif |
| 1150 | 1105 |
| 1151 #ifdef Py_TRACE_REFS | 1106 #ifdef Py_TRACE_REFS |
| 1152 /* Ask a yes/no question */ | 1107 /* Ask a yes/no question */ |
| 1153 | 1108 |
| 1154 int | 1109 int |
| 1155 _Py_AskYesNo(prompt) | 1110 _Py_AskYesNo(char *prompt) |
| 1156 char *prompt; | |
| 1157 { | 1111 { |
| 1158 char buf[256]; | 1112 char buf[256]; |
| 1159 | 1113 |
| 1160 printf("%s [ny] ", prompt); | 1114 printf("%s [ny] ", prompt); |
| 1161 if (fgets(buf, sizeof buf, stdin) == NULL) | 1115 if (fgets(buf, sizeof buf, stdin) == NULL) |
| 1168 | 1122 |
| 1169 /* Check for file descriptor connected to interactive device. | 1123 /* Check for file descriptor connected to interactive device. |
| 1170 Pretend that stdin is always interactive, other files never. */ | 1124 Pretend that stdin is always interactive, other files never. */ |
| 1171 | 1125 |
| 1172 int | 1126 int |
| 1173 isatty(fd) | 1127 isatty(int fd) |
| 1174 int fd; | |
| 1175 { | 1128 { |
| 1176 return fd == fileno(stdin); | 1129 return fd == fileno(stdin); |
| 1177 } | 1130 } |
| 1178 | 1131 |
| 1179 #endif | 1132 #endif |
| 1183 * a) isatty(fd) is TRUE, or | 1136 * a) isatty(fd) is TRUE, or |
| 1184 * b) the -i flag was given, and the filename associated with | 1137 * b) the -i flag was given, and the filename associated with |
| 1185 * the descriptor is NULL or "<stdin>" or "???". | 1138 * the descriptor is NULL or "<stdin>" or "???". |
| 1186 */ | 1139 */ |
| 1187 int | 1140 int |
| 1188 Py_FdIsInteractive(fp, filename) | 1141 Py_FdIsInteractive(FILE *fp, char *filename) |
| 1189 FILE *fp; | |
| 1190 char *filename; | |
| 1191 { | 1142 { |
| 1192 if (isatty((int)fileno(fp))) | 1143 if (isatty((int)fileno(fp))) |
| 1193 return 1; | 1144 return 1; |
| 1194 if (!Py_InteractiveFlag) | 1145 if (!Py_InteractiveFlag) |
| 1195 return 0; | 1146 return 0; |
