"magic" file entries for R'n'D

Discussion around programming R'n'D, its source code and its tools.

Moderators: Zomis, Flumminator

Post Reply
User avatar
Holger
Site Admin
Posts: 3231
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

"magic" file entries for R'n'D

Post by Holger » Sat Nov 12, 2005 1:30 pm

Hi Unix folks! Ever wanted to identify R'n'D level and tape files by the "file" command?

Code: Select all

aeglos@fangorn:~/.rocksndiamonds$ file levels/testing/002.level
levels/testing/002.level: data
aeglos@fangorn:~/.rocksndiamonds$ file tapes/testing/002.tape
tapes/testing/002.tape: data
aeglos@fangorn:~/.rocksndiamonds$
Not very impressive. :-(

So here are some lines to add to "/etc/magic" to improve this:

Code: Select all

# ========== Rocks'n'Diamonds user data files (new IFF format) ================
0       string          RND1            Rocks'n'Diamonds data

# ---------- Rocks'n'Diamonds level file --------------------------------------
>8      string          CAVE            \b, level file
>>12    string          VERS            \b, version
>>>24   byte            x               %d
>>>25   byte            x               \b.%d
>>>26   byte            x               \b.%d
>>>27   byte            x               \b-%d
>>148   string          AUTH            \b, author
>>>156  string          >\0             "%s"
>>28    string          HEAD            \b, title
>>>42   string          >\0             "%s"
>>>36   byte            x               \b, size %d
>>>37   byte            x               x %d
>>>38   beshort         x               \b, time %d s

# ---------- Rocks'n'Diamonds tape file ---------------------------------------
>8      string          TAPE            \b, tape file
>>12    string          VERS            \b, version
>>>24   byte            x               %d
>>>25   byte            x               \b.%d
>>>26   byte            x               \b.%d
>>>27   byte            x               \b-%d
>>28    string          HEAD            \b, engine
>>>52   byte            x               %d
>>>53   byte            x               \b.%d
>>>54   byte            x               \b.%d
>>>55   byte            x               \b-%d
>>>40   belong          >700000         \b, date 19%06d
>>>40   belong          <700000         \b, date 20%06d
>>56    string          INFO            \b, level set
>>>66   string          >\0             "%s"
>>>>(64.S+66)   beshort x               \b, level %d

# ========== Rocks'n'Diamonds user data files (old, non-IFF format) ===========
0       string          ROCKSNDIAMONDS_ Rocks'n'Diamonds data

# ---------- Rocks'n'Diamonds level file --------------------------------------
>15     string          LEVEL_FILE_     \b, level file
>26     string          VERSION_        \b, version
>>34    string          >\0             %s
>>>44   string          >\0             \b, title "%s"

# ---------- Rocks'n'Diamonds tape file ---------------------------------------
>15     string          TAPE_FILE_      \b, tape file
>25     string          VERSION_        \b, version
>>33    string          >\0             %s
Now you would get the following:

Code: Select all

aeglos@fangorn:~/.rocksndiamonds$ file levels/testing/002.level
levels/testing/002.level: Rocks'n'Diamonds data, level file, version 3.2.0-3, author "Holger Schemel", title "nameless level", size 64 x 32, time 30 s
aeglos@fangorn:~/.rocksndiamonds$ file tapes/testing/002.tape
tapes/testing/002.tape: Rocks'n'Diamonds data, tape file, version 3.2.0-2, level set "testing", level 2
aeglos@fangorn:~/.rocksndiamonds$
Looks better, doesn't it? :-)

*EDIT*

I've updated the "magic" file above -- it was missing the (important) engine version for tape files (plus some minor tweaks). Use the "-b" option of "diff" to see the differences (as this forum seems to not allow decent formatting, and whitespaces will come out different on your side), which shows only the non-whitespace differences (so you don't have to re-format all lines (if you care at all about formatting in your "magic" file, that is ;-) )).
Last edited by Holger on Thu Dec 01, 2005 8:25 am, edited 1 time in total.

User avatar
bojster
Posts: 458
Joined: Fri Jun 18, 2004 7:42 pm
Location: Poland
Contact:

Post by bojster » Mon Nov 14, 2005 9:22 am

Thanks, great idea!
I implemented it and it works perfectly.
Only for 0.9 tapes it displays: "Rocks'n'Diamonds data", but it's still better than just 'data'. ;-)

User avatar
Holger
Site Admin
Posts: 3231
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Post by Holger » Thu Dec 01, 2005 8:26 am

I've updated the magic file entry -- see "EDIT" changes above.

Post Reply