14
* it contains an item structure with a `util` field that is not compatible
15
* with the traditional argv interface.
16
*
17
- * Each `argv_array` manages its own memory. Any strings pushed into the
18
- * array are duplicated, and all memory is freed by argv_array_clear().
17
+ * Each `strvec` manages its own memory. Any strings pushed into the
18
+ * array are duplicated, and all memory is freed by strvec_clear().
19
*/
20
21
-extern const char *empty_argv[];
21
+extern const char *empty_strvec[];
22
23
/**
24
* A single array. This should be initialized by assignment from
25
- * `ARGV_ARRAY_INIT`, or by calling `argv_array_init`. The `argv`
25
+ * `STRVEC_INIT`, or by calling `strvec_init`. The `argv`
26
* member contains the actual array; the `argc` member contains the
27
* number of elements in the array, not including the terminating
28
* NULL.
29
*/
30
-struct argv_array {
30
+struct strvec {
31
const char **argv;
32
size_t argc;
33
size_t alloc;
34
};
35
36
-#define ARGV_ARRAY_INIT { empty_argv, 0, 0 }
36
+#define STRVEC_INIT { empty_strvec, 0, 0 }
37
38
/**
39
* Initialize an array. This is no different than assigning from
40
- * `ARGV_ARRAY_INIT`.
40
+ * `STRVEC_INIT`.
41
*/
42
-void argv_array_init(struct argv_array *);
42
+void strvec_init(struct strvec *);
43
44
/* Push a copy of a string onto the end of the array. */
45
-const char *argv_array_push(struct argv_array *, const char *);
45
+const char *strvec_push(struct strvec *, const char *);
46
47
/**
48
* Format a string and push it onto the end of the array. This is a
49
- * convenience wrapper combining `strbuf_addf` and `argv_array_push`.
49
+ * convenience wrapper combining `strbuf_addf` and `strvec_push`.
50
*/
51
__attribute__((format (printf,2,3)))
52
-const char *argv_array_pushf(struct argv_array *, const char *fmt, ...);
52
+const char *strvec_pushf(struct strvec *, const char *fmt, ...);
53
54
/**
55
* Push a list of strings onto the end of the array. The arguments
57
* argument.
58
*/
59
LAST_ARG_MUST_BE_NULL
60
-void argv_array_pushl(struct argv_array *, ...);
60
+void strvec_pushl(struct strvec *, ...);
61
62
/* Push a null-terminated array of strings onto the end of the array. */
63
-void argv_array_pushv(struct argv_array *, const char **);
63
+void strvec_pushv(struct strvec *, const char **);
64
65
/**
66
* Remove the final element from the array. If there are no
67
* elements in the array, do nothing.
68
*/
69
-void argv_array_pop(struct argv_array *);
69
+void strvec_pop(struct strvec *);
70
71
/* Splits by whitespace; does not handle quoted arguments! */
72
-void argv_array_split(struct argv_array *, const char *);
72
+void strvec_split(struct strvec *, const char *);
73
74
/**
75
* Free all memory associated with the array and return it to the
76
* initial, empty state.
77
*/
78
-void argv_array_clear(struct argv_array *);
78
+void strvec_clear(struct strvec *);
79
80
/**
81
- * Disconnect the `argv` member from the `argv_array` struct and
81
+ * Disconnect the `argv` member from the `strvec` struct and
82
* return it. The caller is responsible for freeing the memory used
83
* by the array, and by the strings it references. After detaching,
84
- * the `argv_array` is in a reinitialized state and can be pushed
84
+ * the `strvec` is in a reinitialized state and can be pushed
85
* into again.
86
*/
87
-const char **argv_array_detach(struct argv_array *);
87
+const char **strvec_detach(struct strvec *);
88
+
89
+/* compatibility for historic argv_array interface */
90
+#define argv_array strvec
91
+#define ARGV_ARRAY_INIT STRVEC_INIT
92
+#define argv_array_init strvec_init
93
+#define argv_array_push strvec_push
94
+#define argv_array_pushf strvec_pushf
95
+#define argv_array_pushl strvec_pushl
96
+#define argv_array_pushv strvec_pushv
97
+#define argv_array_pop strvec_pop
98
+#define argv_array_split strvec_split
99
+#define argv_array_clear strvec_clear
100
+#define argv_array_detach strvec_detach
101
102
#endif /* ARGV_ARRAY_H */