Subversion Repositories oidplus

Compare Revisions

Regard whitespace Rev 738 → Rev 739

/trunk_dos/OIDFILE.PAS
38,7 → 38,7
implementation
 
uses
VtsFuncs;
VtsFuncs, OidUtils;
 
const
WANT_VERS = '2022';
67,6 → 67,29
CreateOidDef(oid);
end;
 
procedure BubbleSortSubIds(oid: POid);
var
n, i: integer;
a, b: string;
begin
n := ListCount(oid^.SubIds);
while n>1 do
begin
i := 0;
while i<n-1 do
begin
a := DotNotationPart(ListGetElement(oid^.SubIds, i));
b := DotNotationPart(ListGetElement(oid^.SubIds, i+1));
if CompareOID(a, b) > 0 then
begin
ListSwapElement(oid^.SubIds, i, i+1);
end;
Inc(i);
end;
Dec(n);
end;
end;
 
procedure WriteOidFile(filename: string; oid: POid);
var
f: Text;
84,6 → 107,8
 
WriteLn(f,'SUPR' + oid^.Parent);
 
(* Sort sub IDs *)
BubbleSortSubIds(oid);
for i := 0 to ListCount(oid^.SubIds)-1 do
begin
sTmp := ListGetElement(oid^.SubIds, i);
162,6 → 187,9
end;
end;
 
(* Sort sub IDs *)
BubbleSortSubIds(oid);
 
(* Remove last CRLF *)
oid^.Description := Copy(oid^.Description, 1, Length(oid^.Description)-Length(#13#10));
 
/trunk_dos/OIDPLUS.PAS
327,7 → 327,7
2) then
begin
if sInput = '' then continue;
if not IsNumeric(sInput) then
if not IsPositiveInteger(sInput) then
begin
ShowMessage('Invalid numeric ID (must be a positive integer)', 'ERROR', true);
_Pause;
/trunk_dos/VTSFUNCS.PAS
3,7 → 3,7
(************************************************)
(* VTSFUNCS.PAS *)
(* Author: Daniel Marschall *)
(* Revision: 2022-02-13 *)
(* Revision: 2022-02-14 *)
(* License: Apache 2.0 *)
(* This file contains: *)
(* - Various functions *)
11,14 → 11,23
 
interface
 
function Max(a, b: integer): integer;
function Min(a, b: integer): integer;
 
function CompareEqualLengthString(a, b: string): integer;
function CompareNumericString(a, b: string): integer;
 
procedure Beep;
 
function Trim(s: string): string;
function IsNumeric(s: string): boolean;
function ZeroPad(i: LongInt; n: integer): string;
procedure DeleteFile(filename: string);
function LeftPadStr(s: string; n: integer; ch: char): string;
function RightPadStr(s: string; n: integer; ch: char): string;
 
function DeleteFile(filename: string): boolean;
function FileExists(filename: string): boolean;
 
function IsPositiveInteger(s: string): boolean;
function StrToInt(s: string): Integer;
function IntToStr(Value: Integer): string;
 
27,6 → 36,22
uses
Crt;
 
function Max(a, b: integer): integer;
begin
if a > b then
Max := a
else
Max := b;
end;
 
function Min(a, b: integer): integer;
begin
if a < b then
Min := a
else
Min := b;
end;
 
function CompareEqualLengthString(a, b: string): integer;
var
ao, bo, i: integer;
51,27 → 76,14
 
function CompareNumericString(a, b: string): integer;
var
i, maxlen: integer;
prefix_a, prefix_b: string;
EqualLength: integer;
begin
maxlen := Length(a);
if Length(b) > maxlen then maxlen := Length(b);
 
prefix_a := '';
for i := 1 to maxlen-Length(a) do
begin
prefix_a := prefix_a + '0';
EqualLength := Max(Length(a), Length(b));
a := LeftPadStr(a, EqualLength, '0');
b := LeftPadStr(b, EqualLength, '0');
CompareNumericString := CompareEqualLengthString(a, b);
end;
 
prefix_b := '';
for i := 1 to maxlen-Length(b) do
begin
prefix_b := prefix_b + '0';
end;
 
CompareNumericString := CompareEqualLengthString(prefix_a+a, prefix_b+b);
end;
 
procedure Beep;
begin
Sound(220); (*220Hz*)
98,60 → 110,53
Trim := s;
end;
 
function IsNumeric(s: string): boolean;
function ZeroPad(i: LongInt; n: integer): string;
var
i: integer;
s: string;
begin
IsNumeric := false;
s := IntToStr(i);
ZeroPad := LeftPadStr(s, n, '0');
end;
 
if Length(s) = 0 then exit;
if (s[1] = '0') and (s <> '0') then exit;
for i := 1 to Length(s) do
function LeftPadStr(s: string; n: integer; ch: char): string;
begin
if not (s[i] in ['0'..'9']) then exit;
while Length(s) < n do
begin
s := ch + s;
end;
 
IsNumeric := true;
LeftPadStr := s;
end;
 
function ZeroPad(i: LongInt; n: integer): string;
var
s: string;
function RightPadStr(s: string; n: integer; ch: char): string;
begin
Str(i, s);
while Length(s) < n do
begin
s := '0' + s;
s := s + ch;
end;
ZeroPad := s;
RightPadStr := s;
end;
 
procedure DeleteFile(filename: string);
function DeleteFile(filename: string): boolean;
var
F: file;
Ch: Char;
begin
{ Get file to delete from command line }
Assign(F, filename);
{$I-}
Reset(F);
{$I+}
(*
if IOResult <> 0 then
Writeln('Cannot find ', filename)
begin
DeleteFile := false; (* cannot find file *)
end
else
begin
*)
Close(F);
(*
Write('Erase ', filename, '? ');
Readln(Ch);
if UpCase(CH) = 'Y' then
*)
{$I-}
Erase(F);
(*
{$I+}
DeleteFile := IOResult = 0;
end;
*)
end;
 
function FileExists(filename: string): boolean;
165,6 → 170,22
FileExists := IoResult = 0;
end;
 
function IsPositiveInteger(s: string): boolean;
var
i: integer;
begin
IsPositiveInteger := false;
 
if Length(s) = 0 then exit;
if (s[1] = '0') and (s <> '0') then exit;
for i := 1 to Length(s) do
begin
if not (s[i] in ['0'..'9']) then exit;
end;
 
IsPositiveInteger := true;
end;
 
function StrToInt(s: string): Integer;
var
i, Error: Integer;