cmSystemTools.cxx 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmSystemTools.h"
  14. #include <ctype.h>
  15. #include <errno.h>
  16. #include <time.h>
  17. #include <string.h>
  18. #include <cmsys/RegularExpression.hxx>
  19. #include <cmsys/Directory.hxx>
  20. #include <cmsys/System.h>
  21. #if defined(_WIN32)
  22. # include <windows.h>
  23. #else
  24. # include <sys/types.h>
  25. # include <unistd.h>
  26. # include <utime.h>
  27. # include <sys/wait.h>
  28. #endif
  29. #include <sys/stat.h>
  30. #if defined(_WIN32) && \
  31. (defined(_MSC_VER) || defined(__WATCOMC__) || \
  32. defined(__BORLANDC__) || defined(__MINGW32__))
  33. # include <io.h>
  34. #endif
  35. #if defined(CMAKE_BUILD_WITH_CMAKE)
  36. # include <libtar/libtar.h>
  37. # include <memory> // auto_ptr
  38. # include <fcntl.h>
  39. # include <cm_zlib.h>
  40. # include <cmsys/MD5.h>
  41. #endif
  42. #if defined(__sgi) && !defined(__GNUC__)
  43. # pragma set woff 1375 /* base class destructor not virtual */
  44. #endif
  45. #if !defined(HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
  46. // For GetEnvironmentVariables
  47. # if defined(_WIN32)
  48. extern __declspec( dllimport ) char** environ;
  49. # else
  50. extern char** environ;
  51. # endif
  52. #endif
  53. #ifdef _WIN32
  54. class cmSystemToolsWindowsHandle
  55. {
  56. public:
  57. cmSystemToolsWindowsHandle(HANDLE h): handle_(h) {}
  58. ~cmSystemToolsWindowsHandle()
  59. {
  60. if(this->handle_ != INVALID_HANDLE_VALUE)
  61. {
  62. CloseHandle(this->handle_);
  63. }
  64. }
  65. operator bool() const { return this->handle_ != INVALID_HANDLE_VALUE; }
  66. bool operator !() const { return this->handle_ == INVALID_HANDLE_VALUE; }
  67. operator HANDLE() const { return this->handle_; }
  68. private:
  69. HANDLE handle_;
  70. };
  71. #endif
  72. bool cmSystemTools::s_RunCommandHideConsole = false;
  73. bool cmSystemTools::s_DisableRunCommandOutput = false;
  74. bool cmSystemTools::s_ErrorOccured = false;
  75. bool cmSystemTools::s_FatalErrorOccured = false;
  76. bool cmSystemTools::s_DisableMessages = false;
  77. bool cmSystemTools::s_ForceUnixPaths = false;
  78. std::string cmSystemTools::s_Windows9xComspecSubstitute = "command.com";
  79. void cmSystemTools::SetWindows9xComspecSubstitute(const char* str)
  80. {
  81. if ( str )
  82. {
  83. cmSystemTools::s_Windows9xComspecSubstitute = str;
  84. }
  85. }
  86. const char* cmSystemTools::GetWindows9xComspecSubstitute()
  87. {
  88. return cmSystemTools::s_Windows9xComspecSubstitute.c_str();
  89. }
  90. void (*cmSystemTools::s_ErrorCallback)(const char*, const char*,
  91. bool&, void*);
  92. void (*cmSystemTools::s_StdoutCallback)(const char*, int len, void*);
  93. void* cmSystemTools::s_ErrorCallbackClientData = 0;
  94. void* cmSystemTools::s_StdoutCallbackClientData = 0;
  95. // replace replace with with as many times as it shows up in source.
  96. // write the result into source.
  97. #if defined(_WIN32) && !defined(__CYGWIN__)
  98. void cmSystemTools::ExpandRegistryValues(std::string& source)
  99. {
  100. // Regular expression to match anything inside [...] that begins in HKEY.
  101. // Note that there is a special rule for regular expressions to match a
  102. // close square-bracket inside a list delimited by square brackets.
  103. // The "[^]]" part of this expression will match any character except
  104. // a close square-bracket. The ']' character must be the first in the
  105. // list of characters inside the [^...] block of the expression.
  106. cmsys::RegularExpression regEntry("\\[(HKEY[^]]*)\\]");
  107. // check for black line or comment
  108. while (regEntry.find(source))
  109. {
  110. // the arguments are the second match
  111. std::string key = regEntry.match(1);
  112. std::string val;
  113. if (ReadRegistryValue(key.c_str(), val))
  114. {
  115. std::string reg = "[";
  116. reg += key + "]";
  117. cmSystemTools::ReplaceString(source, reg.c_str(), val.c_str());
  118. }
  119. else
  120. {
  121. std::string reg = "[";
  122. reg += key + "]";
  123. cmSystemTools::ReplaceString(source, reg.c_str(), "/registry");
  124. }
  125. }
  126. }
  127. #else
  128. void cmSystemTools::ExpandRegistryValues(std::string&)
  129. {
  130. }
  131. #endif
  132. std::string cmSystemTools::EscapeQuotes(const char* str)
  133. {
  134. std::string result = "";
  135. for(const char* ch = str; *ch != '\0'; ++ch)
  136. {
  137. if(*ch == '"')
  138. {
  139. result += '\\';
  140. }
  141. result += *ch;
  142. }
  143. return result;
  144. }
  145. std::string cmSystemTools::EscapeSpaces(const char* str)
  146. {
  147. #if defined(_WIN32) && !defined(__CYGWIN__)
  148. bool useDoubleQ = true;
  149. #else
  150. bool useDoubleQ = false;
  151. #endif
  152. if(cmSystemTools::s_ForceUnixPaths)
  153. {
  154. useDoubleQ = false;
  155. }
  156. if(useDoubleQ)
  157. {
  158. std::string result;
  159. // if there are spaces
  160. std::string temp = str;
  161. if (temp.find(" ") != std::string::npos &&
  162. temp.find("\"")==std::string::npos)
  163. {
  164. result = "\"";
  165. result += str;
  166. result += "\"";
  167. return result;
  168. }
  169. return str;
  170. }
  171. else
  172. {
  173. std::string result = "";
  174. for(const char* ch = str; *ch != '\0'; ++ch)
  175. {
  176. if(*ch == ' ')
  177. {
  178. result += '\\';
  179. }
  180. result += *ch;
  181. }
  182. return result;
  183. }
  184. }
  185. std::string cmSystemTools::RemoveEscapes(const char* s)
  186. {
  187. std::string result = "";
  188. for(const char* ch = s; *ch; ++ch)
  189. {
  190. if(*ch == '\\' && *(ch+1) != ';')
  191. {
  192. ++ch;
  193. switch (*ch)
  194. {
  195. case '\\': result.insert(result.end(), '\\'); break;
  196. case '"': result.insert(result.end(), '"'); break;
  197. case ' ': result.insert(result.end(), ' '); break;
  198. case 't': result.insert(result.end(), '\t'); break;
  199. case 'n': result.insert(result.end(), '\n'); break;
  200. case 'r': result.insert(result.end(), '\r'); break;
  201. case '#': result.insert(result.end(), '#'); break;
  202. case '(': result.insert(result.end(), '('); break;
  203. case ')': result.insert(result.end(), ')'); break;
  204. case '0': result.insert(result.end(), '\0'); break;
  205. case '\0':
  206. {
  207. cmSystemTools::Error("Trailing backslash in argument:\n", s);
  208. return result;
  209. }
  210. default:
  211. {
  212. std::string chStr(1, *ch);
  213. cmSystemTools::Error("Invalid escape sequence \\", chStr.c_str(),
  214. "\nin argument ", s);
  215. }
  216. }
  217. }
  218. else
  219. {
  220. result.insert(result.end(), *ch);
  221. }
  222. }
  223. return result;
  224. }
  225. void cmSystemTools::Error(const char* m1, const char* m2,
  226. const char* m3, const char* m4)
  227. {
  228. std::string message = "CMake Error: ";
  229. if(m1)
  230. {
  231. message += m1;
  232. }
  233. if(m2)
  234. {
  235. message += m2;
  236. }
  237. if(m3)
  238. {
  239. message += m3;
  240. }
  241. if(m4)
  242. {
  243. message += m4;
  244. }
  245. cmSystemTools::s_ErrorOccured = true;
  246. cmSystemTools::Message(message.c_str(),"Error");
  247. }
  248. void cmSystemTools::SetErrorCallback(ErrorCallback f, void* clientData)
  249. {
  250. s_ErrorCallback = f;
  251. s_ErrorCallbackClientData = clientData;
  252. }
  253. void cmSystemTools::SetStdoutCallback(StdoutCallback f, void* clientData)
  254. {
  255. s_StdoutCallback = f;
  256. s_StdoutCallbackClientData = clientData;
  257. }
  258. void cmSystemTools::Stdout(const char* s)
  259. {
  260. if(s_StdoutCallback)
  261. {
  262. (*s_StdoutCallback)(s, static_cast<int>(strlen(s)),
  263. s_StdoutCallbackClientData);
  264. }
  265. else
  266. {
  267. std::cout << s;
  268. std::cout.flush();
  269. }
  270. }
  271. void cmSystemTools::Stdout(const char* s, int length)
  272. {
  273. if(s_StdoutCallback)
  274. {
  275. (*s_StdoutCallback)(s, length, s_StdoutCallbackClientData);
  276. }
  277. else
  278. {
  279. std::cout.write(s, length);
  280. std::cout.flush();
  281. }
  282. }
  283. void cmSystemTools::Message(const char* m1, const char *title)
  284. {
  285. if(s_DisableMessages)
  286. {
  287. return;
  288. }
  289. if(s_ErrorCallback)
  290. {
  291. (*s_ErrorCallback)(m1, title, s_DisableMessages,
  292. s_ErrorCallbackClientData);
  293. return;
  294. }
  295. else
  296. {
  297. std::cerr << m1 << std::endl << std::flush;
  298. }
  299. }
  300. void cmSystemTools::ReportLastSystemError(const char* msg)
  301. {
  302. std::string m = msg;
  303. m += ": System Error: ";
  304. m += Superclass::GetLastSystemError();
  305. cmSystemTools::Error(m.c_str());
  306. }
  307. bool cmSystemTools::IsOn(const char* val)
  308. {
  309. if (!val)
  310. {
  311. return false;
  312. }
  313. std::basic_string<char> v = val;
  314. for(std::basic_string<char>::iterator c = v.begin();
  315. c != v.end(); c++)
  316. {
  317. *c = toupper(*c);
  318. }
  319. return (v == "ON" || v == "1" || v == "YES" || v == "TRUE" || v == "Y");
  320. }
  321. bool cmSystemTools::IsNOTFOUND(const char* val)
  322. {
  323. size_t len = strlen(val);
  324. const char* notfound = "-NOTFOUND";
  325. const size_t lenNotFound = 9;
  326. if(len < lenNotFound-1)
  327. {
  328. return false;
  329. }
  330. if(len == lenNotFound-1)
  331. {
  332. return ( strcmp(val, "NOTFOUND") == 0);
  333. }
  334. return ((strncmp((val + (len - lenNotFound)), notfound, lenNotFound) == 0));
  335. }
  336. bool cmSystemTools::IsOff(const char* val)
  337. {
  338. if (!val || strlen(val) == 0)
  339. {
  340. return true;
  341. }
  342. std::basic_string<char> v = val;
  343. for(std::basic_string<char>::iterator c = v.begin();
  344. c != v.end(); c++)
  345. {
  346. *c = toupper(*c);
  347. }
  348. return (v == "OFF" || v == "0" || v == "NO" || v == "FALSE" ||
  349. v == "N" || cmSystemTools::IsNOTFOUND(v.c_str()) || v == "IGNORE");
  350. }
  351. //----------------------------------------------------------------------------
  352. void cmSystemTools::ParseWindowsCommandLine(const char* command,
  353. std::vector<std::string>& args)
  354. {
  355. // See the MSDN document "Parsing C Command-Line Arguments" at
  356. // http://msdn2.microsoft.com/en-us/library/a1y7w461.aspx for rules
  357. // of parsing the windows command line.
  358. bool in_argument = false;
  359. bool in_quotes = false;
  360. int backslashes = 0;
  361. std::string arg;
  362. for(const char* c = command;*c; ++c)
  363. {
  364. if(*c == '\\')
  365. {
  366. ++backslashes;
  367. in_argument = true;
  368. }
  369. else if(*c == '"')
  370. {
  371. int backslash_pairs = backslashes >> 1;
  372. int backslash_escaped = backslashes & 1;
  373. arg.append(backslash_pairs, '\\');
  374. backslashes = 0;
  375. if(backslash_escaped)
  376. {
  377. /* An odd number of backslashes precede this quote.
  378. It is escaped. */
  379. arg.append(1, '"');
  380. }
  381. else
  382. {
  383. /* An even number of backslashes precede this quote.
  384. It is not escaped. */
  385. in_quotes = !in_quotes;
  386. }
  387. in_argument = true;
  388. }
  389. else
  390. {
  391. arg.append(backslashes, '\\');
  392. backslashes = 0;
  393. if(isspace(*c))
  394. {
  395. if(in_quotes)
  396. {
  397. arg.append(1, *c);
  398. }
  399. else if(in_argument)
  400. {
  401. args.push_back(arg);
  402. arg = "";
  403. in_argument = false;
  404. }
  405. }
  406. else
  407. {
  408. in_argument = true;
  409. arg.append(1, *c);
  410. }
  411. }
  412. }
  413. arg.append(backslashes, '\\');
  414. if(in_argument)
  415. {
  416. args.push_back(arg);
  417. }
  418. }
  419. std::string cmSystemTools::EscapeWindowsShellArgument(const char* arg,
  420. int shell_flags)
  421. {
  422. char local_buffer[1024];
  423. char* buffer = local_buffer;
  424. int size = cmsysSystem_Shell_GetArgumentSizeForWindows(arg, shell_flags);
  425. if(size > 1024)
  426. {
  427. buffer = new char[size];
  428. }
  429. cmsysSystem_Shell_GetArgumentForWindows(arg, buffer, shell_flags);
  430. std::string result(buffer);
  431. if(buffer != local_buffer)
  432. {
  433. delete [] buffer;
  434. }
  435. return result;
  436. }
  437. std::vector<cmStdString> cmSystemTools::ParseArguments(const char* command)
  438. {
  439. std::vector<cmStdString> args;
  440. std::string arg;
  441. bool win_path = false;
  442. if ( command[0] != '/' && command[1] == ':' && command[2] == '\\' ||
  443. command[0] == '\"' && command[1] != '/' && command[2] == ':'
  444. && command[3] == '\\' ||
  445. command[0] == '\'' && command[1] != '/' && command[2] == ':'
  446. && command[3] == '\\' ||
  447. command[0] == '\\' && command[1] == '\\')
  448. {
  449. win_path = true;
  450. }
  451. // Split the command into an argv array.
  452. for(const char* c = command; *c;)
  453. {
  454. // Skip over whitespace.
  455. while(*c == ' ' || *c == '\t')
  456. {
  457. ++c;
  458. }
  459. arg = "";
  460. if(*c == '"')
  461. {
  462. // Parse a quoted argument.
  463. ++c;
  464. while(*c && *c != '"')
  465. {
  466. arg.append(1, *c);
  467. ++c;
  468. }
  469. if(*c)
  470. {
  471. ++c;
  472. }
  473. args.push_back(arg);
  474. }
  475. else if(*c == '\'')
  476. {
  477. // Parse a quoted argument.
  478. ++c;
  479. while(*c && *c != '\'')
  480. {
  481. arg.append(1, *c);
  482. ++c;
  483. }
  484. if(*c)
  485. {
  486. ++c;
  487. }
  488. args.push_back(arg);
  489. }
  490. else if(*c)
  491. {
  492. // Parse an unquoted argument.
  493. while(*c && *c != ' ' && *c != '\t')
  494. {
  495. if(*c == '\\' && !win_path)
  496. {
  497. ++c;
  498. if(*c)
  499. {
  500. arg.append(1, *c);
  501. ++c;
  502. }
  503. }
  504. else
  505. {
  506. arg.append(1, *c);
  507. ++c;
  508. }
  509. }
  510. args.push_back(arg);
  511. }
  512. }
  513. return args;
  514. }
  515. bool cmSystemTools::RunSingleCommand(
  516. const char* command,
  517. std::string* output,
  518. int *retVal,
  519. const char* dir,
  520. bool verbose,
  521. double timeout)
  522. {
  523. if(s_DisableRunCommandOutput)
  524. {
  525. verbose = false;
  526. }
  527. std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
  528. if(args.size() < 1)
  529. {
  530. return false;
  531. }
  532. std::vector<const char*> argv;
  533. for(std::vector<cmStdString>::const_iterator a = args.begin();
  534. a != args.end(); ++a)
  535. {
  536. argv.push_back(a->c_str());
  537. }
  538. argv.push_back(0);
  539. if ( output )
  540. {
  541. *output = "";
  542. }
  543. cmsysProcess* cp = cmsysProcess_New();
  544. cmsysProcess_SetCommand(cp, &*argv.begin());
  545. cmsysProcess_SetWorkingDirectory(cp, dir);
  546. if(cmSystemTools::GetRunCommandHideConsole())
  547. {
  548. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  549. }
  550. cmsysProcess_SetTimeout(cp, timeout);
  551. cmsysProcess_Execute(cp);
  552. std::vector<char> tempOutput;
  553. char* data;
  554. int length;
  555. if ( output || verbose )
  556. {
  557. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  558. {
  559. if(output || verbose)
  560. {
  561. // Translate NULL characters in the output into valid text.
  562. // Visual Studio 7 puts these characters in the output of its
  563. // build process.
  564. for(int i=0; i < length; ++i)
  565. {
  566. if(data[i] == '\0')
  567. {
  568. data[i] = ' ';
  569. }
  570. }
  571. }
  572. if ( output )
  573. {
  574. tempOutput.insert(tempOutput.end(), data, data+length);
  575. }
  576. if(verbose)
  577. {
  578. cmSystemTools::Stdout(data, length);
  579. }
  580. }
  581. }
  582. cmsysProcess_WaitForExit(cp, 0);
  583. if ( output && tempOutput.begin() != tempOutput.end())
  584. {
  585. output->append(&*tempOutput.begin(), tempOutput.size());
  586. }
  587. bool result = true;
  588. if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exited)
  589. {
  590. if ( retVal )
  591. {
  592. *retVal = cmsysProcess_GetExitValue(cp);
  593. }
  594. else
  595. {
  596. if ( cmsysProcess_GetExitValue(cp) != 0 )
  597. {
  598. result = false;
  599. }
  600. }
  601. }
  602. else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exception)
  603. {
  604. const char* exception_str = cmsysProcess_GetExceptionString(cp);
  605. if ( verbose )
  606. {
  607. std::cerr << exception_str << std::endl;
  608. }
  609. if ( output )
  610. {
  611. output->append(exception_str, strlen(exception_str));
  612. }
  613. result = false;
  614. }
  615. else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Error)
  616. {
  617. const char* error_str = cmsysProcess_GetErrorString(cp);
  618. if ( verbose )
  619. {
  620. std::cerr << error_str << std::endl;
  621. }
  622. if ( output )
  623. {
  624. output->append(error_str, strlen(error_str));
  625. }
  626. result = false;
  627. }
  628. else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Expired)
  629. {
  630. const char* error_str = "Process terminated due to timeout\n";
  631. if ( verbose )
  632. {
  633. std::cerr << error_str << std::endl;
  634. }
  635. if ( output )
  636. {
  637. output->append(error_str, strlen(error_str));
  638. }
  639. result = false;
  640. }
  641. cmsysProcess_Delete(cp);
  642. return result;
  643. }
  644. bool cmSystemTools::RunCommand(const char* command,
  645. std::string& output,
  646. const char* dir,
  647. bool verbose,
  648. int timeout)
  649. {
  650. int dummy;
  651. return cmSystemTools::RunCommand(command, output, dummy,
  652. dir, verbose, timeout);
  653. }
  654. #if defined(WIN32) && !defined(__CYGWIN__)
  655. #include "cmWin32ProcessExecution.h"
  656. // use this for shell commands like echo and dir
  657. bool RunCommandViaWin32(const char* command,
  658. const char* dir,
  659. std::string& output,
  660. int& retVal,
  661. bool verbose,
  662. int timeout)
  663. {
  664. #if defined(__BORLANDC__)
  665. return
  666. cmWin32ProcessExecution::
  667. BorlandRunCommand(command, dir, output,
  668. retVal,
  669. verbose, timeout,
  670. cmSystemTools::GetRunCommandHideConsole());
  671. #else // Visual studio
  672. ::SetLastError(ERROR_SUCCESS);
  673. if ( ! command )
  674. {
  675. cmSystemTools::Error("No command specified");
  676. return false;
  677. }
  678. cmWin32ProcessExecution resProc;
  679. if(cmSystemTools::GetRunCommandHideConsole())
  680. {
  681. resProc.SetHideWindows(true);
  682. }
  683. if ( cmSystemTools::GetWindows9xComspecSubstitute() )
  684. {
  685. resProc.SetConsoleSpawn(cmSystemTools::GetWindows9xComspecSubstitute() );
  686. }
  687. if ( !resProc.StartProcess(command, dir, verbose) )
  688. {
  689. output = resProc.GetOutput();
  690. if(verbose)
  691. {
  692. cmSystemTools::Stdout(output.c_str());
  693. }
  694. return false;
  695. }
  696. resProc.Wait(timeout);
  697. output = resProc.GetOutput();
  698. retVal = resProc.GetExitValue();
  699. return true;
  700. #endif
  701. }
  702. // use this for shell commands like echo and dir
  703. bool RunCommandViaSystem(const char* command,
  704. const char* dir,
  705. std::string& output,
  706. int& retVal,
  707. bool verbose)
  708. {
  709. std::cout << "@@ " << command << std::endl;
  710. std::string commandInDir;
  711. if(dir)
  712. {
  713. commandInDir = "cd ";
  714. commandInDir += cmSystemTools::ConvertToOutputPath(dir);
  715. commandInDir += " && ";
  716. commandInDir += command;
  717. }
  718. else
  719. {
  720. commandInDir = command;
  721. }
  722. command = commandInDir.c_str();
  723. std::string commandToFile = command;
  724. commandToFile += " > ";
  725. std::string tempFile;
  726. tempFile += _tempnam(0, "cmake");
  727. commandToFile += tempFile;
  728. retVal = system(commandToFile.c_str());
  729. std::ifstream fin(tempFile.c_str());
  730. if(!fin)
  731. {
  732. if(verbose)
  733. {
  734. std::string errormsg = "RunCommand produced no output: command: \"";
  735. errormsg += command;
  736. errormsg += "\"";
  737. errormsg += "\nOutput file: ";
  738. errormsg += tempFile;
  739. cmSystemTools::Error(errormsg.c_str());
  740. }
  741. fin.close();
  742. cmSystemTools::RemoveFile(tempFile.c_str());
  743. return false;
  744. }
  745. bool multiLine = false;
  746. std::string line;
  747. while(cmSystemTools::GetLineFromStream(fin, line))
  748. {
  749. output += line;
  750. if(multiLine)
  751. {
  752. output += "\n";
  753. }
  754. multiLine = true;
  755. }
  756. fin.close();
  757. cmSystemTools::RemoveFile(tempFile.c_str());
  758. return true;
  759. }
  760. #else // We have popen
  761. // BeOS seems to return from a successful pclose() before the process has
  762. // legitimately exited, or at least before SIGCHLD is thrown...the signal may
  763. // come quite some time after pclose returns! This causes havoc with later
  764. // parts of CMake that expect to catch the signal from other child processes,
  765. // so we explicitly wait to catch it here. This should be safe to do with
  766. // popen() so long as we don't actually collect the zombie process ourselves.
  767. #ifdef __BEOS__
  768. #include <signal.h>
  769. #undef SIGBUS // this is the same as SIGSEGV on BeOS and causes issues below.
  770. static volatile bool beos_seen_signal = false;
  771. static void beos_popen_workaround(int sig)
  772. {
  773. beos_seen_signal = true;
  774. }
  775. #endif
  776. bool RunCommandViaPopen(const char* command,
  777. const char* dir,
  778. std::string& output,
  779. int& retVal,
  780. bool verbose,
  781. int /*timeout*/)
  782. {
  783. // if only popen worked on windows.....
  784. std::string commandInDir;
  785. if(dir)
  786. {
  787. commandInDir = "cd \"";
  788. commandInDir += dir;
  789. commandInDir += "\" && ";
  790. commandInDir += command;
  791. }
  792. else
  793. {
  794. commandInDir = command;
  795. }
  796. commandInDir += " 2>&1";
  797. command = commandInDir.c_str();
  798. const int BUFFER_SIZE = 4096;
  799. char buffer[BUFFER_SIZE];
  800. if(verbose)
  801. {
  802. cmSystemTools::Stdout("running ");
  803. cmSystemTools::Stdout(command);
  804. cmSystemTools::Stdout("\n");
  805. }
  806. fflush(stdout);
  807. fflush(stderr);
  808. #ifdef __BEOS__
  809. beos_seen_signal = false;
  810. signal(SIGCHLD, beos_popen_workaround);
  811. #endif
  812. FILE* cpipe = popen(command, "r");
  813. if(!cpipe)
  814. {
  815. #ifdef __BEOS__
  816. signal(SIGCHLD, SIG_DFL);
  817. #endif
  818. return false;
  819. }
  820. fgets(buffer, BUFFER_SIZE, cpipe);
  821. while(!feof(cpipe))
  822. {
  823. if(verbose)
  824. {
  825. cmSystemTools::Stdout(buffer);
  826. }
  827. output += buffer;
  828. fgets(buffer, BUFFER_SIZE, cpipe);
  829. }
  830. retVal = pclose(cpipe);
  831. #ifdef __BEOS__
  832. for (int i = 0; (!beos_seen_signal) && (i < 3); i++)
  833. {
  834. ::sleep(1); // signals should interrupt this...
  835. }
  836. if (!beos_seen_signal)
  837. {
  838. signal(SIGCHLD, SIG_DFL); // oh well, didn't happen. Go on anyhow.
  839. }
  840. #endif
  841. if (WIFEXITED(retVal))
  842. {
  843. retVal = WEXITSTATUS(retVal);
  844. return true;
  845. }
  846. if (WIFSIGNALED(retVal))
  847. {
  848. retVal = WTERMSIG(retVal);
  849. cmOStringStream error;
  850. error << "\nProcess terminated due to ";
  851. switch (retVal)
  852. {
  853. #ifdef SIGKILL
  854. case SIGKILL:
  855. error << "SIGKILL";
  856. break;
  857. #endif
  858. #ifdef SIGFPE
  859. case SIGFPE:
  860. error << "SIGFPE";
  861. break;
  862. #endif
  863. #ifdef SIGBUS
  864. case SIGBUS:
  865. error << "SIGBUS";
  866. break;
  867. #endif
  868. #ifdef SIGSEGV
  869. case SIGSEGV:
  870. error << "SIGSEGV";
  871. break;
  872. #endif
  873. default:
  874. error << "signal " << retVal;
  875. break;
  876. }
  877. output += error.str();
  878. }
  879. return false;
  880. }
  881. #endif // endif WIN32 not CYGWIN
  882. // run a command unix uses popen (easy)
  883. // windows uses system and ShortPath
  884. bool cmSystemTools::RunCommand(const char* command,
  885. std::string& output,
  886. int &retVal,
  887. const char* dir,
  888. bool verbose,
  889. int timeout)
  890. {
  891. if(s_DisableRunCommandOutput)
  892. {
  893. verbose = false;
  894. }
  895. #if defined(WIN32) && !defined(__CYGWIN__)
  896. // if the command does not start with a quote, then
  897. // try to find the program, and if the program can not be
  898. // found use system to run the command as it must be a built in
  899. // shell command like echo or dir
  900. int count = 0;
  901. if(command[0] == '\"')
  902. {
  903. // count the number of quotes
  904. for(const char* s = command; *s != 0; ++s)
  905. {
  906. if(*s == '\"')
  907. {
  908. count++;
  909. if(count > 2)
  910. {
  911. break;
  912. }
  913. }
  914. }
  915. // if there are more than two double quotes use
  916. // GetShortPathName, the cmd.exe program in windows which
  917. // is used by system fails to execute if there are more than
  918. // one set of quotes in the arguments
  919. if(count > 2)
  920. {
  921. cmsys::RegularExpression quoted("^\"([^\"]*)\"[ \t](.*)");
  922. if(quoted.find(command))
  923. {
  924. std::string shortCmd;
  925. std::string cmd = quoted.match(1);
  926. std::string args = quoted.match(2);
  927. if(! cmSystemTools::FileExists(cmd.c_str()) )
  928. {
  929. shortCmd = cmd;
  930. }
  931. else if(!cmSystemTools::GetShortPath(cmd.c_str(), shortCmd))
  932. {
  933. cmSystemTools::Error("GetShortPath failed for " , cmd.c_str());
  934. return false;
  935. }
  936. shortCmd += " ";
  937. shortCmd += args;
  938. //return RunCommandViaSystem(shortCmd.c_str(), dir,
  939. // output, retVal, verbose);
  940. //return WindowsRunCommand(shortCmd.c_str(), dir,
  941. //output, retVal, verbose);
  942. return RunCommandViaWin32(shortCmd.c_str(), dir,
  943. output, retVal, verbose, timeout);
  944. }
  945. else
  946. {
  947. cmSystemTools::Error("Could not parse command line with quotes ",
  948. command);
  949. }
  950. }
  951. }
  952. // if there is only one set of quotes or no quotes then just run the command
  953. //return RunCommandViaSystem(command, dir, output, retVal, verbose);
  954. //return WindowsRunCommand(command, dir, output, retVal, verbose);
  955. return ::RunCommandViaWin32(command, dir, output, retVal, verbose, timeout);
  956. #else
  957. return ::RunCommandViaPopen(command, dir, output, retVal, verbose, timeout);
  958. #endif
  959. }
  960. bool cmSystemTools::DoesFileExistWithExtensions(
  961. const char* name,
  962. const std::vector<std::string>& headerExts)
  963. {
  964. std::string hname;
  965. for( std::vector<std::string>::const_iterator ext = headerExts.begin();
  966. ext != headerExts.end(); ++ext )
  967. {
  968. hname = name;
  969. hname += ".";
  970. hname += *ext;
  971. if(cmSystemTools::FileExists(hname.c_str()))
  972. {
  973. return true;
  974. }
  975. }
  976. return false;
  977. }
  978. bool cmSystemTools::cmCopyFile(const char* source, const char* destination)
  979. {
  980. return Superclass::CopyFileAlways(source, destination);
  981. }
  982. bool cmSystemTools::CopyFileIfDifferent(const char* source,
  983. const char* destination)
  984. {
  985. return Superclass::CopyFileIfDifferent(source, destination);
  986. }
  987. bool cmSystemTools::ComputeFileMD5(const char* source, char* md5out)
  988. {
  989. #if defined(CMAKE_BUILD_WITH_CMAKE)
  990. if(!cmSystemTools::FileExists(source))
  991. {
  992. return false;
  993. }
  994. // Open files
  995. #if defined(_WIN32) || defined(__CYGWIN__)
  996. cmsys_ios::ifstream fin(source, cmsys_ios::ios::binary | cmsys_ios::ios::in);
  997. #else
  998. cmsys_ios::ifstream fin(source);
  999. #endif
  1000. if(!fin)
  1001. {
  1002. return false;
  1003. }
  1004. cmsysMD5* md5 = cmsysMD5_New();
  1005. cmsysMD5_Initialize(md5);
  1006. // Should be efficient enough on most system:
  1007. const int bufferSize = 4096;
  1008. char buffer[bufferSize];
  1009. // This copy loop is very sensitive on certain platforms with
  1010. // slightly broken stream libraries (like HPUX). Normally, it is
  1011. // incorrect to not check the error condition on the fin.read()
  1012. // before using the data, but the fin.gcount() will be zero if an
  1013. // error occurred. Therefore, the loop should be safe everywhere.
  1014. while(fin)
  1015. {
  1016. fin.read(buffer, bufferSize);
  1017. if(fin.gcount())
  1018. {
  1019. cmsysMD5_Append(md5, reinterpret_cast<unsigned char const*>(buffer),
  1020. fin.gcount());
  1021. }
  1022. }
  1023. cmsysMD5_FinalizeHex(md5, md5out);
  1024. cmsysMD5_Delete(md5);
  1025. fin.close();
  1026. return true;
  1027. #else
  1028. (void)source;
  1029. (void)md5out;
  1030. cmSystemTools::Message("md5sum not supported in bootstrapping mode","Error");
  1031. return false;
  1032. #endif
  1033. }
  1034. void cmSystemTools::Glob(const char *directory, const char *regexp,
  1035. std::vector<std::string>& files)
  1036. {
  1037. cmsys::Directory d;
  1038. cmsys::RegularExpression reg(regexp);
  1039. if (d.Load(directory))
  1040. {
  1041. size_t numf;
  1042. unsigned int i;
  1043. numf = d.GetNumberOfFiles();
  1044. for (i = 0; i < numf; i++)
  1045. {
  1046. std::string fname = d.GetFile(i);
  1047. if (reg.find(fname))
  1048. {
  1049. files.push_back(fname);
  1050. }
  1051. }
  1052. }
  1053. }
  1054. void cmSystemTools::GlobDirs(const char *fullPath,
  1055. std::vector<std::string>& files)
  1056. {
  1057. std::string path = fullPath;
  1058. std::string::size_type pos = path.find("/*");
  1059. if(pos == std::string::npos)
  1060. {
  1061. files.push_back(fullPath);
  1062. return;
  1063. }
  1064. std::string startPath = path.substr(0, pos);
  1065. std::string finishPath = path.substr(pos+2);
  1066. cmsys::Directory d;
  1067. if (d.Load(startPath.c_str()))
  1068. {
  1069. for (unsigned int i = 0; i < d.GetNumberOfFiles(); ++i)
  1070. {
  1071. if((std::string(d.GetFile(i)) != ".")
  1072. && (std::string(d.GetFile(i)) != ".."))
  1073. {
  1074. std::string fname = startPath;
  1075. fname +="/";
  1076. fname += d.GetFile(i);
  1077. if(cmSystemTools::FileIsDirectory(fname.c_str()))
  1078. {
  1079. fname += finishPath;
  1080. cmSystemTools::GlobDirs(fname.c_str(), files);
  1081. }
  1082. }
  1083. }
  1084. }
  1085. }
  1086. void cmSystemTools::ExpandList(std::vector<std::string> const& arguments,
  1087. std::vector<std::string>& newargs)
  1088. {
  1089. std::vector<std::string>::const_iterator i;
  1090. for(i = arguments.begin();i != arguments.end(); ++i)
  1091. {
  1092. cmSystemTools::ExpandListArgument(*i, newargs);
  1093. }
  1094. }
  1095. void cmSystemTools::ExpandListArgument(const std::string& arg,
  1096. std::vector<std::string>& newargs,
  1097. bool emptyArgs)
  1098. {
  1099. // If argument is empty, it is an empty list.
  1100. if(arg.length() == 0 && !emptyArgs)
  1101. {
  1102. return;
  1103. }
  1104. // if there are no ; in the name then just copy the current string
  1105. if(arg.find(';') == std::string::npos)
  1106. {
  1107. newargs.push_back(arg);
  1108. return;
  1109. }
  1110. std::vector<char> newArgVec;
  1111. // Break the string at non-escaped semicolons not nested in [].
  1112. int squareNesting = 0;
  1113. for(const char* c = arg.c_str(); *c; ++c)
  1114. {
  1115. switch(*c)
  1116. {
  1117. case '\\':
  1118. {
  1119. // We only want to allow escaping of semicolons. Other
  1120. // escapes should not be processed here.
  1121. ++c;
  1122. if(*c == ';')
  1123. {
  1124. newArgVec.push_back(*c);
  1125. }
  1126. else
  1127. {
  1128. newArgVec.push_back('\\');
  1129. if(*c)
  1130. {
  1131. newArgVec.push_back(*c);
  1132. }
  1133. else
  1134. {
  1135. // Terminate the loop properly.
  1136. --c;
  1137. }
  1138. }
  1139. } break;
  1140. case '[':
  1141. {
  1142. ++squareNesting;
  1143. newArgVec.push_back(*c);
  1144. } break;
  1145. case ']':
  1146. {
  1147. --squareNesting;
  1148. newArgVec.push_back(*c);
  1149. } break;
  1150. case ';':
  1151. {
  1152. // Break the string here if we are not nested inside square
  1153. // brackets.
  1154. if(squareNesting == 0)
  1155. {
  1156. if ( newArgVec.size() || emptyArgs )
  1157. {
  1158. // Add the last argument if the string is not empty.
  1159. newArgVec.push_back(0);
  1160. newargs.push_back(&*newArgVec.begin());
  1161. newArgVec.clear();
  1162. }
  1163. }
  1164. else
  1165. {
  1166. newArgVec.push_back(*c);
  1167. }
  1168. } break;
  1169. default:
  1170. {
  1171. // Just append this character.
  1172. newArgVec.push_back(*c);
  1173. } break;
  1174. }
  1175. }
  1176. if ( newArgVec.size() || emptyArgs )
  1177. {
  1178. // Add the last argument if the string is not empty.
  1179. newArgVec.push_back(0);
  1180. newargs.push_back(&*newArgVec.begin());
  1181. }
  1182. }
  1183. bool cmSystemTools::SimpleGlob(const cmStdString& glob,
  1184. std::vector<cmStdString>& files,
  1185. int type /* = 0 */)
  1186. {
  1187. files.clear();
  1188. if ( glob[glob.size()-1] != '*' )
  1189. {
  1190. return false;
  1191. }
  1192. std::string path = cmSystemTools::GetFilenamePath(glob);
  1193. std::string ppath = cmSystemTools::GetFilenameName(glob);
  1194. ppath = ppath.substr(0, ppath.size()-1);
  1195. if ( path.size() == 0 )
  1196. {
  1197. path = "/";
  1198. }
  1199. bool res = false;
  1200. cmsys::Directory d;
  1201. if (d.Load(path.c_str()))
  1202. {
  1203. for (unsigned int i = 0; i < d.GetNumberOfFiles(); ++i)
  1204. {
  1205. if((std::string(d.GetFile(i)) != ".")
  1206. && (std::string(d.GetFile(i)) != ".."))
  1207. {
  1208. std::string fname = path;
  1209. if ( path[path.size()-1] != '/' )
  1210. {
  1211. fname +="/";
  1212. }
  1213. fname += d.GetFile(i);
  1214. std::string sfname = d.GetFile(i);
  1215. if ( type > 0 && cmSystemTools::FileIsDirectory(fname.c_str()) )
  1216. {
  1217. continue;
  1218. }
  1219. if ( type < 0 && !cmSystemTools::FileIsDirectory(fname.c_str()) )
  1220. {
  1221. continue;
  1222. }
  1223. if ( sfname.size() >= ppath.size() &&
  1224. sfname.substr(0, ppath.size()) ==
  1225. ppath )
  1226. {
  1227. files.push_back(fname);
  1228. res = true;
  1229. }
  1230. }
  1231. }
  1232. }
  1233. return res;
  1234. }
  1235. cmSystemTools::FileFormat cmSystemTools::GetFileFormat(const char* cext)
  1236. {
  1237. if ( ! cext || *cext == 0 )
  1238. {
  1239. return cmSystemTools::NO_FILE_FORMAT;
  1240. }
  1241. //std::string ext = cmSystemTools::LowerCase(cext);
  1242. std::string ext = cext;
  1243. if ( ext == "c" || ext == ".c" ) { return cmSystemTools::C_FILE_FORMAT; }
  1244. if (
  1245. ext == "C" || ext == ".C" ||
  1246. ext == "M" || ext == ".M" ||
  1247. ext == "c++" || ext == ".c++" ||
  1248. ext == "cc" || ext == ".cc" ||
  1249. ext == "cpp" || ext == ".cpp" ||
  1250. ext == "cxx" || ext == ".cxx" ||
  1251. ext == "m" || ext == ".m" ||
  1252. ext == "mm" || ext == ".mm"
  1253. ) { return cmSystemTools::CXX_FILE_FORMAT; }
  1254. if (
  1255. ext == "f" || ext == ".f" ||
  1256. ext == "F" || ext == ".F" ||
  1257. ext == "f77" || ext == ".f77" ||
  1258. ext == "f90" || ext == ".f90" ||
  1259. ext == "for" || ext == ".for" ||
  1260. ext == "f95" || ext == ".f95"
  1261. ) { return cmSystemTools::FORTRAN_FILE_FORMAT; }
  1262. if ( ext == "java" || ext == ".java" )
  1263. { return cmSystemTools::JAVA_FILE_FORMAT; }
  1264. if (
  1265. ext == "H" || ext == ".H" ||
  1266. ext == "h" || ext == ".h" ||
  1267. ext == "h++" || ext == ".h++" ||
  1268. ext == "hm" || ext == ".hm" ||
  1269. ext == "hpp" || ext == ".hpp" ||
  1270. ext == "hxx" || ext == ".hxx" ||
  1271. ext == "in" || ext == ".in" ||
  1272. ext == "txx" || ext == ".txx"
  1273. ) { return cmSystemTools::HEADER_FILE_FORMAT; }
  1274. if ( ext == "rc" || ext == ".rc" )
  1275. { return cmSystemTools::RESOURCE_FILE_FORMAT; }
  1276. if ( ext == "def" || ext == ".def" )
  1277. { return cmSystemTools::DEFINITION_FILE_FORMAT; }
  1278. if ( ext == "lib" || ext == ".lib" ||
  1279. ext == "a" || ext == ".a")
  1280. { return cmSystemTools::STATIC_LIBRARY_FILE_FORMAT; }
  1281. if ( ext == "o" || ext == ".o" ||
  1282. ext == "obj" || ext == ".obj")
  1283. { return cmSystemTools::OBJECT_FILE_FORMAT; }
  1284. #ifdef __APPLE__
  1285. if ( ext == "dylib" || ext == ".dylib" )
  1286. { return cmSystemTools::SHARED_LIBRARY_FILE_FORMAT; }
  1287. if ( ext == "so" || ext == ".so" ||
  1288. ext == "bundle" || ext == ".bundle" )
  1289. { return cmSystemTools::MODULE_FILE_FORMAT; }
  1290. #else // __APPLE__
  1291. if ( ext == "so" || ext == ".so" ||
  1292. ext == "sl" || ext == ".sl" ||
  1293. ext == "dll" || ext == ".dll" )
  1294. { return cmSystemTools::SHARED_LIBRARY_FILE_FORMAT; }
  1295. #endif // __APPLE__
  1296. return cmSystemTools::UNKNOWN_FILE_FORMAT;
  1297. }
  1298. bool cmSystemTools::Split(const char* s, std::vector<cmStdString>& l)
  1299. {
  1300. std::vector<std::string> temp;
  1301. bool res = Superclass::Split(s, temp);
  1302. for(std::vector<std::string>::const_iterator i = temp.begin();
  1303. i != temp.end(); ++i)
  1304. {
  1305. l.push_back(*i);
  1306. }
  1307. return res;
  1308. }
  1309. std::string cmSystemTools::ConvertToOutputPath(const char* path)
  1310. {
  1311. #if defined(_WIN32) && !defined(__CYGWIN__)
  1312. if(s_ForceUnixPaths)
  1313. {
  1314. return cmSystemTools::ConvertToUnixOutputPath(path);
  1315. }
  1316. return cmSystemTools::ConvertToWindowsOutputPath(path);
  1317. #else
  1318. return cmSystemTools::ConvertToUnixOutputPath(path);
  1319. #endif
  1320. }
  1321. void cmSystemTools::ConvertToOutputSlashes(std::string& path)
  1322. {
  1323. #if defined(_WIN32) && !defined(__CYGWIN__)
  1324. if(!s_ForceUnixPaths)
  1325. {
  1326. // Convert to windows slashes.
  1327. std::string::size_type pos = 0;
  1328. while((pos = path.find('/', pos)) != std::string::npos)
  1329. {
  1330. path[pos++] = '\\';
  1331. }
  1332. }
  1333. #else
  1334. static_cast<void>(path);
  1335. #endif
  1336. }
  1337. std::string cmSystemTools::ConvertToRunCommandPath(const char* path)
  1338. {
  1339. #if defined(_WIN32) && !defined(__CYGWIN__)
  1340. return cmSystemTools::ConvertToWindowsOutputPath(path);
  1341. #else
  1342. return cmSystemTools::ConvertToUnixOutputPath(path);
  1343. #endif
  1344. }
  1345. bool cmSystemTools::StringEndsWith(const char* str1, const char* str2)
  1346. {
  1347. if ( !str1 || !str2 || strlen(str1) < strlen(str2) )
  1348. {
  1349. return 0;
  1350. }
  1351. return !strncmp(str1 + (strlen(str1)-strlen(str2)), str2, strlen(str2));
  1352. }
  1353. // compute the relative path from here to there
  1354. std::string cmSystemTools::RelativePath(const char* local, const char* remote)
  1355. {
  1356. if(!cmSystemTools::FileIsFullPath(local))
  1357. {
  1358. cmSystemTools::Error("RelativePath must be passed a full path to local: ",
  1359. local);
  1360. }
  1361. if(!cmSystemTools::FileIsFullPath(remote))
  1362. {
  1363. cmSystemTools::Error
  1364. ("RelativePath must be passed a full path to remote: ", remote);
  1365. }
  1366. return cmsys::SystemTools::RelativePath(local, remote);
  1367. }
  1368. class cmDeletingCharVector : public std::vector<char*>
  1369. {
  1370. public:
  1371. ~cmDeletingCharVector()
  1372. {
  1373. for(std::vector<char*>::iterator i = this->begin();
  1374. i != this->end(); ++i)
  1375. {
  1376. delete []*i;
  1377. }
  1378. }
  1379. };
  1380. bool cmSystemTools::PutEnv(const char* value)
  1381. {
  1382. static cmDeletingCharVector localEnvironment;
  1383. char* envVar = new char[strlen(value)+1];
  1384. strcpy(envVar, value);
  1385. int ret = putenv(envVar);
  1386. // save the pointer in the static vector so that it can
  1387. // be deleted on exit
  1388. localEnvironment.push_back(envVar);
  1389. return ret == 0;
  1390. }
  1391. #ifdef CMAKE_BUILD_WITH_CMAKE
  1392. bool cmSystemTools::UnsetEnv(const char* value)
  1393. {
  1394. #if !defined(HAVE_UNSETENV)
  1395. std::string var = value;
  1396. var += "=";
  1397. return cmSystemTools::PutEnv(var.c_str());
  1398. #else
  1399. unsetenv(value);
  1400. return true;
  1401. #endif
  1402. }
  1403. std::vector<std::string> cmSystemTools::GetEnvironmentVariables()
  1404. {
  1405. std::vector<std::string> env;
  1406. int cc;
  1407. for ( cc = 0; environ[cc]; ++ cc )
  1408. {
  1409. env.push_back(environ[cc]);
  1410. }
  1411. return env;
  1412. }
  1413. #endif
  1414. void cmSystemTools::EnableVSConsoleOutput()
  1415. {
  1416. // Visual Studio 8 2005 (devenv.exe or VCExpress.exe) will not
  1417. // display output to the console unless this environment variable is
  1418. // set. We need it to capture the output of these build tools.
  1419. // Note for future work that one could pass "/out \\.\pipe\NAME" to
  1420. // either of these executables where NAME is created with
  1421. // CreateNamedPipe. This would bypass the internal buffering of the
  1422. // output and allow it to be captured on the fly.
  1423. #ifdef _WIN32
  1424. cmSystemTools::PutEnv("vsconsoleoutput=1");
  1425. #endif
  1426. }
  1427. std::string cmSystemTools::MakeXMLSafe(const char* str)
  1428. {
  1429. std::vector<char> result;
  1430. result.reserve(500);
  1431. const char* pos = str;
  1432. for ( ;*pos; ++pos)
  1433. {
  1434. char ch = *pos;
  1435. if ( (ch > 126 || ch < 32) && ch != 9 && ch != 10 && ch != 13
  1436. && ch != '\r' )
  1437. {
  1438. char buffer[33];
  1439. sprintf(buffer, "&lt;%d&gt;", static_cast<int>(ch));
  1440. //sprintf(buffer, "&#x%0x;", (unsigned int)ch);
  1441. result.insert(result.end(), buffer, buffer+strlen(buffer));
  1442. }
  1443. else
  1444. {
  1445. const char* const encodedChars[] = {
  1446. "&amp;",
  1447. "&lt;",
  1448. "&gt;"
  1449. };
  1450. switch ( ch )
  1451. {
  1452. case '&':
  1453. result.insert(result.end(), encodedChars[0], encodedChars[0]+5);
  1454. break;
  1455. case '<':
  1456. result.insert(result.end(), encodedChars[1], encodedChars[1]+4);
  1457. break;
  1458. case '>':
  1459. result.insert(result.end(), encodedChars[2], encodedChars[2]+4);
  1460. break;
  1461. case '\n':
  1462. result.push_back('\n');
  1463. break;
  1464. case '\r': break; // Ignore \r
  1465. default:
  1466. result.push_back(ch);
  1467. }
  1468. }
  1469. }
  1470. if ( result.size() == 0 )
  1471. {
  1472. return "";
  1473. }
  1474. return std::string(&*result.begin(), result.size());
  1475. }
  1476. bool cmSystemTools::IsPathToFramework(const char* path)
  1477. {
  1478. if(cmSystemTools::FileIsFullPath(path))
  1479. {
  1480. std::string libname = path;
  1481. if(libname.find(".framework") == libname.size()+1-sizeof(".framework"))
  1482. {
  1483. return true;
  1484. }
  1485. }
  1486. return false;
  1487. }
  1488. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1489. struct cmSystemToolsGZStruct
  1490. {
  1491. gzFile GZFile;
  1492. };
  1493. extern "C" {
  1494. int cmSystemToolsGZStructOpen(void* call_data, const char *pathname,
  1495. int oflags, mode_t mode);
  1496. int cmSystemToolsGZStructClose(void* call_data);
  1497. ssize_t cmSystemToolsGZStructRead(void* call_data, void* buf, size_t count);
  1498. ssize_t cmSystemToolsGZStructWrite(void* call_data, const void* buf,
  1499. size_t count);
  1500. }
  1501. int cmSystemToolsGZStructOpen(void* call_data, const char *pathname,
  1502. int oflags, mode_t mode)
  1503. {
  1504. const char *gzoflags;
  1505. int fd;
  1506. cmSystemToolsGZStruct* gzf = static_cast<cmSystemToolsGZStruct*>(call_data);
  1507. switch (oflags & O_ACCMODE)
  1508. {
  1509. case O_WRONLY:
  1510. gzoflags = "wb";
  1511. break;
  1512. case O_RDONLY:
  1513. gzoflags = "rb";
  1514. break;
  1515. default:
  1516. case O_RDWR:
  1517. errno = EINVAL;
  1518. return -1;
  1519. }
  1520. fd = open(pathname, oflags, mode);
  1521. if (fd == -1)
  1522. {
  1523. return -1;
  1524. }
  1525. // no fchmod on BeOS 5...do pathname instead.
  1526. #if defined(__BEOS__) && !defined(__ZETA__)
  1527. if ((oflags & O_CREAT) && chmod(pathname, mode))
  1528. {
  1529. return -1;
  1530. }
  1531. #elif !defined(_WIN32) || defined(__CYGWIN__)
  1532. if ((oflags & O_CREAT) && fchmod(fd, mode))
  1533. {
  1534. return -1;
  1535. }
  1536. #endif
  1537. gzf->GZFile = gzdopen(fd, gzoflags);
  1538. if (!gzf->GZFile)
  1539. {
  1540. errno = ENOMEM;
  1541. return -1;
  1542. }
  1543. return fd;
  1544. }
  1545. int cmSystemToolsGZStructClose(void* call_data)
  1546. {
  1547. cmSystemToolsGZStruct* gzf = static_cast<cmSystemToolsGZStruct*>(call_data);
  1548. return gzclose(gzf->GZFile);
  1549. }
  1550. ssize_t cmSystemToolsGZStructRead(void* call_data, void* buf, size_t count)
  1551. {
  1552. cmSystemToolsGZStruct* gzf = static_cast<cmSystemToolsGZStruct*>(call_data);
  1553. return gzread(gzf->GZFile, buf, static_cast<int>(count));
  1554. }
  1555. ssize_t cmSystemToolsGZStructWrite(void* call_data, const void* buf,
  1556. size_t count)
  1557. {
  1558. cmSystemToolsGZStruct* gzf = static_cast<cmSystemToolsGZStruct*>(call_data);
  1559. return gzwrite(gzf->GZFile, (void*)buf, static_cast<int>(count));
  1560. }
  1561. #endif
  1562. bool cmSystemTools::CreateTar(const char* outFileName,
  1563. const std::vector<cmStdString>& files,
  1564. bool gzip, bool verbose)
  1565. {
  1566. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1567. TAR *t;
  1568. char buf[TAR_MAXPATHLEN];
  1569. char pathname[TAR_MAXPATHLEN];
  1570. cmSystemToolsGZStruct gzs;
  1571. tartype_t gztype = {
  1572. (openfunc_t)cmSystemToolsGZStructOpen,
  1573. (closefunc_t)cmSystemToolsGZStructClose,
  1574. (readfunc_t)cmSystemToolsGZStructRead,
  1575. (writefunc_t)cmSystemToolsGZStructWrite,
  1576. &gzs
  1577. };
  1578. // Ok, this libtar is not const safe. for now use auto_ptr hack
  1579. char* realName = new char[ strlen(outFileName) + 1 ];
  1580. std::auto_ptr<char> realNamePtr(realName);
  1581. strcpy(realName, outFileName);
  1582. int options = 0;
  1583. if(verbose)
  1584. {
  1585. options |= TAR_VERBOSE;
  1586. }
  1587. #ifdef __CYGWIN__
  1588. options |= TAR_GNU;
  1589. #endif
  1590. if (tar_open(&t, realName,
  1591. (gzip? &gztype : NULL),
  1592. O_WRONLY | O_CREAT, 0644,
  1593. options) == -1)
  1594. {
  1595. cmSystemTools::Error("Problem with tar_open(): ", strerror(errno));
  1596. return false;
  1597. }
  1598. std::vector<cmStdString>::const_iterator it;
  1599. for (it = files.begin(); it != files.end(); ++ it )
  1600. {
  1601. strncpy(pathname, it->c_str(), sizeof(pathname));
  1602. pathname[sizeof(pathname)-1] = 0;
  1603. strncpy(buf, pathname, sizeof(buf));
  1604. buf[sizeof(buf)-1] = 0;
  1605. if (tar_append_tree(t, buf, pathname) != 0)
  1606. {
  1607. cmOStringStream ostr;
  1608. ostr << "Problem with tar_append_tree(\"" << buf << "\", \""
  1609. << pathname << "\"): "
  1610. << strerror(errno);
  1611. cmSystemTools::Error(ostr.str().c_str());
  1612. tar_close(t);
  1613. return false;
  1614. }
  1615. }
  1616. if (tar_append_eof(t) != 0)
  1617. {
  1618. cmSystemTools::Error("Problem with tar_append_eof(): ", strerror(errno));
  1619. tar_close(t);
  1620. return false;
  1621. }
  1622. if (tar_close(t) != 0)
  1623. {
  1624. cmSystemTools::Error("Problem with tar_close(): ", strerror(errno));
  1625. return false;
  1626. }
  1627. return true;
  1628. #else
  1629. (void)outFileName;
  1630. (void)files;
  1631. (void)gzip;
  1632. (void)verbose;
  1633. return false;
  1634. #endif
  1635. }
  1636. bool cmSystemTools::ExtractTar(const char* outFileName,
  1637. const std::vector<cmStdString>& files,
  1638. bool gzip, bool verbose)
  1639. {
  1640. (void)files;
  1641. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1642. TAR *t;
  1643. cmSystemToolsGZStruct gzs;
  1644. tartype_t gztype = {
  1645. cmSystemToolsGZStructOpen,
  1646. cmSystemToolsGZStructClose,
  1647. cmSystemToolsGZStructRead,
  1648. cmSystemToolsGZStructWrite,
  1649. &gzs
  1650. };
  1651. // Ok, this libtar is not const safe. for now use auto_ptr hack
  1652. char* realName = new char[ strlen(outFileName) + 1 ];
  1653. std::auto_ptr<char> realNamePtr(realName);
  1654. strcpy(realName, outFileName);
  1655. if (tar_open(&t, realName,
  1656. (gzip? &gztype : NULL),
  1657. O_RDONLY
  1658. #ifdef _WIN32
  1659. | O_BINARY
  1660. #endif
  1661. , 0,
  1662. (verbose?TAR_VERBOSE:0)
  1663. | 0) == -1)
  1664. {
  1665. cmSystemTools::Error("Problem with tar_open(): ", strerror(errno));
  1666. return false;
  1667. }
  1668. if (tar_extract_all(t, 0) != 0)
  1669. {
  1670. cmSystemTools::Error("Problem with tar_extract_all(): ", strerror(errno));
  1671. return false;
  1672. }
  1673. if (tar_close(t) != 0)
  1674. {
  1675. cmSystemTools::Error("Problem with tar_close(): ", strerror(errno));
  1676. return false;
  1677. }
  1678. return true;
  1679. #else
  1680. (void)outFileName;
  1681. (void)gzip;
  1682. (void)verbose;
  1683. return false;
  1684. #endif
  1685. }
  1686. bool cmSystemTools::ListTar(const char* outFileName,
  1687. std::vector<cmStdString>& files, bool gzip,
  1688. bool verbose)
  1689. {
  1690. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1691. TAR *t;
  1692. cmSystemToolsGZStruct gzs;
  1693. tartype_t gztype = {
  1694. cmSystemToolsGZStructOpen,
  1695. cmSystemToolsGZStructClose,
  1696. cmSystemToolsGZStructRead,
  1697. cmSystemToolsGZStructWrite,
  1698. &gzs
  1699. };
  1700. // Ok, this libtar is not const safe. for now use auto_ptr hack
  1701. char* realName = new char[ strlen(outFileName) + 1 ];
  1702. std::auto_ptr<char> realNamePtr(realName);
  1703. strcpy(realName, outFileName);
  1704. if (tar_open(&t, realName,
  1705. (gzip? &gztype : NULL),
  1706. O_RDONLY
  1707. #ifdef _WIN32
  1708. | O_BINARY
  1709. #endif
  1710. , 0,
  1711. (verbose?TAR_VERBOSE:0)
  1712. | 0) == -1)
  1713. {
  1714. cmSystemTools::Error("Problem with tar_open(): ", strerror(errno));
  1715. return false;
  1716. }
  1717. while ((th_read(t)) == 0)
  1718. {
  1719. const char* filename = th_get_pathname(t);
  1720. files.push_back(filename);
  1721. if ( verbose )
  1722. {
  1723. th_print_long_ls(t);
  1724. }
  1725. else
  1726. {
  1727. std::cout << filename << std::endl;
  1728. }
  1729. #ifdef DEBUG
  1730. th_print(t);
  1731. #endif
  1732. if (TH_ISREG(t) && tar_skip_regfile(t) != 0)
  1733. {
  1734. cmSystemTools::Error("Problem with tar_skip_regfile(): ",
  1735. strerror(errno));
  1736. return false;
  1737. }
  1738. }
  1739. if (tar_close(t) != 0)
  1740. {
  1741. cmSystemTools::Error("Problem with tar_close(): ", strerror(errno));
  1742. return false;
  1743. }
  1744. return true;
  1745. #else
  1746. (void)outFileName;
  1747. (void)files;
  1748. (void)gzip;
  1749. (void)verbose;
  1750. return false;
  1751. #endif
  1752. }
  1753. int cmSystemTools::WaitForLine(cmsysProcess* process, std::string& line,
  1754. double timeout,
  1755. std::vector<char>& out,
  1756. std::vector<char>& err)
  1757. {
  1758. line = "";
  1759. std::vector<char>::iterator outiter = out.begin();
  1760. std::vector<char>::iterator erriter = err.begin();
  1761. while(1)
  1762. {
  1763. // Check for a newline in stdout.
  1764. for(;outiter != out.end(); ++outiter)
  1765. {
  1766. if((*outiter == '\r') && ((outiter+1) == out.end()))
  1767. {
  1768. break;
  1769. }
  1770. else if(*outiter == '\n' || *outiter == '\0')
  1771. {
  1772. int length = outiter-out.begin();
  1773. if(length > 1 && *(outiter-1) == '\r')
  1774. {
  1775. --length;
  1776. }
  1777. if(length > 0)
  1778. {
  1779. line.append(&out[0], length);
  1780. }
  1781. out.erase(out.begin(), outiter+1);
  1782. return cmsysProcess_Pipe_STDOUT;
  1783. }
  1784. }
  1785. // Check for a newline in stderr.
  1786. for(;erriter != err.end(); ++erriter)
  1787. {
  1788. if((*erriter == '\r') && ((erriter+1) == err.end()))
  1789. {
  1790. break;
  1791. }
  1792. else if(*erriter == '\n' || *erriter == '\0')
  1793. {
  1794. int length = erriter-err.begin();
  1795. if(length > 1 && *(erriter-1) == '\r')
  1796. {
  1797. --length;
  1798. }
  1799. if(length > 0)
  1800. {
  1801. line.append(&err[0], length);
  1802. }
  1803. err.erase(err.begin(), erriter+1);
  1804. return cmsysProcess_Pipe_STDERR;
  1805. }
  1806. }
  1807. // No newlines found. Wait for more data from the process.
  1808. int length;
  1809. char* data;
  1810. int pipe = cmsysProcess_WaitForData(process, &data, &length, &timeout);
  1811. if(pipe == cmsysProcess_Pipe_Timeout)
  1812. {
  1813. // Timeout has been exceeded.
  1814. return pipe;
  1815. }
  1816. else if(pipe == cmsysProcess_Pipe_STDOUT)
  1817. {
  1818. // Append to the stdout buffer.
  1819. std::vector<char>::size_type size = out.size();
  1820. out.insert(out.end(), data, data+length);
  1821. outiter = out.begin()+size;
  1822. }
  1823. else if(pipe == cmsysProcess_Pipe_STDERR)
  1824. {
  1825. // Append to the stderr buffer.
  1826. std::vector<char>::size_type size = err.size();
  1827. err.insert(err.end(), data, data+length);
  1828. erriter = err.begin()+size;
  1829. }
  1830. else if(pipe == cmsysProcess_Pipe_None)
  1831. {
  1832. // Both stdout and stderr pipes have broken. Return leftover data.
  1833. if(!out.empty())
  1834. {
  1835. line.append(&out[0], outiter-out.begin());
  1836. out.erase(out.begin(), out.end());
  1837. return cmsysProcess_Pipe_STDOUT;
  1838. }
  1839. else if(!err.empty())
  1840. {
  1841. line.append(&err[0], erriter-err.begin());
  1842. err.erase(err.begin(), err.end());
  1843. return cmsysProcess_Pipe_STDERR;
  1844. }
  1845. else
  1846. {
  1847. return cmsysProcess_Pipe_None;
  1848. }
  1849. }
  1850. }
  1851. }
  1852. void cmSystemTools::DoNotInheritStdPipes()
  1853. {
  1854. #ifdef _WIN32
  1855. // Check to see if we are attached to a console
  1856. // if so, then do not stop the inherited pipes
  1857. // or stdout and stderr will not show up in dos
  1858. // shell windows
  1859. CONSOLE_SCREEN_BUFFER_INFO hOutInfo;
  1860. HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
  1861. if(GetConsoleScreenBufferInfo(hOut, &hOutInfo))
  1862. {
  1863. return;
  1864. }
  1865. {
  1866. HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
  1867. DuplicateHandle(GetCurrentProcess(), out,
  1868. GetCurrentProcess(), &out, 0, FALSE,
  1869. DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
  1870. SetStdHandle(STD_OUTPUT_HANDLE, out);
  1871. }
  1872. {
  1873. HANDLE out = GetStdHandle(STD_ERROR_HANDLE);
  1874. DuplicateHandle(GetCurrentProcess(), out,
  1875. GetCurrentProcess(), &out, 0, FALSE,
  1876. DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
  1877. SetStdHandle(STD_ERROR_HANDLE, out);
  1878. }
  1879. #endif
  1880. }
  1881. //----------------------------------------------------------------------------
  1882. bool cmSystemTools::CopyFileTime(const char* fromFile, const char* toFile)
  1883. {
  1884. #if defined(_WIN32) && !defined(__CYGWIN__)
  1885. cmSystemToolsWindowsHandle hFrom =
  1886. CreateFile(fromFile, GENERIC_READ, FILE_SHARE_READ, 0,
  1887. OPEN_EXISTING, 0, 0);
  1888. cmSystemToolsWindowsHandle hTo =
  1889. CreateFile(toFile, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
  1890. if(!hFrom || !hTo)
  1891. {
  1892. return false;
  1893. }
  1894. FILETIME timeCreation;
  1895. FILETIME timeLastAccess;
  1896. FILETIME timeLastWrite;
  1897. if(!GetFileTime(hFrom, &timeCreation, &timeLastAccess, &timeLastWrite))
  1898. {
  1899. return false;
  1900. }
  1901. if(!SetFileTime(hTo, &timeCreation, &timeLastAccess, &timeLastWrite))
  1902. {
  1903. return false;
  1904. }
  1905. #else
  1906. struct stat fromStat;
  1907. if(stat(fromFile, &fromStat) < 0)
  1908. {
  1909. return false;
  1910. }
  1911. struct utimbuf buf;
  1912. buf.actime = fromStat.st_atime;
  1913. buf.modtime = fromStat.st_mtime;
  1914. if(utime(toFile, &buf) < 0)
  1915. {
  1916. return false;
  1917. }
  1918. #endif
  1919. return true;
  1920. }
  1921. //----------------------------------------------------------------------------
  1922. static std::string cmSystemToolsExecutableDirectory;
  1923. void cmSystemTools::FindExecutableDirectory(const char* argv0)
  1924. {
  1925. std::string errorMsg;
  1926. std::string exe;
  1927. if(cmSystemTools::FindProgramPath(argv0, exe, errorMsg))
  1928. {
  1929. cmSystemToolsExecutableDirectory =
  1930. cmSystemTools::GetFilenamePath(exe.c_str());
  1931. }
  1932. else
  1933. {
  1934. // ???
  1935. }
  1936. }
  1937. //----------------------------------------------------------------------------
  1938. const char* cmSystemTools::GetExecutableDirectory()
  1939. {
  1940. return cmSystemToolsExecutableDirectory.c_str();
  1941. }