#!/usr/bin/env python

import sys

sys.stdout.write("""#
# This file has been created by OMD out of the following files:
#
""")

for fn in sys.argv[1:]:
    if fn.endswith('~'):
        continue
    sys.stdout.write("# %s\n" % fn)

sys.stdout.write("""#
# Do not edit this file. It will be recreated each time Nagios
# is started or reloaded. Rather change things in the original
# files.
# 
# ------------------------------------------------------------

""")

for fn in sys.argv[1:]:
    if fn.endswith('~'):
        continue
    lineno = 0
    contline = ""
    for line in file(fn):
	lineno += 1
	ls = line.strip()
	if ls == "" or ls.startswith("#"):
	    continue
	if ls[-1] == '\\':
            contline += ls[:-1] + " "
            continue

	sys.stdout.write("# %s:%d\n" % (fn, lineno))
	sys.stdout.write(contline + line)
        contline = ""
