Пример #1
0
void SymValFunc::execute() {
  // return value for each symbol variable
  boolean noargs = !nargs() && !nkeys();
  int numargs = nargs();
  if (!numargs) return;
  ComValue* varvalues[numargs];
  for (int i=0; i<numargs; i++) {

    // return fully-evaluated value: expression --> symbol --> value
    varvalues[i] = &stack_arg(i, false); 
    //    lookup_symval(*varvalues[i]);
  }

  if (numargs>1) {
    AttributeValueList* avl = new AttributeValueList();
    ComValue retval(avl);
    for (int i=0; i<numargs; i++)
      avl->Append(new ComValue(*varvalues[i]));
    reset_stack();
    push_stack(retval);
  } else {
    ComValue retval (*varvalues[0]);
    reset_stack();
    push_stack(retval);
  }
}
Пример #2
0
void SumFunc::execute() {
  ComValue vallist(stack_arg(0));
  reset_stack();
  
  if (vallist.is_type(ComValue::ArrayType)) {
    AttributeValueList* avl = vallist.array_val();
    AddFunc addfunc(comterp());
    push_stack(ComValue::zeroval());
    Iterator it;
    int count = 0;
    for (avl->First(it); !avl->Done(it); avl->Next(it)) {
      count++;
      push_stack(*avl->GetAttrVal(it));
      addfunc.exec(2,0);
    }
    if (_meanfunc) {
      DivFunc divfunc(comterp());
      ComValue divisor(count, ComValue::IntType);
      push_stack(divisor);
      divfunc.exec(2,0);
    }
  } else {
    push_stack(vallist);
  }
}
Пример #3
0
Transformer* CreateGraphicFunc::get_transformer(AttributeList* al) {
  static int transform_symid = symbol_add("transform");

  AttributeValue* transformv = nil;
  Transformer* rel = nil;
  AttributeValueList* avl = nil;
  if (al && 
      (transformv=al->find(transform_symid)) && 
      transformv->is_array() && 
      (avl=transformv->array_val()) &&
      avl->Number()==6) {
    float a00, a01, a10, a11, a20, a21;
    Iterator it;
    avl->First(it); a00=avl->GetAttrVal(it)->float_val();
    avl->Next(it); a01=avl->GetAttrVal(it)->float_val();
    avl->Next(it); a10=avl->GetAttrVal(it)->float_val();
    avl->Next(it); a11=avl->GetAttrVal(it)->float_val();
    avl->Next(it); a20=avl->GetAttrVal(it)->float_val();
    avl->Next(it); a21=avl->GetAttrVal(it)->float_val();
    rel = new Transformer(a00, a01, a10, a11, a20, a21);
  } else {
    rel = ((OverlayViewer*)_ed->GetViewer())->GetRel();
    if (rel != nil) {
      rel = new Transformer(rel);
      rel->Invert();
    }
  }
  return rel;
  
}
Пример #4
0
void SymbolFunc::execute() {
  // return symbol for each id argument
  boolean noargs = !nargs() && !nkeys();
  int numargs = nargs();
  if (!numargs) return;
  int symbol_ids[numargs];
  for (int i=0; i<numargs; i++) {
    ComValue& val = stack_arg(i, true);
    if (val.is_char() || val.is_short() || val.is_int())
      symbol_ids[i] = val.int_val();
    else 
      symbol_ids[i] = -1;
  }
  reset_stack();

  if (numargs>1) {
    AttributeValueList* avl = new AttributeValueList();
    ComValue retval(avl);
    for (int i=0; i<numargs; i++) {
      ComValue* av = new ComValue(symbol_ids[i], AttributeValue::SymbolType);
      av->bquote(1);
      avl->Append(av);
    }
    push_stack(retval);
  } else {
    ComValue retval (symbol_ids[0], AttributeValue::SymbolType);
    retval.bquote(1);
    push_stack(retval);
  }

}
Пример #5
0
void SymIdFunc::execute() {
  // return id of each symbol in the arguments
  boolean noargs = !nargs() && !nkeys();
  int numargs = nargs();
  if (!numargs) return;
  int symbol_ids[numargs];
  for (int i=0; i<numargs; i++) {
    ComValue& val = stack_arg(i, true);
    if (val.is_type(AttributeValue::CommandType))
      symbol_ids[i] = val.command_symid();
    else if (val.is_type(AttributeValue::StringType))
      symbol_ids[i] = val.string_val();
    else if (val.is_type(AttributeValue::SymbolType))
      symbol_ids[i] = val.symbol_val();
    else 
      symbol_ids[i] = -1;
  }
  reset_stack();

  if (numargs>1) {
    AttributeValueList* avl = new AttributeValueList();
    ComValue retval(avl);
    for (int i=0; i<numargs; i++)
      avl->Append(new AttributeValue(symbol_ids[i], AttributeValue::IntType));
    push_stack(retval);
  } else {
    ComValue retval (symbol_ids[0], AttributeValue::IntType);
    push_stack(retval);
  }

}
Пример #6
0
void CreateLineFunc::execute() {
    const int x0 = 0;  
    const int y0 = 1;  
    const int x1 = 2;  
    const int y1 = 3;  
    const int n = 4;
    int coords[n];
    ComValue& vect = stack_arg(0);
    if (!vect.is_type(ComValue::ArrayType) || vect.array_len() != n) {
        reset_stack();
	push_stack(ComValue::nullval());
	return;
    }

    ALIterator i;
    AttributeValueList* avl = vect.array_val();
    avl->First(i);
    for (int j=0; j<n && !avl->Done(i); j++) {
        coords[j] = avl->GetAttrVal(i)->int_val();
	avl->Next(i);
    }

    AttributeList* al = stack_keys();
    Resource::ref(al);
    reset_stack();

    PasteCmd* cmd = nil;

    if (coords[x0] != coords[x1] || coords[y0] != coords[y1]) {
	BrushVar* brVar = (BrushVar*) _ed->GetState("BrushVar");
	PatternVar* patVar = (PatternVar*) _ed->GetState("PatternVar");
	ColorVar* colVar = (ColorVar*) _ed->GetState("ColorVar");

        Transformer* rel = get_transformer(al);

	ArrowVar* aVar = (ArrowVar*) _ed->GetState("ArrowVar");
	ArrowLine* line = new ArrowLine(coords[x0], coords[y0], coords[x1], coords[y1], aVar->Head(), aVar->Tail(), 
					_ed->GetViewer()->GetMagnification(), stdgraphic);

	if (brVar != nil) line->SetBrush(brVar->GetBrush());

	if (colVar != nil) {
	    line->FillBg(!colVar->GetBgColor()->None());
	    line->SetColors(colVar->GetFgColor(), colVar->GetBgColor());
            }
	line->SetTransformer(rel);
	Unref(rel);
	ArrowLineOvComp* comp = new ArrowLineOvComp(line);
	comp->SetAttributeList(al);
	if (PasteModeFunc::paste_mode()==0)
	  cmd = new PasteCmd(_ed, new Clipboard(comp));
	ComValue compval(new OverlayViewRef(comp), symbol_add("ArrowLineComp"));
	push_stack(compval);
	execute_log(cmd);
    } else 
	push_stack(ComValue::nullval());

    Unref(al);
}
Пример #7
0
void CreateTextFunc::execute() {
    const int x0 = 0;  
    const int y0 = 1;  
    const int n = 2;
    int args[n];
    ComValue& vect = stack_arg(0);
    ComValue& txtv = stack_arg(1);
    if (!vect.is_type(ComValue::ArrayType) || vect.array_len() != n) {
        reset_stack();
	push_stack(ComValue::nullval());
	return;
    }

    ALIterator i;
    AttributeValueList* avl = vect.array_val();
    avl->First(i);
    for (int j=0; j<n && !avl->Done(i); j++) {
        args[j] = avl->GetAttrVal(i)->int_val();
	avl->Next(i);
    }

    const char* txt = symbol_pntr( txtv.symbol_ref() );

    AttributeList* al = stack_keys();
    Resource::ref(al);
    reset_stack();
   
    PasteCmd* cmd = nil;
    
    if (txt) {
	ColorVar* colVar = (ColorVar*) _ed->GetState("ColorVar");
	FontVar* fntVar = (FontVar*) _ed->GetState("FontVar");
	
        Transformer* rel = get_transformer(al);
	
	TextGraphic* text = new TextGraphic(txt, stdgraphic);

	if (colVar != nil) {
	    text->FillBg(!colVar->GetBgColor()->None());
	    text->SetColors(colVar->GetFgColor(), colVar->GetBgColor());
            }
	if (fntVar != nil) text->SetFont(fntVar->GetFont());
	text->SetTransformer(new Transformer());
	text->Translate(args[x0], args[y0]);
	text->GetTransformer()->postmultiply(rel);
	Unref(rel);
	TextOvComp* comp = new TextOvComp(text);
	comp->SetAttributeList(al);
	if (PasteModeFunc::paste_mode()==0)
	  cmd = new PasteCmd(_ed, new Clipboard(comp));
	ComValue compval(new OverlayViewRef(comp), symbol_add("TextComp"));
	push_stack(compval);
	execute_log(cmd);
    } else
        push_stack(ComValue::nullval());

    Unref(al);
}
Пример #8
0
void CreateEllipseFunc::execute() {
    const int x0 = 0;  
    const int y0 = 1;  
    const int r1 = 2;  
    const int r2 = 3;  
    const int n = 4;
    int args[n];
    ComValue& vect = stack_arg(0);
    if (!vect.is_type(ComValue::ArrayType) ||  vect.array_len() != n) {
        reset_stack();
	push_stack(ComValue::nullval());
	return;
    }

    ALIterator i;
    AttributeValueList* avl = vect.array_val();
    avl->First(i);
    for (int j=0; j<n && !avl->Done(i); j++) {
        args[j] = avl->GetAttrVal(i)->int_val();
	avl->Next(i);
    }

    AttributeList* al = stack_keys();
    Resource::ref(al);
    reset_stack();

    PasteCmd* cmd = nil;

    if (args[r1] > 0 && args[r2] > 0) {
	BrushVar* brVar = (BrushVar*) _ed->GetState("BrushVar");
	PatternVar* patVar = (PatternVar*) _ed->GetState("PatternVar");
	ColorVar* colVar = (ColorVar*) _ed->GetState("ColorVar");

	Transformer* rel = get_transformer(al);
	
	SF_Ellipse* ellipse = new SF_Ellipse(args[x0], args[y0], args[r1], args[r2], stdgraphic);

	if (brVar != nil) ellipse->SetBrush(brVar->GetBrush());
	if (patVar != nil) ellipse->SetPattern(patVar->GetPattern());

	if (colVar != nil) {
	    ellipse->FillBg(!colVar->GetBgColor()->None());
	    ellipse->SetColors(colVar->GetFgColor(), colVar->GetBgColor());
            }
	ellipse->SetTransformer(rel);
	Unref(rel);
	EllipseOvComp* comp = new EllipseOvComp(ellipse);
	comp->SetAttributeList(al);
	if (PasteModeFunc::paste_mode()==0)
	  cmd = new PasteCmd(_ed, new Clipboard(comp));
	ComValue compval( new OverlayViewRef(comp), symbol_add("EllipseComp"));
	push_stack(compval);
	execute_log(cmd);
    } else 
	push_stack(ComValue::nullval());

    Unref(al);
}
Пример #9
0
void EvalFunc::execute() {
  static int symret_sym = symbol_add("symret");
  ComValue symretv(stack_key(symret_sym));

  if (!comterp()->is_serv()) {
    cerr << "need server mode comterp (or remote mode) for eval command\n";
    reset_stack();
    push_stack(ComValue::nullval());
    return;
  }

  // evaluate every string fixed argument on the stack and return in array
  int numargs = nargsfixed();
  if (numargs>1) {
    AttributeValueList* avl = nil;
    for (int i=0; i<numargs; i++) {
      ComValue argstrv (stack_arg(i));
      if (argstrv.is_nil()) break;
      if (argstrv.is_string()) {
	ComValue* val = new ComValue(comterpserv()->run(argstrv.symbol_ptr(), true /* nested */));
	if (val->is_nil() && symretv.is_true()) {
	  delete val;
	  val = new ComValue(argstrv.symbol_val(), AttributeValue::SymbolType);
	}
	if (!avl) avl = new AttributeValueList();
	avl->Append(val);
      }
    }
    reset_stack();
    if (avl) {
      ComValue retval(avl);
      push_stack(retval);
    }

  }
  /* unless only single argument */
  else if (numargs==1) {

    ComValue argstrv (stack_arg(0));
    reset_stack();
    if (argstrv.is_nil()) {
      push_stack(ComValue::nullval());
    } else if (argstrv.is_string()) {
	ComValue val(comterpserv()->run(argstrv.symbol_ptr(), true /* nested */));
	if (val.is_nil() && symretv.is_true()) {
	  val.assignval(ComValue(argstrv.symbol_val(), AttributeValue::SymbolType));
	}
	push_stack(val);
	
    }
  } else
    reset_stack();
}
Пример #10
0
void SplitStrFunc::execute() {
  ComValue symvalv(stack_arg(0));
  reset_stack();

  if (symvalv.is_string()) {
    AttributeValueList* avl = new AttributeValueList();
    ComValue retval(avl);
    const char* str = symvalv.symbol_ptr();
    int len = strlen(str);
    for (int i=0; i<len; i++)
      avl->Append(new AttributeValue(str[i]));
    push_stack(retval);
  } else
    push_stack(ComValue::nullval());
}
Пример #11
0
void CreateOpenSplineFunc::execute() {
    ComValue& vect = stack_arg(0);
    if (!vect.is_type(ComValue::ArrayType) || vect.array_len()==0) {
        reset_stack();
	push_stack(ComValue::nullval());
	return;
    }

    const int len = vect.array_len();
    const int npts = len/2;
    int x[npts];
    int y[npts];
    ALIterator i;
    AttributeValueList* avl = vect.array_val();
    avl->First(i);
    for (int j=0; j<npts && !avl->Done(i); j++) {
        x[j] = avl->GetAttrVal(i)->int_val();
	avl->Next(i);
        y[j] = avl->GetAttrVal(i)->int_val();
	avl->Next(i);
    }

    AttributeList* al = stack_keys();
    Resource::ref(al);
    reset_stack();

    PasteCmd* cmd = nil;

    if (npts) {
	BrushVar* brVar = (BrushVar*) _ed->GetState("BrushVar");
	PatternVar* patVar = (PatternVar*) _ed->GetState("PatternVar");
	ColorVar* colVar = (ColorVar*) _ed->GetState("ColorVar");

        Transformer* rel = get_transformer(al);

	ArrowVar* aVar = (ArrowVar*) _ed->GetState("ArrowVar");
	ArrowOpenBSpline* openspline = new ArrowOpenBSpline(x, y, npts, aVar->Head(), aVar->Tail(), 
					_ed->GetViewer()->GetMagnification(), stdgraphic);

	if (brVar != nil) openspline->SetBrush(brVar->GetBrush());
	if (patVar != nil) openspline->SetPattern(patVar->GetPattern());

	if (colVar != nil) {
	    openspline->FillBg(!colVar->GetBgColor()->None());
	    openspline->SetColors(colVar->GetFgColor(), colVar->GetBgColor());
            }
	openspline->SetTransformer(rel);
	Unref(rel);
	ArrowSplineOvComp* comp = new ArrowSplineOvComp(openspline);
	comp->SetAttributeList(al);
	if (PasteModeFunc::paste_mode()==0)
	  cmd = new PasteCmd(_ed, new Clipboard(comp));
	ComValue compval(new OverlayViewRef(comp), symbol_add("ArrowSplineComp"));
	push_stack(compval);
	execute_log(cmd);
    } else 
	push_stack(ComValue::nullval());

    Unref(al);
}
Пример #12
0
void JoinStrFunc::execute() {
  ComValue listv(stack_arg(0));
  static int sym_symid = symbol_add("sym");
  ComValue symflagv(stack_key(sym_symid));
  boolean symflag = symflagv.is_true();
  reset_stack();

  if (listv.is_array()) {
    AttributeValueList* avl = listv.array_val();
    if (avl) {
      char cbuf[avl->Number()+1];
      Iterator i;
      int cnt=0;
      for (avl->First(i); !avl->Done(i); avl->Next(i)) {
	cbuf[cnt] = avl->GetAttrVal(i)->char_val();
	cnt++;
      }
      cbuf[cnt] = '\0';

    ComValue retval(symbol_add(cbuf), symflag ? ComValue::SymbolType : ComValue::StringType);
    push_stack(retval);
    return;
    }
  }
  push_stack(ComValue::nullval());
}
Пример #13
0
void PostEvalFunc::execute() {
    // evaluate every fixed argument on the stack and return in array
    int numargs = nargstotal();
    if (numargs) {
        AttributeValueList* avl = nil;
        for (int i=0; i<numargs; i++) {
            ComValue* val = new ComValue(stack_arg_post_eval(i));
            if (val->is_nil()) {
                delete val;
                break;
            }
            if (!avl) avl = new AttributeValueList();
            avl->Append(val);
        }
        reset_stack();
        if (avl) {
            ComValue retval(avl);
            push_stack(retval);
        }
    } else
        reset_stack();
}
Пример #14
0
void GrStreamFunc::execute() {
  ComValue convertv(stack_arg_post_eval(0));
  
  if (convertv.object_compview()) {
    reset_stack();
    
    static StreamNextFunc* snfunc = nil;
    if (!snfunc) {
      snfunc = new StreamNextFunc(comterp());
      snfunc->funcid(symbol_add("stream"));
    }

    AttributeValueList* avl = new AttributeValueList();
    Component* comp = ((ComponentView*)convertv.obj_val())->GetSubject();
    if (!comp->IsA(OVERLAYS_COMP)) {
      push_stack(ComValue::nullval());
      return;
    }
    OverlaysComp* ovcomps = (OverlaysComp*)comp;
    Iterator it;
    for(ovcomps->First(it); !ovcomps->Done(it); ovcomps->Next(it)) {
      OverlayComp* subcomp = (OverlayComp*) ovcomps->GetComp(it);
      AttributeValue* av = 
        new AttributeValue(new OverlayViewRef(subcomp), subcomp->classid());
      avl->Append(av);
    }
    ComValue stream(snfunc, avl);
    stream.stream_mode(-1); // for internal use (use by this func)
    push_stack(stream);
    
  } else {
    
    StreamFunc strmfunc(comterp());
    strmfunc.exec(funcstate()->nargs(), funcstate()->nkeys(), pedepth());
    return;
    
  }
  
}
Пример #15
0
void GlobalSymbolFunc::execute() {
  // return symbol(s) with global flag set
  boolean noargs = !nargs() && !nkeys();
  int numargs = nargs();
  if (!numargs) {
    reset_stack();
    return;
  }
  int symbol_ids[numargs];
  for (int i=0; i<numargs; i++) {
    ComValue& val = stack_arg(i, true);
    if (val.is_symbol())
      symbol_ids[i] = val.symbol_val();
    else 
      symbol_ids[i] = -1;
  }
  reset_stack();

  if (numargs>1) {
    AttributeValueList* avl = new AttributeValueList();
    ComValue retval(avl);
    for (int i=0; i<numargs; i++) {
      ComValue* av = 
	new ComValue(symbol_ids[i], AttributeValue::SymbolType);
      av->global_flag(true);
      av->bquote(1);
      avl->Append(av);
    }
    push_stack(retval);
  } else {
    
    ComValue retval (symbol_ids[0], AttributeValue::SymbolType);
    retval.global_flag(true);
    retval.bquote(1);
    push_stack(retval);
  }

}
Пример #16
0
void SymAddFunc::execute() {
  // return each symbol in the arguments as is
  boolean noargs = !nargs() && !nkeys();
  int numargs = nargs();
  if (!numargs) return;
  int symbol_ids[numargs];
  for (int i=0; i<numargs; i++) {
    ComValue& val = stack_arg(i);
    if (val.is_type(AttributeValue::CommandType))
      symbol_ids[i] = val.command_symid();
    else if (val.is_type(AttributeValue::StringType))
      symbol_ids[i] = val.string_val();
    else if (val.is_type(AttributeValue::SymbolType))
      symbol_ids[i] = val.symbol_val();
    else 
      symbol_ids[i] = -1;
  }
  reset_stack();

  if (numargs>1) {
    AttributeValueList* avl = new AttributeValueList();
    ComValue retval(avl);
    for (int i=0; i<numargs; i++) {
      ComValue* av = new ComValue(symbol_ids[i], AttributeValue::SymbolType);
      av->bquote(1);
      if (symbol_ids[i]<0) av->type(ComValue::UnknownType);
      avl->Append(av);
    }
    push_stack(retval);
  } else {
    ComValue retval (symbol_ids[0], AttributeValue::SymbolType);
    if (symbol_ids[0]<0) retval.type(ComValue::UnknownType);
    retval.bquote(1);
    push_stack(retval);
  }

}
Пример #17
0
void PrintFunc::execute() {
  ComValue formatstr(stack_arg(0));
  static int str_symid = symbol_add("str");
  ComValue strflag(stack_key(str_symid));
  static int string_symid = symbol_add("string");
  ComValue stringflag(stack_key(string_symid));
  static int sym_symid = symbol_add("sym");
  ComValue symflag(stack_key(sym_symid));
  static int symbol_symid = symbol_add("symbol");
  ComValue symbolflag(stack_key(symbol_symid));
  static int err_symid = symbol_add("err");
  ComValue errflag(stack_key(err_symid));
  static int out_symid = symbol_add("out");
  ComValue outflag(stack_key(out_symid));
  static int file_symid = symbol_add("file");
  ComValue fileobjv(stack_key(file_symid));
  static int prefix_symid = symbol_add("prefix");
  ComValue prefixv(stack_key(prefix_symid));

  const char* fstr = formatstr.is_string() ? formatstr.string_ptr() : "nil";
  ComValue::comterp(comterp());

  streambuf* strmbuf = nil;
  if (stringflag.is_false() && strflag.is_false() &&
      symbolflag.is_false() && symflag.is_false()) {
    if (comterp()->handler() && fileobjv.is_unknown() && errflag.is_false() && outflag.is_false()) {
      FILEBUFP(fbuf, comterp()->handler() && comterp()->handler()->wrfptr() 
	       ? comterp()->handler()->wrfptr() : stdout, ios_base::out);
      strmbuf = fbuf;
    } else if (fileobjv.is_known()) {
      FileObj *fileobj = (FileObj*)fileobjv.geta(FileObj::class_symid());
      if (fileobj) {
        FILEBUFP(fbuf, fileobj->fptr(), ios_base::out);
	strmbuf = fbuf;
      } else {
        PipeObj *pipeobj = (PipeObj*)fileobjv.geta(PipeObj::class_symid());
        FILEBUFP(fbuf, pipeobj ? pipeobj->wrfptr() : stdout, ios_base::out);
	strmbuf = fbuf;
      }
    } else {
      FILEBUFP(fbuf, errflag.is_false() ? stdout : stderr, ios_base::out);
      strmbuf = fbuf;
    }
  } else
    strmbuf = new std::strstreambuf();
  ostream out(strmbuf);

  int narg = nargsfixed();
  if (narg==1) {

    if (formatstr.is_string() && !prefixv.is_string()) {
      out << formatstr.symbol_ptr();
      out.flush();
    }
    else {
      if (prefixv.is_string()) out << prefixv.symbol_ptr();
      out << formatstr;  // which could be arbitrary ComValue
      if (prefixv.is_string()) out << "\n";
    }

  } else {
    const char* fstrptr = fstr;
    int curr=1;
    while (curr<narg) {

      char fbuf[BUFSIZ];
      ComValue printval(stack_arg(curr));
      curr++;

      int i=0;
      if(curr<narg) {
        int flen;
        while(*fstrptr && !(flen=format_extent(fstrptr)) && i<BUFSIZ-1) fbuf[i++] = *fstrptr++;
        if(*fstrptr && flen+i<BUFSIZ-1) {
          strncpy(fbuf+i, fstrptr, flen);
          i += flen;
          fstrptr += flen;
        }
        while(*fstrptr && !format_extent(fstrptr) && i<BUFSIZ-1) fbuf[i++] = *fstrptr++;
        fbuf[i] = '\0';
      } else
        strncpy(fbuf, fstrptr, BUFSIZ);

      switch( printval.type() )
      {
      case ComValue::SymbolType:
      case ComValue::StringType:
	out_form(out, fbuf, symbol_pntr( printval.symbol_ref()));
	break;
	
      case ComValue::BooleanType:
	out_form(out, fbuf, printval.boolean_ref());
	break;
	
      case ComValue::CharType:
	out_form(out, fbuf, printval.char_ref());
	break;	    
	
      case ComValue::UCharType:
	out_form(out, fbuf, printval.uchar_ref());
	break;
	
      case ComValue::IntType:
	out_form(out, fbuf, printval.int_ref());
	break;
	
      case ComValue::UIntType:
	out_form(out, fbuf, printval.uint_ref());
	break;
	
      case ComValue::LongType:
	out_form(out, fbuf, printval.long_ref());
	break;
	
      case ComValue::ULongType:
	out_form(out, fbuf, printval.ulong_ref());
	break;
	
      case ComValue::FloatType:
	out_form(out, fbuf, printval.float_ref());
	break;
	
      case ComValue::DoubleType:
	out_form(out, fbuf, printval.double_ref());
	break;
	
      case ComValue::ArrayType: 
      {
	
        ALIterator i;
        AttributeValueList* avl = printval.array_val();
        avl->First(i);
        boolean first = true;
        while (!avl->Done(i)) {
          ComValue val(*avl->GetAttrVal(i));
          push_stack(formatstr);
          push_stack(val);
          exec(2,0);
          avl->Next(i);
          if (!avl->Done(i)) out << "\n";
        }
      }
      break;
      
      case ComValue::BlankType:
	out << "<blank>";
	break;
	
      case ComValue::UnknownType:
	out_form(out, fbuf, nil);
	break;
	
      case ComValue::ObjectType:
	out_form(out, fbuf, symbol_pntr(printval.class_symid()));
	break;
	
      default:
	break;
      }
    }
  }


  reset_stack();
  if (stringflag.is_true() || strflag.is_true()) {
    out << '\0';
    ComValue retval(((std::strstreambuf*)strmbuf)->str());
    push_stack(retval);
  } else if (symbolflag.is_true() || symflag.is_true()) {
    out << '\0';
    int symbol_id = symbol_add(((std::strstreambuf*)strmbuf)->str());
    ComValue retval(symbol_id, ComValue::SymbolType);
    push_stack(retval);
  } else {
    out.flush();
    push_stack(ComValue::blankval());
  }

  delete strmbuf;

}
Пример #18
0
void PrintFunc::execute() {
    ComValue formatstr(stack_arg(0));
    ComValue printval(stack_arg(1));
    static int str_symid = symbol_add("str");
    ComValue strflag(stack_key(str_symid));
    static int string_symid = symbol_add("string");
    ComValue stringflag(stack_key(string_symid));
    static int sym_symid = symbol_add("sym");
    ComValue symflag(stack_key(sym_symid));
    static int symbol_symid = symbol_add("symbol");
    ComValue symbolflag(stack_key(symbol_symid));
    static int err_symid = symbol_add("err");
    ComValue errflag(stack_key(err_symid));
    reset_stack();

    const char* fstr = formatstr.is_string() ? formatstr.string_ptr() : "nil";
    ComValue::comterp(comterp());

#if __GNUC__<3
    streambuf* strmbuf = nil;
    if (stringflag.is_false() && strflag.is_false() &&
            symbolflag.is_false() && symflag.is_false()) {
        filebuf * fbuf = new filebuf();
        strmbuf = fbuf;
        if (comterp()->handler()) {
            int fd = Math::max(1, comterp()->handler()->get_handle());
            fbuf->attach(fd);
        } else
            fbuf->attach(fileno(errflag.is_false() ? stdout : stderr));
    } else {
        strmbuf = new std::strstreambuf();
    }
#else
    streambuf* strmbuf = nil;
    if (stringflag.is_false() && strflag.is_false() &&
            symbolflag.is_false() && symflag.is_false()) {
        fileptr_filebuf * fbuf = nil;
        if (comterp()->handler()) {
            fbuf = new fileptr_filebuf(comterp()->handler() && comterp()->handler()->wrfptr()
                                       ? comterp()->handler()->wrfptr() : stdout, ios_base::out);
        } else
            fbuf = new fileptr_filebuf(errflag.is_false() ? stdout : stderr, ios_base::out);
        strmbuf = fbuf;
    } else
        strmbuf = new std::strstreambuf();
#endif
    ostream out(strmbuf);

    int narg = nargs();
    if (narg==1) {

        if (formatstr.is_string())
            out << formatstr.symbol_ptr();
        else
            out << formatstr;  // which could be arbitrary ComValue

    } else {
        switch( printval.type() )
        {
        case ComValue::SymbolType:
        case ComValue::StringType:
            out_form(out, fstr, symbol_pntr( printval.symbol_ref()));
            break;

        case ComValue::BooleanType:
            out_form(out, fstr, printval.boolean_ref());
            break;

        case ComValue::CharType:
            out_form(out, fstr, printval.char_ref());
            break;

        case ComValue::UCharType:
            out_form(out, fstr, printval.uchar_ref());
            break;

        case ComValue::IntType:
            out_form(out, fstr, printval.int_ref());
            break;

        case ComValue::UIntType:
            out_form(out, fstr, printval.uint_ref());
            break;

        case ComValue::LongType:
            out_form(out, fstr, printval.long_ref());
            break;

        case ComValue::ULongType:
            out_form(out, fstr, printval.ulong_ref());
            break;

        case ComValue::FloatType:
            out_form(out, fstr, printval.float_ref());
            break;

        case ComValue::DoubleType:
            out_form(out, fstr, printval.double_ref());
            break;

        case ComValue::ArrayType:
        {

            ALIterator i;
            AttributeValueList* avl = printval.array_val();
            avl->First(i);
            boolean first = true;
            while (!avl->Done(i)) {
                ComValue val(*avl->GetAttrVal(i));
                push_stack(formatstr);
                push_stack(val);
                exec(2,0);
                avl->Next(i);
                if (!avl->Done(i)) out << "\n";
            }
        }
        break;

        case ComValue::BlankType:
            out << "<blank>";
            break;

        case ComValue::UnknownType:
            out_form(out, fstr, nil);
            break;

        default:
            break;
        }
    }


    if (stringflag.is_true() || strflag.is_true()) {
        out << '\0';
        ComValue retval(((std::strstreambuf*)strmbuf)->str());
        push_stack(retval);
    } else if (symbolflag.is_true() || symflag.is_true()) {
        out << '\0';
        int symbol_id = symbol_add(((std::strstreambuf*)strmbuf)->str());
        ComValue retval(symbol_id, ComValue::SymbolType);
        push_stack(retval);
    }
    delete strmbuf;
}
Пример #19
0
void CreateRasterFunc::execute() {
    const int x0 = 0;  
    const int y0 = 1;  
    const int x1 = 2;  
    const int y1 = 3;  
    const int n = 4;
    int coords[n];
    ComValue& vect = stack_arg(0);
    if (!vect.is_type(ComValue::ArrayType) || vect.array_len() != n) {
        reset_stack();
	push_stack(ComValue::nullval());
	return;
    }

    ALIterator i;
    AttributeValueList* avl = vect.array_val();
    avl->First(i);
    for (int j=0; j<n && !avl->Done(i); j++) {
        coords[j] = avl->GetAttrVal(i)->int_val();
	avl->Next(i);
    }

    AttributeList* al = stack_keys();
    Resource::ref(al);
    reset_stack();

    PasteCmd* cmd = nil;

    if (coords[x0] != coords[x1] || coords[y0] != coords[y1]) {

	float dcoords[n];
	((OverlayViewer*)GetEditor()->GetViewer())->ScreenToDrawing
	  (coords[x0], coords[y0], dcoords[x0], dcoords[y0]);
	((OverlayViewer*)GetEditor()->GetViewer())->ScreenToDrawing
	  (coords[x1], coords[y1], dcoords[x1], dcoords[y1]);
	
	OverlayRaster* raster = 
	  new OverlayRaster((int)(dcoords[x1]-dcoords[x0]+1), 
			    (int)(dcoords[y1]-dcoords[y0]+1), 
			    2 /* initialize with border of 2 */);

	OverlayRasterRect* rasterrect = new OverlayRasterRect(raster, stdgraphic);

#if 1
	Transformer* t = new Transformer();
	t->Translate(dcoords[x0], dcoords[y0]);
	rasterrect->SetTransformer(t);
	Unref(t);
#else
        Transformer* rel = get_transformer(al);
#endif

	RasterOvComp* comp = new RasterOvComp(rasterrect);
	comp->SetAttributeList(al);
	if (PasteModeFunc::paste_mode()==0)
	  cmd = new PasteCmd(_ed, new Clipboard(comp));
	ComValue compval(new OverlayViewRef(comp), symbol_add("RasterComp"));
	push_stack(compval);
	execute_log(cmd);
    } else 
	push_stack(ComValue::nullval());

    Unref(al);
}
Пример #20
0
void SelectFunc::execute() {
    static int all_symid = symbol_add("all");
    ComValue all_flagv(stack_key(all_symid));
    boolean all_flag = all_flagv.is_true();
    static int clear_symid = symbol_add("clear");
    ComValue clear_flagv(stack_key(clear_symid));
    boolean clear_flag = clear_flagv.is_true();

    Selection* sel = _ed->GetViewer()->GetSelection();
    if (clear_flag) {
      sel->Clear();
      unidraw->Update();
      reset_stack();
      return;
    }
      
    OverlaySelection* newSel = ((OverlayEditor*)_ed)->overlay_kit()->MakeSelection();
    
    Viewer* viewer = _ed->GetViewer();
    AttributeValueList* avl = new AttributeValueList();
    if (all_flag) {

      GraphicView* gv = ((OverlayEditor*)_ed)->GetFrame();
      Iterator i;
      int count=0;
      for (gv->First(i); !gv->Done(i); gv->Next(i)) {
	GraphicView* subgv = gv->GetView(i);
	newSel->Append(subgv);
	OverlayComp* comp = (OverlayComp*)subgv->GetGraphicComp();
	ComValue* compval = new ComValue(new OverlayViewRef(comp), comp->classid());
	avl->Append(compval);
      }

    } else if (nargs()==0) {
      Iterator i;
      int count=0;
      for (sel->First(i); !sel->Done(i); sel->Next(i)) {
	GraphicView* grview = sel->GetView(i);
	OverlayComp* comp = grview ? (OverlayComp*)grview->GetSubject() : nil;
	ComValue* compval = comp ? new ComValue(new OverlayViewRef(comp), comp->classid()) : nil;

	if (compval) {
	  avl->Append(compval);
	}
	delete newSel;
        newSel = nil;
      }

    } else {

      for (int i=0; i<nargsfixed(); i++) {
        ComValue& obj = stack_arg(i);
	if (obj.object_compview()) {
	  ComponentView* comview = (ComponentView*)obj.obj_val();
	  OverlayComp* comp = (OverlayComp*)comview->GetSubject();
	  if (comp) {
	    GraphicView* view = comp->FindView(viewer);
	    if (view) {
	      newSel->Append(view);
	      ComValue* compval = new ComValue(new OverlayViewRef(comp), comp->classid());
	      avl->Append(compval);
	    }
	  }
	} else if (obj.is_array()) {
	  Iterator it;
	  AttributeValueList* al = obj.array_val();
	  al->First(it);
	  while (!al->Done(it)) {
	    if (al->GetAttrVal(it)->object_compview()) {
	      ComponentView* comview = (ComponentView*)al->GetAttrVal(it)->obj_val();
	      OverlayComp* comp = (OverlayComp*)comview->GetSubject();
	      if (comp) {
		GraphicView* view = comp->FindView(viewer);
		if (view) {
		  newSel->Append(view);
		  ComValue* compval = new ComValue(new OverlayViewRef(comp), comp->classid());
		  avl->Append(compval);
		}
	      }
	    }
	    al->Next(it);
	  }
	}
      }
    }

    if (newSel){
      sel->Clear();
      delete sel;
      _ed->SetSelection(newSel);
      newSel->Update(viewer);
      unidraw->Update();
    }
    reset_stack();
    ComValue retval(avl);
    push_stack(retval);
}
Пример #21
0
void VarFunc::execute() {
  ComValue vallist(stack_arg(0));
  reset_stack();
  
  if (vallist.is_type(ComValue::ArrayType)) {
    AttributeValueList* avl = vallist.array_val();
    AddFunc addfunc(comterp());
    MpyFunc mpyfunc(comterp());
    ComValue sqrsumval(ComValue::zeroval());
    ComValue sumval(ComValue::zeroval());
    ComValue mnsquaresval;
    Iterator it;
    int count = 0;
    for (avl->First(it); !avl->Done(it); avl->Next(it)) {
      count++;

      /* square value and add to sum of squares */
      push_stack(*avl->GetAttrVal(it));
      push_stack(*avl->GetAttrVal(it));
      mpyfunc.exec(2,0);
      push_stack(sqrsumval);
      addfunc.exec(2,0);
      sqrsumval = comterp()->pop_stack();

      /* add value to running sum */
      push_stack(sumval);
      push_stack(*avl->GetAttrVal(it));
      addfunc.exec(2,0);
      sumval = comterp()->pop_stack();
    }

    /* compute mean of squares */
    DivFunc divfunc(comterp());
    push_stack(sqrsumval);
    ComValue countval((float)count);
    push_stack(countval);
    divfunc.exec(2,0);
    mnsquaresval = comterp()->pop_stack();

    /* compute mean squared */
    push_stack(sumval);
    push_stack(countval);
    divfunc.exec(2,0);
    ComValue meanval(comterp()->pop_stack());
    push_stack(meanval);
    push_stack(meanval);
    mpyfunc.exec(2,0);
    ComValue mnsquaredval(comterp()->pop_stack());

    /* subract mean squared from sum of squares to get variance */
    SubFunc subfunc(comterp());
    push_stack(mnsquaresval);
    push_stack(mnsquaredval);
    subfunc.exec(2,0);

    /* compute standard deviation if StdDevFunc */
    if (_stddevfunc) {
      SqrtFunc sqrtfunc(comterp());
      sqrtfunc.exec(1,0);
    }

  } else {
    push_stack(ComValue::zeroval());
  }
}
Пример #22
0
void TransformerFunc::execute() {
    
    ComValue objv(stack_arg(0));
    ComValue transv(stack_arg(0));
    reset_stack();
    if (objv.object_compview()) {
      ComponentView* compview = (ComponentView*)objv.obj_val();
      if (compview && compview->GetSubject()) {
	OverlayComp* comp = (OverlayComp*)compview->GetSubject();
	Graphic* gr = comp->GetGraphic();
	if (gr) {
	  Transformer* trans = gr->GetTransformer();
	  if (transv.is_unknown() || !transv.is_array() || transv.array_val()->Number()!=6) {
	    AttributeValueList* avl = new AttributeValueList();
	    float a00, a01, a10, a11, a20, a21;
	    trans->matrix(a00, a01, a10, a11, a20, a21);
	    avl->Append(new AttributeValue(a00));
	    avl->Append(new AttributeValue(a01));
	    avl->Append(new AttributeValue(a10));
	    avl->Append(new AttributeValue(a11));
	    avl->Append(new AttributeValue(a20));
	    avl->Append(new AttributeValue(a21));
	    ComValue retval(avl);
	    push_stack(retval);

	  } else {
	    float a00, a01, a10, a11, a20, a21;
	    AttributeValueList* avl = transv.array_val();
	    Iterator it;
	    AttributeValue* av;

	    avl->First(it);
	    av = avl->GetAttrVal(it);
	    a00 = av->float_val();
	    avl->Next(it);
	    av = avl->GetAttrVal(it);
	    a01 = av->float_val();
	    avl->Next(it);
	    av = avl->GetAttrVal(it);
	    a10 = av->float_val();
	    avl->Next(it);
	    av = avl->GetAttrVal(it);
	    a11 = av->float_val();
	    avl->Next(it);
	    av = avl->GetAttrVal(it);
	    a20 = av->float_val();
	    avl->Next(it);
	    av = avl->GetAttrVal(it);
	    a21 = av->float_val();

	    Transformer t(a00, a01, a10, a11, a20, a21);
	    *gr->GetTransformer()=t;

	    ComValue compval(new OverlayViewRef(comp), comp->class_symid());
	    push_stack(compval);
	  }
	}
      } 	
    }
}
Пример #23
0
ostream& operator<< (ostream& out, const AttributeValue& sv) {
    AttributeValue* svp = (AttributeValue*)&sv;
    char* title;
    char* symbol;
    int counter;
#if 0
    switch( svp->type() )
	{
	case AttributeValue::KeywordType:
	    out << "Keyword (" << symbol_pntr( svp->symbol_ref() ) << 
		")"; 
	    break;
	    
	case AttributeValue::CommandType:
	    title = "Command (";
	    symbol = symbol_pntr( svp->symbol_ref() );
	    out << title << symbol;
	    counter = strlen(title) + strlen(symbol);
	    while( ++counter < 32 ) out << ' ';
	    out << ")";
	    break;
	    
	case AttributeValue::SymbolType:
	    out << "symbol (" << svp->symbol_ptr()  << ")";
	    break;
	    
	case AttributeValue::StringType:
	    out << "string (" << svp->string_ptr()  << ")";
	    break;
	    
	case AttributeValue::BooleanType:
	    out << "boolean (" << svp->boolean_ref() << ")";
	    break;
	    
	case AttributeValue::CharType:
	    out << "char (" << svp->char_ref() << ":" << (int)svp->char_ref() << ")";
	    break;
	    
	case AttributeValue::UCharType:
	    out << "uchar (" << svp->char_ref() << ":" << (int)svp->char_ref() << ")";
	    break;
	    
	case AttributeValue::IntType:
	    out << "int (" << svp->int_ref() << ")";
	    break;
	    
	case AttributeValue::UIntType:
	    if (svp->state()==AttributeValue::OctState) 
	      out << "uint (" << svp->uint_ref() << ")";
	    else if (svp->state()==AttributeValue::HexState) 
	      out << "uint (" << svp->uint_ref() << ")";
	    else
	      out << "uint (" << svp->uint_ref() << ")";
	    break;
	    
	case AttributeValue::LongType:
	    out << "Long (" << svp->long_ref() << ")";
	    break;
	    
	case AttributeValue::ULongType:
	    out << "ulong (" << svp->ulong_ref() << ")";
	    break;
	    
	case AttributeValue::FloatType:
	    out << "float (" << svp->float_ref() << ")";
	    break;
	    
	case AttributeValue::DoubleType:
	    out << "double (" << svp->double_ref() << ")";
	    //printf("%9.2f\n", svp->double_ref());
	    break;
	    
	case AttributeValue::EofType:
	    out << "eof";
	    break;
	    
	case AttributeValue::ArrayType:
	  {
	    out << "list of length " << svp->array_len();
	    ALIterator i;
	    AttributeValueList* avl = svp->array_val();
	    avl->First(i);
	    boolean first = true;
	    while (!avl->Done(i)) {
 	        out << "\n\t" << *avl->GetAttrVal(i);
	        avl->Next(i);
	    }
	  }
	    break;
	    
	case AttributeValue::BlankType:
	    break;
	    
	default:
	    break;
	}
#else
        switch(svp->type()) {
	case AttributeValue::KeywordType:
	  out << "Keyword (" << symbol_pntr( svp->symbol_ref() ) << 
	    ")"; 
	  break;
	  
	case AttributeValue::CommandType:
	  title = "Command (";
	  symbol = symbol_pntr( svp->symbol_ref() );
	  out << title << symbol;
	  counter = strlen(title) + strlen(symbol);
	  while( ++counter < 32 ) out << ' ';
	  out << ")";
	  break;
	  
	case AttributeValue::SymbolType:
	  out << svp->symbol_ptr();
	  break;

	case AttributeValue::StringType:
	  out << "\"" << svp->string_ptr() << "\"";
	  break;

	case AttributeValue::CharType:
	  out << svp->char_ref();
	  break;

	case AttributeValue::UCharType:
	  out << svp->char_ref();
	  break;
	  
	case AttributeValue::IntType:
	  out << svp->int_ref();
	  break;
	  
	case AttributeValue::UIntType:
	  if (svp->state()==AttributeValue::OctState)
	    out << "0" << std::oct << svp->uint_ref() << std::dec;
	  else if (svp->state()==AttributeValue::HexState)
	    out << "0x" << std::hex << svp->uint_ref() << std::dec;
	  else
	    out << svp->uint_ref();
	  break;

	case AttributeValue::BooleanType:
	  out << svp->uint_ref();
	  break;

	case AttributeValue::ShortType:
	  out << svp->short_ref();
	  break;

	case AttributeValue::UShortType:
	  if (svp->state()==AttributeValue::OctState)
	    out << "0" << std::oct << svp->ushort_ref() << std::dec;
	  else if (svp->state()==AttributeValue::HexState)
	    out << "0x" << std::hex << svp->ushort_ref() << std::dec;
	  else
	    out << svp->ushort_ref();
	  break;

	case AttributeValue::LongType:
	  out << svp->long_ref();
	  break;
	  
	case AttributeValue::ULongType:
	  if (svp->state()==AttributeValue::OctState)
	    out << "0" << std::oct << svp->ulong_ref() << std::dec;
	  else if (svp->state()==AttributeValue::HexState)
	    out << "0x" << std::hex << svp->ulong_ref() << std::dec;
	  else
	    out << svp->ulong_ref();
	  break;
	  
	case AttributeValue::FloatType:
#if __GNUG__<3
	  out.form("%.6f", svp->float_val());
#else
          {
	  const int bufsiz=256;
	  char buffer[bufsiz];
	  snprintf(buffer, bufsiz, "%.6f", svp->float_val());
	  out << buffer;
	  }
#endif
	  break;
	  
	case AttributeValue::DoubleType:
#if __GNUG__<3
	  out.form("%.6f", svp->double_val());
#else
	  {
	  const int bufsiz=256;
	  char buffer[bufsiz];
	  snprintf(buffer, bufsiz, "%.6f", svp->double_val());
	  out << buffer;
	  }
#endif
	  break;

	case AttributeValue::EofType:
	    out << "eof";
	    break;
	    
	case AttributeValue::ArrayType:
	  {
	    //out << "array of length " << svp->array_len();
	    ALIterator i;
	    AttributeValueList* avl = svp->array_val();
	    avl->First(i);
	    boolean first = true;
	    while (!avl->Done(i)) {
	      if (!first)
		out << ",";
	      out << *avl->GetAttrVal(i);
	      avl->Next(i);
	      first = false;
	    }
	  }
	    break;
	    
	case AttributeValue::BlankType:
	    break;
	    
	case AttributeValue::ObjectType:
	  out << "<" << symbol_pntr(svp->class_symid()) << ">";
	  break;

	case AttributeValue::StreamType:
	  out << "<stream:" << svp->stream_mode() << ">";
	  break;
	    
	default:
	  out << "nil";
	  break;
	}
#endif
    return out;
}