#!/usr/bin/env python
import os

png_dir = './png'
out = open("all.html", "w")

out.write('''<html>
<head>
  <style>
     div.topspace {
      height: 100px;
     }

     div.vspace {
      height: 100px;
     }

     a, p {
       font-size: 10px;
       margin-top: 10px;
       color: #333;
     }

     img {
         max-width: 100%;
         outline: 0;
         outline-style:none;
         outline-width:0;
     }

     body {
       background-color: #eee;
       color: #333;
       font-family: serif;
     }
   </style>
</head>
<body>
<h1> The rendered graphs are not guaranteed at all to reflect what the code actually does.</h1>
<p>These graphs are rendered by
<a href="http://git.osmocom.org/libosmocore/tree/contrib/fsm-to-dot.py">fsm-to-dot.py</a>,
let loose on all .c files found in the osmocom core network and BSS repositories.</p>
<p>To detect state transitions and so fort, fsm-to-dot.py uses highly
speculative regex evaluation depending on coding style.  So it's just a
hack to help getting an overview of what might be happening, so that you can
more easily pinpoint places in the code to go and look at what it is actually
doing. </p>
<center>
''')

images = []

for f in sorted(os.listdir(png_dir)):
  if not f.endswith('.png'):
    continue

  images.append(f)

meta_image = 'meta.dot.png'
if meta_image in images:
  images.remove(meta_image)
  images = [meta_image] + images

for i in range(len(images)):

  image = images[i]
  if i >= (len(images) - 1):
    next_image = 'bottom'
  else:
    next_image = images[i + 1]

  img_path = '%s/%s' % (png_dir, image)
  out.write(
     ('<a name="%s"><div class="topspace"><br/></div></a>\n' % image)
     + ('<h2>%s</h2>' % image)
     + ('<a href="%s"><img src="%s" border="0"/></a>\n' % (img_path, img_path))
     + ('<div class="vspace"><br/></div>\n\n')
     )

out.write('<a name="bottom"><div class="topspace"><br/></div></a>\n'
          + '<p><a href="#top"><big><big><b>^_^</b></big></big></a></p>\n'
          + ('<div class="vspace"><br/></div>\n\n'))
out.write('</center></body></html>')
out.close()

