src/shell/shelf.c (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#include "cedos.h"
#include "stdio.h"
#include <stdint.h>
int read_line(char *buffer) {
int i = 0;
char c;
buffer[0] = 0;
while (1) {
c = getchar();
if (c == '\n') { break; }
if (c == 0) { continue; }
if (c == 0x08 && i <= 0) { continue; }
if (c == 0x08) {
buffer[--i] = 0;
putchar(c);
} else {
buffer[i++] = c;
putchar(c);
}
}
buffer[i] = 0;
putchar(c);
return i;
}
void main(char *args) {
uint32_t a = 0, b = 1, i = 0;
printf("\n");
printf("ShELF shell interface for CeDOS\n");
printf("Version: " VERSION "\n");
while (1) {
printf("/> ");
char buffer[256];
int length = read_line(buffer);
if (length == 0) { continue; }
char *file = buffer;
char *args = (char *)(0);
int i = 0;
while (buffer[i]) {
if (buffer[i] == ' ') {
buffer[i] = 0;
args = &(buffer[i+1]);
break;
}
i++;
}
//printf("Executing %s...\n", buffer);
int pid = process_spawn(file, args);
//printf("Child process %i spawned, waiting for termination...\n", pid);
if (pid == -1) {
printf("File not found: %s\n", buffer);
} else {
process_wait(pid);
}
//printf("Child process %i terminated.\n", pid);
}
}