mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 14:05:15 +00:00
Userland: Add support for the '-n' flag to 'echo'
This commit is contained in:
parent
3b3e90714f
commit
6df2f8a8cb
Notes:
sideshowbarker
2024-07-19 04:27:33 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/6df2f8a8cb6 Pull-request: https://github.com/SerenityOS/serenity/pull/2907 Reviewed-by: https://github.com/awesomekling
1 changed files with 14 additions and 4 deletions
|
@ -24,6 +24,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -34,11 +35,20 @@ int main(int argc, char** argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i) {
|
Vector<const char*> values;
|
||||||
fputs(argv[i], stdout);
|
bool no_trailing_newline = false;
|
||||||
if (i != argc - 1)
|
|
||||||
|
Core::ArgsParser args_parser;
|
||||||
|
args_parser.add_option(no_trailing_newline, "Do not output a trailing newline", nullptr, 'n');
|
||||||
|
args_parser.add_positional_argument(values, "Values to print out", "string", Core::ArgsParser::Required::No);
|
||||||
|
args_parser.parse(argc, argv);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < values.size(); ++i) {
|
||||||
|
fputs(values[i], stdout);
|
||||||
|
if (i != values.size() - 1)
|
||||||
fputc(' ', stdout);
|
fputc(' ', stdout);
|
||||||
}
|
}
|
||||||
printf("\n");
|
if (!no_trailing_newline)
|
||||||
|
printf("\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue