comparison src/fns.c @ 485:8c615e453683

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Mon, 13 Jan 1992 21:48:08 +0000
parents 4c9349866dac
children 540b047ece4d
comparison
equal deleted inserted replaced
484:3165b2697c78 485:8c615e453683
58 /* Note on some machines this defines `vector' as a typedef, 58 /* Note on some machines this defines `vector' as a typedef,
59 so make sure we don't use that name in this file. */ 59 so make sure we don't use that name in this file. */
60 #undef vector 60 #undef vector
61 #define vector ***** 61 #define vector *****
62 62
63 #ifdef NULL
64 #undef NULL
65 #endif
66 #include "lisp.h" 63 #include "lisp.h"
67 #include "commands.h" 64 #include "commands.h"
68 65
69 #ifdef MULTI_SCREEN 66 #ifdef MULTI_SCREEN
70 #include "screen.h" 67 #include "screen.h"
130 if (XTYPE (obj) == Lisp_Vector || XTYPE (obj) == Lisp_String 127 if (XTYPE (obj) == Lisp_Vector || XTYPE (obj) == Lisp_String
131 || XTYPE (obj) == Lisp_Compiled) 128 || XTYPE (obj) == Lisp_Compiled)
132 return Farray_length (obj); 129 return Farray_length (obj);
133 else if (CONSP (obj)) 130 else if (CONSP (obj))
134 { 131 {
135 for (i = 0, tail = obj; !NULL(tail); i++) 132 for (i = 0, tail = obj; !NILP(tail); i++)
136 { 133 {
137 QUIT; 134 QUIT;
138 tail = Fcdr (tail); 135 tail = Fcdr (tail);
139 } 136 }
140 137
141 XFASTINT (val) = i; 138 XFASTINT (val) = i;
142 return val; 139 return val;
143 } 140 }
144 else if (NULL(obj)) 141 else if (NILP(obj))
145 { 142 {
146 XFASTINT (val) = 0; 143 XFASTINT (val) = 0;
147 return val; 144 return val;
148 } 145 }
149 else 146 else
261 The elements of a list or vector are not copied; they are shared\n\ 258 The elements of a list or vector are not copied; they are shared\n\
262 with the original.") 259 with the original.")
263 (arg) 260 (arg)
264 Lisp_Object arg; 261 Lisp_Object arg;
265 { 262 {
266 if (NULL (arg)) return arg; 263 if (NILP (arg)) return arg;
267 if (!CONSP (arg) && XTYPE (arg) != Lisp_Vector && XTYPE (arg) != Lisp_String) 264 if (!CONSP (arg) && XTYPE (arg) != Lisp_Vector && XTYPE (arg) != Lisp_String)
268 arg = wrong_type_argument (Qsequencep, arg); 265 arg = wrong_type_argument (Qsequencep, arg);
269 return concat (1, &arg, CONSP (arg) ? Lisp_Cons : XTYPE (arg), 0); 266 return concat (1, &arg, CONSP (arg) ? Lisp_Cons : XTYPE (arg), 0);
270 } 267 }
271 268
296 last_tail = Qnil; 293 last_tail = Qnil;
297 294
298 for (argnum = 0; argnum < nargs; argnum++) 295 for (argnum = 0; argnum < nargs; argnum++)
299 { 296 {
300 this = args[argnum]; 297 this = args[argnum];
301 if (!(CONSP (this) || NULL (this) 298 if (!(CONSP (this) || NILP (this)
302 || XTYPE (this) == Lisp_Vector || XTYPE (this) == Lisp_String 299 || XTYPE (this) == Lisp_Vector || XTYPE (this) == Lisp_String
303 || XTYPE (this) == Lisp_Compiled)) 300 || XTYPE (this) == Lisp_Compiled))
304 { 301 {
305 if (XTYPE (this) == Lisp_Int) 302 if (XTYPE (this) == Lisp_Int)
306 args[argnum] = Fint_to_string (this); 303 args[argnum] = Fint_to_string (this);
349 while (1) 346 while (1)
350 { 347 {
351 register Lisp_Object elt; 348 register Lisp_Object elt;
352 349
353 /* Fetch next element of `this' arg into `elt', or break if `this' is exhausted. */ 350 /* Fetch next element of `this' arg into `elt', or break if `this' is exhausted. */
354 if (NULL (this)) break; 351 if (NILP (this)) break;
355 if (CONSP (this)) 352 if (CONSP (this))
356 elt = Fcar (this), this = Fcdr (this); 353 elt = Fcar (this), this = Fcdr (this);
357 else 354 else
358 { 355 {
359 if (thisindex >= thisleni) break; 356 if (thisindex >= thisleni) break;
387 #endif 384 #endif
388 } 385 }
389 } 386 }
390 } 387 }
391 } 388 }
392 if (!NULL (prev)) 389 if (!NILP (prev))
393 XCONS (prev)->cdr = last_tail; 390 XCONS (prev)->cdr = last_tail;
394 391
395 return val; 392 return val;
396 } 393 }
397 394
406 Lisp_Object alist; 403 Lisp_Object alist;
407 { 404 {
408 register Lisp_Object tem; 405 register Lisp_Object tem;
409 406
410 CHECK_LIST (alist, 0); 407 CHECK_LIST (alist, 0);
411 if (NULL (alist)) 408 if (NILP (alist))
412 return alist; 409 return alist;
413 alist = concat (1, &alist, Lisp_Cons, 0); 410 alist = concat (1, &alist, Lisp_Cons, 0);
414 for (tem = alist; CONSP (tem); tem = XCONS (tem)->cdr) 411 for (tem = alist; CONSP (tem); tem = XCONS (tem)->cdr)
415 { 412 {
416 register Lisp_Object car; 413 register Lisp_Object car;
430 Lisp_Object string; 427 Lisp_Object string;
431 register Lisp_Object from, to; 428 register Lisp_Object from, to;
432 { 429 {
433 CHECK_STRING (string, 0); 430 CHECK_STRING (string, 0);
434 CHECK_NUMBER (from, 1); 431 CHECK_NUMBER (from, 1);
435 if (NULL (to)) 432 if (NILP (to))
436 to = Flength (string); 433 to = Flength (string);
437 else 434 else
438 CHECK_NUMBER (to, 2); 435 CHECK_NUMBER (to, 2);
439 436
440 if (XINT (from) < 0) 437 if (XINT (from) < 0)
456 register Lisp_Object list; 453 register Lisp_Object list;
457 { 454 {
458 register int i, num; 455 register int i, num;
459 CHECK_NUMBER (n, 0); 456 CHECK_NUMBER (n, 0);
460 num = XINT (n); 457 num = XINT (n);
461 for (i = 0; i < num && !NULL (list); i++) 458 for (i = 0; i < num && !NILP (list); i++)
462 { 459 {
463 QUIT; 460 QUIT;
464 list = Fcdr (list); 461 list = Fcdr (list);
465 } 462 }
466 return list; 463 return list;
481 register Lisp_Object seq, n; 478 register Lisp_Object seq, n;
482 { 479 {
483 CHECK_NUMBER (n, 0); 480 CHECK_NUMBER (n, 0);
484 while (1) 481 while (1)
485 { 482 {
486 if (XTYPE (seq) == Lisp_Cons || NULL (seq)) 483 if (XTYPE (seq) == Lisp_Cons || NILP (seq))
487 return Fcar (Fnthcdr (n, seq)); 484 return Fcar (Fnthcdr (n, seq));
488 else if (XTYPE (seq) == Lisp_String 485 else if (XTYPE (seq) == Lisp_String
489 || XTYPE (seq) == Lisp_Vector) 486 || XTYPE (seq) == Lisp_Vector)
490 return Faref (seq, n); 487 return Faref (seq, n);
491 else 488 else
499 (elt, list) 496 (elt, list)
500 register Lisp_Object elt; 497 register Lisp_Object elt;
501 Lisp_Object list; 498 Lisp_Object list;
502 { 499 {
503 register Lisp_Object tail; 500 register Lisp_Object tail;
504 for (tail = list; !NULL (tail); tail = Fcdr (tail)) 501 for (tail = list; !NILP (tail); tail = Fcdr (tail))
505 { 502 {
506 register Lisp_Object tem; 503 register Lisp_Object tem;
507 tem = Fcar (tail); 504 tem = Fcar (tail);
508 if (! NULL (Fequal (elt, tem))) 505 if (! NILP (Fequal (elt, tem)))
509 return tail; 506 return tail;
510 QUIT; 507 QUIT;
511 } 508 }
512 return Qnil; 509 return Qnil;
513 } 510 }
518 (elt, list) 515 (elt, list)
519 register Lisp_Object elt; 516 register Lisp_Object elt;
520 Lisp_Object list; 517 Lisp_Object list;
521 { 518 {
522 register Lisp_Object tail; 519 register Lisp_Object tail;
523 for (tail = list; !NULL (tail); tail = Fcdr (tail)) 520 for (tail = list; !NILP (tail); tail = Fcdr (tail))
524 { 521 {
525 register Lisp_Object tem; 522 register Lisp_Object tem;
526 tem = Fcar (tail); 523 tem = Fcar (tail);
527 if (EQ (elt, tem)) return tail; 524 if (EQ (elt, tem)) return tail;
528 QUIT; 525 QUIT;
537 (key, list) 534 (key, list)
538 register Lisp_Object key; 535 register Lisp_Object key;
539 Lisp_Object list; 536 Lisp_Object list;
540 { 537 {
541 register Lisp_Object tail; 538 register Lisp_Object tail;
542 for (tail = list; !NULL (tail); tail = Fcdr (tail)) 539 for (tail = list; !NILP (tail); tail = Fcdr (tail))
543 { 540 {
544 register Lisp_Object elt, tem; 541 register Lisp_Object elt, tem;
545 elt = Fcar (tail); 542 elt = Fcar (tail);
546 if (!CONSP (elt)) continue; 543 if (!CONSP (elt)) continue;
547 tem = Fcar (elt); 544 tem = Fcar (elt);
577 (key, list) 574 (key, list)
578 register Lisp_Object key; 575 register Lisp_Object key;
579 Lisp_Object list; 576 Lisp_Object list;
580 { 577 {
581 register Lisp_Object tail; 578 register Lisp_Object tail;
582 for (tail = list; !NULL (tail); tail = Fcdr (tail)) 579 for (tail = list; !NILP (tail); tail = Fcdr (tail))
583 { 580 {
584 register Lisp_Object elt, tem; 581 register Lisp_Object elt, tem;
585 elt = Fcar (tail); 582 elt = Fcar (tail);
586 if (!CONSP (elt)) continue; 583 if (!CONSP (elt)) continue;
587 tem = Fequal (Fcar (elt), key); 584 tem = Fequal (Fcar (elt), key);
588 if (!NULL (tem)) return elt; 585 if (!NILP (tem)) return elt;
589 QUIT; 586 QUIT;
590 } 587 }
591 return Qnil; 588 return Qnil;
592 } 589 }
593 590
597 (key, list) 594 (key, list)
598 register Lisp_Object key; 595 register Lisp_Object key;
599 Lisp_Object list; 596 Lisp_Object list;
600 { 597 {
601 register Lisp_Object tail; 598 register Lisp_Object tail;
602 for (tail = list; !NULL (tail); tail = Fcdr (tail)) 599 for (tail = list; !NILP (tail); tail = Fcdr (tail))
603 { 600 {
604 register Lisp_Object elt, tem; 601 register Lisp_Object elt, tem;
605 elt = Fcar (tail); 602 elt = Fcar (tail);
606 if (!CONSP (elt)) continue; 603 if (!CONSP (elt)) continue;
607 tem = Fcdr (elt); 604 tem = Fcdr (elt);
624 register Lisp_Object tail, prev; 621 register Lisp_Object tail, prev;
625 register Lisp_Object tem; 622 register Lisp_Object tem;
626 623
627 tail = list; 624 tail = list;
628 prev = Qnil; 625 prev = Qnil;
629 while (!NULL (tail)) 626 while (!NILP (tail))
630 { 627 {
631 tem = Fcar (tail); 628 tem = Fcar (tail);
632 if (EQ (elt, tem)) 629 if (EQ (elt, tem))
633 { 630 {
634 if (NULL (prev)) 631 if (NILP (prev))
635 list = Fcdr (tail); 632 list = Fcdr (tail);
636 else 633 else
637 Fsetcdr (prev, Fcdr (tail)); 634 Fsetcdr (prev, Fcdr (tail));
638 } 635 }
639 else 636 else
657 register Lisp_Object tail, prev; 654 register Lisp_Object tail, prev;
658 register Lisp_Object tem; 655 register Lisp_Object tem;
659 656
660 tail = list; 657 tail = list;
661 prev = Qnil; 658 prev = Qnil;
662 while (!NULL (tail)) 659 while (!NILP (tail))
663 { 660 {
664 tem = Fcar (tail); 661 tem = Fcar (tail);
665 if (Fequal (elt, tem)) 662 if (Fequal (elt, tem))
666 { 663 {
667 if (NULL (prev)) 664 if (NILP (prev))
668 list = Fcdr (tail); 665 list = Fcdr (tail);
669 else 666 else
670 Fsetcdr (prev, Fcdr (tail)); 667 Fsetcdr (prev, Fcdr (tail));
671 } 668 }
672 else 669 else
683 (list) 680 (list)
684 Lisp_Object list; 681 Lisp_Object list;
685 { 682 {
686 register Lisp_Object prev, tail, next; 683 register Lisp_Object prev, tail, next;
687 684
688 if (NULL (list)) return list; 685 if (NILP (list)) return list;
689 prev = Qnil; 686 prev = Qnil;
690 tail = list; 687 tail = list;
691 while (!NULL (tail)) 688 while (!NILP (tail))
692 { 689 {
693 QUIT; 690 QUIT;
694 next = Fcdr (tail); 691 next = Fcdr (tail);
695 Fsetcdr (tail, prev); 692 Fsetcdr (tail, prev);
696 prev = tail; 693 prev = tail;
772 back into the org_ vars. */ 769 back into the org_ vars. */
773 GCPRO4 (org_l1, org_l2, pred, value); 770 GCPRO4 (org_l1, org_l2, pred, value);
774 771
775 while (1) 772 while (1)
776 { 773 {
777 if (NULL (l1)) 774 if (NILP (l1))
778 { 775 {
779 UNGCPRO; 776 UNGCPRO;
780 if (NULL (tail)) 777 if (NILP (tail))
781 return l2; 778 return l2;
782 Fsetcdr (tail, l2); 779 Fsetcdr (tail, l2);
783 return value; 780 return value;
784 } 781 }
785 if (NULL (l2)) 782 if (NILP (l2))
786 { 783 {
787 UNGCPRO; 784 UNGCPRO;
788 if (NULL (tail)) 785 if (NILP (tail))
789 return l1; 786 return l1;
790 Fsetcdr (tail, l1); 787 Fsetcdr (tail, l1);
791 return value; 788 return value;
792 } 789 }
793 tem = call2 (pred, Fcar (l2), Fcar (l1)); 790 tem = call2 (pred, Fcar (l2), Fcar (l1));
794 if (NULL (tem)) 791 if (NILP (tem))
795 { 792 {
796 tem = l1; 793 tem = l1;
797 l1 = Fcdr (l1); 794 l1 = Fcdr (l1);
798 org_l1 = l1; 795 org_l1 = l1;
799 } 796 }
801 { 798 {
802 tem = l2; 799 tem = l2;
803 l2 = Fcdr (l2); 800 l2 = Fcdr (l2);
804 org_l2 = l2; 801 org_l2 = l2;
805 } 802 }
806 if (NULL (tail)) 803 if (NILP (tail))
807 value = tem; 804 value = tem;
808 else 805 else
809 Fsetcdr (tail, tem); 806 Fsetcdr (tail, tem);
810 tail = tem; 807 tail = tem;
811 } 808 }
817 (sym, prop) 814 (sym, prop)
818 Lisp_Object sym; 815 Lisp_Object sym;
819 register Lisp_Object prop; 816 register Lisp_Object prop;
820 { 817 {
821 register Lisp_Object tail; 818 register Lisp_Object tail;
822 for (tail = Fsymbol_plist (sym); !NULL (tail); tail = Fcdr (Fcdr (tail))) 819 for (tail = Fsymbol_plist (sym); !NILP (tail); tail = Fcdr (Fcdr (tail)))
823 { 820 {
824 register Lisp_Object tem; 821 register Lisp_Object tem;
825 tem = Fcar (tail); 822 tem = Fcar (tail);
826 if (EQ (prop, tem)) 823 if (EQ (prop, tem))
827 return Fcar (Fcdr (tail)); 824 return Fcar (Fcdr (tail));
838 Lisp_Object val; 835 Lisp_Object val;
839 { 836 {
840 register Lisp_Object tail, prev; 837 register Lisp_Object tail, prev;
841 Lisp_Object newcell; 838 Lisp_Object newcell;
842 prev = Qnil; 839 prev = Qnil;
843 for (tail = Fsymbol_plist (sym); !NULL (tail); tail = Fcdr (Fcdr (tail))) 840 for (tail = Fsymbol_plist (sym); !NILP (tail); tail = Fcdr (Fcdr (tail)))
844 { 841 {
845 register Lisp_Object tem; 842 register Lisp_Object tem;
846 tem = Fcar (tail); 843 tem = Fcar (tail);
847 if (EQ (prop, tem)) 844 if (EQ (prop, tem))
848 return Fsetcar (Fcdr (tail), val); 845 return Fsetcar (Fcdr (tail), val);
849 prev = tail; 846 prev = tail;
850 } 847 }
851 newcell = Fcons (prop, Fcons (val, Qnil)); 848 newcell = Fcons (prop, Fcons (val, Qnil));
852 if (NULL (prev)) 849 if (NILP (prev))
853 Fsetplist (sym, newcell); 850 Fsetplist (sym, newcell);
854 else 851 else
855 Fsetcdr (Fcdr (prev), newcell); 852 Fsetcdr (Fcdr (prev), newcell);
856 return val; 853 return val;
857 } 854 }
881 if (XINT (o1) == XINT (o2)) return Qt; 878 if (XINT (o1) == XINT (o2)) return Qt;
882 if (XTYPE (o1) == Lisp_Cons) 879 if (XTYPE (o1) == Lisp_Cons)
883 { 880 {
884 Lisp_Object v1; 881 Lisp_Object v1;
885 v1 = Fequal (Fcar (o1), Fcar (o2), depth + 1); 882 v1 = Fequal (Fcar (o1), Fcar (o2), depth + 1);
886 if (NULL (v1)) 883 if (NILP (v1))
887 return v1; 884 return v1;
888 o1 = Fcdr (o1), o2 = Fcdr (o2); 885 o1 = Fcdr (o1), o2 = Fcdr (o2);
889 goto do_cdr; 886 goto do_cdr;
890 } 887 }
891 if (XTYPE (o1) == Lisp_Marker) 888 if (XTYPE (o1) == Lisp_Marker)
903 { 900 {
904 Lisp_Object v, v1, v2; 901 Lisp_Object v, v1, v2;
905 v1 = XVECTOR (o1)->contents [index]; 902 v1 = XVECTOR (o1)->contents [index];
906 v2 = XVECTOR (o2)->contents [index]; 903 v2 = XVECTOR (o2)->contents [index];
907 v = Fequal (v1, v2, depth + 1); 904 v = Fequal (v1, v2, depth + 1);
908 if (NULL (v)) return v; 905 if (NILP (v)) return v;
909 } 906 }
910 return Qt; 907 return Qt;
911 } 908 }
912 if (XTYPE (o1) == Lisp_String) 909 if (XTYPE (o1) == Lisp_String)
913 { 910 {
979 val = Qnil; 976 val = Qnil;
980 977
981 for (argnum = 0; argnum < nargs; argnum++) 978 for (argnum = 0; argnum < nargs; argnum++)
982 { 979 {
983 tem = args[argnum]; 980 tem = args[argnum];
984 if (NULL (tem)) continue; 981 if (NILP (tem)) continue;
985 982
986 if (NULL (val)) 983 if (NILP (val))
987 val = tem; 984 val = tem;
988 985
989 if (argnum + 1 == nargs) break; 986 if (argnum + 1 == nargs) break;
990 987
991 if (!CONSP (tem)) 988 if (!CONSP (tem))
998 QUIT; 995 QUIT;
999 } 996 }
1000 997
1001 tem = args[argnum + 1]; 998 tem = args[argnum + 1];
1002 Fsetcdr (tail, tem); 999 Fsetcdr (tail, tem);
1003 if (NULL (tem)) 1000 if (NILP (tem))
1004 args[argnum + 1] = tail; 1001 args[argnum + 1] = tail;
1005 } 1002 }
1006 1003
1007 return val; 1004 return val;
1008 } 1005 }
1407 Lisp_Object feature; 1404 Lisp_Object feature;
1408 { 1405 {
1409 register Lisp_Object tem; 1406 register Lisp_Object tem;
1410 CHECK_SYMBOL (feature, 0); 1407 CHECK_SYMBOL (feature, 0);
1411 tem = Fmemq (feature, Vfeatures); 1408 tem = Fmemq (feature, Vfeatures);
1412 return (NULL (tem)) ? Qnil : Qt; 1409 return (NILP (tem)) ? Qnil : Qt;
1413 } 1410 }
1414 1411
1415 DEFUN ("provide", Fprovide, Sprovide, 1, 1, 0, 1412 DEFUN ("provide", Fprovide, Sprovide, 1, 1, 0,
1416 "Announce that FEATURE is a feature of the current Emacs.") 1413 "Announce that FEATURE is a feature of the current Emacs.")
1417 (feature) 1414 (feature)
1418 Lisp_Object feature; 1415 Lisp_Object feature;
1419 { 1416 {
1420 register Lisp_Object tem; 1417 register Lisp_Object tem;
1421 CHECK_SYMBOL (feature, 0); 1418 CHECK_SYMBOL (feature, 0);
1422 if (!NULL (Vautoload_queue)) 1419 if (!NILP (Vautoload_queue))
1423 Vautoload_queue = Fcons (Fcons (Vfeatures, Qnil), Vautoload_queue); 1420 Vautoload_queue = Fcons (Fcons (Vfeatures, Qnil), Vautoload_queue);
1424 tem = Fmemq (feature, Vfeatures); 1421 tem = Fmemq (feature, Vfeatures);
1425 if (NULL (tem)) 1422 if (NILP (tem))
1426 Vfeatures = Fcons (feature, Vfeatures); 1423 Vfeatures = Fcons (feature, Vfeatures);
1427 return feature; 1424 return feature;
1428 } 1425 }
1429 1426
1430 DEFUN ("require", Frequire, Srequire, 1, 2, 0, 1427 DEFUN ("require", Frequire, Srequire, 1, 2, 0,
1436 Lisp_Object feature, file_name; 1433 Lisp_Object feature, file_name;
1437 { 1434 {
1438 register Lisp_Object tem; 1435 register Lisp_Object tem;
1439 CHECK_SYMBOL (feature, 0); 1436 CHECK_SYMBOL (feature, 0);
1440 tem = Fmemq (feature, Vfeatures); 1437 tem = Fmemq (feature, Vfeatures);
1441 if (NULL (tem)) 1438 if (NILP (tem))
1442 { 1439 {
1443 int count = specpdl_ptr - specpdl; 1440 int count = specpdl_ptr - specpdl;
1444 1441
1445 /* Value saved here is to be restored into Vautoload_queue */ 1442 /* Value saved here is to be restored into Vautoload_queue */
1446 record_unwind_protect (un_autoload, Vautoload_queue); 1443 record_unwind_protect (un_autoload, Vautoload_queue);
1447 Vautoload_queue = Qt; 1444 Vautoload_queue = Qt;
1448 1445
1449 Fload (NULL (file_name) ? Fsymbol_name (feature) : file_name, 1446 Fload (NILP (file_name) ? Fsymbol_name (feature) : file_name,
1450 Qnil, Qt, Qnil); 1447 Qnil, Qt, Qnil);
1451 1448
1452 tem = Fmemq (feature, Vfeatures); 1449 tem = Fmemq (feature, Vfeatures);
1453 if (NULL (tem)) 1450 if (NILP (tem))
1454 error ("Required feature %s was not provided", 1451 error ("Required feature %s was not provided",
1455 XSYMBOL (feature)->name->data ); 1452 XSYMBOL (feature)->name->data );
1456 1453
1457 /* Once loading finishes, don't undo it. */ 1454 /* Once loading finishes, don't undo it. */
1458 Vautoload_queue = Qt; 1455 Vautoload_queue = Qt;