From 3950ffe2a485479f6561c27364d3d7df5a21d124 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Sun, 24 Jun 2012 22:28:35 +0000 Subject: Imported Upstream version 93u+ --- src/lib/libast/vec/vecload.c | 96 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/lib/libast/vec/vecload.c (limited to 'src/lib/libast/vec/vecload.c') diff --git a/src/lib/libast/vec/vecload.c b/src/lib/libast/vec/vecload.c new file mode 100644 index 0000000..5f83470 --- /dev/null +++ b/src/lib/libast/vec/vecload.c @@ -0,0 +1,96 @@ +/*********************************************************************** +* * +* This software is part of the ast package * +* Copyright (c) 1985-2011 AT&T Intellectual Property * +* and is licensed under the * +* Eclipse Public License, Version 1.0 * +* by AT&T Intellectual Property * +* * +* A copy of the License is available at * +* http://www.eclipse.org/org/documents/epl-v10.html * +* (with md5 checksum b35adb5213ca9657e911e9befb180842) * +* * +* Information and Software Systems Research * +* AT&T Research * +* Florham Park NJ * +* * +* Glenn Fowler * +* David Korn * +* Phong Vo * +* * +***********************************************************************/ +#pragma prototyped +/* + * Glenn Fowler + * AT&T Bell Laboratories + * + * string vector load support + */ + +#include +#include + +/* + * load a string vector from lines in buf + * buf may be modified on return + * + * each line in buf is treated as a new vector element + * lines with # as first char are comments + * \ as the last char joins consecutive lines + * + * the vector ends with a 0 sentinel + * + * the string array pointer is returned + */ + +char** +vecload(char* buf) +{ + register char* s; + register int n; + register char** p; + char** vec; + + vec = 0; + n = (*buf == '#') ? -1 : 0; + for (s = buf;; s++) + { + if (*s == '\n') + { + if (s > buf && *(s - 1) == '\\') *(s - 1) = *s = ' '; + else + { + *s = 0; + if (*(s + 1) != '#') + { + n++; + if (!*(s + 1)) break; + } + } + } + else if (!*s) + { + n++; + break; + } + } + if (n < 0) n = 0; + if (p = newof(0, char*, n + 3, 0)) + { + *p++ = s = buf; + vec = ++p; + if (n > 0) for (;;) + { + if (*s != '#') + { + *p++ = s; + if (--n <= 0) break; + } + while (*s) s++; + s++; + } + *p = 0; + *(vec - 1) = (char*)p; + } + return(vec); +} -- cgit v1.2.3