emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/src/mac.c


From: YAMAMOTO Mitsuharu
Subject: [Emacs-diffs] Changes to emacs/src/mac.c
Date: Thu, 05 Jan 2006 08:14:12 +0000

Index: emacs/src/mac.c
diff -u emacs/src/mac.c:1.52 emacs/src/mac.c:1.53
--- emacs/src/mac.c:1.52        Sat Dec 24 02:50:11 2005
+++ emacs/src/mac.c     Thu Jan  5 08:14:12 2006
@@ -411,91 +411,73 @@
 {
   OSErr err;
 
-  if (type_code == TYPE_FILE_NAME)
+  if (type_code == typeNull)
+    err = errAECoercionFail;
+  else if (type_code == to_type || to_type == typeWildCard)
+    err = AECreateDesc (TYPE_FILE_NAME, data_ptr, data_size, result);
+  else if (type_code == TYPE_FILE_NAME)
     /* Coercion from undecoded file name.  */
-    switch (to_type)
-      {
-      case typeAlias:
-      case typeFSS:
-      case typeFSRef:
+    {
 #ifdef MAC_OSX
-      case typeFileURL:
-#endif
+      CFStringRef str;
+      CFURLRef url = NULL;
+      CFDataRef data = NULL;
+
+      str = CFStringCreateWithBytes (NULL, data_ptr, data_size,
+                                    kCFStringEncodingUTF8, false);
+      if (str)
        {
-#ifdef MAC_OSX
-         CFStringRef str;
-         CFURLRef url = NULL;
-         CFDataRef data = NULL;
-
-         str = CFStringCreateWithBytes (NULL, data_ptr, data_size,
-                                        kCFStringEncodingUTF8, false);
-         if (str)
-           {
-             url = CFURLCreateWithFileSystemPath (NULL, str,
-                                                  kCFURLPOSIXPathStyle, false);
-             CFRelease (str);
-           }
-         if (url)
-           {
-             data = CFURLCreateData (NULL, url, kCFStringEncodingUTF8, true);
-             CFRelease (url);
-           }
-         if (data)
-           {
-             err = AECoercePtr (typeFileURL, CFDataGetBytePtr (data),
-                                CFDataGetLength (data), to_type, result);
-             CFRelease (data);
-           }
-       else
-         err = memFullErr;
+         url = CFURLCreateWithFileSystemPath (NULL, str,
+                                              kCFURLPOSIXPathStyle, false);
+         CFRelease (str);
+       }
+      if (url)
+       {
+         data = CFURLCreateData (NULL, url, kCFStringEncodingUTF8, true);
+         CFRelease (url);
+       }
+      if (data)
+       {
+         err = AECoercePtr (typeFileURL, CFDataGetBytePtr (data),
+                            CFDataGetLength (data), to_type, result);
+         CFRelease (data);
+       }
+      else
+       err = memFullErr;
 #else
-         FSSpec fs;
-         char *buf;
+      FSSpec fs;
+      char *buf;
 
-         buf = xmalloc (data_size + 1);
-         if (buf)
-           {
-             memcpy (buf, data_ptr, data_size);
-             buf[data_size] = '\0';
-             err = posix_pathname_to_fsspec (buf, &fs);
-             xfree (buf);
-           }
-         else
-           err = memFullErr;
-         if (err == noErr)
-           err = AECoercePtr (typeFSS, &fs, sizeof (FSSpec),
-                              to_type, result);
-#endif
+      buf = xmalloc (data_size + 1);
+      if (buf)
+       {
+         memcpy (buf, data_ptr, data_size);
+         buf[data_size] = '\0';
+         err = posix_pathname_to_fsspec (buf, &fs);
+         xfree (buf);
        }
-       break;
-
-      case TYPE_FILE_NAME:
-      case typeWildCard:
-       err = AECreateDesc (TYPE_FILE_NAME, data_ptr, data_size, result);
-       break;
-
-      default:
-       err = errAECoercionFail;
-       break;
-      }
+      else
+       err = memFullErr;
+      if (err == noErr)
+       err = AECoercePtr (typeFSS, &fs, sizeof (FSSpec), to_type, result);
+#endif
+    }
   else if (to_type == TYPE_FILE_NAME)
     /* Coercion to undecoded file name.  */
-    switch (type_code)
-      {
-      case typeAlias:
-      case typeFSS:
-      case typeFSRef:
+    {
 #ifdef MAC_OSX
-      case typeFileURL:
-#endif
+      CFURLRef url = NULL;
+      CFStringRef str = NULL;
+      CFDataRef data = NULL;
+
+      if (type_code == typeFileURL)
+       url = CFURLCreateWithBytes (NULL, data_ptr, data_size,
+                                   kCFStringEncodingUTF8, NULL);
+      else
        {
          AEDesc desc;
-#ifdef MAC_OSX
          Size size;
          char *buf;
-         CFURLRef url = NULL;
-         CFStringRef str = NULL;
-         CFDataRef data = NULL;
 
          err = AECoercePtr (type_code, data_ptr, data_size,
                             typeFileURL, &desc);
@@ -513,33 +495,37 @@
                }
              AEDisposeDesc (&desc);
            }
-         if (url)
-           {
-             str = CFURLCopyFileSystemPath (url, kCFURLPOSIXPathStyle);
-             CFRelease (url);
-           }
-         if (str)
-           {
-             data =
-               CFStringCreateExternalRepresentation (NULL, str,
-                                                     kCFStringEncodingUTF8,
-                                                     '\0');
-             CFRelease (str);
-           }
-         if (data)
-           {
-             err = AECreateDesc (TYPE_FILE_NAME, CFDataGetBytePtr (data),
-                                 CFDataGetLength (data), result);
-             CFRelease (data);
-           }
-         else
-           err = memFullErr;
+       }
+      if (url)
+       {
+         str = CFURLCopyFileSystemPath (url, kCFURLPOSIXPathStyle);
+         CFRelease (url);
+       }
+      if (str)
+       {
+         data = CFStringCreateExternalRepresentation (NULL, str,
+                                                      kCFStringEncodingUTF8,
+                                                      '\0');
+         CFRelease (str);
+       }
+      if (data)
+       {
+         err = AECreateDesc (TYPE_FILE_NAME, CFDataGetBytePtr (data),
+                             CFDataGetLength (data), result);
+         CFRelease (data);
+       }
 #else
+      char file_name[MAXPATHLEN];
+
+      if (type_code == typeFSS && data_size == sizeof (FSSpec))
+       err = fsspec_to_posix_pathname (data_ptr, file_name,
+                                       sizeof (file_name) - 1);
+      else
+       {
+         AEDesc desc;
          FSSpec fs;
-         char file_name[MAXPATHLEN];
 
-         err = AECoercePtr (type_code, data_ptr, data_size,
-                            typeFSS, &desc);
+         err = AECoercePtr (type_code, data_ptr, data_size, typeFSS, &desc);
          if (err == noErr)
            {
 #if TARGET_API_MAC_CARBON
@@ -550,19 +536,14 @@
              if (err == noErr)
                err = fsspec_to_posix_pathname (&fs, file_name,
                                                sizeof (file_name) - 1);
-             if (err == noErr)
-               err = AECreateDesc (TYPE_FILE_NAME, file_name,
-                                   strlen (file_name), result);
              AEDisposeDesc (&desc);
            }
-#endif
        }
-       break;
-
-      default:
-       err = errAECoercionFail;
-       break;
-      }
+      if (err == noErr)
+       err = AECreateDesc (TYPE_FILE_NAME, file_name,
+                           strlen (file_name), result);
+#endif
+    }
   else
     abort ();
 
@@ -581,31 +562,9 @@
   OSErr err = noErr;
   DescType from_type = from_desc->descriptorType;
 
-  if (from_type == TYPE_FILE_NAME)
-    {
-      if (to_type != TYPE_FILE_NAME && to_type != typeWildCard
-         && to_type != typeAlias && to_type != typeFSS
-         && to_type != typeFSRef
-#ifdef MAC_OSX
-         && to_type != typeFileURL
-#endif
-         )
-       return errAECoercionFail;
-    }
-  else if (to_type == TYPE_FILE_NAME)
-    {
-      if (from_type != typeAlias && from_type != typeFSS
-         && from_type != typeFSRef
-#ifdef MAC_OSX
-         && from_type != typeFileURL
-#endif
-         )
-       return errAECoercionFail;
-    }
-  else
-    abort ();
-
-  if (from_type == to_type || to_type == typeWildCard)
+  if (from_type == typeNull)
+    err = errAECoercionFail;
+  else if (from_type == to_type || to_type == typeWildCard)
     err = AEDuplicateDesc (from_desc, result);
   else
     {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]