home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / oogl / util / glob.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-09  |  1.3 KB  |  58 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "ooglutil.h"
  4. #include <sys/signal.h>
  5.  
  6. #define FBUFSIZ 1024
  7. #define INITSIZ 10
  8.  
  9. /*-----------------------------------------------------------------------
  10.  * Function:    *ooglglob
  11.  * Description:    C-shell globbing
  12.  * Args:    *s: the string to glob
  13.  * Returns:    pointer to array of pointers to expanded strings; ends
  14.  *           with NULL
  15.  * Author:    mbp
  16.  * Date:    Tue Aug 25 12:42:21 1992
  17.  * Notes:    Invokes a subshell (/bin/csh) to do the work.
  18.  *        Caller should free the returned value by
  19.  *        first calling ooglblkfree() then free():
  20.  *
  21.  *        char **g;
  22.  *        g = ooglglob(string);
  23.  *        ...
  24.  *        ooglblkfree(g);
  25.  *        free(g);
  26.  */
  27. char **ooglglob(char *s)
  28. {
  29.   FILE *fp;
  30.   char cmd[FBUFSIZ];
  31.   vvec vp;
  32.   char *c;
  33.   int status;
  34.     /* Avoid NeXT pclose() bug: don't catch subprocess' SIGCHLD */
  35.   void (*oldsigchld)() = signal(SIGCHLD, SIG_DFL);
  36.  
  37.   sprintf(cmd, "/bin/csh -f -c \"echo %s\" 2>&-", s);
  38.   fp = popen(cmd, "r");
  39.  
  40.   VVINIT(vp, char *, INITSIZ);
  41.   while (!feof(fp))
  42.     if ((c=ftoken(fp, 2)) != NULL) *VVAPPEND(vp,char*) = strdup(c);
  43.   *VVAPPEND(vp,char*) = NULL;
  44.   vvtrim(&vp);
  45.  
  46.   status = pclose(fp);
  47.   signal(SIGCHLD, oldsigchld);
  48.   return VVEC(vp,char*);
  49. }
  50.  
  51. ooglblkfree(av0)
  52.      char **av0;
  53. {
  54.   register char **av = av0;
  55.   while (*av)
  56.     free(*av++);
  57. }
  58.