#!/usr/bin/env python3

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

    contline = ""
    for lineno, line in enumerate(open(fn)):
        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 = ""
