/*
 * Shell function declarations.
 *
 * Sander van Veen (6167969) / Taddeus Kroes (6054129).
 * <sandervv@gmail.com>      / <taddeuskroes@hotmail.com>
 */

#include "input.yacc.h"

/*
 * Helper functions for line/column counter manipulation (which are used for the
 * lexer's error reporting).
 */
extern int current_line(void);
extern int current_column(void);
extern void reset_line();
extern void reset_column();

extern int yyparse();

/*
 * Helper functions for shell output messages.
 */
void shell_debug(const char *msg, ...);
void shell_error(const char *msg);
void shell_entry();

/*
 * Singly linked list of arguments.
 */
typedef struct shell_args {
    char *arg;
    struct shell_args *next;
} shell_args;

/*
 * A shell command contains a function identifier and an argument list (list
 * could be empty).
 */
typedef enum {FN_CD, FN_HELP, FN_EXIT, FN_EXEC} shell_func;

typedef struct shell_cmd {
    shell_func func;
    shell_args *args;
} shell_cmd;

/*
 * Helper functions for creating / manipulating argument objects.
 */
void shell_push_args(const char *value);
void shell_append_args(const char *value);
shell_args *shell_pop_args();
void shell_free_args(shell_args *args);

/*
 * Builtin shell commands.
 */
void shell_change_dir(const char *path);
void shell_exit();
void shell_help();
void shell_pipe();
void shell_repeat(int prev);
void shell_exec(shell_args *args);
void shell_exec_process(shell_args *args);

/*
 * Doubly linked list containing all executed commands.
 */
typedef struct shell_history_log {
    shell_cmd *cmd;
    struct shell_history_log *prev;
    struct shell_history_log *next;
} shell_history_log;

/*
 * Shell history manipulation functions.
 */
void shell_history_add(shell_cmd *cmd);
shell_cmd *shell_history_get(int prev);
void shell_history_clear();
void shell_history_append(shell_func type, shell_args *args);

