1 : // Copyright 2012 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Defines member function for a generic application implementation base
16 : // class (empty implementation).
17 :
18 : #include "syzygy/common/application.h"
19 :
20 : #include "base/file_util.h"
21 : #include "base/files/file_path.h"
22 :
23 : namespace common {
24 :
25 : AppImplBase::AppImplBase(const base::StringPiece& name)
26 E : : in_(stdin), out_(stdout), err_(stderr) {
27 E : name_.assign(name.begin(), name.end());
28 E : }
29 :
30 E : bool AppImplBase::ParseCommandLine(const CommandLine* command_line) {
31 E : return true;
32 E : }
33 :
34 E : bool AppImplBase::SetUp() {
35 E : return true;
36 E : }
37 :
38 E : int AppImplBase::Run() {
39 E : return 0;
40 E : }
41 :
42 E : void AppImplBase::TearDown() {
43 E : }
44 :
45 E : base::FilePath AppImplBase::AbsolutePath(const base::FilePath& path) {
46 E : if (path.empty())
47 E : return base::FilePath();
48 :
49 E : base::FilePath temp(base::MakeAbsoluteFilePath(path));
50 E : if (temp.empty())
51 i : return path;
52 i : else
53 E : return temp;
54 E : }
55 :
56 : bool AppImplBase::AppendMatchingPaths(const base::FilePath& pattern,
57 E : std::vector<base::FilePath>* matches) {
58 E : DCHECK(matches != NULL);
59 E : bool found_a_match = false;
60 :
61 : // Whether the pattern is an existing file or not, we expand it as a glob.
62 : // If it's a file, it'll match itself and nothing else.
63 : file_util::FileEnumerator files(AbsolutePath(pattern.DirName()),
64 : false,
65 : file_util::FileEnumerator::FILES,
66 E : pattern.BaseName().value());
67 E : while (true) {
68 E : base::FilePath file = files.Next();
69 E : if (file.empty())
70 E : break;
71 :
72 E : DCHECK(file.IsAbsolute());
73 :
74 E : found_a_match = true;
75 E : matches->push_back(file);
76 E : }
77 :
78 E : return found_a_match;
79 E : }
80 :
81 : } // namespace common
|