Filetype setting patch

Peter Naulls peter at chocky.org
Wed Aug 7 14:51:52 PDT 2002


As discussed:

Index: unixlib/source/clib/unixlib/local.h
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/unixlib/source/clib/unixlib/local.h,v
retrieving revision 1.2.2.3
diff -u -r1.2.2.3 local.h
--- unixlib/source/clib/unixlib/local.h 14 Sep 2001 14:01:17 -0000      1.2.2.3
+++ unixlib/source/clib/unixlib/local.h 7 Aug 2002 21:50:53 -0000
@@ -156,11 +156,16 @@
    will get a ",fff" extension when translated to their Unix form.  */
 #define __RISCOSIFY_FILETYPE_FFF_EXT   0x2000
 
+/* If the filename has a unix-style extension, look up the extension
+   using RISC OS MimeMap SWIs and set a filetype.  If the filetype
+   could not be found, use 0xFFF.                                  */
+#define __RISCOSIFY_FILETYPE_SET        0x4000
+
 /* Mask of acceptable values. Keep other bits zero. Checks may be made.  */
-#define __RISCOSIFY_MASK               0x3FF0
+#define __RISCOSIFY_MASK               0x7FF0
 
 /* Value indicating that __riscosify[_std] didn't see a filetype extension
-   in it's argument __name or that it wasn't instructed to look for one.  */
+   in its argument __name or that it wasn't instructed to look for one.  */
 #define __RISCOSIFY_FILETYPE_NOTFOUND  -1
 
 /* Value indicating for __unixify that there is no filetype (e.g. a
@@ -168,7 +173,7 @@
    the flag bits.  */
 #define __RISCOSIFY_FILETYPE_NOTSPECIFIED -1
 
-/* Convert Unix filenames/pathnames to Risc OS format creating the final
+/* Convert Unix filenames/pathnames to RISC OS format creating the final
    directory if necessary and CREATE_DIR is non-zero.
    Pass RISC OS pathnames through unchanged.
    Returns pointer to terminating '\0' in buffer,


Index: unixlib/source/unix/features.c
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/unixlib/source/unix/features.c,v
retrieving revision 1.2.2.3
diff -u -r1.2.2.3 features.c
--- unixlib/source/unix/features.c      10 Jun 2002 12:01:27 -0000      1.2.2.3
+++ unixlib/source/unix/features.c      7 Aug 2002 21:51:59 -0000
@@ -114,7 +114,7 @@
 
   /* Initialise runtime features to their default values before querying
      the environment variables.  */
-  __riscosify_control = 0;
+  __riscosify_control =  __RISCOSIFY_FILETYPE_SET;
   __sdirinit (); /* Initialise riscosify.  */
 
   /* Default to recognising Image filesystems as directories.  Some programs


Index: unixlib/source/common/riscosify.c
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/unixlib/source/common/riscosify.c,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 riscosify.c
--- unixlib/source/common/riscosify.c   4 Sep 2001 16:32:04 -0000       1.2.2.2
+++ unixlib/source/common/riscosify.c   7 Aug 2002 21:52:30 -0000
@@ -932,6 +932,25 @@
          next = *++in0;
        }
 
+      /* Use MimeMap to find a filetype to match the filename
+         extension.  e.g.  file.html -> 0xfaf */
+      if ((flags & __RISCOSIFY_FILETYPE_SET) &&
+          filetype != NULL && last_dot != NULL)
+        {
+           _kernel_swi_regs regs;
+
+          regs.r[0] = MMM_TYPE_DOT_EXTN; /* Input extension */
+          regs.r[1] = (int)last_dot;
+          regs.r[2] = MMM_TYPE_RISCOS; /* Output filetype */
+
+          if (_kernel_swi(MimeMap_Translate, &regs, &regs)) {
+            /* Default to text if there's an error */
+            *filetype = 0xFFF;
+          } else {
+            *filetype = regs.r[3];
+          }
+        }
+
       /* Check if we have "blabla,xyz" as filename where `xyz' is a
          valid 12 bit hex number.  Only perform the check if
          __RISCOSIFY_FILETYPE_EXT is set and xyz != 0xfff.  However
@@ -1005,7 +1024,7 @@
             [From the choice of filenames above guess who is writing this]
 
             IMHO this is naïve:
-            0: The directory doesn't exists
+            0: The directory doesn't exist
             1: Write the file out as !Perl/lib/File.pm (!Perl.lib.File/pm)
             2: Create the directory to house more files
             3: Try to read back !Perl/lib/File.pm and it's "not there"



-- 
------------------------------------------------------------------------
 Peter Naulls - peter at chocky.org
 Homepage                     -  http://www.chocky.org/
 RISC OS C Programming        -  http://www.riscos.info/
 Unix Programs on RISC OS     -  http://www.chocky.org/unix/
------------------------------------------------------------------------



More information about the gcc mailing list