Skip to content

proj_shell

Jihun Kim edited this page Mar 29, 2019 · 3 revisions

Overview

Simple shell writed in C.

Structs & Typedefs

Command

A struct representing a single command.
The string stored in cmd is same with that of argv[0].
argv[argc] must point NULL.

struct Command {
    char * cmd;
    char ** argv;
    size_t argc;
    size_t argv_size;
    pid_t pid;
};

CommandVec

vector of Command *.
Last element of CommandVec must point null.

typedef Command ** CommandVec;

Functions

read_line()

reads a single line from infile. The function can read long line.

char * read_line(FILE * infile);

parse_line()

Parse a single line to CommandVec.

CommandVec parse_line(char * line);

Safety

line can be changed while parsing.

parse_command()

Parse given command_string, and convert it to Command. command_string must contain only one command.

Command * parse_command(const char * command_string);

Safety

If command_string is a whitespace string or empty string, return NULL.

exec_commands()

Executes commands in command_vec. If any of command in command_vec, function returns non-zero value.

int exec_commands(const CommandVec command_vec);

free_command_vec()

Helper function for deallocate memory of CommandVec.

void free_command_vec(CommandVec command_vec);