Require: #657 ([compare](https://git.kolibrios.org/Egor00f/kolibrios/compare/update-shell-api...shell-api-implement-return-value)) Implement a return value for shell API functions. required for updating libc streams. The return value is declared after `data` for consistency with older programs. # Changes: ## [`shell`](https://git.kolibrios.org/KolibriOS/kolibrios/pulls/660/files#diff-9e9982c0c3e401531fcfbc1f9dd5f1f3d85452fd) + `SHELL_PUTS` and `SHELL_GETS` return the number of bytes written + `SHELL_GETC` write full `int` value ## `libshell` + [`shell_gets`](https://git.kolibrios.org/KolibriOS/kolibrios/pulls/660/files#diff-8840a9f9a5e28f05f5f46e1b5106caf3ce6c470e) returns `NULL` or `EOF`, or a pointer to a string and returns the number of bytes received + [`shell_getc`](https://git.kolibrios.org/KolibriOS/kolibrios/pulls/660/files#diff-955a257b2a02cfc5ee9879b7efc50d0644ad179c) return `int` + [`shell_printf`](https://git.kolibrios.org/KolibriOS/kolibrios/pulls/660/files#diff-4ffb653a63ef098530e336370053615fee66be03) returns the number of bytes written + [`shell_puts`](https://git.kolibrios.org/KolibriOS/kolibrios/pulls/660/files#diff-ee4df9617f16bc52153701c0edc6c2947dd877a8) returns the number of bytes written + [`shell_write_string`](https://git.kolibrios.org/KolibriOS/kolibrios/pulls/660/files#diff-cebe23f17158adc73d20c5f9096862c209732598) returns the number of bytes written Reviewed-on: https://git.kolibrios.org/KolibriOS/kolibrios/pulls/660 Reviewed-by: Kiril Lipatov <lipatov.kiril@gmail.com>
97 lines
2.3 KiB
C
97 lines
2.3 KiB
C
#include <shell_api.h>
|
|
|
|
|
|
int program_console(int pid) {
|
|
char name[32];
|
|
struct shell_shm_buffer *buffer;
|
|
char *buf1k;
|
|
int result;
|
|
int i;
|
|
char command;
|
|
int size;
|
|
int is_end;
|
|
|
|
itoa(pid, name);
|
|
strcat(name, "-SHELL");
|
|
|
|
buffer = NULL;
|
|
buf1k = NULL;
|
|
|
|
for (i = 0; i < 30; i++) {
|
|
result = kol_buffer_open(name, SHM_OPEN | SHM_WRITE, 0, &buffer);
|
|
if (buffer != NULL)
|
|
break;
|
|
|
|
kol_sleep(2);
|
|
}
|
|
|
|
if (buffer == NULL)
|
|
return 0;
|
|
else
|
|
size = result;
|
|
|
|
is_end = 0;
|
|
for (;;) {
|
|
command = buffer->cmd;
|
|
|
|
switch (command) {
|
|
case SHELL_EXIT:
|
|
buffer->cmd = SHELL_OK;
|
|
is_end = 1;
|
|
break;
|
|
|
|
case SHELL_OK:
|
|
kol_sleep(5);
|
|
break;
|
|
|
|
case SHELL_CLS:
|
|
con_cls();
|
|
buffer->cmd = SHELL_OK;
|
|
break;
|
|
|
|
case SHELL_PUTC:
|
|
printf("%c", buffer->data[0]);
|
|
buffer->cmd = SHELL_OK;
|
|
break;
|
|
|
|
case SHELL_PUTS:
|
|
buffer->return_value.written_bytes = printf("%s", &buffer->data );
|
|
buffer->cmd = SHELL_OK;
|
|
break;
|
|
|
|
case SHELL_GETC:
|
|
*((int *)buffer->data) = getch();
|
|
buffer->cmd = SHELL_OK;
|
|
break;
|
|
|
|
case SHELL_GETS:
|
|
buffer->return_value.str = gets(buffer->data, size - 2);
|
|
buffer->return_value.written_bytes = strlen(buffer->data);
|
|
buffer->cmd = SHELL_OK;
|
|
break;
|
|
|
|
case SHELL_PID:
|
|
buf1k=malloc(1024);
|
|
kol_process_info(-1, buf1k);
|
|
memcpy(buffer->data, buf1k+30, sizeof(unsigned));
|
|
buffer->cmd = SHELL_OK;
|
|
free(buf1k);
|
|
break;
|
|
|
|
case SHELL_PING:
|
|
buffer->cmd = SHELL_OK;
|
|
break;
|
|
|
|
default:
|
|
printf (CON_APP_ERROR);
|
|
return 0;
|
|
};
|
|
if (is_end) {
|
|
printf("\n\r");
|
|
return 1;
|
|
}
|
|
} // for end
|
|
return 9;
|
|
}
|
|
|