Author Topic: FiXos, a UNIX-like kernel for fx9860  (Read 18956 times)

0 Members and 1 Guest are viewing this topic.

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: FiXos, a UNIX-like kernel for fx9860
« Reply #30 on: August 02, 2014, 05:22:05 am »
OK I'm officially on the project. Let's see if I can make something like a shell..

EDIT : stupid echo routine
Code: [Select]
static void test_echo(int fdin, int fdout) {
char buffer[33];
ssize_t result = 0;
int index = 0;
char current_char;
while(1){
read(fdin, &current_char, 1);
buffer[index++] = current_char;
if(current_char == '\n' || index == 32) {
result = write(fdout, buffer, index);
if(result != index)
break;
index = 0;
}
}
}
I think I should find a way to cleanly read a whole line of text.
« Last Edit: August 05, 2014, 07:07:06 pm by Eiyeron »

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: FiXos, a UNIX-like kernel for fx9860
« Reply #31 on: October 01, 2014, 02:41:26 pm »
I'm on the rails again as a side side project. I started to parse arguments given from a command line to train my UNIX programming skills. That'll come quite handy for the minishell project i plan to do.

Here's the code atm for anyone who wants to dig into (only for PC as test, I haven't ported it to FiXOS, but that should be easy) :
Code: [Select]
#define _GNU_SOURCE
#include <unistd.h>
#include <string.h>
#define BUFFER_LENGTH 128
#define COMMAND_LIST_SIZE 8
#define COMMAND_SIZE 32

void next_command(char* current_command, int* current_command_index, int* command_index) {
current_command[*current_command_index] = '\0';
*current_command_index = 0;
*command_index += 1;
}

void parse_command(char* buffer, char command_list[COMMAND_LIST_SIZE][COMMAND_SIZE], int buffer_index) {
int command_index = 0;
int current_command_index = 0;
char in_quotes = 0;
char in_double_quotes = 0;
char c;
int i;
for(i = 0; i < buffer_index; i++) {
char *current_command = command_list[command_index];
c = buffer[i];

if(in_quotes) {
if(c == '\'') {
in_quotes = 0;
}
else {
current_command[current_command_index] = c;
current_command_index++;
}
}
else if(in_double_quotes) {
if(c == '"') {
in_double_quotes = 0;
}
else {
current_command[current_command_index] = c;
current_command_index++;
}
}
else {
if(c == '"' || c == '\'') {
if(current_command_index > 0) {
next_command(current_command, &current_command_index, &command_index);
}
if(c == '"')
in_double_quotes = 1;
else
in_quotes = 1;
}
else if(c == ' ' && current_command_index > 0) {
next_command(current_command, &current_command_index, &command_index);
}
else {
current_command[current_command_index] = c;
current_command_index++;
}
}

}
next_command(command_list[command_index], &current_command_index, &command_index);

for(i = 0; i < command_index; i++) {
write(1, "=>{", 3);
write(1, &command_list[i], strlen(command_list[i]));
write(1, "}\n", 2);
}
}

int main()
{
char c;
int buffer_index = 0;
char buffer[BUFFER_LENGTH + 1];
char command_list[COMMAND_LIST_SIZE][COMMAND_SIZE];

while(1) {
read(0, &c, 1);
if(c == '\n') {
// TODO : manage command
parse_command(buffer, command_list, buffer_index);
buffer_index = 0;
}
else if(buffer_index <= BUFFER_LENGTH) {
buffer[buffer_index++] = c;
}
}
return 0;
}

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: FiXos, a UNIX-like kernel for fx9860
« Reply #32 on: October 01, 2014, 03:40:42 pm »
Good to hear it's still progressing :)

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: FiXos, a UNIX-like kernel for fx9860
« Reply #33 on: October 02, 2014, 09:18:39 am »

My shell project seems to work. Seems because I don't know if it actually tries to open anything but I get the reply when the program execution failed, so I consider my fork/exec/wait routine working!