///
///  @file    file.h
///  @brief   Header file for TECO file functions.
///
///  @copyright 2019-2023 Franklin P. Johnston / Nowwith Treble Software
///
///  Permission is hereby granted, free of charge, to any person obtaining a
///  copy of this software and associated documentation files (the "Software"),
///  to deal in the Software without restriction, including without limitation
///  the rights to use, copy, modify, merge, publish, distribute, sublicense,
///  and/or sell copies of the Software, and to permit persons to whom the
///  Software is furnished to do so, subject to the following conditions:
///
///  The above copyright notice and this permission notice shall be included in
///  all copies or substantial portions of the Software.
///
///  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
///  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
///  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
///  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIA-
///  BILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
///  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
///  THE SOFTWARE.
///
////////////////////////////////////////////////////////////////////////////////

#if     !defined(_FILE_H)

#define _FILE_H

#include <stdbool.h>


///  @enum    itype
///  @brief   Definition of input file stream types.

enum itype
{
    IFILE_PRIMARY,                  ///< Primary input stream
    IFILE_SECONDARY,                ///< Secondary input stream
    IFILE_QREGISTER,                ///< EQ input stream
    IFILE_INDIRECT,                 ///< EI command stream
    IFILE_MAX                       ///< Maximum input files
};

///  @enum    otype
///  @brief   Definition of output file stream types.

enum otype
{
    OFILE_PRIMARY,                  ///< Primary output stream
    OFILE_SECONDARY,                ///< Secondary output stream
    OFILE_QREGISTER,                ///< E%q command stream
    OFILE_LOG,                      ///< EL log file
    OFILE_MAX                       ///< Maximum output files
};

// Global variables

extern struct ifile ifiles[];

extern struct ofile ofiles[];

extern uint istream;

extern uint ostream;

extern char last_file[];

// File functions

extern void close_input(uint stream);

extern void close_output(uint stream);

extern struct ifile *find_command(const char *name, uint stream, bool colon);

extern int get_wild(void);

extern char *init_filename(const char *src, uint_t len, bool colon);

extern struct ifile *open_command(const char *name, uint stream, bool colon, uint_t *size);

extern struct ifile *open_input(const char *name, uint stream, bool colon);

extern struct ofile *open_output(const char *name, uint stream, bool colon,
                                 int c);

extern FILE *open_temp(const char *oname, uint stream);

extern void read_command(struct ifile *ifile, uint stream, tbuffer *text);

extern bool read_memory(char *p, uint len);

extern void rename_output(struct ofile *ofile);

extern void set_last(const char *name);

extern bool set_wild(const char *filename);

extern void write_memory(const char *file);

#endif  // !defined(_FILE_H)
