assignment 1
This commit is contained in:
49
cmd.h
Normal file
49
cmd.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef CMD_H
|
||||
#define CMD_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "scanner.h"
|
||||
#define INITIAL_ARRAY_SIZE 4
|
||||
|
||||
// models one executable + options
|
||||
// thanks to the use of pointers, not as wasteful of memory as it might at first appear.
|
||||
// this struct makes it much easier to pass a TokenList to an exec() system call.
|
||||
typedef struct Command {
|
||||
char **arguments;
|
||||
char *command;
|
||||
int capacity;
|
||||
int numArguments;
|
||||
} Command;
|
||||
|
||||
// models a list of commands
|
||||
// used to properly handle piping.
|
||||
typedef struct CommandList {
|
||||
Command *commands;
|
||||
int capacity;
|
||||
int numCommands;
|
||||
} CommandList;
|
||||
|
||||
// models one complete chain of numCommands
|
||||
// For lab1, somewhat barebones.
|
||||
// Will be expanded upon when we implement redirection/background processes/piping
|
||||
typedef struct Chain {
|
||||
CommandList commands;
|
||||
bool runInBackground;
|
||||
} Chain;
|
||||
|
||||
|
||||
void freeCommand(Command cmd);
|
||||
void freeChain(Chain chain);
|
||||
|
||||
Command buildCommand(List *lp);
|
||||
Chain buildChain(List *lp);
|
||||
|
||||
void executeChain(Chain chain, int* status);
|
||||
#if EXT_PROMPT
|
||||
bool executeBuiltin(Command cmd, int *status, bool *debug);
|
||||
#else
|
||||
bool executeBuiltin(Command cmd, int *status);
|
||||
#endif
|
||||
|
||||
void printChain(Chain chain);
|
||||
#endif
|
||||
Reference in New Issue
Block a user