Programming Assignment
Posted: 02 Apr 2011, 05:49
I got this assignment around 1 week ago and still can't get anywhere with it.
So far i have installed ubuntu Linux in order to check if what im doing is right.
Instructions
A shell is a piece of software that provides an interface for users to an operating
system shell which provides access to the services of a kernel. In this workshop
you will implement a simple command language interpreter.
Marking Scheme
and this is the sample code i was given to start me off
Sample Code
Please note that " " indicates a string containing a space character.
Can anyone provide help with getting these functions working, or direction into already working functions that send the commands, that i can use as an example to implement them into my version.
So far i have installed ubuntu Linux in order to check if what im doing is right.
Instructions
A shell is a piece of software that provides an interface for users to an operating
system shell which provides access to the services of a kernel. In this workshop
you will implement a simple command language interpreter.
Marking Scheme
Spoiler: show
Sample Code
Please note that " " indicates a string containing a space character.
Code: Select all
# include < stdlib .h>
# include < stdio .h>
# include < string .h>
# include <sys/ types .h>
# include <sys/ wait .h>
# include < unistd .h>
# include < errno .h>
# define MAX_LINE 4096
# define MAX_WORDS MAX_LINE /2
/* a line can have at most MAX_LINE /2 words ! */
void tokenize ( char *line , char ** words , int * nwords );
/* break line into words separated by whitespace , placing them in the
array words , and setting the count to nwords , doesnt handle quoted
strings so no spaces in names as "cd" builtin only uses words [1]!!!
*/
main ()
{
char line [ MAX_LINE ], * words [ MAX_WORDS ], message [ MAX_LINE ];
int stop =0, nwords =0;
while (1)
{
printf ("WS B Shell $ ");
if( NULL == fgets (line , MAX_LINE , stdin ))
return 0;
tokenize (line ,words ,& nwords );
/* More to do here */
}
}
void tokenize ( char *line , char ** words , int * nwords )
{
* nwords =1;
for( words [0]= strtok (line ," \t\n");
(* nwords < MAX_WORDS )&&( words [* nwords ]= strtok (NULL , " \t\n"));
* nwords =* nwords +1);
return ;
}