53 lines
1.2 KiB
C
53 lines
1.2 KiB
C
#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;
|
|
char *in;
|
|
char *out;
|
|
} Chain;
|
|
|
|
|
|
void freeCommand(Command cmd);
|
|
void freeChain(Chain chain);
|
|
|
|
Command buildCommand(List *lp);
|
|
void addRedirect(List *lp, Chain *chain);
|
|
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
|