Exemple #1
0
static
void BrowWriteUnformattedSet(Tcl_Interp *interp,struct Instance *i)
{
  CONST struct set_t *s;
  unsigned long len,c;
  char value[80];
  s = SetAtomList(i);
  switch(SetKind(s)) {
  case empty_set:
    break;
  case integer_set:
  case string_set:
    len = Cardinality(s);
    for(c=1;c<=len;c++) {
      if (SetKind(s)==integer_set) {
        sprintf(value,"%u", FetchIntMember(s,c));
        Tcl_AppendResult(interp,value," ",(char *)NULL);
      } else {
        Tcl_AppendResult(interp,"'",SCP(FetchStrMember(s,c)),"' ",
                         (char *)NULL);
      }
    }
    return;
  default:
    return;
  }
}
Exemple #2
0
int Asc_BrowSimListCmd(ClientData cdata, Tcl_Interp *interp,
                   int argc, CONST84 char *argv[])
{
  struct Instance *sptr;
  struct gl_list_t *sl;
  unsigned long len, c;

  UNUSED_PARAMETER(cdata);
  (void)argv;     /* stop gcc whine about unused parameter */

  if ( argc != 1 ) {
    Tcl_SetResult(interp, "wrong # args to \"slist\"", TCL_STATIC);
    return TCL_ERROR;
  }
  sl = g_simulation_list;
  if (sl==NULL) {
    Tcl_SetResult(interp, "Simulation list is NULL", TCL_STATIC);
  } else {
    len = gl_length(sl);
    for(c=1;c<=len;c++) {
      sptr = (struct Instance *)gl_fetch(sl,c);
      Tcl_AppendElement(interp,(char *)SCP(GetSimulationName(sptr)));
    }
  }
  return TCL_OK;
}
Exemple #3
0
struct Instance *FindInstance(symchar *str)
{
  register struct DumpRec *p,*prev;
  register int cmp;
  register struct gl_list_t *l;
  register struct Instance *result;
  register unsigned long bucket;
  if (*(SCP(str)) == '\0') return NULL;
  bucket = DUMPHASHINDEX(SCP(str));
  if ((p = g_dump_ht[bucket])==NULL) return NULL;
  if ((cmp=CmpSymchar(p->type,str)) > 0) return NULL;
  else {
    if (cmp==0) {
      l = p->instances;
      result = (struct Instance *)gl_fetch(l,gl_length(l));
      gl_delete(l,gl_length(l),0);
      g_dump_inst_count--;
      if (gl_length(l)==0) {
	gl_destroy(l);
	g_dump_ht[bucket] = p->next;
	g_dump_type_count--;
	ascfree((char *)p);
      }
    }
    else {
      prev = p;
      if ((p = p->next)==NULL) return NULL;
      while((cmp=CmpSymchar(p->type,str))<0) {
	prev = p;
	if ((p=p->next)==NULL) return NULL;
      }
      if (cmp!=0) return NULL;
      /* pick out instance */
      l = p->instances;
      result = (struct Instance *)gl_fetch(l,gl_length(l));
      gl_delete(l,gl_length(l),0);
      g_dump_inst_count--;
      if (gl_length(l)==0) {
	gl_destroy(l);
	prev->next = p->next;
	g_dump_type_count--;
	ascfree((char *)p);
      }
    }
    return result;
  }
}
Exemple #4
0
static
int Asc_BrowInstAtomValue(Tcl_Interp *interp, struct Instance *i)
{
  enum inst_t kind;
  char value[256];
  char *ustr;

  switch(kind = InstanceKind(i)) {
  case DUMMY_INST:
    break;
  case REAL_INST:
  case REAL_ATOM_INST:
  case REAL_CONSTANT_INST:
    ustr = Asc_UnitValue(i);
    Tcl_AppendResult(interp,ustr,(char *)NULL);
    break;
  case INTEGER_INST:
  case INTEGER_ATOM_INST:
  case INTEGER_CONSTANT_INST:
    sprintf(value,"%ld",GetIntegerAtomValue(i));
    Tcl_AppendResult(interp,value,(char *)NULL);
    break;
  case BOOLEAN_INST:
  case BOOLEAN_ATOM_INST:
  case BOOLEAN_CONSTANT_INST:
    sprintf(value,GetBooleanAtomValue(i)?"TRUE":"FALSE");
    Tcl_AppendResult(interp,value,(char *)NULL);
    break;
  case SYMBOL_INST:
  case SYMBOL_ATOM_INST:
  case SYMBOL_CONSTANT_INST:
    Tcl_AppendResult(interp,(char *)SCP(GetSymbolAtomValue(i)),(char *)NULL);
    break;
  case SET_INST:
  case SET_ATOM_INST:
    BrowWriteUnformattedSet(interp,i);
    break;
  case REL_INST:
    ustr = Asc_UnitValue(i);
    Tcl_AppendResult(interp,ustr,(char *)NULL);
    break;
  case LREL_INST:
    if (GetInstanceLogRel(i)!=NULL) {
      Tcl_AppendResult(interp,(LogRelResidual(GetInstanceLogRel(i)) ?
                                   "TRUE" : "FALSE"), (char *)NULL);
    } else {
      Tcl_AppendResult(interp,"UNDEFINED",(char *)NULL);
    }
    break;
  default:
    Asc_Panic(2, "Asc_BrowInstAtomValue",
              "Unrecognized atom type in Asc_BrowInstAtomValue\n");
  }
  return 0;
}
Exemple #5
0
double var_odeatol(struct var_variable *var){
	struct Instance *c;
	if(var==NULL||var->ratom==NULL){
		ERROR_REPORTER_HERE(ASC_PROG_ERR,"bad var");
		return -1;
	}
	c = ChildByChar(IPTR(var->ratom),ODEATOL_V);
	if(c==NULL){
		ERROR_REPORTER_HERE(ASC_PROG_ERR,"no '%s' field",SCP(ODEATOL_V));
		return -1;
	}
	return RealAtomValue(c);
}
Exemple #6
0
int Asc_BrowInstListCmd(ClientData cdata, Tcl_Interp *interp,
                    int argc, CONST84 char *argv[])
{
  struct Instance *p, *c;
  struct InstanceName name;
  unsigned long cc, cindex;

  UNUSED_PARAMETER(cdata);
  UNUSED_PARAMETER(argv);

  if ( argc != 1 ) {
    Tcl_SetResult(interp, "wrong # args to \"instlist\"", TCL_STATIC);
    return TCL_ERROR;
  }
  if (g_depth<1) {
    Tcl_SetResult(interp, "No instances to list", TCL_STATIC);
    return TCL_OK;
  }
  for(cc=1;cc<g_depth;cc++) {
    p = g_instlist[cc];
    c = g_instlist[cc+1];
    cindex = ChildIndex(p,c);
    if(cindex) {
      name = ChildName(p,cindex);
      switch(InstanceNameType(name)) {
      case IntArrayIndex:
        PRINTF("[%ld]\n",InstanceIntIndex(name)); break;
      case StrArrayIndex:
        PRINTF("['%s']\n",SCP(InstanceStrIndex(name)));
        break;
      case StrName:
        PRINTF("%s\n",SCP(InstanceNameStr(name)));
        break;
      }
    }
  }
  return TCL_OK;
}
Exemple #7
0
void TrashType(symchar *str)
{
  register unsigned long c,len,bucket;
  register struct DumpRec *p,*prev;
  register struct gl_list_t *l;
  register int cmp;
  assert(AscFindSymbol(str)!=NULL);
  if (*(SCP(str)) == '\0') return;
  bucket = DUMPHASHINDEX(SCP(str));
  if ((p = g_dump_ht[bucket])==NULL) return;
  cmp = CmpSymchar(p->type,str);
  if (cmp == 0)
    g_dump_ht[bucket] = p->next;
  else
    if (cmp > 0) return;
    else {
      prev = p;
      if ((p = p->next)==NULL) return;
      while((cmp=CmpSymchar(p->type,str))<0) {
	prev = p;
	if ((p=p->next)==NULL) return;
      }
      if (cmp!=0) return;
      /* remove from linked list */
      prev->next = p->next;
    }
  if ((l=p->instances)!=NULL) {
    len = gl_length(l);
    for(c=1;c<=len;c++)
      DestroyInstance((struct Instance *)gl_fetch(l,c),NULL);
    gl_destroy(l);
    g_dump_inst_count -= len;
  }
  g_dump_type_count--;
  ascfree((char *)p);
}
Exemple #8
0
void AddInstance(struct Instance *i)

     /* add instance i to the trash dump */
{
  register struct DumpRec *p,*prev;
  register symchar *type;
  register int cmp;
  register unsigned long bucket;
  type = InstanceType(i);
  if ((i==NULL)||(type==NULL)) return;
  bucket = DUMPHASHINDEX(SCP(type));
  if ((p=g_dump_ht[bucket])==NULL) {
    g_dump_type_count++;
    g_dump_ht[bucket] = ASC_NEW(struct DumpRec);
    p = g_dump_ht[bucket];
    p->next = NULL;
  }
Exemple #9
0
int Asc_BrowSimTypeCmd(ClientData cdata, Tcl_Interp *interp,
                   int argc, CONST84 char *argv[])
{
  struct Instance *sptr;

  UNUSED_PARAMETER(cdata);

  if ( argc != 2 ) {
    Tcl_SetResult(interp,"wrong # args: Usage \"simtype\" simname",TCL_STATIC);
    return TCL_ERROR;
  }
  sptr = Asc_FindSimulationRoot(AddSymbol(argv[1]));
  if (sptr) {
    Tcl_AppendResult(interp,(char *)SCP(InstanceType(sptr)),(char *)NULL);
    return TCL_OK;
  }
  Tcl_SetResult(interp, "Simulation name not found", TCL_STATIC);
  return TCL_ERROR;
}
/**
   'heatex_prepare' just gets the stream details and the number of slices for
	internal calculation, and checks that the stream names are valid in FPROPS.

	TODO FIXME allow general support for specification of components, incl type,source.
*/
int heatex_prepare(struct BBoxInterp *bbox,
	   struct Instance *data,
	   struct gl_list_t *arglist
){
	HeatExData *hxd = ASC_NEW(HeatExData);
	if(!hxd)goto fail;

	struct Instance *compinst[2], *ninst;
	const char *comp[2];

	N_SYM = AddSymbol("n");
	/* we look through these 0,1 below */
	heatex_symbols[0] = AddSymbol("component");
	heatex_symbols[1] = AddSymbol("component_hot");

	ninst = ChildByChar(data,N_SYM);
	if(!ninst){
		ERROR_REPORTER_HERE(ASC_USER_ERROR
			,"Couldn't locate '%s' in DATA, please check usage.",SCP(N_SYM)
		);
		goto fail;
	}
	if(InstanceKind(ninst)!=INTEGER_CONSTANT_INST){
		ERROR_REPORTER_HERE(ASC_USER_ERROR,"DATA member '%s' must be a symbol_constant",SCP(N_SYM));
		goto fail;
	}
	hxd->n = IC_INST(ninst)->value;

	int i;
	for(i=0;i<2;++i){
		/* get the component names for cold and hot sides */
		compinst[i] = ChildByChar(data,heatex_symbols[i]);
		if(!compinst[i]){
			ERROR_REPORTER_HERE(ASC_USER_ERROR
				,"Couldn't locate '%s' in DATA, please check usage."
				,SCP(heatex_symbols[i])
			);
			goto fail;
		}
		if(InstanceKind(compinst[i])!=SYMBOL_CONSTANT_INST){
			ERROR_REPORTER_HERE(ASC_USER_ERROR,"DATA member '%s' must be a symbol_constant",SCP(heatex_symbols[i]));
			goto fail;
		}
		comp[i] = SCP(SYMC_INST(compinst[i])->value);
		CONSOLE_DEBUG("%s: %s",SCP(heatex_symbols[i]),comp[i]);
		if(comp[i]==NULL || strlen(comp[i])==0){
			ERROR_REPORTER_HERE(ASC_USER_ERROR,"'%s' is NULL or empty",heatex_symbols[i]);
			goto fail;
		}

		hxd->comp[i] = fprops_fluid(comp[i], NULL,NULL);
		if(hxd->comp[i] == NULL){
			ERROR_REPORTER_HERE(ASC_USER_ERROR,"Heat exchanger %s name '%s' not recognised. Check list of supported species.",SCP(heatex_symbols[i]),comp[i]);
			goto fail;
		}
	}

	bbox->user_data = (void *)hxd;
	ERROR_REPORTER_HERE(ASC_PROG_NOTE,"Heat exchanger data structure OK.\n",comp);
	return 0;

fail:
	if(hxd){
		/* TODO FIXME implement FPROPS freeing, will be important with fprops2 */
		//if(hxd->comp[0])ASC_FREE(hxd->comp[0]);
		//if(hxd->comp[1])ASC_FREE(hxd->comp[1]);
		ASC_FREE(hxd);
	}
	return 1;
}
Exemple #11
0
static void mime_content_type(MIME_NODE *node, const HEADER_OPTS *header_info)
{
	const char *cp;
	ssize_t tok_count;
	MIME_STATE *state = node->state;

#define PARSE_CONTENT_TYPE_HEADER(state, ptr) \
	header_token(state->token, MIME_MAX_TOKEN, \
		state->token_buffer, ptr, RFC2045_TSPECIALS, ';')

	cp = STR(node->buffer) + strlen(header_info->name) + 1;
	if ((tok_count = PARSE_CONTENT_TYPE_HEADER(state, &cp)) <= 0) {

		/*
		* other/whatever.
		*/
		node->ctype = MIME_CTYPE_OTHER;
		return;
	}

	/* tok_count > 0 */

	/*
	* message/whatever body parts start with another block of message
	* headers that we may want to look at. The partial and external-body
	* subtypes cannot be subjected to 8-bit -> 7-bit conversion, so we
	* must properly recognize them.
	*/
	if (TOKEN_MATCH(state->token[0], "message")) {
		node->ctype = MIME_CTYPE_MESSAGE;
		node->stype = MIME_STYPE_OTHER;
		if (tok_count >= 3 && state->token[1].type == '/') {
			if (TOKEN_MATCH(state->token[2], "rfc822"))
				node->stype = MIME_STYPE_RFC822;
			else if (TOKEN_MATCH(state->token[2], "partial"))
				node->stype = MIME_STYPE_PARTIAL;
			else if (TOKEN_MATCH(state->token[2], "external-body"))
				node->stype = MIME_STYPE_EXTERN_BODY;
		}
	}

	/*
	* multipart/digest has default content type message/rfc822,
	* multipart/whatever has default content type text/plain.
	*/
	else if (TOKEN_MATCH(state->token[0], "multipart")) {
		node->ctype = MIME_CTYPE_MULTIPART;
		if (tok_count >= 3 && state->token[1].type == '/') {
			if (TOKEN_MATCH(state->token[2], "digest")) {
				node->ctype = MIME_CTYPE_MESSAGE;
				node->stype = MIME_STYPE_RFC822;
			} else if (TOKEN_MATCH(state->token[2], "alternative")) {
				node->stype = MIME_STYPE_ALTERNATIVE;
			} else if (TOKEN_MATCH(state->token[2], "related")) {
				node->stype = MIME_STYPE_RELATED;
			} else if (TOKEN_MATCH(state->token[2], "mixed")) {
				node->stype = MIME_STYPE_MIXED;
			} else {
				node->stype = MIME_STYPE_OTHER;
			}
		} else {
			node->ctype = MIME_CTYPE_TEXT;
			node->stype = MIME_STYPE_PLAIN;
		}

		/*
		* Yes, this is supposed to capture multiple boundary strings,
		* which are illegal and which could be used to hide content in
		* an implementation dependent manner. The code below allows us
		* to find embedded message headers as long as the sender uses
		* only one of these same-level boundary strings.
		* 
		* Yes, this is supposed to ignore the boundary value type.
		*/
		while ((tok_count = PARSE_CONTENT_TYPE_HEADER(state, &cp)) >= 0) {
			if (tok_count < 3 || state->token[1].type != '=')
				continue;
			if (TOKEN_MATCH(state->token[0], "boundary")) {
				if (node->boundary == NULL)
					node->boundary = acl_vstring_alloc(256);
				/* 需要添加 "--" 做为分隔符的前导符 */
				SCP(node->boundary, "--");
				SCAT(node->boundary, state->token[2].u.value);
				break;
			}
		}
	}

	/*
	* text/whatever. Right now we don't really care if it is plain or
	* not, but we may want to recognize subtypes later, and then this
	* code can serve as an example.
	*/
	else if (TOKEN_MATCH(state->token[0], "text")) {
		node->ctype = MIME_CTYPE_TEXT;
		if (tok_count >= 3 && state->token[1].type == '/') {
			if (TOKEN_MATCH(state->token[2], "plain"))
				node->stype = MIME_STYPE_PLAIN;
			else if (TOKEN_MATCH(state->token[2], "html"))
				node->stype = MIME_STYPE_HTML;
			else
				node->stype = MIME_STYPE_OTHER;
		} else
			node->stype = MIME_STYPE_OTHER;

		while ((tok_count = PARSE_CONTENT_TYPE_HEADER(state, &cp)) >= 0) {
			if (tok_count < 3 || state->token[1].type != '=')
				continue;
			if (TOKEN_MATCH(state->token[0], "charset")
				&& node->charset == NULL)
			{
				node->charset = acl_mystrdup(state->token[2].u.value);
				break;
			}
		}

		/* 如果没有字符集, 则缺省采用 gb2312 */
		if (node->charset == NULL)
			node->charset = acl_mystrdup("gb2312");
	}
	else if (TOKEN_MATCH(state->token[0], "image")) {
		node->ctype = MIME_CTYPE_IMAGE;
		if (tok_count >= 3 && state->token[1].type == '/') {
			if (TOKEN_MATCH(state->token[2], "jpeg"))
				node->stype = MIME_STYPE_JPEG;
			else if (TOKEN_MATCH(state->token[2], "gif"))
				node->stype = MIME_STYPE_GIF;
			else if (TOKEN_MATCH(state->token[2], "bmp"))
				node->stype = MIME_STYPE_BMP;
			else if (TOKEN_MATCH(state->token[2], "png"))
				node->stype = MIME_STYPE_PNG;
			else
				node->stype = MIME_STYPE_OTHER;
		} else
			node->stype = MIME_STYPE_OTHER;

		while ((tok_count = PARSE_CONTENT_TYPE_HEADER(state, &cp)) >= 0) {
			if (tok_count < 3 || state->token[1].type != '=')
				continue;
			if (TOKEN_MATCH(state->token[0], "name")
				&& node->header_name == NULL)
			{
				node->header_name = acl_mystrdup(state->token[2].u.value);
				break;
			}
		}
	}
	else if (TOKEN_MATCH(state->token[0], "application")) {
		node->ctype = MIME_CTYPE_APPLICATION;
		if (tok_count >= 3 && state->token[1].type == '/') {
			if (TOKEN_MATCH(state->token[2], "octet-stream"))
				node->stype = MIME_STYPE_OCTET_STREAM;
			else
				node->stype = MIME_STYPE_OTHER;
		}
		while ((tok_count = PARSE_CONTENT_TYPE_HEADER(state, &cp)) >= 0) {
			if (tok_count < 3 || state->token[1].type != '=')
				continue;
			if (TOKEN_MATCH(state->token[0], "name")
				&& node->header_name == NULL)
			{
				node->header_name = acl_mystrdup(state->token[2].u.value);
				break;
			}
		}
	}
}
Exemple #12
0
/**
   'fprops_prepare' just gets the data member and checks that it's
	valid, and stores it in the blackbox data field.
*/
int asc_fprops_prepare(struct BBoxInterp *bbox,
	   struct Instance *data,
	   struct gl_list_t *arglist
){
	struct Instance *compinst, *typeinst, *srcinst;
	const char *comp, *type = NULL, *src = NULL;

	fprops_symbols[0] = AddSymbol("component");
	fprops_symbols[1] = AddSymbol("type");
	fprops_symbols[2] = AddSymbol("source");

	/* get the component name */
	compinst = ChildByChar(data,COMPONENT_SYM);
	if(!compinst){
		ERROR_REPORTER_HERE(ASC_USER_ERROR
			,"Couldn't locate 'component' in DATA, please check usage of FPROPS."
		);
		return 1;
	}
	if(InstanceKind(compinst)!=SYMBOL_CONSTANT_INST){
		ERROR_REPORTER_HERE(ASC_USER_ERROR,"DATA member 'component' must be a symbol_constant");
		return 1;
	}
	comp = SCP(SYMC_INST(compinst)->value);
	if(comp==NULL || strlen(comp)==0){
		ERROR_REPORTER_HERE(ASC_USER_ERROR,"'component' is NULL or empty");
		return 1;
	}

	/* get the component correlation type (FPROPS doesn't mind if none given) */
	typeinst = ChildByChar(data,TYPE_SYM);
	if(typeinst){
		if(InstanceKind(typeinst)!=SYMBOL_CONSTANT_INST){
			ERROR_REPORTER_HERE(ASC_USER_ERROR,"DATA member 'type' must be a symbol_constant");
			return 1;
		}
		type = SCP(SYMC_INST(typeinst)->value);
		//CONSOLE_DEBUG("TYPE: %s",type?type:"(null)");
		if(type && strlen(type)==0)type = NULL;
	}

	/* get the source data string (FPROPS doesn't mind if none given) */
	srcinst = ChildByChar(data,SOURCE_SYM);
	if(srcinst){
		if(InstanceKind(srcinst)!=SYMBOL_CONSTANT_INST){
			ERROR_REPORTER_HERE(ASC_USER_ERROR,"DATA member 'source' must be a symbol_constant");
			return 1;
		}
		src = SCP(SYMC_INST(srcinst)->value);
		CONSOLE_DEBUG("SOURCE: %s",src?src:"(null)");
		if(src && strlen(src)==0)src = NULL;
	}

	bbox->user_data = (void *)fprops_fluid(comp,type,src);
	if(bbox->user_data == NULL){
		ERROR_REPORTER_HERE(ASC_USER_ERROR,"Component name/type was not recognised. Check the source-code for for the supported species.");
		return 1;
	}

#ifdef ASC_FPROPS_DEBUG
	ERROR_REPORTER_HERE(ASC_PROG_NOTE,"Prepared component '%s'%s%s%s OK.\n"
		,comp
		,type?" type '":""
		,type?type:""
		,type?"'":""
	);
#endif
	return 0;
}
Exemple #13
0
int Asc_BrowInstQueryCmd(ClientData cdata, Tcl_Interp *interp,
                     int argc, CONST84 char *argv[])
{
  struct Instance *i;
  struct Instance *p;
  struct InstanceName in;
  char buf[MAXIMUM_NUMERIC_LENGTH];     /* string to hold long integer */
  char *rstring = NULL;
  char *tmps = NULL;
  unsigned long n;
  unsigned long c;
  unsigned long nch;
  unsigned long npa;
  int result;

  UNUSED_PARAMETER(cdata);

  if ( argc == 1 ) {
    Tcl_AppendResult(interp,"Usage : inst <",
        "name, type, kind, old, nchild, nparents, child, parent",
        ", atomchild, isassignable, isfixable, "
        "ismutable, isconstant, iswhenvar, operands",
        ", atomvalue> [current,search]",(char *)NULL);
    return TCL_ERROR;
  }
  i = g_curinst;
  if ( argc == 3 ) {
    if(strncmp(argv[2],"current",3)==0) {
      i = g_curinst;
    } else if(strncmp(argv[2],"search",3)==0) {
      i = g_search_inst;
    } else {
      i = g_curinst;
    }
  }

  if (!i) {
    Tcl_SetResult(interp, "NULL_INSTANCE", TCL_STATIC);
    return TCL_ERROR;
  }
  if (strncmp(argv[1],"name",3)==0) {
    result = BrowInstName(i,&rstring);
    WriteInstanceName(stdout,i,NULL); PRINTF("\n");
    return TCL_OK;
  }

  if (strncmp(argv[1],"operands",3)==0) {
    return BrowOperands(interp,i);
  }
  if (strncmp(argv[1],"type",3)==0) {
    Tcl_AppendResult(interp,SCP(InstanceType(i)),(char *)NULL);
    return TCL_OK;
  }

  if (strncmp(argv[1],"kind",3)==0) {
    result = BrowInstKind(i,&rstring);
    if (result==0) {
      Tcl_ResetResult(interp);
      Tcl_AppendResult(interp,rstring,(char *)NULL);
      ascfree(rstring);
      return TCL_OK;
    } else {
      if (rstring) {
        ascfree(rstring);
      }
      Tcl_ResetResult(interp);
      return TCL_ERROR;
    }
  }

  /* always uses current instance */
  if (strncmp(argv[1],"atomchild",5)==0) {
    result = BrowInstIsAtomChild(i);
    if (result) {
      Tcl_SetResult(interp, "1", TCL_STATIC);
    } else {
      Tcl_SetResult(interp, "0", TCL_STATIC);
    }
    return TCL_OK;
  }

  if (strncmp(argv[1],"isassignable",4)==0) {
    result = BrowInstIsAssignable(i);
    if (result) {
      Tcl_SetResult(interp, "1", TCL_STATIC);
    } else {
      Tcl_SetResult(interp, "0", TCL_STATIC);
    }
    return TCL_OK;
  }

  if (strncmp(argv[1],"isfixable",3)==0) {
    result = BrowInstIsFixable(i);
    if (result) {
      Tcl_SetResult(interp, "1", TCL_STATIC);
    } else {
      Tcl_SetResult(interp, "0", TCL_STATIC);
    }
    return TCL_OK;
  }

  if (strncmp(argv[1],"ismutable",3)==0) {
    result = Asc_BrowInstIsMutable(i);
    if (result) {
      Tcl_SetResult(interp, "1", TCL_STATIC);
   } else {
      Tcl_SetResult(interp, "0", TCL_STATIC);
    }
    return TCL_OK;
  }

  if (strncmp(argv[1],"isconstant",3)==0) {
    result = Asc_BrowInstIsConstant(i);
    if (result) {
      Tcl_SetResult(interp, "1", TCL_STATIC);
    } else {
      Tcl_SetResult(interp, "0", TCL_STATIC);
    }
    return TCL_OK;
  }

  if (strncmp(argv[1],"iswhenvar",3)==0) {
    result = BrowInstIsWhenVar(i);
    if (result) {
      Tcl_SetResult(interp, "1", TCL_STATIC);
    } else {
      Tcl_SetResult(interp, "0", TCL_STATIC);
    }
    return TCL_OK;
  }

  if (strncmp(argv[1],"atomvalue",5)==0) {
    if(Asc_BrowInstIsAtomic(i)
       || BrowInstIsAtomChild(i) || Asc_BrowInstIsConstant (i)) {
      if (AtomAssigned(i)) {
        result = Asc_BrowInstAtomValue(interp,i);
      } else {
        Tcl_AppendResult(interp,"UNDEFINED",(char *)NULL);
        return TCL_OK;
      }
    } else if(InstanceKind(i)== REL_INST || InstanceKind(i)==LREL_INST ) {
      result = Asc_BrowInstAtomValue(interp,i);
    } else {
      Tcl_AppendResult(interp,
                       "Only atomic instances, constants or relations"
                       " have the notion of value",
                       (char *)NULL);
      return TCL_ERROR;
    }
    if (result==0) {
      return TCL_OK;
    } else {
      Tcl_ResetResult(interp);
      return TCL_OK;
    }
  }

  if (strncmp(argv[1],"child",3)==0) {
    nch = NumberChildren(i);
    if (nch) {
      tmps = Asc_MakeInitString(256);
      for(c=1;c<=nch;c++) {
        in = ChildName(i,c);
        switch(InstanceNameType(in)) {
        case StrName:
          Tcl_AppendElement(interp,(char *)InstanceNameStr(in));
          break;
        case IntArrayIndex:
          sprintf(tmps,"[%ld]",InstanceIntIndex(in));
          Tcl_AppendElement(interp,tmps);
          break;
        case StrArrayIndex:
          sprintf(tmps,"[\'%s\']",SCP(InstanceStrIndex(in)));
          Tcl_AppendElement(interp,tmps);
          break;
        }
      }
      ascfree(tmps);
      return TCL_OK;
    } else {
      Tcl_SetResult(interp, "0", TCL_STATIC);
      return TCL_OK;
    }
  }

  if (strncmp(argv[1],"parents",3)==0) {
    npa = NumberParents(i);
    if (npa) {
      tmps = Asc_MakeInitString(256); /* fixme size assumed */
      for(c=1;c<=npa;c++) {
        p = InstanceParent(i,c);
        in = ParentsName(p,i);
        switch(InstanceNameType(in)) {
        case StrName:
          Tcl_AppendElement(interp,(char *)SCP(InstanceNameStr(in)));
          break;
        case IntArrayIndex:
          sprintf(tmps,"[%ld]",InstanceIntIndex(in));
          Tcl_AppendElement(interp,tmps);
          break;
        case StrArrayIndex:
          sprintf(tmps,"[\'%s\']",SCP(InstanceStrIndex(in)));
          Tcl_AppendElement(interp,tmps);
          break;
        }
      }
      ascfree(tmps);
      return TCL_OK;
    }
  }

  if (strncmp(argv[1],"nchild",3)==0) {
    result = BrowInstNChild(i,&n);
    if (result==0) {
      sprintf(buf, "%lu", n);
      Tcl_SetResult(interp, buf, TCL_VOLATILE);
      return TCL_OK;
    } else {
      Tcl_SetResult(interp, "0", TCL_STATIC);
      return TCL_OK;
    }
  }

  if (strncmp(argv[1],"nparents",3)==0) {
    result = BrowInstNParents(i,&n);
    if (result==0) {
      sprintf(buf, "%lu", n);
      Tcl_SetResult(interp, buf, TCL_VOLATILE);
    }
    return TCL_OK;
  }

  Tcl_SetResult(interp, "unrecognized command to inst", TCL_STATIC);
  return TCL_ERROR;/*UNREACHED*/
}
Exemple #14
0
string& string::operator =(const char* s)
{
	SCP(vbf_, s);
	return *this;
}