System/Shell/Commands/cat: Allow concatenating http/https URLs
This commit is contained in:
parent
195df64e38
commit
f2800ba2d6
1 changed files with 22 additions and 2 deletions
|
@ -1,3 +1,19 @@
|
||||||
|
U8* @cat_buf_from_url_string(U8* url_string, I64* size)
|
||||||
|
{
|
||||||
|
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, Fs);
|
||||||
|
@http_response* resp = fetch(url_string, fetch_buffer);
|
||||||
|
if (!resp)
|
||||||
|
return 0;
|
||||||
|
U8* buf = NULL;
|
||||||
|
if (resp->body.length) {
|
||||||
|
buf = CAlloc(resp->body.length);
|
||||||
|
MemCpy(buf, resp->body.data, resp->body.length);
|
||||||
|
}
|
||||||
|
*size = resp->body.length;
|
||||||
|
Free(fetch_buffer);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
I64 @shell_cmd_cat(@shell* sh, I64 argc, U8** argv)
|
I64 @shell_cmd_cat(@shell* sh, I64 argc, U8** argv)
|
||||||
{
|
{
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
|
@ -8,8 +24,12 @@ I64 @shell_cmd_cat(@shell* sh, I64 argc, U8** argv)
|
||||||
U8* filename = NULL;
|
U8* filename = NULL;
|
||||||
U8* buf = NULL;
|
U8* buf = NULL;
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
filename = @shell_expand_relative_path(sh, argv[i]);
|
if (!MemCmp(argv[i], "http://", 7) || !MemCmp(argv[i], "https://", 8)) {
|
||||||
buf = FileSystem.ReadFile(filename, &size);
|
buf = @cat_buf_from_url_string(argv[i], &size);
|
||||||
|
} else {
|
||||||
|
filename = @shell_expand_relative_path(sh, argv[i]);
|
||||||
|
buf = FileSystem.ReadFile(filename, &size);
|
||||||
|
}
|
||||||
for (j = 0; j < size; j++)
|
for (j = 0; j < size; j++)
|
||||||
FifoU8Ins(sh->output, buf[j]);
|
FifoU8Ins(sh->output, buf[j]);
|
||||||
Free(buf);
|
Free(buf);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue