/* Copyright (c) 2018, 2019, 2020, 2022 Dennis Wölfing
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/* sh/sh.h
 * Shell defintions.
 */

#ifndef SH_H
#define SH_H

#include <stdbool.h>
#include <stdnoreturn.h>
#include <sys/types.h>

#define NO_DISCARD __attribute__((warn_unused_result))

struct ShellOptions {
    bool allexport; // unimplemented
    bool errexit; // unimplemented
    bool hashall; // unimplemented
    bool ignoreeof; // unimplemented
    bool monitor;
    bool noclobber;
    bool noexec; // unimplemented
    bool noglob;
    bool nolog; // unimplemented
    bool notify; // unimplemented
    bool nounset; // unimplemented
    bool verbose; // unimplemented
    bool vi; // unimplemented
    bool xtrace; // unimplemented

    bool command;
    bool interactive;
    bool stdInput;
};

extern struct CompleteCommand* currentCommand;
extern bool endOfFileReached;
extern bool inputIsTerminal;
extern int lastStatus;
extern struct ShellOptions shellOptions;
extern pid_t shellPid;

noreturn void executeScript(int argc, char** argv);
bool handleShortOption(bool plusOption, char option);
bool handleLongOption(bool plusOption, const char* option);
void addToArray(void** array, size_t* used, const void* value, size_t size);
void addMultipleToArray(void** array, size_t* used, const void* values,
        size_t size, size_t amount);
NO_DISCARD bool moveFd(int old, int new);
int printPrompt(bool newCommand);
void printQuoted(const char* string);

#endif
