* config/m32c/predicates.md (m32c_psi_scale): New.
[official-gcc.git] / libgfortran / intrinsics / tty.c
blob93416f9983c2a9a49aec55e6cd0f28f892297420
1 /* Implementation of the ISATTY and TTYNAM g77 intrinsics.
2 Copyright (C) 2005 Free Software Foundation, Inc.
3 Contributed by François-Xavier Coudert <coudert@clipper.ens.fr>
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
7 Libgfortran is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file into combinations with other programs,
15 and to distribute those combinations without any restriction coming
16 from the use of this file. (The General Public License restrictions
17 do apply in other respects; for example, they cover modification of
18 the file, and distribution when not linked into a combine
19 executable.)
21 Libgfortran is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public
27 License along with libgfortran; see the file COPYING. If not,
28 write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29 Boston, MA 02110-1301, USA. */
31 #include "config.h"
32 #include "libgfortran.h"
33 #include "../io/io.h"
35 #include <string.h>
37 /* LOGICAL FUNCTION ISATTY(UNIT)
38 INTEGER, INTENT(IN) :: UNIT */
40 extern GFC_LOGICAL_4 isatty_l4 (int *);
41 export_proto(isatty_l4);
43 GFC_LOGICAL_4
44 isatty_l4 (int *unit)
46 gfc_unit *u;
47 GFC_LOGICAL_4 ret = 0;
49 u = find_unit (*unit);
50 if (u != NULL)
52 ret = (GFC_LOGICAL_4) stream_isatty (u->s);
53 unlock_unit (u);
55 return ret;
59 extern GFC_LOGICAL_8 isatty_l8 (int *);
60 export_proto(isatty_l8);
62 GFC_LOGICAL_8
63 isatty_l8 (int *unit)
65 gfc_unit *u;
66 GFC_LOGICAL_8 ret = 0;
68 u = find_unit (*unit);
69 if (u != NULL)
71 ret = (GFC_LOGICAL_8) stream_isatty (u->s);
72 unlock_unit (u);
74 return ret;
78 /* SUBROUTINE TTYNAM(UNIT,NAME)
79 INTEGER,SCALAR,INTENT(IN) :: UNIT
80 CHARACTER,SCALAR,INTENT(OUT) :: NAME */
82 extern void ttynam_sub (int *, char *, gfc_charlen_type);
83 export_proto(ttynam_sub);
85 void
86 ttynam_sub (int *unit, char * name, gfc_charlen_type name_len)
88 gfc_unit *u;
89 char * n;
90 int i;
92 memset (name, ' ', name_len);
93 u = find_unit (*unit);
94 if (u != NULL)
96 n = stream_ttyname (u->s);
97 if (n != NULL)
99 i = 0;
100 while (*n && i < name_len)
101 name[i++] = *(n++);
103 unlock_unit (u);
108 extern void ttynam (char **, gfc_charlen_type *, int);
109 export_proto(ttynam);
111 void
112 ttynam (char ** name, gfc_charlen_type * name_len, int unit)
114 gfc_unit *u;
116 u = find_unit (unit);
117 if (u != NULL)
119 *name = stream_ttyname (u->s);
120 if (*name != NULL)
122 *name_len = strlen (*name);
123 *name = strdup (*name);
124 unlock_unit (u);
125 return;
127 unlock_unit (u);
130 *name_len = 0;
131 *name = NULL;