1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:57:35 +00:00

Userland: Use Core::ArgsParser for 'tr'

This commit is contained in:
Linus Groh 2020-08-05 20:17:02 +02:00 committed by Andreas Kling
parent 559ea8e1b5
commit d320f7b9d2

View file

@ -27,18 +27,23 @@
#include <AK/String.h>
#include <AK/QuickSort.h>
#include <AK/Vector.h>
#include <LibCore/ArgsParser.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
if (argc != 3) {
printf("usage: tr <from> <to>");
return 0;
}
const char* from_chars = nullptr;
const char* to_chars = nullptr;
char from = argv[1][0];
char to = argv[2][0];
Core::ArgsParser args_parser;
args_parser.add_positional_argument(from_chars, "Character to translate from", "from");
args_parser.add_positional_argument(to_chars, "Character to translate to", "to");
args_parser.parse(argc, argv);
// TODO: Support multiple characters to translate from and to
auto from = from_chars[0];
auto to = to_chars[0];
for (;;) {
char ch = fgetc(stdin);