RosettaCodeData/Task/Find-common-directory-path/XPL0/find-common-directory-path....

32 lines
1.1 KiB
Plaintext

string 0; \use zero-terminated strings
func CommonPath(Separator, NumStrings, Strings); \Return common path string
int Separator, NumStrings, Strings;
char Str0, Str;
int Char, I, J, K;
func CmpStrs; \Return index where strings don't match, or end
[for I:= 0 to 1000 do
[Char:= Str0(I); \get Char from first string
if Char = 0 then return I;
for J:= 1 to NumStrings-1 do
[Str:= Strings(J);
if Str(I) # Char then return I;
];
];
];
[Str0:= Strings(0); \access individual bytes
for K:= CmpStrs downto 0 do \search back from index
if Str0(K) = Separator or Str0(K) = 0 then
[Str0(K):= 0; \terminate first string at mismatch
return Str0; \return address of common path string
];
];
[Text(0, CommonPath(^/, 3, ["/home/user1/tmp/coverage/test",
"/home/user1/tmp/covert/operator",
"/home/user1/tmp/coven/members"]));
CrLf(0);
]