Commit graph

33 commits

Author SHA1 Message Date
Ori Bernstein 7ea6821a83 rc: revert 2f8a59f4b5
this patch doesn't pull its weight; it's not worth it.
2021-09-08 14:24:25 +00:00
Ori Bernstein 2f8a59f4b5 rc: add subshell-function syntax
fn foo @{bar} is now equivalent to
fn foo {@{bar}}. As a side effect,
this disallows creating functions
named after keywords without first
quoting them.
2021-07-08 21:35:34 +00:00
Ori Bernstein 759aafa007 rc: skip arguments to Xsrcline, Xsrcfile in codefree
We weren't correctly skipping the location operators
in codefree. This would mostly be work, but sometimes
you'd get unlucky and have one of the argmuents mismatch,
and that would lead to an invalid free.

This correctly skips the args in codefree.
2021-06-25 23:10:07 +00:00
Ori Bernstein 5770332282 rc: correct line numbers
When loading a file using ".", we could
end up with our line numbers thrown off
due to the mutation of lexline. Putting
lexline into the runq beside the file
that we're reading from causes it to get
pushed and popped correctly, so that we
no longer lose track of our location.
2021-06-22 23:40:11 +00:00
Ori Bernstein d75d842cf5 rc: show line numbers on error
This change provides a location for errors
like 'null list in concatenation'.
2020-11-01 11:56:26 -08:00
cinap_lenrek 53800208bd rc: avoid stat calls for directory globbing
On Plan9, we can count on Readdir() onlydirs argument
to work, which allows us to avoid stating every single
file to see if it is a directory.
2020-08-04 16:21:37 +02:00
cinap_lenrek a48b462e44 rc: avoid forking for final command that has variable assignments (to get $apid right)
basically, we want the following commands to print
the same pid twice:

rc -c 'cat /dev/pid &;echo $apid'

vs:

rc -c 'a=1 cat /dev/pid &;echo $apid'

basically, Xsimple() calls exitnext() to determine if
a simple command should be promoted to exec, by peeking
ahead into the code and searching for Xexit instruction.

Xexit might not follow immediately after the Xsimple
instruction because of redirections, which exitnext()
would skip.

but it would not skip the Xunlocal instructions that
where added by the variable assignment.
2020-05-30 02:03:18 +02:00
cinap_lenrek 94bd7700aa rc: fix code serialization for PIPEFD (thanks BurnZeZ)
BurnZeZ reported this the other day. It seems like if we have
a pipeline that looks like:

	fn foo{cat < <{echo hi}}

then the '<' will get merged in /env/'fn#foo'. This change
fixes pcmd to add a space. It looks to me like this is the
only token that can get merged this way by pcmd.
2020-04-18 18:20:34 +02:00
Ori Bernstein fc90f7a666 fix heredoc crash
we emitted an error on heredoc tags, but we
continued on, and added a heredoc entry to
the list, with a tag that we couldn't handle.

when processing this heredoc, rc would segfault.

fix: don't add a heredoc to the list on error.
2020-03-09 14:24:02 -07:00
cinap_lenrek 116b075371 rc: clear out redirections on "rfork F" (RFCFDG)
rfork F closes all file descriptors, so we have to
invalidate the redirections as they are now refering
to closed files. not doing so causes the wrong file
descriptors being closed later on as the fd numbers
get reused.
2019-01-20 12:02:03 +01:00
cinap_lenrek b6251bff91 rc: implement $"x in terms of Xdol() and new Xqw() instruction
to get $"1 right, remove Xqdol() and instead implement it in
terms of Xdol() instruction and use the new Xqw() instruction
to quote the resulting list.
2018-11-18 04:56:48 +01:00
cinap_lenrek d81f4d4866 rc: skip searchpath for "", "." and ".." 2018-10-27 18:32:00 +02:00
cinap_lenrek d17a049c5b rc: use searchpath() logic to handle $cdpath 2018-10-26 10:25:23 +02:00
cinap_lenrek 1a55b8d1f0 rc: ignore $cdpath for # device rooted paths (thanks kivik) 2018-10-26 09:52:05 +02:00
cinap_lenrek 2839760066 rc: fix Xpipefd unbalancing the redir stack
Xpipefd wants the pipe descriptor to be closed in turfredir(), so
it pushes the redirection, but this breaks Xpopredir after normal
redirection. so we shuffle the Xpipefd redir to the bottom of the
stack.
2018-09-08 14:49:00 +02:00
cinap_lenrek 3ec84c5d73 rc: implement 9atoms ` split {command} syntax extension 2016-06-30 19:09:27 +02:00
cinap_lenrek 65977417e7 rc: write /dev/wdir after printing the prompt, not after executing "cd" command 2016-06-30 00:45:37 +02:00
cinap_lenrek b15430979d rc: simplify execfinit() / Xrdfn() using the globber to lookup /env/fn'#'* 2016-05-16 19:57:53 +02:00
cinap_lenrek ce7f7d3ab9 rc: fix double close() in addenv() 2016-05-16 18:03:57 +02:00
cinap_lenrek 31a6f6c83d rc: remove duplicate Xrdfn entry from fname[] array 2016-05-16 00:46:46 +02:00
cinap_lenrek 4ad3f4f2fd rc: remove historical unix and win32 ports 2016-05-16 00:37:49 +02:00
cinap_lenrek 45d6bca5f0 rc: fix shift regresison, sorry 2016-05-15 23:09:23 +02:00
cinap_lenrek d0e510b29a rc: remove pointless Memcpy(),Malloc(),Realloc() and efree() wrappers 2016-05-15 19:58:24 +02:00
cinap_lenrek 7717051e3c rc: fix inband globbing bugs, cleanup
add glob information to the word structure so we wont accidently
deglob quoted strings containing the GLOB. we store Globsize(word)
in in word->glob which avoids recalculating that values and the
check if a word should be globbed quick.

globlist() now substitutes the word inplace avoiding the copying
when all words are literals and avoids recursion.

minor cleanups: use list2str() in execeval(), move octal() to
unix.c, remove the (char*) casts to efree().
2016-05-15 19:10:37 +02:00
cinap_lenrek 258fe87faf rc: terminate rc when exec fails, cleanup
The execexec() function should never return, as it irreversably changes
the filedescriptor table for the new program. This means rc's internal
filedesciptors for reading the script get implicitely closed and we cannot
continue the rc interpreter when Execute() fails. So Execute() now sets the
error status, and execexec() runs Xexit() in case Execute() returns.
2016-02-22 22:25:21 +01:00
cinap_lenrek a2f7d03d4e rc: fix slow Xqdol(), avoid recursion in conclist(), estrdup(), avoid copying
Xqdol() used to take quadratic time because of strcat(),
the code isnt really needed as list2str() aready does the
same thing in linear time without the strcat().

add estrdup() which uses emalloc() so allocation error are
catched.

move strdups() of name from callers into newvar().

avoid recursion of conclist(), and avoid copying of word
strings by providing Newword() function which doesnt copy
the word string.
2014-07-23 15:28:37 +02:00
cinap_lenrek 9a3a722dde rc: flush environment variables (update /env) before fork
on races... normal forks will all share the /env environment but
not the in memory variables of rc. so when we would normally fork
whoever does an exec (flush) first will override what the values of the
/env variables are, *independent* of the variables that where
actually modified *in* the process.

when we flush *before* fork, then at least both processes start out
with marked clean in memory variables and the processes will flush
only the things they actually change.
2013-08-20 23:56:15 +02:00
cinap_lenrek 667010554b make all the commands agnostic about Rune width. (from sources) 2013-04-24 20:13:18 +02:00
cinap_lenrek c7522489a3 rc: remove silly efree check 2012-02-08 04:14:32 +01:00
cinap_lenrek f2f19dd888 rc: change plan9 envname limit to 128, cleanup 2012-02-08 04:09:48 +01:00
stanley lieber a504af8833 erik's patches to lift 8192 byte word size restriction 2011-04-04 20:22:56 +00:00
Taru Karttunen a9060cc06b Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
Taru Karttunen e5888a1ffd Import sources from 2011-03-30 iso image 2011-03-30 15:46:40 +03:00