#!/bin/sh
# Thanks to Stevan Bajić <stevan@bajic.ch> and Milan Straka <fox@ucw.cz>
# for their great help on writing this script

CONFIG_FILE="src/dspam.conf.in"

for foo in Hash=hash ExtLookup=extlookup SQLite=sqlite MySQL=mysql PostgreSQL=pgsql;
do
  first_line="/^#[\t ]\{1,\}-\{2,3\}[\t ]\{1,\}${foo%=*}[\t ]\{1,\}-\{2,3\}[\t ]*$/"
  one_line_below="/^#[\t ]\{1,\}-\{2,3\}[\t ]\{1,\}[^-]\{1,\}-\{2,3\}[\t ]*$/"
  sed -n -e "$first_line,$one_line_below {$one_line_below {$first_line!d}; p}" $CONFIG_FILE > src/${foo#*=}.conf;
  sed -i -e "$first_line,$one_line_below {$one_line_below {$first_line!p}; d}" $CONFIG_FILE
done;
