Commit graph

36 commits

Author SHA1 Message Date
826abdf623 fix(wildcard): error handling for wildcard expansion in redirections 2025-04-30 15:10:08 +02:00
04eabf096d fix(wildcard): error detection in wordlist_expand_star
Will help in closing #167
2025-04-30 14:55:12 +02:00
a8c3473b1a fix(norm): khais -> kcolin in headers
Closes #184
2025-04-30 11:29:20 +02:00
92d647e33c feat(redirections): allow a command composed only of redirections 2025-04-28 14:44:20 +02:00
e5027323e1 fix(field_splitting): ensure no extraneous spaces appear
debug notes:
= 250  !! OK ===================================================================
export HOLA="bonjour "
echo $HOLA | cat -e
= out =
bonjour $

= err =
rc: 0

= refout =
bonjour$

++++++++++++++++++++++++++++++++++++++++++++++++++++
failed: quote removal before word splitting
++++++++++++++++++++++++++++++++++++++++++++++++++++
++++ test input:
export VAR="hello "
echo $VAR | cat -e
++++ Got output:
hello $
++++ But expected:
hello$

Problem is in post-processing:
parsed command
 ╰─ t_cmd
     ├─ t_cmd_type = FT_SIMPLE
     ├─ flags = 0
     ├─ line = 0
     ╰─ value
         ╰─ t_simple_cmd
             ├─ line = 0
             ├─ t_wordlist
             │   ├─ t_worddesc
             │   │   ├─ word   = [echo]
             │   │   ├─ marker = [    ]
             │   │   ├─ flags = 0
             │   │   ╰─ t_token_type = WORD_TOKEN
             │   ╰─ t_worddesc
             │       ├─ word   = [$VAR]
             │       ├─ marker = [    ]
             │       ├─ flags = 1
             │       ╰─ t_token_type = WORD_TOKEN
             ╰─ redirections = (empty redir list)
about to post-process
 ╰─ t_simple_cmd
     ├─ line = 0
     ├─ t_wordlist
     │   ├─ t_worddesc
     │   │   ├─ word   = [echo]
     │   │   ├─ marker = [    ]
     │   │   ├─ flags = 0
     │   │   ╰─ t_token_type = WORD_TOKEN
     │   ╰─ t_worddesc
     │       ├─ word   = [$VAR]
     │       ├─ marker = [    ]
     │       ├─ flags = 1
     │       ╰─ t_token_type = WORD_TOKEN
     ╰─ redirections = (empty redir list)
about to post-process
 ╰─ t_simple_cmd
     ├─ line = 0
     ├─ t_wordlist
     │   ├─ t_worddesc
     │   │   ├─ word   = [echo]
     │   │   ├─ marker = [    ]
     │   │   ├─ flags = 0
     │   │   ╰─ t_token_type = WORD_TOKEN
     │   ╰─ t_worddesc
     │       ├─ word   = [hello ]
     │       ├─ marker = [$$$$$$]
     │       ├─ flags = 1
     │       ╰─ t_token_type = WORD_TOKEN
     ╰─ redirections = (empty redir list)
about to post-process
 ╰─ t_simple_cmd
     ├─ line = 0
     ├─ t_wordlist
     │   ├─ t_worddesc
     │   │   ├─ word   = [echo]
     │   │   ├─ marker = [    ]
     │   │   ├─ flags = 0
     │   │   ╰─ t_token_type = WORD_TOKEN
     │   ├─ t_worddesc
     │   │   ├─ word   = [hello]
     │   │   ├─ marker = [$$$$$]
     │   │   ├─ flags = 1
     │   │   ╰─ t_token_type = WORD_TOKEN
     │   ╰─ t_worddesc <---- WHAT IS THIS DOING HERE???
     │       ├─ word   = []
     │       ├─ marker = []
     │       ├─ flags = 1
     │       ╰─ t_token_type = WORD_TOKEN
     ╰─ redirections = (empty redir list)
about to post-process
 ╰─ t_simple_cmd
     ├─ line = 0
     ├─ t_wordlist
     │   ├─ t_worddesc
     │   │   ├─ word   = [echo]
     │   │   ├─ marker = [    ]
     │   │   ├─ flags = 0
     │   │   ╰─ t_token_type = WORD_TOKEN
     │   ├─ t_worddesc
     │   │   ├─ word   = [hello]
     │   │   ├─ marker = [$$$$$]
     │   │   ├─ flags = 1
     │   │   ╰─ t_token_type = WORD_TOKEN
     │   ╰─ t_worddesc
     │       ├─ word   = []
     │       ├─ marker = []
     │       ├─ flags = 1
     │       ╰─ t_token_type = WORD_TOKEN
     ╰─ redirections = (empty redir list)
about to execute
 ╰─ t_simple_cmd
     ├─ line = 0
     ├─ t_wordlist
     │   ├─ t_worddesc
     │   │   ├─ word   = [echo]
     │   │   ├─ marker = [(null)]
     │   │   ├─ flags = 0
     │   │   ╰─ t_token_type = WORD_TOKEN
     │   ├─ t_worddesc
     │   │   ├─ word   = [hello]
     │   │   ├─ marker = [(null)]
     │   │   ├─ flags = 1
     │   │   ╰─ t_token_type = WORD_TOKEN
     │   ╰─ t_worddesc
     │       ├─ word   = []
     │       ├─ marker = [(null)]
     │       ├─ flags = 1
     │       ╰─ t_token_type = WORD_TOKEN
     ╰─ redirections = (empty redir list)

Problem seems to be in field splitting
2025-04-25 14:32:16 +02:00
38ffac7fc3 feat(redir): expand wildcards in targets and handle ambiguous redirects 2025-04-24 12:45:00 +02:00
920ad586e1 refactor(redirect): ambiguous redirect message to own file 2025-04-24 12:45:00 +02:00
2dd20b21bc feat(redir): fieldsplit redir target, and handle ambiguous redirects 2025-04-24 12:44:33 +02:00
c00cc21ae4 feat(redirect): do variable expansion on redirect targets 2025-04-21 08:17:22 +02:00
655ff36351 fix(susbt/variable): empty variables on their own are removed 2025-04-18 09:22:18 +02:00
18014cda98
token_type: add field with no logic for populating it 2025-04-15 15:15:30 +02:00
be183b99ee
minishell: do wildcard expansion 2025-04-15 15:06:46 +02:00
32e3976774
field splitting: implement field splitting 2025-04-15 15:05:52 +02:00
bac3512898
minishell: do variable substitution in postprocessing 2025-04-01 13:50:14 +02:00
Jérôme Guélen
5ff990ef50 Parsing-refactor: Determining structures. 2025-03-28 15:03:15 +01:00
dff5de66da
fix redirection parsing sometimes skipping over redirections
This happens when multiple redirections are following each others, such as in

	 echo hi > out < in

which would be parsed as

 ╰─ t_cmdgroup
     ├─ t_cmdlist
     │   ├─ num_cmds = 1
     │   ╰─ cmd[0]
     │       ├─ t_cmdlist_item
     │       │   ╰─ t_pipeline
     │       │       ├─ num_cmd = 1
     │       │       ╰─ cmd[0]
     │       │           ╰─ t_simple_cmd
     │       │               ├─ words = [echo][hi][<][in]
     │       │               ╰─ t_redir_list
     │       │                   ╰─ redirection[0]
     │       │                       ╰─ t_redirection
     │       │                           ├─ t_redir_type = REDIR_OUTPUT
     │       │                           ╰─ marker = [out]
     │       ╰─ t_operator = END
     ╰─ (no redirections)

when the correct parsing is
 ╰─ t_cmdgroup
     ├─ t_cmdlist
     │   ├─ num_cmds = 1
     │   ╰─ cmd[0]
     │       ├─ t_cmdlist_item
     │       │   ╰─ t_pipeline
     │       │       ├─ num_cmd = 1
     │       │       ╰─ cmd[0]
     │       │           ╰─ t_simple_cmd
     │       │               ├─ words = [echo][hi]
     │       │               ╰─ t_redir_list
     │       │                   ├─ redirection[0]
     │       │                   │   ╰─ t_redirection
     │       │                   │       ├─ t_redir_type = REDIR_OUTPUT
     │       │                   │       ╰─ marker = [out]
     │       │                   ╰─ redirection[1]
     │       │                       ╰─ t_redirection
     │       │                           ├─ t_redir_type = REDIR_INPUT
     │       │                           ╰─ marker = [in]
     │       ╰─ t_operator = END
     ╰─ (no redirections)
2025-03-28 14:50:37 +01:00
9fb4e13420
implement tree debug for redirections 2025-03-28 14:50:37 +01:00
88ed66e138
refactor cmdlist.num_cmds -> cmdlist.num_cmd to be more consistent 2025-03-28 14:50:37 +01:00
448458b37f
redirection parsing: parse redirections for cmdgroup 2025-03-28 14:50:37 +01:00
c258fa6077
fix(simple_cmd): did not free redirection list correctly 2025-03-28 14:50:37 +01:00
1f03cbbedb
tree debug: implement rest of tree debug
This is a big commit, sorry!
2025-03-28 14:50:37 +01:00
1486c3b124
treeprint refactor: use simpler types 2025-03-28 14:50:37 +01:00
40c5164eef
tree debug: create library for easy indent/dedent 2025-03-28 14:50:37 +01:00
d196649106
redirection parsing: handle other types of redirection 2025-03-11 14:58:13 +01:00
47ac767f2a
redirection parsing: check for null in arguments 2025-03-11 14:58:13 +01:00
d9dfac106d
redirection parsing refactor: put redirection found actions in subroutine 2025-03-11 14:57:58 +01:00
5df876bba3
redirection parsing: detect malformed redirection 2025-03-10 16:57:02 +01:00
06dd3c3e83
redirection parings: handle redirections not at start 2025-03-10 16:34:15 +01:00
2a1660865d
redirection parsing: use redir_type_from_worddesc 2025-03-10 15:10:18 +01:00
e7946b4192
redirection parsing: add missing null check 2025-03-10 15:10:18 +01:00
b0439c9d7d
redirection parsing: get redirection type from worddesc 2025-03-10 15:10:18 +01:00
a20ea8315d
redirection parsing: handle > at start of wordlist 2025-03-10 15:10:18 +01:00
541bad80c0
redirection parsing: add utility functions for t_redir_list 2025-03-10 15:10:18 +01:00
b0c34f36ef
redirection parsing: add utility function for t_redirection 2025-03-10 15:10:18 +01:00
cf517bb7f8
redirection parsing: define types in own files 2025-03-10 15:10:18 +01:00
06ebcf132a
redirection parsing: handle commands with no redirections 2025-03-10 15:10:18 +01:00