2020-01-27 23:54:57 +01:00
|
|
|
/*
|
2020-02-19 02:08:03 +01:00
|
|
|
umka_shell: User-Mode KolibriOS developer tools, the shell
|
2020-01-27 23:54:57 +01:00
|
|
|
Copyright (C) 2018--2020 Ivan Baravy <dunkaist@gmail.com>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-10-18 22:19:53 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2018-05-14 09:54:05 +02:00
|
|
|
#include <inttypes.h>
|
2019-10-30 22:54:12 +01:00
|
|
|
#include <limits.h>
|
2018-04-23 12:09:46 +02:00
|
|
|
#include <stdlib.h>
|
2019-10-21 04:51:56 +02:00
|
|
|
#include <stddef.h>
|
2017-11-02 21:41:11 +01:00
|
|
|
#include <string.h>
|
2018-04-26 15:07:34 +02:00
|
|
|
#include <unistd.h>
|
2017-10-18 22:19:53 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2018-06-18 03:55:51 +02:00
|
|
|
#include <assert.h>
|
2019-10-31 21:26:53 +01:00
|
|
|
#include <time.h>
|
2020-05-07 03:08:20 +02:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
2020-02-21 00:18:40 +01:00
|
|
|
#include "vdisk.h"
|
2020-05-06 23:33:32 +02:00
|
|
|
#include "vnet.h"
|
2018-05-09 23:08:52 +02:00
|
|
|
#include "kolibri.h"
|
2020-02-06 04:19:20 +01:00
|
|
|
#include "syscalls.h"
|
2019-10-09 01:35:47 +02:00
|
|
|
#include "trace.h"
|
2020-02-19 01:27:18 +01:00
|
|
|
#include "lodepng.h"
|
2017-10-18 22:19:53 +02:00
|
|
|
|
2019-10-25 03:48:13 +02:00
|
|
|
#define PATH_MAX 4096
|
2018-04-26 11:17:55 +02:00
|
|
|
#define FGETS_BUF_LEN 4096
|
|
|
|
#define MAX_COMMAND_ARGS 42
|
2018-06-18 03:55:51 +02:00
|
|
|
#define PRINT_BYTES_PER_LINE 32
|
|
|
|
#define MAX_DIRENTS_TO_READ 100
|
2020-02-29 02:04:32 +01:00
|
|
|
#define MAX_BYTES_TO_READ (1024*1024)
|
2018-04-26 11:17:55 +02:00
|
|
|
|
2020-02-18 03:30:16 +01:00
|
|
|
#define DEFAULT_READDIR_ENCODING UTF8
|
2019-12-08 02:32:07 +01:00
|
|
|
#define DEFAULT_PATH_ENCODING UTF8
|
|
|
|
|
2020-02-21 00:18:40 +01:00
|
|
|
diskfunc_t vdisk_functions = {
|
|
|
|
.strucsize = sizeof(diskfunc_t),
|
|
|
|
.close = vdisk_close,
|
|
|
|
.closemedia = NULL,
|
|
|
|
.querymedia = vdisk_querymedia,
|
|
|
|
.read = vdisk_read,
|
|
|
|
.write = vdisk_write,
|
|
|
|
.flush = NULL,
|
2020-03-07 23:09:36 +01:00
|
|
|
.adjust_cache_size = NULL,
|
2020-02-21 00:18:40 +01:00
|
|
|
};
|
2020-05-06 23:33:32 +02:00
|
|
|
|
|
|
|
net_device_t vnet = {
|
|
|
|
.device_type = NET_TYPE_ETH,
|
|
|
|
.mtu = 1514,
|
|
|
|
.name = "UMK0770",
|
|
|
|
|
|
|
|
.unload = vnet_unload,
|
|
|
|
.reset = vnet_reset,
|
|
|
|
.transmit = vnet_transmit,
|
|
|
|
|
|
|
|
.bytes_tx = 0,
|
|
|
|
.bytes_rx = 0,
|
|
|
|
.packets_tx = 0,
|
|
|
|
.packets_rx = 0,
|
|
|
|
|
2020-05-07 03:08:20 +02:00
|
|
|
.link_state = ETH_LINK_FD + ETH_LINK_10M,
|
2020-05-06 23:33:32 +02:00
|
|
|
.hwacc = 0,
|
2020-05-07 03:08:20 +02:00
|
|
|
.mac = {0x80, 0x2b, 0xf9, 0x3b, 0x6c, 0xca},
|
2020-05-06 23:33:32 +02:00
|
|
|
};
|
|
|
|
|
2019-10-25 03:48:13 +02:00
|
|
|
char cur_dir[PATH_MAX] = "/";
|
|
|
|
const char *last_dir = cur_dir;
|
|
|
|
bool cur_dir_changed = true;
|
|
|
|
|
2018-04-26 11:17:55 +02:00
|
|
|
char cmd_buf[FGETS_BUF_LEN];
|
|
|
|
|
2019-10-25 03:48:13 +02:00
|
|
|
const char *f70_status_name[] = {
|
|
|
|
"success",
|
|
|
|
"disk_base",
|
|
|
|
"unsupported_fs",
|
|
|
|
"unknown_fs",
|
|
|
|
"partition",
|
|
|
|
"file_not_found",
|
|
|
|
"end_of_file",
|
|
|
|
"memory_pointer",
|
|
|
|
"disk_full",
|
|
|
|
"fs_fail",
|
|
|
|
"access_denied",
|
|
|
|
"device",
|
|
|
|
"out_of_memory"
|
|
|
|
};
|
|
|
|
|
2020-02-21 00:18:40 +01:00
|
|
|
const char *get_f70_status_name(int s) {
|
2019-10-25 03:48:13 +02:00
|
|
|
switch (s) {
|
2019-12-08 02:32:07 +01:00
|
|
|
case ERROR_SUCCESS:
|
2019-10-27 02:54:38 +02:00
|
|
|
// return "";
|
2019-12-08 02:32:07 +01:00
|
|
|
case ERROR_DISK_BASE:
|
|
|
|
case ERROR_UNSUPPORTED_FS:
|
|
|
|
case ERROR_UNKNOWN_FS:
|
|
|
|
case ERROR_PARTITION:
|
|
|
|
case ERROR_FILE_NOT_FOUND:
|
|
|
|
case ERROR_END_OF_FILE:
|
|
|
|
case ERROR_MEMORY_POINTER:
|
|
|
|
case ERROR_DISK_FULL:
|
|
|
|
case ERROR_FS_FAIL:
|
|
|
|
case ERROR_ACCESS_DENIED:
|
|
|
|
case ERROR_DEVICE:
|
|
|
|
case ERROR_OUT_OF_MEMORY:
|
2019-10-25 03:48:13 +02:00
|
|
|
return f70_status_name[s];
|
|
|
|
default:
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-07 00:51:55 +01:00
|
|
|
void convert_f70_file_attr(uint32_t attr, char s[KF_ATTR_CNT+1]) {
|
|
|
|
s[0] = (attr & KF_READONLY) ? 'r' : '-';
|
|
|
|
s[1] = (attr & KF_HIDDEN) ? 'h' : '-';
|
|
|
|
s[2] = (attr & KF_SYSTEM) ? 's' : '-';
|
|
|
|
s[3] = (attr & KF_LABEL) ? 'l' : '-';
|
|
|
|
s[4] = (attr & KF_FOLDER) ? 'f' : '-';
|
|
|
|
s[5] = '\0';
|
|
|
|
}
|
|
|
|
|
2019-12-08 02:32:07 +01:00
|
|
|
void print_f70_status(f7080ret_t *r, int use_ebx) {
|
2019-10-27 02:54:38 +02:00
|
|
|
printf("status = %d %s", r->status, get_f70_status_name(r->status));
|
2019-12-08 02:32:07 +01:00
|
|
|
if (use_ebx && (r->status == ERROR_SUCCESS || r->status == ERROR_END_OF_FILE))
|
2019-10-25 03:48:13 +02:00
|
|
|
printf(", count = %d", r->count);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
2019-10-21 04:51:56 +02:00
|
|
|
bool parse_uintmax(const char *str, uintmax_t *res) {
|
|
|
|
char *endptr;
|
|
|
|
*res = strtoumax(str, &endptr, 0);
|
|
|
|
bool ok = (str != endptr) && (*endptr == '\0');
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool parse_uint32(const char *str, uint32_t *res) {
|
|
|
|
uintmax_t x;
|
|
|
|
if (parse_uintmax(str, &x) && x <= UINT32_MAX) {
|
2019-10-22 04:24:44 +02:00
|
|
|
*res = (uint32_t)x;
|
2019-10-21 04:51:56 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
perror("invalid number");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool parse_uint64(const char *str, uint64_t *res) {
|
|
|
|
uintmax_t x;
|
|
|
|
if (parse_uintmax(str, &x) && x <= UINT64_MAX) {
|
|
|
|
*res = x;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
perror("invalid number");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_bytes(uint8_t *x, size_t len) {
|
|
|
|
for (size_t i = 0; i < len; i++) {
|
|
|
|
if (i % PRINT_BYTES_PER_LINE == 0 && i != 0) {
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
printf("%2.2x", x[i]);
|
|
|
|
}
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_hash(uint8_t *x, size_t len) {
|
|
|
|
hash_context ctx;
|
|
|
|
hash_oneshot(&ctx, x, len);
|
|
|
|
for (size_t i = 0; i < HASH_SIZE; i++) {
|
|
|
|
printf("%2.2x", ctx.hash[i]);
|
|
|
|
}
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
2019-10-25 03:48:13 +02:00
|
|
|
const char *get_last_dir(const char *path) {
|
|
|
|
const char *last = strrchr(path, '/');
|
|
|
|
if (!last) {
|
|
|
|
last = path;
|
|
|
|
} else if (last != path || last[1] != '\0') {
|
|
|
|
last++;
|
|
|
|
}
|
|
|
|
return last;
|
|
|
|
}
|
|
|
|
|
2017-10-18 22:19:53 +02:00
|
|
|
void prompt() {
|
2019-10-25 03:48:13 +02:00
|
|
|
if (cur_dir_changed) {
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-19 03:47:17 +01:00
|
|
|
umka_sys_get_cwd(cur_dir, PATH_MAX);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2019-10-25 03:48:13 +02:00
|
|
|
last_dir = get_last_dir(cur_dir);
|
|
|
|
cur_dir_changed = false;
|
|
|
|
}
|
|
|
|
printf("%s> ", last_dir);
|
2018-05-19 17:48:10 +02:00
|
|
|
fflush(stdout);
|
2017-10-18 22:19:53 +02:00
|
|
|
}
|
|
|
|
|
2019-10-30 22:54:12 +01:00
|
|
|
int next_line(FILE *file, int is_tty) {
|
2018-04-26 15:07:34 +02:00
|
|
|
if (is_tty) {
|
|
|
|
prompt();
|
|
|
|
}
|
2019-10-30 22:54:12 +01:00
|
|
|
return fgets(cmd_buf, FGETS_BUF_LEN, file) != NULL;
|
2018-04-26 11:17:55 +02:00
|
|
|
}
|
|
|
|
|
2020-02-18 03:30:16 +01:00
|
|
|
int split_args(char *s, char **argv) {
|
2018-04-26 11:17:55 +02:00
|
|
|
int argc = -1;
|
2019-10-30 22:54:12 +01:00
|
|
|
for (; (argv[++argc] = strtok(s, " \t\n")) != NULL; s = NULL);
|
2019-10-13 03:17:29 +02:00
|
|
|
return argc;
|
|
|
|
}
|
|
|
|
|
2020-05-06 16:53:15 +02:00
|
|
|
void shell_i40(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: i40 <eax> [ebx [ecx [edx [esi [edi [ebp]]]]]]...\n"
|
|
|
|
" see '/kernel/docs/sysfuncs.txt' for details";
|
|
|
|
if (argc == 1 || argc > 8) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pushad_t regs = {0, 0, 0, 0, 0, 0, 0, 0};
|
|
|
|
if (argv[1]) regs.eax = strtoul(argv[1], NULL, 0);
|
|
|
|
if (argv[2]) regs.ebx = strtoul(argv[2], NULL, 0);
|
|
|
|
if (argv[3]) regs.ecx = strtoul(argv[3], NULL, 0);
|
|
|
|
if (argv[4]) regs.edx = strtoul(argv[4], NULL, 0);
|
|
|
|
if (argv[5]) regs.esi = strtoul(argv[5], NULL, 0);
|
|
|
|
if (argv[6]) regs.edi = strtoul(argv[6], NULL, 0);
|
|
|
|
if (argv[7]) regs.ebp = strtoul(argv[7], NULL, 0);
|
|
|
|
COVERAGE_ON();
|
|
|
|
umka_i40(®s);
|
|
|
|
COVERAGE_OFF();
|
|
|
|
printf("eax = %8.8x %" PRIu32 " %" PRIi32 "\n"
|
|
|
|
"ebx = %8.8x %" PRIu32 " %" PRIi32 "\n",
|
|
|
|
regs.eax, regs.eax, (int32_t)regs.eax,
|
|
|
|
regs.ebx, regs.ebx, (int32_t)regs.ebx);
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_disk_list_partitions(disk_t *d) {
|
2020-02-21 00:18:40 +01:00
|
|
|
for (size_t i = 0; i < d->num_partitions; i++) {
|
|
|
|
printf("/%s/%d: ", d->name, i+1);
|
|
|
|
if (d->partitions[i]->fs_user_functions == xfs_user_functions) {
|
|
|
|
printf("xfs\n");
|
|
|
|
} else if (d->partitions[i]->fs_user_functions == ext_user_functions) {
|
|
|
|
printf("ext\n");
|
|
|
|
} else if (d->partitions[i]->fs_user_functions == fat_user_functions) {
|
|
|
|
printf("fat\n");
|
|
|
|
} else if (d->partitions[i]->fs_user_functions == ntfs_user_functions) {
|
|
|
|
printf("ntfs\n");
|
|
|
|
} else {
|
|
|
|
printf("???\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_disk_add(int argc, char **argv) {
|
2020-03-07 23:09:36 +01:00
|
|
|
const char *usage = \
|
|
|
|
"usage: disk_add <file> <name> [option]...\n"
|
|
|
|
" <file> absolute or relative path\n"
|
|
|
|
" <name> disk name, e.g. hd0 or rd\n"
|
|
|
|
" -c cache size size of disk cache in bytes";
|
|
|
|
if (argc < 3) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
unsigned cache_size = 0u;
|
|
|
|
int opt;
|
|
|
|
optind = 1;
|
|
|
|
const char *file_name = argv[optind++];
|
|
|
|
const char *disk_name = argv[optind++];
|
|
|
|
while ((opt = getopt(argc, argv, "c:")) != -1) {
|
|
|
|
switch (opt) {
|
|
|
|
case 'c':
|
|
|
|
cache_size = strtoul(optarg, NULL, 0);
|
|
|
|
vdisk_functions.adjust_cache_size = vdisk_adjust_cache_size;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-02-21 00:18:40 +01:00
|
|
|
|
2020-03-07 23:09:36 +01:00
|
|
|
void *userdata = vdisk_init(file_name, cache_size);
|
2020-02-21 00:18:40 +01:00
|
|
|
if (userdata) {
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-21 00:18:40 +01:00
|
|
|
void *vdisk = disk_add(&vdisk_functions, disk_name, userdata, 0);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-21 00:18:40 +01:00
|
|
|
if (vdisk) {
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-21 00:18:40 +01:00
|
|
|
disk_media_changed(vdisk, 1);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
|
|
|
shell_disk_list_partitions(vdisk);
|
2020-02-21 00:18:40 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-10-13 03:17:29 +02:00
|
|
|
}
|
2020-02-21 00:18:40 +01:00
|
|
|
printf("umka: can't add file '%s' as disk '%s'\n", file_name, disk_name);
|
2019-10-13 03:17:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_disk_del_by_name(const char *name) {
|
2020-02-21 00:18:40 +01:00
|
|
|
for(disk_t *d = disk_list.next; d != &disk_list; d = d->next) {
|
|
|
|
if (!strcmp(d->name, name)) {
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-21 00:18:40 +01:00
|
|
|
disk_del(d);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-21 00:18:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("umka: can't find disk '%s'\n", name);
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_disk_del(int argc, char **argv) {
|
2019-10-13 03:17:29 +02:00
|
|
|
(void)argc;
|
|
|
|
const char *name = argv[1];
|
2020-03-09 22:03:57 +01:00
|
|
|
shell_disk_del_by_name(name);
|
2019-10-13 03:17:29 +02:00
|
|
|
return;
|
2018-04-26 11:17:55 +02:00
|
|
|
}
|
|
|
|
|
2020-02-20 04:41:53 +01:00
|
|
|
void shell_pwd(int argc, char **argv) {
|
2019-10-25 03:48:13 +02:00
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
bool quoted = false;
|
|
|
|
const char *quote = quoted ? "'" : "";
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-19 03:47:17 +01:00
|
|
|
umka_sys_get_cwd(cur_dir, PATH_MAX);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2019-10-25 03:48:13 +02:00
|
|
|
printf("%s%s%s\n", quote, cur_dir, quote);
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_set_pixel(int argc, char **argv) {
|
2020-02-06 04:19:20 +01:00
|
|
|
size_t x = strtoul(argv[1], NULL, 0);
|
|
|
|
size_t y = strtoul(argv[2], NULL, 0);
|
|
|
|
uint32_t color = strtoul(argv[3], NULL, 16);
|
|
|
|
int invert = (argc == 5) && !strcmp(argv[4], "-i");
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-06 04:19:20 +01:00
|
|
|
umka_sys_set_pixel(x, y, color, invert);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-06 04:19:20 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_write_text(int argc, char **argv) {
|
2020-02-06 04:19:20 +01:00
|
|
|
(void)argc;
|
|
|
|
size_t x = strtoul(argv[1], NULL, 0);
|
|
|
|
size_t y = strtoul(argv[2], NULL, 0);
|
|
|
|
uint32_t color = strtoul(argv[3], NULL, 16);
|
|
|
|
const char *string = argv[4];
|
|
|
|
int asciiz = strtoul(argv[5], NULL, 0);
|
|
|
|
int fill_background = strtoul(argv[6], NULL, 0);
|
|
|
|
int font_and_encoding = strtoul(argv[7], NULL, 0);
|
|
|
|
int draw_to_buffer = strtoul(argv[8], NULL, 0);
|
|
|
|
int scale_factor = strtoul(argv[9], NULL, 0);
|
|
|
|
int length = strtoul(argv[10], NULL, 0);
|
|
|
|
int background_color_or_buffer = strtoul(argv[11], NULL, 0);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-06 04:19:20 +01:00
|
|
|
umka_sys_write_text(x, y, color, asciiz, fill_background, font_and_encoding, draw_to_buffer, scale_factor, string, length, background_color_or_buffer);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-06 04:19:20 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_dump_win_stack(int argc, char **argv) {
|
2020-02-08 04:13:04 +01:00
|
|
|
int depth = 5;
|
|
|
|
if (argc > 1) {
|
|
|
|
depth = strtol(argv[1], NULL, 0);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < depth; i++) {
|
|
|
|
printf("%3i: %3u\n", i, kos_win_stack[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_dump_win_pos(int argc, char **argv) {
|
2020-02-08 04:13:04 +01:00
|
|
|
int depth = 5;
|
|
|
|
if (argc > 1) {
|
|
|
|
depth = strtol(argv[1], NULL, 0);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < depth; i++) {
|
|
|
|
printf("%3i: %3u\n", i, kos_win_pos[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_process_info(int argc, char **argv) {
|
2020-02-08 04:13:04 +01:00
|
|
|
(void)argc;
|
|
|
|
process_information_t info;
|
|
|
|
int32_t pid = strtol(argv[1], NULL, 0);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-08 04:13:04 +01:00
|
|
|
umka_sys_process_info(pid, &info);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-08 04:13:04 +01:00
|
|
|
printf("cpu_usage: %u\n", info.cpu_usage);
|
|
|
|
printf("window_stack_position: %u\n", info.window_stack_position);
|
|
|
|
printf("window_stack_value: %u\n", info.window_stack_value);
|
|
|
|
printf("process_name: %s\n", info.process_name);
|
|
|
|
printf("memory_start: 0x%.8" PRIx32 "\n", info.memory_start);
|
|
|
|
printf("used_memory: %u (0x%x)\n", info.used_memory, info.used_memory);
|
|
|
|
printf("pid: %u\n", info.pid);
|
|
|
|
printf("box: %u %u %u %u\n", info.box.left, info.box.top, info.box.width, info.box.height);
|
|
|
|
printf("slot_state: %u\n", info.slot_state);
|
|
|
|
printf("client_box: %u %u %u %u\n", info.client_box.left, info.client_box.top, info.client_box.width, info.client_box.height);
|
|
|
|
printf("wnd_state: 0x%.2" PRIx8 "\n", info.wnd_state);
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_display_number(int argc, char **argv) {
|
2020-02-06 04:19:20 +01:00
|
|
|
(void)argc;
|
|
|
|
int is_pointer = strtoul(argv[1], NULL, 0);
|
|
|
|
int base = strtoul(argv[2], NULL, 0);
|
|
|
|
if (base == 10) base = 0;
|
|
|
|
else if (base == 16) base = 1;
|
|
|
|
else if (base == 2) base = 2;
|
|
|
|
else base = 0;
|
|
|
|
size_t digits_to_display = strtoul(argv[3], NULL, 0);
|
|
|
|
int is_qword = strtoul(argv[4], NULL, 0);
|
|
|
|
int show_leading_zeros = strtoul(argv[5], NULL, 0);
|
|
|
|
uintptr_t number_or_pointer = strtoul(argv[6], NULL, 0);
|
|
|
|
size_t x = strtoul(argv[7], NULL, 0);
|
|
|
|
size_t y = strtoul(argv[8], NULL, 0);
|
|
|
|
uint32_t color = strtoul(argv[9], NULL, 16);
|
|
|
|
int fill_background = strtoul(argv[10], NULL, 0);
|
|
|
|
int font = strtoul(argv[11], NULL, 0);
|
|
|
|
int draw_to_buffer = strtoul(argv[12], NULL, 0);
|
|
|
|
int scale_factor = strtoul(argv[13], NULL, 0);
|
|
|
|
uintptr_t background_color_or_buffer = strtoul(argv[14], NULL, 16);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-06 04:19:20 +01:00
|
|
|
umka_sys_display_number(is_pointer, base, digits_to_display, is_qword, show_leading_zeros, number_or_pointer, x, y, color, fill_background, font, draw_to_buffer, scale_factor, background_color_or_buffer);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-06 04:19:20 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_set_window_colors(int argc, char **argv) {
|
2020-02-09 02:48:16 +01:00
|
|
|
if (argc != (1 + sizeof(system_colors_t)/4)) {
|
|
|
|
printf("10 colors required\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
system_colors_t colors;
|
|
|
|
colors.frame = strtoul(argv[1], NULL, 16);
|
|
|
|
colors.grab = strtoul(argv[2], NULL, 16);
|
|
|
|
colors.work_3d_dark = strtoul(argv[3], NULL, 16);
|
|
|
|
colors.work_3d_light = strtoul(argv[4], NULL, 16);
|
|
|
|
colors.grab_text = strtoul(argv[5], NULL, 16);
|
|
|
|
colors.work = strtoul(argv[6], NULL, 16);
|
|
|
|
colors.work_button = strtoul(argv[7], NULL, 16);
|
|
|
|
colors.work_button_text = strtoul(argv[8], NULL, 16);
|
|
|
|
colors.work_text = strtoul(argv[9], NULL, 16);
|
|
|
|
colors.work_graph = strtoul(argv[10], NULL, 16);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-09 02:48:16 +01:00
|
|
|
umka_sys_set_window_colors(&colors);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-09 02:48:16 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_get_window_colors(int argc, char **argv) {
|
2020-02-09 02:48:16 +01:00
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
system_colors_t colors;
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-09 02:48:16 +01:00
|
|
|
umka_sys_get_window_colors(&colors);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-09 02:48:16 +01:00
|
|
|
printf("0x%.8" PRIx32 " frame\n", colors.frame);
|
|
|
|
printf("0x%.8" PRIx32 " grab\n", colors.grab);
|
|
|
|
printf("0x%.8" PRIx32 " work_3d_dark\n", colors.work_3d_dark);
|
|
|
|
printf("0x%.8" PRIx32 " work_3d_light\n", colors.work_3d_light);
|
|
|
|
printf("0x%.8" PRIx32 " grab_text\n", colors.grab_text);
|
|
|
|
printf("0x%.8" PRIx32 " work\n", colors.work);
|
|
|
|
printf("0x%.8" PRIx32 " work_button\n", colors.work_button);
|
|
|
|
printf("0x%.8" PRIx32 " work_button_text\n", colors.work_button_text);
|
|
|
|
printf("0x%.8" PRIx32 " work_text\n", colors.work_text);
|
|
|
|
printf("0x%.8" PRIx32 " work_graph\n", colors.work_graph);
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_get_skin_height(int argc, char **argv) {
|
2020-02-09 02:48:16 +01:00
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-09 02:48:16 +01:00
|
|
|
uint32_t skin_height = umka_sys_get_skin_height();
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-09 02:48:16 +01:00
|
|
|
printf("%" PRIu32 "\n", skin_height);
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_get_screen_area(int argc, char **argv) {
|
2020-02-09 02:48:16 +01:00
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
rect_t wa;
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-09 02:48:16 +01:00
|
|
|
umka_sys_get_screen_area(&wa);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-09 02:48:16 +01:00
|
|
|
printf("%" PRIu32 " left\n", wa.left);
|
|
|
|
printf("%" PRIu32 " top\n", wa.top);
|
|
|
|
printf("%" PRIu32 " right\n", wa.right);
|
|
|
|
printf("%" PRIu32 " bottom\n", wa.bottom);
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_set_screen_area(int argc, char **argv) {
|
2020-02-09 02:48:16 +01:00
|
|
|
if (argc != 5) {
|
|
|
|
printf("left top right bottom\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rect_t wa;
|
|
|
|
wa.left = strtoul(argv[1], NULL, 0);
|
|
|
|
wa.top = strtoul(argv[2], NULL, 0);
|
|
|
|
wa.right = strtoul(argv[3], NULL, 0);
|
|
|
|
wa.bottom = strtoul(argv[4], NULL, 0);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-09 02:48:16 +01:00
|
|
|
umka_sys_set_screen_area(&wa);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-09 02:48:16 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_get_skin_margins(int argc, char **argv) {
|
2020-02-09 02:48:16 +01:00
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
rect_t wa;
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-09 02:48:16 +01:00
|
|
|
umka_sys_get_skin_margins(&wa);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-09 02:48:16 +01:00
|
|
|
printf("%" PRIu32 " left\n", wa.left);
|
|
|
|
printf("%" PRIu32 " top\n", wa.top);
|
|
|
|
printf("%" PRIu32 " right\n", wa.right);
|
|
|
|
printf("%" PRIu32 " bottom\n", wa.bottom);
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_set_button_style(int argc, char **argv) {
|
2020-02-09 02:48:16 +01:00
|
|
|
(void)argc;
|
|
|
|
uint32_t style = strtoul(argv[1], NULL, 0);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-09 02:48:16 +01:00
|
|
|
umka_sys_set_button_style(style);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-09 02:48:16 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_set_skin(int argc, char **argv) {
|
2020-02-08 19:27:29 +01:00
|
|
|
(void)argc;
|
|
|
|
const char *path = argv[1];
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-08 19:27:29 +01:00
|
|
|
int32_t status = umka_sys_set_skin(path);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-08 19:27:29 +01:00
|
|
|
printf("status: %" PRIi32 "\n", status);
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_get_font_smoothing(int argc, char **argv) {
|
2020-02-07 03:26:27 +01:00
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
const char *names[] = {"off", "anti-aliasing", "subpixel"};
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-09 02:48:16 +01:00
|
|
|
int type = umka_sys_get_font_smoothing();
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-07 03:26:27 +01:00
|
|
|
printf("font smoothing: %i - %s\n", type, names[type]);
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_set_font_smoothing(int argc, char **argv) {
|
2020-02-07 03:26:27 +01:00
|
|
|
(void)argc;
|
|
|
|
int type = strtol(argv[1], NULL, 0);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-09 02:48:16 +01:00
|
|
|
umka_sys_set_font_smoothing(type);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-09 02:48:16 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_get_font_size(int argc, char **argv) {
|
2020-02-09 02:48:16 +01:00
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-09 02:48:16 +01:00
|
|
|
size_t size = umka_sys_get_font_size();
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-09 02:48:16 +01:00
|
|
|
printf("%upx\n", size);
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_set_font_size(int argc, char **argv) {
|
2020-02-09 02:48:16 +01:00
|
|
|
(void)argc;
|
|
|
|
uint32_t size = strtoul(argv[1], NULL, 0);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-09 02:48:16 +01:00
|
|
|
umka_sys_set_font_size(size);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-07 03:26:27 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_button(int argc, char **argv) {
|
2020-02-06 04:19:20 +01:00
|
|
|
(void)argc;
|
|
|
|
size_t x = strtoul(argv[1], NULL, 0);
|
|
|
|
size_t xsize = strtoul(argv[2], NULL, 0);
|
|
|
|
size_t y = strtoul(argv[3], NULL, 0);
|
|
|
|
size_t ysize = strtoul(argv[4], NULL, 0);
|
|
|
|
uint32_t button_id = strtoul(argv[5], NULL, 0);
|
|
|
|
uint32_t color = strtoul(argv[6], NULL, 16);
|
|
|
|
int draw_button = strtoul(argv[7], NULL, 0);
|
|
|
|
int draw_frame = strtoul(argv[8], NULL, 0);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-06 04:19:20 +01:00
|
|
|
umka_sys_button(x, xsize, y, ysize, button_id, draw_button, draw_frame, color);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-06 04:19:20 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_put_image(int argc, char **argv) {
|
2020-02-06 04:19:20 +01:00
|
|
|
(void)argc;
|
|
|
|
FILE *f = fopen(argv[1], "r");
|
|
|
|
fseek(f, 0, SEEK_END);
|
|
|
|
size_t fsize = ftell(f);
|
|
|
|
rewind(f);
|
|
|
|
uint8_t *image = (uint8_t*)malloc(fsize);
|
|
|
|
fread(image, fsize, 1, f);
|
|
|
|
fclose(f);
|
|
|
|
size_t xsize = strtoul(argv[2], NULL, 0);
|
|
|
|
size_t ysize = strtoul(argv[3], NULL, 0);
|
|
|
|
size_t x = strtoul(argv[4], NULL, 0);
|
|
|
|
size_t y = strtoul(argv[5], NULL, 0);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-06 04:19:20 +01:00
|
|
|
umka_sys_put_image(image, xsize, ysize, x, y);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-06 04:19:20 +01:00
|
|
|
free(image);
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_put_image_palette(int argc, char **argv) {
|
2020-02-06 04:19:20 +01:00
|
|
|
(void)argc;
|
|
|
|
FILE *f = fopen(argv[1], "r");
|
|
|
|
fseek(f, 0, SEEK_END);
|
|
|
|
size_t fsize = ftell(f);
|
|
|
|
rewind(f);
|
|
|
|
uint8_t *image = (uint8_t*)malloc(fsize);
|
|
|
|
fread(image, fsize, 1, f);
|
|
|
|
fclose(f);
|
|
|
|
size_t xsize = strtoul(argv[2], NULL, 0);
|
|
|
|
size_t ysize = strtoul(argv[3], NULL, 0);
|
|
|
|
size_t x = strtoul(argv[4], NULL, 0);
|
|
|
|
size_t y = strtoul(argv[5], NULL, 0);
|
|
|
|
size_t bpp = strtoul(argv[6], NULL, 0);
|
|
|
|
void *palette = NULL;
|
|
|
|
size_t row_offset = strtoul(argv[7], NULL, 0);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-06 04:19:20 +01:00
|
|
|
umka_sys_put_image_palette(image, xsize, ysize, x, y, bpp, palette, row_offset);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-06 04:19:20 +01:00
|
|
|
free(image);
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_draw_rect(int argc, char **argv) {
|
2020-02-06 04:19:20 +01:00
|
|
|
size_t x = strtoul(argv[1], NULL, 0);
|
|
|
|
size_t xsize = strtoul(argv[2], NULL, 0);
|
|
|
|
size_t y = strtoul(argv[3], NULL, 0);
|
|
|
|
size_t ysize = strtoul(argv[4], NULL, 0);
|
|
|
|
uint32_t color = strtoul(argv[5], NULL, 16);
|
|
|
|
int gradient = (argc == 7) && !strcmp(argv[6], "-g");
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-06 04:19:20 +01:00
|
|
|
umka_sys_draw_rect(x, xsize, y, ysize, color, gradient);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-06 04:19:20 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_get_screen_size(int argc, char **argv) {
|
2020-02-19 01:27:18 +01:00
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
uint32_t xsize, ysize;
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-19 01:27:18 +01:00
|
|
|
umka_sys_get_screen_size(&xsize, &ysize);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-19 01:27:18 +01:00
|
|
|
printf("%" PRIu32 "x%" PRIu32 "\n", xsize, ysize);
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_draw_line(int argc, char **argv) {
|
2020-02-06 04:19:20 +01:00
|
|
|
size_t x = strtoul(argv[1], NULL, 0);
|
|
|
|
size_t xend = strtoul(argv[2], NULL, 0);
|
|
|
|
size_t y = strtoul(argv[3], NULL, 0);
|
|
|
|
size_t yend = strtoul(argv[4], NULL, 0);
|
|
|
|
uint32_t color = strtoul(argv[5], NULL, 16);
|
|
|
|
int invert = (argc == 7) && !strcmp(argv[6], "-i");
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-06 04:19:20 +01:00
|
|
|
umka_sys_draw_line(x, xend, y, yend, color, invert);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-06 04:19:20 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_set_window_caption(int argc, char **argv) {
|
2020-02-07 03:26:27 +01:00
|
|
|
(void)argc;
|
|
|
|
const char *caption = argv[1];
|
|
|
|
int encoding = strtoul(argv[2], NULL, 0);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-07 03:26:27 +01:00
|
|
|
umka_sys_set_window_caption(caption, encoding);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-07 03:26:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_draw_window(int argc, char **argv) {
|
2020-02-06 04:19:20 +01:00
|
|
|
(void)argc;
|
2020-02-07 03:26:27 +01:00
|
|
|
size_t x = strtoul(argv[1], NULL, 0);
|
|
|
|
size_t xsize = strtoul(argv[2], NULL, 0);
|
|
|
|
size_t y = strtoul(argv[3], NULL, 0);
|
|
|
|
size_t ysize = strtoul(argv[4], NULL, 0);
|
|
|
|
uint32_t color = strtoul(argv[5], NULL, 16);
|
|
|
|
int has_caption = strtoul(argv[6], NULL, 0);
|
|
|
|
int client_relative = strtoul(argv[7], NULL, 0);
|
|
|
|
int fill_workarea = strtoul(argv[8], NULL, 0);
|
|
|
|
int gradient_fill = strtoul(argv[9], NULL, 0);
|
|
|
|
int movable = strtoul(argv[10], NULL, 0);
|
|
|
|
int style = strtoul(argv[11], NULL, 0);
|
|
|
|
const char *caption = argv[12];
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-07 03:26:27 +01:00
|
|
|
umka_sys_draw_window(x, xsize, y, ysize, color, has_caption, client_relative, fill_workarea, gradient_fill, movable, style, caption);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-07 03:26:27 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_window_redraw(int argc, char **argv) {
|
2020-02-07 03:26:27 +01:00
|
|
|
(void)argc;
|
|
|
|
int begin_end = strtoul(argv[1], NULL, 0);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-07 03:26:27 +01:00
|
|
|
umka_sys_window_redraw(begin_end);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-07 03:26:27 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_move_window(int argc, char **argv) {
|
2020-02-07 03:26:27 +01:00
|
|
|
(void)argc;
|
|
|
|
size_t x = strtoul(argv[1], NULL, 0);
|
|
|
|
size_t y = strtoul(argv[2], NULL, 0);
|
|
|
|
ssize_t xsize = strtol(argv[3], NULL, 0);
|
|
|
|
ssize_t ysize = strtol(argv[4], NULL, 0);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-07 03:26:27 +01:00
|
|
|
umka_sys_move_window(x, y, xsize, ysize);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-07 03:26:27 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_blit_bitmap(int argc, char **argv) {
|
2020-02-07 03:26:27 +01:00
|
|
|
(void)argc;
|
|
|
|
FILE *f = fopen(argv[1], "r");
|
|
|
|
fseek(f, 0, SEEK_END);
|
|
|
|
size_t fsize = ftell(f);
|
|
|
|
rewind(f);
|
|
|
|
uint8_t *image = (uint8_t*)malloc(fsize);
|
|
|
|
fread(image, fsize, 1, f);
|
|
|
|
fclose(f);
|
|
|
|
size_t dstx = strtoul(argv[2], NULL, 0);
|
|
|
|
size_t dsty = strtoul(argv[3], NULL, 0);
|
|
|
|
size_t dstxsize = strtoul(argv[4], NULL, 0);
|
|
|
|
size_t dstysize = strtoul(argv[5], NULL, 0);
|
|
|
|
size_t srcx = strtoul(argv[6], NULL, 0);
|
|
|
|
size_t srcy = strtoul(argv[7], NULL, 0);
|
|
|
|
size_t srcxsize = strtoul(argv[8], NULL, 0);
|
|
|
|
size_t srcysize = strtoul(argv[9], NULL, 0);
|
|
|
|
int operation = strtoul(argv[10], NULL, 0);
|
|
|
|
int background = strtoul(argv[11], NULL, 0);
|
|
|
|
int transparent = strtoul(argv[12], NULL, 0);
|
|
|
|
int client_relative = strtoul(argv[13], NULL, 0);
|
|
|
|
int row_length = strtoul(argv[14], NULL, 0);
|
|
|
|
uint32_t params[] = {dstx, dsty, dstxsize, dstysize, srcx, srcy, srcxsize, srcysize, (uintptr_t)image, row_length};
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-07 03:26:27 +01:00
|
|
|
umka_sys_blit_bitmap(operation, background, transparent, client_relative, params);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-07 03:26:27 +01:00
|
|
|
free(image);
|
2020-02-06 04:19:20 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_scrot(int argc, char **argv) {
|
2020-02-04 22:53:24 +01:00
|
|
|
(void)argc;
|
2020-02-19 01:27:18 +01:00
|
|
|
uint32_t xsize, ysize;
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-19 01:27:18 +01:00
|
|
|
umka_sys_get_screen_size(&xsize, &ysize);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2020-02-19 01:27:18 +01:00
|
|
|
|
2020-02-04 22:53:24 +01:00
|
|
|
uint32_t *lfb = kos_lfb_base;
|
2020-02-19 01:27:18 +01:00
|
|
|
for (size_t y = 0; y < ysize; y++) {
|
|
|
|
for (size_t x = 0; x < xsize; x++) {
|
|
|
|
*lfb++ |= 0xff000000;
|
2020-02-04 22:53:24 +01:00
|
|
|
}
|
|
|
|
}
|
2020-02-19 01:27:18 +01:00
|
|
|
|
|
|
|
unsigned error = lodepng_encode32_file(argv[1], (const unsigned char *)kos_lfb_base, xsize, ysize);
|
|
|
|
if(error) printf("error %u: %s\n", error, lodepng_error_text(error));
|
2020-02-04 22:53:24 +01:00
|
|
|
}
|
|
|
|
|
2020-02-19 03:47:17 +01:00
|
|
|
void shell_cd(int argc, char **argv) {
|
2019-10-25 03:48:13 +02:00
|
|
|
(void)argc;
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-19 03:47:17 +01:00
|
|
|
umka_sys_set_cwd(argv[1]);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2019-10-25 03:48:13 +02:00
|
|
|
cur_dir_changed = true;
|
|
|
|
}
|
|
|
|
|
2019-12-08 02:32:07 +01:00
|
|
|
void ls_range(f7080s1arg_t *fX0, f70or80_t f70or80) {
|
|
|
|
f7080ret_t r;
|
|
|
|
size_t bdfe_len = (fX0->encoding == CP866) ? BDFE_LEN_CP866 : BDFE_LEN_UNICODE;
|
|
|
|
uint32_t requested = fX0->size;
|
|
|
|
if (fX0->size > MAX_DIRENTS_TO_READ) {
|
|
|
|
fX0->size = MAX_DIRENTS_TO_READ;
|
2018-06-18 03:55:51 +02:00
|
|
|
}
|
2019-12-08 02:32:07 +01:00
|
|
|
for (; requested; requested -= fX0->size) {
|
|
|
|
if (fX0->size > requested) {
|
|
|
|
fX0->size = requested;
|
2018-06-13 03:29:17 +02:00
|
|
|
}
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-06 04:19:20 +01:00
|
|
|
umka_sys_lfn(fX0, &r, f70or80);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2019-12-08 02:32:07 +01:00
|
|
|
fX0->offset += fX0->size;
|
2019-10-25 03:48:13 +02:00
|
|
|
print_f70_status(&r, 1);
|
2019-12-08 02:32:07 +01:00
|
|
|
f7080s1info_t *dir = fX0->buf;
|
|
|
|
int ok = (r.count <= fX0->size);
|
2019-11-07 00:51:55 +01:00
|
|
|
ok &= (dir->cnt == r.count);
|
2019-12-08 02:32:07 +01:00
|
|
|
ok &= (r.status == ERROR_SUCCESS && r.count == fX0->size)
|
|
|
|
|| (r.status == ERROR_END_OF_FILE && r.count < fX0->size);
|
2019-11-07 00:51:55 +01:00
|
|
|
assert(ok);
|
|
|
|
if (!ok)
|
|
|
|
break;
|
2019-12-08 02:32:07 +01:00
|
|
|
bdfe_t *bdfe = dir->bdfes;
|
2018-06-18 03:55:51 +02:00
|
|
|
for (size_t i = 0; i < dir->cnt; i++) {
|
2019-11-07 00:51:55 +01:00
|
|
|
char fattr[KF_ATTR_CNT+1];
|
2019-12-08 02:32:07 +01:00
|
|
|
convert_f70_file_attr(bdfe->attr, fattr);
|
|
|
|
printf("%s %s\n", fattr, bdfe->name);
|
|
|
|
bdfe = (bdfe_t*)((uintptr_t)bdfe + bdfe_len);
|
2018-06-18 03:55:51 +02:00
|
|
|
}
|
2019-12-08 02:32:07 +01:00
|
|
|
if (r.status == ERROR_END_OF_FILE) {
|
2018-06-18 03:55:51 +02:00
|
|
|
break;
|
2018-05-14 09:54:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-08 02:32:07 +01:00
|
|
|
void ls_all(f7080s1arg_t *fX0, f70or80_t f70or80) {
|
|
|
|
f7080ret_t r;
|
|
|
|
size_t bdfe_len = (fX0->encoding == CP866) ? BDFE_LEN_CP866 : BDFE_LEN_UNICODE;
|
2018-05-09 23:08:52 +02:00
|
|
|
while (true) {
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-06 04:19:20 +01:00
|
|
|
umka_sys_lfn(fX0, &r, f70or80);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2019-10-25 03:48:13 +02:00
|
|
|
print_f70_status(&r, 1);
|
2019-12-08 02:32:07 +01:00
|
|
|
assert((r.status == ERROR_SUCCESS && r.count == fX0->size)
|
|
|
|
|| (r.status == ERROR_END_OF_FILE && r.count < fX0->size));
|
|
|
|
f7080s1info_t *dir = fX0->buf;
|
|
|
|
fX0->offset += dir->cnt;
|
|
|
|
int ok = (r.count <= fX0->size);
|
2019-11-07 00:51:55 +01:00
|
|
|
ok &= (dir->cnt == r.count);
|
2019-12-08 02:32:07 +01:00
|
|
|
ok &= (r.status == ERROR_SUCCESS && r.count == fX0->size)
|
|
|
|
|| (r.status == ERROR_END_OF_FILE && r.count < fX0->size);
|
2019-11-07 00:51:55 +01:00
|
|
|
assert(ok);
|
|
|
|
if (!ok)
|
|
|
|
break;
|
2019-11-11 03:20:06 +01:00
|
|
|
printf("total = %"PRIi32"\n", dir->total_cnt);
|
2019-12-08 02:32:07 +01:00
|
|
|
bdfe_t *bdfe = dir->bdfes;
|
2018-05-09 23:08:52 +02:00
|
|
|
for (size_t i = 0; i < dir->cnt; i++) {
|
2019-11-07 00:51:55 +01:00
|
|
|
char fattr[KF_ATTR_CNT+1];
|
2019-12-08 02:32:07 +01:00
|
|
|
convert_f70_file_attr(bdfe->attr, fattr);
|
|
|
|
printf("%s %s\n", fattr, bdfe->name);
|
|
|
|
bdfe = (bdfe_t*)((uintptr_t)bdfe + bdfe_len);
|
2018-05-09 23:08:52 +02:00
|
|
|
}
|
2019-12-08 02:32:07 +01:00
|
|
|
if (r.status == ERROR_END_OF_FILE) {
|
2018-05-09 23:08:52 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-04-26 11:17:55 +02:00
|
|
|
}
|
2018-05-14 09:54:05 +02:00
|
|
|
}
|
|
|
|
|
2020-02-18 03:30:16 +01:00
|
|
|
fs_enc_t parse_encoding(const char *str) {
|
|
|
|
fs_enc_t enc;
|
|
|
|
if (!strcmp(str, "default")) {
|
|
|
|
enc = DEFAULT_ENCODING;
|
|
|
|
} else if (!strcmp(str, "cp866")) {
|
|
|
|
enc = CP866;
|
|
|
|
} else if (!strcmp(str, "utf16")) {
|
|
|
|
enc = UTF16;
|
|
|
|
} else if (!strcmp(str, "utf8")) {
|
|
|
|
enc = UTF8;
|
|
|
|
} else {
|
|
|
|
enc = INVALID_ENCODING;
|
|
|
|
}
|
|
|
|
return enc;
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_ls(int argc, char **argv, const char *usage, f70or80_t f70or80) {
|
2020-02-18 03:30:16 +01:00
|
|
|
int opt;
|
|
|
|
optind = 1;
|
|
|
|
const char *optstring = (f70or80 == F70) ? "f:c:e:" : "f:c:e:p:";
|
|
|
|
const char *path = ".";
|
|
|
|
uint32_t readdir_enc = DEFAULT_READDIR_ENCODING;
|
|
|
|
uint32_t path_enc = DEFAULT_PATH_ENCODING;
|
|
|
|
uint32_t from_idx = 0, count = MAX_DIRENTS_TO_READ;
|
2020-02-28 03:18:09 +01:00
|
|
|
if (argc > 1 && *argv[optind] != '-') {
|
2020-02-18 03:30:16 +01:00
|
|
|
path = argv[optind++];
|
|
|
|
}
|
|
|
|
while ((opt = getopt(argc, argv, optstring)) != -1) {
|
|
|
|
switch (opt) {
|
|
|
|
case 'f':
|
2020-02-28 03:18:09 +01:00
|
|
|
from_idx = strtoul(optarg, NULL, 0);
|
2020-02-18 03:30:16 +01:00
|
|
|
break;
|
|
|
|
case 'c':
|
2020-02-28 03:18:09 +01:00
|
|
|
count = strtoul(optarg, NULL, 0);
|
2020-02-18 03:30:16 +01:00
|
|
|
break;
|
|
|
|
case 'e':
|
2020-02-28 03:18:09 +01:00
|
|
|
readdir_enc = parse_encoding(optarg);
|
2020-02-18 03:30:16 +01:00
|
|
|
break;
|
|
|
|
case 'p':
|
2020-02-28 03:18:09 +01:00
|
|
|
path_enc = parse_encoding(optarg);
|
2020-02-18 03:30:16 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t bdfe_len = (readdir_enc <= CP866) ? BDFE_LEN_CP866 : BDFE_LEN_UNICODE;
|
2019-12-08 02:32:07 +01:00
|
|
|
f7080s1info_t *dir = (f7080s1info_t*)malloc(sizeof(f7080s1info_t) + bdfe_len * MAX_DIRENTS_TO_READ);
|
2020-02-18 03:30:16 +01:00
|
|
|
f7080s1arg_t fX0 = {.sf = 1, .offset = from_idx, .encoding = readdir_enc, .size = count, .buf = dir};
|
2019-12-08 02:32:07 +01:00
|
|
|
if (f70or80 == F70) {
|
|
|
|
fX0.u.f70.zero = 0;
|
2020-02-18 03:30:16 +01:00
|
|
|
fX0.u.f70.path = path;
|
2019-12-08 02:32:07 +01:00
|
|
|
} else {
|
2020-02-18 03:30:16 +01:00
|
|
|
fX0.u.f80.path_encoding = path_enc;
|
|
|
|
fX0.u.f80.path = path;
|
2019-12-08 02:32:07 +01:00
|
|
|
}
|
2020-02-18 03:30:16 +01:00
|
|
|
if (count != MAX_DIRENTS_TO_READ) {
|
2019-12-08 02:32:07 +01:00
|
|
|
ls_range(&fX0, f70or80);
|
2018-05-14 09:54:05 +02:00
|
|
|
} else {
|
2019-12-08 02:32:07 +01:00
|
|
|
ls_all(&fX0, f70or80);
|
2018-05-14 09:54:05 +02:00
|
|
|
}
|
2018-05-09 23:08:52 +02:00
|
|
|
free(dir);
|
2018-04-26 11:17:55 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_ls70(int argc, char **argv) {
|
2020-02-18 03:30:16 +01:00
|
|
|
const char *usage = \
|
|
|
|
"usage: ls70 [dir] [option]...\n"
|
|
|
|
" -f number index of the first dir entry to read\n"
|
|
|
|
" -c number number of dir entries to read\n"
|
|
|
|
" -e encoding cp866|utf16|utf8\n"
|
|
|
|
" return directory listing in this encoding";
|
2020-03-09 22:03:57 +01:00
|
|
|
shell_ls(argc, argv, usage, F70);
|
2019-12-08 02:32:07 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_ls80(int argc, char **argv) {
|
2020-02-18 03:30:16 +01:00
|
|
|
const char *usage = \
|
|
|
|
"usage: ls80 [dir] [option]...\n"
|
|
|
|
" -f number index of the first dir entry to read\n"
|
|
|
|
" -c number number of dir entries to read\n"
|
|
|
|
" -e encoding cp866|utf16|utf8\n"
|
|
|
|
" return directory listing in this encoding\n"
|
|
|
|
" -p encoding cp866|utf16|utf8\n"
|
|
|
|
" path to dir is specified in this encoding";
|
2020-03-09 22:03:57 +01:00
|
|
|
shell_ls(argc, argv, usage, F80);
|
2019-12-08 02:32:07 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_stat(int argc, char **argv, f70or80_t f70or80) {
|
2019-10-13 03:17:29 +02:00
|
|
|
(void)argc;
|
2019-12-08 02:32:07 +01:00
|
|
|
f7080s5arg_t fX0 = {.sf = 5, .flags = 0};
|
|
|
|
f7080ret_t r;
|
2019-10-21 04:51:56 +02:00
|
|
|
bdfe_t file;
|
2019-12-08 02:32:07 +01:00
|
|
|
fX0.buf = &file;
|
|
|
|
if (f70or80 == F70) {
|
|
|
|
fX0.u.f70.zero = 0;
|
|
|
|
fX0.u.f70.path = argv[1];
|
|
|
|
} else {
|
|
|
|
fX0.u.f80.path_encoding = DEFAULT_PATH_ENCODING;
|
|
|
|
fX0.u.f80.path = argv[1];
|
|
|
|
}
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-06 04:19:20 +01:00
|
|
|
umka_sys_lfn(&fX0, &r, f70or80);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2019-10-25 03:48:13 +02:00
|
|
|
print_f70_status(&r, 0);
|
2019-12-08 02:32:07 +01:00
|
|
|
if (r.status != ERROR_SUCCESS)
|
2019-10-31 21:26:53 +01:00
|
|
|
return;
|
2019-11-07 00:51:55 +01:00
|
|
|
char fattr[KF_ATTR_CNT+1];
|
|
|
|
convert_f70_file_attr(file.attr, fattr);
|
|
|
|
printf("attr: %s\n", fattr);
|
|
|
|
if ((file.attr & KF_FOLDER) == 0) { // don't show size for dirs
|
2019-10-31 21:26:53 +01:00
|
|
|
printf("size: %llu\n", file.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if PRINT_DATE_TIME == 1
|
|
|
|
time_t time;
|
|
|
|
struct tm *t;
|
|
|
|
time = kos_time_to_epoch(&file.ctime);
|
|
|
|
t = localtime(&time);
|
|
|
|
printf("ctime: %4.4i.%2.2i.%2.2i %2.2i:%2.2i:%2.2i\n",
|
|
|
|
t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
|
|
|
|
t->tm_hour, t->tm_min, t->tm_sec);
|
|
|
|
time = kos_time_to_epoch(&file.atime);
|
|
|
|
t = localtime(&time);
|
|
|
|
printf("atime: %4.4i.%2.2i.%2.2i %2.2i:%2.2i:%2.2i\n",
|
|
|
|
t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
|
|
|
|
t->tm_hour, t->tm_min, t->tm_sec);
|
|
|
|
time = kos_time_to_epoch(&file.mtime);
|
|
|
|
t = localtime(&time);
|
|
|
|
printf("mtime: %4.4i.%2.2i.%2.2i %2.2i:%2.2i:%2.2i\n",
|
|
|
|
t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
|
|
|
|
t->tm_hour, t->tm_min, t->tm_sec);
|
|
|
|
#endif
|
2018-04-26 11:17:55 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_stat70(int argc, char **argv) {
|
|
|
|
shell_stat(argc, argv, F70);
|
2019-12-08 02:32:07 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_stat80(int argc, char **argv) {
|
|
|
|
shell_stat(argc, argv, F80);
|
2019-12-08 02:32:07 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_read(int argc, char **argv, f70or80_t f70or80) {
|
2019-10-13 03:17:29 +02:00
|
|
|
(void)argc;
|
2019-12-08 02:32:07 +01:00
|
|
|
f7080s0arg_t fX0 = {.sf = 0};
|
|
|
|
f7080ret_t r;
|
2019-10-21 04:51:56 +02:00
|
|
|
bool dump_bytes = false, dump_hash = false;
|
|
|
|
if (argc < 4) {
|
2019-12-08 02:32:07 +01:00
|
|
|
printf("usage: %s <offset> <length> [-b] [-h] [-e cp866|utf8|utf16]\n", argv[0]);
|
2019-10-21 04:51:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
int opt = 1;
|
2019-12-08 02:32:07 +01:00
|
|
|
if (f70or80 == F70) {
|
|
|
|
fX0.u.f70.zero = 0;
|
|
|
|
fX0.u.f70.path = argv[opt++];
|
|
|
|
} else {
|
|
|
|
fX0.u.f80.path_encoding = DEFAULT_PATH_ENCODING;
|
|
|
|
fX0.u.f80.path = argv[opt++];
|
|
|
|
}
|
|
|
|
if ((opt >= argc) || !parse_uint64(argv[opt++], &fX0.offset))
|
2019-10-21 04:51:56 +02:00
|
|
|
return;
|
2019-12-08 02:32:07 +01:00
|
|
|
if ((opt >= argc) || !parse_uint32(argv[opt++], &fX0.count))
|
2019-10-21 04:51:56 +02:00
|
|
|
return;
|
|
|
|
for (; opt < argc; opt++) {
|
|
|
|
if (!strcmp(argv[opt], "-b")) {
|
|
|
|
dump_bytes = true;
|
|
|
|
} else if (!strcmp(argv[opt], "-h")) {
|
|
|
|
dump_hash = true;
|
2019-12-08 02:32:07 +01:00
|
|
|
} else if (!strcmp(argv[opt], "-e")) {
|
|
|
|
if (f70or80 == F70) {
|
|
|
|
printf("f70 doesn't accept encoding parameter, use f80\n");
|
|
|
|
return;
|
|
|
|
}
|
2019-10-21 04:51:56 +02:00
|
|
|
} else {
|
|
|
|
printf("invalid option: '%s'\n", argv[opt]);
|
|
|
|
return;
|
2018-05-07 17:31:42 +02:00
|
|
|
}
|
|
|
|
}
|
2019-12-08 02:32:07 +01:00
|
|
|
fX0.buf = (uint8_t*)malloc(fX0.count);
|
2019-10-21 04:51:56 +02:00
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_ON();
|
2020-02-06 04:19:20 +01:00
|
|
|
umka_sys_lfn(&fX0, &r, f70or80);
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2019-10-25 03:48:13 +02:00
|
|
|
|
|
|
|
print_f70_status(&r, 1);
|
2019-12-08 02:32:07 +01:00
|
|
|
if (r.status == ERROR_SUCCESS || r.status == ERROR_END_OF_FILE) {
|
|
|
|
if (dump_bytes)
|
|
|
|
print_bytes(fX0.buf, r.count);
|
|
|
|
if (dump_hash)
|
|
|
|
print_hash(fX0.buf, r.count);
|
|
|
|
}
|
2019-10-21 04:51:56 +02:00
|
|
|
|
2019-12-08 02:32:07 +01:00
|
|
|
free(fX0.buf);
|
2018-05-07 17:31:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_read70(int argc, char **argv) {
|
|
|
|
shell_read(argc, argv, F70);
|
2019-12-08 02:32:07 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
void shell_read80(int argc, char **argv) {
|
|
|
|
shell_read(argc, argv, F80);
|
2019-12-08 02:32:07 +01:00
|
|
|
}
|
|
|
|
|
2020-05-02 00:09:42 +02:00
|
|
|
void shell_acpi_preload_table(int argc, char **argv) {
|
|
|
|
(void)argc;
|
|
|
|
FILE *f = fopen(argv[1], "r");
|
|
|
|
fseek(f, 0, SEEK_END);
|
|
|
|
size_t fsize = ftell(f);
|
|
|
|
rewind(f);
|
|
|
|
uint8_t *table = (uint8_t*)malloc(fsize);
|
|
|
|
fread(table, fsize, 1, f);
|
|
|
|
fclose(f);
|
|
|
|
fprintf(stderr, "# %zu\n", kos_acpi_ssdt_cnt);
|
|
|
|
kos_acpi_ssdt_base[kos_acpi_ssdt_cnt] = table;
|
|
|
|
kos_acpi_ssdt_size[kos_acpi_ssdt_cnt] = fsize;
|
|
|
|
kos_acpi_ssdt_cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_acpi_enable(int argc, char **argv) {
|
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
COVERAGE_ON();
|
|
|
|
kos_enable_acpi();
|
|
|
|
COVERAGE_OFF();
|
|
|
|
}
|
|
|
|
|
2020-05-06 23:33:32 +02:00
|
|
|
void shell_stack_init(int argc, char **argv) {
|
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
kos_stack_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_add_device(int argc, char **argv) {
|
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
int32_t dev_num = kos_net_add_device(&vnet);
|
|
|
|
printf("device number: %" PRIi32 "\n", dev_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_get_dev_count(int argc, char **argv) {
|
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
uint32_t count = umka_sys_net_get_dev_count();
|
|
|
|
printf("active network devices: %u\n", count);
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_get_dev_type(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_get_dev_type <dev_num>\n"
|
|
|
|
" dev_num device number as returned by net_add_device";
|
|
|
|
if (argc != 2) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t dev_num = strtoul(argv[1], NULL, 0);
|
|
|
|
int32_t dev_type = umka_sys_net_get_dev_type(dev_num);
|
|
|
|
printf("status: %s\n", dev_type == -1 ? "fail" : "ok");
|
|
|
|
if (dev_type != -1) {
|
|
|
|
printf("type of network device #%" PRIu8 ": %i\n", dev_num, dev_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_get_dev_name(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_get_dev_name <dev_num>\n"
|
|
|
|
" dev_num device number as returned by net_add_device";
|
|
|
|
if (argc != 2) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
char dev_name[64];
|
|
|
|
uint8_t dev_num = strtoul(argv[1], NULL, 0);
|
|
|
|
int32_t status = umka_sys_net_get_dev_name(dev_num, dev_name);
|
|
|
|
printf("status: %s\n", status == -1 ? "fail" : "ok");
|
|
|
|
if (status != -1) {
|
|
|
|
printf("name of network device #%" PRIu8 ": %s\n", dev_num, dev_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_dev_reset(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_dev_reset <dev_num>\n"
|
|
|
|
" dev_num device number as returned by net_add_device";
|
|
|
|
if (argc != 2) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t dev_num = strtoul(argv[1], NULL, 0);
|
|
|
|
int32_t status = umka_sys_net_dev_reset(dev_num);
|
|
|
|
printf("status: %s\n", status == -1 ? "fail" : "ok");
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_dev_stop(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_dev_stop <dev_num>\n"
|
|
|
|
" dev_num device number as returned by net_add_device";
|
|
|
|
if (argc != 2) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t dev_num = strtoul(argv[1], NULL, 0);
|
|
|
|
int32_t status = umka_sys_net_dev_stop(dev_num);
|
|
|
|
printf("status: %s\n", status == -1 ? "fail" : "ok");
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_get_dev(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_get_dev <dev_num>\n"
|
|
|
|
" dev_num device number as returned by net_add_device";
|
|
|
|
if (argc != 2) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t dev_num = strtoul(argv[1], NULL, 0);
|
|
|
|
intptr_t dev = umka_sys_net_get_dev(dev_num);
|
|
|
|
printf("status: %s\n", dev == -1 ? "fail" : "ok");
|
|
|
|
if (dev != -1) {
|
|
|
|
printf("address of net dev #%" PRIu8 ": 0x%x\n", dev_num, dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_get_packet_tx_count(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_get_packet_tx_count <dev_num>\n"
|
|
|
|
" dev_num device number as returned by net_add_device";
|
|
|
|
if (argc != 2) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t dev_num = strtoul(argv[1], NULL, 0);
|
|
|
|
uint32_t count = umka_sys_net_get_packet_tx_count(dev_num);
|
|
|
|
printf("status: %s\n", count == UINT32_MAX ? "fail" : "ok");
|
|
|
|
if (count != UINT32_MAX) {
|
|
|
|
printf("packet tx count of net dev #%" PRIu8 ": %" PRIu32 "\n",
|
|
|
|
dev_num, count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_get_packet_rx_count(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_get_packet_rx_count <dev_num>\n"
|
|
|
|
" dev_num device number as returned by net_add_device";
|
|
|
|
if (argc != 2) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t dev_num = strtoul(argv[1], NULL, 0);
|
|
|
|
uint32_t count = umka_sys_net_get_packet_rx_count(dev_num);
|
|
|
|
printf("status: %s\n", count == UINT32_MAX ? "fail" : "ok");
|
|
|
|
if (count != UINT32_MAX) {
|
|
|
|
printf("packet rx count of net dev #%" PRIu8 ": %" PRIu32 "\n",
|
|
|
|
dev_num, count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_get_byte_tx_count(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_get_byte_tx_count <dev_num>\n"
|
|
|
|
" dev_num device number as returned by net_add_device";
|
|
|
|
if (argc != 2) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t dev_num = strtoul(argv[1], NULL, 0);
|
|
|
|
uint32_t count = umka_sys_net_get_byte_tx_count(dev_num);
|
|
|
|
printf("status: %s\n", count == UINT32_MAX ? "fail" : "ok");
|
|
|
|
if (count != UINT32_MAX) {
|
|
|
|
printf("byte tx count of net dev #%" PRIu8 ": %" PRIu32 "\n",
|
|
|
|
dev_num, count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_get_byte_rx_count(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_get_byte_rx_count <dev_num>\n"
|
|
|
|
" dev_num device number as returned by net_add_device";
|
|
|
|
if (argc != 2) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t dev_num = strtoul(argv[1], NULL, 0);
|
|
|
|
uint32_t count = umka_sys_net_get_byte_rx_count(dev_num);
|
|
|
|
printf("status: %s\n", count == UINT32_MAX ? "fail" : "ok");
|
|
|
|
if (count != UINT32_MAX) {
|
|
|
|
printf("byte rx count of net dev #%" PRIu8 ": %" PRIu32 "\n",
|
|
|
|
dev_num, count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_link_status_names(uint32_t status) {
|
|
|
|
switch (status & 0x3) {
|
|
|
|
case ETH_LINK_DOWN:
|
|
|
|
printf("ETH_LINK_DOWN");
|
|
|
|
break;
|
|
|
|
case ETH_LINK_UNKNOWN:
|
|
|
|
printf("ETH_LINK_UNKNOWN");
|
|
|
|
break;
|
|
|
|
case ETH_LINK_FD:
|
|
|
|
printf("ETH_LINK_FD");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("ERROR");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(status & ~3u) {
|
|
|
|
case ETH_LINK_1G:
|
|
|
|
printf(" + ETH_LINK_1G");
|
|
|
|
break;
|
|
|
|
case ETH_LINK_100M:
|
|
|
|
printf(" + ETH_LINK_100M");
|
|
|
|
break;
|
|
|
|
case ETH_LINK_10M:
|
|
|
|
printf(" + ETH_LINK_10M");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf(" + UNKNOWN");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_get_link_status(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_get_link_status <dev_num>\n"
|
|
|
|
" dev_num device number as returned by net_add_device";
|
|
|
|
if (argc != 2) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t dev_num = strtoul(argv[1], NULL, 0);
|
2020-05-07 03:08:20 +02:00
|
|
|
uint32_t status = umka_sys_net_get_link_status(dev_num);
|
2020-05-06 23:33:32 +02:00
|
|
|
printf("status: %s\n", status == UINT32_MAX ? "fail" : "ok");
|
|
|
|
if (status != UINT32_MAX) {
|
|
|
|
printf("link status of net dev #%" PRIu8 ": %" PRIu32 " ",
|
|
|
|
dev_num, status);
|
|
|
|
print_link_status_names(status);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-07 03:08:20 +02:00
|
|
|
void shell_net_open_socket(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_open_socket <domain> <type> <protocol>\n"
|
|
|
|
" domain domain\n"
|
|
|
|
" type type\n"
|
|
|
|
" protocol protocol";
|
|
|
|
if (argc != 4) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint32_t domain = strtoul(argv[1], NULL, 0);
|
|
|
|
uint32_t type = strtoul(argv[2], NULL, 0);
|
|
|
|
uint32_t protocol = strtoul(argv[3], NULL, 0);
|
|
|
|
f75ret_t r = umka_sys_net_open_socket(domain, type, protocol);
|
|
|
|
printf("value: 0x%" PRIx32 "\n", r.value);
|
|
|
|
printf("errorcode: 0x%" PRIx32 "\n", r.errorcode);
|
|
|
|
// UINT32_MAX
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_close_socket(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_close_socket <socket number>\n"
|
|
|
|
" socket number socket number";
|
|
|
|
if (argc != 2) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint32_t fd = strtoul(argv[1], NULL, 0);
|
|
|
|
f75ret_t r = umka_sys_net_close_socket(fd);
|
|
|
|
printf("value: 0x%" PRIx32 "\n", r.value);
|
|
|
|
printf("errorcode: 0x%" PRIx32 "\n", r.errorcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_bind(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_bind <fd> <port> <ip>\n"
|
|
|
|
" fd socket number\n"
|
|
|
|
" port port\n"
|
|
|
|
" addr addr";
|
|
|
|
if (argc != 4) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint32_t fd = strtoul(argv[1], NULL, 0);
|
|
|
|
uint16_t port = strtoul(argv[2], NULL, 0);
|
|
|
|
char *addr_str = argv[3];
|
|
|
|
uint32_t addr = inet_addr(addr_str);
|
|
|
|
struct sockaddr_in sa;
|
|
|
|
memset(&sa, 0, sizeof(sa));
|
|
|
|
sa.sin_family = AF_INET4;
|
|
|
|
sa.sin_port = htons(port);
|
|
|
|
sa.sin_addr.s_addr = addr;
|
|
|
|
printf("sockaddr at %p\n", &sa);
|
|
|
|
f75ret_t r = umka_sys_net_bind(fd, &sa, sizeof(struct sockaddr_in));
|
|
|
|
printf("value: 0x%" PRIx32 "\n", r.value);
|
|
|
|
printf("errorcode: 0x%" PRIx32 "\n", r.errorcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_listen(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_listen <fd> <backlog>\n"
|
|
|
|
" fd socket number\n"
|
|
|
|
" backlog max queue length";
|
|
|
|
if (argc != 3) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint32_t fd = strtoul(argv[1], NULL, 0);
|
|
|
|
uint32_t backlog = strtoul(argv[2], NULL, 0);
|
|
|
|
f75ret_t r = umka_sys_net_listen(fd, backlog);
|
|
|
|
printf("value: 0x%" PRIx32 "\n", r.value);
|
|
|
|
printf("errorcode: 0x%" PRIx32 "\n", r.errorcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_connect(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_connect <fd> <port> <ip>\n"
|
|
|
|
" fd socket number\n"
|
|
|
|
" port port\n"
|
|
|
|
" addr addr";
|
|
|
|
if (argc != 4) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint32_t fd = strtoul(argv[1], NULL, 0);
|
|
|
|
uint16_t port = strtoul(argv[2], NULL, 0);
|
|
|
|
char *addr_str = argv[3];
|
|
|
|
uint32_t addr = inet_addr(addr_str);
|
|
|
|
struct sockaddr_in sa;
|
|
|
|
memset(&sa, 0, sizeof(sa));
|
|
|
|
sa.sin_family = AF_INET4;
|
|
|
|
sa.sin_port = htons(port);
|
|
|
|
sa.sin_addr.s_addr = addr;
|
|
|
|
printf("sockaddr at %p\n", &sa);
|
|
|
|
f75ret_t r = umka_sys_net_connect(fd, &sa, sizeof(struct sockaddr_in));
|
|
|
|
printf("value: 0x%" PRIx32 "\n", r.value);
|
|
|
|
printf("errorcode: 0x%" PRIx32 "\n", r.errorcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_accept(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_accept <fd> <port> <ip>\n"
|
|
|
|
" fd socket number\n"
|
|
|
|
" port port\n"
|
|
|
|
" addr addr";
|
|
|
|
if (argc != 4) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint32_t fd = strtoul(argv[1], NULL, 0);
|
|
|
|
uint16_t port = strtoul(argv[2], NULL, 0);
|
|
|
|
char *addr_str = argv[3];
|
|
|
|
uint32_t addr = inet_addr(addr_str);
|
|
|
|
struct sockaddr_in sa;
|
|
|
|
memset(&sa, 0, sizeof(sa));
|
|
|
|
sa.sin_family = AF_INET4;
|
|
|
|
sa.sin_port = htons(port);
|
|
|
|
sa.sin_addr.s_addr = addr;
|
|
|
|
printf("sockaddr at %p\n", &sa);
|
|
|
|
f75ret_t r = umka_sys_net_accept(fd, &sa, sizeof(struct sockaddr_in));
|
|
|
|
printf("value: 0x%" PRIx32 "\n", r.value);
|
|
|
|
printf("errorcode: 0x%" PRIx32 "\n", r.errorcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_eth_read_mac(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_eth_read_mac <dev_num>\n"
|
|
|
|
" dev_num device number as returned by net_add_device";
|
|
|
|
if (argc != 2) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint32_t dev_num = strtoul(argv[1], NULL, 0);
|
|
|
|
f76ret_t r = umka_sys_net_eth_read_mac(dev_num);
|
|
|
|
if (r.eax == UINT32_MAX) {
|
|
|
|
printf("status: fail\n");
|
|
|
|
} else {
|
|
|
|
printf("%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
|
|
|
|
(uint8_t)(r.ebx >> 0), (uint8_t)(r.ebx >> 8),
|
|
|
|
(uint8_t)(r.eax >> 0), (uint8_t)(r.eax >> 8),
|
|
|
|
(uint8_t)(r.eax >> 16), (uint8_t)(r.eax >> 24));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_ipv4_get_addr(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_ipv4_get_addr <dev_num>\n"
|
|
|
|
" dev_num device number as returned by net_add_device";
|
|
|
|
if (argc != 2) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint32_t dev_num = strtoul(argv[1], NULL, 0);
|
|
|
|
f76ret_t r = umka_sys_net_ipv4_get_addr(dev_num);
|
|
|
|
if (r.eax == UINT32_MAX) {
|
|
|
|
printf("status: fail\n");
|
|
|
|
} else {
|
|
|
|
printf("%d.%d.%d.%d\n",
|
|
|
|
(uint8_t)(r.eax >> 0), (uint8_t)(r.eax >> 8),
|
|
|
|
(uint8_t)(r.eax >> 16), (uint8_t)(r.eax >> 24));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void shell_net_ipv4_set_addr(int argc, char **argv) {
|
|
|
|
const char *usage = \
|
|
|
|
"usage: net_ipv4_set_addr <dev_num> <addr>\n"
|
|
|
|
" dev_num device number as returned by net_add_device\n"
|
|
|
|
" addr a.b.c.d";
|
|
|
|
if (argc != 3) {
|
|
|
|
puts(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint32_t dev_num = strtoul(argv[1], NULL, 0);
|
|
|
|
char *addr_str = argv[2];
|
|
|
|
uint32_t addr = inet_addr(addr_str);
|
|
|
|
f76ret_t r = umka_sys_net_ipv4_set_addr(dev_num, addr);
|
|
|
|
if (r.eax == UINT32_MAX) {
|
|
|
|
printf("status: fail\n");
|
|
|
|
} else {
|
|
|
|
printf("status: ok\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-06 23:33:32 +02:00
|
|
|
|
2019-10-25 03:48:13 +02:00
|
|
|
typedef struct {
|
2018-04-26 11:17:55 +02:00
|
|
|
char *name;
|
2020-02-18 03:30:16 +01:00
|
|
|
void (*func) (int, char **);
|
2019-10-25 03:48:13 +02:00
|
|
|
} func_table_t;
|
2018-04-26 11:17:55 +02:00
|
|
|
|
2019-10-25 03:48:13 +02:00
|
|
|
func_table_t funcs[] = {
|
2020-05-06 23:33:32 +02:00
|
|
|
{ "i40", shell_i40 },
|
|
|
|
{ "disk_add", shell_disk_add },
|
|
|
|
{ "disk_del", shell_disk_del },
|
|
|
|
{ "ls70", shell_ls70 },
|
|
|
|
{ "ls80", shell_ls80 },
|
|
|
|
{ "stat70", shell_stat70 },
|
|
|
|
{ "stat80", shell_stat80 },
|
|
|
|
{ "read70", shell_read70 },
|
|
|
|
{ "read80", shell_read80 },
|
|
|
|
{ "pwd", shell_pwd },
|
|
|
|
{ "cd", shell_cd },
|
|
|
|
{ "set_cwd", shell_cd },
|
|
|
|
{ "draw_window", shell_draw_window },
|
|
|
|
{ "set_pixel", shell_set_pixel },
|
|
|
|
{ "write_text", shell_write_text },
|
|
|
|
{ "put_image", shell_put_image },
|
|
|
|
{ "button", shell_button },
|
|
|
|
{ "process_info", shell_process_info },
|
|
|
|
{ "window_redraw", shell_window_redraw },
|
|
|
|
{ "draw_rect", shell_draw_rect },
|
|
|
|
{ "get_screen_size", shell_get_screen_size },
|
|
|
|
{ "draw_line", shell_draw_line },
|
|
|
|
{ "display_number", shell_display_number },
|
|
|
|
{ "set_button_style", shell_set_button_style },
|
|
|
|
{ "set_window_colors", shell_set_window_colors },
|
|
|
|
{ "get_window_colors", shell_get_window_colors },
|
|
|
|
{ "get_skin_height", shell_get_skin_height },
|
|
|
|
{ "get_screen_area", shell_get_screen_area },
|
|
|
|
{ "set_screen_area", shell_set_screen_area },
|
|
|
|
{ "get_skin_margins", shell_get_skin_margins },
|
|
|
|
{ "set_skin", shell_set_skin },
|
|
|
|
{ "get_font_smoothing", shell_get_font_smoothing },
|
|
|
|
{ "set_font_smoothing", shell_set_font_smoothing },
|
|
|
|
{ "get_font_size", shell_get_font_size },
|
|
|
|
{ "set_font_size", shell_set_font_size },
|
|
|
|
{ "put_image_palette", shell_put_image_palette },
|
|
|
|
{ "move_window", shell_move_window },
|
|
|
|
{ "set_window_caption", shell_set_window_caption },
|
|
|
|
{ "blit_bitmap", shell_blit_bitmap },
|
|
|
|
{ "scrot", shell_scrot },
|
|
|
|
{ "dump_win_stack", shell_dump_win_stack },
|
|
|
|
{ "dump_win_pos", shell_dump_win_pos },
|
|
|
|
{ "acpi_enable", shell_acpi_enable },
|
|
|
|
{ "acpi_preload_table", shell_acpi_preload_table },
|
|
|
|
{ "stack_init", shell_stack_init },
|
|
|
|
{ "net_add_device", shell_net_add_device },
|
|
|
|
{ "net_get_dev_count", shell_net_get_dev_count },
|
|
|
|
{ "net_get_dev_type", shell_net_get_dev_type },
|
|
|
|
{ "net_get_dev_name", shell_net_get_dev_name },
|
|
|
|
{ "net_dev_reset", shell_net_dev_reset },
|
|
|
|
{ "net_dev_stop", shell_net_dev_stop },
|
|
|
|
{ "net_get_dev", shell_net_get_dev },
|
|
|
|
{ "net_get_packet_tx_count", shell_net_get_packet_tx_count },
|
|
|
|
{ "net_get_packet_rx_count", shell_net_get_packet_rx_count },
|
|
|
|
{ "net_get_byte_tx_count", shell_net_get_byte_tx_count },
|
|
|
|
{ "net_get_byte_rx_count", shell_net_get_byte_rx_count },
|
|
|
|
{ "net_get_link_status", shell_net_get_link_status },
|
2020-05-07 03:08:20 +02:00
|
|
|
{ "net_open_socket", shell_net_open_socket },
|
|
|
|
{ "net_close_socket", shell_net_close_socket },
|
|
|
|
{ "net_bind", shell_net_bind },
|
|
|
|
{ "net_listen", shell_net_listen },
|
|
|
|
{ "net_connect", shell_net_connect },
|
|
|
|
{ "net_accept", shell_net_accept },
|
|
|
|
{ "net_eth_read_mac", shell_net_eth_read_mac },
|
|
|
|
{ "net_ipv4_get_addr", shell_net_ipv4_get_addr },
|
|
|
|
{ "net_ipv4_set_addr", shell_net_ipv4_set_addr },
|
2020-05-06 23:33:32 +02:00
|
|
|
{ NULL, NULL },
|
|
|
|
};
|
2018-04-26 11:17:55 +02:00
|
|
|
|
2019-10-30 22:54:12 +01:00
|
|
|
void *run_test(const char *infile_name) {
|
|
|
|
FILE *infile, *outfile;
|
|
|
|
|
|
|
|
if (!infile_name) {
|
|
|
|
infile = stdin;
|
|
|
|
outfile = stdout;
|
|
|
|
} else {
|
|
|
|
char outfile_name[PATH_MAX];
|
2020-03-09 22:03:57 +01:00
|
|
|
strncpy(outfile_name, infile_name, PATH_MAX-2); // ".t" is shorter than ".out"
|
2019-10-30 22:54:12 +01:00
|
|
|
char *last_dot = strrchr(outfile_name, '.');
|
|
|
|
if (!last_dot) {
|
|
|
|
printf("test file must have '.t' suffix\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-02-21 03:21:09 +01:00
|
|
|
strcpy(last_dot, ".out.log");
|
2019-10-30 22:54:12 +01:00
|
|
|
infile = fopen(infile_name, "r");
|
|
|
|
outfile = fopen(outfile_name, "w");
|
|
|
|
if (!infile || !outfile) {
|
|
|
|
printf("can't open in/out files\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-04-23 13:42:32 +02:00
|
|
|
}
|
2018-04-26 11:17:55 +02:00
|
|
|
|
2019-10-30 22:54:12 +01:00
|
|
|
int is_tty = isatty(fileno(infile));
|
2020-03-09 22:03:57 +01:00
|
|
|
char **argv = (char**)malloc(sizeof(char*) * (MAX_COMMAND_ARGS + 1));
|
2019-10-30 22:54:12 +01:00
|
|
|
while(next_line(infile, is_tty)) {
|
2019-10-28 04:10:38 +01:00
|
|
|
if (cmd_buf[0] == '#' || cmd_buf[0] == '\n') {
|
|
|
|
printf("%s", cmd_buf);
|
|
|
|
continue;
|
|
|
|
}
|
2019-10-25 03:48:13 +02:00
|
|
|
if (cmd_buf[0] == 'X') break;
|
2018-04-26 15:07:34 +02:00
|
|
|
if (!is_tty) {
|
|
|
|
prompt();
|
2018-05-19 17:48:10 +02:00
|
|
|
printf("%s", cmd_buf);
|
2019-10-30 22:54:12 +01:00
|
|
|
fflush(outfile);
|
2018-04-26 15:07:34 +02:00
|
|
|
}
|
2020-03-09 22:03:57 +01:00
|
|
|
int argc = split_args(cmd_buf, argv);
|
2019-10-25 03:48:13 +02:00
|
|
|
func_table_t *ft;
|
|
|
|
for (ft = funcs; ft->name != NULL; ft++) {
|
2020-03-09 22:03:57 +01:00
|
|
|
if (!strcmp(argv[0], ft->name)) {
|
2018-04-26 11:17:55 +02:00
|
|
|
break;
|
2017-11-02 21:41:11 +01:00
|
|
|
}
|
2018-04-26 11:17:55 +02:00
|
|
|
}
|
2019-10-25 03:48:13 +02:00
|
|
|
if (ft->name) {
|
2020-03-09 22:03:57 +01:00
|
|
|
ft->func(argc, argv);
|
2019-10-25 03:48:13 +02:00
|
|
|
} else {
|
2020-03-09 22:03:57 +01:00
|
|
|
printf("unknown command: %s\n", argv[0]);
|
2017-10-18 22:19:53 +02:00
|
|
|
}
|
|
|
|
}
|
2020-03-09 22:03:57 +01:00
|
|
|
free(argv);
|
2019-10-09 01:35:47 +02:00
|
|
|
|
2019-10-30 22:54:12 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2020-03-08 03:02:53 +01:00
|
|
|
const char *usage = \
|
|
|
|
"usage: umka_shell [test_file.t] [-c]\n"
|
2020-03-09 22:03:57 +01:00
|
|
|
" -c collect coverage";
|
2020-03-08 03:02:53 +01:00
|
|
|
const char *test_file = NULL;
|
|
|
|
|
|
|
|
int opt;
|
|
|
|
optind = 1;
|
|
|
|
if (argc > 1 && *argv[optind] != '-') {
|
|
|
|
test_file = argv[optind++];
|
|
|
|
}
|
|
|
|
while ((opt = getopt(argc, argv, "c")) != -1) {
|
|
|
|
switch (opt) {
|
|
|
|
case 'c':
|
2020-03-09 22:03:57 +01:00
|
|
|
coverage = 1;
|
2020-03-08 03:02:53 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
puts(usage);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
if (coverage)
|
2019-10-30 22:54:12 +01:00
|
|
|
trace_begin();
|
2020-03-09 22:03:57 +01:00
|
|
|
|
|
|
|
COVERAGE_ON();
|
2019-10-30 22:54:12 +01:00
|
|
|
kos_init();
|
2020-03-09 22:03:57 +01:00
|
|
|
COVERAGE_OFF();
|
2019-10-30 22:54:12 +01:00
|
|
|
|
2020-03-08 03:02:53 +01:00
|
|
|
run_test(test_file);
|
2019-10-30 22:54:12 +01:00
|
|
|
|
2020-03-09 22:03:57 +01:00
|
|
|
if (coverage)
|
2019-10-30 22:54:12 +01:00
|
|
|
trace_end();
|
|
|
|
|
2017-10-18 22:19:53 +02:00
|
|
|
return 0;
|
|
|
|
}
|