Mercurial > hg > xemacs-beta
comparison src/editfns.c @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | de805c49cfc1 |
children | 41dbb7a9d5f2 |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
26 | 26 |
27 /* Hacked on for Mule by Ben Wing, December 1994. */ | 27 /* Hacked on for Mule by Ben Wing, December 1994. */ |
28 | 28 |
29 #include <config.h> | 29 #include <config.h> |
30 #include "lisp.h" | 30 #include "lisp.h" |
31 #ifdef HAVE_UNISTD_H | |
32 #include <unistd.h> | |
33 #endif | |
31 | 34 |
32 #include "buffer.h" | 35 #include "buffer.h" |
33 #include "commands.h" | 36 #include "commands.h" |
34 #include "events.h" /* for EVENTP */ | 37 #include "events.h" /* for EVENTP */ |
35 #include "extents.h" | 38 #include "extents.h" |
40 #include "line-number.h" | 43 #include "line-number.h" |
41 | 44 |
42 #include "systime.h" | 45 #include "systime.h" |
43 #include "sysdep.h" | 46 #include "sysdep.h" |
44 #include "syspwd.h" | 47 #include "syspwd.h" |
45 #include "sysfile.h" /* for getcwd */ | |
46 | 48 |
47 /* Some static data, and a function to initialize it for each run */ | 49 /* Some static data, and a function to initialize it for each run */ |
48 | 50 |
49 Lisp_Object Vsystem_name; /* #### - I don't see why this should be */ | 51 Lisp_Object Vsystem_name; /* #### - I don't see why this should be */ |
50 /* static, either... --Stig */ | 52 /* static, either... --Stig */ |
61 /* It's useful to be able to set this as user customization, so we'll | 63 /* It's useful to be able to set this as user customization, so we'll |
62 keep it. */ | 64 keep it. */ |
63 Lisp_Object Vuser_full_name; | 65 Lisp_Object Vuser_full_name; |
64 EXFUN (Fuser_full_name, 1); | 66 EXFUN (Fuser_full_name, 1); |
65 | 67 |
68 char *get_system_name (void); | |
69 | |
66 Lisp_Object Qformat; | 70 Lisp_Object Qformat; |
67 | 71 |
68 Lisp_Object Qpoint, Qmark, Qregion_beginning, Qregion_end; | 72 Lisp_Object Qpoint, Qmark, Qregion_beginning, Qregion_end; |
69 | 73 |
70 Lisp_Object Quser_files_and_directories; | 74 Lisp_Object Quser_files_and_directories; |
91 #endif | 95 #endif |
92 | 96 |
93 if ((p = getenv ("NAME"))) | 97 if ((p = getenv ("NAME"))) |
94 /* I don't think it's the right thing to do the ampersand | 98 /* I don't think it's the right thing to do the ampersand |
95 modification on NAME. Not that it matters anymore... -hniksic */ | 99 modification on NAME. Not that it matters anymore... -hniksic */ |
96 Vuser_full_name = build_ext_string (p, Qnative); | 100 Vuser_full_name = build_ext_string (p, FORMAT_OS); |
97 else | 101 else |
98 Vuser_full_name = Fuser_full_name (Qnil); | 102 Vuser_full_name = Fuser_full_name (Qnil); |
99 } | 103 } |
100 | 104 |
101 DEFUN ("char-to-string", Fchar_to_string, 1, 1, 0, /* | 105 DEFUN ("char-to-string", Fchar_to_string, 1, 1, 0, /* |
126 Convert arg STRING to a character, the first character of that string. | 130 Convert arg STRING to a character, the first character of that string. |
127 An empty string will return the constant `nil'. | 131 An empty string will return the constant `nil'. |
128 */ | 132 */ |
129 (str)) | 133 (str)) |
130 { | 134 { |
131 Lisp_String *p; | 135 struct Lisp_String *p; |
132 CHECK_STRING (str); | 136 CHECK_STRING (str); |
133 | 137 |
134 p = XSTRING (str); | 138 p = XSTRING (str); |
135 if (string_length (p) != 0) | 139 if (string_length (p) != 0) |
136 return make_char (string_char (p, 0)); | 140 return make_char (string_char (p, 0)); |
435 return make_int (BUF_SIZE (b)); | 439 return make_int (BUF_SIZE (b)); |
436 } | 440 } |
437 | 441 |
438 DEFUN ("point-min", Fpoint_min, 0, 1, 0, /* | 442 DEFUN ("point-min", Fpoint_min, 0, 1, 0, /* |
439 Return the minimum permissible value of point in BUFFER. | 443 Return the minimum permissible value of point in BUFFER. |
440 This is 1, unless narrowing (a buffer restriction) | 444 This is 1, unless narrowing (a buffer restriction) is in effect. |
441 is in effect, in which case it may be greater. | |
442 If BUFFER is nil, the current buffer is assumed. | 445 If BUFFER is nil, the current buffer is assumed. |
443 */ | 446 */ |
444 (buffer)) | 447 (buffer)) |
445 { | 448 { |
446 struct buffer *b = decode_buffer (buffer, 1); | 449 struct buffer *b = decode_buffer (buffer, 1); |
447 return make_int (BUF_BEGV (b)); | 450 return make_int (BUF_BEGV (b)); |
448 } | 451 } |
449 | 452 |
450 DEFUN ("point-min-marker", Fpoint_min_marker, 0, 1, 0, /* | 453 DEFUN ("point-min-marker", Fpoint_min_marker, 0, 1, 0, /* |
451 Return a marker to the minimum permissible value of point in BUFFER. | 454 Return a marker to the minimum permissible value of point in BUFFER. |
452 This is the beginning, unless narrowing (a buffer restriction) | 455 This is the beginning, unless narrowing (a buffer restriction) is in effect. |
453 is in effect, in which case it may be greater. | |
454 If BUFFER is nil, the current buffer is assumed. | 456 If BUFFER is nil, the current buffer is assumed. |
455 */ | 457 */ |
456 (buffer)) | 458 (buffer)) |
457 { | 459 { |
458 struct buffer *b = decode_buffer (buffer, 1); | 460 struct buffer *b = decode_buffer (buffer, 1); |
460 } | 462 } |
461 | 463 |
462 DEFUN ("point-max", Fpoint_max, 0, 1, 0, /* | 464 DEFUN ("point-max", Fpoint_max, 0, 1, 0, /* |
463 Return the maximum permissible value of point in BUFFER. | 465 Return the maximum permissible value of point in BUFFER. |
464 This is (1+ (buffer-size)), unless narrowing (a buffer restriction) | 466 This is (1+ (buffer-size)), unless narrowing (a buffer restriction) |
465 is in effect, in which case it may be less. | 467 is in effect, in which case it is less. |
466 If BUFFER is nil, the current buffer is assumed. | 468 If BUFFER is nil, the current buffer is assumed. |
467 */ | 469 */ |
468 (buffer)) | 470 (buffer)) |
469 { | 471 { |
470 struct buffer *b = decode_buffer (buffer, 1); | 472 struct buffer *b = decode_buffer (buffer, 1); |
471 return make_int (BUF_ZV (b)); | 473 return make_int (BUF_ZV (b)); |
472 } | 474 } |
473 | 475 |
474 DEFUN ("point-max-marker", Fpoint_max_marker, 0, 1, 0, /* | 476 DEFUN ("point-max-marker", Fpoint_max_marker, 0, 1, 0, /* |
475 Return a marker to the maximum permissible value of point in BUFFER. | 477 Return a marker to the maximum permissible value of point BUFFER. |
476 This is (1+ (buffer-size)), unless narrowing (a buffer restriction) | 478 This is (1+ (buffer-size)), unless narrowing (a buffer restriction) |
477 is in effect, in which case it may be less. | 479 is in effect, in which case it is less. |
478 If BUFFER is nil, the current buffer is assumed. | 480 If BUFFER is nil, the current buffer is assumed. |
479 */ | 481 */ |
480 (buffer)) | 482 (buffer)) |
481 { | 483 { |
482 struct buffer *b = decode_buffer (buffer, 1); | 484 struct buffer *b = decode_buffer (buffer, 1); |
561 return (BUF_PT (b) == BUF_ZV (b) || BUF_FETCH_CHAR (b, BUF_PT (b)) == '\n') | 563 return (BUF_PT (b) == BUF_ZV (b) || BUF_FETCH_CHAR (b, BUF_PT (b)) == '\n') |
562 ? Qt : Qnil; | 564 ? Qt : Qnil; |
563 } | 565 } |
564 | 566 |
565 DEFUN ("char-after", Fchar_after, 0, 2, 0, /* | 567 DEFUN ("char-after", Fchar_after, 0, 2, 0, /* |
566 Return the character at position POS in BUFFER. | 568 Return character in BUFFER at position POS. |
567 POS is an integer or a marker. | 569 POS is an integer or a buffer pointer. |
568 If POS is out of range, the value is nil. | 570 If POS is out of range, the value is nil. |
571 If BUFFER is nil, the current buffer is assumed. | |
569 if POS is nil, the value of point is assumed. | 572 if POS is nil, the value of point is assumed. |
570 If BUFFER is nil, the current buffer is assumed. | |
571 */ | 573 */ |
572 (pos, buffer)) | 574 (pos, buffer)) |
573 { | 575 { |
574 struct buffer *b = decode_buffer (buffer, 1); | 576 struct buffer *b = decode_buffer (buffer, 1); |
575 Bufpos n = (NILP (pos) ? BUF_PT (b) : | 577 Bufpos n = (NILP (pos) ? BUF_PT (b) : |
579 return Qnil; | 581 return Qnil; |
580 return make_char (BUF_FETCH_CHAR (b, n)); | 582 return make_char (BUF_FETCH_CHAR (b, n)); |
581 } | 583 } |
582 | 584 |
583 DEFUN ("char-before", Fchar_before, 0, 2, 0, /* | 585 DEFUN ("char-before", Fchar_before, 0, 2, 0, /* |
584 Return the character preceding position POS in BUFFER. | 586 Return character in BUFFER before position POS. |
585 POS is an integer or a marker. | 587 POS is an integer or a buffer pointer. |
586 If POS is out of range, the value is nil. | 588 If POS is out of range, the value is nil. |
589 If BUFFER is nil, the current buffer is assumed. | |
587 if POS is nil, the value of point is assumed. | 590 if POS is nil, the value of point is assumed. |
588 If BUFFER is nil, the current buffer is assumed. | |
589 */ | 591 */ |
590 (pos, buffer)) | 592 (pos, buffer)) |
591 { | 593 { |
592 struct buffer *b = decode_buffer (buffer, 1); | 594 struct buffer *b = decode_buffer (buffer, 1); |
593 Bufpos n = (NILP (pos) ? BUF_PT (b) : | 595 Bufpos n = ((NILP (pos) ? BUF_PT (b) : |
594 get_buffer_pos_char (b, pos, GB_NO_ERROR_IF_BAD)); | 596 get_buffer_pos_char (b, pos, GB_NO_ERROR_IF_BAD))); |
595 | 597 |
596 n--; | 598 n--; |
597 | 599 |
598 if (n < BUF_BEGV (b)) | 600 if (n < BUF_BEGV (b)) |
599 return Qnil; | 601 return Qnil; |
601 } | 603 } |
602 | 604 |
603 | 605 |
604 DEFUN ("temp-directory", Ftemp_directory, 0, 0, 0, /* | 606 DEFUN ("temp-directory", Ftemp_directory, 0, 0, 0, /* |
605 Return the pathname to the directory to use for temporary files. | 607 Return the pathname to the directory to use for temporary files. |
606 On MS Windows, this is obtained from the TEMP or TMP environment variables, | 608 On NT/MSDOS, this is obtained from the TEMP or TMP environment variables, |
607 defaulting to / if they are both undefined. | 609 defaulting to / if they are both undefined. |
608 On Unix it is obtained from TMPDIR, with /tmp as the default | 610 On Unix it is obtained from TMPDIR, with /tmp as the default |
609 */ | 611 */ |
610 ()) | 612 ()) |
611 { | 613 { |
612 char *tmpdir; | 614 char *tmpdir; |
613 #if defined(WIN32_NATIVE) | 615 #if defined(WINDOWSNT) || defined(MSDOS) |
614 tmpdir = getenv ("TEMP"); | 616 tmpdir = getenv ("TEMP"); |
615 if (!tmpdir) | 617 if (!tmpdir) |
616 tmpdir = getenv ("TMP"); | 618 tmpdir = getenv ("TMP"); |
617 if (!tmpdir) | 619 if (!tmpdir) |
618 tmpdir = "/"; | 620 tmpdir = "/"; |
619 #else /* WIN32_NATIVE */ | 621 #else /* WINDOWSNT || MSDOS */ |
620 tmpdir = getenv ("TMPDIR"); | 622 tmpdir = getenv ("TMPDIR"); |
621 if (!tmpdir) | 623 if (!tmpdir) |
622 tmpdir = "/tmp"; | 624 tmpdir = "/tmp"; |
623 #endif | 625 #endif |
624 | 626 |
625 return build_ext_string (tmpdir, Qfile_name); | 627 return build_ext_string (tmpdir, FORMAT_FILENAME); |
626 } | 628 } |
627 | 629 |
628 DEFUN ("user-login-name", Fuser_login_name, 0, 1, 0, /* | 630 DEFUN ("user-login-name", Fuser_login_name, 0, 1, 0, /* |
629 Return the name under which the user logged in, as a string. | 631 Return the name under which the user logged in, as a string. |
630 This is based on the effective uid, not the real uid. | 632 This is based on the effective uid, not the real uid. |
634 ignored and this function returns the login name for that UID, or nil. | 636 ignored and this function returns the login name for that UID, or nil. |
635 */ | 637 */ |
636 (uid)) | 638 (uid)) |
637 { | 639 { |
638 char *returned_name; | 640 char *returned_name; |
639 uid_t local_uid; | 641 int local_uid; |
640 | 642 |
641 if (!NILP (uid)) | 643 if (!NILP (uid)) |
642 { | 644 { |
643 CHECK_INT (uid); | 645 CHECK_INT (uid); |
644 local_uid = XINT (uid); | 646 local_uid = XINT(uid); |
645 returned_name = user_login_name (&local_uid); | 647 returned_name = user_login_name(&local_uid); |
646 } | 648 } |
647 else | 649 else |
648 { | 650 { |
649 returned_name = user_login_name (NULL); | 651 returned_name = user_login_name(NULL); |
650 } | 652 } |
651 /* #### - I believe this should return nil instead of "unknown" when pw==0 | 653 /* #### - I believe this should return nil instead of "unknown" when pw==0 |
652 pw=0 is indicated by a null return from user_login_name | 654 pw=0 is indicated by a null return from user_login_name |
653 */ | 655 */ |
654 return returned_name ? build_string (returned_name) : Qnil; | 656 return returned_name ? build_string (returned_name) : Qnil; |
660 reference. If UID == NULL, then the USER name | 662 reference. If UID == NULL, then the USER name |
661 for the user running XEmacs will be returned. This | 663 for the user running XEmacs will be returned. This |
662 corresponds to a nil argument to Fuser_login_name. | 664 corresponds to a nil argument to Fuser_login_name. |
663 */ | 665 */ |
664 char* | 666 char* |
665 user_login_name (uid_t *uid) | 667 user_login_name (int *uid) |
666 { | 668 { |
669 struct passwd *pw = NULL; | |
670 | |
667 /* uid == NULL to return name of this user */ | 671 /* uid == NULL to return name of this user */ |
668 if (uid != NULL) | 672 if (uid != NULL) |
669 { | 673 { |
670 struct passwd *pw = getpwuid (*uid); | 674 pw = getpwuid (*uid); |
671 return pw ? pw->pw_name : NULL; | 675 return pw ? pw->pw_name : NULL; |
672 } | 676 } |
673 else | 677 else |
674 { | 678 { |
675 /* #### - when euid != uid, then LOGNAME and USER are leftovers from the | 679 /* #### - when euid != uid, then LOGNAME and USER are leftovers from the |
676 old environment (I site observed behavior on sunos and linux), so the | 680 old environment (I site observed behavior on sunos and linux), so the |
677 environment variables should be disregarded in that case. --Stig */ | 681 environment variables should be disregarded in that case. --Stig */ |
678 char *user_name = getenv ("LOGNAME"); | 682 char *user_name = getenv ("LOGNAME"); |
679 if (!user_name) | 683 if (!user_name) |
680 user_name = getenv ( | 684 user_name = getenv ( |
681 #ifdef WIN32_NATIVE | 685 #ifdef WINDOWSNT |
682 "USERNAME" /* it's USERNAME on NT */ | 686 "USERNAME" /* it's USERNAME on NT */ |
683 #else | 687 #else |
684 "USER" | 688 "USER" |
685 #endif | 689 #endif |
686 ); | 690 ); |
687 if (user_name) | 691 if (user_name) |
688 return (user_name); | 692 return (user_name); |
689 else | 693 else |
690 { | 694 { |
691 struct passwd *pw = getpwuid (geteuid ()); | 695 pw = getpwuid (geteuid ()); |
692 #ifdef CYGWIN | 696 #ifdef __CYGWIN32__ |
693 /* Since the Cygwin environment may not have an /etc/passwd, | 697 /* Since the Cygwin environment may not have an /etc/passwd, |
694 return "unknown" instead of the null if the username | 698 return "unknown" instead of the null if the username |
695 cannot be determined. | 699 cannot be determined. |
696 */ | 700 */ |
697 return pw ? pw->pw_name : "unknown"; | 701 return pw ? pw->pw_name : "unknown"; |
711 ()) | 715 ()) |
712 { | 716 { |
713 struct passwd *pw = getpwuid (getuid ()); | 717 struct passwd *pw = getpwuid (getuid ()); |
714 /* #### - I believe this should return nil instead of "unknown" when pw==0 */ | 718 /* #### - I believe this should return nil instead of "unknown" when pw==0 */ |
715 | 719 |
720 #ifdef MSDOS | |
721 /* We let the real user name default to "root" because that's quite | |
722 accurate on MSDOG and because it lets Emacs find the init file. | |
723 (The DVX libraries override the Djgpp libraries here.) */ | |
724 Lisp_Object tem = build_string (pw ? pw->pw_name : "root");/* no gettext */ | |
725 #else | |
716 Lisp_Object tem = build_string (pw ? pw->pw_name : "unknown");/* no gettext */ | 726 Lisp_Object tem = build_string (pw ? pw->pw_name : "unknown");/* no gettext */ |
727 #endif | |
717 return tem; | 728 return tem; |
718 } | 729 } |
719 | 730 |
720 DEFUN ("user-uid", Fuser_uid, 0, 0, 0, /* | 731 DEFUN ("user-uid", Fuser_uid, 0, 0, 0, /* |
721 Return the effective uid of Emacs, as an integer. | 732 Return the effective uid of Emacs, as an integer. |
752 return Vuser_full_name; | 763 return Vuser_full_name; |
753 | 764 |
754 user_name = (STRINGP (user) ? user : Fuser_login_name (user)); | 765 user_name = (STRINGP (user) ? user : Fuser_login_name (user)); |
755 if (!NILP (user_name)) /* nil when nonexistent UID passed as arg */ | 766 if (!NILP (user_name)) /* nil when nonexistent UID passed as arg */ |
756 { | 767 { |
757 const char *user_name_ext; | 768 CONST char *user_name_ext; |
758 | 769 |
759 /* Fuck me. getpwnam() can call select() and (under IRIX at least) | 770 /* Fuck me. getpwnam() can call select() and (under IRIX at least) |
760 things get wedged if a SIGIO arrives during this time. */ | 771 things get wedged if a SIGIO arrives during this time. */ |
761 TO_EXTERNAL_FORMAT (LISP_STRING, user_name, | 772 GET_C_STRING_OS_DATA_ALLOCA (user_name, user_name_ext); |
762 C_STRING_ALLOCA, user_name_ext, | |
763 Qnative); | |
764 slow_down_interrupts (); | 773 slow_down_interrupts (); |
765 pw = (struct passwd *) getpwnam (user_name_ext); | 774 pw = (struct passwd *) getpwnam (user_name_ext); |
766 speed_up_interrupts (); | 775 speed_up_interrupts (); |
767 } | 776 } |
768 | 777 |
769 /* #### - Stig sez: this should return nil instead of "unknown" when pw==0 */ | 778 /* #### - Stig sez: this should return nil instead of "unknown" when pw==0 */ |
770 /* Ben sez: bad idea because it's likely to break something */ | 779 /* Ben sez: bad idea because it's likely to break something */ |
771 #ifndef AMPERSAND_FULL_NAME | 780 #ifndef AMPERSAND_FULL_NAME |
772 p = pw ? USER_FULL_NAME : "unknown"; /* don't gettext */ | 781 p = ((pw) ? USER_FULL_NAME : "unknown"); /* don't gettext */ |
773 q = strchr (p, ','); | 782 q = strchr (p, ','); |
774 #else | 783 #else |
775 p = pw ? USER_FULL_NAME : "unknown"; /* don't gettext */ | 784 p = ((pw) ? USER_FULL_NAME : "unknown"); /* don't gettext */ |
776 q = strchr (p, ','); | 785 q = strchr (p, ','); |
777 #endif | 786 #endif |
778 tem = ((!NILP (user) && !pw) | 787 tem = ((!NILP (user) && !pw) |
779 ? Qnil | 788 ? Qnil |
780 : make_ext_string ((Extbyte *) p, (q ? q - p : strlen (p)), | 789 : make_ext_string ((Extbyte *) p, (q ? q - p : strlen (p)), |
781 Qnative)); | 790 FORMAT_OS)); |
782 | 791 |
783 #ifdef AMPERSAND_FULL_NAME | 792 #ifdef AMPERSAND_FULL_NAME |
784 if (!NILP (tem)) | 793 if (!NILP (tem)) |
785 { | 794 { |
786 p = (char *) XSTRING_DATA (tem); | 795 p = (char *) XSTRING_DATA (tem); |
801 #endif /* AMPERSAND_FULL_NAME */ | 810 #endif /* AMPERSAND_FULL_NAME */ |
802 | 811 |
803 return tem; | 812 return tem; |
804 } | 813 } |
805 | 814 |
806 static Extbyte *cached_home_directory; | 815 static char *cached_home_directory; |
807 | 816 |
808 void | 817 void |
809 uncache_home_directory (void) | 818 uncache_home_directory (void) |
810 { | 819 { |
811 cached_home_directory = NULL; /* in some cases, this may cause the leaking | 820 cached_home_directory = NULL; /* in some cases, this may cause the leaking |
812 of a few bytes */ | 821 of a few bytes */ |
813 } | 822 } |
814 | 823 |
815 /* !!#### not Mule correct. */ | |
816 | |
817 /* Returns the home directory, in external format */ | 824 /* Returns the home directory, in external format */ |
818 Extbyte * | 825 char * |
819 get_home_directory (void) | 826 get_home_directory (void) |
820 { | 827 { |
821 /* !!#### this is hopelessly bogus. Rule #1: Do not make any assumptions | |
822 about what format an external string is in. Could be Unicode, for all | |
823 we know, and then all the operations below are totally bogus. | |
824 Instead, convert all data to internal format *right* at the juncture | |
825 between XEmacs and the outside world, the very moment we first get | |
826 the data. --ben */ | |
827 int output_home_warning = 0; | 828 int output_home_warning = 0; |
828 | 829 |
829 if (cached_home_directory == NULL) | 830 if (cached_home_directory == NULL) |
830 { | 831 { |
831 if ((cached_home_directory = (Extbyte *) getenv("HOME")) == NULL) | 832 if ((cached_home_directory = getenv("HOME")) == NULL) |
832 { | 833 { |
833 #if defined(WIN32_NATIVE) | 834 #if defined(WINDOWSNT) && !defined(__CYGWIN32__) |
834 char *homedrive, *homepath; | 835 char *homedrive, *homepath; |
835 | 836 |
836 if ((homedrive = getenv("HOMEDRIVE")) != NULL && | 837 if ((homedrive = getenv("HOMEDRIVE")) != NULL && |
837 (homepath = getenv("HOMEPATH")) != NULL) | 838 (homepath = getenv("HOMEPATH")) != NULL) |
838 { | 839 { |
839 cached_home_directory = | 840 cached_home_directory = |
840 (Extbyte *) xmalloc (strlen (homedrive) + | 841 (char *) xmalloc(strlen(homedrive) + strlen(homepath) + 1); |
841 strlen (homepath) + 1); | 842 sprintf(cached_home_directory, "%s%s", homedrive, homepath); |
842 sprintf((char *) cached_home_directory, "%s%s", | |
843 homedrive, | |
844 homepath); | |
845 } | 843 } |
846 else | 844 else |
847 { | 845 { |
848 # if 0 /* changed by ben. This behavior absolutely stinks, and the | 846 # if 1 |
849 possibility being addressed here occurs quite commonly. | |
850 Using the current directory makes absolutely no sense. */ | |
851 /* | 847 /* |
852 * Use the current directory. | 848 * Use the current directory. |
853 * This preserves the existing XEmacs behavior, but is different | 849 * This preserves the existing XEmacs behavior, but is different |
854 * from NT Emacs. | 850 * from NT Emacs. |
855 */ | 851 */ |
856 if (initial_directory[0] != '\0') | 852 if (initial_directory[0] != '\0') |
857 { | 853 { |
858 cached_home_directory = (Extbyte*) initial_directory; | 854 cached_home_directory = initial_directory; |
859 } | 855 } |
860 else | 856 else |
861 { | 857 { |
862 /* This will probably give the wrong value */ | 858 /* This will probably give the wrong value */ |
863 cached_home_directory = (Extbyte*) getcwd (NULL, 0); | 859 cached_home_directory = getcwd (NULL, 0); |
864 } | 860 } |
865 # else | 861 # else |
866 /* | 862 /* |
867 * This is NT Emacs behavior | 863 * This is NT Emacs behavior |
868 */ | 864 */ |
869 cached_home_directory = (Extbyte *) "C:\\"; | 865 cached_home_directory = "C:\\"; |
870 output_home_warning = 1; | 866 output_home_warning = 1; |
871 # endif | 867 # endif |
872 } | 868 } |
873 #else /* !WIN32_NATIVE */ | 869 #else /* !WINDOWSNT */ |
874 /* | 870 /* |
875 * Unix, typically. | 871 * Unix, typically. |
876 * Using "/" isn't quite right, but what should we do? | 872 * Using "/" isn't quite right, but what should we do? |
877 * We probably should try to extract pw_dir from /etc/passwd, | 873 * We probably should try to extract pw_dir from /etc/passwd, |
878 * before falling back to this. | 874 * before falling back to this. |
879 */ | 875 */ |
880 cached_home_directory = (Extbyte *) "/"; | 876 cached_home_directory = "/"; |
881 output_home_warning = 1; | 877 output_home_warning = 1; |
882 #endif /* !WIN32_NATIVE */ | 878 #endif /* !WINDOWSNT */ |
883 } | 879 } |
884 if (initialized && output_home_warning) | 880 if (initialized && output_home_warning) |
885 { | 881 { |
886 warn_when_safe (Quser_files_and_directories, Qwarning, "\n" | 882 warn_when_safe (Quser_files_and_directories, Qwarning, "\n" |
887 " XEmacs was unable to determine a good value for the user's $HOME\n" | 883 " XEmacs was unable to determine a good value for the user's $HOME\n" |
898 DEFUN ("user-home-directory", Fuser_home_directory, 0, 0, 0, /* | 894 DEFUN ("user-home-directory", Fuser_home_directory, 0, 0, 0, /* |
899 Return the user's home directory, as a string. | 895 Return the user's home directory, as a string. |
900 */ | 896 */ |
901 ()) | 897 ()) |
902 { | 898 { |
903 Extbyte *path = get_home_directory (); | 899 char *path = get_home_directory (); |
904 | 900 |
905 return path == NULL ? Qnil : | 901 return path == NULL ? Qnil : |
906 Fexpand_file_name (Fsubstitute_in_file_name | 902 Fexpand_file_name (Fsubstitute_in_file_name |
907 (build_ext_string ((char *) path, Qfile_name)), | 903 (build_ext_string (path, FORMAT_FILENAME)), |
908 Qnil); | 904 Qnil); |
909 } | 905 } |
910 | 906 |
911 DEFUN ("system-name", Fsystem_name, 0, 0, 0, /* | 907 DEFUN ("system-name", Fsystem_name, 0, 0, 0, /* |
912 Return the name of the machine you are running on, as a string. | 908 Return the name of the machine you are running on, as a string. |
913 */ | 909 */ |
914 ()) | 910 ()) |
915 { | 911 { |
916 return Fcopy_sequence (Vsystem_name); | 912 return Fcopy_sequence (Vsystem_name); |
913 } | |
914 | |
915 /* For the benefit of callers who don't want to include lisp.h. | |
916 Caller must free! */ | |
917 char * | |
918 get_system_name (void) | |
919 { | |
920 return xstrdup ((char *) XSTRING_DATA (Vsystem_name)); | |
917 } | 921 } |
918 | 922 |
919 DEFUN ("emacs-pid", Femacs_pid, 0, 0, 0, /* | 923 DEFUN ("emacs-pid", Femacs_pid, 0, 0, 0, /* |
920 Return the process ID of Emacs, as an integer. | 924 Return the process ID of Emacs, as an integer. |
921 */ | 925 */ |
1002 { | 1006 { |
1003 unsigned int item = (unsigned int) the_time; | 1007 unsigned int item = (unsigned int) the_time; |
1004 return Fcons (make_int (item >> 16), make_int (item & 0xffff)); | 1008 return Fcons (make_int (item >> 16), make_int (item & 0xffff)); |
1005 } | 1009 } |
1006 | 1010 |
1007 size_t emacs_strftime (char *string, size_t max, const char *format, | 1011 size_t emacs_strftime (char *string, size_t max, CONST char *format, |
1008 const struct tm *tm); | 1012 CONST struct tm *tm); |
1009 static long difftm (const struct tm *a, const struct tm *b); | 1013 static long difftm (CONST struct tm *a, CONST struct tm *b); |
1010 | 1014 |
1011 | 1015 |
1012 DEFUN ("format-time-string", Fformat_time_string, 1, 2, 0, /* | 1016 DEFUN ("format-time-string", Fformat_time_string, 1, 2, 0, /* |
1013 Use FORMAT-STRING to format the time TIME. | 1017 Use FORMAT-STRING to format the time TIME. |
1014 TIME is specified as (HIGH LOW . IGNORED) or (HIGH . LOW), as from | 1018 TIME is specified as (HIGH LOW . IGNORED) or (HIGH . LOW), as from |
1034 %M is replaced by the minute (00-59). | 1038 %M is replaced by the minute (00-59). |
1035 %n is a synonym for "\\n". | 1039 %n is a synonym for "\\n". |
1036 %p is replaced by AM or PM, as appropriate. | 1040 %p is replaced by AM or PM, as appropriate. |
1037 %r is a synonym for "%I:%M:%S %p". | 1041 %r is a synonym for "%I:%M:%S %p". |
1038 %R is a synonym for "%H:%M". | 1042 %R is a synonym for "%H:%M". |
1039 %s is replaced by the time in seconds since 00:00:00, Jan 1, 1970 (a | |
1040 nonstandard extension) | |
1041 %S is replaced by the second (00-60). | 1043 %S is replaced by the second (00-60). |
1042 %t is a synonym for "\\t". | 1044 %t is a synonym for "\\t". |
1043 %T is a synonym for "%H:%M:%S". | 1045 %T is a synonym for "%H:%M:%S". |
1044 %U is replaced by the week of the year (00-53), first day of week is Sunday. | 1046 %U is replaced by the week of the year (00-53), first day of week is Sunday. |
1045 %w is replaced by the day of week (0-6), Sunday is day 0. | 1047 %w is replaced by the day of week (0-6), Sunday is day 0. |
1071 while (1) | 1073 while (1) |
1072 { | 1074 { |
1073 char *buf = (char *) alloca (size); | 1075 char *buf = (char *) alloca (size); |
1074 *buf = 1; | 1076 *buf = 1; |
1075 if (emacs_strftime (buf, size, | 1077 if (emacs_strftime (buf, size, |
1076 (const char *) XSTRING_DATA (format_string), | 1078 (CONST char *) XSTRING_DATA (format_string), |
1077 localtime (&value)) | 1079 localtime (&value)) |
1078 || !*buf) | 1080 || !*buf) |
1079 return build_ext_string (buf, Qbinary); | 1081 return build_ext_string (buf, FORMAT_BINARY); |
1080 /* If buffer was too small, make it bigger. */ | 1082 /* If buffer was too small, make it bigger. */ |
1081 size *= 2; | 1083 size *= 2; |
1082 } | 1084 } |
1083 } | 1085 } |
1084 | 1086 |
1228 tem = (char *) ctime (&value); | 1230 tem = (char *) ctime (&value); |
1229 | 1231 |
1230 strncpy (buf, tem, 24); | 1232 strncpy (buf, tem, 24); |
1231 buf[24] = 0; | 1233 buf[24] = 0; |
1232 | 1234 |
1233 return build_ext_string (buf, Qbinary); | 1235 return build_ext_string (buf, FORMAT_BINARY); |
1234 } | 1236 } |
1235 | 1237 |
1236 #define TM_YEAR_ORIGIN 1900 | 1238 #define TM_YEAR_ORIGIN 1900 |
1237 | 1239 |
1238 /* Yield A - B, measured in seconds. */ | 1240 /* Yield A - B, measured in seconds. */ |
1239 static long | 1241 static long |
1240 difftm (const struct tm *a, const struct tm *b) | 1242 difftm (CONST struct tm *a, CONST struct tm *b) |
1241 { | 1243 { |
1242 int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); | 1244 int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); |
1243 int by = b->tm_year + (TM_YEAR_ORIGIN - 1); | 1245 int by = b->tm_year + (TM_YEAR_ORIGIN - 1); |
1244 /* Some compilers can't handle this as a single return statement. */ | 1246 /* Some compilers can't handle this as a single return statement. */ |
1245 long days = ( | 1247 long days = ( |
1822 | 1824 |
1823 get_buffer_range_char (buf, start, end, &pos, &stop, 0); | 1825 get_buffer_range_char (buf, start, end, &pos, &stop, 0); |
1824 mc_count = begin_multiple_change (buf, pos, stop); | 1826 mc_count = begin_multiple_change (buf, pos, stop); |
1825 if (STRINGP (table)) | 1827 if (STRINGP (table)) |
1826 { | 1828 { |
1827 Lisp_String *stable = XSTRING (table); | 1829 struct Lisp_String *stable = XSTRING (table); |
1828 Charcount size = string_char_length (stable); | 1830 Charcount size = string_char_length (stable); |
1829 #ifdef MULE | 1831 #ifdef MULE |
1830 /* Under Mule, string_char(n) is O(n), so for large tables or | 1832 /* Under Mule, string_char(n) is O(n), so for large tables or |
1831 large regions it makes sense to create an array of Emchars. */ | 1833 large regions it makes sense to create an array of Emchars. */ |
1832 if (size * (stop - pos) > 65536) | 1834 if (size * (stop - pos) > 65536) |
1902 } | 1904 } |
1903 else if (CHAR_TABLEP (table) | 1905 else if (CHAR_TABLEP (table) |
1904 && (XCHAR_TABLE_TYPE (table) == CHAR_TABLE_TYPE_GENERIC | 1906 && (XCHAR_TABLE_TYPE (table) == CHAR_TABLE_TYPE_GENERIC |
1905 || XCHAR_TABLE_TYPE (table) == CHAR_TABLE_TYPE_CHAR)) | 1907 || XCHAR_TABLE_TYPE (table) == CHAR_TABLE_TYPE_CHAR)) |
1906 { | 1908 { |
1907 Lisp_Char_Table *ctable = XCHAR_TABLE (table); | 1909 struct Lisp_Char_Table *ctable = XCHAR_TABLE (table); |
1908 | 1910 |
1909 for (; pos < stop && (oc = BUF_FETCH_CHAR (buf, pos), 1); pos++) | 1911 for (; pos < stop && (oc = BUF_FETCH_CHAR (buf, pos), 1); pos++) |
1910 { | 1912 { |
1911 Lisp_Object replacement = get_char_table (oc, ctable); | 1913 Lisp_Object replacement = get_char_table (oc, ctable); |
1912 retry2: | 1914 retry2: |
2236 ? DOWNCASE (b, x1) == DOWNCASE (b, x2) | 2238 ? DOWNCASE (b, x1) == DOWNCASE (b, x2) |
2237 : x1 == x2) | 2239 : x1 == x2) |
2238 ? Qt : Qnil; | 2240 ? Qt : Qnil; |
2239 } | 2241 } |
2240 | 2242 |
2241 DEFUN ("char=", Fchar_Equal, 2, 2, 0, /* | 2243 DEFUN ("char=", Fchar_Equal, 2, 3, 0, /* |
2242 Return t if two characters match, case is significant. | 2244 Return t if two characters match, case is significant. |
2243 Both arguments must be characters (i.e. NOT integers). | 2245 Both arguments must be characters (i.e. NOT integers). |
2244 */ | 2246 The optional buffer argument is for symmetry and is ignored. |
2245 (c1, c2)) | 2247 */ |
2248 (c1, c2, buffer)) | |
2246 { | 2249 { |
2247 CHECK_CHAR_COERCE_INT (c1); | 2250 CHECK_CHAR_COERCE_INT (c1); |
2248 CHECK_CHAR_COERCE_INT (c2); | 2251 CHECK_CHAR_COERCE_INT (c2); |
2249 | 2252 |
2250 return EQ (c1, c2) ? Qt : Qnil; | 2253 return XCHAR(c1) == XCHAR(c2) ? Qt : Qnil; |
2251 } | 2254 } |
2252 | 2255 |
2253 #if 0 /* Undebugged FSFmacs code */ | 2256 #if 0 /* Undebugged FSFmacs code */ |
2254 /* Transpose the markers in two regions of the current buffer, and | 2257 /* Transpose the markers in two regions of the current buffer, and |
2255 adjust the ones between them if necessary (i.e.: if the regions | 2258 adjust the ones between them if necessary (i.e.: if the regions |