Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/runtime/c-libs/smlnj-date/strftime.c
ViewVC logotype

Annotation of /sml/trunk/src/runtime/c-libs/smlnj-date/strftime.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 249 - (view) (download) (as text)
Original Path: sml/branches/SMLNJ/src/runtime/c-libs/smlnj-date/strftime.c

1 : monnier 249 /* strftime.c
2 :     *
3 :     * COPYRIGHT (c) 1996 AT&T Research.
4 :     */
5 :    
6 :     #include <time.h>
7 :     #include "ml-base.h"
8 :     #include "ml-values.h"
9 :     #include "ml-objects.h"
10 :     #include "ml-c.h"
11 :     #include "cfun-proto-list.h"
12 :    
13 :     /* _ml_Date_strftime :
14 :     * (string * (int * int * int * int * int * int * int * int * int)) -> string
15 :     *
16 :     * This takes a format field and nine integer fields (sec, min, hour, mday, mon,
17 :     * year, wday, yday, and isdst), and converts it into a string representation
18 :     * according to the format string.
19 :     */
20 :     ml_val_t _ml_Date_strftime (ml_state_t *msp, ml_val_t arg)
21 :     {
22 :     ml_val_t fmt = REC_SEL(arg, 0);
23 :     ml_val_t res, date;
24 :     struct tm tm;
25 :     char buf[512];
26 :     size_t sz;
27 :    
28 :     date = REC_SEL(arg, 1);
29 :     tm.tm_sec = REC_SELINT(date, 0);
30 :     tm.tm_min = REC_SELINT(date, 1);
31 :     tm.tm_hour = REC_SELINT(date, 2);
32 :     tm.tm_mday = REC_SELINT(date, 3);
33 :     tm.tm_mon = REC_SELINT(date, 4);
34 :     tm.tm_year = REC_SELINT(date, 5);
35 :     tm.tm_wday = REC_SELINT(date, 6);
36 :     tm.tm_yday = REC_SELINT(date, 7);
37 :     tm.tm_isdst = REC_SELINT(date, 8);
38 :    
39 :     sz = strftime (buf, sizeof(buf), STR_MLtoC(fmt), &tm);
40 :     if (sz > 0) {
41 :     res = ML_AllocString(msp, sz);
42 :     strncpy (STR_MLtoC(res), buf, sz);
43 :     return res;
44 :     }
45 :     else
46 :     return RAISE_ERROR(msp, "strftime failed");
47 :    
48 :     } /* end of _ml_Date_strftime */
49 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0