some token stuff
This commit is contained in:
parent
c5b837a8e6
commit
fff4912306
11 changed files with 267 additions and 109 deletions
213
42sh/Session.vim
213
42sh/Session.vim
|
|
@ -3,12 +3,12 @@ if &cp | set nocp | endif
|
||||||
let s:so_save = &so | let s:siso_save = &siso | set so=0 siso=0
|
let s:so_save = &so | let s:siso_save = &siso | set so=0 siso=0
|
||||||
let v:this_session=expand("<sfile>:p")
|
let v:this_session=expand("<sfile>:p")
|
||||||
silent only
|
silent only
|
||||||
cd ~/42/minishell
|
cd ~/minishell
|
||||||
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
|
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
|
||||||
let s:wipebuf = bufnr('%')
|
let s:wipebuf = bufnr('%')
|
||||||
endif
|
endif
|
||||||
set shortmess=aoO
|
set shortmess=aoO
|
||||||
badd +1 includes/minishell.h
|
badd +38 includes/minishell.h
|
||||||
badd +1 src/user-interaction/ft_word_left.c
|
badd +1 src/user-interaction/ft_word_left.c
|
||||||
badd +11 src/user-interaction/ft_cursor_left.c
|
badd +11 src/user-interaction/ft_cursor_left.c
|
||||||
badd +8 src/user-interaction/ft_interactive_sh.c
|
badd +8 src/user-interaction/ft_interactive_sh.c
|
||||||
|
|
@ -17,7 +17,7 @@ badd +18 src/user-interaction/ft_cursor_right.c
|
||||||
badd +7 src/user-interaction/ft_clear_line.c
|
badd +7 src/user-interaction/ft_clear_line.c
|
||||||
badd +1 src/user-interaction/ft_line_start.c
|
badd +1 src/user-interaction/ft_line_start.c
|
||||||
badd +5 src/user-interaction/ft_line_end.c
|
badd +5 src/user-interaction/ft_line_end.c
|
||||||
badd +1 src/main/main.c
|
badd +2 src/main/main.c
|
||||||
badd +12 src/builtin/builtin_exit.c
|
badd +12 src/builtin/builtin_exit.c
|
||||||
badd +1 src/user-interaction/ft_cmd.c
|
badd +1 src/user-interaction/ft_cmd.c
|
||||||
badd +8 src/line-editing/ft_cmd.c
|
badd +8 src/line-editing/ft_cmd.c
|
||||||
|
|
@ -25,7 +25,7 @@ badd +2 src/main/ft_cmd.c
|
||||||
badd +13 src/main/sig_handler.c
|
badd +13 src/main/sig_handler.c
|
||||||
badd +1 src/main/prompt.c
|
badd +1 src/main/prompt.c
|
||||||
badd +3 src/main/ft_prompt.c
|
badd +3 src/main/ft_prompt.c
|
||||||
badd +45 src/line-editing/ft_interactive_sh.c
|
badd +24 src/line-editing/ft_interactive_sh.c
|
||||||
badd +7 src/line-editing/ft_key_ctrl_d.c
|
badd +7 src/line-editing/ft_key_ctrl_d.c
|
||||||
badd +32 src/builtin/builtin_cd.c
|
badd +32 src/builtin/builtin_cd.c
|
||||||
badd +4 src/main/lib_expansion.c
|
badd +4 src/main/lib_expansion.c
|
||||||
|
|
@ -37,7 +37,7 @@ badd +10 src/line-editing/ft_key_enter.c
|
||||||
badd +16 src/line-editing/ft_history_add.c
|
badd +16 src/line-editing/ft_history_add.c
|
||||||
badd +9 src/line-editing/ft_history_up.c
|
badd +9 src/line-editing/ft_history_up.c
|
||||||
badd +18 src/line-editing/ft_history_down.c
|
badd +18 src/line-editing/ft_history_down.c
|
||||||
badd +19 src/token/ft_tokenize.c
|
badd +26 src/token/ft_tokenize.c
|
||||||
badd +30 src/line-editing/line-editing.h
|
badd +30 src/line-editing/line-editing.h
|
||||||
badd +1 libft/Makefile
|
badd +1 libft/Makefile
|
||||||
badd +36 Makefile
|
badd +36 Makefile
|
||||||
|
|
@ -50,13 +50,21 @@ badd +14 src/line-editing/ft_prompt.c
|
||||||
badd +22 src/line-editing/ft_tc_init.c
|
badd +22 src/line-editing/ft_tc_init.c
|
||||||
badd +33 libft/includes/libft.h
|
badd +33 libft/includes/libft.h
|
||||||
badd +5 libft/includes/get_next_line.h
|
badd +5 libft/includes/get_next_line.h
|
||||||
badd +22 src/token/token_init.c
|
badd +21 src/token/token_init.c
|
||||||
badd +1 src/token/includes/token.h
|
badd +32 src/token/includes/token.h
|
||||||
badd +15 src/token/token_recognition.c
|
badd +15 src/token/token_recognition.c
|
||||||
argglobal
|
badd +1 src
|
||||||
|
badd +14 src/token/token_append.c
|
||||||
|
badd +20 libft/src/mem/ft_realloc.c
|
||||||
|
badd +12 libft/src/mem/ft_memcpy.c
|
||||||
|
badd +23 libft/src/mem/ft_memalloc.c
|
||||||
|
badd +1 libft/src/mem/ft_memset.c
|
||||||
|
badd +23 libft/src/mem/ft_memmove.c
|
||||||
|
badd +14 libft/src/mem/ft_memchr.c
|
||||||
|
badd +13 src/token/token_delimit.c
|
||||||
|
badd +0 src/token/token_operator_match.c
|
||||||
silent! argdel *
|
silent! argdel *
|
||||||
set stal=2
|
edit src/main/main.c
|
||||||
edit includes/minishell.h
|
|
||||||
set splitbelow splitright
|
set splitbelow splitright
|
||||||
wincmd _ | wincmd |
|
wincmd _ | wincmd |
|
||||||
vsplit
|
vsplit
|
||||||
|
|
@ -66,8 +74,8 @@ set nosplitbelow
|
||||||
set nosplitright
|
set nosplitright
|
||||||
wincmd t
|
wincmd t
|
||||||
set winheight=1 winwidth=1
|
set winheight=1 winwidth=1
|
||||||
exe 'vert 1resize ' . ((&columns * 89 + 89) / 178)
|
exe 'vert 1resize ' . ((&columns * 91 + 90) / 180)
|
||||||
exe 'vert 2resize ' . ((&columns * 88 + 89) / 178)
|
exe 'vert 2resize ' . ((&columns * 88 + 90) / 180)
|
||||||
argglobal
|
argglobal
|
||||||
setlocal fdm=manual
|
setlocal fdm=manual
|
||||||
setlocal fde=0
|
setlocal fde=0
|
||||||
|
|
@ -78,12 +86,12 @@ setlocal fml=1
|
||||||
setlocal fdn=20
|
setlocal fdn=20
|
||||||
setlocal fen
|
setlocal fen
|
||||||
silent! normal! zE
|
silent! normal! zE
|
||||||
let s:l = 43 - ((18 * winheight(0) + 20) / 40)
|
let s:l = 35 - ((34 * winheight(0) + 37) / 75)
|
||||||
if s:l < 1 | let s:l = 1 | endif
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
exe s:l
|
exe s:l
|
||||||
normal! zt
|
normal! zt
|
||||||
43
|
35
|
||||||
normal! 046|
|
normal! 020l
|
||||||
wincmd w
|
wincmd w
|
||||||
argglobal
|
argglobal
|
||||||
edit src/line-editing/includes/line_editing.h
|
edit src/line-editing/includes/line_editing.h
|
||||||
|
|
@ -96,65 +104,16 @@ setlocal fml=1
|
||||||
setlocal fdn=20
|
setlocal fdn=20
|
||||||
setlocal fen
|
setlocal fen
|
||||||
silent! normal! zE
|
silent! normal! zE
|
||||||
let s:l = 46 - ((25 * winheight(0) + 20) / 40)
|
let s:l = 2 - ((1 * winheight(0) + 37) / 75)
|
||||||
if s:l < 1 | let s:l = 1 | endif
|
|
||||||
exe s:l
|
|
||||||
normal! zt
|
|
||||||
46
|
|
||||||
normal! 0
|
|
||||||
wincmd w
|
|
||||||
exe 'vert 1resize ' . ((&columns * 89 + 89) / 178)
|
|
||||||
exe 'vert 2resize ' . ((&columns * 88 + 89) / 178)
|
|
||||||
tabedit src/main/main.c
|
|
||||||
set splitbelow splitright
|
|
||||||
wincmd _ | wincmd |
|
|
||||||
vsplit
|
|
||||||
1wincmd h
|
|
||||||
wincmd w
|
|
||||||
set nosplitbelow
|
|
||||||
set nosplitright
|
|
||||||
wincmd t
|
|
||||||
set winheight=1 winwidth=1
|
|
||||||
exe 'vert 1resize ' . ((&columns * 89 + 89) / 178)
|
|
||||||
exe 'vert 2resize ' . ((&columns * 88 + 89) / 178)
|
|
||||||
argglobal
|
|
||||||
setlocal fdm=manual
|
|
||||||
setlocal fde=0
|
|
||||||
setlocal fmr={{{,}}}
|
|
||||||
setlocal fdi=#
|
|
||||||
setlocal fdl=0
|
|
||||||
setlocal fml=1
|
|
||||||
setlocal fdn=20
|
|
||||||
setlocal fen
|
|
||||||
silent! normal! zE
|
|
||||||
let s:l = 2 - ((1 * winheight(0) + 20) / 40)
|
|
||||||
if s:l < 1 | let s:l = 1 | endif
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
exe s:l
|
exe s:l
|
||||||
normal! zt
|
normal! zt
|
||||||
2
|
2
|
||||||
normal! 016|
|
normal! 0
|
||||||
wincmd w
|
wincmd w
|
||||||
argglobal
|
exe 'vert 1resize ' . ((&columns * 91 + 90) / 180)
|
||||||
edit src/line-editing/ft_interactive_sh.c
|
exe 'vert 2resize ' . ((&columns * 88 + 90) / 180)
|
||||||
setlocal fdm=manual
|
tabedit src/token/ft_tokenize.c
|
||||||
setlocal fde=0
|
|
||||||
setlocal fmr={{{,}}}
|
|
||||||
setlocal fdi=#
|
|
||||||
setlocal fdl=0
|
|
||||||
setlocal fml=1
|
|
||||||
setlocal fdn=20
|
|
||||||
setlocal fen
|
|
||||||
silent! normal! zE
|
|
||||||
let s:l = 15 - ((14 * winheight(0) + 20) / 40)
|
|
||||||
if s:l < 1 | let s:l = 1 | endif
|
|
||||||
exe s:l
|
|
||||||
normal! zt
|
|
||||||
15
|
|
||||||
normal! 016|
|
|
||||||
wincmd w
|
|
||||||
exe 'vert 1resize ' . ((&columns * 89 + 89) / 178)
|
|
||||||
exe 'vert 2resize ' . ((&columns * 88 + 89) / 178)
|
|
||||||
tabedit src/token/includes/token.h
|
|
||||||
set splitbelow splitright
|
set splitbelow splitright
|
||||||
wincmd _ | wincmd |
|
wincmd _ | wincmd |
|
||||||
vsplit
|
vsplit
|
||||||
|
|
@ -164,8 +123,8 @@ set nosplitbelow
|
||||||
set nosplitright
|
set nosplitright
|
||||||
wincmd t
|
wincmd t
|
||||||
set winheight=1 winwidth=1
|
set winheight=1 winwidth=1
|
||||||
exe 'vert 1resize ' . ((&columns * 89 + 89) / 178)
|
exe 'vert 1resize ' . ((&columns * 90 + 90) / 180)
|
||||||
exe 'vert 2resize ' . ((&columns * 88 + 89) / 178)
|
exe 'vert 2resize ' . ((&columns * 89 + 90) / 180)
|
||||||
argglobal
|
argglobal
|
||||||
setlocal fdm=manual
|
setlocal fdm=manual
|
||||||
setlocal fde=0
|
setlocal fde=0
|
||||||
|
|
@ -176,15 +135,16 @@ setlocal fml=1
|
||||||
setlocal fdn=20
|
setlocal fdn=20
|
||||||
setlocal fen
|
setlocal fen
|
||||||
silent! normal! zE
|
silent! normal! zE
|
||||||
let s:l = 29 - ((27 * winheight(0) + 20) / 40)
|
let s:l = 28 - ((27 * winheight(0) + 37) / 75)
|
||||||
if s:l < 1 | let s:l = 1 | endif
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
exe s:l
|
exe s:l
|
||||||
normal! zt
|
normal! zt
|
||||||
29
|
28
|
||||||
normal! 029|
|
normal! 0
|
||||||
|
lcd ~/minishell
|
||||||
wincmd w
|
wincmd w
|
||||||
argglobal
|
argglobal
|
||||||
edit src/token/ft_tokenize.c
|
edit ~/minishell/src/token/includes/token.h
|
||||||
setlocal fdm=manual
|
setlocal fdm=manual
|
||||||
setlocal fde=0
|
setlocal fde=0
|
||||||
setlocal fmr={{{,}}}
|
setlocal fmr={{{,}}}
|
||||||
|
|
@ -194,22 +154,28 @@ setlocal fml=1
|
||||||
setlocal fdn=20
|
setlocal fdn=20
|
||||||
setlocal fen
|
setlocal fen
|
||||||
silent! normal! zE
|
silent! normal! zE
|
||||||
let s:l = 36 - ((19 * winheight(0) + 20) / 40)
|
let s:l = 48 - ((39 * winheight(0) + 37) / 75)
|
||||||
if s:l < 1 | let s:l = 1 | endif
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
exe s:l
|
exe s:l
|
||||||
normal! zt
|
normal! zt
|
||||||
36
|
48
|
||||||
normal! 028|
|
normal! 0
|
||||||
wincmd w
|
wincmd w
|
||||||
2wincmd w
|
2wincmd w
|
||||||
exe 'vert 1resize ' . ((&columns * 89 + 89) / 178)
|
exe 'vert 1resize ' . ((&columns * 90 + 90) / 180)
|
||||||
exe 'vert 2resize ' . ((&columns * 88 + 89) / 178)
|
exe 'vert 2resize ' . ((&columns * 89 + 90) / 180)
|
||||||
tabedit src/token/token_init.c
|
tabedit ~/minishell/src/token/token_delimit.c
|
||||||
set splitbelow splitright
|
set splitbelow splitright
|
||||||
|
wincmd _ | wincmd |
|
||||||
|
vsplit
|
||||||
|
1wincmd h
|
||||||
|
wincmd w
|
||||||
set nosplitbelow
|
set nosplitbelow
|
||||||
set nosplitright
|
set nosplitright
|
||||||
wincmd t
|
wincmd t
|
||||||
set winheight=1 winwidth=1
|
set winheight=1 winwidth=1
|
||||||
|
exe 'vert 1resize ' . ((&columns * 90 + 90) / 180)
|
||||||
|
exe 'vert 2resize ' . ((&columns * 89 + 90) / 180)
|
||||||
argglobal
|
argglobal
|
||||||
setlocal fdm=manual
|
setlocal fdm=manual
|
||||||
setlocal fde=0
|
setlocal fde=0
|
||||||
|
|
@ -220,14 +186,89 @@ setlocal fml=1
|
||||||
setlocal fdn=20
|
setlocal fdn=20
|
||||||
setlocal fen
|
setlocal fen
|
||||||
silent! normal! zE
|
silent! normal! zE
|
||||||
let s:l = 19 - ((10 * winheight(0) + 20) / 40)
|
let s:l = 13 - ((12 * winheight(0) + 37) / 75)
|
||||||
if s:l < 1 | let s:l = 1 | endif
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
exe s:l
|
exe s:l
|
||||||
normal! zt
|
normal! zt
|
||||||
19
|
13
|
||||||
normal! 035|
|
normal! 017l
|
||||||
tabnext 3
|
lcd ~/minishell
|
||||||
set stal=1
|
wincmd w
|
||||||
|
argglobal
|
||||||
|
edit ~/minishell/src/token/token_operator_match.c
|
||||||
|
setlocal fdm=manual
|
||||||
|
setlocal fde=0
|
||||||
|
setlocal fmr={{{,}}}
|
||||||
|
setlocal fdi=#
|
||||||
|
setlocal fdl=0
|
||||||
|
setlocal fml=1
|
||||||
|
setlocal fdn=20
|
||||||
|
setlocal fen
|
||||||
|
silent! normal! zE
|
||||||
|
let s:l = 16 - ((15 * winheight(0) + 37) / 75)
|
||||||
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
|
exe s:l
|
||||||
|
normal! zt
|
||||||
|
16
|
||||||
|
normal! 0
|
||||||
|
lcd ~/minishell
|
||||||
|
wincmd w
|
||||||
|
2wincmd w
|
||||||
|
exe 'vert 1resize ' . ((&columns * 90 + 90) / 180)
|
||||||
|
exe 'vert 2resize ' . ((&columns * 89 + 90) / 180)
|
||||||
|
tabedit ~/minishell/libft/src/mem/ft_realloc.c
|
||||||
|
set splitbelow splitright
|
||||||
|
wincmd _ | wincmd |
|
||||||
|
vsplit
|
||||||
|
1wincmd h
|
||||||
|
wincmd w
|
||||||
|
set nosplitbelow
|
||||||
|
set nosplitright
|
||||||
|
wincmd t
|
||||||
|
set winheight=1 winwidth=1
|
||||||
|
exe 'vert 1resize ' . ((&columns * 90 + 90) / 180)
|
||||||
|
exe 'vert 2resize ' . ((&columns * 89 + 90) / 180)
|
||||||
|
argglobal
|
||||||
|
setlocal fdm=manual
|
||||||
|
setlocal fde=0
|
||||||
|
setlocal fmr={{{,}}}
|
||||||
|
setlocal fdi=#
|
||||||
|
setlocal fdl=0
|
||||||
|
setlocal fml=1
|
||||||
|
setlocal fdn=20
|
||||||
|
setlocal fen
|
||||||
|
silent! normal! zE
|
||||||
|
let s:l = 15 - ((14 * winheight(0) + 37) / 75)
|
||||||
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
|
exe s:l
|
||||||
|
normal! zt
|
||||||
|
15
|
||||||
|
normal! 014l
|
||||||
|
lcd ~/minishell
|
||||||
|
wincmd w
|
||||||
|
argglobal
|
||||||
|
edit ~/minishell/libft/includes/libft.h
|
||||||
|
setlocal fdm=manual
|
||||||
|
setlocal fde=0
|
||||||
|
setlocal fmr={{{,}}}
|
||||||
|
setlocal fdi=#
|
||||||
|
setlocal fdl=0
|
||||||
|
setlocal fml=1
|
||||||
|
setlocal fdn=20
|
||||||
|
setlocal fen
|
||||||
|
silent! normal! zE
|
||||||
|
let s:l = 131 - ((61 * winheight(0) + 37) / 75)
|
||||||
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
|
exe s:l
|
||||||
|
normal! zt
|
||||||
|
131
|
||||||
|
normal! 0
|
||||||
|
lcd ~/minishell
|
||||||
|
wincmd w
|
||||||
|
2wincmd w
|
||||||
|
exe 'vert 1resize ' . ((&columns * 90 + 90) / 180)
|
||||||
|
exe 'vert 2resize ' . ((&columns * 89 + 90) / 180)
|
||||||
|
tabnext 2
|
||||||
if exists('s:wipebuf')
|
if exists('s:wipebuf')
|
||||||
silent exe 'bwipe ' . s:wipebuf
|
silent exe 'bwipe ' . s:wipebuf
|
||||||
endif
|
endif
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/10 14:54:23 by jhalford ### ########.fr */
|
/* Updated: 2016/11/11 17:04:25 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 87f043154c8e46ae7d0df30ec25ee420ce1b8099
|
Subproject commit 87a0b6b9b00cafbdcf00ca1398b6dfd64a670fcc
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 13:44:21 by jhalford #+# #+# */
|
/* Created: 2016/11/10 13:44:21 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/10 14:59:44 by jhalford ### ########.fr */
|
/* Updated: 2016/11/11 14:39:10 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 13:35:14 by jhalford #+# #+# */
|
/* Created: 2016/11/10 13:35:14 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/10 15:43:18 by jhalford ### ########.fr */
|
/* Updated: 2016/11/11 17:10:01 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -34,6 +34,8 @@ int main(void)
|
||||||
cmd = ft_strdup(data.history->prev->content);
|
cmd = ft_strdup(data.history->prev->content);
|
||||||
g_mode = MODE_EXEC;
|
g_mode = MODE_EXEC;
|
||||||
|
|
||||||
|
ft_printf("got command:'%s'\n", cmd);
|
||||||
|
|
||||||
/* (void)av; */
|
/* (void)av; */
|
||||||
/* ft_printf("got string:'%s'\n", cmd); */
|
/* ft_printf("got string:'%s'\n", cmd); */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,27 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */
|
/* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/10 17:04:10 by jhalford ### ########.fr */
|
/* Updated: 2016/11/11 20:37:49 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
t_operator g_ops[] =
|
||||||
|
{
|
||||||
|
{TK_LESS, "<", NUM_BEFORE | WORD_AFTER},
|
||||||
|
{TK_GREAT, ">", NUM_BEFORE | WORD_AFTER},
|
||||||
|
{TK_DGREAT, ">>", NUM_BEFORE | WORD_AFTER},
|
||||||
|
|
||||||
|
{TK_LESSAND, "<&", NUM_BEFORE | WORD_AFTER | MIN_END},
|
||||||
|
{TK_GREATAND, ">&", NUM_BEFORE | WORD_AFTER | MIN_END},
|
||||||
|
|
||||||
|
{TK_DLESS, "<<", NUM_BEFORE | WORD_AFTER},
|
||||||
|
|
||||||
|
{TK_SCOLON, ";", 0},
|
||||||
|
{TK_PIPE, "|", 0},
|
||||||
|
}
|
||||||
|
|
||||||
int ft_tokenize(t_list **alst, char *str)
|
int ft_tokenize(t_list **alst, char *str)
|
||||||
{
|
{
|
||||||
static int quoted = 0;
|
static int quoted = 0;
|
||||||
|
|
@ -22,24 +37,35 @@ int ft_tokenize(t_list **alst, char *str)
|
||||||
else
|
else
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
if (!*str)
|
if (!*str)
|
||||||
return (0);
|
|
||||||
else if ((token->type >= TK_OP_MIN) && !quoted)
|
|
||||||
{
|
{
|
||||||
if (can_be_used_in_op)
|
token_delimit(token);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
else if ((token->type | TK_OPERATOR) && !quoted)
|
||||||
|
{
|
||||||
|
if (token_operator_match(token, *str))
|
||||||
token_append(token, *str);
|
token_append(token, *str);
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
token_delimit(token);
|
||||||
ft_tokenize(&(*alst)->next, str);
|
ft_tokenize(&(*alst)->next, str);
|
||||||
}
|
}
|
||||||
else if (can_be_first_of_op && !quoted)
|
}
|
||||||
|
else if (ft_strchr(OPERATOR_START, *str) && !quoted)
|
||||||
{
|
{
|
||||||
|
token_delimit(token);
|
||||||
(*alst)->next = ft_lstnew(token_init(), sizeof(t_token));
|
(*alst)->next = ft_lstnew(token_init(), sizeof(t_token));
|
||||||
(*alst) = (*alst)->next;
|
(*alst) = (*alst)->next;
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
|
token->type = TK_UNKNOWN;
|
||||||
|
token_append(token, *str);
|
||||||
|
ft_tokenize(alst, str + 1);
|
||||||
}
|
}
|
||||||
else if (*str == '\n' && !quoted)
|
|
||||||
ft_tokenize(&(*alst)->next, str + 1);
|
|
||||||
else if (*str == ' ' && !quoted)
|
else if (*str == ' ' && !quoted)
|
||||||
|
{
|
||||||
|
token_delimit(token);
|
||||||
ft_tokenize(&(*alst)->next, str + 1);
|
ft_tokenize(&(*alst)->next, str + 1);
|
||||||
|
}
|
||||||
else if (token->type == TOKEN_WORD)
|
else if (token->type == TOKEN_WORD)
|
||||||
token_append(token, *str);
|
token_append(token, *str);
|
||||||
else if (*str = '#')
|
else if (*str = '#')
|
||||||
|
|
@ -48,8 +74,11 @@ int ft_tokenize(t_list **alst, char *str)
|
||||||
str++;
|
str++;
|
||||||
ft_tokenize(alst, str);
|
ft_tokenize(alst, str);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
(*alst)->next = ft_lstnew(token_init(), sizeof(t_token));
|
(*alst)->next = ft_lstnew(token_init(), sizeof(t_token));
|
||||||
token->type = TK_WORD;
|
token->type = TK_WORD;
|
||||||
token_append(token, *str);
|
token_append(token, *str);
|
||||||
|
}
|
||||||
ft_tokenize(&(*alst)->next, str + 1);
|
ft_tokenize(&(*alst)->next, str + 1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,40 +6,67 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 15:31:42 by jhalford #+# #+# */
|
/* Created: 2016/11/10 15:31:42 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/10 17:04:12 by jhalford ### ########.fr */
|
/* Updated: 2016/11/11 20:44:28 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef TOKEN_H
|
#ifndef TOKEN_H
|
||||||
# define TOKEN_H
|
# define TOKEN_H
|
||||||
|
|
||||||
|
typedef long long t_type;
|
||||||
|
|
||||||
# define TK_WORD 0x0001
|
# define TK_WORD 0x0001
|
||||||
# define TK_NEWLINE 0x0002
|
# define TK_NEWLINE 0x0002
|
||||||
# define TK_IOHERE 0x0004
|
# define TK_IOHERE 0x0004
|
||||||
|
|
||||||
# define TK_LESS 0x0010
|
# define TK_LESS 0x0010
|
||||||
# define TK_GREAT 0x0020
|
# define TK_GREAT 0x0020
|
||||||
# define TK_DLESS 0x0048
|
# define TK_DLESS 0x0040
|
||||||
# define TK_DGREAT 0x0080
|
# define TK_DGREAT 0x0080
|
||||||
# define TK_LESSAND 0x0100
|
# define TK_LESSAND 0x0100
|
||||||
# define TK_GREATAND 0x0200
|
# define TK_GREATAND 0x0200
|
||||||
# define TK_SCOLON 0x0400
|
# define TK_SCOLON 0x0400
|
||||||
# define TK_PIPE 0x0800
|
# define TK_PIPE 0x0800
|
||||||
|
# define TK_UNKNOWN 0x1000
|
||||||
|
|
||||||
# define TK_OP_MIN TK_LESS
|
# define TK_OPERATOR 1 & (~TK_WORD | ~TK_NEWLINE | ~TK_IOHERE)
|
||||||
|
# define OPERATOR_ST "<>;|0123456789"
|
||||||
|
|
||||||
|
# define NUM_BEFORE 0x0001
|
||||||
|
# define WORD_AFTER 0x0002
|
||||||
|
# define MIN_END 0x0004
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct s_operator t_operator;
|
||||||
typedef struct s_token t_token;
|
typedef struct s_token t_token;
|
||||||
|
typedef struct s_redir t_redir;
|
||||||
|
|
||||||
|
struct s_operator
|
||||||
|
{
|
||||||
|
t_type type;
|
||||||
|
char symbol[3];
|
||||||
|
t_type format;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_redir
|
||||||
|
{
|
||||||
|
t_type type;
|
||||||
|
int fd;
|
||||||
|
char *filename;
|
||||||
|
};
|
||||||
|
|
||||||
struct s_token
|
struct s_token
|
||||||
{
|
{
|
||||||
int type;
|
t_type type;
|
||||||
int id;
|
|
||||||
char *content;
|
char *content;
|
||||||
char *size;
|
char *size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern t_operator g_ops[];
|
||||||
|
|
||||||
t_token *token_init();
|
t_token *token_init();
|
||||||
int ft_tokenize(t_list **alst, char *str);
|
int ft_tokenize(t_list **alst, char *str);
|
||||||
int token_recognition(t_list *alst, char *str);
|
int token_recognition(t_list *alst, char *str);
|
||||||
|
int token_append(t_token *token, char str);
|
||||||
|
int token_delimit(t_token *token);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
23
42sh/src/token/token_append.c
Normal file
23
42sh/src/token/token_append.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* token_append.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/11 17:18:42 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/11 17:47:15 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "token.h"
|
||||||
|
|
||||||
|
int token_append(t_token *token, char str)
|
||||||
|
{
|
||||||
|
if (ft_strlen(token->data) <= token->size)
|
||||||
|
{
|
||||||
|
token->data = (char *)ft_realloc(token->size + 10);
|
||||||
|
token->size += 10;
|
||||||
|
}
|
||||||
|
ft_strcat(token->data, &str);
|
||||||
|
}
|
||||||
18
42sh/src/token/token_delimit.c
Normal file
18
42sh/src/token/token_delimit.c
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* token_delimit.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/11 17:47:31 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/11 20:25:08 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "token.h"
|
||||||
|
|
||||||
|
int token_delimit(t_token *token)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 15:30:25 by jhalford #+# #+# */
|
/* Created: 2016/11/10 15:30:25 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/10 16:52:13 by jhalford ### ########.fr */
|
/* Updated: 2016/11/11 17:47:14 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
18
42sh/src/token/token_operator_match.c
Normal file
18
42sh/src/token/token_operator_match.c
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* token_operator_match.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/11 20:12:52 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/11 20:13:36 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "token.h"
|
||||||
|
|
||||||
|
int token_operator_match(t_token *token)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue