# (improved) dir to html converter -- ten years later
# the original version was written in awk back in 1996

import codecs, sys

longext = dict((x[:3], x) for x in ["html", "factor", "java", "class"])

src = sys.stdin.readlines()
dst = []
block = inuse = header = space = False

for line in reversed(src):

  text, mode, file = line[0:63], line[64:68], line[69:]
  text = text.rstrip()
  file = file.rstrip()

  if file != "":
    block = True
    header = space = False
    if mode != " -- ": inuse = True
    else: continue
  else:
    if text != "":
      if block and not inuse: header = True
      space = False
    else:
      if block and not inuse or header: space = True
      header = False
    block = inuse = False
    if header or space: continue

  file = file.replace("\\", "/")

  if file[-6:-3] == "~1." and file[-3:] in longext.keys():
    if file == "index~1.htm":
      file = "MIM.DIR"
    else:
      file = file[:-6] + "." + longext[file[-3:]]

  if file == "":
    dst.append(text + "\n")
  else:
    dst.append("<a href=\"%s\">%s</a>\n" % (file, text))

dst.append("<pre>\n")
dst.reverse()
dst.append("</pre>\n")

output = codecs.EncodedFile(sys.stdout, "cp866", "koi8-r")
output.writelines(dst)
