diff 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
line wrap: on
line diff
--- a/src/editfns.c	Mon Aug 13 11:19:22 2007 +0200
+++ b/src/editfns.c	Mon Aug 13 11:20:41 2007 +0200
@@ -28,6 +28,9 @@
 
 #include <config.h>
 #include "lisp.h"
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
 
 #include "buffer.h"
 #include "commands.h"
@@ -42,7 +45,6 @@
 #include "systime.h"
 #include "sysdep.h"
 #include "syspwd.h"
-#include "sysfile.h"			/* for getcwd */
 
 /* Some static data, and a function to initialize it for each run */
 
@@ -63,6 +65,8 @@
 Lisp_Object Vuser_full_name;
 EXFUN (Fuser_full_name, 1);
 
+char *get_system_name (void);
+
 Lisp_Object Qformat;
 
 Lisp_Object Qpoint, Qmark, Qregion_beginning, Qregion_end;
@@ -93,7 +97,7 @@
   if ((p = getenv ("NAME")))
     /* I don't think it's the right thing to do the ampersand
        modification on NAME.  Not that it matters anymore...  -hniksic */
-    Vuser_full_name = build_ext_string (p, Qnative);
+    Vuser_full_name = build_ext_string (p, FORMAT_OS);
   else
     Vuser_full_name = Fuser_full_name (Qnil);
 }
@@ -128,7 +132,7 @@
 */
        (str))
 {
-  Lisp_String *p;
+  struct Lisp_String *p;
   CHECK_STRING (str);
 
   p = XSTRING (str);
@@ -437,8 +441,7 @@
 
 DEFUN ("point-min", Fpoint_min, 0, 1, 0, /*
 Return the minimum permissible value of point in BUFFER.
-This is 1, unless narrowing (a buffer restriction)
-is in effect, in which case it may be greater.
+This is 1, unless narrowing (a buffer restriction) is in effect.
 If BUFFER is nil, the current buffer is assumed.
 */
        (buffer))
@@ -449,8 +452,7 @@
 
 DEFUN ("point-min-marker", Fpoint_min_marker, 0, 1, 0, /*
 Return a marker to the minimum permissible value of point in BUFFER.
-This is the beginning, unless narrowing (a buffer restriction)
-is in effect, in which case it may be greater.
+This is the beginning, unless narrowing (a buffer restriction) is in effect.
 If BUFFER is nil, the current buffer is assumed.
 */
        (buffer))
@@ -462,7 +464,7 @@
 DEFUN ("point-max", Fpoint_max, 0, 1, 0, /*
 Return the maximum permissible value of point in BUFFER.
 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)
-is in effect, in which case it may be less.
+is in effect, in which case it is less.
 If BUFFER is nil, the current buffer is assumed.
 */
        (buffer))
@@ -472,9 +474,9 @@
 }
 
 DEFUN ("point-max-marker", Fpoint_max_marker, 0, 1, 0, /*
-Return a marker to the maximum permissible value of point in BUFFER.
+Return a marker to the maximum permissible value of point BUFFER.
 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)
-is in effect, in which case it may be less.
+is in effect, in which case it is less.
 If BUFFER is nil, the current buffer is assumed.
 */
        (buffer))
@@ -563,11 +565,11 @@
 }
 
 DEFUN ("char-after", Fchar_after, 0, 2, 0, /*
-Return the character at position POS in BUFFER.
-POS is an integer or a marker.
+Return character in BUFFER at position POS.
+POS is an integer or a buffer pointer.
 If POS is out of range, the value is nil.
+If BUFFER is nil, the current buffer is assumed.
 if POS is nil, the value of point is assumed.
-If BUFFER is nil, the current buffer is assumed.
 */
        (pos, buffer))
 {
@@ -581,17 +583,17 @@
 }
 
 DEFUN ("char-before", Fchar_before, 0, 2, 0, /*
-Return the character preceding position POS in BUFFER.
-POS is an integer or a marker.
+Return character in BUFFER before position POS.
+POS is an integer or a buffer pointer.
 If POS is out of range, the value is nil.
+If BUFFER is nil, the current buffer is assumed.
 if POS is nil, the value of point is assumed.
-If BUFFER is nil, the current buffer is assumed.
 */
        (pos, buffer))
 {
   struct buffer *b = decode_buffer (buffer, 1);
-  Bufpos n = (NILP (pos) ? BUF_PT (b) :
-	      get_buffer_pos_char (b, pos, GB_NO_ERROR_IF_BAD));
+  Bufpos n = ((NILP (pos) ? BUF_PT (b) :
+	       get_buffer_pos_char (b, pos, GB_NO_ERROR_IF_BAD)));
 
   n--;
 
@@ -603,26 +605,26 @@
 
 DEFUN ("temp-directory", Ftemp_directory, 0, 0, 0, /*
 Return the pathname to the directory to use for temporary files.
-On MS Windows, this is obtained from the TEMP or TMP environment variables,
+On NT/MSDOS, this is obtained from the TEMP or TMP environment variables,
 defaulting to / if they are both undefined.
 On Unix it is obtained from TMPDIR, with /tmp as the default
 */
        ())
 {
   char *tmpdir;
-#if defined(WIN32_NATIVE)
+#if defined(WINDOWSNT) || defined(MSDOS)
   tmpdir = getenv ("TEMP");
   if (!tmpdir)
     tmpdir = getenv ("TMP");
   if (!tmpdir)
     tmpdir = "/";
-#else /* WIN32_NATIVE */
+#else /* WINDOWSNT || MSDOS */
  tmpdir = getenv ("TMPDIR");
  if (!tmpdir)
    tmpdir = "/tmp";
 #endif
 
-  return build_ext_string (tmpdir, Qfile_name);
+  return build_ext_string (tmpdir, FORMAT_FILENAME);
 }
 
 DEFUN ("user-login-name", Fuser_login_name, 0, 1, 0, /*
@@ -636,17 +638,17 @@
        (uid))
 {
   char *returned_name;
-  uid_t local_uid;
+  int local_uid;
 
   if (!NILP (uid))
     {
       CHECK_INT (uid);
-      local_uid = XINT (uid);
-      returned_name = user_login_name (&local_uid);
+      local_uid = XINT(uid);
+      returned_name = user_login_name(&local_uid);
     }
   else
     {
-      returned_name = user_login_name (NULL);
+      returned_name = user_login_name(NULL);
     }
   /* #### - I believe this should return nil instead of "unknown" when pw==0
      pw=0 is indicated by a null return from user_login_name
@@ -662,12 +664,14 @@
    corresponds to a nil argument to Fuser_login_name.
 */
 char*
-user_login_name (uid_t *uid)
+user_login_name (int *uid)
 {
+  struct passwd *pw = NULL;
+
   /* uid == NULL to return name of this user */
   if (uid != NULL)
     {
-      struct passwd *pw = getpwuid (*uid);
+      pw = getpwuid (*uid);
       return pw ? pw->pw_name : NULL;
     }
   else
@@ -678,7 +682,7 @@
       char *user_name = getenv ("LOGNAME");
       if (!user_name)
 	user_name = getenv (
-#ifdef WIN32_NATIVE
+#ifdef WINDOWSNT
 			    "USERNAME" /* it's USERNAME on NT */
 #else
 			    "USER"
@@ -688,8 +692,8 @@
 	return (user_name);
       else
 	{
-	  struct passwd *pw = getpwuid (geteuid ());
-#ifdef CYGWIN
+	  pw = getpwuid (geteuid ());
+#ifdef __CYGWIN32__
 	  /* Since the Cygwin environment may not have an /etc/passwd,
 	     return "unknown" instead of the null if the username
 	     cannot be determined.
@@ -713,7 +717,14 @@
   struct passwd *pw = getpwuid (getuid ());
   /* #### - I believe this should return nil instead of "unknown" when pw==0 */
 
+#ifdef MSDOS
+  /* We let the real user name default to "root" because that's quite
+     accurate on MSDOG and because it lets Emacs find the init file.
+     (The DVX libraries override the Djgpp libraries here.)  */
+  Lisp_Object tem = build_string (pw ? pw->pw_name : "root");/* no gettext */
+#else
   Lisp_Object tem = build_string (pw ? pw->pw_name : "unknown");/* no gettext */
+#endif
   return tem;
 }
 
@@ -754,13 +765,11 @@
   user_name = (STRINGP (user) ? user : Fuser_login_name (user));
   if (!NILP (user_name))	/* nil when nonexistent UID passed as arg */
     {
-      const char *user_name_ext;
+      CONST char *user_name_ext;
 
       /* Fuck me.  getpwnam() can call select() and (under IRIX at least)
 	 things get wedged if a SIGIO arrives during this time. */
-      TO_EXTERNAL_FORMAT (LISP_STRING, user_name,
-			  C_STRING_ALLOCA, user_name_ext,
-			  Qnative);
+      GET_C_STRING_OS_DATA_ALLOCA (user_name, user_name_ext);
       slow_down_interrupts ();
       pw = (struct passwd *) getpwnam (user_name_ext);
       speed_up_interrupts ();
@@ -769,16 +778,16 @@
   /* #### - Stig sez: this should return nil instead of "unknown" when pw==0 */
   /* Ben sez: bad idea because it's likely to break something */
 #ifndef AMPERSAND_FULL_NAME
-  p = pw ? USER_FULL_NAME : "unknown"; /* don't gettext */
+  p = ((pw) ? USER_FULL_NAME : "unknown"); /* don't gettext */
   q = strchr (p, ',');
 #else
-  p = pw ? USER_FULL_NAME : "unknown"; /* don't gettext */
+  p = ((pw) ? USER_FULL_NAME : "unknown"); /* don't gettext */
   q = strchr (p, ',');
 #endif
   tem = ((!NILP (user) && !pw)
 	 ? Qnil
 	 : make_ext_string ((Extbyte *) p, (q ? q - p : strlen (p)),
-			    Qnative));
+			    FORMAT_OS));
 
 #ifdef AMPERSAND_FULL_NAME
   if (!NILP (tem))
@@ -803,7 +812,7 @@
   return tem;
 }
 
-static Extbyte *cached_home_directory;
+static char *cached_home_directory;
 
 void
 uncache_home_directory (void)
@@ -812,42 +821,29 @@
 				   of a few bytes */
 }
 
-/* !!#### not Mule correct. */
-
 /* Returns the home directory, in external format */
-Extbyte *
+char *
 get_home_directory (void)
 {
-  /* !!#### this is hopelessly bogus.  Rule #1: Do not make any assumptions
-     about what format an external string is in.  Could be Unicode, for all
-     we know, and then all the operations below are totally bogus.
-     Instead, convert all data to internal format *right* at the juncture
-     between XEmacs and the outside world, the very moment we first get
-     the data.  --ben */
   int output_home_warning = 0;
 
   if (cached_home_directory == NULL)
     {
-      if ((cached_home_directory = (Extbyte *) getenv("HOME")) == NULL)
+      if ((cached_home_directory = getenv("HOME")) == NULL)
 	{
-#if defined(WIN32_NATIVE)
-	  char *homedrive, *homepath;
+#if defined(WINDOWSNT) && !defined(__CYGWIN32__)
+	  char	*homedrive, *homepath;
 
 	  if ((homedrive = getenv("HOMEDRIVE")) != NULL &&
 	      (homepath = getenv("HOMEPATH")) != NULL)
 	    {
 	      cached_home_directory =
-		(Extbyte *) xmalloc (strlen (homedrive) +
-				     strlen (homepath) + 1);
-	      sprintf((char *) cached_home_directory, "%s%s",
-		      homedrive,
-		      homepath);
+		(char *) xmalloc(strlen(homedrive) + strlen(homepath) + 1);
+	      sprintf(cached_home_directory, "%s%s", homedrive, homepath);
 	    }
 	  else
 	    {
-# if 0 /* changed by ben.  This behavior absolutely stinks, and the
-	  possibility being addressed here occurs quite commonly.
-	  Using the current directory makes absolutely no sense. */
+# if 1
 	      /*
 	       * Use the current directory.
 	       * This preserves the existing XEmacs behavior, but is different
@@ -855,31 +851,31 @@
 	       */
 	      if (initial_directory[0] != '\0')
 		{
-		  cached_home_directory = (Extbyte*) initial_directory;
+		  cached_home_directory = initial_directory;
 		}
 	      else
 		{
 		  /* This will probably give the wrong value */
-		  cached_home_directory = (Extbyte*) getcwd (NULL, 0);
+		  cached_home_directory = getcwd (NULL, 0);
 		}
 # else
 	      /*
 	       * This is NT Emacs behavior
 	       */
-	      cached_home_directory = (Extbyte *) "C:\\";
+	      cached_home_directory = "C:\\";
 	      output_home_warning = 1;
 # endif
 	    }
-#else	/* !WIN32_NATIVE */
+#else	/* !WINDOWSNT */
 	  /*
 	   * Unix, typically.
 	   * Using "/" isn't quite right, but what should we do?
 	   * We probably should try to extract pw_dir from /etc/passwd,
 	   * before falling back to this.
 	   */
-	  cached_home_directory = (Extbyte *) "/";
+	  cached_home_directory = "/";
 	  output_home_warning = 1;
-#endif	/* !WIN32_NATIVE */
+#endif	/* !WINDOWSNT */
 	}
       if (initialized && output_home_warning)
 	{
@@ -900,11 +896,11 @@
 */
        ())
 {
-  Extbyte *path = get_home_directory ();
+  char *path = get_home_directory ();
 
   return path == NULL ? Qnil :
     Fexpand_file_name (Fsubstitute_in_file_name
-		       (build_ext_string ((char *) path, Qfile_name)),
+		       (build_ext_string (path, FORMAT_FILENAME)),
 		       Qnil);
 }
 
@@ -916,6 +912,14 @@
     return Fcopy_sequence (Vsystem_name);
 }
 
+/* For the benefit of callers who don't want to include lisp.h.
+   Caller must free! */
+char *
+get_system_name (void)
+{
+  return xstrdup ((char *) XSTRING_DATA (Vsystem_name));
+}
+
 DEFUN ("emacs-pid", Femacs_pid, 0, 0, 0, /*
 Return the process ID of Emacs, as an integer.
 */
@@ -1004,9 +1008,9 @@
   return Fcons (make_int (item >> 16), make_int (item & 0xffff));
 }
 
-size_t emacs_strftime (char *string, size_t max, const char *format,
-		       const struct tm *tm);
-static long difftm (const struct tm *a, const struct tm *b);
+size_t emacs_strftime (char *string, size_t max, CONST char *format,
+		       CONST struct tm *tm);
+static long difftm (CONST struct tm *a, CONST struct tm *b);
 
 
 DEFUN ("format-time-string", Fformat_time_string, 1, 2, 0, /*
@@ -1036,8 +1040,6 @@
 %p is replaced by AM or PM, as appropriate.
 %r is a synonym for "%I:%M:%S %p".
 %R is a synonym for "%H:%M".
-%s is replaced by the time in seconds since 00:00:00, Jan 1, 1970 (a
-      nonstandard extension)
 %S is replaced by the second (00-60).
 %t is a synonym for "\\t".
 %T is a synonym for "%H:%M:%S".
@@ -1073,10 +1075,10 @@
       char *buf = (char *) alloca (size);
       *buf = 1;
       if (emacs_strftime (buf, size,
-			  (const char *) XSTRING_DATA (format_string),
+			  (CONST char *) XSTRING_DATA (format_string),
 			  localtime (&value))
 	  || !*buf)
-	return build_ext_string (buf, Qbinary);
+	return build_ext_string (buf, FORMAT_BINARY);
       /* If buffer was too small, make it bigger.  */
       size *= 2;
     }
@@ -1230,14 +1232,14 @@
   strncpy (buf, tem, 24);
   buf[24] = 0;
 
-  return build_ext_string (buf, Qbinary);
+  return build_ext_string (buf, FORMAT_BINARY);
 }
 
 #define TM_YEAR_ORIGIN 1900
 
 /* Yield A - B, measured in seconds.  */
 static long
-difftm (const struct tm *a, const struct tm *b)
+difftm (CONST struct tm *a, CONST struct tm *b)
 {
   int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
   int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
@@ -1824,7 +1826,7 @@
   mc_count = begin_multiple_change (buf, pos, stop);
   if (STRINGP (table))
     {
-      Lisp_String *stable = XSTRING (table);
+      struct Lisp_String *stable = XSTRING (table);
       Charcount size = string_char_length (stable);
 #ifdef MULE
       /* Under Mule, string_char(n) is O(n), so for large tables or
@@ -1904,7 +1906,7 @@
 	   && (XCHAR_TABLE_TYPE (table) == CHAR_TABLE_TYPE_GENERIC
 	       || XCHAR_TABLE_TYPE (table) == CHAR_TABLE_TYPE_CHAR))
     {
-      Lisp_Char_Table *ctable = XCHAR_TABLE (table);
+      struct Lisp_Char_Table *ctable = XCHAR_TABLE (table);
 
       for (; pos < stop && (oc = BUF_FETCH_CHAR (buf, pos), 1); pos++)
 	{
@@ -2238,16 +2240,17 @@
     ? Qt : Qnil;
 }
 
-DEFUN ("char=", Fchar_Equal, 2, 2, 0, /*
+DEFUN ("char=", Fchar_Equal, 2, 3, 0, /*
 Return t if two characters match, case is significant.
 Both arguments must be characters (i.e. NOT integers).
+The optional buffer argument is for symmetry and is ignored.
 */
-       (c1, c2))
+       (c1, c2, buffer))
 {
   CHECK_CHAR_COERCE_INT (c1);
   CHECK_CHAR_COERCE_INT (c2);
 
-  return EQ (c1, c2) ? Qt : Qnil;
+  return XCHAR(c1) == XCHAR(c2) ? Qt : Qnil;
 }
 
 #if 0 /* Undebugged FSFmacs code */