Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

pack.c File Reference

#include "ruby.h"
#include <sys/types.h>
#include <ctype.h>

Go to the source code of this file.

Defines

#define SIZE16   2
#define SIZE32   4
#define NATINT_LEN(type, len)   sizeof(type)
#define NATINT_HTOVS(x)   htovs(x)
#define NATINT_HTOVL(x)   htovl(x)
#define NATINT_HTONS(x)   htons(x)
#define NATINT_HTONL(x)   htonl(x)
#define OFF16(p)   (char*)(p)
#define OFF32(p)   (char*)(p)
#define OFF16B(p)   (char*)(p)
#define OFF32B(p)   (char*)(p)
#define define_swapx(x, xtype)
#define swap16(x)   ((((x)&0xFF)<<8) | (((x)>>8)&0xFF))
#define swaps(x)   swap16(x)
#define swap32(x)
#define swapl(x)   swap32(x)
#define swapf(x)   swapl(x)
#define FLOAT_SWAPPER   unsigned long
#define ntohs(x)   swaps(x)
#define ntohl(x)   swapl(x)
#define htons(x)   swaps(x)
#define htonl(x)   swapl(x)
#define ntohf(x)   swapf(x)
#define ntohd(x)   swapd(x)
#define htonf(x)   swapf(x)
#define htond(x)   swapd(x)
#define htovs(x)   (x)
#define htovl(x)   (x)
#define htovf(x)   (x)
#define htovd(x)   (x)
#define vtohs(x)   (x)
#define vtohl(x)   (x)
#define vtohf(x)   (x)
#define vtohd(x)   (x)
#define FLOAT_CONVWITH(y)   FLOAT_SWAPPER y;
#define HTONF(x, y)
#define HTOVF(x, y)
#define NTOHF(x, y)
#define VTOHF(x, y)
#define DOUBLE_CONVWITH(y)
#define HTOND(x, y)   htond(x)
#define HTOVD(x, y)   htovd(x)
#define NTOHD(x, y)   ntohd(x)
#define VTOHD(x, y)   vtohd(x)
#define EXTEND32(x)
#define EXTEND16(x)
#define QUAD_SIZE   sizeof(LONG_LONG)
#define THISFROM   RARRAY(ary)->ptr[idx]
#define NEXTFROM   (items-- > 0 ? RARRAY(ary)->ptr[idx++] : (rb_raise(rb_eArgError, toofew),0))
#define PACK_LENGTH_ADJUST_SIZE(sz)
#define PACK_LENGTH_ADJUST(type, sz)   PACK_LENGTH_ADJUST_SIZE(sizeof(type))
#define PACK_ITEM_ADJUST()   while (tmp--) rb_ary_push(ary, Qnil)
#define BYTEWIDTH   8

Functions

double swapd (double d) const
unsigned long rb_big2ulong_pack (VALUE x)
unsigned long num2i32 (VALUE x)
void encodes (VALUE, char *, long, int)
void qpencode (VALUE, VALUE, long)
int uv_to_utf8 (char *, unsigned long)
unsigned long utf8_to_uv (char *, long *)
VALUE pack_pack (VALUE ary, VALUE fmt)
int hex2num (char c)
VALUE infected_str_new (char *ptr, long len, VALUE str) const
VALUE pack_unpack (VALUE str, VALUE fmt)
void Init_pack ()

Variables

char * toofew = "too few arguments"
char uu_table []
char b64_table []
char hex_table [] = "0123456789ABCDEF"
const unsigned long utf8_limits []


Define Documentation

#define BYTEWIDTH   8
 

Definition at line 1990 of file pack.c.

Referenced by is_in_list_sbc(), print_mbc(), print_partial_compiled_pattern(), re_compile_fastmap(), and re_compile_pattern().

#define define_swapx x,
xtype   ) 
 

Value:

static xtype                            \
TOKEN_PASTE(swap,x)(z)                  \
    xtype z;                            \
{                                       \
    xtype r;                            \
    xtype *zp;                          \
    unsigned char *s, *t;               \
    int i;                              \
                                        \
    zp = malloc(sizeof(xtype));         \
    *zp = z;                            \
    s = (unsigned char*)zp;             \
    t = malloc(sizeof(xtype));          \
    for (i=0; i<sizeof(xtype); i++) {   \
        t[sizeof(xtype)-i-1] = s[i];    \
    }                                   \
    r = *(xtype *)t;                    \
    free(t);                            \
    free(zp);                           \
    return r;                           \
}

Definition at line 53 of file pack.c.

#define DOUBLE_CONVWITH  ) 
 

Definition at line 327 of file pack.c.

Referenced by pack_pack(), and pack_unpack().

#define EXTEND16  ) 
 

Definition at line 357 of file pack.c.

Referenced by pack_unpack().

#define EXTEND32  ) 
 

Definition at line 351 of file pack.c.

Referenced by pack_unpack().

#define FLOAT_CONVWITH  )     FLOAT_SWAPPER y;
 

Definition at line 283 of file pack.c.

Referenced by pack_pack(), and pack_unpack().

#define FLOAT_SWAPPER   unsigned long
 

Definition at line 118 of file pack.c.

#define HTOND x,
 )     htond(x)
 

Definition at line 328 of file pack.c.

Referenced by pack_pack().

#define htond  )     swapd(x)
 

Definition at line 264 of file pack.c.

#define HTONF x,
 ) 
 

Value:

(memcpy(&y,&x,sizeof(float)),   \
                         y = htonf((FLOAT_SWAPPER)y),   \
                         memcpy(&x,&y,sizeof(float)),   \
                         x)

Definition at line 284 of file pack.c.

Referenced by pack_pack().

#define htonf  )     swapf(x)
 

Definition at line 263 of file pack.c.

#define htonl  )     swapl(x)
 

Definition at line 260 of file pack.c.

#define htons  )     swaps(x)
 

Definition at line 259 of file pack.c.

#define HTOVD x,
 )     htovd(x)
 

Definition at line 329 of file pack.c.

Referenced by pack_pack().

#define htovd  )     (x)
 

Definition at line 268 of file pack.c.

#define HTOVF x,
 ) 
 

Value:

(memcpy(&y,&x,sizeof(float)),   \
                         y = htovf((FLOAT_SWAPPER)y),   \
                         memcpy(&x,&y,sizeof(float)),   \
                         x)

Definition at line 288 of file pack.c.

Referenced by pack_pack().

#define htovf  )     (x)
 

Definition at line 267 of file pack.c.

#define htovl  )     (x)
 

Definition at line 266 of file pack.c.

#define htovs  )     (x)
 

Definition at line 265 of file pack.c.

#define NATINT_HTONL  )     htonl(x)
 

Definition at line 41 of file pack.c.

Referenced by pack_pack().

#define NATINT_HTONS  )     htons(x)
 

Definition at line 40 of file pack.c.

Referenced by pack_pack().

#define NATINT_HTOVL  )     htovl(x)
 

Definition at line 39 of file pack.c.

Referenced by pack_pack().

#define NATINT_HTOVS  )     htovs(x)
 

Definition at line 38 of file pack.c.

Referenced by pack_pack().

#define NATINT_LEN type,
len   )     sizeof(type)
 

Definition at line 37 of file pack.c.

Referenced by pack_pack(), and pack_unpack().

#define NEXTFROM   (items-- > 0 ? RARRAY(ary)->ptr[idx++] : (rb_raise(rb_eArgError, toofew),0))
 

Referenced by pack_pack().

#define NTOHD x,
 )     ntohd(x)
 

Definition at line 330 of file pack.c.

Referenced by pack_unpack().

#define ntohd  )     swapd(x)
 

Definition at line 262 of file pack.c.

#define NTOHF x,
 ) 
 

Value:

(memcpy(&y,&x,sizeof(float)),   \
                         y = ntohf((FLOAT_SWAPPER)y),   \
                         memcpy(&x,&y,sizeof(float)),   \
                         x)

Definition at line 292 of file pack.c.

Referenced by pack_unpack().

#define ntohf  )     swapf(x)
 

Definition at line 261 of file pack.c.

#define ntohl  )     swapl(x)
 

Definition at line 258 of file pack.c.

Referenced by pack_unpack().

#define ntohs  )     swaps(x)
 

Definition at line 257 of file pack.c.

Referenced by pack_unpack().

#define OFF16  )     (char*)(p)
 

Definition at line 45 of file pack.c.

Referenced by pack_pack(), and pack_unpack().

#define OFF16B  )     (char*)(p)
 

Definition at line 49 of file pack.c.

Referenced by pack_unpack().

#define OFF32  )     (char*)(p)
 

Definition at line 46 of file pack.c.

Referenced by pack_pack(), and pack_unpack().

#define OFF32B  )     (char*)(p)
 

Definition at line 50 of file pack.c.

Referenced by pack_unpack().

 
#define PACK_ITEM_ADJUST  )     while (tmp--) rb_ary_push(ary, Qnil)
 

Definition at line 1149 of file pack.c.

Referenced by pack_unpack().

#define PACK_LENGTH_ADJUST type,
sz   )     PACK_LENGTH_ADJUST_SIZE(sizeof(type))
 

Definition at line 1145 of file pack.c.

Referenced by pack_unpack().

#define PACK_LENGTH_ADJUST_SIZE sz   ) 
 

Value:

do {    \
    tmp = 0;                                    \
    if (len > (send-s)/sz) {                    \
        if (!star) {                            \
            tmp = len-(send-s)/sz;              \
        }                                       \
        len = (send-s)/sz;                      \
    }                                           \
} while (0)

Definition at line 1129 of file pack.c.

Referenced by pack_unpack().

#define QUAD_SIZE   sizeof(LONG_LONG)
 

Definition at line 363 of file pack.c.

Referenced by pack_pack(), and pack_unpack().

#define SIZE16   2
 

Definition at line 17 of file pack.c.

#define SIZE32   4
 

Definition at line 18 of file pack.c.

#define swap16  )     ((((x)&0xFF)<<8) | (((x)>>8)&0xFF))
 

Definition at line 77 of file pack.c.

#define swap32  ) 
 

Value:

((((x)&0xFF)<<24)       \
                        |(((x)>>24)&0xFF)       \
                        |(((x)&0x0000FF00)<<8)  \
                        |(((x)&0x00FF0000)>>8)  )

Definition at line 93 of file pack.c.

#define swapf  )     swapl(x)
 

Definition at line 117 of file pack.c.

#define swapl  )     swap32(x)
 

Definition at line 99 of file pack.c.

Referenced by swapd().

#define swaps  )     swap16(x)
 

Definition at line 80 of file pack.c.

#define THISFROM   RARRAY(ary)->ptr[idx]
 

Referenced by pack_pack().

#define VTOHD x,
 )     vtohd(x)
 

Definition at line 331 of file pack.c.

Referenced by pack_unpack().

#define vtohd  )     (x)
 

Definition at line 272 of file pack.c.

#define VTOHF x,
 ) 
 

Value:

(memcpy(&y,&x,sizeof(float)),   \
                         y = vtohf((FLOAT_SWAPPER)y),   \
                         memcpy(&x,&y,sizeof(float)),   \
                         x)

Definition at line 296 of file pack.c.

Referenced by pack_unpack().

#define vtohf  )     (x)
 

Definition at line 271 of file pack.c.

#define vtohl  )     (x)
 

Definition at line 270 of file pack.c.

Referenced by pack_unpack().

#define vtohs  )     (x)
 

Definition at line 269 of file pack.c.

Referenced by pack_unpack().


Function Documentation

void encodes VALUE  ,
char *  ,
long  ,
int 
[static]
 

Definition at line 1011 of file pack.c.

References ALLOCA_N, b64_table, rb_str_buf_cat(), uu_table, and VALUE.

Referenced by pack_pack().

int hex2num char  c  )  [inline, static]
 

Definition at line 1111 of file pack.c.

Referenced by pack_unpack().

VALUE infected_str_new char *  ptr,
long  len,
VALUE  str
const [static]
 

Definition at line 1152 of file pack.c.

References OBJ_INFECT, rb_str_new(), and VALUE.

Referenced by pack_unpack().

void Init_pack void   ) 
 

Definition at line 2102 of file pack.c.

References pack_pack(), pack_unpack(), rb_cArray, rb_cString, and rb_define_method().

Referenced by rb_call_inits().

unsigned long num2i32 VALUE  x  )  [static]
 

Definition at line 337 of file pack.c.

References FIX2LONG, FIXNUM_P, rb_big2ulong_pack(), rb_eTypeError, rb_obj_classname(), rb_raise(), rb_to_int(), T_BIGNUM, TYPE, and VALUE.

Referenced by pack_pack().

VALUE pack_pack VALUE  ary,
VALUE  fmt
[static]
 

Definition at line 441 of file pack.c.

References DOUBLE_CONVWITH, encodes(), FLOAT_CONVWITH, HTOND, HTONF, HTOVD, HTOVF, ISALPHA, ISDIGIT, ISSPACE, NATINT_HTONL, NATINT_HTONS, NATINT_HTOVL, NATINT_HTOVS, NATINT_LEN, NEXTFROM, NIL_P, num2i32(), NUM2INT, NUM2LONG, OBJ_INFECT, OFF16, OFF32, qpencode(), QUAD_SIZE, RARRAY, rb_ary_new(), rb_ary_push(), rb_big_divmod(), rb_eArgError, rb_eRangeError, rb_eRuntimeError, rb_Float(), rb_obj_as_string(), rb_quad_pack(), rb_raise(), rb_str_associate(), rb_str_buf_cat(), rb_str_buf_new(), rb_str_new(), rb_to_int(), rb_uint2big(), RFLOAT, RSTRING, strchr(), StringValue, StringValuePtr, strtoul(), T_BIGNUM, THISFROM, TYPE, uv_to_utf8(), and VALUE.

Referenced by Init_pack().

VALUE pack_unpack VALUE  str,
VALUE  fmt
[static]
 

Definition at line 1302 of file pack.c.

References b64_table, DOUBLE_CONVWITH, end, EXTEND16, EXTEND32, FLOAT_CONVWITH, hex2num(), infected_str_new(), INT2FIX, INT2NUM, ISDIGIT, ISSPACE, LONG2NUM, NATINT_LEN, NTOHD, NTOHF, ntohl, ntohs, OBJ_INFECT, OFF16, OFF16B, OFF32, OFF32B, PACK_ITEM_ADJUST, PACK_LENGTH_ADJUST, PACK_LENGTH_ADJUST_SIZE, Qnil, QUAD_SIZE, RARRAY, rb_ary_new(), rb_ary_push(), rb_big_mul(), rb_big_plus(), rb_eArgError, rb_float_new(), rb_quad_unpack(), rb_raise(), rb_str_associated(), rb_str_new(), rb_str_new2(), rb_tainted_str_new(), rb_uint2big(), RSTRING, strchr(), StringValue, strtoul(), T_STRING, TYPE, UINT2NUM, ULONG2NUM, utf8_to_uv(), VALUE, VTOHD, VTOHF, vtohl, and vtohs.

Referenced by Init_pack().

void qpencode VALUE  ,
VALUE  ,
long 
[static]
 

Definition at line 1056 of file pack.c.

References hex_table, rb_str_buf_cat(), RSTRING, and VALUE.

Referenced by pack_pack().

unsigned long rb_big2ulong_pack VALUE  x  ) 
 

Definition at line 750 of file bignum.c.

References big2ulong(), RBIGNUM, and VALUE.

Referenced by num2i32().

double swapd double  d  )  const [static]
 

Definition at line 138 of file pack.c.

References swapl.

unsigned long utf8_to_uv char *  ,
long * 
[static]
 

Definition at line 2050 of file pack.c.

References rb_eArgError, rb_raise(), and utf8_limits.

Referenced by pack_unpack().

int uv_to_utf8 char *  ,
unsigned  long
[static]
 

Definition at line 1993 of file pack.c.

References rb_eRangeError, and rb_raise().

Referenced by pack_pack().


Variable Documentation

char b64_table[] [static]
 

Initial value:

"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

Definition at line 1007 of file pack.c.

Referenced by encodes(), and pack_unpack().

char hex_table[] = "0123456789ABCDEF" [static]
 

Definition at line 1053 of file pack.c.

Referenced by qpencode().

char* toofew = "too few arguments" [static]
 

Definition at line 367 of file pack.c.

const unsigned long utf8_limits[] [static]
 

Initial value:

 {
    0x0,                        
    0x80,                       
    0x800,                      
    0x10000,                    
    0x200000,                   
    0x4000000,                  
    0x80000000,                 
}

Definition at line 2039 of file pack.c.

Referenced by utf8_to_uv().

char uu_table[] [static]
 

Initial value:

"`!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"

Definition at line 1005 of file pack.c.

Referenced by encodes().


Generated on Wed Jan 18 23:32:10 2006 for Ruby by doxygen 1.3.5