hedgewars/uFLUtils.pas
author unC0Rr
Wed, 02 Dec 2015 13:39:16 +0300
branchqmlfrontend
changeset 11444 dd1350a475d9
parent 10757 f71275973737
permissions -rw-r--r--
Fix build for windows + other small fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     1
unit uFLUtils;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     2
interface
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     3
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     4
function str2PChar(const s: shortstring): PChar;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     5
function intToStr(n: LongInt): shortstring;
10616
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10517
diff changeset
     6
function strToInt(s: shortstring): LongInt;
10440
b74a7bbe224e - Implement getTeamsList (not tested)
unc0rr
parents: 10434
diff changeset
     7
function midStr(s: shortstring; pos: byte): shortstring;
10517
844bd43db47a getScriptsList implementation
unc0rr
parents: 10440
diff changeset
     8
procedure underScore2Space(var s: shortstring);
10757
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
     9
function readInt(name, input: shortstring; var value: LongInt): boolean;
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    10
function readBool(name, input: shortstring; var value: boolean): boolean;
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    11
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    12
implementation
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    13
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    14
var
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    15
    str2PCharBuffer: array[0..255] of char;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    16
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    17
function str2PChar(const s: shortstring): PChar;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    18
var i: Integer;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    19
begin
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    20
   for i:= 1 to Length(s) do
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    21
      begin
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    22
      str2PCharBuffer[i - 1] := s[i];
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    23
      end;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    24
   str2PCharBuffer[Length(s)]:= #0;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    25
   str2PChar:= @(str2PCharBuffer[0]);
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    26
end;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    27
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    28
function intToStr(n: LongInt): shortstring;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    29
begin
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    30
    str(n, intToStr)
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    31
end;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    32
10616
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10517
diff changeset
    33
function strToInt(s: shortstring): LongInt;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10517
diff changeset
    34
begin
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10517
diff changeset
    35
val(s, strToInt);
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10517
diff changeset
    36
end;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents: 10517
diff changeset
    37
10440
b74a7bbe224e - Implement getTeamsList (not tested)
unc0rr
parents: 10434
diff changeset
    38
function midStr(s: shortstring; pos: byte): shortstring;
b74a7bbe224e - Implement getTeamsList (not tested)
unc0rr
parents: 10434
diff changeset
    39
begin
b74a7bbe224e - Implement getTeamsList (not tested)
unc0rr
parents: 10434
diff changeset
    40
    midStr:= copy(s, pos, length(s) - pos + 1)
b74a7bbe224e - Implement getTeamsList (not tested)
unc0rr
parents: 10434
diff changeset
    41
end;
b74a7bbe224e - Implement getTeamsList (not tested)
unc0rr
parents: 10434
diff changeset
    42
10517
844bd43db47a getScriptsList implementation
unc0rr
parents: 10440
diff changeset
    43
procedure underScore2Space(var s: shortstring);
844bd43db47a getScriptsList implementation
unc0rr
parents: 10440
diff changeset
    44
var i: LongInt;
844bd43db47a getScriptsList implementation
unc0rr
parents: 10440
diff changeset
    45
begin
844bd43db47a getScriptsList implementation
unc0rr
parents: 10440
diff changeset
    46
    for i:= length(s) downto 1 do
844bd43db47a getScriptsList implementation
unc0rr
parents: 10440
diff changeset
    47
        if s[i] = '_' then s[i]:= ' '
844bd43db47a getScriptsList implementation
unc0rr
parents: 10440
diff changeset
    48
end;
844bd43db47a getScriptsList implementation
unc0rr
parents: 10440
diff changeset
    49
10757
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    50
function readInt(name, input: shortstring; var value: LongInt): boolean;
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    51
var l: LongInt;
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    52
begin
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    53
    name:= name + '=';
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    54
    l:= length(name);
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    55
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    56
    if copy(input, 1, l) = name then
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    57
    begin
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    58
        value:= strToInt(midStr(input, l + 1));
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    59
        readInt:= true
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    60
    end
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    61
    else
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    62
        readInt:= false
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    63
end;
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    64
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    65
function readBool(name, input: shortstring; var value: boolean): boolean;
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    66
var l: LongInt;
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    67
begin
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    68
    name:= name + '=';
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    69
    l:= length(name);
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    70
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    71
    if copy(input, 1, l) = name then
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    72
    begin
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    73
        value:= (length(input) > l) and (input[l + 1] <> 'f');
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    74
        readBool:= true
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    75
    end
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    76
    else
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    77
        readBool:= false
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    78
end;
f71275973737 Scheme parsing
unc0rr
parents: 10616
diff changeset
    79
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    80
end.