Blame snprintfv/stream.h

Packit Service 96b5d3
/*  -*- Mode: C -*-  */
Packit Service 96b5d3
Packit Service 96b5d3
/* stream.h --- customizable stream routines
Packit Service 96b5d3
 * Copyright (C) 1998, 1999, 2000, 2002 Gary V. Vaughan
Packit Service 96b5d3
 * Originally by Gary V. Vaughan, 1998
Packit Service 96b5d3
 * This file is part of Snprintfv
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * Snprintfv is free software; you can redistribute it and/or
Packit Service 96b5d3
 * modify it under the terms of the GNU General Public License as
Packit Service 96b5d3
 * published by the Free Software Foundation; either version 2 of the
Packit Service 96b5d3
 * License, or (at your option) any later version.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * Snprintfv program is distributed in the hope that it will be useful,
Packit Service 96b5d3
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 96b5d3
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 96b5d3
 * General Public License for more details.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * You should have received a copy of the GNU General Public License
Packit Service 96b5d3
 * along with this program.  If not, see <http://www.gnu.org/licenses>.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * As a special exception to the GNU General Public License, if you
Packit Service 96b5d3
 * distribute this file as part of a program that also links with and
Packit Service 96b5d3
 * uses the libopts library from AutoGen, you may include it under
Packit Service 96b5d3
 * the same distribution terms used by the libopts library.
Packit Service 96b5d3
 */
Packit Service 96b5d3
Packit Service 96b5d3
/* Code: */
Packit Service 96b5d3
Packit Service 96b5d3
#ifndef STREAM_H
Packit Service 96b5d3
#define STREAM_H 1
Packit Service 96b5d3
Packit Service 96b5d3
#define STREAM_READABLE		(1 << 0)
Packit Service 96b5d3
#define STREAM_WRITABLE		(1 << 1)
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 * SNV_UNLIMITED:
Packit Service 96b5d3
 * Used to denote that there is no upper limit to the number of characters
Packit Service 96b5d3
 * that can safely be written to a stream.
Packit Service 96b5d3
 **/
Packit Service 96b5d3
#define SNV_UNLIMITED           (~0UL)
Packit Service 96b5d3
Packit Service 96b5d3
#ifdef __cplusplus
Packit Service 96b5d3
extern "C"
Packit Service 96b5d3
{
Packit Service 96b5d3
#if 0
Packit Service 96b5d3
/* This brace is so that emacs can still indent properly: */ }
Packit Service 96b5d3
#endif
Packit Service 96b5d3
#endif				/* __cplusplus */
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 * STREAM:
Packit Service 96b5d3
 * Data type used to pass details of streams between functions,
Packit Service 96b5d3
 * much like stdio's %FILE, but more flexible.  A %STREAM can be uni- or
Packit Service 96b5d3
 * bi-directional depending on how it is initialised.
Packit Service 96b5d3
 **/
Packit Service 96b5d3
typedef struct stream STREAM;
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 * StreamPut:
Packit Service 96b5d3
 * @ch: The character to write to @stream cast to an int.
Packit Service 96b5d3
 * @stream:  The stream being written to.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * Type of the function to put a character in a writeable stream.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * Return value:
Packit Service 96b5d3
 * The function should return the character written to the
Packit Service 96b5d3
 * stream, cast to an int if it was written successfully, or
Packit Service 96b5d3
 * else %EOF, if the write failed.
Packit Service 96b5d3
 **/
Packit Service 96b5d3
typedef int (*StreamPut) (int ch, STREAM * stream);
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 * StreamGet:
Packit Service 96b5d3
 * @stream:  The stream being read from.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * Type of the function to get a character from a readable stream.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * Return value:
Packit Service 96b5d3
 * The function should return the character read from the
Packit Service 96b5d3
 * stream, cast to an int if it was read successfully, or
Packit Service 96b5d3
 * else %EOF, if the read failed.
Packit Service 96b5d3
 **/
Packit Service 96b5d3
typedef int (*StreamGet) (STREAM * stream);
Packit Service 96b5d3
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 * stream_new: constructor
Packit Service 96b5d3
 * @dets: user supplied stream details to be passed into the various funcs.
Packit Service 96b5d3
 * @limit: the maximum number of consecutive bytes to fit in @dets.
Packit Service 96b5d3
 * @get_func: function to get a character from @dets stream.
Packit Service 96b5d3
 * @put_func: function to put a character in @dets stream.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * Allocate and initialize a new %STREAM data type.  The @get_func
Packit Service 96b5d3
 * and @put_func can be NULL if you intend to create a non-readable
Packit Service 96b5d3
 * or non-writable stream, respectively.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * Return value:
Packit Service 96b5d3
 * The address of the newly allocated and initialised stream is returned.
Packit Service 96b5d3
 **/
Packit Service 96b5d3
extern STREAM *
Packit Service 96b5d3
stream_new (snv_pointer dets, unsigned long limit, StreamGet get_func, StreamPut put_func);
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 * stream_delete: destructor
Packit Service 96b5d3
 * @stream: The stream pending deletion
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * The memory associated with @stream is recycled.
Packit Service 96b5d3
Packit Service 96b5d3
 * Return value:
Packit Service 96b5d3
 * The %dets supplied by the user when the stream was created are
Packit Service 96b5d3
 * returned for handling by the calling function.
Packit Service 96b5d3
 **/
Packit Service 96b5d3
extern snv_pointer
Packit Service 96b5d3
stream_delete (STREAM *stream);
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 * stream_details:
Packit Service 96b5d3
 * @stream: the stream being queried.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * The finalization function specified when @stream was created (if any)
Packit Service 96b5d3
 * is called, and then the memory associated with @stream is recycled.
Packit Service 96b5d3
 * It is the responsibility of the finalization function to recycle, or
Packit Service 96b5d3
 * otherwise manage, any memory associated with the user supplied %dets.
Packit Service 96b5d3
 * Return value:
Packit Service 96b5d3
 * This function returns the stream details associated with @stream
Packit Service 96b5d3
 * when it was originally created.
Packit Service 96b5d3
 **/
Packit Service 96b5d3
extern snv_pointer
Packit Service 96b5d3
stream_details (STREAM *stream);
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 * stream_put:
Packit Service 96b5d3
 * @ch: A single character to be placed in @stream.
Packit Service 96b5d3
 * @stream: The stream to be written to.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * This function will @ch in @stream if that stream's output limit will
Packit Service 96b5d3
 * not be exceeded.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * Return value:
Packit Service 96b5d3
 * If @stream is full, return 1.  Otherwise, if any other error occurs,
Packit Service 96b5d3
 * that error code is returned unchanged.  This is of course dependant
Packit Service 96b5d3
 * on what the handler function uses to indicate an error.  If the stream
Packit Service 96b5d3
 * is not full and the stream's writing function succeeds, 1 (the number of
Packit Service 96b5d3
 * characters emitted!) is returned.
Packit Service 96b5d3
 **/
Packit Service 96b5d3
extern int
Packit Service 96b5d3
stream_put (int ch, STREAM *stream);
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 * stream_puts:
Packit Service 96b5d3
 * @s: A string to be placed in @stream.
Packit Service 96b5d3
 * @stream: The stream to be written to.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * This function will @ch in @stream if that stream's output limit will
Packit Service 96b5d3
 * not be exceeded.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * Return value:
Packit Service 96b5d3
 * If any other error occurs, that error code is returned unchanged.
Packit Service 96b5d3
 * This is of course dependant on what the handler function uses to
Packit Service 96b5d3
 * indicate an error.  If the stream becomes full, the remaining
Packit Service 96b5d3
 * characters are not printed.  If the stream's writing function
Packit Service 96b5d3
 * always succeeds, the number of characters emitted or skipped is
Packit Service 96b5d3
 * returned.
Packit Service 96b5d3
 **/
Packit Service 96b5d3
extern int
Packit Service 96b5d3
stream_puts (char *s, STREAM *stream);
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 * stream_get:
Packit Service 96b5d3
 * @stream: The stream to be read from.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * This function will try to read a single character from @stream.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * Return value:
Packit Service 96b5d3
 * If an error occurs or the end of @stream is reached, -1 is returned.
Packit Service 96b5d3
 * Under normal circumstances the value if the character read (cast to
Packit Service 96b5d3
 * an int) is returned.
Packit Service 96b5d3
 **/
Packit Service 96b5d3
extern int
Packit Service 96b5d3
stream_get (STREAM *stream);
Packit Service 96b5d3
Packit Service 96b5d3
#line 87 "stream.in"
Packit Service 96b5d3
#ifdef __cplusplus
Packit Service 96b5d3
#if 0
Packit Service 96b5d3
/* This brace is so that emacs can still indent properly: */
Packit Service 96b5d3
{
Packit Service 96b5d3
#endif
Packit Service 96b5d3
}
Packit Service 96b5d3
#endif /* __cplusplus */
Packit Service 96b5d3
Packit Service 96b5d3
#endif /* STREAM_H */