program main(output, input);

type
  number_str = varying [2] of char;

const
  esc = chr (27);

var
  terminator : char;
  ref_string,
  out_string,
  in_string  : varying [40] of char;
  term_choice,
  temp_str   : varying [4] of char;
  temp_nbr,
  len_str,
  i,
  which_key  : integer;

function hex_out ( dec_in : integer ) : number_str;

var
  i, j : integer;
  t1, t2 : varying [1] of char;

begin { hex out }

  i := dec_in div 16;
  writev ( t1, i:1 );
  j := dec_in - (i*16);
  if j < 10 
    then 
      writev (t2, j:1)
    else
      t2 := chr ( j+55);
{ end if J < 10 }
  hex_out := t1 + t2;
end; { hex out }

begin { main }
  writeln ('Enter the string to be stored in a function key');
  readln  (in_string);
  writeln ('Enter the number of the function key (6-20)');
  readln  (which_key);
  writeln ('Enter a terminator for when the key is pressed');
  writeln ('C=return, T=tab, N=nothing');
  readln  (term_choice);
  case which_key of
    11,12,13,14 : which_key := which_key + 1;
    15,16 : which_key := which_key + 2;
    17, 18,19,20 : which_key := which_key + 3;
    otherwise
      { noop }
    end; { case }
  which_key := which_key + 11;

  terminator := term_choice [1];

  if terminator in ['a'..'z']
    then
      terminator  := chr ( ord (terminator ) - ord (' '));

  case terminator  of
    'C' : term_choice := '0d ';
    'T' : term_choice := '09 ';
    'N' : term_choice := ' ';
    otherwise
      { noop }
  end; { case }

  out_string := esc + 'P1;1|';
  ref_string := 'P1;1|';
  writev (temp_str, which_key:2);
  out_string := out_string + temp_str;
  ref_string := ref_string + temp_str;
  out_string := out_string + '/';
  ref_string := ref_string + '/';
{ writeln( which_key, ' which key '); }

  len_str := length (in_string);
  for i := 1 to len_str do
    begin
    temp_nbr := ord( in_string [ i ] );
    temp_str := hex_out ( temp_nbr);
 {  writeln (temp_nbr, temp_str); }
    out_string := out_string + temp_str;
    ref_string := ref_string + temp_str;
    ref_string := ref_string + ' '
    end;

  writeln (out_string, term_choice, esc, '\');
  writeln ( '<esc>', ref_string, term_choice, '<esc>\')
end.
