summaryrefslogtreecommitdiff
path: root/src/runtime/c/teyjus/system/stream.h
blob: ec24fb4746fb353275c194fe0f2a986aaa4c7ed3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//////////////////////////////////////////////////////////////////////////////
//Copyright 2008
//  Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
//////////////////////////////////////////////////////////////////////////////
// This file is part of Teyjus.                                             //
//                                                                          //
// Teyjus is free software: you can redistribute it and/or modify           //
// it under the terms of the GNU General Public License as published by     //
// the Free Software Foundation, either version 3 of the License, or        //
// (at your option) any later version.                                      //
//                                                                          //
// Teyjus is distributed in the hope that it will be useful,                //
// but WITHOUT ANY WARRANTY; without even the implied warranty of           //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
// GNU General Public License for more details.                             //
//                                                                          //
// You should have received a copy of the GNU General Public License        //
// along with Teyjus.  If not, see <http://www.gnu.org/licenses/>.          //
//////////////////////////////////////////////////////////////////////////////
/****************************************************************************
 *                                                                          *
 * system/stream.h{c} implements stream support for the C part  of the LP   *
 * system.                                                                  *
 ****************************************************************************/
#ifndef STREAM_H
#define STREAM_H

#include <stdarg.h>
#include <stdio.h>
#include "../simulator/mctypes.h" //to be modified

/*****************************************************************************
 *                                CONSTANTS                                  *
 *****************************************************************************/

#define STREAM_ILLEGAL    0

#define STREAM_READ       "r"
#define STREAM_WRITE      "w"
#define STREAM_APPEND     "a"

/*****************************************************************************
 *                             EXPORTED VARIABLES                            *
 *****************************************************************************/
/* STREAMs corresponding to the three standard streams */
extern WordPtr STREAM_stdin, STREAM_stdout, STREAM_stderr;

/****************************************************************************
 *                      BASIC FUNCTIONS                                     *
 ****************************************************************************/

/* STREAM_open returns STREAM_ILLEGAL if the stream can't be opened;
   if inDoCountLines is false, the line numbering calls below will not
   work. */
WordPtr  STREAM_open(char *inFilename, char *inMode, int inDoUsePaths);
/* open strings as streams.  Note that the STREAM system does not
   distinguish to_string and from_string streams after they are
   opened.  Results are undefined for a write to a from_string or read
   from a to_string. */
WordPtr  STREAM_fromString(char *inString, int inDoCopyString);
WordPtr  STREAM_toString();

/* will not close the standard			    streams */
void     STREAM_close(WordPtr inStream); 


/***************************************************************************
 *                    RAW I/O SUPPORT ROUTINES                             *
 *      each routine returns -1 to indicate an error                       * 
 ***************************************************************************/
int STREAM_readCharacters(WordPtr inStream, int inMaxCount, char* outString, 
                          int inDoStopOnNewline);
/* STREAM_printf and STREAM_sans_printf return the number of characters 
   written, -1 in case of error. STREAM_printf takes a format 
   STREAM_sans_printf interprets the input as a string to be printed */
int     STREAM_printf(WordPtr inStream, char *format, ...);
int     STREAM_sans_printf(WordPtr inStream, char *str);
/* STREAM_printf returns the number of characters written, -1 in case of error*/
int     STREAM_lookahead(WordPtr inStream, char *outChar);
Boolean STREAM_eof(WordPtr inStream); 
int     STREAM_flush(WordPtr inStream);

/***************************************************************************
 *                             ACCESSORS                                   *  
 ***************************************************************************/
char*   STREAM_getString(WordPtr inStream);
FILE*   STREAM_getFile(WordPtr inStream);
char*   STREAM_getName(WordPtr inStream);

#endif //STREAM_H