builtins.awk 1.24 KB
#
# "$Revision: 1.2 $"
#
# Generate a C structure from a table of commands
#
BEGIN	{
	fname=FILENAME;
	sub("[.]awk", "", fname);
	print "#include \"ide.h\"";
	count = 0;
}
/^[^#]/ {
	name[count] = $1;
	type[count] = $2;
	addr[count] = $3;
	if ( NF > 3 )
		help[count] = $4;
	else
		help[count] = "";
	count++;
}
END	{
	for ( i  = 0; i < count; i++ )
	    if ( type[i] == "CMD" || type[i] == "SCMD" || type[i] == "DCMD" )
		printf("extern int %s();\n", addr[i]);

	printf("\nbuiltin_t %s[] = {\n", fname);

	for ( i = 0; i < count; i++ )
	if ( type[i] == "CMD" )
		printf("\t\"%s\",\t(char *)%s,\tB_CMD,\"%s\",\n",name[i],addr[i],help[i]);
	else
	if ( type[i] == "STR" )
		printf("\t\"%s\",\t%s,\tB_STR,\"%s\",\n",name[i],addr[i],help[i]);
	else
	if ( type[i] == "INT" )
		printf("\t\"%s\",\t(char *)%s,\tB_INT,\"%s\",\n",name[i],addr[i],help[i]);
	else
	if ( type[i] == "SCMD" )
		printf("\t\"%s\",\t(char *)%s,\tB_SCMD,\"%s\",\n",name[i],addr[i],help[i]);
	else
	if ( type[i] == "DCMD" )
		printf("\t\"%s\",\t(char *)%s,\tB_DCMD,\"%s\",\n",name[i],addr[i],help[i]);
	else
		exit 1;

	printf("};\n");
	printf("%sinit(){syminit(sizeof(%s)/sizeof(builtin_t),%s);}\n",fname,fname,fname);
	printf("%shelp(){symhelp(sizeof(%s)/sizeof(builtin_t),%s);}\n",fname,fname,fname);
}