Page 2 of 2

Re: Best way of making a shell

Posted: Sat Jun 01, 2013 5:13 am
by iansjack
I assure you I didn't get my reward checks without doing it.
A notable achievement I'm sure, but let's use facts rather than achievements to back up arguments.

You certainly can implement a queue with a linked list (but that is not the only possible implementation - you could implement a queue using an array if you chose to). That doesn't mean that a linked list is equivalent to a queue. Those who use, for example, FIFO queues in their programs would probably not impressed by your pettifogging. If it pleases you then by all means please yourself.

Enough of this silly diversion I think.

Re: Best way of making a shell

Posted: Sat Jun 01, 2013 5:29 am
by dozniak
Love4Boobies wrote:It's hardly entertaining if you didn't get the joke.
I did, I did, thanks.

Re: Best way of making a shell

Posted: Sat Jun 01, 2013 6:05 am
by computertrick
sortie wrote:The best way of making a shell is writing a lexer and a parser that generates an abstract syntax tree representing the commands that user want executed. This is trivial for a shell that only understands 'foo bar baz' commands, but things get more complicated if you add environmental variables, escape characters, quotes, pipes, conditionals, and all the other good shell features. Depending on your shell language, another approach may be better, but lexer+parser is a good and well-understood solution for parsing context-free programming languages.

Why use a stack as a stack? Just allocate 256 characters as a string and fill it up from the start using user-input. When it fills up completely, you reallocate and double its size and then continue. When you encounter a newline, you discard that character, put in a '\0' that terminates the string and call execute_a_shell_command(const char*). Voila!
My operating system is written entirely in assembly so the best approach would be doing something like this ?

Code: Select all

STRING db 0x00
And then using SI register to act as a pointer?

Re: Best way of making a shell

Posted: Sat Jun 01, 2013 8:47 am
by sortie
I suggest you learn your programming language (in this case assembler). Once you know it, it should be easy to do what you are asking.

Re: Best way of making a shell

Posted: Sat Jun 01, 2013 3:07 pm
by Love4Boobies
iansjack wrote:You certainly can implement a queue with a linked list (but that is not the only possible implementation - you could implement a queue using an array if you chose to). That doesn't mean that a linked list is equivalent to a queue. Those who use, for example, FIFO queues in their programs would probably not impressed by your pettifogging. If it pleases you then by all means please yourself.
You missed the point. I never claimed linked lists were the only possible implementation (I even used the word "usually" to suggest the contrary). A data structure is a pattern of data organization---it is already an implementation. ADT's are defined by their semantics.

Re: Best way of making a shell

Posted: Sat Jun 01, 2013 3:22 pm
by computertrick
This is the final way i came up with

Code: Select all

	BITS 16
	ORG 0

start:
	cli
	mov ax, cs
	mov ds, ax
	mov es, ax
	sti

setup_str:
	mov si, STRING	; Clean up STRING 
	mov cl, 20	; 20 bytes 
	call clean
keypress:

	mov ah, 00h	; Check for key press
	int 16h
	cmp al, 13	; Enter pressed?
	je execute	; Then execute command
	mov ah, 0eh
	int 10h
	mov byte [si], al
	lodsb
	jmp keypress
execute:
	mov si, STRING	; Print out string
	call print	
	jmp setup_str	; Reset String

print:
	pusha
	mov ah, 0eh
.repeat:
	lodsb
	cmp al, 0
	je .done
	int 10h
	jmp .repeat
.done:
	popa
	ret

clean:
	pusha
.repeat:	
	cmp cl, 0
	je .done
	mov byte [si], 0
	dec cl
	lodsb
	jmp .repeat
.done:
	mov si, STRING
	popa
	ret
	
; Variables

STRING times 20 db 0 ; Allocate 20 bytes for input string
CHAR_COUNT DB 0
How did i do? can anyone think of a better way

also the shell isn't complete this is just my example of how I am storing the users commands