7 /* string array utilities
11 /* ARGV *argv_split(string, delim)
12 /* const char *string;
14 /* ARGV *argv_split_count(string, delim, count)
15 /* const char *string;
18 /* ARGV *argv_split_append(argv, string, delim)
20 /* const char *string;
23 /* argv_split() breaks up \fIstring\fR into tokens according
24 /* to the delimiters specified in \fIdelim\fR. The result is
25 /* a null-terminated string array.
27 /* argv_split_count() is like argv_split() but stops splitting
28 /* input after at most \fIcount\fR -1 times and leaves the
29 /* remainder, if any, in the last array element. It is an error
30 /* to specify a count < 1.
32 /* argv_split_append() performs the same operation as argv_split(),
33 /* but appends the result to an existing string array.
35 /* mystrtok(), safe string splitter.
37 /* Fatal errors: memory allocation problem.
41 /* The Secure Mailer license must be distributed with this software.
44 /* IBM T.J. Watson Research
46 /* Yorktown Heights, NY 10598, USA
49 /* System libraries. */
54 /* Application-specific. */
57 #include "stringops.h"
61 /* argv_split - split string into token array */
63 ARGV
*argv_split(const char *string
, const char *delim
)
65 ARGV
*argvp
= argv_alloc(1);
66 char *saved_string
= mystrdup(string
);
67 char *bp
= saved_string
;
70 while ((arg
= mystrtok(&bp
, delim
)) != 0)
71 argv_add(argvp
, arg
, (char *) 0);
72 argv_terminate(argvp
);
77 /* argv_split_count - split string into token array */
79 ARGV
*argv_split_count(const char *string
, const char *delim
, ssize_t count
)
81 ARGV
*argvp
= argv_alloc(1);
82 char *saved_string
= mystrdup(string
);
83 char *bp
= saved_string
;
87 msg_panic("argv_split_count: bad count: %ld", (long) count
);
88 while (count
-- > 1 && (arg
= mystrtok(&bp
, delim
)) != 0)
89 argv_add(argvp
, arg
, (char *) 0);
91 bp
+= strspn(bp
, delim
);
93 argv_add(argvp
, bp
, (char *) 0);
94 argv_terminate(argvp
);
99 /* argv_split_append - split string into token array, append to array */
101 ARGV
*argv_split_append(ARGV
*argvp
, const char *string
, const char *delim
)
103 char *saved_string
= mystrdup(string
);
104 char *bp
= saved_string
;
107 while ((arg
= mystrtok(&bp
, delim
)) != 0)
108 argv_add(argvp
, arg
, (char *) 0);
109 argv_terminate(argvp
);
110 myfree(saved_string
);