@@ -166,6 +166,7 @@ static int sc_reparse = 0; /* needs 3th parse because of changed prototypes
166
166
static int sc_parsenum = 0 ; /* number of the extra parses */
167
167
static int wq [wqTABSZ ]; /* "while queue", internal stack for nested loops */
168
168
static int * wqptr ; /* pointer to next entry */
169
+ static time_t now ; /* current timestamp, for built-in constants "__time" and "__timestamp" */
169
170
#if !defined SC_LIGHT
170
171
static char sc_rootpath [_MAX_PATH ];
171
172
static char * sc_documentation = NULL ;/* main documentation */
@@ -1554,6 +1555,8 @@ static void usage(void)
1554
1555
static void setconstants (void )
1555
1556
{
1556
1557
int debug ;
1558
+ time_t loctime ;
1559
+ struct tm loctm ,utctm ;
1557
1560
1558
1561
assert (sc_status == statIDLE );
1559
1562
append_constval (& tagname_tab ,"_" ,0 ,0 );/* "untagged" */
@@ -1601,6 +1604,13 @@ static void setconstants(void)
1601
1604
line_sym = add_builtin_constant ("__line" ,0 ,sGLOBAL ,0 );
1602
1605
add_builtin_constant ("__compat" ,pc_compat ,sGLOBAL ,0 );
1603
1606
1607
+ now = time (NULL );
1608
+ loctm = * localtime (& now );
1609
+ utctm = * gmtime (& now );
1610
+ loctime = now + (loctm .tm_sec - utctm .tm_sec )+ (loctm .tm_min - utctm .tm_min )* 60
1611
+ + (loctm .tm_hour - utctm .tm_hour )* 60 * 60 + (loctm .tm_mday - utctm .tm_mday )* 60 * 60 * 24 ;
1612
+ add_builtin_constant ("__timestamp" ,(cell )loctime ,sGLOBAL ,0 );
1613
+
1604
1614
debug = 0 ;
1605
1615
if ((sc_debug & (sCHKBOUNDS | sSYMBOLIC ))== (sCHKBOUNDS | sSYMBOLIC ))
1606
1616
debug = 2 ;
@@ -1613,14 +1623,12 @@ static void setconstants(void)
1613
1623
1614
1624
static void setstringconstants ()
1615
1625
{
1616
- time_t now ;
1617
1626
char timebuf [arraysize ("11:22:33" )];
1618
1627
char datebuf [arraysize ("10 Jan 2017" )];
1619
1628
1620
1629
assert (sc_status != statIDLE );
1621
1630
add_builtin_string_constant ("__file" ,"" ,sGLOBAL );
1622
1631
1623
- now = time (NULL );
1624
1632
strftime (timebuf ,arraysize (timebuf ),"%H:%M:%S" ,localtime (& now ));
1625
1633
add_builtin_string_constant ("__time" ,timebuf ,sGLOBAL );
1626
1634
strftime (datebuf ,arraysize (datebuf ),"%d %b %Y" ,localtime (& now ));
0 commit comments