Ruby  1.9.3p551(2014-11-13revision48407)
Macros | Functions | Variables
strftime.c File Reference
#include "ruby/ruby.h"
#include "timev.h"
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <errno.h>
#include <math.h>

Go to the source code of this file.

Macros

#define SYSV_EXT   1 /* stuff in System V ascftime routine */
 
#define SUNOS_EXT   1 /* stuff in SunOS strftime routine */
 
#define POSIX2_DATE   1 /* stuff in Posix 1003.2 date command */
 
#define VMS_EXT   1 /* include %v for VMS date format */
 
#define MAILHEADER_EXT   1 /* add %z for HHMM format */
 
#define ISO_DATE_EXT   1 /* %G and %g for year of ISO week */
 
#define adddecl(stuff)   stuff
 
#define const
 
#define range(low, item, hi)   max((low), min((item), (hi)))
 
#define add(x, y)   (rb_funcall((x), '+', 1, (y)))
 
#define sub(x, y)   (rb_funcall((x), '-', 1, (y)))
 
#define mul(x, y)   (rb_funcall((x), '*', 1, (y)))
 
#define quo(x, y)   (rb_funcall((x), rb_intern("quo"), 1, (y)))
 
#define div(x, y)   (rb_funcall((x), rb_intern("div"), 1, (y)))
 
#define mod(x, y)   (rb_funcall((x), '%', 1, (y)))
 
#define BIT_OF(n)   (1U<<(n))
 
#define FLAG_FOUND()
 
#define NEEDS(n)   do if (s >= endp || (n) >= endp - s - 1) goto err; while (0)
 
#define FILL_PADDING(i)
 
#define FMT(def_pad, def_prec, fmt, val)
 
#define STRFTIME(fmt)
 
#define FMTV(def_pad, def_prec, fmt, val)
 

Functions

static int weeknumber ()
 
static int weeknumber_v ()
 
voidmalloc ()
 
voidrealloc ()
 
char * getenv ()
 
char * strchr ()
 
static size_t rb_strftime_with_timespec (char *s, size_t maxsize, const char *format, const struct vtm *vtm, VALUE timev, struct timespec *ts, int gmt)
 
size_t rb_strftime (char *s, size_t maxsize, const char *format, const struct vtm *vtm, VALUE timev, int gmt)
 
size_t rb_strftime_timespec (char *s, size_t maxsize, const char *format, const struct vtm *vtm, struct timespec *ts, int gmt)
 
static void vtm2tm_noyear (const struct vtm *vtm, struct tm *result)
 
 switch (jan1day)
 
 if (timeptr->tm_mon==11)
 
static int iso8601wknum_v (const struct vtm *vtm)
 
 if (firstweekday==1)
 
static int weeknumber_v (const struct vtm *vtm, int firstweekday)
 

Variables

static int int a
 
static int int b
 
static int long year
 
static int struct tm * timeptr
 
 weeknum = weeknumber(timeptr, 1)
 
 jan1day = timeptr->tm_wday - (timeptr->tm_yday % 7)
 
int firstweekday
 
int ret
 

Macro Definition Documentation

#define add (   x,
 
)    (rb_funcall((x), '+', 1, (y)))

Definition at line 161 of file strftime.c.

Referenced by rb_strftime_with_timespec().

#define adddecl (   stuff)    stuff

Definition at line 93 of file strftime.c.

#define BIT_OF (   n)    (1U<<(n))
#define const

Definition at line 101 of file strftime.c.

#define div (   x,
 
)    (rb_funcall((x), rb_intern("div"), 1, (y)))

Definition at line 165 of file strftime.c.

#define FILL_PADDING (   i)
Value:
do { \
if (!(flags & BIT_OF(LEFT)) && precision > (i)) { \
NEEDS(precision); \
memset(s, padding ? padding : ' ', precision - (i)); \
s += precision - (i); \
} \
NEEDS(i); \
} \
} while (0);
#define NEEDS(n)
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
memset(y->frac+ix+1, 0,(y->Prec-(ix+1))*sizeof(BDIGIT))
int flags
Definition: tcltklib.c:3012
register char * s
Definition: os2.c:56
else
Definition: bigdecimal.c:1150
#define BIT_OF(n)
ssize_t i
Definition: bigdecimal.c:5519

Referenced by rb_strftime_with_timespec().

#define FLAG_FOUND ( )
Value:
do { \
if (precision > 0 || flags & (BIT_OF(LOCALE_E)|BIT_OF(LOCALE_O))) \
goto unknown; \
} while (0)
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
int flags
Definition: tcltklib.c:3012
#define BIT_OF(n)

Referenced by rb_strftime_with_timespec().

#define FMT (   def_pad,
  def_prec,
  fmt,
  val 
)
Value:
do { \
int l; \
if (precision <= 0) precision = (def_prec); \
if (flags & BIT_OF(LEFT)) precision = 1; \
l = snprintf(s, endp - s, \
((padding == '0' || (!padding && (def_pad) == '0')) ? "%0*"fmt : "%*"fmt), \
precision, (val)); \
if (l < 0) goto err; \
s += l; \
} while (0)
VP_EXPORT int
Definition: bigdecimal.c:4911
parser parser_yylval val
Definition: ripper.c:14289
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
const char * fmt
Definition: tcltklib.c:837
while(a->frac[0]/shift==0)
Definition: bigdecimal.c:4978
int flags
Definition: tcltklib.c:3012
#define snprintf
Definition: subst.h:6
int err
Definition: win32.c:78
register char * s
Definition: os2.c:56
#define BIT_OF(n)

Referenced by rb_strftime_with_timespec().

#define FMTV (   def_pad,
  def_prec,
  fmt,
  val 
)
Value:
do { \
VALUE tmp = (val); \
if (FIXNUM_P(tmp)) { \
FMT((def_pad), (def_prec), "l"fmt, FIX2LONG(tmp)); \
} \
size_t l; \
if (precision <= 0) precision = (def_prec); \
if (flags & BIT_OF(LEFT)) precision = 1; \
args[0] = INT2FIX(precision); \
args[1] = (val); \
if (padding == '0' || (!padding && (def_pad) == '0')) \
result = rb_str_format(2, args, rb_str_new2("%0*"fmt)); \
else \
result = rb_str_format(2, args, rb_str_new2("%*"fmt)); \
l = strlcpy(s, StringValueCStr(result), endp-s); \
if ((size_t)(endp-s) <= l) \
goto err; \
s += l; \
} \
} while (0)
parser parser_yylval val
Definition: ripper.c:14289
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
unsigned long VALUE
Definition: ruby.h:88
#define FIXNUM_P(f)
Definition: ruby.h:338
VALUE VALUE args
Definition: tcltklib.c:2550
const char * fmt
Definition: tcltklib.c:837
while(a->frac[0]/shift==0)
Definition: bigdecimal.c:4978
int flags
Definition: tcltklib.c:3012
int err
Definition: win32.c:78
q result
Definition: tcltklib.c:7059
VALUE rb_str_format(int, const VALUE *, VALUE)
Definition: sprintf.c:439
register char * s
Definition: os2.c:56
RUBY_EXTERN size_t strlcpy(char *, const char *, size_t)
else
Definition: bigdecimal.c:1150
#define StringValueCStr(v)
Definition: ruby.h:468
#define INT2FIX(i)
Definition: ruby.h:225
#define FMT(def_pad, def_prec, fmt, val)
#define BIT_OF(n)
#define FIX2LONG(x)
Definition: ruby.h:336
VALUE rb_str_new2(const char *)

Referenced by rb_strftime_with_timespec().

#define ISO_DATE_EXT   1 /* %G and %g for year of ISO week */

Definition at line 75 of file strftime.c.

#define MAILHEADER_EXT   1 /* add %z for HHMM format */

Definition at line 74 of file strftime.c.

#define mod (   x,
 
)    (rb_funcall((x), '%', 1, (y)))

Definition at line 166 of file strftime.c.

Referenced by rb_strftime_with_timespec(), and vtm2tm_noyear().

#define mul (   x,
 
)    (rb_funcall((x), '*', 1, (y)))

Definition at line 163 of file strftime.c.

Referenced by rb_strftime_with_timespec().

#define NEEDS (   n)    do if (s >= endp || (n) >= endp - s - 1) goto err; while (0)
#define POSIX2_DATE   1 /* stuff in Posix 1003.2 date command */

Definition at line 72 of file strftime.c.

#define quo (   x,
 
)    (rb_funcall((x), rb_intern("quo"), 1, (y)))

Definition at line 164 of file strftime.c.

#define range (   low,
  item,
  hi 
)    max((low), min((item), (hi)))

Definition at line 123 of file strftime.c.

Referenced by rb_strftime_with_timespec().

#define STRFTIME (   fmt)
Value:
do { \
i = rb_strftime_with_timespec(s, endp - s, (fmt), vtm, timev, ts, gmt); \
if (!i) return 0; \
if (precision > i) {\
NEEDS(precision); \
memmove(s + precision - i, s, i);\
memset(s, padding ? padding : ' ', precision - i); \
s += precision; \
}\
else s += i; \
} while (0)
#define NEEDS(n)
static size_t rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, const struct vtm *vtm, VALUE timev, struct timespec *ts, int gmt)
Definition: strftime.c:171
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
const char * fmt
Definition: tcltklib.c:837
RUBY_EXTERN void * memmove(void *, const void *, size_t)
Definition: memmove.c:7
memset(y->frac+ix+1, 0,(y->Prec-(ix+1))*sizeof(BDIGIT))
Definition: timev.h:4
register char * s
Definition: os2.c:56
else
Definition: bigdecimal.c:1150
return
Definition: name2ctype.h:23857
ssize_t i
Definition: bigdecimal.c:5519

Referenced by rb_strftime_with_timespec().

#define sub (   x,
 
)    (rb_funcall((x), '-', 1, (y)))

Definition at line 162 of file strftime.c.

Referenced by rb_strftime_with_timespec().

#define SUNOS_EXT   1 /* stuff in SunOS strftime routine */

Definition at line 71 of file strftime.c.

#define SYSV_EXT   1 /* stuff in System V ascftime routine */

Definition at line 70 of file strftime.c.

#define VMS_EXT   1 /* include %v for VMS date format */

Definition at line 73 of file strftime.c.

Function Documentation

char* getenv ( )
if ( timeptr->  tm_mon = = 11)

Definition at line 934 of file strftime.c.

if ( firstweekday  = = 1)

Definition at line 986 of file strftime.c.

static int iso8601wknum_v ( const struct vtm vtm)
static

Definition at line 960 of file strftime.c.

References vtm2tm_noyear().

Referenced by rb_strftime_with_timespec().

void* malloc ( )
size_t rb_strftime ( char *  s,
size_t  maxsize,
const char *  format,
const struct vtm vtm,
VALUE  timev,
int  gmt 
)

Definition at line 792 of file strftime.c.

References NULL, and rb_strftime_with_timespec().

Referenced by rb_strftime_alloc().

size_t rb_strftime_timespec ( char *  s,
size_t  maxsize,
const char *  format,
const struct vtm vtm,
struct timespec ts,
int  gmt 
)

Definition at line 798 of file strftime.c.

References Qnil, and rb_strftime_with_timespec().

Referenced by rb_strftime_alloc().

static size_t rb_strftime_with_timespec ( char *  s,
size_t  maxsize,
const char *  format,
const struct vtm vtm,
VALUE  timev,
struct timespec ts,
int  gmt 
)
static
void* realloc ( )
char* strchr ( )
switch ( jan1day  )

Definition at line 904 of file strftime.c.

References timeptr.

static void vtm2tm_noyear ( const struct vtm vtm,
struct tm *  result 
)
static
static int weeknumber ( )
static

Referenced by weeknumber_v().

static int weeknumber_v ( )
static
static int weeknumber_v ( const struct vtm vtm,
int  firstweekday 
)
static

Definition at line 999 of file strftime.c.

References vtm2tm_noyear(), and weeknumber().

Variable Documentation

int int a
inlinestatic
Initial value:
{
return (a < b ? a : b)
Real * b
Definition: bigdecimal.c:1140
Real * a
Definition: bigdecimal.c:1140

Definition at line 132 of file strftime.c.

int int b
inlinestatic

Definition at line 132 of file strftime.c.

int firstweekday

Definition at line 977 of file strftime.c.

jan1day = timeptr->tm_wday - (timeptr->tm_yday % 7)

Definition at line 887 of file strftime.c.

return ret
Initial value:
{
int wday = timeptr->tm_wday
static int struct tm * timeptr
Definition: strftime.c:849

Definition at line 982 of file strftime.c.

static int struct tm * timeptr
static

Definition at line 849 of file strftime.c.

Referenced by switch().

return weeknum = weeknumber(timeptr, 1)

Definition at line 872 of file strftime.c.

int long year
static