Index talk:US Copyright Office - Renewal Registrations - 1950.djvu/Reformat

// This is the code I'm using to reformat these pages.

import java.io._

object Process { val o = new PrintWriter (new File ("bob")) def outputFormattedData (data : Seq[Seq[(String, Int)]]) : Unit = { //println (data) val chunk = (data.head +: data.tail.takeWhile (_.head._1.isEmpty)).toVector println (chunk) for (ch <- chunk) { for (c <- ch) { if (c._1.isEmpty) {o.println(""); o.print (":")} else o.print (c._1 + " ") }   }    o.println ("") o.println ("") println (data.tail) if (!data.tail.isEmpty) outputFormattedData (data.tail.dropWhile (_.head._1.isEmpty)) else o.close }

def allTails[T] (s : Seq[T], bp : T => Boolean) : Seq[Seq[T]] = { if (s.isEmpty) Seq else if (bp(s.head)) s +: allTails(s.tail, bp) else allTails(s.tail, bp) }

def main(args: Array[String]): Unit = { val file = { if (args.isEmpty) "sample" else args(0)} val lines = io.Source.fromFile(file).getLines.toVector val processedData = allTails (     lines.map (l => (l.dropWhile(_ == ' '), l.takeWhile(_ == ' ').length)),      {x : (String, Int) => (x._2 == 0)}    ).map {x => (x.head +: x.tail.takeWhile (_._2 != 0)) }.filter (l => l.length != 1 || (l.head._1 != "")) outputFormattedData (processedData.toVector) }

}