]>
jfr.im git - irc/quakenet/newserv.git/blob - lib/splitline.c
2 * splitline: splits a line into a list of parameters.
4 * This function works "in place", i.e. the original input string is destroyed.
6 * This function splits lines on each space, up to a maximum of maxparams.
7 * Spaces at the beginning/between words are replaced with '\0', as are all
10 * If "coloncheck" is nonzero, a parameter beginning with ':' will be treated
11 * as the last. The inevitable exception to this is the _first_ parameter...
14 int splitline(char *inputstring
, char **outputvector
, int maxparams
, int coloncheck
) {
16 int instr
=0; /* State variable: 0 = between params, 1 = in param */
19 for (c
=inputstring
;*c
;c
++) {
22 /* Space in string -- end string, obliterate */
28 /* Space when not in string: obliterate */
31 /* Non-space character, start new word. */
32 if (*c
==':' && coloncheck
&& paramcount
) {
33 outputvector
[paramcount
++]=c
+1;
35 } else if (paramcount
+1==maxparams
) {
36 outputvector
[paramcount
++]=c
;
39 outputvector
[paramcount
++]=c
;
50 * This function reconnects extra arguments together with spaces.
52 * Multiple spaces will be not be removed
54 * USE WITH CARE -- you don't have to worry about the original string
55 * being untrusted, but you must get the arguments right :)
58 void rejoinline(char *input
, int argstojoin
) {
67 for (ch
=input
;;ch
++) {