Linux distro of choice? (57)

22 Name: Redhatter 2005-11-13 10:40 ID:kC45xWS+

Those posts weren't there when I wrote my reply... I saw them after I had clicked Reply.

Okay, Mac OS X might have this wizz bang XML parser. Linux has one two... libxml2 for one.

However, my point is, it's still an additional library kicking around. And for things like Busybox ( http://www.busybox.net ), this is a Bad Thing.

XML is also overkill for the task. A lot of these programs just need a simple, flat config file structure. XML is a tree structure. For things that are "trees", yes, XML is wonderful. But for things like cron tables, file system tables, etc... it very quickly turns into a mess of tags.

Suppose we wanted to revamp the format of the /etc/fstab file. At present, this is what it looks like. This is my fstab file:

stuartl@beast /mnt/scratch/gentoo/mips/ip22/busybox-1.01 $ cat /etc/fstab
/dev/sdc1 / xfs rw 0 0
/dev/sdb1 /boot ext2 rw,noauto 0 0
... some more for /usr, /opt, /var...etc...
/dev/sdb2 /mnt/win2k ntfs ro,umask=0000 0 0
/dev/sdb5 /mnt/apps vfat rw,umask=0000 0 0
... etc...

Now, you could do that in XML. This is what it could look like:

<fstab>
<device node="/dev/sdc1">
<mountpoint>/</mountpoint>
<type>xfs</type>
<options>rw</options>
<dump>0</dump>
<pass>0</pass>
</device>
...
</fstab>

Or perhaps you could do this...

<fstab>
<device node="/dev/sdc1">
<mountpoint dir="/" />
<type name="xfs" />
<options>
rw
</options>
<dump value="0" />
<pass value="0" />
</device>
...
</fstab>

Notice how less readable that is?

I'd much rather see a far simpler format. Something like this:

/dev/sdc1
mountpoint: /
fstype: xfs
options: rw
dump: 0
pass: 0

/dev/sdb1
mountpoint: /boot
fstype: ext2
options: rw noauto
dump: 0
pass: 0

Now isn't that so much neater? :-) It's also trivial to parse too. Not as easy as the original format (cut -d' ' -f COLUMN), but considerably easier than the XML.

Pseudocode for parsing the above file:

Define a data type, mountRecord with the following members:
String device
String mountpoint
String fstype
Array of Strings options
int dump
int pass
Define an array of mountRecords, mounts
Define a mountRecord, record
Define a String, var
Define a String, val
Define an int, position
foreach line in file:
if line starts with whitespace:
Strip proceeding whitespace from line
position = location of ": " sequence in line
if sequence found:
var = line->subString( from start to position )
val = line->subString( from position to end )
case var in:
mountpoint: record->mountpoint = val
fstype: record->fstype = val
options: record->options = val
... etc ...
else
add record to mounts
clear record

Not terribly difficult in C. Now, does this explain my opposition to the idea of XML? I agree, some files could do with an update... it's very difficult to mount a partition on a directory containing spaces unless you do it by hand. I'm not sure if mount is smart enough to recognise the \ escape sequence. That format above would handle spaces in the middle of a directory name (but not starting or trailing spaces).

My point is, yes... things could be improved... but we don't have to turn to XML. If you use a hammer to solve every problem, then every problem will tend to look like a nail.

This thread has been closed. You cannot post in this thread any longer.