1 /* GNU m4 -- A simple macro processor
2 Copyright (C) 1999, 2000, 2001, 2006, 2007, 2008, 2009 Free
3 Software Foundation, Inc.
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), M4ARGLEN (1),
115 obstack_grow (obs
, s
, 24);
119 format_tm (m4_obstack
*obs
, struct tm
*tm
)
121 m4_shipout_int (obs
, tm
->tm_sec
);
122 obstack_1grow (obs
, ',');
124 m4_shipout_int (obs
, tm
->tm_min
);
125 obstack_1grow (obs
, ',');
127 m4_shipout_int (obs
, tm
->tm_hour
);
128 obstack_1grow (obs
, ',');
130 m4_shipout_int (obs
, tm
->tm_mday
);
131 obstack_1grow (obs
, ',');
133 m4_shipout_int (obs
, tm
->tm_mon
);
134 obstack_1grow (obs
, ',');
136 m4_shipout_int (obs
, tm
->tm_year
);
137 obstack_1grow (obs
, ',');
139 m4_shipout_int (obs
, tm
->tm_wday
);
140 obstack_1grow (obs
, ',');
142 m4_shipout_int (obs
, tm
->tm_yday
);
143 obstack_1grow (obs
, ',');
145 m4_shipout_int (obs
, tm
->tm_isdst
);
151 M4BUILTIN_HANDLER (gmtime
)
156 if (!m4_numeric_arg (context
, m4_arg_info (argv
), M4ARG (1), M4ARGLEN (1),
161 format_tm (obs
, gmtime (&t
));
167 M4BUILTIN_HANDLER (localtime
)
172 if (!m4_numeric_arg (context
, m4_arg_info (argv
), M4ARG (1), M4ARGLEN (1),
177 format_tm (obs
, localtime (&t
));
182 * mktime(SEC, MIN, HOUR, MDAY, MONTH, YEAR, [ISDST])
184 M4BUILTIN_HANDLER (mktime
)
186 const m4_call_info
*me
= m4_arg_info (argv
);
190 if (!m4_numeric_arg (context
, me
, M4ARG (1), M4ARGLEN (1), &tm
.tm_sec
))
192 if (!m4_numeric_arg (context
, me
, M4ARG (2), M4ARGLEN (2), &tm
.tm_min
))
194 if (!m4_numeric_arg (context
, me
, M4ARG (3), M4ARGLEN (3), &tm
.tm_hour
))
196 if (!m4_numeric_arg (context
, me
, M4ARG (4), M4ARGLEN (4), &tm
.tm_mday
))
198 if (!m4_numeric_arg (context
, me
, M4ARG (5), M4ARGLEN (5), &tm
.tm_mon
))
200 if (!m4_numeric_arg (context
, me
, M4ARG (6), M4ARGLEN (6), &tm
.tm_year
))
202 if (M4ARG (7) && !m4_numeric_arg (context
, me
, M4ARG (7), M4ARGLEN (7),
208 m4_shipout_int (obs
, t
);
210 #endif /* HAVE_MKTIME */
214 * strftime(FORMAT, SECONDS)
216 M4BUILTIN_HANDLER (strftime
)
223 if (!m4_numeric_arg (context
, m4_arg_info (argv
), M4ARG (2), M4ARGLEN (2),
230 buf
= (char *) obstack_alloc (obs
, 1024);
231 l
= strftime (buf
, 1024, M4ARG (1), tm
);
232 obstack_grow (obs
, buf
, l
);
234 #endif /* HAVE_STRFTIME */