]>
Commit | Line | Data |
---|---|---|
35059811 | 1 | /* Implementation of the CTIME and FDATE g77 intrinsics. |
36ae8a61 | 2 | Copyright (C) 2005, 2007 Free Software Foundation, Inc. |
35059811 FXC |
3 | Contributed by François-Xavier Coudert <coudert@clipper.ens.fr> |
4 | ||
5 | This file is part of the GNU Fortran 95 runtime library (libgfortran). | |
6 | ||
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. | |
11 | ||
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.) | |
20 | ||
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. | |
25 | ||
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. */ | |
30 | ||
35059811 FXC |
31 | #include "libgfortran.h" |
32 | ||
33 | #ifdef TIME_WITH_SYS_TIME | |
34 | # include <sys/time.h> | |
35 | # include <time.h> | |
36 | #else | |
37 | # if HAVE_SYS_TIME_H | |
38 | # include <sys/time.h> | |
39 | # else | |
40 | # ifdef HAVE_TIME_H | |
41 | # include <time.h> | |
42 | # endif | |
43 | # endif | |
44 | #endif | |
45 | ||
46 | #include <string.h> | |
47 | ||
48 | ||
49 | extern void fdate (char **, gfc_charlen_type *); | |
50 | export_proto(fdate); | |
51 | ||
52 | void | |
53 | fdate (char ** date, gfc_charlen_type * date_len) | |
54 | { | |
55 | #if defined(HAVE_TIME) && defined(HAVE_CTIME) | |
56 | int i; | |
57 | time_t now = time(NULL); | |
58 | *date = ctime (&now); | |
59 | if (*date != NULL) | |
60 | { | |
61 | *date = strdup (*date); | |
62 | *date_len = strlen (*date); | |
63 | ||
64 | i = 0; | |
65 | while ((*date)[i]) | |
66 | { | |
67 | if ((*date)[i] == '\n') | |
68 | (*date)[i] = ' '; | |
69 | i++; | |
70 | } | |
71 | return; | |
72 | } | |
73 | #endif | |
74 | ||
75 | *date = NULL; | |
76 | *date_len = 0; | |
77 | } | |
78 | ||
79 | ||
80 | extern void fdate_sub (char *, gfc_charlen_type); | |
81 | export_proto(fdate_sub); | |
82 | ||
83 | void | |
84 | fdate_sub (char * date, gfc_charlen_type date_len) | |
85 | { | |
86 | #if defined(HAVE_TIME) && defined(HAVE_CTIME) | |
87 | int i; | |
88 | char *d; | |
89 | time_t now = time(NULL); | |
90 | #endif | |
91 | ||
92 | memset (date, ' ', date_len); | |
93 | #if defined(HAVE_TIME) && defined(HAVE_CTIME) | |
94 | d = ctime (&now); | |
95 | if (d != NULL) | |
96 | { | |
97 | i = 0; | |
98 | while (*d && *d != '\n' && i < date_len) | |
99 | date[i++] = *(d++); | |
100 | } | |
101 | #endif | |
102 | } | |
103 | ||
104 | ||
105 | ||
106 | extern void PREFIX(ctime) (char **, gfc_charlen_type *, GFC_INTEGER_8); | |
107 | export_proto_np(PREFIX(ctime)); | |
108 | ||
109 | void | |
110 | PREFIX(ctime) (char ** date, gfc_charlen_type * date_len, GFC_INTEGER_8 t) | |
111 | { | |
112 | #if defined(HAVE_CTIME) | |
113 | time_t now = t; | |
114 | int i; | |
115 | *date = ctime (&now); | |
116 | if (*date != NULL) | |
117 | { | |
118 | *date = strdup (*date); | |
119 | *date_len = strlen (*date); | |
120 | ||
121 | i = 0; | |
122 | while ((*date)[i]) | |
123 | { | |
124 | if ((*date)[i] == '\n') | |
125 | (*date)[i] = ' '; | |
126 | i++; | |
127 | } | |
128 | return; | |
129 | } | |
130 | #endif | |
131 | ||
132 | *date = NULL; | |
133 | *date_len = 0; | |
134 | } | |
135 | ||
136 | ||
137 | extern void ctime_sub (GFC_INTEGER_8 *, char *, gfc_charlen_type); | |
138 | export_proto(ctime_sub); | |
139 | ||
140 | void | |
141 | ctime_sub (GFC_INTEGER_8 * t, char * date, gfc_charlen_type date_len) | |
142 | { | |
143 | #if defined(HAVE_CTIME) | |
144 | int i; | |
145 | char *d; | |
146 | time_t now = *t; | |
147 | #endif | |
148 | ||
149 | memset (date, ' ', date_len); | |
150 | #if defined(HAVE_CTIME) | |
151 | d = ctime (&now); | |
152 | if (d != NULL) | |
153 | { | |
154 | i = 0; | |
155 | while (*d && *d != '\n' && i < date_len) | |
156 | date[i++] = *(d++); | |
157 | } | |
158 | #endif | |
159 | } |