Example #1
0
//
//  Partial1: C
// 
// Process the /part (or /skip) and other length modifying
// arguments.
//
REBINT Partial1(REBVAL *sval, REBVAL *lval)
{
    REBI64 len;
    REBINT maxlen;
    REBINT is_ser = ANY_SERIES(sval);

    // If lval is not set or is BAR!, use the current len of the target value:
    if (IS_UNSET(lval) || IS_BAR(lval)) {
        if (!is_ser) return 1;
        if (VAL_INDEX(sval) >= VAL_LEN_HEAD(sval)) return 0;
        return (VAL_LEN_HEAD(sval) - VAL_INDEX(sval));
    }
    if (IS_INTEGER(lval) || IS_DECIMAL(lval)) len = Int32(lval);
    else {
        if (is_ser && VAL_TYPE(sval) == VAL_TYPE(lval) && VAL_SERIES(sval) == VAL_SERIES(lval))
            len = (REBINT)VAL_INDEX(lval) - (REBINT)VAL_INDEX(sval);
        else
            fail (Error(RE_INVALID_PART, lval));
    }

    if (is_ser) {
        // Restrict length to the size available:
        if (len >= 0) {
            maxlen = (REBINT)VAL_LEN_AT(sval);
            if (len > maxlen) len = maxlen;
        } else {
            len = -len;
            if (len > (REBINT)VAL_INDEX(sval)) len = (REBINT)VAL_INDEX(sval);
            VAL_INDEX(sval) -= (REBCNT)len;
        }
    }

    return (REBINT)len;
}
Example #2
0
//
//  Update_Typeset_Bits_Core: C
//
// This sets the bits in a bitset according to a block of datatypes.  There
// is special handling by which BAR! will set the "variadic" bit on the
// typeset, which is heeded by functions only.
//
// !!! R3-Alpha supported fixed word symbols for datatypes and typesets.
// Confusingly, this means that if you have said `word!: integer!` and use
// WORD!, you will get the integer type... but if WORD! is unbound then it
// will act as WORD!.  Also, is essentially having "keywords" and should be
// reviewed to see if anything actually used it.
//
REBOOL Update_Typeset_Bits_Core(
    REBVAL *typeset,
    const REBVAL *head,
    REBOOL trap // if TRUE, then return FALSE instead of failing
) {
    const REBVAL *item = head;

    REBARR *types = VAL_ARRAY(ROOT_TYPESETS);

    assert(IS_TYPESET(typeset));

    VAL_TYPESET_BITS(typeset) = 0;

    for (; NOT_END(item); item++) {
        const REBVAL *var = NULL;

        if (IS_BAR(item)) {
            SET_VAL_FLAG(typeset, TYPESET_FLAG_VARIADIC);
            continue;
        }

        if (IS_WORD(item) && !(var = TRY_GET_OPT_VAR(item))) {
            REBSYM sym = VAL_WORD_SYM(item);

            // See notes: if a word doesn't look up to a variable, then its
            // symbol is checked as a second chance.
            //
            if (IS_KIND_SYM(sym)) {
                TYPE_SET(typeset, KIND_FROM_SYM(sym));
                continue;
            }
            else if (sym >= SYM_ANY_NOTHING_X && sym < SYM_DATATYPES)
                var = ARR_AT(types, sym - SYM_ANY_NOTHING_X);
        }

        if (!var) var = item;

        if (IS_DATATYPE(var)) {
            TYPE_SET(typeset, VAL_TYPE_KIND(var));
        }
        else if (IS_TYPESET(var)) {
            VAL_TYPESET_BITS(typeset) |= VAL_TYPESET_BITS(var);
        }
        else {
            if (trap) return FALSE;

            fail (Error_Invalid_Arg(item));
        }
    }

    return TRUE;
}
Example #3
0
void NL_SetCols(struct NLData *data)
{
  if (data->do_setcols)
  {
    if (data->cols)
    {
      LONG column;
      LONG weight,weight_all,weight_num,width,width_all,colx,minwidth,maxwidth,mincolwidth,maxcolwidth;
      BOOL do_colwidthmax = FALSE;

      weight_num = 0;
      weight_all = 0;
      width_all = data->mwidth;
      column = 0;
      while (column < data->numcols)
      {
        if (data->cols[column].c->userwidth >= 0)
          width_all -= data->cols[column].c->userwidth;
        else if (data->cols[column].c->width_type == CI_PIX)
          width_all -= data->cols[column].c->width;
        else if (data->cols[column].c->width_type == CI_COL)
          width_all -= data->cols[column].c->width * data->hinc +1;
        else if (data->cols[column].c->width == -1)
        { if (!do_colwidthmax)
          { if (data->cols[column].c->colwidthbiggestptr == -2)
            {
              NL_SetColsAdd(data,-2,TRUE);
              do_colwidthmax = TRUE;
            }
            else
            { data->cols[column].c->colwidthmax = data->cols[column].c->colwidthbiggest;
            }
          }
          width_all -= data->cols[column].c->colwidthmax;
        }
        else
        { weight_all += data->cols[column].c->width;
          weight_num++;
        }
        if (column < data->numcols-1)
          width_all -= data->cols[column].c->delta;
        column++;
      }
      if (weight_all <= (column*5))
        weight_all = (column*5)+1;
      colx = 0;
      column = 0;
      while (column < data->numcols)
      { weight = (LONG) data->cols[column].c->width;
        if (data->cols[column].c->userwidth >= 0)
          width = data->cols[column].c->userwidth;
        else if (data->cols[column].c->width_type == CI_PIX)
          width = weight;
        else if (data->cols[column].c->width_type == CI_COL)
          width = weight * data->hinc;
        else if (weight == -1)
          width = data->cols[column].c->colwidthmax;
        else
        {
          width = (weight * width_all) / weight_all;
          minwidth = (LONG) data->cols[column].c->minwidth;
          if (minwidth == -1)
          { if (!do_colwidthmax && (data->cols[column].c->colwidthbiggestptr == -2))
            {
              NL_SetColsAdd(data,-2,TRUE);
              do_colwidthmax = TRUE;
            }
            minwidth = data->cols[column].c->colwidthmax;
          }
          else
            minwidth = (minwidth * ((LONG) data->mwidth)) / 100L;
          maxwidth = (LONG) data->cols[column].c->maxwidth;
          maxwidth = (maxwidth * ((LONG) data->mwidth)) / 100L;

          mincolwidth = (LONG) data->cols[column].c->mincolwidth;
          mincolwidth = mincolwidth * ((LONG) data->hinc) + 1;
          maxcolwidth = (LONG) data->cols[column].c->maxcolwidth;
          maxcolwidth = maxcolwidth * ((LONG) data->hinc) + 1;

          if (mincolwidth > minwidth)
            minwidth = mincolwidth;
          if (data->cols[column].c->minpixwidth > minwidth)
            minwidth = data->cols[column].c->minpixwidth;

          if (maxcolwidth < maxwidth)
            maxwidth = maxcolwidth;
          if (data->cols[column].c->maxpixwidth < maxwidth)
            maxwidth = data->cols[column].c->maxpixwidth;

          if ((maxwidth > 10) && (width > maxwidth))
            width = maxwidth;

          if (width < minwidth)
            width = minwidth;

          if (width < 6)
            width = 6;

          width_all -= width;
          weight_all -= data->cols[column].c->width;
          if (weight_all < 10)
            weight_all = 10;
        }
        if (data->cols[column].c->dx != (WORD) width)
        { data->do_wwrap = data->force_wwrap = data->do_draw_all = TRUE;
          data->cols[column].c->dx = (WORD) width;
          if (data->NList_TypeSelect)
            UnSelectCharSel(data,FALSE);
        }
        if (data->cols[column].c->minx != (WORD) colx)
        { data->do_wwrap = data->force_wwrap = data->do_draw_all = TRUE;
          data->cols[column].c->minx = (WORD) colx;
          if (data->NList_TypeSelect)
            UnSelectCharSel(data,FALSE);
        }
        colx += width;
        if (data->cols[column].c->maxx != (WORD) colx)
        { if (column < data->numcols-1)
          { data->do_wwrap = data->force_wwrap = data->do_draw_all = TRUE;
          }
          data->cols[column].c->maxx = (WORD) colx;
        }
        if (column < data->numcols-1)
          colx += data->cols[column].c->delta;
        else if (data->cols[column].c->userwidth >= 0)
        { LONG ent = 0;
          while (data->EntriesArray && (ent < data->NList_Entries))
          { data->EntriesArray[ent]->PixLen = -1;
            ent++;
          }
        }
        if (!IS_BAR(column,data->cols[column].c))
          data->cols[column].c->maxx = MUI_MAXMAX;
        column++;
      }
    }
    data->do_setcols = FALSE;
  }
}