builtin_read first commit
This commit is contained in:
parent
4b22633cab
commit
ee7ddc5e14
6 changed files with 164 additions and 4 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 17:21:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/09 16:57:22 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/20 15:11:37 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
# include "types.h"
|
||||
# include "libft.h"
|
||||
# include "builtin_read.h"
|
||||
|
||||
t_execf *is_builtin(t_process *p);
|
||||
int builtin_env(const char *path, char *const argv[], char *const envp[]);
|
||||
|
|
|
|||
55
42sh/includes/builtin_read.h
Normal file
55
42sh/includes/builtin_read.h
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* builtin_read.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/20 19:32:45 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef BUILTIN_H
|
||||
# define BUILTIN_H
|
||||
|
||||
# include "types.h"
|
||||
# include "libft.h"
|
||||
# include "builtin.h"
|
||||
# include "minishell.h"
|
||||
|
||||
# define READ_OPT_LA (1 << 0)
|
||||
# define READ_OPT_LD (1 << 1)
|
||||
# define READ_OPT_LE (1 << 2)
|
||||
# define READ_OPT_LI (1 << 3)
|
||||
# define READ_OPT_LN (1 << 4)
|
||||
# define READ_OPT_UN (1 << 5)
|
||||
# define READ_OPT_LP (1 << 6)
|
||||
# define READ_OPT_LR (1 << 7)
|
||||
# define READ_OPT_LS (1 << 8)
|
||||
# define READ_OPT_LT (1 << 9)
|
||||
# define READ_OPT_LU (1 << 10)
|
||||
|
||||
typedef struct s_read t_read;
|
||||
|
||||
struct s_read
|
||||
{
|
||||
char delim;
|
||||
int nchars;
|
||||
char *prompt;
|
||||
int timeout;
|
||||
int fd;
|
||||
};
|
||||
|
||||
struct s_readopt
|
||||
{
|
||||
char letter;
|
||||
t_flag flag;
|
||||
int (*get)(t_read *data, char *arg);
|
||||
};
|
||||
|
||||
extern t_readopt g_readtab[];
|
||||
|
||||
int builtin_read(const char *path, char *const av[], char *const envp[]);
|
||||
|
||||
#endif
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/12 14:57:41 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/20 15:24:55 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
103
42sh/src/builtin/builtin_read.c
Normal file
103
42sh/src/builtin/builtin_read.c
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* builtin_read.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/20 19:32:44 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "builtin_read.h"
|
||||
|
||||
t_readopt g_readtab[] =
|
||||
{
|
||||
{'a', READ_OPT_LA, NULL},
|
||||
{'d', READ_OPT_LD, NULL},
|
||||
{'e', READ_OPT_LE, NULL},
|
||||
{'i', READ_OPT_LI, NULL},
|
||||
{'n', READ_OPT_LN, NULL},
|
||||
{'N', READ_OPT_UN, NULL},
|
||||
{'p', READ_OPT_LP, NULL},
|
||||
{'r', READ_OPT_LR, NULL},
|
||||
{'s', READ_OPT_LS, NULL},
|
||||
{'t', READ_OPT_LT, NULL},
|
||||
{'u', READ_OPT_LU, NULL},
|
||||
{0, 0, 0},
|
||||
};
|
||||
|
||||
void bt_read_init(t_read *data)
|
||||
{
|
||||
data.delim = '\n';
|
||||
data.nchars = -1;
|
||||
data.prompt = NULL;
|
||||
data.timeout = -1;
|
||||
data.fd = 0;
|
||||
}
|
||||
|
||||
t_readopt bt_read_getopt(char letter)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (g_readtab[i].letter)
|
||||
{
|
||||
if (g_readtab[i].letter == letter)
|
||||
return (g_readtab[i]);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int bt_read_parse(t_read *data, char **av)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
t_readopt opt;
|
||||
|
||||
while (av[i])
|
||||
{
|
||||
j = 0;
|
||||
if (av[i][j++] == '-')
|
||||
{
|
||||
if (av[i][j] == '-')
|
||||
{
|
||||
i++;
|
||||
break ;
|
||||
}
|
||||
while (av[i][j])
|
||||
{
|
||||
if (!(opt = bt_read_getopt(av[i][j])))
|
||||
{
|
||||
ft_dprintf(2, "%s: bad option: %c", SHELL_NAME, av[i][j]);
|
||||
return (2);
|
||||
}
|
||||
data->opts |= opt.flag;
|
||||
if (data->get)
|
||||
{
|
||||
(*data->get)(data, av[i + 1]);
|
||||
break ;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (av[i])
|
||||
bt_read_getnames(())
|
||||
return (0);
|
||||
}
|
||||
|
||||
int builtin_read(const char *path, char *const av[], char *const envp[])
|
||||
{
|
||||
t_read data;
|
||||
int i;
|
||||
|
||||
(void)path;
|
||||
(void)envp;
|
||||
bt_read_init(&data);
|
||||
if ((i = bt_read_parse(&data, (char **)av)))
|
||||
return (i);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/09 16:58:13 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/20 15:01:34 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,6 +22,7 @@ t_stof g_builtin[] = {
|
|||
{"jobs", &builtin_jobs},
|
||||
{"fg", &builtin_fg},
|
||||
{"bg", &builtin_bg},
|
||||
{"read", &builtin_read},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/12 14:02:30 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/01/20 15:23:46 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue