Mercurial > hg > xemacs-beta
comparison src/buffer.c @ 327:03446687b7cc r21-0-61
Import from CVS: tag r21-0-61
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:48:16 +0200 |
parents | c9fe270a4101 |
children | 4f79e16b1112 |
comparison
equal
deleted
inserted
replaced
326:e2671bc7f66a | 327:03446687b7cc |
---|---|
123 buffers and as a reset-value when local-vars are killed. */ | 123 buffers and as a reset-value when local-vars are killed. */ |
124 struct buffer buffer_local_flags; | 124 struct buffer buffer_local_flags; |
125 | 125 |
126 /* This is the initial (startup) directory, as used for the *scratch* buffer. | 126 /* This is the initial (startup) directory, as used for the *scratch* buffer. |
127 We're making this a global to make others aware of the startup directory. | 127 We're making this a global to make others aware of the startup directory. |
128 `initial_directory' is stored in external format. | |
128 */ | 129 */ |
129 char initial_directory[MAXPATHLEN+1]; | 130 char initial_directory[MAXPATHLEN+1]; |
130 | 131 |
131 /* This structure holds the names of symbols whose values may be | 132 /* This structure holds the names of symbols whose values may be |
132 buffer-local. It is indexed and accessed in the same way as the above. */ | 133 buffer-local. It is indexed and accessed in the same way as the above. */ |
2745 /* Want no undo records for *scratch* until after Emacs is dumped */ | 2746 /* Want no undo records for *scratch* until after Emacs is dumped */ |
2746 Fbuffer_disable_undo (scratch); | 2747 Fbuffer_disable_undo (scratch); |
2747 } | 2748 } |
2748 } | 2749 } |
2749 | 2750 |
2751 /* Is PWD another name for `.' ? */ | |
2752 static int | |
2753 directory_is_current_directory (char *pwd) | |
2754 { | |
2755 Bufbyte *pwd_internal; | |
2756 struct stat dotstat, pwdstat; | |
2757 | |
2758 GET_C_CHARPTR_INT_FILENAME_DATA_ALLOCA (pwd, pwd_internal); | |
2759 | |
2760 return (IS_DIRECTORY_SEP (*pwd_internal) | |
2761 && stat (pwd_internal, &pwdstat) == 0 | |
2762 && stat ("." , &dotstat) == 0 | |
2763 && dotstat.st_ino == pwdstat.st_ino | |
2764 && dotstat.st_dev == pwdstat.st_dev | |
2765 && (int) strlen (pwd_internal) < MAXPATHLEN); | |
2766 } | |
2767 | |
2750 void | 2768 void |
2751 init_initial_directory (void) | 2769 init_initial_directory (void) |
2752 { | 2770 { |
2753 /* This function can GC */ | 2771 /* This function can GC */ |
2754 | 2772 |
2755 char *pwd; | 2773 char *pwd; |
2756 struct stat dotstat, pwdstat; | |
2757 int rc; | |
2758 | 2774 |
2759 initial_directory[0] = 0; | 2775 initial_directory[0] = 0; |
2760 | 2776 |
2761 /* If PWD is accurate, use it instead of calling getcwd. This is faster | 2777 /* If PWD is accurate, use it instead of calling getcwd. This is faster |
2762 when PWD is right, and may avoid a fatal error. */ | 2778 when PWD is right, and may avoid a fatal error. */ |
2763 if ((pwd = getenv ("PWD")) != 0 && IS_DIRECTORY_SEP (*pwd) | 2779 if ((pwd = getenv ("PWD")) != NULL |
2764 && stat (pwd, &pwdstat) == 0 | 2780 && directory_is_current_directory (pwd)) |
2765 && stat (".", &dotstat) == 0 | |
2766 && dotstat.st_ino == pwdstat.st_ino | |
2767 && dotstat.st_dev == pwdstat.st_dev | |
2768 && (int) strlen (pwd) < MAXPATHLEN) | |
2769 strcpy (initial_directory, pwd); | 2781 strcpy (initial_directory, pwd); |
2770 else if (getcwd (initial_directory, MAXPATHLEN) == NULL) | 2782 else if (getcwd (initial_directory, MAXPATHLEN) == NULL) |
2771 fatal ("`getcwd' failed: %s\n", strerror (errno)); | 2783 fatal ("`getcwd' failed: %s\n", strerror (errno)); |
2772 | 2784 |
2773 /* Maybe this should really use some standard subroutine | 2785 /* Make sure pwd is DIRECTORY_SEP-terminated. |
2786 Maybe this should really use some standard subroutine | |
2774 whose definition is filename syntax dependent. */ | 2787 whose definition is filename syntax dependent. */ |
2775 rc = strlen (initial_directory); | 2788 { |
2776 if (!(IS_DIRECTORY_SEP (initial_directory[rc - 1]))) | 2789 int len = strlen (initial_directory); |
2777 { | 2790 |
2778 initial_directory[rc] = DIRECTORY_SEP; | 2791 if (! IS_DIRECTORY_SEP (initial_directory[len - 1])) |
2779 initial_directory[rc + 1] = '\0'; | 2792 { |
2780 } | 2793 initial_directory[len] = DIRECTORY_SEP; |
2794 initial_directory[len + 1] = '\0'; | |
2795 } | |
2796 } | |
2797 | |
2781 /* XEmacs change: store buffer's default directory | 2798 /* XEmacs change: store buffer's default directory |
2782 using prefered (i.e. as defined at compile-time) | 2799 using prefered (i.e. as defined at compile-time) |
2783 directory separator. --marcpa */ | 2800 directory separator. --marcpa */ |
2784 #ifdef DOS_NT | 2801 #ifdef DOS_NT |
2785 #define CORRECT_DIR_SEPS(s) \ | 2802 #define CORRECT_DIR_SEPS(s) \ |
2796 { | 2813 { |
2797 /* This function can GC */ | 2814 /* This function can GC */ |
2798 | 2815 |
2799 Fset_buffer (Fget_buffer_create (QSscratch)); | 2816 Fset_buffer (Fget_buffer_create (QSscratch)); |
2800 | 2817 |
2801 current_buffer->directory = build_string (initial_directory); | 2818 current_buffer->directory = |
2819 build_ext_string (initial_directory, FORMAT_FILENAME); | |
2802 | 2820 |
2803 #if 0 /* FSFmacs */ | 2821 #if 0 /* FSFmacs */ |
2804 /* #### is this correct? */ | 2822 /* #### is this correct? */ |
2805 temp = get_minibuffer (0); | 2823 temp = get_minibuffer (0); |
2806 XBUFFER (temp)->directory = current_buffer->directory; | 2824 XBUFFER (temp)->directory = current_buffer->directory; |