pike.git / src / opcodes.c

version» Context lines:

pike.git/src/opcodes.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: opcodes.c,v 1.138 2003/02/11 16:16:01 grubba Exp $ + || $Id: opcodes.c,v 1.139 2003/02/13 13:53:08 grubba Exp $   */      #include "global.h"   #include <errno.h>   #include <math.h>   #include <ctype.h>   #include "interpret.h"   #include "svalue.h"   #include "array.h"   #include "stralloc.h"
pike.git/src/opcodes.c:23:   #include "fd_control.h"   #include "cyclic.h"   #include "builtin_functions.h"   #include "module_support.h"   #include "security.h"   #include "bignum.h"   #include "operators.h"      #define sp Pike_sp    - RCSID("$Id: opcodes.c,v 1.138 2003/02/11 16:16:01 grubba Exp $"); + RCSID("$Id: opcodes.c,v 1.139 2003/02/13 13:53:08 grubba Exp $");      void index_no_free(struct svalue *to,struct svalue *what,struct svalue *ind)   {    INT32 i;      #ifdef PIKE_SECURITY    if(what->type <= MAX_COMPLEX)    if(!CHECK_DATA_SECURITY(what->u.array, SECURITY_BIT_INDEX))    Pike_error("Index permission denied.\n");   #endif
pike.git/src/opcodes.c:856:    sp[-2]=sp[-1];    sp--;    dmalloc_touch_svalue(sp);   }         /*    * helper functions for sscanf %O    */    - static int pcharp_extract_char_const(PCHARP str, -  PCHARP *dstr, -  ptrdiff_t maxlength, -  ptrdiff_t *dmaxlength) + /* Calling convention: +  * val: Integer to fill in. +  * str: string to parse. +  * len: length of the string. +  * +  * Returns: +  * NULL on failure. +  * continuation point in str on success. +  */ + static void *pcharp_extract_char_const(INT_TYPE *val, +  PCHARP str, ptrdiff_t len)   {    int c;    -  *dstr=str; -  *dmaxlength=maxlength-1; -  +     /* use of macros to keep similar to lexer.h: char_const */ - #define LOOK() (maxlength?INDEX_PCHARP(str,1):0) - #define GETC() (maxlength?(INC_PCHARP(str,1),maxlength--,EXTRACT_PCHARP(str)):0) + #define LOOK() (len>0?EXTRACT_PCHARP(str):0) + #define GETC() ((len > 0)?(INC_PCHARP(str, 1), len--, INDEX_PCHARP(str, -1)):0)       switch (c=GETC())    {    case 0: -  *dmaxlength=maxlength+1; -  *dstr=str; -  return 0; -  case '\\': -  return '\\'; +  return NULL;    -  +  case '\n': return NULL; /* Newline in character constant. */ +  +  case 'a': c = 7; break; /* BEL */ +  case 'b': c = 8; break; /* BS */ +  case 't': c = 9; break; /* HT */ +  case 'n': c = 10; break; /* LF */ +  case 'v': c = 11; break; /* VT */ +  case 'f': c = 12; break; /* FF */ +  case 'r': c = 13; break; /* CR */ +  case 'e': c = 27; break; /* ESC */ +     case '0': case '1': case '2': case '3':    case '4': case '5': case '6': case '7': -  +  /* Octal escape. */    c-='0';    while(LOOK()>='0' && LOOK()<='8')    c=c*8+(GETC()-'0');    break;    -  case 'a': return 7; /* BEL */ -  case 'b': return 8; /* BS */ -  case 't': return 9; /* HT */ -  case 'n': return 10; /* LF */ -  case 'v': return 11; /* VT */ -  case 'f': return 12; /* FF */ -  case 'r': return 13; /* CR */ -  case 'e': return 27; /* ESC */ -  -  case '\n': return '\n'; -  +     case 'x': -  +  /* Hexadecimal escape. */    c=0;    while(1)    {    switch(LOOK())    {    case '0': case '1': case '2': case '3':    case '4': case '5': case '6': case '7':    case '8': case '9':    c=c*16+GETC()-'0';    continue;
pike.git/src/opcodes.c:922:       case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':    c=c*16+GETC()-'A'+10;    continue;    }    break;    }    break;       case 'd': +  /* Decimal escape. */    c=0;    while(1)    {    switch(LOOK())    {    case '0': case '1': case '2': case '3':    case '4': case '5': case '6': case '7':    case '8': case '9':    c=c*10+GETC()-'0';    continue;    }    break;    }    break;   #undef LOOK   #undef GETC    } -  *dmaxlength=maxlength; -  *dstr=str; -  return c; +  *val = c; +  return str.ptr;   }    - static int pcharp_to_svalue_percent_o(struct svalue *r, + /* Calling convention: +  * res: svalue to fill in. +  * str: string to parse. +  * len: length of the string. +  * +  * Returns: +  * NULL on failure. +  * continuation point in str on success. +  */ + static void *pcharp_to_svalue_percent_o(struct svalue *res,    PCHARP str, -  PCHARP *dstr, -  ptrdiff_t maxlength) +  ptrdiff_t len)   { -  *dstr=str; /* default: no hit */ +  res->type = T_INT; +  res->subtype = NUMBER_UNDEFINED; +  res->u.integer = 0;    -  maxlength--; - /* calling convention: max_length <= 0 means no max length. */ -  -  for (;;) +  for (;len>0; INC_PCHARP(str, 1), len--)    {    switch (EXTRACT_PCHARP(str))    {    case ' ': /* whitespace */    case '\t':    case '\n':    case '\r':    break;       case '0': case '1': case '2': case '3': case '4':    case '5': case '6': case '7': case '8': case '9': -  +  {    /* fixme: grok floats */ -  return pcharp_to_svalue_inumber(r,str,dstr,0,maxlength+1); +  if (!pcharp_to_svalue_inumber(res, str, &str, 0, len)) { +  return NULL; +  } +  return str.ptr; +  }       case '\"':    {    struct string_builder tmp; -  +  PCHARP start; +  int cnt;    init_string_builder(&tmp,0); -  for (;;) +  +  INC_PCHARP(str, 1); /* Skip the quote. */ +  len--; +  +  start = str; +  cnt = 0; +  for (;len;)    { -  PCHARP start; -  int len=0; -  INC_PCHARP(str,1); -  start=str; -  for (;;) +  switch(EXTRACT_PCHARP(str))    { -  if (!maxlength) -  { -  free_string_builder(&tmp); -  return 0; /* end of data */ -  } -  maxlength--; -  switch (EXTRACT_PCHARP(str)) -  { +     case '\"': -  case 0: +  /* End of string -- done. */ +  INC_PCHARP(str, 1); /* Skip the quote. */ +  +  if (cnt) string_builder_append(&tmp, start, cnt); +  res->type=T_STRING; +  res->subtype=0; +  res->u.string=finish_string_builder(&tmp); +  return str.ptr; +     case '\\': -  +  { +  /* Escaped character */ +  INT_TYPE val; +  +  if (cnt) string_builder_append(&tmp, start, cnt); +  INC_PCHARP(str, 1); +  len--; +  start.ptr = pcharp_extract_char_const(&val, str, len); +  if (!start.ptr) break; +  string_builder_putchar(&tmp, val); +  +  /* Continue parsing after the escaped character. */ +  len -= LOW_SUBTRACT_PCHARP(start, str); +  cnt = 0; +  str = start; +  } +  continue; +  +  case '\n': +  /* Newline in string -- fail. */    break; -  +     default: -  len++; -  INC_PCHARP(str,1); +  len--; +  cnt++; +  INC_PCHARP(str, 1);    continue;    }    break;    } -  if (len) string_builder_append(&tmp, start, len); -  -  switch (EXTRACT_PCHARP(str)) -  { -  case '\"': -  INC_PCHARP(str,1); -  *dstr=str; -  r->type=T_STRING; -  r->subtype=0; -  r->u.string=finish_string_builder(&tmp); -  return 1; -  case 0: /* abort on NUL */ +  /* Unterminated string -- fail. */    free_string_builder(&tmp); -  return 0; -  case '\\': -  if (maxlength) -  { -  INC_PCHARP(str,1); -  -  string_builder_putchar( -  &tmp, -  pcharp_extract_char_const(str,&str, -  maxlength+1,&maxlength)); -  break; +  return NULL; /* end of data */    } -  break; -  } -  } +        case '\'': -  if (maxlength<0 || -  maxlength>2) +  if (len>2)    { -  r->subtype=0; -  r->type=T_INT; +  INC_PCHARP(str, 1); /* Skip the quote. */    -  INC_PCHARP(str,1); -  r->u.integer=EXTRACT_PCHARP(str); -  INC_PCHARP(str,1); -  if (r->u.integer=='\\') +  res->subtype=0; +  res->type=T_INT; +  res->u.integer = EXTRACT_PCHARP(str); +  INC_PCHARP(str, 1); +  +  len -= 2; +  +  if (res->u.integer == '\\')    { -  r->u.integer= -  pcharp_extract_char_const(str,&str, -  maxlength+1,&maxlength); -  INC_PCHARP(str,1); -  maxlength--; +  PCHARP tmp; +  tmp.ptr = pcharp_extract_char_const(&res->u.integer, str, len); +  if (!tmp.ptr) return NULL; +  tmp.shift = str.shift; +  len -= LOW_SUBTRACT_PCHARP(tmp, str); +  str.ptr = tmp.ptr;    } -  if (!maxlength || EXTRACT_PCHARP(str)!='\'') -  return 0; -  INC_PCHARP(str,1); /* skip that ending quote */ -  -  *dstr=str; -  return 1; +  if (!len || (EXTRACT_PCHARP(str) != '\'')) +  return NULL; +  INC_PCHARP(str, 1); /* Skip the ending quote. */ +  return str.ptr;    } -  return 0; +  return NULL;       /* fixme: arrays, multisets, mappings */    } -  -  default: -  /* unknown */ -  return 0; +     } -  if (!maxlength) return 0; /* end of data */ -  INC_PCHARP(str,1); -  maxlength--; +  return NULL;   } - } +       /*    flags:    *    operators:    %d    %s    %f    %c    %n
pike.git/src/opcodes.c:1965:    } \    if(set.a) { free_array(set.a); set.a=0; } \    sval.type=T_STRING; \    DO_IF_CHECKER(sval.subtype=0); \    sval.u.string=PIKE_CONCAT(make_shared_binary_string, \    INPUT_SHIFT)(input+e,eye-e); \    break; \    \    case 'O': \    { \ -  PIKE_CONCAT(p_wchar, INPUT_SHIFT) *t; \ -  PCHARP tmp; \ +  PIKE_CONCAT(p_wchar, INPUT_SHIFT) *cont; \    if(eye>=input_len) \    { \    chars_matched[0]=eye; \    return matches; \    } \ -  +  if ((field_length == -1) || \ +  ((input_len - eye) < field_length)) \ +  field_length = input_len - eye; \    \ -  +  cont = \    pcharp_to_svalue_percent_o(&sval, \ -  MKPCHARP(input+eye,INPUT_SHIFT), \ -  &tmp, \ +  MKPCHARP(input+eye, INPUT_SHIFT), \    field_length); \ -  t=(PIKE_CONCAT(p_wchar, INPUT_SHIFT) *)tmp.ptr; \ -  if(input + eye == t) \ +  if(!cont) \    { \    chars_matched[0]=eye; \    return matches; \    } \ -  eye=t-input; \ +  eye = cont-input; \    \    break; \    } \    \    case 'n': \    sval.type=T_INT; \    sval.subtype=NUMBER_NUMBER; \    sval.u.integer=TO_INT32(eye); \    break; \    \