Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / utilities / Installer / misc.c
blob43f379fa9fd7124779df16cbca55b4ba8e8da53f
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /* misc.c -- here are all miscellaneous functions for global use */
8 #include "Installer.h"
9 #include "cleanup.h"
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;
19 char **out = *outarr;
21 while (*in)
23 i++;
24 /* allocate space for next string */
25 out = realloc(out, (i+1) * sizeof(char *));
26 outofmem(out);
27 for ( j = 0 ; in[j] && in[j]!=LINEFEED ; j++ );
28 out[i-1] = malloc((j+1) * sizeof(char));
29 outofmem(out[i-1]);
30 for ( k = 0 ; k < j ; k++ )
32 /* save char to string */
33 out[i-1][k] = *in;
34 in++;
36 /* NULL-terminate string */
37 out[i-1][j] = 0;
38 if (*in)
39 in++;
41 /* NULL-terminate array */
42 out[i] = NULL;
43 *outarr = out;
45 return i;
49 * Collate array of strings with glueing LINEFEEDs
51 char *collatestrings(int n, char ** instrs)
53 char *retval;
54 int len = 0, i, j, k;
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);
63 if (retval != NULL)
65 j = 0;
66 for ( i = 0 ; i < n ; i++ )
68 k = 0;
69 for ( len = strlen(instrs[i]) ; len > 0 ; len-- )
71 retval[j] = instrs[i][k];
72 j++;
73 k++;
75 retval[j] = LINEFEED;
76 j++;
78 retval[j-1] = 0;
81 return retval;
85 * Add surrounding quotes to string
86 * Creates a copy of input string
88 char *addquotes(char * string)
90 char *retval;
91 int c;
93 /* Add surrounding quotes */
94 c = (string == NULL) ? 0 : strlen(string);
95 retval = malloc(c+3);
96 outofmem(retval);
97 retval[0] = DQUOTE;
98 strcpy(retval+1, string);
99 retval[c+1] = DQUOTE;
100 retval[c+2] = 0;
102 return retval;
106 * free() array of strings (eg. allocated by strtostrs())
108 void freestrlist(STRPTR *array)
110 int i=0;
112 while (array[i])
114 free(array[i]);
115 i++;
117 free(array);