#!/usr/bin/python

import sys, re


header = """/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */
#ifndef __IOS_H__
#define __IOS_H__

#include <iostypes.h>

#if defined(_LANGUAGE_C)
#include <iosiobuf.h>
"""

footer = """
#endif /* _LANGUAGE_C */

#endif /*__IOS_H__*/
"""

def parse_syscalls(name):
  f = open(name)
  calls = []
  for l in f.readlines():
    l = l.strip()
    if l != "":
      result = re.match('([a-zA-Z0-9_]*\s*\**)([^(]*)\((.*)\)', l)
      ret = result.group(1)
      func = result.group(2)
      params = []
      for p in result.group(3).split(','):
        result = re.match('([a-zA-Z0-9_]*\s*\**)(.*)', p.strip())
        params.append((result.group(1), result.group(2)))
      calls.append((ret, func, params));
  return calls

if __name__ == "__main__":
  calls = parse_syscalls(sys.argv[1])
  out = open(sys.argv[2], "w")
  out.write(header)
  for call in calls:
    s = "%sIOS_%s" %  (call[0], call[1])
    s = s + "("
    prefix = ""
    for p in call[2]:
      s = s + "%s%s%s" % (prefix, p[0], p[1])
      prefix = ", "
    s = s + ");"
    out.write(s + '\n')
  out.write(footer)
  out.close()
