comparison Python/errors.c @ 23029:8291473fde3e legacy-trunk

Mass checkin of universal newline support. Highlights: import and friends will understand any of \r, \n and \r\n as end of line. Python file input will do the same if you use mode 'U'. Everything can be disabled by configuring with --without-universal-newlines. See PEP278 for details.
author Jack Jansen <jack.jansen@cwi.nl>
date Sun, 14 Apr 2002 20:12:41 +0000
parents f4487350c537
children 8142f8d668a0
comparison
equal deleted inserted replaced
23028:a9a6c118dfba 23029:8291473fde3e
644 int i; 644 int i;
645 char linebuf[1000]; 645 char linebuf[1000];
646 646
647 if (filename == NULL || lineno <= 0) 647 if (filename == NULL || lineno <= 0)
648 return NULL; 648 return NULL;
649 fp = fopen(filename, "r"); 649 fp = fopen(filename, "r" PY_STDIOTEXTMODE);
650 if (fp == NULL) 650 if (fp == NULL)
651 return NULL; 651 return NULL;
652 for (i = 0; i < lineno; i++) { 652 for (i = 0; i < lineno; i++) {
653 char *pLastChar = &linebuf[sizeof(linebuf) - 2]; 653 char *pLastChar = &linebuf[sizeof(linebuf) - 2];
654 do { 654 do {
655 *pLastChar = '\0'; 655 *pLastChar = '\0';
656 if (fgets(linebuf, sizeof linebuf, fp) == NULL) 656 if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf, fp, NULL) == NULL)
657 break; 657 break;
658 /* fgets read *something*; if it didn't get as 658 /* fgets read *something*; if it didn't get as
659 far as pLastChar, it must have found a newline 659 far as pLastChar, it must have found a newline
660 or hit the end of the file; if pLastChar is \n, 660 or hit the end of the file; if pLastChar is \n,
661 it obviously found a newline; else we haven't 661 it obviously found a newline; else we haven't