15dfecf96Smrg/*
25dfecf96Smrg * Copyright (c) 2002 by The XFree86 Project, Inc.
35dfecf96Smrg *
45dfecf96Smrg * Permission is hereby granted, free of charge, to any person obtaining a
55dfecf96Smrg * copy of this software and associated documentation files (the "Software"),
65dfecf96Smrg * to deal in the Software without restriction, including without limitation
75dfecf96Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
85dfecf96Smrg * and/or sell copies of the Software, and to permit persons to whom the
95dfecf96Smrg * Software is furnished to do so, subject to the following conditions:
105dfecf96Smrg *
115dfecf96Smrg * The above copyright notice and this permission notice shall be included in
125dfecf96Smrg * all copies or substantial portions of the Software.
135dfecf96Smrg *
145dfecf96Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
155dfecf96Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
165dfecf96Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
175dfecf96Smrg * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
185dfecf96Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
195dfecf96Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
205dfecf96Smrg * SOFTWARE.
215dfecf96Smrg *
225dfecf96Smrg * Except as contained in this notice, the name of the XFree86 Project shall
235dfecf96Smrg * not be used in advertising or otherwise to promote the sale, use or other
245dfecf96Smrg * dealings in this Software without prior written authorization from the
255dfecf96Smrg * XFree86 Project.
265dfecf96Smrg *
275dfecf96Smrg * Author: Paulo César Pereira de Andrade
285dfecf96Smrg */
295dfecf96Smrg
305dfecf96Smrg/* $XFree86: xc/programs/xedit/lisp/io.h,v 1.9tsi Exp $ */
315dfecf96Smrg
325dfecf96Smrg#ifndef Lisp_io_h
335dfecf96Smrg#define Lisp_io_h
345dfecf96Smrg
355dfecf96Smrg#include "lisp/private.h"
365dfecf96Smrg
375dfecf96Smrg#define	FILE_READ	0x01
385dfecf96Smrg#define FILE_WRITE	0x02
395dfecf96Smrg#define FILE_IO		0x03
405dfecf96Smrg#define FILE_APPEND	0x06	/* append mode, write bit also set */
415dfecf96Smrg#define FILE_BUFFERED	0x08	/* force buffered mode */
425dfecf96Smrg#define FILE_UNBUFFERED	0x10	/* force unbuffered mode */
435dfecf96Smrg#define FILE_BINARY	0x20
445dfecf96Smrg
455dfecf96Smrg/*
465dfecf96Smrg * Types
475dfecf96Smrg */
485dfecf96Smrgtypedef ssize_t (*io_write_fn)(int, const void*, size_t);
495dfecf96Smrg
505dfecf96Smrgstruct _LispFile {
515dfecf96Smrg    char *buffer;
525dfecf96Smrg    int line;			/* input line number */
535dfecf96Smrg    int column;			/* output column number */
545dfecf96Smrg    int descriptor;
555dfecf96Smrg    int length;			/* number of bytes used */
565dfecf96Smrg    int offset;			/* read/write offset */
575dfecf96Smrg    int unget : 8;		/* unread char */
585dfecf96Smrg    unsigned int readable : 1;
595dfecf96Smrg    unsigned int writable : 1;
605dfecf96Smrg    unsigned int regular : 1;	/* regular file */
615dfecf96Smrg    unsigned int buffered : 1;
625dfecf96Smrg    unsigned int available : 1;	/* unget field holds a char */
635dfecf96Smrg    unsigned int nonblock : 1;	/* in nonblock mode */
645dfecf96Smrg    unsigned int binary : 1;	/* if set, don't calculate column/line-number */
655dfecf96Smrg    io_write_fn io_write;
665dfecf96Smrg};
675dfecf96Smrg
685dfecf96Smrgstruct _LispString {
695dfecf96Smrg    char *string;
705dfecf96Smrg    int line;			/* input line number */
715dfecf96Smrg    int column;			/* output column number */
725dfecf96Smrg    int space;			/* number of bytes alocated */
735dfecf96Smrg    int length;			/* number of bytes used */
745dfecf96Smrg    int input;			/* input offset, for read operations */
755dfecf96Smrg    int output;			/* output offset, for write operations */
765dfecf96Smrg    unsigned int fixed : 1;	/* if set, don't try to reallocate string */
775dfecf96Smrg    unsigned int binary : 1;	/* if set, don't calculate column/line-number */
785dfecf96Smrg};
795dfecf96Smrg
805dfecf96Smrg/*
815dfecf96Smrg * Prototypes
825dfecf96Smrg */
835dfecf96Smrg	/* higher level functions */
845dfecf96Smrgint LispGet(void);
855dfecf96Smrgint LispUnget(int);
865dfecf96Smrgvoid LispPushInput(LispObj*);
875dfecf96Smrgvoid LispPopInput(LispObj*);
885dfecf96Smrg
895dfecf96Smrg	/* functions that read/write using the LispFile structure */
905dfecf96SmrgLispFile *LispFdopen(int, int);
91f765521fSmrgLispFile *LispFopen(const char*, int);
925dfecf96Smrgvoid LispFclose(LispFile*);
935dfecf96Smrgint LispFflush(LispFile*);
945dfecf96Smrgint LispFungetc(LispFile*, int);
955dfecf96Smrgint LispFgetc(LispFile*);
965dfecf96Smrgint LispFputc(LispFile*, int);
975dfecf96Smrgchar *LispFgets(LispFile*, char*, int);
98f765521fSmrgint LispFputs(LispFile*, const char*);
995dfecf96Smrgint LispFread(LispFile*, void*, int);
100f765521fSmrgint LispFwrite(LispFile*, const void*, int);
101f765521fSmrgint LispRename(const char*, const char*);
102f765521fSmrgint LispUnlink(const char*);
1035dfecf96Smrg
1045dfecf96Smrg	/* io wrappers */
1055dfecf96Smrgio_write_fn LispSetFileWrite(LispFile*, io_write_fn);
1065dfecf96Smrg
1075dfecf96Smrg	/* functions that read/write using the LispString structure */
1085dfecf96Smrgint LispSgetc(LispString*);
1095dfecf96Smrgint LispSputc(LispString*, int);
110f765521fSmrgint LispSputs(LispString*, const char*);
111f765521fSmrgint LispSwrite(LispString*, const void*, int);
1125dfecf96Smrg
113f765521fSmrgconst char *LispGetSstring(LispString*, int*);
1145dfecf96Smrg
1155dfecf96Smrg#endif /* Lisp_io_h */
116