#!/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 __SWI_H__
#define __SWI_H__

"""

footer = """
#endif /*__SWI_H__*/
"""

def parse_syscalls(name):
  f = open(name)
  calls = []
  for l in f.readlines():
    l = l.strip()
    c = re.match('//', l)
    if (c == None) and (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__":
  out = open(sys.argv[-1], "w")
  out.write(header)
  i = 0
  for f in sys.argv[1:-1]:
    calls = parse_syscalls(f)
    for call in calls:
      out.write("#define SWI_%-25s  %2d\n" % (call[1], i))
      i = i + 1
  out.write("#define SWI_%-25s  %2d\n" % ("NUM_CALLS", i))
  out.write(footer)
  out.close()
