Configuration files
Posted: Sat Jan 25, 2014 3:47 am
Well I'm not at the stage to need it yet but today I was thinking about configuration files. I'm thinking about how to handle files and their associated programs. The system will be a database in memory that reads a configuration into the database for the supported file types. The configuration files will be read on a need to know basis so that file types that are rarely used wont have a database entry until that file type is loaded from the shell. Programs can load any type of file without affecting the database, this system only affects files that are opened by the user from a file shell like double clicking a png file.
The configuration files will be stored in the file system in the following way:
so that if the entry isn't found in the database in memory it will load the entry from the ext.id file.
What I wanted to know is what type of configuration file would be the most useful?
I started with a design using something like a shell script:
With this example the usual sha-bang loads bin/syscfg and the parameter ftypes as the table to set. The settings for the file type are then entered into the configuration table.
The other option I considered was XML with the following layout:
The second example makes use of media types and uses a default value for handling files that do not need special commands. The question is which type of configuration would be natural (to programmers mainly) and is there a different file format like JSON or YAML that would be preferred?
The format would be used for all configuration files loaded to the system database so the user and group files would be similar in XML:
The configuration files will be stored in the file system in the following way:
Code: Select all
sys/config/ftypes/
html.id
htm.id -> html.id # A filesystem link to another file type
jpg.id
png.id
txt.id
What I wanted to know is what type of configuration file would be the most useful?
I started with a design using something like a shell script:
Code: Select all
txt.id:
#! bin/syscfg ftypes
# Header ID
head.id = "" # Text files have no defined header
# Commands
cmd.open = "textview $1"
cmd.edit = "textedit $1"
jpg.id:
#! bin/syscfg ftypes
# Header ID
head.id = ?,?,"JFIF" # If the first 6 bytes do not match then this entry is ignored
# Commands
cmd.open = "picview $1"
cmd.edit = "picedit $1"
png.id:
#! bin/syscfg ftypes
# Header ID
head.id = 137, 80, 78, 71, 13, 10, 26, 10 # If the first 8 bytes do not match then this entry is ignored
# Commands
cmd.open = "pngview $1"
cmd.edit = "pngedit $1"
The other option I considered was XML with the following layout:
Code: Select all
txt.id:
<ftype media:"text/plain" ext="txt">
<!-- No head entry because text files have no defined header -->
<action>
<cmd open="textview $1"/>
<cmd edit="textedit $1"/>
</action>
</ftype>
# This entry could appear in a default.id file that includes defaults for a number of different file types and is loaded when the system is initialised
image.id:
<!-- default action for all images -->
<ftype media:"image">
<action>
<cmd open="picview $1"/>
<cmd edit="picedit $1"/>
</action>
</ftype>
jpg.id:
<ftype media:"image/jpeg" ext="jpg;jpeg">
<head>
<id>?,?,"JFIF"
</id>
</head>
<!-- Use default image actions -->
</ftype>
png.id:
<ftype media:"image/png" ext="png">
<head>
<id>137, 80, 78, 71, 13, 10, 26, 10
</id>
</head>
<action>
<cmd open="pngview $1"/>
<cmd edit="pngedit $1"/>
</action>
</ftype>
The format would be used for all configuration files loaded to the system database so the user and group files would be similar in XML:
Code: Select all
users.cfg:
<user id="user1" password="1%34timeocg12f4gygu" name="First user">
<attrib>
<something>This is something that this user has, but not all user have</something>
</attrib>
</user>
<user id="user2" password="aehn234%&gpgjk" name="Another user"/>
<user id="user3" password="atn.ud@#g,'.k" name="This user"/>