#!/bin/bash
FILE=/tmp/$RANDOM
TOP=56
NEXTFIELD=5
LEFT=22
AUTHLEFT=66
DATELEFT=37
MAXLENGTH=17

GIVENNAME=$1
SURNAME=$2
HOME=$3


if [ ${#GIVENNAME} -gt $MAXLENGTH ] || [ ${#SURNAME} -gt $MAXLENGTH ] || [ ${#HOME} -gt $MAXLENGTH ]; then
  echo "MAXLENGTH EXCEEDED."
  exit 1
fi


source ../include/nixdorf
init
smallLetters $FILE
printf "\x1b\x33\x0e" >> $FILE
makeNewline $TOP $FILE
makeLeft $LEFT $FILE
printf "$GIVENNAME" >> $FILE

# Authority field
makeNewline 2 $FILE
makeLeft $AUTHLEFT $FILE
printf "c3gov" >> $FILE

makeNewline 3 $FILE
makeLeft $LEFT $FILE
printf "$SURNAME" >> $FILE

makeNewline $NEXTFIELD $FILE
makeLeft $LEFT $FILE
printf "$HOME" >> $FILE

makeNewline 4 $FILE
makeLeft $DATELEFT $FILE

if [ -n "$EVENT" ]; then
  printf "/ $EVENT, $(date -I)" >> $FILE
else
  printf "/ $(date -I)" >> $FILE
fi

printFile $FILE
rm $FILE
