changeset 679:8907387e7a6a

doppelgaenger ....
author thomask
date Thu, 22 Sep 2005 14:40:55 +0000
parents f9e1d827a255
children 7242b6a90eb2
files run/o/opCat_16_A.d run/o/opCat_16_B.d run/o/opCat_17_A.d run/o/opCat_17_B.d unique.d
diffstat 5 files changed, 108 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/run/o/opCat_16_A.d	Wed Sep 21 21:15:30 2005 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-// $HeadURL$
-// $Date$
-// $Author$
-
-// @author@	AJG <AJG@nospam.com>
-// @date@	2005-09-18
-// @uri@	news:dgj92k$226p$1@digitaldaemon.com
-
-module dstress.run.o.opCat_16_A;
-
-int main(){
-	const static char[][] strings = ["Foo"];
-	const static char[] test = "Bar";
-	assert((strings ~  test).length==2);
-	assert((strings ~  test)[0] == "Foo");
-	assert((strings ~  test)[1] == "Bar");
-	return 0;
-}
--- a/run/o/opCat_16_B.d	Wed Sep 21 21:15:30 2005 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-// $HeadURL$
-// $Date$
-// $Author$
-
-// @author@	AJG <AJG@nospam.com>
-// @date@	2005-09-18
-// @uri@	news:dgj92k$226p$1@digitaldaemon.com
-
-module dstress.run.o.opCat_16_B;
-
-int main(){
-	static char[][] strings = ["Foo"];
-	static char[] test = "Bar";
-	assert((strings ~  test).length==2);
-	assert((strings ~  test)[0] == "Foo");
-	assert((strings ~  test)[1] == "Bar");
-	return 0;
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/run/o/opCat_17_A.d	Thu Sep 22 14:40:55 2005 +0000
@@ -0,0 +1,18 @@
+// $HeadURL$
+// $Date$
+// $Author$
+
+// @author@	AJG <AJG@nospam.com>
+// @date@	2005-09-18
+// @uri@	news:dgj92k$226p$1@digitaldaemon.com
+
+module dstress.run.o.opCat_17_A;
+
+int main(){
+	const static char[][] strings = ["Foo"];
+	const static char[] test = "Bar";
+	assert((strings ~  test).length==2);
+	assert((strings ~  test)[0] == "Foo");
+	assert((strings ~  test)[1] == "Bar");
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/run/o/opCat_17_B.d	Thu Sep 22 14:40:55 2005 +0000
@@ -0,0 +1,18 @@
+// $HeadURL$
+// $Date$
+// $Author$
+
+// @author@	AJG <AJG@nospam.com>
+// @date@	2005-09-18
+// @uri@	news:dgj92k$226p$1@digitaldaemon.com
+
+module dstress.run.o.opCat_17_B;
+
+int main(){
+	static char[][] strings = ["Foo"];
+	static char[] test = "Bar";
+	assert((strings ~  test).length==2);
+	assert((strings ~  test)[0] == "Foo");
+	assert((strings ~  test)[1] == "Bar");
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/unique.d	Thu Sep 22 14:40:55 2005 +0000
@@ -0,0 +1,72 @@
+module cn.kuehne.uniquefile;
+
+private import std.file;
+private import std.stdio;
+private import std.path;
+
+private char[][char[]] known;
+private uint doppelgaenger;
+
+private char[] lastPathElem(char[] path){
+	size_t end=path.length-1;
+	size_t start;
+	
+	for(end = path.length-1; path[end]==std.path.sep[0]; end--){
+		if(end==0){
+			return std.path.sep;
+		}
+	}
+
+	for(start = end-1; start<start.max; start--){
+		if(path[start]==std.path.sep[0]){
+			break;
+		}
+	}
+	
+	if(start==start.max){
+		start=0;
+	}else{
+		start+=1;
+	}
+	return path[start .. end+1];
+}
+
+private void add(char[] file){
+	char[] base = lastPathElem(file);
+	
+	if(isfile(file)){
+		char[]* tmp = base in known;
+		if(tmp){
+			writef("%s :\n\t%s\n\t%s\n", base, file, *tmp);
+			doppelgaenger++;
+		}else{
+			known[base] = file;
+		}
+	}
+	
+	if(isdir(file) && (base[0]!='.')){
+		foreach(char[] entry; listdir(file)){
+			add(file~std.path.sep~entry);
+		}
+	}
+}
+
+int main(char[][] args){
+	if(args.length<2){
+		fwritef(stderr, "at least one directory name is required as argument\n");
+		return -1;
+	}
+	
+	doppelgaenger = 0;
+	
+	foreach(char[] file; args[1 .. args.length]){
+		if(file=="."){
+			file=getcwd();
+		}
+		add(file);
+	}
+	
+	printf("hits : %i\n", doppelgaenger);
+
+	return doppelgaenger > 0;
+}
\ No newline at end of file