/* Copyright (C) 1992-1998 The Geometry Center * Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips * * This file is part of Geomview. * * Geomview is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) * any later version. * * Geomview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with Geomview; see the file COPYING. If not, write * to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, * USA, or visit http://www.gnu.org. */ #if defined(HAVE_CONFIG_H) && !defined(CONFIG_H_INCLUDED) #include "config.h" #endif static char copyright[] = "Copyright (C) 1992-1998 The Geometry Center\n\ Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips"; #include #include #include #include "ooglutil.h" #if defined(unix) || defined(__unix) #include #endif /*unix*/ #if defined(unix) || defined(__unix) /* Don't try to compile for Windows */ #define FBUFSIZ 1024 #define INITSIZ 10 /*----------------------------------------------------------------------- * Function: *ooglglob * Description: C-shell globbing * Args: *s: the string to glob * Returns: pointer to array of pointers to expanded strings; ends * with NULL * Author: mbp * Date: Tue Aug 25 12:42:21 1992 * Notes: Invokes a subshell (/bin/csh) to do the work. * Caller should free the returned value by * first calling ooglblkfree() then free(): * * char **g; * g = ooglglob(string); * ... * ooglblkfree(g); * free(g); */ char **ooglglob(char *s) { FILE *fp; char cmd[FBUFSIZ]; vvec vp; char *c; int status; #ifdef SIGCHLD /* Avoid NeXT pclose() bug: don't catch subprocess' SIGCHLD */ void (*oldsigchld)() = signal(SIGCHLD, SIG_DFL); #endif sprintf(cmd, "/bin/csh -f -c \"echo %s\" 2>&-", s); fp = popen(cmd, "r"); VVINIT(vp, char *, INITSIZ); while (!feof(fp)) if ((c=ftoken(fp, 2)) != NULL) *VVAPPEND(vp,char*) = strdup(c); *VVAPPEND(vp,char*) = NULL; vvtrim(&vp); status = pclose(fp); #ifdef SIGCHLD signal(SIGCHLD, oldsigchld); #endif return VVEC(vp,char*); } void ooglblkfree(av0) char **av0; { register char **av = av0; while (*av) free(*av++); } #endif /*unix*/