Mercurial > emacs
comparison src/print.c @ 22231:35af9a276272
(print) <Lisp_Cons>: Detect circular list.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 25 May 1998 16:28:02 +0000 |
parents | 3eedfddbbadd |
children | 4e4c377f3310 |
comparison
equal
deleted
inserted
replaced
22230:32f2adf05397 | 22231:35af9a276272 |
---|---|
1416 { | 1416 { |
1417 PRINTCHAR ('('); | 1417 PRINTCHAR ('('); |
1418 { | 1418 { |
1419 register int i = 0; | 1419 register int i = 0; |
1420 register int print_length = 0; | 1420 register int print_length = 0; |
1421 Lisp_Object halftail = obj; | |
1421 | 1422 |
1422 if (INTEGERP (Vprint_length)) | 1423 if (INTEGERP (Vprint_length)) |
1423 print_length = XINT (Vprint_length); | 1424 print_length = XINT (Vprint_length); |
1424 /* Could recognize circularities in cdrs here, | |
1425 but that would make printing of long lists quadratic. | |
1426 It's not worth doing. */ | |
1427 while (CONSP (obj)) | 1425 while (CONSP (obj)) |
1428 { | 1426 { |
1427 /* Detect circular list. */ | |
1428 if (i != 0 && EQ (obj, halftail)) | |
1429 { | |
1430 sprintf (buf, " . #%d", i / 2); | |
1431 strout (buf, -1, -1, printcharfun, 0); | |
1432 obj = Qnil; | |
1433 break; | |
1434 } | |
1429 if (i++) | 1435 if (i++) |
1430 PRINTCHAR (' '); | 1436 PRINTCHAR (' '); |
1431 if (print_length && i > print_length) | 1437 if (print_length && i > print_length) |
1432 { | 1438 { |
1433 strout ("...", 3, 3, printcharfun, 0); | 1439 strout ("...", 3, 3, printcharfun, 0); |
1434 break; | 1440 break; |
1435 } | 1441 } |
1436 print (XCAR (obj), printcharfun, escapeflag); | 1442 print (XCAR (obj), printcharfun, escapeflag); |
1437 obj = XCDR (obj); | 1443 obj = XCDR (obj); |
1444 if (!(i & 1)) | |
1445 halftail = XCDR (halftail); | |
1438 } | 1446 } |
1439 } | 1447 } |
1440 if (!NILP (obj)) | 1448 if (!NILP (obj)) |
1441 { | 1449 { |
1442 strout (" . ", 3, 3, printcharfun, 0); | 1450 strout (" . ", 3, 3, printcharfun, 0); |