io.h revision f765521f
1/*
2 * Copyright (c) 2002 by The XFree86 Project, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17 * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 *
22 * Except as contained in this notice, the name of the XFree86 Project shall
23 * not be used in advertising or otherwise to promote the sale, use or other
24 * dealings in this Software without prior written authorization from the
25 * XFree86 Project.
26 *
27 * Author: Paulo César Pereira de Andrade
28 */
29
30/* $XFree86: xc/programs/xedit/lisp/io.h,v 1.9tsi Exp $ */
31
32#ifndef Lisp_io_h
33#define Lisp_io_h
34
35#include "lisp/private.h"
36
37#define	FILE_READ	0x01
38#define FILE_WRITE	0x02
39#define FILE_IO		0x03
40#define FILE_APPEND	0x06	/* append mode, write bit also set */
41#define FILE_BUFFERED	0x08	/* force buffered mode */
42#define FILE_UNBUFFERED	0x10	/* force unbuffered mode */
43#define FILE_BINARY	0x20
44
45/*
46 * Types
47 */
48typedef ssize_t (*io_write_fn)(int, const void*, size_t);
49
50struct _LispFile {
51    char *buffer;
52    int line;			/* input line number */
53    int column;			/* output column number */
54    int descriptor;
55    int length;			/* number of bytes used */
56    int offset;			/* read/write offset */
57    int unget : 8;		/* unread char */
58    unsigned int readable : 1;
59    unsigned int writable : 1;
60    unsigned int regular : 1;	/* regular file */
61    unsigned int buffered : 1;
62    unsigned int available : 1;	/* unget field holds a char */
63    unsigned int nonblock : 1;	/* in nonblock mode */
64    unsigned int binary : 1;	/* if set, don't calculate column/line-number */
65    io_write_fn io_write;
66};
67
68struct _LispString {
69    char *string;
70    int line;			/* input line number */
71    int column;			/* output column number */
72    int space;			/* number of bytes alocated */
73    int length;			/* number of bytes used */
74    int input;			/* input offset, for read operations */
75    int output;			/* output offset, for write operations */
76    unsigned int fixed : 1;	/* if set, don't try to reallocate string */
77    unsigned int binary : 1;	/* if set, don't calculate column/line-number */
78};
79
80/*
81 * Prototypes
82 */
83	/* higher level functions */
84int LispGet(void);
85int LispUnget(int);
86void LispPushInput(LispObj*);
87void LispPopInput(LispObj*);
88
89	/* functions that read/write using the LispFile structure */
90LispFile *LispFdopen(int, int);
91LispFile *LispFopen(const char*, int);
92void LispFclose(LispFile*);
93int LispFflush(LispFile*);
94int LispFungetc(LispFile*, int);
95int LispFgetc(LispFile*);
96int LispFputc(LispFile*, int);
97char *LispFgets(LispFile*, char*, int);
98int LispFputs(LispFile*, const char*);
99int LispFread(LispFile*, void*, int);
100int LispFwrite(LispFile*, const void*, int);
101int LispRename(const char*, const char*);
102int LispUnlink(const char*);
103
104	/* io wrappers */
105io_write_fn LispSetFileWrite(LispFile*, io_write_fn);
106
107	/* functions that read/write using the LispString structure */
108int LispSgetc(LispString*);
109int LispSputc(LispString*, int);
110int LispSputs(LispString*, const char*);
111int LispSwrite(LispString*, const void*, int);
112
113const char *LispGetSstring(LispString*, int*);
114
115#endif /* Lisp_io_h */
116