#!/bin/sh

# mktitlepage for VideoteXt
#
# Copyright (c) 1994 Martin Buck  <martin.buck@student.uni-ulm.de>
# Read COPYING for more information

# This little GAWK-script converts a raw titlepage to a includable header-file.
# Every character on the page is represented by 2 hex-digits or an underscore followed by a
# literal character. There are exactly 960 characters on one page. There is also a section
# for character-attributes, which is seperated by a blank line. Every attribute is represented
# by 2 hex-digits, so currently we can only set the lower 16 bits of the attributes.


exec gawk '
  BEGIN {
    print "/* This file was created automatically by mktitlepage. DO NOT EDIT */"
    print ""
    print "static chr_t titlepage_chr[960] = {"
  }

  /.+/ {
    for (pos = 0; pos <= 39; pos++) {
      if (substr($0, pos * 2 + 1, 1) == "_") {
        printf "\047%c\047 ", substr($0, pos * 2 + 2, 1)
      } else {
        printf "0x%s", substr($0, pos * 2 + 1, 2)
      }
      if (count < 959) {
        printf ","
      } else {
        printf "\n};\n\n"
        if (doattr) {
          exit
        }
        doattr = 1
        print "static chr_t titlepage_attrib[960] = {"
        count = -1
      }
      if (count % 20 == 19) {
        print ""
      }
      count++
    }
  }

'
