Example #1
0
t_infos	*ft_newl(t_infos *llist, struct dirent *ret, t_opt *option, char *path)
{
	t_infos		*node;
	struct stat buf;

	if (!(node = (t_infos*)malloc(sizeof(t_infos))))
		print_err(1, '-');
	ft_putnull(node);
	ft_bzero(node->rights, 12);
	node->path = createpath(ret->d_name, path);
	if (lstat(node->path, &buf) == -1)
		perror("Erreur de lstat =");
	node->type = typedefine(ret->d_type);
	if (node->type == 0)
		node->type = typedefineargs(buf.st_mode);
	node->name = ft_strdup(ret->d_name);
	if (check_long_flag(option) == 1)
		ft_fillstats(node, &buf, option);
	if (!llist)
	{
		llist = node;
		node->nxt = NULL;
	}
	else
		llist = ft_sort(llist, node, option->flag);
	return (llist);
}
Example #2
0
path *addpthdir(path *pth, char *dir)
{
	char *withslash = addslash(dir);
	if (hasdir( withslash, pth) == -1) {
		path *newpath = createpath(dir);
		newpath->next = pth->next;
		pth->next = newpath;
	}
	return pth;
}
Example #3
0
int main()
{
	char line[MAXLINE];
	path *pth = createpath("");
	while (1) {
		programlist *pgl;
		
		if (printprompt() == -1) {
			fprintf(stderr, "Getting current directory failed.\n");
		}

		fgets(line, MAXLINE, stdin);
		pgl = parseline(line, pth);

		int child;
		if(handleexit(pgl) == 0){
			cleanuppgl(pgl);
			exit(0);
		}
		if (handlechdir(pgl) <= 0){
			cleanuppgl(pgl);
			continue;
		} else if (handlepath(pgl, pth) <= 0) {
			cleanuppgl(pgl);
			continue;
		}
		child = fork();
		if (child == 0) {
			execline(pgl, pth);
			/*printf("executed line\n"); */
			cleanuppgl(pgl);
			exit(0);
		} else {
			int status;
			int waitret;

			while (1) {
				waitret = wait(&status);
				/* printf("wait ret = %d\n", waitret); */
				if (waitret == -1 && errno == ECHILD) {
					break;
				} else if (waitret == -1 && errno != ECHILD) {
					fprintf(stderr, "Wait failed\n");
					break;
				}
			}
			cleanuppgl(pgl);
		}
	}

	return 0;
}