#!/bin/bash

function init() {

  stty -F $DEVICE 1:0:80000dbd:0:3:1c:7f:15:4:5:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0

  # \x1b\x47     - Double Strike
  # \x1b\x78\x01 - Standard Letter Mode
  # \x1b\x52\x02 - German
  # \x1b\x33\x20 - 20/180 inch line spacing (standard)
  printf "\x1b\x47\x1b\x78\x01\x1b\x52\x02\x1b\x33\x20" >> "$DEVICE"

}

function printFile() {
  # Replace charset stuff
  sed -i 's/╔/\xc9/g;s/═/\xcd/g;s/╗/\xbb/g;s/║/\xba/g;s/╚/\xc8/g;s/╝/\xbc/g;s/§/\x40/g;s/Ä/\x5b/g;s/Ö/\x5c/g;s/Ü/\x5d/g;s/ä/\x7b/g;s/ö/\x7c/g;s/ü/\x7d/g;s/ß/\x7e/g' "$1"

  # Eject
  printf "\x0c" >> "$1"

  # Print
  cat $1 >> "$DEVICE"
}

function resetLetters() {
  printf "\x12\x14\x1b\x35" >> "$1"
}

function bigLetters() {
  resetLetters "$1"
  printf "\x0e" >> "$1"
}

function smallLetters() {
  resetLetters "$1"
  printf "\x0f" >> "$1"
}

function italicLetters() {
  printf "\x1b\x34" >> "$1"
}

function makeNewline() {
  for((i=0; i<$1; i++)); do
    printf "\n" >> "$2"
  done
}

function makeLeft() {
  for((i=0; i<$1; i++)); do
    printf " " >> "$2"
  done
}

init
resetLetters $DEVICE
