User Tools

Site Tools


user:abrunda1:portfolio:gnush

Project: My GNU shell program

A project for SYSPROG by Andrew Brundage during the Fall 2011.

Objectives

State the purpose of this project. What is the point of this project? What do we hope to accomplish by undertaking it?

To create my own shell environment of my very own though it still needs 
quite a bit of work to get more functionality for it but other than that
it seems to run pretty good considering you currently can't change 
directories and for some strange reason it will not display the hostname
correctly is says "(null)"

Prerequisites

In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved:

  • fork
  • system calls
  • switch/case
  • command line arguments

Background

State the idea or purpose of the project. What are you attempting to pursue?

Upon approval, you'll want to fill this section out with more detailed background information. DO NOT JUST PROVIDE A LINK.

Providing any links to original source material, such as from a project page, is a good idea.

You'll want to give a general overview of what is going to be accomplished (for example, if your project is about installing a web server, do a little write-up on web servers. What is it, why do we need one, how does it work, etc.)

Attributes

State and justify the attributes you'd like to receive upon successful approval and completion of this project.

  • fork
  • system calls
  • switch/case
  • command line arguments

Code

forky.c

#include "standard.h"
int Forky(char *tmp)
{
	int i;
	if(fork() == 0)
	{
		i = system(tmp);
		if(i < 0)
		{
			printf("%s: %s\n", tmp, "command not found");
			exit(1);
		}
		else
		{
			wait(NULL);
			Prompt();
		}
	}
}

initloop.c

#include "standard.h"
//#include <curses.h>
int InitLoop()
{
 
	char *tmpargs = (char *) malloc(sizeof(char) * 100);
	char c;
	Prompt();
	while(c != EOF)
	{
		c = getchar();
		switch(c)
		{
			case '\n':
				if(tmpargs[0] == '\0')
				{
					Prompt();
				}
				else
				{
					// blah
					//printf("%s",tmpargs);
					Forky(tmpargs);
				}
				bzero(tmpargs, 100);
				break;
 
			/*case KEY_LEFT:
				break;
			case KEY_RIGHT:
				break;
			case KEY_DOWN:
				break;
			case KEY_UP:
				break;*/
 
			default:
				strncat(tmpargs, &c, 1);
				break;
		}
	}
}

main.c

#include "standard.h"
 
int main(int argc, char **argv)
{
	return Runtime(argc, argv);
}

prompt.c

#include "standard.h"
 
void Prompt()
{
	char *u = getenv("USER");
	char *hostname = getenv("HOSTNAME");
	char *pwd = getenv("PWD");
	printf("%s@%s:%s$ ", u, hostname, pwd);
}

runtime.c

#include "standard.h"
 
int Runtime(int argc, char **argv)
{
	if(argc == 1)
	{
		InitLoop();
	}
 
	if(argc >= 2)
	{
		if((strcmp(argv[1],"--version") == 0) || (strcmp(argv[1],"-v") == 0))
		{
			printf("%s version: %s\n", argv[0], VERSION);
			return 0;
		}
		else
		{
			printf("Syntax: gnush [(optional{--version | -v })]\n");
		}
	}
}

Execution

Again, if there is associated code with the project, and you haven't already indicated how to run it, provide a sample run of your code:

andoryuu@andoryuu-laptop:~/src/THORSH$ ./gnush 
andoryuu@(null):/home/andoryuu/src/THORSH$ echo hi
hi
andoryuu@(null):/home/andoryuu/src/THORSH$ ping google.com
PING google.com (209.85.225.103) 56(84) bytes of data.
64 bytes from iy-in-f103.1e100.net (209.85.225.103): icmp_req=1 ttl=51 time=49.6 ms
^C
--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 49.619/49.619/49.619/0.000 ms

andoryuu@(null):/home/andoryuu/src/THORSH$ andoryuu@andoryuu-laptop:~/src/THORSH$ 

Known Bugs/Implementations

  • (null) hostname
  • disable CTRL+C from exitting the program and have it so only CTRL+D/exit exits the program
  • there is no “cd” at the moment

References

In performing this project, the following resources were referenced:

  • URL1
  • URL2
  • URL3 (provides useful information on topic)
  • URL4

Generally, state where you got informative and useful information to help you accomplish this project when you originally worked on it (from Google, other wiki documents on the Lab46 wiki, etc.)

user/abrunda1/portfolio/gnush.txt · Last modified: 2011/12/16 00:53 by abrunda1