4 * Copyright (c) 1998-2002, Darren Hiebert
6 * This source code is released for free distribution under the terms of the
7 * GNU General Public License.
9 * External interface to read.c
14 #if defined(FILE_WRITE) || defined(VAXC)
17 # define CONST_FILE const
23 #include "general.h" /* must always come first */
34 #define getInputLineNumber() File.lineNumber
35 #define getInputFileName() vStringValue (File.source.name)
36 #define getInputFilePosition() File.filePosition
37 #define getInputBufferPosition() File.fpBufferPosition
38 #define getSourceFileName() vStringValue (File.source.name)
39 #define getSourceFileTagPath() File.source.tagPath
40 #define getSourceLanguage() File.source.language
41 #define getSourceLanguageName() getLanguageName (File.source.language)
42 #define getSourceLineNumber() File.source.lineNumber
43 #define isLanguage(lang) (boolean)((lang) == File.source.language)
44 #define isHeaderFile() File.source.isHeader
51 /* white space characters */
59 /* some hard to read characters */
64 STRING_SYMBOL
= ('S' + 0x80),
65 CHAR_SYMBOL
= ('C' + 0x80)
68 /* Maintains the state of the current source file.
70 typedef struct sInputFile
{
71 vString
*name
; /* name of input file */
72 vString
*path
; /* path of input file (if any) */
73 vString
*line
; /* last line read from file */
74 const unsigned char* currentLine
; /* current line being worked on */
75 FILE *fp
; /* stream used for reading the file */
76 unsigned long lineNumber
; /* line number in the input file */
77 fpos_t filePosition
; /* file position of current line */
78 unsigned char* fpBuffer
; /* buffer which contains the text to be parsed.
79 This is optional to the use of a file-descriptor */
80 int fpBufferSize
; /* size of the fpBuffer */
81 int fpBufferPosition
; /* pointer to the current position in buffer */
83 int ungetch
; /* a single character that was ungotten */
84 boolean eof
; /* have we reached the end of file? */
85 boolean newLine
; /* will the next character begin a new line? */
86 langType language
; /* language of input file */
88 /* Contains data pertaining to the original source file in which the tag
89 * was defined. This may be different from the input file when #line
90 * directives are processed (i.e. the input file is preprocessor output).
93 vString
*name
; /* name to report for source file */
94 char *tagPath
; /* path of source file relative to tag file */
95 unsigned long lineNumber
;/* line number in the source file */
96 boolean isHeader
; /* is source file a header file? */
97 langType language
; /* language of source file */
104 extern CONST_FILE inputFile File
;
107 * FUNCTION PROTOTYPES
109 extern void freeSourceFileResources (void);
110 extern boolean
fileOpen (const char *const fileName
, const langType language
);
111 extern boolean
fileEOF (void);
112 extern void fileClose (void);
113 extern int fileGetc (void);
114 extern void fileUngetc (int c
);
115 extern const unsigned char *fileReadLine (void);
116 extern char *readLine (vString
*const vLine
, FILE *const fp
);
117 extern char *readSourceLine (vString
*const vLine
, fpos_t location
, long *const pSeekValue
);
119 extern boolean
bufferOpen (unsigned char *buffer
, int buffer_size
,
120 const char *const fileName
, const langType language
);
121 extern void bufferClose (void);
122 extern void setBufPos (int new_position
);
123 extern int getBufPos (void);
124 extern boolean
useFile (void);
129 /* vi:set tabstop=4 shiftwidth=4: */