1 /* Find the correct compiler.
2 Copyright (C) 2014-2017 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
25 #include "libiberty.h"
27 #include "findcomp.hh"
34 scanner (const std::string
&dir
)
36 m_dir
= opendir (dir
.c_str ());
50 struct dirent
*entry
= readdir (m_dir
);
63 search_dir (const regex_t
®exp
, const std::string
&dir
, std::string
*result
)
68 while ((filename
= scan
.next ()) != NULL
)
70 if (regexec (®exp
, filename
, 0, NULL
, 0) == 0)
72 *result
= dir
+ DIR_SEPARATOR
+ filename
;
84 tokenizer (const char *str
)
92 return m_pos
== std::string::npos
;
97 std::string::size_type last_pos
= m_pos
;
98 std::string::size_type colon
= m_str
.find(':', last_pos
);
101 if (colon
== std::string::npos
)
104 result
= m_str
.substr(last_pos
, colon
);
109 result
= m_str
.substr(last_pos
, colon
- last_pos
);
120 std::string::size_type m_pos
;
124 find_compiler (const regex_t
®exp
, std::string
*result
)
126 const char *cpath
= getenv ("PATH");
131 tokenizer
dirs (cpath
);
132 while (!dirs
.done ())
134 std::string dir
= dirs
.next ();
135 if (search_dir (regexp
, dir
, result
))