/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped22/*23* Glenn Fowler24* AT&T Bell Laboratories25*26* string vector load support27*/2829#include <ast.h>30#include <vecargs.h>3132/*33* load a string vector from lines in buf34* buf may be modified on return35*36* each line in buf is treated as a new vector element37* lines with # as first char are comments38* \ as the last char joins consecutive lines39*40* the vector ends with a 0 sentinel41*42* the string array pointer is returned43*/4445char**46vecload(char* buf)47{48register char* s;49register int n;50register char** p;51char** vec;5253vec = 0;54n = (*buf == '#') ? -1 : 0;55for (s = buf;; s++)56{57if (*s == '\n')58{59if (s > buf && *(s - 1) == '\\') *(s - 1) = *s = ' ';60else61{62*s = 0;63if (*(s + 1) != '#')64{65n++;66if (!*(s + 1)) break;67}68}69}70else if (!*s)71{72n++;73break;74}75}76if (n < 0) n = 0;77if (p = newof(0, char*, n + 3, 0))78{79*p++ = s = buf;80vec = ++p;81if (n > 0) for (;;)82{83if (*s != '#')84{85*p++ = s;86if (--n <= 0) break;87}88while (*s) s++;89s++;90}91*p = 0;92*(vec - 1) = (char*)p;93}94return(vec);95}969798