#!/bin/gawk -f

BEGIN { 
        database="/usr/share/alterator-x11/videocards";
        FS = ":"; 
       	OFS="\t";

	OPT_SEPARATOR="\t";
	ARGV[ARGC++] = database;
	ARGV[ARGC++] = "-";
       }


/^[a-z]+/   { 
		if (FILENAME == "-")
		{
			if (current[$0])
				print current[$0,"priority"],$0,
				      current[$0,"description"],
				      current[$0,"depth"],
				      current[$0,"options"];
			else
				print 0,$0,-1,$0,"";
		}
		else
		{
			driver=$0;
			current[$0] = $0;
			current[$0,"priority"] = 0;
			current[$0,"description"] = $0;
			current[$0,"depth"] = -1;
			current[$0,"options"] = "";
		}
            }

/^+priority/ {  current[driver,"priority"]=$2; }
/^+description/ { current[driver,"description"]=$2; }
/^+depth/ { current[driver,"depth"]=$2; }
/^+option/ { current[driver,"options"]=current[driver,"options"] OPT_SEPARATOR $2; }
