# Generate, if possible, relative path from directory SRC to path read 
# Used by simplestPath cover script
# Copyright (C) 2014-2018 FARGOS Development, LLC
# $Id$

BEGIN {
	srcPathCount = split(SRC, srcPath, "/");
	if (srcPathCount > 0) {
		if (srcPath[1] == "") {
			srcPath[1] = "/";
		}
	}
}

{
	newPath="";
	e = split($0, dirs, "/");
	if (e > 0) {
		if (dirs[1] == "") dirs[1] = "/";
	}
	i=1;
	while(i <= srcPathCount) {
		if (srcPath[i] != dirs[i]) break;
		i += 1;
	}
	j = i;
	sep = "";
	if (i > 2) {
		while(i <= srcPathCount) {
			newPath = newPath sep "..";
			sep = "/";
			i += 1;
		}
	} else {
		sep = "/"; # absolute path
	}
	while (j <= e) {
		newPath = newPath sep dirs[j]
		sep = "/";
		j += 1;
	}
	print newPath;
}
