sanders@peyote.cactus.org (Tony Sanders) (02/26/91)
Here is a filter to format app-defaults files.
If your system supports '#!' you could make it '#!/bin/awk -f'.
You may wish to post process with "tab". You may need a recent version
of awk, but you could change the sub() in the main body and work around it.
For now I don't do anything with continuation lines but you could
special case translations without much trouble, or uncomment the
sub/printf in 'contline==1'. It tries not to format comments, while
formatting resource lines that are commented.
enjoy,
-- sanders@peyote.cactus.org
First rule of software: Throw the first one away.
and so on...
---------------------------- xfmt ---------------------------
#!/bin/sh
awk '
BEGIN { FS=" "; contline=0; }
# Format continuation line
contline==1 {
if (!match($0,/\\$/))
contline=0; # last continuation line
# sub(/^[ \t]*/,"",$0); # strip leading spaces
# printf(" %s\n",$0);
print;
next;
}
# Special case for #define for future use
/^#[ \t]*define/ { print; next; }
# Skip cpp lines and obvious comments
/^#/ || /^!#/ || /^!.*XConsortium/ || /^! @/ { print; next; }
# Format line if it contains a colon (resource line)
/:/ {
if (match($0,/\\$/))
contline=1; # set continuation flag, format this line
i=index($0,":");
one=substr($0,0,i);
sub(/[ \t]*:/,":",one);
if (i==length) {
# emtpy resource spec
printf("%s\n",one);
next;
}
two=substr($0,i+1,length-i);
ac=split(two,al," ");
printf("%-40s",one);
for (i=1;i<=ac;i++) {
printf("%s",al[i]);
if (i != ac) printf(" ");
}
printf("\n");
next;
}
{ print; next; }
'
exit 0