Programming Assignment

A Place For Programmers Of All Levels To Discuss Programming & Web Building.

Moderator: Community Moderator

Post Reply
wogpk
Soldier First Class
Soldier First Class
Posts: 2
Joined: 18 May 2010, 07:39

Programming Assignment

Post by wogpk »

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
Spoiler: show
Marks will be awarded for programs that successfully implement the following
features. The mark value for each feature is given at the right.
Read a full line of text from the user (1)
Detect exit as rst word (1)
break line into words (1)
Appropriate test of fork() return value (1)
Correct process handles new task (1)
Appropriate choice of exec() family member (1)
Correct usage of exec() member (1)
Correct use of wait() (1)
Printing the exit status (1)
Working cd implementation (1)
each mark is given for a correctly working function.
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.

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 ;
}
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.
Last edited by wogpk on 02 Apr 2011, 05:50, edited 1 time in total.
User avatar
MrNiitriiX
Premium Uploader
Premium Uploader
Posts: 2197
Joined: 19 Apr 2010, 14:52
Location: between space and time
Has thanked: 24 times
Been thanked: 164 times

Re: Programming Assignment

Post by MrNiitriiX »

well i dont realy understand the question. but in the sample "code" you got stuff that needs to be in what ever you got to do.

as an example:
# include < stdlib .h> means you have to include "stdlib .h" which has a few functions such as dynamic memory management, etc.

if your not sure what all the "include codes" mean just google them. and reread the notes u made during your course...you should have gone through them all during class. then just make what is asked...
can't help you more then that as it is your learning curv.

**edit**
the best thing you can do is read the notes you made during class ! trust
Last edited by MrNiitriiX on 31 May 2011, 04:26, edited 1 time in total.
"Injustice anywhere is a threat to justice everywhere." - Martin Luther King
Image
Upload List
User avatar
ChetanG
Premium User
Premium User
Posts: 3170
Joined: 15 Oct 2009, 16:57
Location: Under the Lotus Feet of my Guru
Has thanked: 11 times
Been thanked: 19 times

Re: Programming Assignment

Post by ChetanG »

In this workshop you will implement a simple command language interpreter.
Your instructor is having you implement a C.L.I. or shell which is the same thing as a DOS window or command interpreter.

Although the Linux/Unix Shell is much more elegant, powerful and predates DOS by over a decade.


This is the framework given you that implements the shell/C.L.I.
Your instructor is quite clear of what you must do. Start with what seems easiest for you in the spoiler you supplied that shows what your CLI must be able to do...

He shows you where YOU must add the working code to finish the Shell.
Like portzero says you can google the answer or at least get great ideas how to finish this.
Also, do you know how to compile and execute this code of yours when ready?
Linux is the correct OS to learn C/C++ Perl and the others but has a bit of a learning curve.
Good Luck!!
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 ;
}
" Pray: Let the music of peace and harmony be heard everywhere. — Amma "
Post Reply

Return to “Programming/Web Building Chat & Support”