#!/usr/bin/awk -f

# kcs (c) 1995 by Joerg Hessdoerfer (joe@amber.dinoco.de)
# Permission to use and re-distribute this software is 
# granted according to the GPL

BEGIN {

  num = split(ARGV[1], a, ".");
  filetype = a[num];

  while(getline < sprintf("%s.lookup", ENVIRON["CONFTMP"]))
    {
      taglist[$1]=$2;
    }

  mconf=".config";
  cconf=".config.h";
  if ( filetype != "req" )
    {
      getline;
  
      match($0, /\".*\"/);
      text = substr($0, RSTART, RLENGTH);
      split(text, array, "\"");
      
      print "" >> mconf;
      print "" >> mconf;
      printf("#\n# %s\n#\n",array[4]) >> mconf;
      
      print "" >> cconf;
      print "" >> cconf;
      printf("/*\n * %s\n */\n",array[4]) >> cconf;
    }
}

{
  if(filetype != "req")
    {
      match($0, /\".*\"/);
      sub(/\".*\"/, "DUMMY", $0);
      
      if( $3 == "on" )
	{
	  printf("%s=y\n",taglist[$1]) >> mconf;
	  printf("#define %s 1\n",taglist[$1]) >> cconf;
	}
      else
	{
	  printf("# %s is not set\n",taglist[$1]) >> mconf;
	  printf("#undef %s\n",taglist[$1]) >> cconf;
	}
    }
  else
    {
      printf("%s=%s\n",taglist[$3],$4) >> mconf;
      printf("#define %s (%s)\n",taglist[$3],$4) >> cconf;
      getline;
    }
}
