1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmSiteNameCommand.cxx,v $
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"
20 bool cmSiteNameCommand::InitialPass(std::vector
<std::string
> const& args
)
24 this->SetError("called with incorrect number of arguments");
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());
42 const char *temp
= m_Makefile
->GetDefinition("HOSTNAME");
43 std::string hostname_cmd
;
50 hostname_cmd
= cmSystemTools::FindProgram("hostname", paths
);
53 std::string siteName
= "unknown";
54 #if defined(_WIN32) && !defined(__CYGWIN__)
56 if(cmSystemTools::ReadRegistryValue(
57 "HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\ComputerName\\ComputerName;ComputerName",
63 // try to find the hostname for this computer
64 if (!cmSystemTools::IsOff(hostname_cmd
.c_str()))
67 cmSystemTools::RunCommand(hostname_cmd
.c_str(),
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()))
79 host
= hostReg
.match(1);
86 temp
= m_Makefile
->GetDefinition("NSLOOKUP");
87 std::string nslookup_cmd
;
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()))
101 nslookup_cmd
+= host
;
102 std::string nsOutput
;
103 cmSystemTools::RunCommand(nslookup_cmd
.c_str(),
106 // got the domain name
107 if (nsOutput
.length())
109 std::string RegExp
= ".*Name:[ \t\n]*";
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));
124 AddCacheDefinition(args
[0].c_str(),
126 "Name of the computer/site where compile is being run",
127 cmCacheManager::STRING
);