1 /* GNU m4 -- A simple macro processor
2 Copyright (C) 1999, 2000, 2001, 2006, 2007 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 # include <sys/time.h>
26 #endif /* TM_IN_SYS_TIME */
28 /* Build using only the exported interfaces, unless NDEBUG is set, in
29 which case use private symbols to speed things up as much as possible. */
31 # include <m4/m4module.h>
33 # include "m4private.h"
36 /* Rename exported symbols for dlpreload()ing. */
37 #define m4_builtin_table time_LTX_m4_builtin_table
39 /* function macros blind side minargs maxargs */
40 #define builtin_functions \
41 BUILTIN (currenttime, false, false, false, 0, 0 ) \
42 BUILTIN (ctime, false, false, false, 0, 1 ) \
43 BUILTIN (gmtime, false, true, false, 1, 1 ) \
44 BUILTIN (localtime, false, true, false, 1, 1 ) \
46 #define mktime_functions \
47 BUILTIN (mktime, false, true, false, 6, 7 ) \
49 #define strftime_functions \
50 BUILTIN (strftime, false, true, false, 2, 2 ) \
53 #define BUILTIN(handler, macros, blind, side, min, max) M4BUILTIN(handler)
63 m4_builtin m4_builtin_table
[] =
65 #define BUILTIN(handler, macros, blind, side, min, max) \
66 { CONC(builtin_, handler), STR(handler), \
67 ((macros ? M4_BUILTIN_GROKS_MACRO : 0) \
68 | (blind ? M4_BUILTIN_BLIND : 0) \
69 | (side ? M4_BUILTIN_SIDE_EFFECT : 0)), \
81 { NULL
, NULL
, 0, 0, 0 },
87 M4BUILTIN_HANDLER (currenttime
)
94 l
= sprintf (buf
, "%ld", now
);
96 obstack_grow (obs
, buf
, l
);
102 M4BUILTIN_HANDLER (ctime
)
110 m4_numeric_arg (context
, argc
, argv
, 1, &i
);
117 obstack_grow (obs
, s
, 24);
121 format_tm (m4_obstack
*obs
, struct tm
*tm
)
123 m4_shipout_int (obs
, tm
->tm_sec
);
124 obstack_1grow (obs
, ',');
126 m4_shipout_int (obs
, tm
->tm_min
);
127 obstack_1grow (obs
, ',');
129 m4_shipout_int (obs
, tm
->tm_hour
);
130 obstack_1grow (obs
, ',');
132 m4_shipout_int (obs
, tm
->tm_mday
);
133 obstack_1grow (obs
, ',');
135 m4_shipout_int (obs
, tm
->tm_mon
);
136 obstack_1grow (obs
, ',');
138 m4_shipout_int (obs
, tm
->tm_year
);
139 obstack_1grow (obs
, ',');
141 m4_shipout_int (obs
, tm
->tm_wday
);
142 obstack_1grow (obs
, ',');
144 m4_shipout_int (obs
, tm
->tm_yday
);
145 obstack_1grow (obs
, ',');
147 m4_shipout_int (obs
, tm
->tm_isdst
);
153 M4BUILTIN_HANDLER (gmtime
)
158 if (!m4_numeric_arg (context
, argc
, argv
, 1, &i
))
162 format_tm (obs
, gmtime (&t
));
168 M4BUILTIN_HANDLER (localtime
)
173 if (!m4_numeric_arg (context
, argc
, argv
, 1, &i
))
177 format_tm (obs
, localtime (&t
));
182 * mktime(SEC, MIN, HOUR, MDAY, MONTH, YEAR, [ISDST])
184 M4BUILTIN_HANDLER (mktime
)
189 if (!m4_numeric_arg (context
, argc
, argv
, 1, &tm
.tm_sec
))
191 if (!m4_numeric_arg (context
, argc
, argv
, 2, &tm
.tm_min
))
193 if (!m4_numeric_arg (context
, argc
, argv
, 3, &tm
.tm_hour
))
195 if (!m4_numeric_arg (context
, argc
, argv
, 4, &tm
.tm_mday
))
197 if (!m4_numeric_arg (context
, argc
, argv
, 5, &tm
.tm_mon
))
199 if (!m4_numeric_arg (context
, argc
, argv
, 6, &tm
.tm_year
))
201 if (M4ARG (7) && !m4_numeric_arg (context
, argc
, argv
, 7, &tm
.tm_isdst
))
206 m4_shipout_int (obs
, t
);
208 #endif /* HAVE_MKTIME */
212 * strftime(FORMAT, SECONDS)
214 M4BUILTIN_HANDLER (strftime
)
221 if (!m4_numeric_arg (context
, argc
, argv
, 2, &l
))
227 buf
= (char *) obstack_alloc (obs
, 1024);
228 l
= strftime (buf
, 1024, M4ARG (1), tm
);
229 obstack_grow (obs
, buf
, l
);
231 #endif /* HAVE_STRFTIME */