14887Schin /*********************************************************************** 24887Schin * * 34887Schin * This software is part of the ast package * 4*8462SApril.Chin@Sun.COM * Copyright (c) 1985-2008 AT&T Intellectual Property * 54887Schin * and is licensed under the * 64887Schin * Common Public License, Version 1.0 * 7*8462SApril.Chin@Sun.COM * by AT&T Intellectual Property * 84887Schin * * 94887Schin * A copy of the License is available at * 104887Schin * http://www.opensource.org/licenses/cpl1.0.txt * 114887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 124887Schin * * 134887Schin * Information and Software Systems Research * 144887Schin * AT&T Research * 154887Schin * Florham Park NJ * 164887Schin * * 174887Schin * Glenn Fowler <gsf@research.att.com> * 184887Schin * David Korn <dgk@research.att.com> * 194887Schin * Phong Vo <kpv@research.att.com> * 204887Schin * * 214887Schin ***********************************************************************/ 224887Schin #pragma prototyped 234887Schin /* 244887Schin * Glenn Fowler 254887Schin * AT&T Bell Laboratories 264887Schin * 274887Schin * string vector argv insertion 284887Schin */ 294887Schin 304887Schin #include <ast.h> 314887Schin #include <vecargs.h> 324887Schin #include <ctype.h> 334887Schin 344887Schin /* 354887Schin * insert the string vector vec between 364887Schin * (*argvp)[0] and (*argvp)[1], sliding (*argvp)[1] ... over 374887Schin * null and blank args are deleted 384887Schin * 394887Schin * vecfree always called 404887Schin * 414887Schin * -1 returned if insertion failed 424887Schin */ 434887Schin 444887Schin int 454887Schin vecargs(register char** vec, int* argcp, char*** argvp) 464887Schin { 474887Schin register char** argv; 484887Schin register char** oargv; 494887Schin char** ovec; 504887Schin char* s; 514887Schin int num; 524887Schin 534887Schin if (!vec) return(-1); 544887Schin if ((num = (char**)(*(vec - 1)) - vec) > 0) 554887Schin { 564887Schin if (!(argv = newof(0, char*, num + *argcp + 1, 0))) 574887Schin { 584887Schin vecfree(vec, 0); 594887Schin return(-1); 604887Schin } 614887Schin oargv = *argvp; 624887Schin *argvp = argv; 634887Schin *argv++ = *oargv++; 644887Schin ovec = vec; 654887Schin while (s = *argv = *vec++) 664887Schin { 674887Schin while (isspace(*s)) s++; 684887Schin if (*s) argv++; 694887Schin } 704887Schin vecfree(ovec, 1); 714887Schin while (*argv = *oargv++) argv++; 724887Schin *argcp = argv - *argvp; 734887Schin } 744887Schin else vecfree(vec, 0); 754887Schin return(0); 764887Schin } 77