Luna/apps/edit.cpp
apio a164dcc160
All checks were successful
continuous-integration/drone/push Build is passing
libos: Add libos + very basic ArgumentParser
libluna but for stuff that interests only userspace, like an argument parser or files or stuff like that.
2023-03-29 18:27:02 +02:00

36 lines
592 B
C++

#include <os/ArgumentParser.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char** argv)
{
FILE* f;
StringView pathname;
ArgumentParser parser;
parser.add_positional_argument(pathname, "file", true);
parser.parse(argc, argv);
f = fopen(pathname.chars(), "w");
if (!f)
{
perror(pathname.chars());
return 1;
}
char buffer[4096];
while (1)
{
char* rc = fgets(buffer, sizeof(buffer), stdin);
if (rc == 0) break;
fputs(buffer, f);
}
fclose(f);
return 0;
}