[File] Advice on writing magic entry for SOSI map format?

Petter Reinholdtsen pere at hungry.com
Fri May 3 13:56:31 UTC 2019


Hi.  I am trying to write a new magic rule to recognize the SOSI map
file format, and hope you can help me get it right.  Once it is working,
I will send in a proper patch.  Two example .sos files are available
from <URL: https://trac.osgeo.org/gdal/ticket/3638 >, but I am hoping to
find more example files to test the rule.

This is what imy rule look like at the moment:

#------------------------------------------------------------------------------
# $File: $
# SOSI
# Summary: Systematic Organization of Spatial Information
# Long description: Norwegian text based map format
# File extension: .sos
# Full name:    Petter Reinholdtsen (pere at hungry.com)
# Reference: https://en.wikipedia.org/wiki/SOSI

# Start with ".HODE" and end with ".SLUTT", might have BOM at the
# start and following ".HODE" near the start there is "\n..TEGNSETT "
# followed by the charset and "\n" or "\r\n", as well as
# "\n..SOSI-VERSJON " followed by the format version and "\n" or
# "\r\n".

0       string  .HODE           SOSI map file
>5      search  \n..TEGNSETT	tegnsett
>5      search  \n..SOSI-VERSJON	version
-9      string  \n.SLUTT\r\n		slutt
!:mime application/vnd.sosi
!:ext sos

First of all, I wonder which file would be a good fit for this rule.  It
is a text based format, is it still a good fit for magic/Magdir/map?

Second, how can I best handle both dos and unix line endings and an
optional BOM at the start?

And last, how can I extract the string following ..TEGNSETT and
..SOSI-VERSJON until the next newline and print it as part of the output
from file?  It would show the charset and SOSI version info.

PS: I am not subscribed to thist mailing list, please keep me on CC.

-- 
Happy hacking
Petter Reinholdtsen


More information about the File mailing list