====== parsecfg: configuration & command line parser (as of 0.8.1) ====== ===== preface ===== Especially in this document, the term **configuration** refers to the control of the process which is implemented by kernel-autobuild. Not to the kernel configuration or anything else. ===== outline ===== There are mainly 3 sources of configuration input: * ''.conf'' files, which have a shell like syntax: * ''/etc/kernal-autobuild.conf'' * ''~/.kernal-autobuild.conf'' * ''./kernal-autobuild.conf'' * ''.xml'' files, which contain XML data * ''/etc/kernal-autobuild.xml'' * ''~/.kernal-autobuild.xml'' * ''./kernal-autobuild.xml'' * command line parameters which are described in [[project:kernel-autobuild:commandline]] The ''.xml'' files contain * a general section and * template sections providing sets of options. As usual with *nix software, the files in /etc precede the ones inside the user's home directory (''~'') which precede those in the local directory which precede the command line options which in turn means the settings override each other the other way round. As far as kernel-autobuild is concerned, the ''.conf'' files also precede the ''.xml'' files. The use of ''.conf'' files is deprecated. And last but not least the settings from a template section inside an ''.xml'' file override the settings from the general section. None of these file are mandatory neither are any command line options. ===== sequence ===== In detail settings are recognized in the following order: * /etc/kernel-autobuild.conf * /etc/kernel-autobuild.xml * general options * template options * ~/.kernel-autobuild.conf * ~/.kernel-autobuild.xml * general options * template options * ./kernel-autobuild.conf * ./kernel-autobuild.xml * general options * template options * command line options ===== implemenation ===== ==== pitfall ==== There is an implementation pitfall. One can't process the template options at the time of reading the configuration file because the command line hasn't been processed yet. So you don't know about the selected template yet. The other way round doesn't work either. ==== how parsecfg puts things in order ==== First there is a class of structures used: structure | *-- general *-- templates | *-- template A *-- template B ... Parsecfg reads all the configuration files at once, storing the data in one structure per file. Then it copies the contents of each structure in turn to a master structure and by doing so it calculates the overriding by just overwriting the values. There is an exception to options which are allowed to be called multiple times: those values are not overwritten but added to a list. After that it processes the command line parameters storing all of them in some extra structure in the general subtree. Next step is to look if a "''--template''" parameter has been specified. If so inside the master structure the data from the corresponding template section is written to the general section. So template data supersedes general data. Last step is to overwrite the master structure with data from the command line structure. This is how in the end the command line "wins". ===== the xml format ===== ==== some simple conversion helper ==== #!/bin/bash ( cat << '.' . awk ' /^#/ { print "\t\t" }; /^[A-Za-z_][A-Za-z_0-9]*="/ { a=$0; b=$0; sub(/=.*/,"",a);sub(/^.*=/,"",b); printf "\t\t\t\n",a,b }; /^[A-Za-z_][A-Za-z_0-9]*='"'"'/ { a=$0; b=$0; sub(/=.*/,"",a);sub(/^.*=/,"",b); printf "\t\t\t\n",a,b }; /^[A-Za-z_][A-Za-z_0-9]*=[^'"'"'"]/ { a=$0; b=$0; sub(/=.*/,"",a);sub(/^.*=/,"",b); printf "\t\t\t\n",a,b }; ' cat << '.' . ) < kernel-autobuild.conf > kernel-autobuild.xml