summaryrefslogtreecommitdiff
path: root/fpcdocs/mkkeytab.pp
blob: 55aa99130bb2fcee56881d861e396468ef823216 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
program mkkeytab;

{
 This program takes the keyboard scan code definitions, (the const section
 of the rtl/unix/keyboard.pp file) and outputs a
 latex table. The final output is done with some reformatting with the
 following sed commands:

 mkkeytab | sed 's/[aA]lt/ALT-/g' | sed 's/[Ss]hift/SHIFT-/g' | sed 's/[Cc]trl/CTRL-/g' > keys.tex

}

uses sysutils,classes;

Function ScanLine (S: String) : String;

Var
  I : Integer;
  KN,KC : String;

begin
  I:=Pos('=',S);
  Result:='';
  If I<>0 then
    begin
    KN:=Trim(Copy(S,1,I-1));
    Delete(KN,1,2);
    Delete(S,1,I);
    I:=Pos(';',S);
    If I<>0 then
      begin
      KC:=Trim(Copy(S,1,I-1));
      Delete(KC,1,1);
      Result:= KC+' & '+KN;
      end;
    end;
end;

Var
  F : text;
  List : TstringList;
  I,RowCount : Integer;
  S: String;

begin
  List:=TstringList.Create;
  Assign(f,'keys.txt');
  Reset(f);
  While not eof(f) do
    begin
    Readln (f,s);
    S:=ScanLine(s);
    If S<>'' then
      List.Add(S);
    end;
  RowCount:=List.Count div 3;
  if (List.Count mod 3)<>0 then
    begin
    Inc(RowCount);
    List.Add('');
    List.Add('');
    end;
  For I:=0 to rowcount-1 do
    Writeln(Format('%-20s & %-20s & %-20s \\',[List[i],List[I+RowCount],List[I+2*RowCount]]));
end.