Main Page
Related Pages
Data Structures
Files
File List
Globals
src
libgfsm
gfsmIO.h
Go to the documentation of this file.
1
/*=============================================================================*\
2
* File: gfsmIO.h
3
* Author: Bryan Jurish <moocow.bovine@gmail.com>
4
* Description: finite state machine library: I/O
5
*
6
* Copyright (c) 2006-2008 Bryan Jurish.
7
*
8
* For information on usage and redistribution, and for a DISCLAIMER
9
* OF ALL WARRANTIES, see the file "COPYING" in this distribution.
10
*
11
* This library is free software; you can redistribute it and/or
12
* modify it under the terms of the GNU Lesser General Public
13
* License as published by the Free Software Foundation; either
14
* version 3 of the License, or (at your option) any later version.
15
*
16
* This library is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
* Lesser General Public License for more details.
20
*
21
* You should have received a copy of the GNU Lesser General Public
22
* License along with this library; if not, write to the Free Software
23
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
*=============================================================================*/
25
30
#ifndef _GFSM_IO_H
31
#define _GFSM_IO_H
32
33
#include <
gfsmConfig.h
>
34
#include <
gfsmError.h
>
35
36
#include <stdarg.h>
37
#include <string.h>
38
#include <unistd.h>
39
#include <stdio.h>
40
41
#define GFSMIO_EOF ((int)-1)
42
43
/*======================================================================
44
* I/O: types
45
*/
46
48
typedef
enum
{
49
gfsmIOTCFile
,
50
gfsmIOTZFile
,
51
gfsmIOTGString
,
52
gfsmIOTUser
= 255
53
}
gfsmIOHandleType
;
54
55
/*======================================================================
56
* I/O: Handles: Function types
57
*/
58
60
typedef
void (*
gfsmIOFlushFunc
) (
void
*handle);
61
63
typedef
void (*
gfsmIOCloseFunc
) (
void
*handle);
64
66
typedef
gboolean (*
gfsmIOEofFunc
) (
void
*handle);
67
68
70
typedef
gboolean (*
gfsmIOReadFunc
) (
void
*handle,
void
*buf,
size_t
nbytes);
71
73
typedef
ssize_t (*
gfsmIOGetdelimFunc
) (
void
*handle,
char
**lineptr,
size_t
*n,
int
delim);
74
75
77
typedef
gboolean (*
gfsmIOWriteFunc
) (
void
*handle,
const
void
*buf,
size_t
nbytes);
78
80
typedef
int (*
gfsmIOVprintfFunc
) (
void
*handle,
const
char
*fmt, va_list *app);
81
82
83
84
/*======================================================================
85
* I/O: Handles: structs
86
*/
87
89
typedef
struct
{
90
gfsmIOHandleType
iotype
;
91
void
*
handle
;
92
93
gfsmIOReadFunc
read_func
;
94
gfsmIOGetdelimFunc
getdelim_func
;
96
gfsmIOWriteFunc
write_func
;
97
gfsmIOVprintfFunc
vprintf_func
;
99
gfsmIOFlushFunc
flush_func
;
100
gfsmIOCloseFunc
close_func
;
101
gfsmIOEofFunc
eof_func
;
102
}
gfsmIOHandle
;
103
104
106
typedef
struct
{
107
GString *
gs
;
108
size_t
pos
;
109
}
gfsmPosGString
;
110
111
/*======================================================================
112
* I/O: Handles: Constructors etc.
113
*/
114
125
gfsmIOHandle
*
gfsmio_handle_new
(
gfsmIOHandleType
typ,
void
*handle_data);
126
128
void
gfsmio_handle_free
(
gfsmIOHandle
*ioh);
129
130
/* TODO: utilities ? file_handle_new, zfile_handle_new, gstring_handle_new, user_handle_new ? */
131
135
gfsmIOHandle
*
gfsmio_new_file
(FILE *f);
136
141
gfsmIOHandle
*
gfsmio_new_zfile
(FILE *f,
const
char
*mode,
int
compress_level);
142
147
gfsmIOHandle
*
gfsmio_new_filename
(
const
char
*filename,
const
char
*mode,
int
compress_level,
gfsmError
**errp);
148
152
gfsmIOHandle
*
gfsmio_new_gstring
(
gfsmPosGString
*pgs);
153
154
/*======================================================================
155
* I/O: Handles: Methods: Basic
156
*/
157
159
void
gfsmio_close
(
gfsmIOHandle
*ioh);
160
162
void
gfsmio_flush
(
gfsmIOHandle
*ioh);
163
165
gboolean
gfsmio_eof
(
gfsmIOHandle
*ioh);
166
167
168
169
/*======================================================================
170
* I/O: Handles: Methods: Read
171
*/
172
174
int
gfsmio_getc
(
gfsmIOHandle
*ioh);
175
177
gboolean
gfsmio_read
(
gfsmIOHandle
*ioh,
void
*buf,
size_t
nbytes);
178
180
ssize_t
gfsmio_getline
(
gfsmIOHandle
*ioh,
char
**lineptr,
size_t
*n);
181
182
184
ssize_t
gfsmio_getdelim
(
gfsmIOHandle
*io,
char
**lineptr,
size_t
*n,
int
delim);
185
186
187
188
/*======================================================================
189
* I/O: Handles: Methods: Write
190
*/
191
193
gboolean
gfsmio_putc
(
gfsmIOHandle
*ioh,
int
c);
194
196
gboolean
gfsmio_puts
(
gfsmIOHandle
*io,
const
char
*s);
197
199
gboolean
gfsmio_write
(
gfsmIOHandle
*io,
const
void
*buf,
size_t
nbytes);
200
202
int
gfsmio_printf
(
gfsmIOHandle
*io,
const
char
*fmt, ...);
203
205
int
gfsmio_vprintf
(
gfsmIOHandle
*io,
const
char
*fmt, va_list *app);
206
207
208
#endif
/* _GFSM_IO_H */
Generated on Tue Oct 21 2014 09:44:47 for libgfsm by
1.8.1.2