import re


def process_tspi_h(input_string):
  """Process the file content of tspi.h

  Parses the input file content and tokenize each function declaration into a
  3-tuple as shown in the following example:

  ***declaration***:
  TSPICALL Tspi_Context_Create
  (
      TSS_HCONTEXT*       phContext                      // out
  );

  ***output***:
  ("TSS_RESULT", "Tspi_Context_Create", [("TSS_HCONTEXT*", "phContext")])

  Args:
    input_string: the file content of tspi.h in a string.

  Returns:
    A list of 3-tuples of return type, function name, a list of 2-tuple in form
    of (data type, variable name)
  """
  r = re.compile(r'^TSPICALL[\s\S]*?;', flags=re.M)
  arr = []
  for m in r.finditer(input_string):
    tokens = m.group(0).splitlines()
    name = tokens[0].split()[1]
    arguments = []
    for t in tokens[2:-1]:
      var_type, var_name = t.split()[:2]
      arguments.append((var_type, var_name.replace(',', '')))
    arr.append(('TSS_RESULT', name, arguments))

  # For self-test purpose.
  expected_api_counts = input_string.count('\nTSPICALL')
  assert expected_api_counts == len(arr)

  return arr