__PREFIX_BEGIN__
//-----------------------------------------------------------------------------
// Copyright © 2003 - Philip Howard - All rights reserved
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//-----------------------------------------------------------------------------
// package	libh/io
// homepage	http://libh.slashusr.org/
//-----------------------------------------------------------------------------
// author	Philip Howard
// email	libh at ipal dot org
// homepage	http://phil.ipal.org/
//-----------------------------------------------------------------------------
// This file is best viewed using a fixed spaced font such as Courier
// and in a display at least 120 columns wide.
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// file		io.h
//-----------------------------------------------------------------------------
#ifndef __IO_H__
#define __IO_H__

__PREFIX_END__

__INCLUDE_BEGIN__
#include <dirent.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <poll.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include <libh/map.h>

__INCLUDE_END__

__DEFINE_BEGIN__
//-----------------------------------------------------------------------------
// struct	get_item_s
// typedef	get_item_t, get_item_p
//
// purpose	Hold the parameters and state for parsing an item stream.
//-----------------------------------------------------------------------------
struct get_item_s {

    unsigned long long		pos_cnt			;
    unsigned long		pos_col			;
    unsigned long		pos_row			;

    unsigned long long		beg_cnt			;
    unsigned long		beg_col			;
    unsigned long		beg_row			;

    unsigned long long		end_cnt			;
    unsigned long		end_col			;
    unsigned long		end_row			;

    //------------------------------------------------
    // Which of these union members is used depends on
    // which input source is designated via getc_p.
    //------------------------------------------------
    union get_item_s_input_sources {
	struct get_item_s_input_sources_fd {
	    size_t		size			;
	    int			fd			;
	}				fd		;

	struct get_item_s_input_sources_file {
	    FILE *		file			;
	}				file		;

	struct get_item_s_input_sources_str {
	    const char *	str			;
	    size_t		len			;
	}				str		;

	struct get_item_s_input_sources_call {
	    int		( *	fun	)(void*)	;
	    void	*	arg			;
	}				call		;
    }						in	;

    int		( *	getc_p	)(struct get_item_s*)	;

    char *		buf_get_p			;
    char *		buf_put_p			;
    char *		buf_end_p			;

    size_t		actual_len			;
    size_t		stored_len			;

    int			opt_hold			;

    int			opt_tab				;
    int			opt_bslash			;
    int			opt_carat			;
    int			opt_colon			;
    int			opt_quote2			;
    int			opt_equal			;
    int			opt_percent			;
    int			opt_quote1			;
    int			opt_hash			;
    int			opt_scolon			;
    int			opt_slash			;
    int			opt_bquote			;

    unsigned char	in_eof				;
    unsigned char	in_error			;
    unsigned char	in_newline			;
    unsigned char	in_comment			;
    unsigned char	in_hold				;

    char		buffer		[3]		;
};

typedef struct get_item_s	get_item_t		;
typedef struct get_item_s *	get_item_p		;

__DEFINE_END__

__SUFFIX_BEGIN__
#endif /* __IO_H__ */
__SUFFIX_END__

