#!/bin/sh
hfile=../../include/Aatom.h
cfile=initatoms.c
#hfile=foo.h
#cfile=foo.c
rm -f $hfile $cfile
umask 222
awk '
BEGIN {
	hfile = "'$hfile'";
	cfile = "'$cfile'";
	hformat = "#define AA_%s ((AAtom) %d)\n";
	printf("#ifndef AATOM_H\n") > hfile;
	printf("#define AATOM_H 1\n\n") > hfile;
	printf("/* THIS IS A GENERATED FILE\n") > hfile;
	printf(" *\n") > hfile;
	printf(" * Do not change!  Changing this file implies a protocol change!\n") > hfile;
	printf(" */\n\n") > hfile;

	printf("/* THIS IS A GENERATED FILE\n") > cfile;
	printf(" *\n") > cfile;
	printf(" * Do not change!  Changing this file implies a protocol change!\n") > cfile;
	printf(" */\n\n") > cfile;
	printf("#include \"audio.h\"\n") > cfile;
	printf("#include \"Aatom.h\"\n") > cfile;
	printf("extern AAtom MakeAtom();\n") > cfile;
	printf("MakePredeclaredAtoms()\n") > cfile;
	printf("{\n") > cfile;

	}

NF == 2 && $2 == "@" {
	printf(hformat, $1, ++atomno) > hfile ;
	printf("    if (MakeAtom(\"%s\", %d, 1) != AA_%s) AtomError();\n", $1, length($1), $1) > cfile ;
	}

END {
	printf("\n") > hfile;
	printf(hformat, "LAST_PREDEFINED", atomno) > hfile ;
	printf("#endif /* AATOM_H */\n") > hfile;
	printf("}\n") > cfile ;
	}
' BuiltInAtoms
exit 0
