FIX: stupid pb fixed (close to being medieval'ed by The Ken)
[cmake.git] / Source / cmSiteNameCommand.cxx
blob88daa7cd779bc0b12478fc2847fe98995b08cbe1
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmSiteNameCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2002-04-26 13:35:03 $
7 Version: $Revision: 1.15 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmSiteNameCommand.h"
19 // cmSiteNameCommand
20 bool cmSiteNameCommand::InitialPass(std::vector<std::string> const& args)
22 if(args.size() != 1 )
24 this->SetError("called with incorrect number of arguments");
25 return false;
27 std::vector<std::string> paths;
28 paths.push_back("/usr/bsd");
29 paths.push_back("/usr/sbin");
30 paths.push_back("/usr/bin");
31 paths.push_back("/bin");
32 paths.push_back("/sbin");
33 paths.push_back("/usr/local/bin");
35 const char* cacheValue
36 = m_Makefile->GetDefinition(args[0].c_str());
37 if(cacheValue)
39 return true;
42 const char *temp = m_Makefile->GetDefinition("HOSTNAME");
43 std::string hostname_cmd;
44 if(temp)
46 hostname_cmd = temp;
48 else
50 hostname_cmd = cmSystemTools::FindProgram("hostname", paths);
53 std::string siteName = "unknown";
54 #if defined(_WIN32) && !defined(__CYGWIN__)
55 std::string host;
56 if(cmSystemTools::ReadRegistryValue(
57 "HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\ComputerName\\ComputerName;ComputerName",
58 host))
60 siteName = host;
62 #else
63 // try to find the hostname for this computer
64 if (!cmSystemTools::IsOff(hostname_cmd.c_str()))
66 std::string host;
67 cmSystemTools::RunCommand(hostname_cmd.c_str(),
68 host);
70 // got the hostname
71 if (host.length())
73 // remove any white space from the host name
74 std::string hostRegExp = "[ \t\n\r]*([^\t\n\r ]*)[ \t\n\r]*";
75 cmRegularExpression hostReg (hostRegExp.c_str());
76 if (hostReg.find(host.c_str()))
78 // strip whitespace
79 host = hostReg.match(1);
82 if(host.length())
84 siteName = host;
86 temp = m_Makefile->GetDefinition("NSLOOKUP");
87 std::string nslookup_cmd;
88 if(temp)
90 nslookup_cmd = temp;
92 else
94 nslookup_cmd = cmSystemTools::FindProgram("nslookup", paths);
97 // try to find the domain name for this computer
98 if (!cmSystemTools::IsOff(nslookup_cmd.c_str()))
100 nslookup_cmd += " ";
101 nslookup_cmd += host;
102 std::string nsOutput;
103 cmSystemTools::RunCommand(nslookup_cmd.c_str(),
104 nsOutput);
106 // got the domain name
107 if (nsOutput.length())
109 std::string RegExp = ".*Name:[ \t\n]*";
110 RegExp += host;
111 RegExp += "\\.([^ \t\n\r]*)[ \t\n\r]*Address:";
112 cmRegularExpression reg( RegExp.c_str() );
113 if(reg.find(nsOutput.c_str()))
115 siteName += '.' + cmSystemTools::LowerCase(reg.match(1));
122 #endif
123 m_Makefile->
124 AddCacheDefinition(args[0].c_str(),
125 siteName.c_str(),
126 "Name of the computer/site where compile is being run",
127 cmCacheManager::STRING);
129 return true;