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"
33 scanner (const std::string
&dir
)
35 m_dir
= opendir (dir
.c_str ());
49 struct dirent
*entry
= readdir (m_dir
);
62 search_dir (const regex_t
®exp
, const std::string
&dir
, std::string
*result
)
67 while ((filename
= scan
.next ()) != NULL
)
69 if (regexec (®exp
, filename
, 0, NULL
, 0) == 0)
83 tokenizer (const char *str
)
91 return m_pos
== std::string::npos
;
96 std::string::size_type last_pos
= m_pos
;
97 std::string::size_type colon
= m_str
.find(':', last_pos
);
100 if (colon
== std::string::npos
)
103 result
= m_str
.substr(last_pos
, colon
);
108 result
= m_str
.substr(last_pos
, colon
- last_pos
);
119 std::string::size_type m_pos
;
123 find_compiler (const regex_t
®exp
, std::string
*result
)
125 const char *cpath
= getenv ("PATH");
130 tokenizer
dirs (cpath
);
131 while (!dirs
.done ())
133 std::string dir
= dirs
.next ();
134 if (search_dir (regexp
, dir
, result
))