pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: builtin_functions.c,v 1.530 2004/02/03 22:00:07 grubba Exp $ + || $Id: builtin_functions.c,v 1.531 2004/02/29 03:41:37 mast Exp $   */      #include "global.h" - RCSID("$Id: builtin_functions.c,v 1.530 2004/02/03 22:00:07 grubba Exp $"); + RCSID("$Id: builtin_functions.c,v 1.531 2004/02/29 03:41:37 mast Exp $");   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"   #include "object.h"   #include "program.h"   #include "array.h"   #include "pike_error.h"   #include "constants.h"   #include "mapping.h"   #include "stralloc.h"
pike.git/src/builtin_functions.c:1650:    *! @seealso    *! @[Locale.Charset.encoder()], @[string_to_unicode()],    *! @[unicode_to_string()], @[utf8_to_string()]    */   PMOD_EXPORT void f_string_to_utf8(INT32 args)   {    ptrdiff_t len;    struct pike_string *in;    struct pike_string *out;    ptrdiff_t i,j; -  int extended = 0; +  INT_TYPE extended = 0;    -  get_all_args("string_to_utf8", args, "%W", &in); +  get_all_args("string_to_utf8", args, "%W.%i", &in, &extended);    -  if (args > 1) { -  if (Pike_sp[1-args].type != T_INT) { -  SIMPLE_BAD_ARG_ERROR("string_to_utf8", 2, "int|void"); -  } -  extended = Pike_sp[1-args].u.integer; -  } -  +     len = in->len;       for(i=0; i < in->len; i++) {    unsigned INT32 c = index_shared_string(in, i);    if (c & ~0x7f) {    /* 8bit or more. */    len++;    if (c & ~0x7ff) {    /* 12bit or more. */    len++;
pike.git/src/builtin_functions.c:1784:    *! @[Locale.Charset.encoder()], @[string_to_unicode()], @[string_to_utf8()],    *! @[unicode_to_string()]    */   PMOD_EXPORT void f_utf8_to_string(INT32 args)   {    struct pike_string *in;    struct pike_string *out;    int len = 0;    int shift = 0;    int i,j; -  int extended = 0; +  INT_TYPE extended = 0;    -  get_all_args("utf8_to_string", args, "%S", &in); +  get_all_args("utf8_to_string", args, "%S.%i", &in, &extended);    -  if (args > 1) { -  if (Pike_sp[1-args].type != T_INT) { -  SIMPLE_BAD_ARG_ERROR("utf8_to_string()", 2, "int|void"); -  } -  extended = Pike_sp[1-args].u.integer; -  } -  +     for(i=0; i < in->len; i++) {    unsigned int c = ((unsigned char *)in->str)[i];    len++;    if (c & 0x80) {    int cont = 0;    if ((c & 0xc0) == 0x80) {    Pike_error("utf8_to_string(): "    "Unexpected continuation block 0x%02x at index %d.\n",    c, i);    }
pike.git/src/builtin_functions.c:4460: Inside #if defined(HAVE_MKTIME)
   *!    *! On most systems, the supported range of dates are Dec 13, 1901    *! 20:45:52 UTC through Jan 19, 2038 03:14:07 UTC (inclusive).    *!    *! @seealso    *! @[time()], @[ctime()], @[localtime()], @[gmtime()]    */   PMOD_EXPORT void f_mktime (INT32 args)   {    INT_TYPE sec, min, hour, mday, mon, year; +  INT_TYPE isdst = -1, tz;    struct tm date;    int retval;       if (args<1)    SIMPLE_TOO_FEW_ARGS_ERROR("mktime", 1);       if(args == 1)    {    MEMSET(&date, 0, sizeof(date));   
pike.git/src/builtin_functions.c:4487: Inside #if defined(HAVE_MKTIME)
   push_text("timezone");    f_aggregate(8);    f_rows(2);    Pike_sp--;    dmalloc_touch_svalue(Pike_sp);    push_array_items(Pike_sp->u.array);       args=8;    }    -  get_all_args("mktime",args, "%i%i%i%i%i%i", -  &sec, &min, &hour, &mday, &mon, &year); +  get_all_args("mktime",args, "%i%i%i%i%i%i.%i%i", +  &sec, &min, &hour, &mday, &mon, &year, &isdst, &tz);       MEMSET(&date, 0, sizeof(date));    date.tm_sec=sec;    date.tm_min=min;    date.tm_hour=hour;    date.tm_mday=mday;    date.tm_mon=mon;    date.tm_year=year; -  +  date.tm_isdst=isdst;    -  if (args > 6) { -  if (Pike_sp[6-args].type != T_INT) { -  SIMPLE_BAD_ARG_ERROR("mktime", 6, "int"); -  } -  if (args > 7) { -  if (Pike_sp[7-args].type != T_INT) { -  SIMPLE_BAD_ARG_ERROR("mktime", 7, "int"); -  } -  } -  } -  -  if ((args > 6) && (Pike_sp[6-args].subtype == NUMBER_NUMBER)) -  { -  date.tm_isdst = Pike_sp[6-args].u.integer; -  } else { -  date.tm_isdst = -1; -  } -  +     /* date.tm_zone = NULL; */      #ifdef HAVE_GMTIME -  if((args > 7) && (Pike_sp[7-args].subtype == NUMBER_NUMBER)) +  if(args > 7)    {    /* UTC-relative time. Use my_timegm(). */    retval = my_timegm(&date);    if (retval == -1)    PIKE_ERROR("mktime", "Cannot convert.\n", Pike_sp, args); -  retval += Pike_sp[7-args].u.integer; +  retval += tz;    } else {   #endif /* HAVE_GMTIME */      #ifdef STRUCT_TM_HAS_GMTOFF    /* BSD-style */    date.tm_gmtoff = 0;   #else   #ifdef STRUCT_TM_HAS___TM_GMTOFF    /* Linux-style */    date.__tm_gmtoff = 0;   #else -  if((args > 7) && (Pike_sp[7-args].subtype == NUMBER_NUMBER)) +  if(args > 7)    {    /* Pre-adjust for the timezone.    *    * Note that pre-adjustment must be done on AIX for dates    * near Jan 1, 1970, sine AIX mktime(3) doesn't support    * negative time.    */ -  date.tm_sec += Pike_sp[7-args].u.integer +  date.tm_sec += tz   #ifdef HAVE_EXTERNAL_TIMEZONE    - timezone   #endif /* HAVE_EXTERNAL_TIMEZONE */    ;    }   #endif /* STRUCT_TM_HAS___TM_GMTOFF */   #endif /* STRUCT_TM_HAS_GMTOFF */       retval = mktime(&date);       if (retval == -1)    PIKE_ERROR("mktime", "Cannot convert.\n", Pike_sp, args);      #if defined(STRUCT_TM_HAS_GMTOFF) || defined(STRUCT_TM_HAS___TM_GMTOFF) -  if((args > 7) && (Pike_sp[7-args].subtype == NUMBER_NUMBER)) +  if(args > 7)    {    /* Post-adjust for the timezone.    *    * Note that tm_gmtoff has the opposite sign of timezone.    *    * Note also that it must be post-adjusted, since the gmtoff    * field is set by mktime(3).    */   #ifdef STRUCT_TM_HAS_GMTOFF -  retval += Pike_sp[7-args].u.integer + date.tm_gmtoff; +  retval += tz + date.tm_gmtoff;   #else -  retval += Pike_sp[7-args].u.integer + date.__tm_gmtoff; +  retval += tz + date.__tm_gmtoff;   #endif /* STRUCT_TM_HAS_GMTOFF */    }    -  if ((args > 6) && (Pike_sp[6-args].subtype == NUMBER_NUMBER) && -  (Pike_sp[6-args].u.integer != -1) && -  (Pike_sp[6-args].u.integer != date.tm_isdst)) { +  if ((isdst != -1) && (isdst != date.tm_isdst)) {    /* Some stupid libc's (Hi Linux!) don't accept that we've set isdst... */ -  retval += 3600 * (Pike_sp[6-args].u.integer - date.tm_isdst); +  retval += 3600 * (isdst - date.tm_isdst);    }   #endif /* STRUCT_TM_HAS_GMTOFF || STRUCT_TM_HAS___TM_GMTOFF */   #ifdef HAVE_GMTIME    }   #endif /* HAVE_GMTIME */       pop_n_elems(args);    push_int(retval);   }