Mercurial > hg > xemacs-beta
comparison src/editfns.c @ 398:74fd4e045ea6 r21-2-29
Import from CVS: tag r21-2-29
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:13:30 +0200 |
parents | 4af0ddfb7c5b |
children | a86b2b5e0111 |
comparison
equal
deleted
inserted
replaced
397:f4aeb21a5bad | 398:74fd4e045ea6 |
---|---|
43 #include "line-number.h" | 43 #include "line-number.h" |
44 | 44 |
45 #include "systime.h" | 45 #include "systime.h" |
46 #include "sysdep.h" | 46 #include "sysdep.h" |
47 #include "syspwd.h" | 47 #include "syspwd.h" |
48 #include "sysfile.h" /* for getcwd */ | |
48 | 49 |
49 /* Some static data, and a function to initialize it for each run */ | 50 /* Some static data, and a function to initialize it for each run */ |
50 | 51 |
51 Lisp_Object Vsystem_name; /* #### - I don't see why this should be */ | 52 Lisp_Object Vsystem_name; /* #### - I don't see why this should be */ |
52 /* static, either... --Stig */ | 53 /* static, either... --Stig */ |
63 /* It's useful to be able to set this as user customization, so we'll | 64 /* It's useful to be able to set this as user customization, so we'll |
64 keep it. */ | 65 keep it. */ |
65 Lisp_Object Vuser_full_name; | 66 Lisp_Object Vuser_full_name; |
66 EXFUN (Fuser_full_name, 1); | 67 EXFUN (Fuser_full_name, 1); |
67 | 68 |
68 char *get_system_name (void); | |
69 | |
70 Lisp_Object Qformat; | 69 Lisp_Object Qformat; |
71 | 70 |
72 Lisp_Object Qpoint, Qmark, Qregion_beginning, Qregion_end; | 71 Lisp_Object Qpoint, Qmark, Qregion_beginning, Qregion_end; |
73 | 72 |
74 Lisp_Object Quser_files_and_directories; | 73 Lisp_Object Quser_files_and_directories; |
95 #endif | 94 #endif |
96 | 95 |
97 if ((p = getenv ("NAME"))) | 96 if ((p = getenv ("NAME"))) |
98 /* I don't think it's the right thing to do the ampersand | 97 /* I don't think it's the right thing to do the ampersand |
99 modification on NAME. Not that it matters anymore... -hniksic */ | 98 modification on NAME. Not that it matters anymore... -hniksic */ |
100 Vuser_full_name = build_ext_string (p, FORMAT_OS); | 99 Vuser_full_name = build_ext_string (p, Qnative); |
101 else | 100 else |
102 Vuser_full_name = Fuser_full_name (Qnil); | 101 Vuser_full_name = Fuser_full_name (Qnil); |
103 } | 102 } |
104 | 103 |
105 DEFUN ("char-to-string", Fchar_to_string, 1, 1, 0, /* | 104 DEFUN ("char-to-string", Fchar_to_string, 1, 1, 0, /* |
130 Convert arg STRING to a character, the first character of that string. | 129 Convert arg STRING to a character, the first character of that string. |
131 An empty string will return the constant `nil'. | 130 An empty string will return the constant `nil'. |
132 */ | 131 */ |
133 (str)) | 132 (str)) |
134 { | 133 { |
135 struct Lisp_String *p; | 134 Lisp_String *p; |
136 CHECK_STRING (str); | 135 CHECK_STRING (str); |
137 | 136 |
138 p = XSTRING (str); | 137 p = XSTRING (str); |
139 if (string_length (p) != 0) | 138 if (string_length (p) != 0) |
140 return make_char (string_char (p, 0)); | 139 return make_char (string_char (p, 0)); |
439 return make_int (BUF_SIZE (b)); | 438 return make_int (BUF_SIZE (b)); |
440 } | 439 } |
441 | 440 |
442 DEFUN ("point-min", Fpoint_min, 0, 1, 0, /* | 441 DEFUN ("point-min", Fpoint_min, 0, 1, 0, /* |
443 Return the minimum permissible value of point in BUFFER. | 442 Return the minimum permissible value of point in BUFFER. |
444 This is 1, unless narrowing (a buffer restriction) is in effect. | 443 This is 1, unless narrowing (a buffer restriction) |
444 is in effect, in which case it may be greater. | |
445 If BUFFER is nil, the current buffer is assumed. | 445 If BUFFER is nil, the current buffer is assumed. |
446 */ | 446 */ |
447 (buffer)) | 447 (buffer)) |
448 { | 448 { |
449 struct buffer *b = decode_buffer (buffer, 1); | 449 struct buffer *b = decode_buffer (buffer, 1); |
450 return make_int (BUF_BEGV (b)); | 450 return make_int (BUF_BEGV (b)); |
451 } | 451 } |
452 | 452 |
453 DEFUN ("point-min-marker", Fpoint_min_marker, 0, 1, 0, /* | 453 DEFUN ("point-min-marker", Fpoint_min_marker, 0, 1, 0, /* |
454 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. |
455 This is the beginning, unless narrowing (a buffer restriction) is in effect. | 455 This is the beginning, unless narrowing (a buffer restriction) |
456 is in effect, in which case it may be greater. | |
456 If BUFFER is nil, the current buffer is assumed. | 457 If BUFFER is nil, the current buffer is assumed. |
457 */ | 458 */ |
458 (buffer)) | 459 (buffer)) |
459 { | 460 { |
460 struct buffer *b = decode_buffer (buffer, 1); | 461 struct buffer *b = decode_buffer (buffer, 1); |
462 } | 463 } |
463 | 464 |
464 DEFUN ("point-max", Fpoint_max, 0, 1, 0, /* | 465 DEFUN ("point-max", Fpoint_max, 0, 1, 0, /* |
465 Return the maximum permissible value of point in BUFFER. | 466 Return the maximum permissible value of point in BUFFER. |
466 This is (1+ (buffer-size)), unless narrowing (a buffer restriction) | 467 This is (1+ (buffer-size)), unless narrowing (a buffer restriction) |
467 is in effect, in which case it is less. | 468 is in effect, in which case it may be less. |
468 If BUFFER is nil, the current buffer is assumed. | 469 If BUFFER is nil, the current buffer is assumed. |
469 */ | 470 */ |
470 (buffer)) | 471 (buffer)) |
471 { | 472 { |
472 struct buffer *b = decode_buffer (buffer, 1); | 473 struct buffer *b = decode_buffer (buffer, 1); |
473 return make_int (BUF_ZV (b)); | 474 return make_int (BUF_ZV (b)); |
474 } | 475 } |
475 | 476 |
476 DEFUN ("point-max-marker", Fpoint_max_marker, 0, 1, 0, /* | 477 DEFUN ("point-max-marker", Fpoint_max_marker, 0, 1, 0, /* |
477 Return a marker to the maximum permissible value of point BUFFER. | 478 Return a marker to the maximum permissible value of point in BUFFER. |
478 This is (1+ (buffer-size)), unless narrowing (a buffer restriction) | 479 This is (1+ (buffer-size)), unless narrowing (a buffer restriction) |
479 is in effect, in which case it is less. | 480 is in effect, in which case it may be less. |
480 If BUFFER is nil, the current buffer is assumed. | 481 If BUFFER is nil, the current buffer is assumed. |
481 */ | 482 */ |
482 (buffer)) | 483 (buffer)) |
483 { | 484 { |
484 struct buffer *b = decode_buffer (buffer, 1); | 485 struct buffer *b = decode_buffer (buffer, 1); |
563 return (BUF_PT (b) == BUF_ZV (b) || BUF_FETCH_CHAR (b, BUF_PT (b)) == '\n') | 564 return (BUF_PT (b) == BUF_ZV (b) || BUF_FETCH_CHAR (b, BUF_PT (b)) == '\n') |
564 ? Qt : Qnil; | 565 ? Qt : Qnil; |
565 } | 566 } |
566 | 567 |
567 DEFUN ("char-after", Fchar_after, 0, 2, 0, /* | 568 DEFUN ("char-after", Fchar_after, 0, 2, 0, /* |
568 Return character in BUFFER at position POS. | 569 Return the character at position POS in BUFFER. |
569 POS is an integer or a buffer pointer. | 570 POS is an integer or a marker. |
570 If POS is out of range, the value is nil. | 571 If POS is out of range, the value is nil. |
572 if POS is nil, the value of point is assumed. | |
571 If BUFFER is nil, the current buffer is assumed. | 573 If BUFFER is nil, the current buffer is assumed. |
572 if POS is nil, the value of point is assumed. | |
573 */ | 574 */ |
574 (pos, buffer)) | 575 (pos, buffer)) |
575 { | 576 { |
576 struct buffer *b = decode_buffer (buffer, 1); | 577 struct buffer *b = decode_buffer (buffer, 1); |
577 Bufpos n = (NILP (pos) ? BUF_PT (b) : | 578 Bufpos n = (NILP (pos) ? BUF_PT (b) : |
581 return Qnil; | 582 return Qnil; |
582 return make_char (BUF_FETCH_CHAR (b, n)); | 583 return make_char (BUF_FETCH_CHAR (b, n)); |
583 } | 584 } |
584 | 585 |
585 DEFUN ("char-before", Fchar_before, 0, 2, 0, /* | 586 DEFUN ("char-before", Fchar_before, 0, 2, 0, /* |
586 Return character in BUFFER before position POS. | 587 Return the character preceding position POS in BUFFER. |
587 POS is an integer or a buffer pointer. | 588 POS is an integer or a marker. |
588 If POS is out of range, the value is nil. | 589 If POS is out of range, the value is nil. |
590 if POS is nil, the value of point is assumed. | |
589 If BUFFER is nil, the current buffer is assumed. | 591 If BUFFER is nil, the current buffer is assumed. |
590 if POS is nil, the value of point is assumed. | |
591 */ | 592 */ |
592 (pos, buffer)) | 593 (pos, buffer)) |
593 { | 594 { |
594 struct buffer *b = decode_buffer (buffer, 1); | 595 struct buffer *b = decode_buffer (buffer, 1); |
595 Bufpos n = ((NILP (pos) ? BUF_PT (b) : | 596 Bufpos n = (NILP (pos) ? BUF_PT (b) : |
596 get_buffer_pos_char (b, pos, GB_NO_ERROR_IF_BAD))); | 597 get_buffer_pos_char (b, pos, GB_NO_ERROR_IF_BAD)); |
597 | 598 |
598 n--; | 599 n--; |
599 | 600 |
600 if (n < BUF_BEGV (b)) | 601 if (n < BUF_BEGV (b)) |
601 return Qnil; | 602 return Qnil; |
622 tmpdir = getenv ("TMPDIR"); | 623 tmpdir = getenv ("TMPDIR"); |
623 if (!tmpdir) | 624 if (!tmpdir) |
624 tmpdir = "/tmp"; | 625 tmpdir = "/tmp"; |
625 #endif | 626 #endif |
626 | 627 |
627 return build_ext_string (tmpdir, FORMAT_FILENAME); | 628 return build_ext_string (tmpdir, Qfile_name); |
628 } | 629 } |
629 | 630 |
630 DEFUN ("user-login-name", Fuser_login_name, 0, 1, 0, /* | 631 DEFUN ("user-login-name", Fuser_login_name, 0, 1, 0, /* |
631 Return the name under which the user logged in, as a string. | 632 Return the name under which the user logged in, as a string. |
632 This is based on the effective uid, not the real uid. | 633 This is based on the effective uid, not the real uid. |
636 ignored and this function returns the login name for that UID, or nil. | 637 ignored and this function returns the login name for that UID, or nil. |
637 */ | 638 */ |
638 (uid)) | 639 (uid)) |
639 { | 640 { |
640 char *returned_name; | 641 char *returned_name; |
641 int local_uid; | 642 uid_t local_uid; |
642 | 643 |
643 if (!NILP (uid)) | 644 if (!NILP (uid)) |
644 { | 645 { |
645 CHECK_INT (uid); | 646 CHECK_INT (uid); |
646 local_uid = XINT(uid); | 647 local_uid = XINT (uid); |
647 returned_name = user_login_name(&local_uid); | 648 returned_name = user_login_name (&local_uid); |
648 } | 649 } |
649 else | 650 else |
650 { | 651 { |
651 returned_name = user_login_name(NULL); | 652 returned_name = user_login_name (NULL); |
652 } | 653 } |
653 /* #### - I believe this should return nil instead of "unknown" when pw==0 | 654 /* #### - I believe this should return nil instead of "unknown" when pw==0 |
654 pw=0 is indicated by a null return from user_login_name | 655 pw=0 is indicated by a null return from user_login_name |
655 */ | 656 */ |
656 return returned_name ? build_string (returned_name) : Qnil; | 657 return returned_name ? build_string (returned_name) : Qnil; |
662 reference. If UID == NULL, then the USER name | 663 reference. If UID == NULL, then the USER name |
663 for the user running XEmacs will be returned. This | 664 for the user running XEmacs will be returned. This |
664 corresponds to a nil argument to Fuser_login_name. | 665 corresponds to a nil argument to Fuser_login_name. |
665 */ | 666 */ |
666 char* | 667 char* |
667 user_login_name (int *uid) | 668 user_login_name (uid_t *uid) |
668 { | 669 { |
669 struct passwd *pw = NULL; | |
670 | |
671 /* uid == NULL to return name of this user */ | 670 /* uid == NULL to return name of this user */ |
672 if (uid != NULL) | 671 if (uid != NULL) |
673 { | 672 { |
674 pw = getpwuid (*uid); | 673 struct passwd *pw = getpwuid (*uid); |
675 return pw ? pw->pw_name : NULL; | 674 return pw ? pw->pw_name : NULL; |
676 } | 675 } |
677 else | 676 else |
678 { | 677 { |
679 /* #### - when euid != uid, then LOGNAME and USER are leftovers from the | 678 /* #### - when euid != uid, then LOGNAME and USER are leftovers from the |
690 ); | 689 ); |
691 if (user_name) | 690 if (user_name) |
692 return (user_name); | 691 return (user_name); |
693 else | 692 else |
694 { | 693 { |
695 pw = getpwuid (geteuid ()); | 694 struct passwd *pw = getpwuid (geteuid ()); |
696 #ifdef __CYGWIN32__ | 695 #ifdef __CYGWIN32__ |
697 /* Since the Cygwin environment may not have an /etc/passwd, | 696 /* Since the Cygwin environment may not have an /etc/passwd, |
698 return "unknown" instead of the null if the username | 697 return "unknown" instead of the null if the username |
699 cannot be determined. | 698 cannot be determined. |
700 */ | 699 */ |
763 return Vuser_full_name; | 762 return Vuser_full_name; |
764 | 763 |
765 user_name = (STRINGP (user) ? user : Fuser_login_name (user)); | 764 user_name = (STRINGP (user) ? user : Fuser_login_name (user)); |
766 if (!NILP (user_name)) /* nil when nonexistent UID passed as arg */ | 765 if (!NILP (user_name)) /* nil when nonexistent UID passed as arg */ |
767 { | 766 { |
768 CONST char *user_name_ext; | 767 const char *user_name_ext; |
769 | 768 |
770 /* Fuck me. getpwnam() can call select() and (under IRIX at least) | 769 /* Fuck me. getpwnam() can call select() and (under IRIX at least) |
771 things get wedged if a SIGIO arrives during this time. */ | 770 things get wedged if a SIGIO arrives during this time. */ |
772 GET_C_STRING_OS_DATA_ALLOCA (user_name, user_name_ext); | 771 TO_EXTERNAL_FORMAT (LISP_STRING, user_name, |
772 C_STRING_ALLOCA, user_name_ext, | |
773 Qnative); | |
773 slow_down_interrupts (); | 774 slow_down_interrupts (); |
774 pw = (struct passwd *) getpwnam (user_name_ext); | 775 pw = (struct passwd *) getpwnam (user_name_ext); |
775 speed_up_interrupts (); | 776 speed_up_interrupts (); |
776 } | 777 } |
777 | 778 |
785 q = strchr (p, ','); | 786 q = strchr (p, ','); |
786 #endif | 787 #endif |
787 tem = ((!NILP (user) && !pw) | 788 tem = ((!NILP (user) && !pw) |
788 ? Qnil | 789 ? Qnil |
789 : make_ext_string ((Extbyte *) p, (q ? q - p : strlen (p)), | 790 : make_ext_string ((Extbyte *) p, (q ? q - p : strlen (p)), |
790 FORMAT_OS)); | 791 Qnative)); |
791 | 792 |
792 #ifdef AMPERSAND_FULL_NAME | 793 #ifdef AMPERSAND_FULL_NAME |
793 if (!NILP (tem)) | 794 if (!NILP (tem)) |
794 { | 795 { |
795 p = (char *) XSTRING_DATA (tem); | 796 p = (char *) XSTRING_DATA (tem); |
810 #endif /* AMPERSAND_FULL_NAME */ | 811 #endif /* AMPERSAND_FULL_NAME */ |
811 | 812 |
812 return tem; | 813 return tem; |
813 } | 814 } |
814 | 815 |
815 static char *cached_home_directory; | 816 static Extbyte *cached_home_directory; |
816 | 817 |
817 void | 818 void |
818 uncache_home_directory (void) | 819 uncache_home_directory (void) |
819 { | 820 { |
820 cached_home_directory = NULL; /* in some cases, this may cause the leaking | 821 cached_home_directory = NULL; /* in some cases, this may cause the leaking |
821 of a few bytes */ | 822 of a few bytes */ |
822 } | 823 } |
823 | 824 |
824 /* Returns the home directory, in external format */ | 825 /* Returns the home directory, in external format */ |
825 char * | 826 Extbyte * |
826 get_home_directory (void) | 827 get_home_directory (void) |
827 { | 828 { |
828 int output_home_warning = 0; | 829 int output_home_warning = 0; |
829 | 830 |
830 if (cached_home_directory == NULL) | 831 if (cached_home_directory == NULL) |
831 { | 832 { |
832 if ((cached_home_directory = getenv("HOME")) == NULL) | 833 if ((cached_home_directory = (Extbyte *) getenv("HOME")) == NULL) |
833 { | 834 { |
834 #if defined(WINDOWSNT) && !defined(__CYGWIN32__) | 835 #if defined(WINDOWSNT) && !defined(__CYGWIN32__) |
835 char *homedrive, *homepath; | 836 char *homedrive, *homepath; |
836 | 837 |
837 if ((homedrive = getenv("HOMEDRIVE")) != NULL && | 838 if ((homedrive = getenv("HOMEDRIVE")) != NULL && |
838 (homepath = getenv("HOMEPATH")) != NULL) | 839 (homepath = getenv("HOMEPATH")) != NULL) |
839 { | 840 { |
840 cached_home_directory = | 841 cached_home_directory = |
841 (char *) xmalloc(strlen(homedrive) + strlen(homepath) + 1); | 842 (Extbyte *) xmalloc (strlen (homedrive) + |
842 sprintf(cached_home_directory, "%s%s", homedrive, homepath); | 843 strlen (homepath) + 1); |
844 sprintf((char *) cached_home_directory, "%s%s", | |
845 homedrive, | |
846 homepath); | |
843 } | 847 } |
844 else | 848 else |
845 { | 849 { |
846 # if 1 | 850 # if 1 |
847 /* | 851 /* |
860 } | 864 } |
861 # else | 865 # else |
862 /* | 866 /* |
863 * This is NT Emacs behavior | 867 * This is NT Emacs behavior |
864 */ | 868 */ |
865 cached_home_directory = "C:\\"; | 869 cached_home_directory = (Extbyte *) "C:\\"; |
866 output_home_warning = 1; | 870 output_home_warning = 1; |
867 # endif | 871 # endif |
868 } | 872 } |
869 #else /* !WINDOWSNT */ | 873 #else /* !WINDOWSNT */ |
870 /* | 874 /* |
871 * Unix, typically. | 875 * Unix, typically. |
872 * Using "/" isn't quite right, but what should we do? | 876 * Using "/" isn't quite right, but what should we do? |
873 * We probably should try to extract pw_dir from /etc/passwd, | 877 * We probably should try to extract pw_dir from /etc/passwd, |
874 * before falling back to this. | 878 * before falling back to this. |
875 */ | 879 */ |
876 cached_home_directory = "/"; | 880 cached_home_directory = (Extbyte *) "/"; |
877 output_home_warning = 1; | 881 output_home_warning = 1; |
878 #endif /* !WINDOWSNT */ | 882 #endif /* !WINDOWSNT */ |
879 } | 883 } |
880 if (initialized && output_home_warning) | 884 if (initialized && output_home_warning) |
881 { | 885 { |
894 DEFUN ("user-home-directory", Fuser_home_directory, 0, 0, 0, /* | 898 DEFUN ("user-home-directory", Fuser_home_directory, 0, 0, 0, /* |
895 Return the user's home directory, as a string. | 899 Return the user's home directory, as a string. |
896 */ | 900 */ |
897 ()) | 901 ()) |
898 { | 902 { |
899 char *path = get_home_directory (); | 903 Extbyte *path = get_home_directory (); |
900 | 904 |
901 return path == NULL ? Qnil : | 905 return path == NULL ? Qnil : |
902 Fexpand_file_name (Fsubstitute_in_file_name | 906 Fexpand_file_name (Fsubstitute_in_file_name |
903 (build_ext_string (path, FORMAT_FILENAME)), | 907 (build_ext_string ((char *) path, Qfile_name)), |
904 Qnil); | 908 Qnil); |
905 } | 909 } |
906 | 910 |
907 DEFUN ("system-name", Fsystem_name, 0, 0, 0, /* | 911 DEFUN ("system-name", Fsystem_name, 0, 0, 0, /* |
908 Return the name of the machine you are running on, as a string. | 912 Return the name of the machine you are running on, as a string. |
909 */ | 913 */ |
910 ()) | 914 ()) |
911 { | 915 { |
912 return Fcopy_sequence (Vsystem_name); | 916 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)); | |
921 } | 917 } |
922 | 918 |
923 DEFUN ("emacs-pid", Femacs_pid, 0, 0, 0, /* | 919 DEFUN ("emacs-pid", Femacs_pid, 0, 0, 0, /* |
924 Return the process ID of Emacs, as an integer. | 920 Return the process ID of Emacs, as an integer. |
925 */ | 921 */ |
1006 { | 1002 { |
1007 unsigned int item = (unsigned int) the_time; | 1003 unsigned int item = (unsigned int) the_time; |
1008 return Fcons (make_int (item >> 16), make_int (item & 0xffff)); | 1004 return Fcons (make_int (item >> 16), make_int (item & 0xffff)); |
1009 } | 1005 } |
1010 | 1006 |
1011 size_t emacs_strftime (char *string, size_t max, CONST char *format, | 1007 size_t emacs_strftime (char *string, size_t max, const char *format, |
1012 CONST struct tm *tm); | 1008 const struct tm *tm); |
1013 static long difftm (CONST struct tm *a, CONST struct tm *b); | 1009 static long difftm (const struct tm *a, const struct tm *b); |
1014 | 1010 |
1015 | 1011 |
1016 DEFUN ("format-time-string", Fformat_time_string, 1, 2, 0, /* | 1012 DEFUN ("format-time-string", Fformat_time_string, 1, 2, 0, /* |
1017 Use FORMAT-STRING to format the time TIME. | 1013 Use FORMAT-STRING to format the time TIME. |
1018 TIME is specified as (HIGH LOW . IGNORED) or (HIGH . LOW), as from | 1014 TIME is specified as (HIGH LOW . IGNORED) or (HIGH . LOW), as from |
1038 %M is replaced by the minute (00-59). | 1034 %M is replaced by the minute (00-59). |
1039 %n is a synonym for "\\n". | 1035 %n is a synonym for "\\n". |
1040 %p is replaced by AM or PM, as appropriate. | 1036 %p is replaced by AM or PM, as appropriate. |
1041 %r is a synonym for "%I:%M:%S %p". | 1037 %r is a synonym for "%I:%M:%S %p". |
1042 %R is a synonym for "%H:%M". | 1038 %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) | |
1043 %S is replaced by the second (00-60). | 1041 %S is replaced by the second (00-60). |
1044 %t is a synonym for "\\t". | 1042 %t is a synonym for "\\t". |
1045 %T is a synonym for "%H:%M:%S". | 1043 %T is a synonym for "%H:%M:%S". |
1046 %U is replaced by the week of the year (00-53), first day of week is Sunday. | 1044 %U is replaced by the week of the year (00-53), first day of week is Sunday. |
1047 %w is replaced by the day of week (0-6), Sunday is day 0. | 1045 %w is replaced by the day of week (0-6), Sunday is day 0. |
1073 while (1) | 1071 while (1) |
1074 { | 1072 { |
1075 char *buf = (char *) alloca (size); | 1073 char *buf = (char *) alloca (size); |
1076 *buf = 1; | 1074 *buf = 1; |
1077 if (emacs_strftime (buf, size, | 1075 if (emacs_strftime (buf, size, |
1078 (CONST char *) XSTRING_DATA (format_string), | 1076 (const char *) XSTRING_DATA (format_string), |
1079 localtime (&value)) | 1077 localtime (&value)) |
1080 || !*buf) | 1078 || !*buf) |
1081 return build_ext_string (buf, FORMAT_BINARY); | 1079 return build_ext_string (buf, Qbinary); |
1082 /* If buffer was too small, make it bigger. */ | 1080 /* If buffer was too small, make it bigger. */ |
1083 size *= 2; | 1081 size *= 2; |
1084 } | 1082 } |
1085 } | 1083 } |
1086 | 1084 |
1230 tem = (char *) ctime (&value); | 1228 tem = (char *) ctime (&value); |
1231 | 1229 |
1232 strncpy (buf, tem, 24); | 1230 strncpy (buf, tem, 24); |
1233 buf[24] = 0; | 1231 buf[24] = 0; |
1234 | 1232 |
1235 return build_ext_string (buf, FORMAT_BINARY); | 1233 return build_ext_string (buf, Qbinary); |
1236 } | 1234 } |
1237 | 1235 |
1238 #define TM_YEAR_ORIGIN 1900 | 1236 #define TM_YEAR_ORIGIN 1900 |
1239 | 1237 |
1240 /* Yield A - B, measured in seconds. */ | 1238 /* Yield A - B, measured in seconds. */ |
1241 static long | 1239 static long |
1242 difftm (CONST struct tm *a, CONST struct tm *b) | 1240 difftm (const struct tm *a, const struct tm *b) |
1243 { | 1241 { |
1244 int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); | 1242 int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); |
1245 int by = b->tm_year + (TM_YEAR_ORIGIN - 1); | 1243 int by = b->tm_year + (TM_YEAR_ORIGIN - 1); |
1246 /* Some compilers can't handle this as a single return statement. */ | 1244 /* Some compilers can't handle this as a single return statement. */ |
1247 long days = ( | 1245 long days = ( |
1824 | 1822 |
1825 get_buffer_range_char (buf, start, end, &pos, &stop, 0); | 1823 get_buffer_range_char (buf, start, end, &pos, &stop, 0); |
1826 mc_count = begin_multiple_change (buf, pos, stop); | 1824 mc_count = begin_multiple_change (buf, pos, stop); |
1827 if (STRINGP (table)) | 1825 if (STRINGP (table)) |
1828 { | 1826 { |
1829 struct Lisp_String *stable = XSTRING (table); | 1827 Lisp_String *stable = XSTRING (table); |
1830 Charcount size = string_char_length (stable); | 1828 Charcount size = string_char_length (stable); |
1831 #ifdef MULE | 1829 #ifdef MULE |
1832 /* Under Mule, string_char(n) is O(n), so for large tables or | 1830 /* Under Mule, string_char(n) is O(n), so for large tables or |
1833 large regions it makes sense to create an array of Emchars. */ | 1831 large regions it makes sense to create an array of Emchars. */ |
1834 if (size * (stop - pos) > 65536) | 1832 if (size * (stop - pos) > 65536) |
1904 } | 1902 } |
1905 else if (CHAR_TABLEP (table) | 1903 else if (CHAR_TABLEP (table) |
1906 && (XCHAR_TABLE_TYPE (table) == CHAR_TABLE_TYPE_GENERIC | 1904 && (XCHAR_TABLE_TYPE (table) == CHAR_TABLE_TYPE_GENERIC |
1907 || XCHAR_TABLE_TYPE (table) == CHAR_TABLE_TYPE_CHAR)) | 1905 || XCHAR_TABLE_TYPE (table) == CHAR_TABLE_TYPE_CHAR)) |
1908 { | 1906 { |
1909 struct Lisp_Char_Table *ctable = XCHAR_TABLE (table); | 1907 Lisp_Char_Table *ctable = XCHAR_TABLE (table); |
1910 | 1908 |
1911 for (; pos < stop && (oc = BUF_FETCH_CHAR (buf, pos), 1); pos++) | 1909 for (; pos < stop && (oc = BUF_FETCH_CHAR (buf, pos), 1); pos++) |
1912 { | 1910 { |
1913 Lisp_Object replacement = get_char_table (oc, ctable); | 1911 Lisp_Object replacement = get_char_table (oc, ctable); |
1914 retry2: | 1912 retry2: |
2238 ? DOWNCASE (b, x1) == DOWNCASE (b, x2) | 2236 ? DOWNCASE (b, x1) == DOWNCASE (b, x2) |
2239 : x1 == x2) | 2237 : x1 == x2) |
2240 ? Qt : Qnil; | 2238 ? Qt : Qnil; |
2241 } | 2239 } |
2242 | 2240 |
2243 DEFUN ("char=", Fchar_Equal, 2, 3, 0, /* | 2241 DEFUN ("char=", Fchar_Equal, 2, 2, 0, /* |
2244 Return t if two characters match, case is significant. | 2242 Return t if two characters match, case is significant. |
2245 Both arguments must be characters (i.e. NOT integers). | 2243 Both arguments must be characters (i.e. NOT integers). |
2246 The optional buffer argument is for symmetry and is ignored. | 2244 */ |
2247 */ | 2245 (c1, c2)) |
2248 (c1, c2, buffer)) | |
2249 { | 2246 { |
2250 CHECK_CHAR_COERCE_INT (c1); | 2247 CHECK_CHAR_COERCE_INT (c1); |
2251 CHECK_CHAR_COERCE_INT (c2); | 2248 CHECK_CHAR_COERCE_INT (c2); |
2252 | 2249 |
2253 return XCHAR(c1) == XCHAR(c2) ? Qt : Qnil; | 2250 return EQ (c1, c2) ? Qt : Qnil; |
2254 } | 2251 } |
2255 | 2252 |
2256 #if 0 /* Undebugged FSFmacs code */ | 2253 #if 0 /* Undebugged FSFmacs code */ |
2257 /* Transpose the markers in two regions of the current buffer, and | 2254 /* Transpose the markers in two regions of the current buffer, and |
2258 adjust the ones between them if necessary (i.e.: if the regions | 2255 adjust the ones between them if necessary (i.e.: if the regions |