dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libast / common / vec / vecload.c
blobbdb3fffe8e1f9aa497ce82f733d75201d72b6f84
1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
20 * *
21 ***********************************************************************/
22 #pragma prototyped
24 * Glenn Fowler
25 * AT&T Bell Laboratories
27 * string vector load support
30 #include <ast.h>
31 #include <vecargs.h>
34 * load a string vector from lines in buf
35 * buf may be modified on return
37 * each line in buf is treated as a new vector element
38 * lines with # as first char are comments
39 * \ as the last char joins consecutive lines
41 * the vector ends with a 0 sentinel
43 * the string array pointer is returned
46 char**
47 vecload(char* buf)
49 register char* s;
50 register int n;
51 register char** p;
52 char** vec;
54 vec = 0;
55 n = (*buf == '#') ? -1 : 0;
56 for (s = buf;; s++)
58 if (*s == '\n')
60 if (s > buf && *(s - 1) == '\\') *(s - 1) = *s = ' ';
61 else
63 *s = 0;
64 if (*(s + 1) != '#')
66 n++;
67 if (!*(s + 1)) break;
71 else if (!*s)
73 n++;
74 break;
77 if (n < 0) n = 0;
78 if (p = newof(0, char*, n + 3, 0))
80 *p++ = s = buf;
81 vec = ++p;
82 if (n > 0) for (;;)
84 if (*s != '#')
86 *p++ = s;
87 if (--n <= 0) break;
89 while (*s) s++;
90 s++;
92 *p = 0;
93 *(vec - 1) = (char*)p;
95 return(vec);