]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/m2/mc-boot/GStrIO.c
1 /* do not edit automatically generated by mc from StrIO. */
2 /* StrIO.mod provides simple string input output routines.
4 Copyright (C) 2001-2023 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
;
47 static unsigned int IsATTY
;
50 WriteLn - writes a carriage return and a newline
54 extern "C" void StrIO_WriteLn (void);
57 ReadString - reads a sequence of characters into a string.
58 Line editing accepts Del, Ctrl H, Ctrl W and
62 extern "C" void StrIO_ReadString (char *a
, unsigned int _a_high
);
65 WriteString - writes a string to the default output.
68 extern "C" void StrIO_WriteString (const char *a_
, unsigned int _a_high
);
71 Erase - writes a backspace, space and backspace to remove the
72 last character displayed.
75 static void Erase (void);
78 Echo - echos the character, ch, onto the output channel if IsATTY
82 static void Echo (char ch
);
85 AlphaNum- returns true if character, ch, is an alphanumeric character.
88 static unsigned int AlphaNum (char ch
);
92 Erase - writes a backspace, space and backspace to remove the
93 last character displayed.
96 static void Erase (void)
105 Echo - echos the character, ch, onto the output channel if IsATTY
109 static void Echo (char ch
)
119 AlphaNum- returns true if character, ch, is an alphanumeric character.
122 static unsigned int AlphaNum (char ch
)
124 return (((ch
>= 'a') && (ch
<= 'z')) || ((ch
>= 'A') && (ch
<= 'Z'))) || ((ch
>= '0') && (ch
<= '9'));
125 /* static analysis guarentees a RETURN statement will be used before here. */
126 __builtin_unreachable ();
131 WriteLn - writes a carriage return and a newline
135 extern "C" void StrIO_WriteLn (void)
138 StdIO_Write (ASCII_lf
);
143 ReadString - reads a sequence of characters into a string.
144 Line editing accepts Del, Ctrl H, Ctrl W and
148 extern "C" void StrIO_ReadString (char *a
, unsigned int _a_high
)
158 if ((ch
== ASCII_del
) || (ch
== ASCII_bs
))
162 StdIO_Write (ASCII_bel
);
170 else if (ch
== ASCII_nak
)
172 /* avoid dangling else. */
179 else if (ch
== ASCII_etb
)
181 /* avoid dangling else. */
186 else if (AlphaNum (a
[n
-1]))
188 /* avoid dangling else. */
192 } while (! ((n
== 0) || (! (AlphaNum (a
[n
-1])))));
196 /* avoid dangling else. */
203 /* avoid dangling else. */
204 if ((ch
== ASCII_cr
) || (ch
== ASCII_lf
))
209 else if (ch
== ASCII_ff
)
211 /* avoid dangling else. */
221 /* avoid dangling else. */
226 else if (ch
== ASCII_eof
)
228 /* avoid dangling else. */
238 else if (ch
!= ASCII_cr
)
240 /* avoid dangling else. */
243 } while (! ((ch
== ASCII_cr
) || (ch
== ASCII_lf
)));
248 WriteString - writes a string to the default output.
251 extern "C" void StrIO_WriteString (const char *a_
, unsigned int _a_high
)
257 /* make a local copy of each unbounded array. */
258 memcpy (a
, a_
, _a_high
+1);
262 while ((n
<= high
) && (a
[n
] != ASCII_nul
))
269 extern "C" void _M2_StrIO_init (__attribute__((unused
)) int argc
,__attribute__((unused
)) char *argv
[],__attribute__((unused
)) char *envp
[])
271 /* IsATTY := isatty() */
275 extern "C" void _M2_StrIO_finish (__attribute__((unused
)) int argc
,__attribute__((unused
)) char *argv
[],__attribute__((unused
)) char *envp
[])