/* (C) Copyright International Business Machines Corporation 23 January */
/* 1990.  All Rights Reserved. */
/*  */
/* See the file USERAGREEMENT distributed with this software for full */
/* terms and conditions of use. */
/* SCCS Info: @(#)parse.c	1.3 3/13/90 */

#include "stdio.h"
#include "ctype.h"
#define MAX 100
#define MAXARGS 32

typedef char str[256];
struct
{
str name;
int count;
char *args[MAXARGS];
char *ret;
} func[MAX];
struct 
 { char *name,*hname; }
mapping[] = 
{{"void","unixoperand_type__void"},
 {"char","unixoperand_type__char"},
 {"int","unixoperand_type__int"},
 {"short","unixoperand_type__short"},
 {"long","unixoperand_type__long"},
 {"uint","unixoperand_type__unsigned_int"},
 {"ushort","unixoperand_type__unsigned_short"},
 {"ulong","unixoperand_type__unsigned_long"},
 {"handle","unixoperand_type__handle"},
 {"boolean","unixoperand_type__boolean"},
 {"string","unixoperand_type__string"},
 {"buffer","unixoperand_type__buffer"},
 {"array","unixoperand_type__array"}};
main()
{
str buffer;
char c;
int i,j,f,n;
i=0; f=0; n=0; 
while (!feof(stdin))
  {
  c=getchar();
  if (!(isalnum(c)||(c=='_'))){
    if (i) 
      {
       buffer[i]='\0'; 
       i=0;
       n++;
       switch (n)
       {
       case 1:
        /* initialize */
        strcpy(func[f].name,buffer);
        func[f].count = -1;
        func[f].ret = "NULL";
        break;
       case 2:
        {int t;
        for (t=0;t<sizeof(mapping)/(2*sizeof((char *)0));t++)
         if (strcmp(mapping[t].name,buffer)==0)
          func[f].ret = mapping[t].hname;
        }        
        break;
       case 3:
        /* It is typed (not "test") */
        func[f].count = 0; 
        /* just for checking */
        if (strcmp(func[f].name,buffer)!=0)
         fprintf(stderr,"Error: \"%s\"<->\"%s\".\n",func[f].name,buffer);
        break;
       default:
        {int t;
        for (t=0;t<sizeof(mapping)/(2*sizeof((char *)0));t++)
         if (strcmp(mapping[t].name,buffer)==0)
          func[f].args[func[f].count++]=mapping[t].hname;
        }
        break;
       }
        }}
   else
    if (i<1023)
     buffer[i++]=c;   
  if (c=='\n'||c==EOF) 
   {
    if (n>0) f++; n=0;}
  }
 for  (i=0;i<f;i++)
  if (func[i].count>0)
   {
   printf("static unixargtype\n");
   printf(" syscall_intf_%s[%d]={\n",func[i].name,MAXARGS);
   for (j=0;j<func[i].count;((++j<func[i].count)?puts(","):puts("")))
    printf("                         %s",func[i].args[j]); 
   printf("                          };\n");
   }
 printf("static interface syscall_intf[%d]={\n",f);
 for (i=0;i<f;((++i<f)?puts(","):puts("")))
  {
  printf(" {%s,%d,",func[i].ret,func[i].count);
  if (func[i].count>0) 
   printf("(unixargtypelist *)syscall_intf_%s}",func[i].name);
  else
   printf("NULL}");
  }
 printf("};\n");

 exit(0);
}

