1 /* Copyright (c) 2006-2014 Jonas Fonseca <jonas.fonseca@gmail.com>
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License as
5 * published by the Free Software Foundation; either version 2 of
6 * the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
20 * Argument array helpers.
23 #define SIZEOF_ARG 32 /* Default argument array size. */
25 bool argv_to_string(const char *argv
[SIZEOF_ARG
], char *buf
, size_t buflen
, const char *sep
);
26 bool argv_from_string_no_quotes(const char *argv
[SIZEOF_ARG
], int *argc
, char *cmd
);
27 bool argv_from_string(const char *argv
[SIZEOF_ARG
], int *argc
, char *cmd
);
28 bool argv_from_env(const char **argv
, const char *name
);
29 void argv_free(const char *argv
[]);
30 size_t argv_size(const char **argv
);
31 bool argv_append(const char ***argv
, const char *arg
);
32 bool argv_append_array(const char ***dst_argv
, const char *src_argv
[]);
33 bool argv_copy(const char ***dst
, const char *src
[]);
34 bool argv_remove_quotes(const char *argv
[]);
35 bool argv_contains(const char **argv
, const char *arg
);
37 typedef char argv_string
[SIZEOF_STR
];
38 typedef unsigned long argv_number
;
40 #define ARGV_ENV_INFO(_) \
41 _(argv_string, commit, "", "HEAD") \
42 _(argv_string, blob, "", "") \
43 _(argv_string, branch, "", "") \
44 _(argv_string, directory, ".", "") \
45 _(argv_string, file, "", "") \
46 _(argv_string, head, "", "HEAD") \
47 _(argv_number, lineno, "", 0) \
48 _(argv_string, ref, "HEAD", "") \
49 _(argv_string, remote, "origin", "") \
50 _(argv_string, stash, "", "") \
51 _(argv_string, status, "", "") \
52 _(argv_string, tag, "", "")
54 #define ARGV_ENV_FIELDS(type, name, ifempty, initval) type name;
57 ARGV_ENV_INFO(ARGV_ENV_FIELDS
);
58 unsigned long goto_lineno
;
59 char search
[SIZEOF_STR
];
63 extern struct argv_env argv_env
;
65 bool argv_format(struct argv_env
*argv_env
, const char ***dst_argv
, const char *src_argv
[], bool first
, bool file_filter
);
66 char *argv_format_arg(struct argv_env
*argv_env
, const char *src_arg
);
74 bool argv_parse_rev_flag(const char *arg
, struct rev_flags
*flags
);
77 /* vim: set ts=8 sw=8 noexpandtab: */