1 /* @(#)fstream.h 1.19 18/10/07 Copyright 1985-2018 J. Schilling */ 2 /* 3 * Definitions for the file stream package 4 * 5 * Copyright (c) 1985-2018 J. Schilling 6 */ 7 /* 8 * The contents of this file are subject to the terms of the 9 * Common Development and Distribution License, Version 1.0 only 10 * (the "License"). You may not use this file except in compliance 11 * with the License. 12 * 13 * See the file CDDL.Schily.txt in this distribution for details. 14 * A copy of the CDDL is also available via the Internet at 15 * http://www.opensource.org/licenses/cddl1.txt 16 * 17 * When distributing Covered Code, include this CDDL HEADER in each 18 * file and include the License file CDDL.Schily.txt from this distribution. 19 */ 20 21 #ifndef _SCHILY_FSTREAM_H 22 #define _SCHILY_FSTREAM_H 23 24 #ifndef _SCHILY_MCONFIG_H 25 #include <schily/mconfig.h> 26 #endif 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 #define STR_SBUF_SIZE 127 /* Size of "static" stream buffer */ 33 34 #ifdef WSTRINGS 35 typedef short CHAR; 36 #else 37 typedef char CHAR; 38 #endif 39 40 /* 41 * The stream filter structure. 42 * 43 * If the filter function (*fstr_func)() is a NULL pointer, then fstr_file is 44 * a FILE * object and input is read from that FILE * by calling the read 45 * function (*fstr_rfunc)(). 46 * 47 * If the filter function (*fstr_func)() is not a NULL pointer, then fstr_file 48 * is a stream * object and input is read from that stream object by calling 49 * the filter function (*fstr_func)(). 50 * 51 * The two callback functions have the following tasks: 52 * 53 * (*fstr_func)(ostream, istream) filters from istream to ostream 54 * (*fstr_rfunc)(istream) reads a new input from is->fstr_file 55 * 56 * As long as fstr_bp points to a non-null character, this character is 57 * returned. If the local buffer is empty, the functions are checked: 58 * 59 * If (*fstr_func)() is not a NULL pointer, then it is a filter function 60 * that is called whenever fstr_buf is empty. 61 * 62 * If (*fstr_func)() is a NULL pointer and (*fstr_rfunc)() is not a NULL pointer 63 * then (*fstr_rfunc)() is called to fill the buffer and to return the first 64 * charcter from the buffer. 65 */ 66 typedef struct fstream fstream; 67 68 struct fstream { 69 FILE *fstr_file; /* The input FILE * or input fstream * */ 70 int fstr_flags; /* Flags available for the caller */ 71 /* End of the public part of the structure */ 72 fstream *fstr_pushed; /* Chain of pushed strcutures */ 73 CHAR *fstr_bp; /* The current pointer to coocked input */ 74 CHAR *fstr_buf; /* The current buffer for coocked input */ 75 int (*fstr_func) __PR((struct fstream *__out, FILE *__in)); 76 int (*fstr_rfunc) __PR((struct fstream *__in)); 77 void *fstr_auxp; /* Aux pointer e.g. to detect alias loops */ 78 CHAR fstr_sbuf[STR_SBUF_SIZE + 1]; 79 }; 80 81 typedef int (*fstr_fun) __PR((struct fstream *, FILE *)); 82 typedef int (*fstr_efun) __PR((char *)); 83 typedef int (*fstr_rfun) __PR((struct fstream *)); 84 85 extern fstream *mkfstream __PR((FILE *f, fstr_fun, fstr_rfun, fstr_efun)); 86 extern fstream *fspush __PR((fstream *fsp, fstr_efun efun)); 87 extern fstream *fspop __PR((fstream *fsp)); 88 extern fstream *fspushed __PR((fstream *fsp)); 89 extern void fsclose __PR((fstream *fsp)); 90 extern FILE *fssetfile __PR((fstream *fsp, FILE *f)); 91 extern int fsgetc __PR((fstream *fsp)); 92 extern size_t fsgetlen __PR((fstream *fsp)); 93 extern void fspushstr __PR((fstream *fsp, char *ss)); 94 extern void fspushcha __PR((fstream *fsp, int c)); 95 96 #ifdef __cplusplus 97 } 98 #endif 99 100 #endif /* _SCHILY_FSTREAM_H */ 101