2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
6 /* misc.c -- here are all miscellaneous functions for global use */
13 * Break string into array of strings at LINEFEEDs
14 * **outarr must be obtained via malloc!
16 int strtostrs(char * in
, char ***outarr
)
18 int i
= 0, j
= 0, k
= 0;
24 /* allocate space for next string */
25 out
= realloc(out
, (i
+1) * sizeof(char *));
27 for ( j
= 0 ; in
[j
] && in
[j
]!=LINEFEED
; j
++ );
28 out
[i
-1] = malloc((j
+1) * sizeof(char));
30 for ( k
= 0 ; k
< j
; k
++ )
32 /* save char to string */
36 /* NULL-terminate string */
41 /* NULL-terminate array */
49 * Collate array of strings with glueing LINEFEEDs
51 char *collatestrings(int n
, char ** instrs
)
56 for ( i
= 0 ; i
< n
; i
++ )
58 /* Add length of line to total length of text,
59 plus additional LINEFEED (NULL for last item) */
60 len
+= strlen(instrs
[i
]) + 1;
62 retval
= malloc(sizeof(char) * len
);
66 for ( i
= 0 ; i
< n
; i
++ )
69 for ( len
= strlen(instrs
[i
]) ; len
> 0 ; len
-- )
71 retval
[j
] = instrs
[i
][k
];
85 * Add surrounding quotes to string
86 * Creates a copy of input string
88 char *addquotes(char * string
)
93 /* Add surrounding quotes */
94 c
= (string
== NULL
) ? 0 : strlen(string
);
98 strcpy(retval
+1, string
);
106 * free() array of strings (eg. allocated by strtostrs())
108 void freestrlist(STRPTR
*array
)