The MimeMap module

Introduction and Overview

The MimeMap module provides a central service for mapping between RISC OS file types, MIME content types, 'dot' extensions and Mac filetype/creator pairs.

When the module is loaded it reads the file <Inet$MimeMappings> and stores the parsed file internally. If the system variable is changed, or the module is explicitly told to, the old version will be discarded and the file parsed again.

The MimeMap module can handle 5 different file typing schemes:

Any type can be converted to any other type.

Technical Details

Mac type names

Mac types are specified in the form: "XXXXxxxx" where XXXX is the filetype and xxxx is the vendor type. ? can be used as a single character wildcard. \? means a literal ?. \t, \v, \n, \r have their usual meanings. \DD (where DD are 2 hex digits) represents the character with ASCII code &DD.

There is a default Mac mapping defined, where "&DDDAcrn" maps to filetype &DDD (for hex digits DDD). This vendor name is registered with Apple. Within Mac mappings, the least number of wildcards is matched if multiple matches are possible.

Mac mappings must be enclosed in double quotes (") when passed to the *MimeMap command, and in the MimeMap file.

File format

The MimeMap file is split into 5 fields to provide the type mappings database. Entries within the file are searched in the same order in which they appear, with wildcards matched last. Fields are tab delimited, and consist of:

<mimetype> <tab> <ro-text> <tab> <ro-hex> <tab> <extensions> <tab> <mactype>

FieldMeaning
<mimetype>Takes the form <major>/<minor> types as defined by IANA. <minor> may be a '*' wildcard to match anything with the <major> type. <major> may be a '*' wildcard to match any type.
<ro-text>The textual form of <ro-hex>.
<ro-hex>The hexadecimal RISC OS type.
<extensions>A period (.) prefixed, tab separated list of file extensions.
<mactype>A Mac type/creator pair as described above.

System Variables

Inet$MimeMappings
The file of MIME type mappings read by MimeMap

The file named by this variable is read by the MimeMap module when it is loaded, and parsed into its internal database. If the variable is changed, or the module is told to re-read the file, the old version is discarded and the file parsed again.

SWI Calls

MimeMap_TranslateSWI &50B00
Translate between file type formats
R0=Input format
R1=Input data or pointer to buffer
R2=Output format
R3=Pointer to output data buffer (if needed, 128 bytes)
R0 - R2preserved
R3=Result, or output buffer pointer
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

This SWI is used to access the mapping translation database to convert from one type format to another.

The 5 formats supported are:

#NameMeaning
0MMM_TYPE_RISCOSRISC OS file type passed as an int
1MMM_TYPE_RISCOS_STRINGRISC OS file type passed as a pointer
2MMM_TYPE_MIMEMIME content type passed as a pointer
3MMM_TYPE_DOT_EXTNFile extension (no dot) as a pointer
4MMM_TYPE_MACMac type as a pointer

*Commands

*MimeMap
Read the mime file or display the translation of certain types
*MimeMap &hex
*MimeMap .extension
*MimeMap major/minor
*MimeMap typename
*MimeMap "Mac_Type"
None

This command is used to read the mime file or display the translation of certain types. If issued with no parameters it will list all the known types. Alternatively, it can be followed by the type names as used in the types file:

  • a type name &xxx to map a RISC OS file type in hexadecimal
  • .ext to map a file name extension
  • major/minor to map a MIME content type
  • a simple string to look up for a RISC OS file type
  • a Mac type pair in quotes

*ReadMimeMap
Re-read the MimeMap mappings file
*ReadMimeMap
None

This command causes the MimeMap module to re-read the mappings file.