Ejemplo n.º 1
0
void
hashdir(char **dirp)
{
    Cmdnam cn;
    DIR *dir;
    char *fn;

    if (isrelative(*dirp) || !(dir = opendir(unmeta(*dirp))))
	return;

    while ((fn = zreaddir(dir))) {
	/* Ignore `.' and `..'. */
	if (fn[0] == '.' &&
	    (fn[1] == '\0' ||
	     (fn[1] == '.' && fn[2] == '\0')))
	    continue;
#ifndef WINNT
	if (!cmdnamtab->getnode(cmdnamtab, fn)) {
	    cn = (Cmdnam) zcalloc(sizeof *cn);
	    cn->flags = 0;
	    cn->u.name = dirp;
	    cmdnamtab->addnode(cmdnamtab, ztrdup(fn), cn);
	}
#else
	if (!cmdnamtab->getnode(cmdnamtab, fn)) {
	    char *fext;
	    fext = fn;
	    while(*fext++)
		;

	    while((fext >fn )&& (*fext != '.'))
		fext--;

	    if ( (fext == fn) /*no extension */
		    || is_pathext(fext+1) ) {
		cn = (Cmdnam) zcalloc(sizeof *cn);
		cn->flags = 0;
		cn->u.name = dirp;
		cmdnamtab->addnode(cmdnamtab, ztrdup(fn), cn);

		/*if (fext != fn && !strnicmp(fext+1,"exe",3)) */

		*fext = 0;
		cn = (Cmdnam) zcalloc(sizeof *cn);
		cn->flags = 0;
		cn->u.name = dirp;

		cmdnamtab->addnode(cmdnamtab, ztrdup(fn), cn);
	    }
#ifdef ZSH_HASH_DEBUG
	    printhashtabinfo(cmdnamtab);
#endif /* ZSH_HASH_DEBUG */
	}
#endif /* WINNT */
    }
    closedir(dir);
}
Ejemplo n.º 2
0
static DWORD get_file_attributes(const char *filename, const char *extension, int hasext, int mode, int *isx)
{
	char *buf;
	size_t filenamelen;
	DWORD attribs, bintype;

	filenamelen = strlen(filename);
	if (hasext) {
		buf = (char *)_alloca(filenamelen + 1);
		strcpy(buf, filename);
	} else {
		buf = (char *)_alloca(filenamelen + strlen(extension) + 1);
		strcpy(buf, filename);
		strcpy(buf + filenamelen, extension);
	}
	attribs = GetFileAttributes(buf);
	if ((attribs != (DWORD)(-1)) && (mode & X_OK) &&
	    (GetBinaryType(buf, &bintype) || is_pathext(extension)))
		/* found, and executable */
		*isx = 1;
	else
		*isx = 0;
	return attribs;
}