File Mainc Author Stephen Brennan Date Thursday 8 January 2015 Brief Lsh Libstephen Shell Q37079141

/***************************************************************************//**
@file main.c
@author Stephen Brennan
@date Thursday, 8 January 2015
@brief LSH (Libstephen SHell)
*******************************************************************************/

#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

/*
Function Declarations for builtin shell commands:
*/
int lsh_cd(char **args);
int lsh_help(char **args);
int lsh_exit(char **args);

/*
List of builtin commands, followed by their correspondingfunctions.
*/
char *builtin_str[] = {
“cd”,
“help”,
“exit”
};

int (*builtin_func[]) (char **) = {
&lsh_cd,
&lsh_help,
&lsh_exit
};

int lsh_num_builtins() {
return sizeof(builtin_str) / sizeof(char *);
}

/*
Builtin function implementations.
*/

/**
@brief Bultin command: change directory.
@param args List of args. args[0] is “cd”. args[1] is thedirectory.
@return Always returns 1, to continue executing.
*/
int lsh_cd(char **args)
{
if (args[1] == NULL) {
fprintf(stderr, “lsh: expected argument to “cd”n”);
} else {
if (chdir(args[1]) != 0) {
perror(“lsh”);
}
}
return 1;
}

/**
@brief Builtin command: print help.
@param args List of args. Not examined.
@return Always

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.