path = Lst_Init();
path = Lst_New();
Dir_Expand (word, path, expansions)    char    *word;      /* the word to expand */    Lst     path;   	/* the list of directories in which to find			 * the resulting files */    Lst	    expansions;	/* the list on which to place the results */{    char    	  *cp;    if (DEBUG(DIR)) {	printf("expanding \"%s\"...", word);    }    cp = strchr(word, '{');    if (cp) {	DirExpandCurly(word, cp, path, expansions);    } else {	cp = strchr(word, '/');	if (cp) {	    /*	     * The thing has a directory component -- find the first wildcard	     * in the string.	     */	    for (cp = word; *cp; cp++) {		if (*cp == '?' || *cp == '[' || *cp == '*' || *cp == '{') {		    break;		}	    }	    if (*cp == '{') {		/*		 * This one will be fun.		 */		DirExpandCurly(word, cp, path, expansions);		return;	    } else if (*cp != '\0') {		/*		 * Back up to the start of the component		 */		char  *dirpath;		while (cp > word && *cp != '/') {		    cp--;		}		if (cp != word) {		    char sc;		    /*		     * If the glob isn't in the first component, try and find		     * all the components up to the one with a wildcard.		     */		    sc = cp[1];		    cp[1] = '\0';		    dirpath = Dir_FindFile(word, path);		    cp[1] = sc;		    /*		     * dirpath is null if can't find the leading component		     * XXX: Dir_FindFile won't find internal components.		     * i.e. if the path contains ../Etc/Object and we're		     * looking for Etc, it won't be found. Ah well.		     * Probably not important.		     */		    if (dirpath != (char *)NULL) {			char *dp = &dirpath[strlen(dirpath) - 1];			if (*dp == '/')			    *dp = '\0';			path = Lst_Init();			Dir_AddDir(path, dirpath);			DirExpandInt(cp+1, path, expansions);			Lst_Destroy(path, NOFREE);		    }		} else {		    /*		     * Start the search from the local directory		     */		    DirExpandInt(word, path, expansions);		}	    } else {		/*		 * Return the file -- this should never happen.		 */		DirExpandInt(word, path, expansions);	    }	} else {	    /*	     * First the files in dot	     */	    DirMatchFiles(word, dot, expansions);	    /*	     * Then the files in every other directory on the path.	     */	    DirExpandInt(word, path, expansions);	}    }    if (DEBUG(DIR)) {	Lst_Every(expansions, DirPrintWord);	fputc('\n', stdout);    }}