blob: 4ba03b6dc6142d07d612eef8d17423877d5580ba [file] [log] [blame]
Shinichiro Hamaji1d545aa2015-06-23 15:29:13 +09001// Copyright 2015 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
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090015#ifndef FUNC_H_
16#define FUNC_H_
17
Shinichiro Hamajic9b0aca2015-07-31 16:47:56 +090018#include <memory>
19#include <string>
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090020#include <vector>
21
Shinichiro Hamaji645cca72015-09-24 17:04:21 +090022#include "expr.h"
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090023
24using namespace std;
25
26struct FuncInfo {
27 const char* name;
28 void (*func)(const vector<Value*>& args, Evaluator* ev, string* s);
29 int arity;
Shinichiro Hamajifead3b72015-06-18 15:31:15 +090030 int min_arity;
31 // For all parameters.
32 bool trim_space;
33 // Only for the first parameter.
34 bool trim_right_space_1st;
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090035};
36
37void InitFuncTable();
38void QuitFuncTable();
39
40FuncInfo* GetFuncInfo(StringPiece name);
41
Shinichiro Hamajic9b0aca2015-07-31 16:47:56 +090042struct FindCommand;
43
Dan Willemsenf06d8012016-10-03 00:16:07 -070044enum struct CommandOp {
45 SHELL,
46 FIND,
47 READ,
48 READ_MISSING,
49 WRITE,
50 APPEND,
51};
52
Shinichiro Hamaji4db9edc2015-08-13 16:43:02 +090053struct CommandResult {
Dan Willemsenf06d8012016-10-03 00:16:07 -070054 CommandOp op;
Stefan Beckerd4f28712016-04-07 13:29:36 +030055 string shell;
Dan Willemsen064be222016-09-30 20:17:14 -070056 string shellflag;
Shinichiro Hamajic9b0aca2015-07-31 16:47:56 +090057 string cmd;
58 unique_ptr<FindCommand> find;
59 string result;
60};
61
Shinichiro Hamaji4db9edc2015-08-13 16:43:02 +090062const vector<CommandResult*>& GetShellCommandResults();
Shinichiro Hamajic9b0aca2015-07-31 16:47:56 +090063
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090064#endif // FUNC_H_