1 /* GNU m4 -- A simple macro processor
2 Copyright (C) 1999, 2000, 2001, 2006, 2007, 2008 Free Software
5 This file is part of GNU M4.
7 GNU M4 is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU M4 is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 # include <sys/time.h>
27 #endif /* TM_IN_SYS_TIME */
29 /* Build using only the exported interfaces, unless NDEBUG is set, in
30 which case use private symbols to speed things up as much as possible. */
32 # include <m4/m4module.h>
34 # include "m4private.h"
37 /* Rename exported symbols for dlpreload()ing. */
38 #define m4_builtin_table time_LTX_m4_builtin_table
40 /* function macros blind side minargs maxargs */
41 #define builtin_functions \
42 BUILTIN (currenttime, false, false, false, 0, 0 ) \
43 BUILTIN (ctime, false, false, false, 0, 1 ) \
44 BUILTIN (gmtime, false, true, false, 1, 1 ) \
45 BUILTIN (localtime, false, true, false, 1, 1 ) \
47 #define mktime_functions \
48 BUILTIN (mktime, false, true, false, 6, 7 ) \
50 #define strftime_functions \
51 BUILTIN (strftime, false, true, false, 2, 2 ) \
54 #define BUILTIN(handler, macros, blind, side, min, max) M4BUILTIN (handler)
64 const m4_builtin m4_builtin_table
[] =
66 #define BUILTIN(handler, macros, blind, side, min, max) \
67 M4BUILTIN_ENTRY (handler, #handler, macros, blind, side, min, max)
78 { NULL
, NULL
, 0, 0, 0 },
84 M4BUILTIN_HANDLER (currenttime
)
91 l
= sprintf (buf
, "%ld", now
);
93 obstack_grow (obs
, buf
, l
);
99 M4BUILTIN_HANDLER (ctime
)
107 m4_numeric_arg (context
, m4_arg_info (argv
), M4ARG (1), &i
);
114 obstack_grow (obs
, s
, 24);
118 format_tm (m4_obstack
*obs
, struct tm
*tm
)
120 m4_shipout_int (obs
, tm
->tm_sec
);
121 obstack_1grow (obs
, ',');
123 m4_shipout_int (obs
, tm
->tm_min
);
124 obstack_1grow (obs
, ',');
126 m4_shipout_int (obs
, tm
->tm_hour
);
127 obstack_1grow (obs
, ',');
129 m4_shipout_int (obs
, tm
->tm_mday
);
130 obstack_1grow (obs
, ',');
132 m4_shipout_int (obs
, tm
->tm_mon
);
133 obstack_1grow (obs
, ',');
135 m4_shipout_int (obs
, tm
->tm_year
);
136 obstack_1grow (obs
, ',');
138 m4_shipout_int (obs
, tm
->tm_wday
);
139 obstack_1grow (obs
, ',');
141 m4_shipout_int (obs
, tm
->tm_yday
);
142 obstack_1grow (obs
, ',');
144 m4_shipout_int (obs
, tm
->tm_isdst
);
150 M4BUILTIN_HANDLER (gmtime
)
155 if (!m4_numeric_arg (context
, m4_arg_info (argv
), M4ARG (1), &i
))
159 format_tm (obs
, gmtime (&t
));
165 M4BUILTIN_HANDLER (localtime
)
170 if (!m4_numeric_arg (context
, m4_arg_info (argv
), M4ARG (1), &i
))
174 format_tm (obs
, localtime (&t
));
179 * mktime(SEC, MIN, HOUR, MDAY, MONTH, YEAR, [ISDST])
181 M4BUILTIN_HANDLER (mktime
)
183 const m4_call_info
*me
= m4_arg_info (argv
);
187 if (!m4_numeric_arg (context
, me
, M4ARG (1), &tm
.tm_sec
))
189 if (!m4_numeric_arg (context
, me
, M4ARG (2), &tm
.tm_min
))
191 if (!m4_numeric_arg (context
, me
, M4ARG (3), &tm
.tm_hour
))
193 if (!m4_numeric_arg (context
, me
, M4ARG (4), &tm
.tm_mday
))
195 if (!m4_numeric_arg (context
, me
, M4ARG (5), &tm
.tm_mon
))
197 if (!m4_numeric_arg (context
, me
, M4ARG (6), &tm
.tm_year
))
199 if (M4ARG (7) && !m4_numeric_arg (context
, me
, M4ARG (7), &tm
.tm_isdst
))
204 m4_shipout_int (obs
, t
);
206 #endif /* HAVE_MKTIME */
210 * strftime(FORMAT, SECONDS)
212 M4BUILTIN_HANDLER (strftime
)
219 if (!m4_numeric_arg (context
, m4_arg_info (argv
), M4ARG (2), &l
))
225 buf
= (char *) obstack_alloc (obs
, 1024);
226 l
= strftime (buf
, 1024, M4ARG (1), tm
);
227 obstack_grow (obs
, buf
, l
);
229 #endif /* HAVE_STRFTIME */