1 module caLib_util.misc;
2 
3 import std.file : exists, isFile;
4 import std.process : environment;
5 import std.string : split;
6 import caLib_util.build : os;
7 
8 
9 
10 T mod(T)(T m, T n)
11 {
12 	T temp = m % n;
13 	
14     if (temp < 0)
15     	temp += n;
16 
17     return temp;
18 }
19 
20 
21 
22 string findInPATH(string fileName)
23 {
24 	string filePath = null;
25 
26 	foreach(path ; environment.get("PATH").split(';'))
27 	{
28 		string temp = path ~ "/" ~ fileName;
29 		if(exists(temp) && isFile(temp))
30 			filePath = path ~ "/" ~ fileName;
31 	}
32 
33 	return filePath; 
34 }
35 
36 
37 
38 string withExecutableBinaryExstention(string fileName)
39 {
40 	static if(os == "Windows")
41 	{
42 		return fileName ~ ".exe";
43 	}
44 	else
45 	{
46 		return fileName;
47 	}
48 }
49 
50 
51 
52 string withDynamiclyLinkedExstention(string fileName)
53 {
54 	static if(os == "Windows")
55 	{
56 		return fileName ~ ".dll";
57 	}
58 	else static if(os == "Linux")
59 	{
60 		return fileName ~ ".so";
61 	}
62 	else
63 	{
64 		static assert(0, "Suppoert for " ~ os ~ "is not implemented");
65 	}
66 }