pike.git / src / sscanf.c

version» Context lines:

pike.git/src/sscanf.c:1854:    check_all_args("array_sscanf",args,BIT_STRING, BIT_STRING,0);       i = low_sscanf(Pike_sp[-args].u.string, Pike_sp[1-args].u.string);       a = aggregate_array(Pike_sp - save_sp);    pop_n_elems(args);    push_array(a);   }      static void push_sscanf_argument_types(PCHARP format, ptrdiff_t format_len, -  int cnt) +  int cnt, struct mapping *state)   {    for(; cnt < format_len; cnt++)    {    int no_assign=0;       while((cnt<format_len) && (INDEX_PCHARP(format, cnt) != '%'))    cnt++;    cnt++;    if (cnt >= format_len) break;   
pike.git/src/sscanf.c:1913:    switch(INDEX_PCHARP(format, e+1))    {    case '%': e++; break;    case '}': depth--; break;    case '{': depth++; break;    }    }    }    if (!no_assign) {    type_stack_mark(); -  push_sscanf_argument_types(format, e, cnt+1); +  push_sscanf_argument_types(format, e, cnt+1, state);    if (!(depth = pop_stack_mark())) {    push_type(PIKE_T_ZERO);    } else {    /* Join the argument types. */    while (depth > 1) {    push_type(T_OR);    depth--;    }    }    push_unlimited_array_type(PIKE_T_ARRAY);
pike.git/src/sscanf.c:2013:    0, "Error in sscanf format string.");    break;    }    ch = INDEX_PCHARP(format, cnt);    }    }    /* FALLTHRU */    case 's':    case 'H':    if (!no_assign) { -  /* FIXME: Use the type of the input string. */ +  struct svalue *s = +  simple_mapping_string_lookup(state, "sscanf_input"); +  if (s && (TYPEOF(*s) == PIKE_T_TYPE)) { +  /* Use the type of the input string. */ +  push_finished_type(s->u.type); +  } else {    push_finished_type(string_type_string);    } -  +  }    break;       case 'F':    case 'f':    if (!no_assign)    push_finished_type(float_type_string);    break;       break;   
pike.git/src/sscanf.c:2049:    }    }   }      void f___handle_sscanf_format(INT32 args)   {    struct pike_type *res;    struct pike_type *tmp;    struct pike_string *attr;    struct pike_string *fmt; +  struct pike_string *sscanf_input_string;    struct pike_string *sscanf_format_string;    struct pike_string *sscanf_76_format_string; -  +  struct mapping *state;    int found = 0;    int fmt_count;      #if 0    fprintf(stderr, "__handle_sscanf_format()\n");   #endif /* 0 */    if (args != 5)    SIMPLE_WRONG_NUM_ARGS_ERROR("__handle_sscanf_format", 5);    if (TYPEOF(Pike_sp[-5]) != PIKE_T_STRING)    SIMPLE_ARG_TYPE_ERROR("__handle_sscanf_format", 1, "string"); -  if (TYPEOF(Pike_sp[-4]) != PIKE_T_STRING) -  SIMPLE_ARG_TYPE_ERROR("__handle_sscanf_format", 2, "string"); +     if (TYPEOF(Pike_sp[-3]) != PIKE_T_TYPE)    SIMPLE_ARG_TYPE_ERROR("__handle_sscanf_format", 3, "type");    if (TYPEOF(Pike_sp[-2]) != PIKE_T_TYPE)    SIMPLE_ARG_TYPE_ERROR("__handle_sscanf_format", 4, "type");    if (TYPEOF(Pike_sp[-1]) != PIKE_T_MAPPING)    SIMPLE_ARG_TYPE_ERROR("__handle_sscanf_format", 5, "mapping");       tmp = Pike_sp[-2].u.type;    if ((tmp->type != PIKE_T_FUNCTION) && (tmp->type != T_MANY)) {    SIMPLE_ARG_TYPE_ERROR("__handle_sscanf_format", 4, "type(function)");    }    -  +  state = Pike_sp[-1].u.mapping; +  +  MAKE_CONST_STRING(sscanf_input_string, "sscanf_input"); +  +  if (Pike_sp[-5].u.string == sscanf_input_string) { +  mapping_string_insert(state, sscanf_input_string, Pike_sp-3); +  pop_n_elems(args); +  push_undefined(); +  return; +  } +  +  if (TYPEOF(Pike_sp[-4]) != PIKE_T_STRING) { +  if (TYPEOF(Pike_sp[-4]) == PIKE_T_INT) { +  pop_n_elems(args); +  push_undefined(); +  return; +  } +  SIMPLE_ARG_TYPE_ERROR("__handle_sscanf_format", 2, "string"); +  } +     MAKE_CONST_STRING(sscanf_format_string, "sscanf_format");    MAKE_CONST_STRING(sscanf_76_format_string, "sscanf_76_format");       if (Pike_sp[-5].u.string != sscanf_format_string) {    if (Pike_sp[-5].u.string != sscanf_76_format_string) {    pop_n_elems(args);    push_undefined();    return;    }    }
pike.git/src/sscanf.c:2122:    continue;    default:    arg = NULL;    break;    }    break;    }    if (arg) {    type_stack_mark();    push_sscanf_argument_types(MKPCHARP(fmt->str, fmt->size_shift), -  fmt->len, 0); +  fmt->len, 0, state);    if (!array_cnt) {    pop_stack_mark();    push_type(T_VOID); /* No more args */    while (tmp->type == PIKE_T_FUNCTION) {    tmp = tmp->cdr;    }    push_finished_type(tmp->cdr); /* return type */    push_reverse_type(T_MANY);    fmt_count = pop_stack_mark();    while (fmt_count > 1) {
pike.git/src/sscanf.c:2215:    continue;    default:    arg = NULL;    break;    }    break;    }    if (arg) {    type_stack_mark();    push_sscanf_argument_types(MKPCHARP(fmt->str, fmt->size_shift), -  fmt->len, 0); +  fmt->len, 0, state);    /* Join the argument types. */    if (!(fmt_count = pop_stack_mark())) {    push_type(PIKE_T_ZERO);    } else while (fmt_count > 2) {    push_type(T_OR);    fmt_count--;    }    while (array_cnt--) {    push_unlimited_array_type(PIKE_T_ARRAY);    }