42 lines
1.2 KiB
Text
42 lines
1.2 KiB
Text
$ include "seed7_05.s7i";
|
|
|
|
const func integer: commonLen (in array string: names, in char: sep) is func
|
|
result
|
|
var integer: result is -1;
|
|
local
|
|
var integer: index is 0;
|
|
var integer: pos is 1;
|
|
begin
|
|
if length(names) <> 0 then
|
|
repeat
|
|
for index range 1 to length(names) do
|
|
if pos > length(names[index]) or names[index][pos] <> names[1][pos] then
|
|
decr(pos);
|
|
while pos >= 1 and names[1][pos] <> sep do
|
|
decr(pos);
|
|
end while;
|
|
if pos > 1 then
|
|
decr(pos);
|
|
end if;
|
|
result := pos;
|
|
end if;
|
|
end for;
|
|
incr(pos);
|
|
until result <> -1;
|
|
end if;
|
|
end func;
|
|
|
|
const proc: main is func
|
|
local
|
|
var integer: length is 0;
|
|
const array string: names is [] ("/home/user1/tmp/coverage/test",
|
|
"/home/user1/tmp/covert/operator",
|
|
"/home/user1/tmp/coven/members")
|
|
begin
|
|
length := commonLen(names, '/');
|
|
if length = 0 then
|
|
writeln("No common path");
|
|
else
|
|
writeln("Common path: " <& names[1][.. length]);
|
|
end if;
|
|
end func;
|