summaryrefslogtreecommitdiff
path: root/argv-array.h
diff options
context:
space:
mode:
Diffstat (limited to 'argv-array.h')
-rw-r--r--argv-array.h51
1 files changed, 32 insertions, 19 deletions
diff --git a/argv-array.h b/argv-array.h
index 4fc57b6902..ca66a338ad 100644
--- a/argv-array.h
+++ b/argv-array.h
@@ -14,42 +14,42 @@
* it contains an item structure with a `util` field that is not compatible
* with the traditional argv interface.
*
- * Each `argv_array` manages its own memory. Any strings pushed into the
- * array are duplicated, and all memory is freed by argv_array_clear().
+ * Each `strvec` manages its own memory. Any strings pushed into the
+ * array are duplicated, and all memory is freed by strvec_clear().
*/
-extern const char *empty_argv[];
+extern const char *empty_strvec[];
/**
* A single array. This should be initialized by assignment from
- * `ARGV_ARRAY_INIT`, or by calling `argv_array_init`. The `argv`
+ * `STRVEC_INIT`, or by calling `strvec_init`. The `argv`
* member contains the actual array; the `argc` member contains the
* number of elements in the array, not including the terminating
* NULL.
*/
-struct argv_array {
+struct strvec {
const char **argv;
size_t argc;
size_t alloc;
};
-#define ARGV_ARRAY_INIT { empty_argv, 0, 0 }
+#define STRVEC_INIT { empty_strvec, 0, 0 }
/**
* Initialize an array. This is no different than assigning from
- * `ARGV_ARRAY_INIT`.
+ * `STRVEC_INIT`.
*/
-void argv_array_init(struct argv_array *);
+void strvec_init(struct strvec *);
/* Push a copy of a string onto the end of the array. */
-const char *argv_array_push(struct argv_array *, const char *);
+const char *strvec_push(struct strvec *, const char *);
/**
* Format a string and push it onto the end of the array. This is a
- * convenience wrapper combining `strbuf_addf` and `argv_array_push`.
+ * convenience wrapper combining `strbuf_addf` and `strvec_push`.
*/
__attribute__((format (printf,2,3)))
-const char *argv_array_pushf(struct argv_array *, const char *fmt, ...);
+const char *strvec_pushf(struct strvec *, const char *fmt, ...);
/**
* Push a list of strings onto the end of the array. The arguments
@@ -57,33 +57,46 @@ const char *argv_array_pushf(struct argv_array *, const char *fmt, ...);
* argument.
*/
LAST_ARG_MUST_BE_NULL
-void argv_array_pushl(struct argv_array *, ...);
+void strvec_pushl(struct strvec *, ...);
/* Push a null-terminated array of strings onto the end of the array. */
-void argv_array_pushv(struct argv_array *, const char **);
+void strvec_pushv(struct strvec *, const char **);
/**
* Remove the final element from the array. If there are no
* elements in the array, do nothing.
*/
-void argv_array_pop(struct argv_array *);
+void strvec_pop(struct strvec *);
/* Splits by whitespace; does not handle quoted arguments! */
-void argv_array_split(struct argv_array *, const char *);
+void strvec_split(struct strvec *, const char *);
/**
* Free all memory associated with the array and return it to the
* initial, empty state.
*/
-void argv_array_clear(struct argv_array *);
+void strvec_clear(struct strvec *);
/**
- * Disconnect the `argv` member from the `argv_array` struct and
+ * Disconnect the `argv` member from the `strvec` struct and
* return it. The caller is responsible for freeing the memory used
* by the array, and by the strings it references. After detaching,
- * the `argv_array` is in a reinitialized state and can be pushed
+ * the `strvec` is in a reinitialized state and can be pushed
* into again.
*/
-const char **argv_array_detach(struct argv_array *);
+const char **strvec_detach(struct strvec *);
+
+/* compatibility for historic argv_array interface */
+#define argv_array strvec
+#define ARGV_ARRAY_INIT STRVEC_INIT
+#define argv_array_init strvec_init
+#define argv_array_push strvec_push
+#define argv_array_pushf strvec_pushf
+#define argv_array_pushl strvec_pushl
+#define argv_array_pushv strvec_pushv
+#define argv_array_pop strvec_pop
+#define argv_array_split strvec_split
+#define argv_array_clear strvec_clear
+#define argv_array_detach strvec_detach
#endif /* ARGV_ARRAY_H */