x-octave and x-matlab mime types should be different
Submitted by Carnë Draug
Assigned to Shared Mime Info group
Description
At the moment, Octave and Matlab share the same mime type (one is an alias for the other) but these languages are different. Indeed, one of the magic being used to identify a file as x-matlab is even inavlid matlab syntax (string "##" at offset 0).
The attached commit treats them as separate mime types, adds new tests for this, and adjusts the current ones.
Here's the rationale for the changes:
- since it is possible to write octave executables, I have added magic for a shebang line with typical paths for octave.
- octave and matlab can be distinguished by the character used for comments (octave uses #, and matlab %). A file using % is also a valid octave program but if the author used % then it probably wants matlab compatibility in which case it makes sense to treat it as matlab.
- an octave script can have function definitions. In such case, to distinguish between a script and a function file, the first statement must not be a function declaration. The statement "1;" is the most common so I added it as magic too.
Despite these changes, a file that starts with "function" is still undifferentiated between the two. The easiest methods to do the distinction are:
-
if the file ends with endfunction. Matlab uses general statements "end" while Octave allows for specific "endfunction". Is it possible to do this? something like 'value="endfunction" offset="-11"'?
-
if there is any # or % comment line (first is Octave only). However, checking for such a character near the start of the file would be too much. Files which are plain text would be identified as x-matlab just because they have a "%". Is there a way to use a specific magic if another one worked? I.e., only search for "#" or "%" comments if we already checked the file starts with "function"?