1 /* do not edit automatically generated by mc from PushBackInput. */
2 /* PushBackInput.mod provides a method for pushing back and consuming input.
4 Copyright (C) 2001-2021 Free Software Foundation, Inc.
5 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
7 This file is part of GNU Modula-2.
9 GNU Modula-2 is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GNU Modula-2 is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 Under Section 7 of GPL version 3, you are granted additional
20 permissions described in the GCC Runtime Library Exception, version
21 3.1, as published by the Free Software Foundation.
23 You should have received a copy of the GNU General Public License and
24 a copy of the GCC Runtime Library Exception along with this program;
25 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
26 <http://www.gnu.org/licenses/>. */
30 # if !defined (PROC_D)
32 typedef void (*PROC_t
) (void);
33 typedef struct { PROC_t proc
; } PROC
;
40 #if defined(__cplusplus)
44 #define _PushBackInput_H
45 #define _PushBackInput_C
48 # include "GDynamicStrings.h"
52 # include "GNumberIO.h"
57 # define MaxPushBackStack 8192
58 # define MaxFileName 4096
59 typedef struct PushBackInput__T2_a PushBackInput__T2
;
61 typedef struct PushBackInput__T3_a PushBackInput__T3
;
63 struct PushBackInput__T2_a
{ char array
[MaxFileName
+1]; };
64 struct PushBackInput__T3_a
{ char array
[MaxPushBackStack
+1]; };
65 static PushBackInput__T2 FileName
;
66 static PushBackInput__T3 CharStack
;
67 static unsigned int ExitStatus
;
68 static unsigned int Column
;
69 static unsigned int StackPtr
;
70 static unsigned int LineNo
;
71 static unsigned int Debugging
;
74 Open - opens a file for reading.
77 extern "C" FIO_File
PushBackInput_Open (const char *a_
, unsigned int _a_high
);
80 GetCh - gets a character from either the push back stack or
84 extern "C" char PushBackInput_GetCh (FIO_File f
);
87 PutCh - pushes a character onto the push back stack, it also
88 returns the character which has been pushed.
91 extern "C" char PushBackInput_PutCh (char ch
);
94 PutString - pushes a string onto the push back stack.
97 extern "C" void PushBackInput_PutString (const char *a_
, unsigned int _a_high
);
100 PutStr - pushes a dynamic string onto the push back stack.
101 The string, s, is not deallocated.
104 extern "C" void PushBackInput_PutStr (DynamicStrings_String s
);
107 Error - emits an error message with the appropriate file, line combination.
110 extern "C" void PushBackInput_Error (const char *a_
, unsigned int _a_high
);
113 WarnError - emits an error message with the appropriate file, line combination.
114 It does not terminate but when the program finishes an exit status of
118 extern "C" void PushBackInput_WarnError (const char *a_
, unsigned int _a_high
);
121 WarnString - emits an error message with the appropriate file, line combination.
122 It does not terminate but when the program finishes an exit status of
126 extern "C" void PushBackInput_WarnString (DynamicStrings_String s
);
129 Close - closes the opened file.
132 extern "C" void PushBackInput_Close (FIO_File f
);
135 GetExitStatus - returns the exit status which will be 1 if any warnings were issued.
138 extern "C" unsigned int PushBackInput_GetExitStatus (void);
141 SetDebug - sets the debug flag on or off.
144 extern "C" void PushBackInput_SetDebug (unsigned int d
);
147 GetColumnPosition - returns the column position of the current character.
150 extern "C" unsigned int PushBackInput_GetColumnPosition (void);
153 GetCurrentLine - returns the current line number.
156 extern "C" unsigned int PushBackInput_GetCurrentLine (void);
159 ErrChar - writes a char, ch, to stderr.
162 static void ErrChar (char ch
);
165 Init - initialize global variables.
168 static void Init (void);
172 ErrChar - writes a char, ch, to stderr.
175 static void ErrChar (char ch
)
177 FIO_WriteChar (FIO_StdErr
, ch
);
182 Init - initialize global variables.
185 static void Init (void)
195 Open - opens a file for reading.
198 extern "C" FIO_File
PushBackInput_Open (const char *a_
, unsigned int _a_high
)
202 /* make a local copy of each unbounded array. */
203 memcpy (a
, a_
, _a_high
+1);
206 StrLib_StrCopy ((const char *) a
, _a_high
, (char *) &FileName
.array
[0], MaxFileName
);
207 return FIO_OpenToRead ((const char *) a
, _a_high
);
208 /* static analysis guarentees a RETURN statement will be used before here. */
209 __builtin_unreachable ();
214 GetCh - gets a character from either the push back stack or
218 extern "C" char PushBackInput_GetCh (FIO_File f
)
227 StdIO_Write (CharStack
.array
[StackPtr
]);
229 return CharStack
.array
[StackPtr
];
233 if ((FIO_EOF (f
)) || (! (FIO_IsNoError (f
))))
240 ch
= FIO_ReadChar (f
);
241 } while (! (((ch
!= ASCII_cr
) || (FIO_EOF (f
))) || (! (FIO_IsNoError (f
)))));
258 /* static analysis guarentees a RETURN statement will be used before here. */
259 __builtin_unreachable ();
264 PutCh - pushes a character onto the push back stack, it also
265 returns the character which has been pushed.
268 extern "C" char PushBackInput_PutCh (char ch
)
270 if (StackPtr
< MaxPushBackStack
)
272 CharStack
.array
[StackPtr
] = ch
;
277 Debug_Halt ((const char *) "max push back stack exceeded, increase MaxPushBackStack", 55, 150, (const char *) "../../gcc-git-devel-modula2/gcc/m2/gm2-libs/PushBackInput.mod", 61);
280 /* static analysis guarentees a RETURN statement will be used before here. */
281 __builtin_unreachable ();
286 PutString - pushes a string onto the push back stack.
289 extern "C" void PushBackInput_PutString (const char *a_
, unsigned int _a_high
)
294 /* make a local copy of each unbounded array. */
295 memcpy (a
, a_
, _a_high
+1);
297 l
= StrLib_StrLen ((const char *) a
, _a_high
);
301 if ((PushBackInput_PutCh (a
[l
])) != a
[l
])
303 Debug_Halt ((const char *) "assert failed", 13, 132, (const char *) "../../gcc-git-devel-modula2/gcc/m2/gm2-libs/PushBackInput.mod", 61);
310 PutStr - pushes a dynamic string onto the push back stack.
311 The string, s, is not deallocated.
314 extern "C" void PushBackInput_PutStr (DynamicStrings_String s
)
318 i
= DynamicStrings_Length (s
);
322 if ((PushBackInput_PutCh (DynamicStrings_char (s
, static_cast<int> (i
)))) != (DynamicStrings_char (s
, static_cast<int> (i
))))
324 Debug_Halt ((const char *) "assert failed", 13, 113, (const char *) "../../gcc-git-devel-modula2/gcc/m2/gm2-libs/PushBackInput.mod", 61);
331 Error - emits an error message with the appropriate file, line combination.
334 extern "C" void PushBackInput_Error (const char *a_
, unsigned int _a_high
)
338 /* make a local copy of each unbounded array. */
339 memcpy (a
, a_
, _a_high
+1);
341 StdIO_PushOutput ((StdIO_ProcWrite
) {(StdIO_ProcWrite_t
) ErrChar
});
342 StrIO_WriteString ((const char *) &FileName
.array
[0], MaxFileName
);
344 NumberIO_WriteCard (LineNo
, 0);
346 StrIO_WriteString ((const char *) a
, _a_high
);
349 FIO_Close (FIO_StdErr
);
355 WarnError - emits an error message with the appropriate file, line combination.
356 It does not terminate but when the program finishes an exit status of
360 extern "C" void PushBackInput_WarnError (const char *a_
, unsigned int _a_high
)
364 /* make a local copy of each unbounded array. */
365 memcpy (a
, a_
, _a_high
+1);
367 StdIO_PushOutput ((StdIO_ProcWrite
) {(StdIO_ProcWrite_t
) ErrChar
});
368 StrIO_WriteString ((const char *) &FileName
.array
[0], MaxFileName
);
370 NumberIO_WriteCard (LineNo
, 0);
372 StrIO_WriteString ((const char *) a
, _a_high
);
380 WarnString - emits an error message with the appropriate file, line combination.
381 It does not terminate but when the program finishes an exit status of
385 extern "C" void PushBackInput_WarnString (DynamicStrings_String s
)
387 typedef char *WarnString__T1
;
391 p
= static_cast<WarnString__T1
> (DynamicStrings_string (s
));
392 StrIO_WriteString ((const char *) &FileName
.array
[0], MaxFileName
);
394 NumberIO_WriteCard (LineNo
, 0);
399 if ((*p
) == ASCII_lf
)
402 StrIO_WriteString ((const char *) &FileName
.array
[0], MaxFileName
);
404 NumberIO_WriteCard (LineNo
, 0);
413 } while (! ((p
== NULL
) || ((*p
) == ASCII_nul
)));
419 Close - closes the opened file.
422 extern "C" void PushBackInput_Close (FIO_File f
)
429 GetExitStatus - returns the exit status which will be 1 if any warnings were issued.
432 extern "C" unsigned int PushBackInput_GetExitStatus (void)
435 /* static analysis guarentees a RETURN statement will be used before here. */
436 __builtin_unreachable ();
441 SetDebug - sets the debug flag on or off.
444 extern "C" void PushBackInput_SetDebug (unsigned int d
)
451 GetColumnPosition - returns the column position of the current character.
454 extern "C" unsigned int PushBackInput_GetColumnPosition (void)
456 if (StackPtr
> Column
)
462 return Column
-StackPtr
;
464 /* static analysis guarentees a RETURN statement will be used before here. */
465 __builtin_unreachable ();
470 GetCurrentLine - returns the current line number.
473 extern "C" unsigned int PushBackInput_GetCurrentLine (void)
476 /* static analysis guarentees a RETURN statement will be used before here. */
477 __builtin_unreachable ();
480 extern "C" void _M2_PushBackInput_init (__attribute__((unused
)) int argc
,__attribute__((unused
)) char *argv
[],__attribute__((unused
)) char *envp
[])
482 PushBackInput_SetDebug (FALSE
);
486 extern "C" void _M2_PushBackInput_finish (__attribute__((unused
)) int argc
,__attribute__((unused
)) char *argv
[],__attribute__((unused
)) char *envp
[])