Commit graph

286 commits

Author SHA1 Message Date
Andreas Kling 3de8dd921e Userland: Remove serialize-to-JSON functions only used for Inspector 2023-04-25 14:48:40 +02:00
Andreas Kling 411d36719e LibCore: Simplify Core::Notifier by only allowing one event type
Not a single client of this API actually used the event mask feature to
listen for readability AND writability.

Let's simplify the API and have only one hook: on_activation.
2023-04-25 14:48:40 +02:00
Cameron Youell da305017de Shell: Use JsonArray::append in save_to
We can convert it into a failable function here easily
2023-04-24 09:21:51 +02:00
Cameron Youell 8134dccdc7 AK: Add new failable JsonArray::{append/set} functions
Move all old usages to the more explicit `JsonArray:must_{append/set}`
2023-04-24 09:21:51 +02:00
Tim Schumacher 8370377832 Shell: Add map_fixed to the pledges for command autocompletion 2023-04-12 07:06:54 -04:00
Ben Wiederhake 560133a0c6 Everywhere: Remove unused DeprecatedString includes 2023-04-09 22:00:54 +02:00
Ali Mohammad Pur 1173adb90a Shell: Don't require ArgsParser values to be null-terminated 2023-03-31 06:55:46 +02:00
Tim Schumacher d01ac59b82 Shell: Skip rc files when not running interactively
This makes debugging a bit nicer.
2023-03-29 03:39:09 +03:30
Tim Schumacher 9a6b5a53a7 Shell: Correctly mark the end line of a parsed list 2023-03-29 03:39:09 +03:30
Tim Schumacher 46c22ee49d Shell: Allow appending empty string literals
Otherwise, we just silently drop arguments that are empty strings.
2023-03-29 03:39:09 +03:30
Tim Schumacher c26639eac2 Shell: Properly skip POSIX Fi tokens 2023-03-29 03:39:09 +03:30
Tim Schumacher b1739029ef Shell: Evaluate the program name before parsing arguments
Otherwise, we are too late to catch the "load the POSIX-compatible
shellrc" branch.
2023-03-29 03:39:09 +03:30
Ali Mohammad Pur 7c312980b0 Shell: Implement arithmetic expansions for POSIX mode
This also adds a 'math' immediate function that can be used in Shell
proper to do arithmetic stuff.
2023-03-22 09:46:16 +01:00
Ali Mohammad Pur d0112d76e9 Shell: Resolve nonexistent string env variables to the empty string
We did this for lists, but not for strings.
2023-03-22 09:46:16 +01:00
Ali Mohammad Pur d997b794fa Shell: Load a different rc file when in POSIX mode 2023-03-22 09:46:16 +01:00
Cameron Youell 1d24f394c6 Everywhere: Use LibFileSystem where trivial 2023-03-21 19:03:21 +00:00
Sam Atkins 6d8f046fd0 LibGfx+Userland: Make TextAttributes::underline_style optional
Rather than having a style AND a field saying whether to use the style,
just make the style Optional.
2023-03-15 14:55:49 +01:00
Tim Schumacher ecd1862859 AK: Rename Stream::write_entire_buffer to Stream::write_until_depleted
No functional changes.
2023-03-13 15:16:20 +00:00
Tim Schumacher a3f73e7d85 AK: Rename Stream::read_entire_buffer to Stream::read_until_filled
No functional changes.
2023-03-13 15:16:20 +00:00
Ali Mohammad Pur 56b5b78d7b Shell: Error out on invalid `export' argument
Previously `export =` would crash the shell, make this an error instead.
2023-03-10 22:33:30 +03:30
Andreas Kling 4797fad91c Shell: Fix bogus C-style casts from NonnullOwnPtr<T>* to T*
Thanks UBSAN for spotting this!
2023-03-07 09:42:20 +01:00
Andreas Kling 21db2b7b90 Everywhere: Remove NonnullOwnPtr.h includes 2023-03-06 23:46:35 +01:00
Andreas Kling 359d6e7b0b Everywhere: Stop using NonnullOwnPtrVector
Same as NonnullRefPtrVector: weird semantics, questionable benefits.
2023-03-06 23:46:35 +01:00
Andreas Kling 689ca370d4 Everywhere: Remove NonnullRefPtr.h includes 2023-03-06 23:46:35 +01:00
Andreas Kling 8a48246ed1 Everywhere: Stop using NonnullRefPtrVector
This class had slightly confusing semantics and the added weirdness
doesn't seem worth it just so we can say "." instead of "->" when
iterating over a vector of NNRPs.

This patch replaces NonnullRefPtrVector<T> with Vector<NNRP<T>>.
2023-03-06 23:46:35 +01:00
Ali Mohammad Pur 500044906d LibCore+Everywhere: Remove ArgsParser::add*(char const*&)
This is not guaranteed to always work correctly as ArgsParser deals in
StringViews and might have a non-properly-null-terminated string as a
value. As a bonus, using StringView (and DeprecatedString where
necessary) leads to nicer looking code too :^)
2023-03-01 10:47:19 +01:00
Linus Groh 51c3967516 Everywhere: Use '_{short_,}string' literals more
This mostly updates code what was written before but merged after these
were added.
2023-02-28 15:15:36 +00:00
Ali Mohammad Pur db886fe18b Userland+AK: Stop using getopt() for ArgsParser
This commit moves the implementation of getopt into AK, and converts its
API to understand and use StringView instead of char*.
Everything else is caught in the crossfire of making
Option::accept_value() take a StringView instead of a char const*.

With this, we must now pass a Span<StringView> to ArgsParser::parse(),
applications using LibMain are unaffected, but anything not using that
or taking its own argc/argv has to construct a Vector<StringView> for
this method.
2023-02-28 15:52:24 +03:30
Ali Mohammad Pur b2b851b361 Shell: Convert the POSIX parser/lexer to ErrorOr 2023-02-28 15:52:24 +03:30
Ali Mohammad Pur 0c28fd41ed Shell: Convert all immediately convertible fallible functions to ErrorOr 2023-02-28 15:52:24 +03:30
Ali Mohammad Pur e403dbabfa Shell: Convert the remaining fallible AST functions to ErrorOr 2023-02-28 15:52:24 +03:30
Ali Mohammad Pur 5f950df3d4 Shell: Make Immediate expression invocation fallible
This removes a whole bunch of FIXMEs in the immediate expr
implementations as well :^)
2023-02-28 15:52:24 +03:30
Ali Mohammad Pur 007767fc14 Shell: Convert builtins to use the modern main() style
That is, return ErrorOr<int>, handle fallible ops with TRY() and accept
a Main::Arguments.
Note that we do not populate the argc/argv members of Main::Arguments,
so all accesses have to go through .strings.
2023-02-28 15:52:24 +03:30
Ali Mohammad Pur d575c50f3e Shell: Make AST::dump() ErrorOr-aware 2023-02-28 15:52:24 +03:30
Ali Mohammad Pur beeb58bd93 Shell+LibCodeComprehension: Start replacing {Deprecated => }String
This starts by switching all AST members to Strings, and dealing with
the fallout.
2023-02-28 15:52:24 +03:30
Andreas Kling 68b5df6bf1 Shell: Fix (and paper over) various const-correctness issues 2023-02-21 00:54:04 +01:00
Ali Mohammad Pur 99d264afbe Shell: Correct the out-of-bounds expansion bailing condition
Also adds a couple (useful) debug prints which helped track down the
problem.
2023-02-18 06:55:46 +03:30
Ali Mohammad Pur d56fbaa7e8 Shell: Allow underscores in normal expansion names 2023-02-18 06:55:46 +03:30
Ali Mohammad Pur a6d77162f4 Shell: Correctly keep track of special parameter length
We were previously treating special expansions (e.g. $#) as zero-length
expansions, which made the shell repeat them literally after expanding
them.
2023-02-18 06:55:46 +03:30
Ali Mohammad Pur 6da438e992 Shell: Clear expansions after committing a word in the POSIX parser 2023-02-18 06:55:46 +03:30
Ali Mohammad Pur 2881bb4c3a Shell: Add support for heredocs to the POSIX parser 2023-02-18 06:55:46 +03:30
Ali Mohammad Pur a5e4bc4faf Shell: Add a '--posix' mode to the 'dump' builtin 2023-02-18 06:55:46 +03:30
Ali Mohammad Pur 4efc632e15 Shell: Allow the heredoc node to act as a redirection too
This will be used in a future commit to implement POSIX sh heredocs.
2023-02-18 06:55:46 +03:30
Ali Mohammad Pur eb20fbe145 Everywhere: Use /bin/Shell as the shebang for Shell scripts 2023-02-13 23:00:15 +03:30
Ali Mohammad Pur beaae6b420 Shell: Use the POSIX parser if run as /bin/sh or passed the --posix flag
Note that the default shellrc is most likely not valid posix sh code, so
passing --skip-shellrc is suggested until we come up with a separate
shellrc file for the POSIX parser to use when interactive.
2023-02-13 23:00:15 +03:30
Ali Mohammad Pur 2a276c86d4 Shell: Start implementing a POSIX-compliant parser
The parser is still very much a work-in-progress, but it can currently
parse most of the basic bits, the only *completely* unimplemented things
in the parser are:
- heredocs (io_here)
- alias expansion
- arithmetic expansion

There are a whole suite of bugs, and syntax highlighting is unreliable
at best.
For now, this is not attached anywhere, a future commit will enable it
for /bin/sh or a `Shell --posix` invocation.
2023-02-13 23:00:15 +03:30
Tim Schumacher 874c7bba28 LibCore: Remove Stream.h 2023-02-13 00:50:07 +00:00
Tim Schumacher d43a7eae54 LibCore: Rename File to DeprecatedFile
As usual, this removes many unused includes and moves used includes
further down the chain.
2023-02-13 00:50:07 +00:00
Tim Schumacher 093cf428a3 AK: Move memory streams from LibCore 2023-01-29 19:16:44 -07:00
Linus Groh 6e7459322d AK: Remove StringBuilder::build() in favor of to_deprecated_string()
Having an alias function that only wraps another one is silly, and
keeping the more obvious name should flush out more uses of deprecated
strings.
No behavior change.
2023-01-27 20:38:49 +00:00