program lcr;
uses Dos;
const
fallback : boolean = false;
pre : string = '';
Type
t_Distance = (none,local,DE,Mobile,Foreign);
var
infile : Text;
tString : string;
Distance : t_Distance;
CallerString : String;
procedure trim(var is :string);
begin
while (pos (' ',is) > 0) do delete (is,pos (' ',is),1);
end;
function timeOK:boolean;
var
h,m,s,hund : word;
fromT,toT : byte;
temp : string[5];
begin
timeOK:=false;
if pos('Uhr',tString) > 0 then
begin
GetTime (h,m,s,hund);
temp := copy (tString,1,pos('-',tString)-1);
trim (temp);
val (temp,fromT,hund);
temp := copy (tString,pos('-',tString)+1,2);
trim (temp);
val (temp,toT,hund);
if toT = 0 then toT := 24;
timeOK:= (h>=fromT) and (h<toT);
{ writeln (tString);}
end;
end;
procedure workOn;
const
start = 7;
var
count : byte;
cost,
lcr : string[12];
startp : byte;
endp : byte;
begin
if Distance = local then count := start;
if Distance = DE then count := start+1;
if Distance = Mobile then count := start+2;
if Distance = Foreign then count := start+3;
if fallback then count:=count+4;
while (not EOF(infile)) do
begin
readln (infile,tString);
if count = 0 then begin
writeln (tString);
lcr := copy (tString,1,pos(' ',tString)-1);
startp := pos('>',tString)+1;
endp := pos (' c',tString);
writeln ('Start : ',startp, ' Ende : ',endp);
cost := copy (tString,startp, endp-startp);
writeln ( 'SET VARIABLE LCR ',lcr,pre);
writeln ( 'SET VARIABLE COSTS ',cost);
end;
dec(count);
end;
end;
function setDistance:boolean;
begin
Distance := none;
if callerString[1] <> '0' then Distance := local;
if callerString[1] = '0' then Distance := DE;
if pos ('01',callerString) = 1 then Distance := Mobile;
if pos ('00',callerString) = 1 then Distance := Foreign;
if pos (paramstr(2),callerString)> 0 then Distance := local;
if Distance = local then pre := paramstr(2);
setDistance := Distance <> none;
end;
begin
{ Parameter
1 : gewaehlte Nummer
2 : lokale Vorwahl
3 : Fallback
}
Assign (infile, '/tmp/bt-call-cost.txt');
Reset(infile);
callerString := paramstr(1);
fallback := paramstr(3) = 'fallback';
if setDistance then
begin
while (not EOF(infile)) do
begin
readln (infile,tString);
if timeOK then workOn;
end;
end;
writeln;
end.