#line 344 "/home/travis/build/felix-lang/felix/src/packages/flx_doc.fdoc"
  var dirname = System::argv_dflt 1 "src/web/tut";
  var homepage = System::argv_dflt 2 "";
  
  if dirname == "--help" do
    println "Usage flx_mktutindex directory homepage";
    println "  Makes src/web/tutname_index.fdoc for files in src/web/tutname_\\d*\\.fdoc";
    System::exit 0;
  done
  
  proc make_index (prefix:string)
  {
    re := RE2(prefix+"_\\d*\\.fdoc");
    var docs = FileSystem::regfilesin(dirname, re);
    docs = sort docs;
    iter println of (string) docs;
    f := fopen_output(Filename::join (dirname,prefix+"_index.fdoc"));
    if homepage != "" do
      writeln$ f,
       "<p><a href='"+homepage+"'>Up</a></p>"
      ;
    done
  
    writeln$ f,"@h1 "+prefix +" Index";
    var abstract = load (Filename::join (dirname, prefix + "_abstract.html"));
    if abstract != "" do
      writeln$ f,abstract;
    done
    writeln$ f,"<ul>";
    iter (proc (x:string) { writeln$ f, mkentry x; }) docs;
    writeln$ f,"</ul>";
    fclose f;
  
    fun mkentry(x:string):string =
    {
      var hline = "\n";
      begin // find first non-blank line
        f := fopen_input(Filename::join (dirname,x));
        while hline == "\n" do
          hline = f.readln;
        done
        fclose f;
      end
      scan:for var i in 0uz upto hline.len - 1uz do
        if hline.[i]== char ' ' do break scan; done
      done
      title := hline.[i to].strip;
      html := '<li><a href="' + Filename::basename x + '">' + title + '</a></li>';
      return html;
    }
  }
  
  var re = RE2(".*_01.fdoc");
  var samples = FileSystem::regfilesin(dirname, re);
  for name in samples do
    var prefix = name.[0 to -8];
    make_index prefix;
  done