#!/usr/bin/python

# Author: Peter Schwabe
# Date: 2009-03-19
# Public domain

import re
import sys

from consts import *

definestr = "^[\ \t]*@define.*\\\\"
insidestr = "\\\\$"
mdefine = re.compile(definestr)
minside = re.compile(insidestr)

def subprint(line, inside):
  if inside:
    line = re.sub("#", macro_comment_str, line)
  else:
    line = re.sub("#", commentstr, line)
  line = re.sub("@", "#", line)
  print line,

inside = False
for line in sys.stdin.readlines():
  done = False
  exp = mdefine.match(line)
  if exp:
    inside = True
    comment = re.sub("@define[\t \ ]","",line)
    comment = re.sub("[\(\ \t].*","",comment)
    comment = re.sub("[\\\\\n]","",comment)
    subprint(line,inside)
    print macro_comment_str+" BEGIN MACRO "+comment+";\\"
    done = True
  elif inside:
    exp = minside.search(line)
    if not exp:
      if re.match("^[\t\ ]*$",line):
        print macro_comment_str+"END MACRO "+comment+";\\"
        subprint(line,inside)
      else:
        subprint(line,inside)
        print macro_comment_str+" END MACRO "+comment+";\\"
      done=True
      inside=False

  if not done:
    subprint(line,inside)
