This repository has been archived by the owner on Sep 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
/
cmd.h
55 lines (49 loc) · 1.72 KB
/
cmd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in
* the LICENSE file in the root directory of this source tree. An
* additional grant of patent rights can be found in the PATENTS file
* in the same directory.
*
*/
#pragma once
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
#include "argv.h"
#define CMD_ARG_FORWARDED (1<<0)
#define CMD_ARG_NON_FORWARDED (1<<1)
#define CMD_ARG_NAME (1<<2)
#define CMD_ARG_ALL (CMD_ARG_FORWARDED|CMD_ARG_NON_FORWARDED)
typedef int (*cmdfn)(int argc, const char** argv);
struct cmd {
const char* name;
cmdfn main;
};
__attribute__((noreturn,format(printf,1,2)))
void usage_error(const char* fmt, ...);
__attribute__((noreturn))
void default_getopt(char c, const char* const* argv, const char* usage);
void append_argv_accumulation(struct strlist* sl,
const struct strlist* accum);
void accumulate_option(struct strlist** slp,
const char* opt,
const char* val);
struct cmd_rcmd_info;
int rcmd_main(const struct cmd_rcmd_info*);
int forward_to_rcmd(struct strlist* non_forwarded_args,
struct strlist* forwarded_args);
#ifdef FBADB_MAIN
# define FORWARD(cmd) \
int cmd##_main(const struct cmd_##cmd##_info* info) { \
return forward_to_rcmd( \
make_args_cmd_##cmd(CMD_ARG_NON_FORWARDED, info), \
make_args_cmd_##cmd(CMD_ARG_FORWARDED, info)); \
}
#else
# define FORWARD(cmd)
#endif
void show_help(const char* help);
extern const char full_usage[];