Exemplo n.º 1
0
void
plugh(struct rule *r, char *bfr, int size)
{
    switch (r->action) {
    case FILTER:
    case FFILTER:
	    filter_it(bfr, size, r);
	    break;
    case PIPE:
    case FPIPE:
	    pipe_it(bfr, size, r);
	    break;
    case TEXT:
    case POSTSCRIPT:
    case CAT:
	    cat_it(bfr, size, r);
	    break;
    case REJECT:
	    reject(filetype ? "can't print %s files"
			    : "can't print this file", filetype);
    default:
	    reject("internal processing error (r->action = %d)", r->action);
    }
    exit(1);
}
/**
 * list_dir - Recursively goes through all the folders
 * @dir_name: path
 * @len: length of original path
 * @tree: path to ntree 
 * Description: Puts all file/folder names to an ntree
 */
void list_dir (char * dir_name, int len, NTree **tree)
{
	DIR * d;
	d = opendir (dir_name);
	while (1)
	{
		char **array;
		struct dirent * entry;
		char * d_name;
		entry = readdir (d);
		if (! entry)
		{
			break;
		}
		d_name = entry->d_name;
		if (strcmp(d_name, ".") == 0 || strcmp(d_name, "..") == 0)
		{ 
			continue;
		}
		filter_it(dir_name+len);
		ntree_insert(tree, (array = string_split(dir_name, ' ')), d_name);
		free_str_array(array);
		filter_back(dir_name+len);
		if (entry->d_type & DT_DIR)
		{
			if (strcmp(d_name, "..")!=0 && strcmp(d_name, ".")!=0)
			{
				char *path;
				path = string_concat(dir_name, '/', d_name);
				list_dir (path, len, tree);
				free(path);
			}
		}
	}
	closedir (d);
}