wordexp.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
7abd0c58a5ce51db13f93de82407b2188d55d298Christian Maeder/***********************************************************************
94ceeb2edbd25b4697ddd9f63c94377924352cf4Christian Maeder* This software is part of the ast package *
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian Maeder* Copyright (c) 1985-2011 AT&T Intellectual Property *
7abd0c58a5ce51db13f93de82407b2188d55d298Christian Maeder* and is licensed under the *
b4fbc96e05117839ca409f5f20f97b3ac872d1edTill Mossakowski* Eclipse Public License, Version 1.0 *
7abd0c58a5ce51db13f93de82407b2188d55d298Christian Maeder* by AT&T Intellectual Property *
08faa81d4dd8409cd923b334064f64f802ecc33dChristian Maeder* A copy of the License is available at *
94ceeb2edbd25b4697ddd9f63c94377924352cf4Christian Maeder* http://www.eclipse.org/org/documents/epl-v10.html *
08faa81d4dd8409cd923b334064f64f802ecc33dChristian Maeder* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maeder* Information and Software Systems Research *
08faa81d4dd8409cd923b334064f64f802ecc33dChristian Maeder* AT&T Research *
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maeder* Florham Park NJ *
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maeder* Glenn Fowler <gsf@research.att.com> *
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maeder* David Korn <dgk@research.att.com> *
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maeder* Phong Vo <kpv@research.att.com> *
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder***********************************************************************/
94ceeb2edbd25b4697ddd9f63c94377924352cf4Christian Maeder * POSIX 1003.2 wordexp implementation
c18e9c3c6d5039618f1f2c05526ece84c7794ea3Christian Maeder * elimnates shell quoting as inserted with sh_fmtq
94ceeb2edbd25b4697ddd9f63c94377924352cf4Christian Maeder * result relaces <string>
94ceeb2edbd25b4697ddd9f63c94377924352cf4Christian Maeder * length of resulting string is returned.
94ceeb2edbd25b4697ddd9f63c94377924352cf4Christian Maeder register int c;
81946e2b3f6dde6167f48769bd02c7a634736856Christian Maeder /* copy all but trailing ' */
94ceeb2edbd25b4697ddd9f63c94377924352cf4Christian Maederint wordexp(const char *string, wordexp_t *wdarg, register int flags)
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder while(c = *cp++)
81946e2b3f6dde6167f48769bd02c7a634736856Christian Maeder if(c=='\\' && (!quoted || strchr("\\\"`\n$",c)))
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder else if(c=='"')
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowski /* only the shell can parse the rest */
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder else if(c=='(') /* allow | and & inside pattern */
81946e2b3f6dde6167f48769bd02c7a634736856Christian Maeder if(!(iop = sfpopen((Sfio_t*)0,stakptr(0),"r")))
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder av = (char**)realloc((void*)&wdarg->we_wordv[-1], (wdarg->we_wordc+c)*sizeof(char*));
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder else if(av = (char**)malloc(c*sizeof(char*)))
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder memset((void*)av,0,(wdarg->we_offs+1)*sizeof(char*));
c = staktell();
c=WRDE_NOSPACE;
goto err;
cp += sizeof(char*);
while(ac-- > 0)
while(c= *cp++);
*av = 0;
err:
if(offset)
stakseek(0);