Ruby  1.9.3p551(2014-11-13revision48407)
Macros | Functions
date_strftime.c File Reference
#include "ruby/ruby.h"
#include "date_tmx.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 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

void * malloc ()
 
void * realloc ()
 
char * getenv ()
 
char * strchr ()
 
static int min (int a, int b)
 
static int max (int a, int b)
 
static size_t date_strftime_with_tmx (char *s, size_t maxsize, const char *format, const struct tmx *tmx)
 
size_t date_strftime (char *s, size_t maxsize, const char *format, const struct tmx *tmx)
 

Macro Definition Documentation

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

Definition at line 93 of file date_strftime.c.

#define BIT_OF (   n)    (1U<<(n))
#define div (   x,
 
)    (rb_funcall((x), rb_intern("div"), 1, (y)))
#define FILL_PADDING (   i)
Value:
do { \
if (!(flags & BIT_OF(LEFT)) && precision > (i)) { \
NEEDS(precision); \
memset(s, padding ? padding : ' ', precision - (i)); \
s += precision - (i); \
} \
else { \
NEEDS(i); \
} \
} while (0);

Referenced by date_strftime_with_tmx(), and 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)

Referenced by date_strftime_with_tmx(), and 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)

Referenced by date_strftime_with_tmx(), and 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)); \
} \
else { \
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)

Referenced by date_strftime_with_tmx(), and rb_strftime_with_timespec().

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

Definition at line 75 of file date_strftime.c.

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

Definition at line 74 of file date_strftime.c.

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

Definition at line 165 of file date_strftime.c.

Referenced by date_strftime_with_tmx().

#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 date_strftime.c.

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

Definition at line 166 of file date_strftime.c.

#define range (   low,
  item,
  hi 
)    max((low), min((item), (hi)))
#define STRFTIME (   fmt)
Value:
do { \
i = date_strftime_with_tmx(s, endp - s, (fmt), tmx); \
if (!i) return 0; \
if (precision > i) {\
if (start + maxsize < s + precision) { \
errno = ERANGE; \
return 0; \
} \
memmove(s + precision - i, s, i);\
memset(s, padding ? padding : ' ', precision - i); \
s += precision; \
}\
else s += i; \
} while (0)

Referenced by date_strftime_with_tmx(), and rb_strftime_with_timespec().

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

Definition at line 164 of file date_strftime.c.

Referenced by rb_str_index_m(), rb_str_rindex_m(), and rb_str_substr().

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

Definition at line 71 of file date_strftime.c.

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

Definition at line 70 of file date_strftime.c.

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

Definition at line 73 of file date_strftime.c.

Function Documentation

size_t date_strftime ( char *  s,
size_t  maxsize,
const char *  format,
const struct tmx tmx 
)

Definition at line 807 of file date_strftime.c.

References date_strftime_with_tmx().

Referenced by date_strftime_alloc().

static size_t date_strftime_with_tmx ( char *  s,
size_t  maxsize,
const char *  format,
const struct tmx tmx 
)
static
char* getenv ( )
void* malloc ( )
static int max ( int  a,
int  b 
)
inlinestatic
static int min ( int  a,
int  b 
)
inlinestatic
void* realloc ( )
char* strchr ( )