diff Python/traceback.c @ 1073:2c0432fcc270 legacy-trunk

Modified most (but not yet all) I/O to always go through sys.stdout or sys.stderr or sys.stdin, and to work with any object as long as it has a write() (respectively readline()) methods. Some functions that took a FILE* argument now take an object* argument.
author Guido van Rossum <guido@python.org>
date Fri, 25 Sep 1992 21:59:05 +0000
parents 0cd197947d81
children 1cabc2b6c970
line wrap: on
line diff
--- a/Python/traceback.c	Fri Sep 25 21:54:05 1992 +0000
+++ b/Python/traceback.c	Fri Sep 25 21:59:05 1992 +0000
@@ -150,8 +150,8 @@
 }
 
 static void
-tb_displayline(fp, filename, lineno)
-	FILE *fp;
+tb_displayline(f, filename, lineno)
+	object *f;
 	char *filename;
 	int lineno;
 {
@@ -189,15 +189,17 @@
 			}
 		}
 	}
-	fprintf(fp, "  File \"%s\"", filename);
+	sprintf(linebuf, "  File \"%.900s\"%s line %d\n",
+		filename,
 #ifdef applec /* MPW */
-	/* This is needed by MPW's File and Line commands */
-	fprintf(fp, "; ");
+		/* This is needed by MPW's File and Line commands */
+		";",
 #else
-	/* This is needed by Emacs' compile command */
-	fprintf(fp, ", ");
+		/* This is needed by Emacs' compile command */
+		",",
 #endif
-	fprintf(fp, "line %d\n", lineno);
+		lineno);
+	writestring(linebuf, f);
 	if (xfp == NULL)
 		return;
 	for (i = 0; i < lineno; i++) {
@@ -208,20 +210,21 @@
 		char *p = linebuf;
 		while (*p == ' ' || *p == '\t')
 			p++;
-		fprintf(fp, "    %s", p);
+		writestring("    ", f);
+		writestring(p, f);
 		if (strchr(p, '\n') == NULL)
-			fprintf(fp, "\n");
+			writestring("\n", f);
 	}
 	fclose(xfp);
 }
 
 static void
-tb_printinternal(tb, fp)
+tb_printinternal(tb, f)
 	tracebackobject *tb;
-	FILE *fp;
+	object *f;
 {
 	while (tb != NULL && !intrcheck()) {
-		tb_displayline(fp,
+		tb_displayline(f,
 		     getstringvalue(tb->tb_frame->f_code->co_filename),
 							tb->tb_lineno);
 		tb = tb->tb_next;
@@ -229,9 +232,9 @@
 }
 
 int
-tb_print(v, fp)
+tb_print(v, f)
 	object *v;
-	FILE *fp;
+	object *f;
 {
 	if (v == NULL)
 		return 0;
@@ -240,6 +243,6 @@
 		return -1;
 	}
 	sysset("last_traceback", v);
-	tb_printinternal((tracebackobject *)v, fp);
+	tb_printinternal((tracebackobject *)v, f);
 	return 0;
 }