Ejemplo n.º 1
0
CBTType *TreeFindNode(CBTType *treeNode,DATA data)         //查找结点
{
	CBTType *ptr;
	if(treeNode == NULL)
	{
		return NULL;
	}
	else
	{	
		if(treeNode->data == data)
		{	
			return treeNode;
		}
		else
		{
			if(ptr = TreeFindNode(treeNode->left,data))            //分别向左右子树递归查找
			{
				return ptr;
			}else if(ptr = TreeFindNode(treeNode->right,data))
			{
				return ptr;
			}
			else
			{
				return NULL;
			}
		}
	}

}
Ejemplo n.º 2
0
JNIEXPORT void JNICALL Java_LocalDataProvider_SetEnvironmentSpecific(JNIEnv *env, jobject obj, 
																	 jstring in, jstring jdefNode)
{
	int status, nid;
    const char *in_char = (*env)->GetStringUTFChars(env, in, 0);
	const char *defNode;
    struct descriptor in_d = {0,DTYPE_T,CLASS_S,0};
    EMPTYXD(xd);
	error_message[0] = 0;
	if(in_char && *in_char)
	{
		in_d.length = strlen(in_char);
		in_d.pointer = (char *)in_char;
		status = TdiCompile(&in_d, &xd MDS_END_ARG);
		if(status & 1)
    		status = TdiData(&xd, &xd MDS_END_ARG);
		if(!(status & 1))
   			strncpy(error_message, MdsGetMsg(status), 512);
		MdsFree1Dx(&xd, NULL);
		(*env)->ReleaseStringUTFChars(env, in, in_char);
    }
	if(jdefNode)
	{
		defNode = (*env)->GetStringUTFChars(env, jdefNode, 0);
		status = TreeFindNode((char *)defNode, &nid);
		if(status & 1)
			TreeSetDefaultNid(nid);
		(*env)->ReleaseStringUTFChars(env, jdefNode, defNode);
	}

}
Ejemplo n.º 3
0
	/***************************************************************
	 * TclShowAttribute:
	 ***************************************************************/
int TclShowAttribute() {
  int status;
  int nid;
  EMPTYXD(xd);
  static DYNAMIC_DESCRIPTOR(dsc_node);
  static DYNAMIC_DESCRIPTOR(dsc_attr);
  static DYNAMIC_DESCRIPTOR(dsc_string);
  cli_get_value("NODE",&dsc_node);
  status = TreeFindNode(dsc_node.dscA_pointer,&nid);
  if (status & 1) {
    status = cli_get_value("NAME",&dsc_attr);
    if (status & 1) {
      status = TreeGetXNci(nid,dsc_attr.dscA_pointer,&xd);
      if (status & 1) {
	status = TdiDecompile(&xd,&dsc_string MDS_END_ARG);
	if (status & 1) {
	  char *p = malloc(dsc_string.dscW_length+1);
	  strncpy(p,dsc_string.dscA_pointer,dsc_string.dscW_length);
	  p[dsc_string.dscW_length]='\0';
	  TclTextOut(p);
	  free(p);
	}
	StrFree1Dx(&dsc_string);
	MdsFree1Dx(&xd,0);
      }
    } else {
      if (TreeGetXNci(nid,"attributenames",&xd)&1) {
	TdiSortVal(&xd,&xd MDS_END_ARG);
	if (xd.dscA_pointer && xd.dscA_pointer->dscB_class == CLASS_A) {
	  typedef ARRAY(char) ARRAY_DSC;
	  ARRAY_DSC *array=(ARRAY_DSC *)xd.dscA_pointer;
	  char *name=array->dscA_pointer;
	  TclTextOut("Defined attributes for this node:");
	  for (name=array->dscA_pointer;name<array->dscA_pointer+array->dscL_arsize;name+=array->dscW_length) {
	    char *out=malloc(array->dscW_length+6);
	    sprintf(out,"    %.*s",array->dscW_length,name);
	    TclTextOut(out);
	    free(out);
	  }
	} else {
	  TclTextOut("No attributes defined for this node");
	}
	MdsFree1Dx(&xd,0);
      } else {
Ejemplo n.º 4
0
static void Load(Widget w)
{
  char *l8590_memname;
  static char nodename[13];
  static NCI_ITM itmlst[] = {{12,NciNODE_NAME,nodename,0},{0,0,0,0}};
  int i;
  XtPointer temp;
  int nid;
  int found = False;
  XtVaGetValues(w, XmNuserData, &temp, NULL);
  nid =  (intptr_t)temp;
  l8590_memname = TreeGetPath(nid);
  XmListDeleteAllItems(w);
  for (i=1;i<17;i++)
  {
    int ctx = 0;
    int dig_nid;
    int status;
    XmString item;
    char digname[512];
    sprintf(digname,"%s:L8590_%d",l8590_memname,i);
    status = TreeFindNode(digname,&dig_nid);
    if (status & 1)
    {
      TreeGetNci(dig_nid,itmlst);
      item = XmStringCreateSimple(nodename);
      XmListAddItem(w, item, 0);
      XmStringFree(item);
      found = True;
    }
    else
      break;
  }
  TreeFree(l8590_memname);
  if (!found)
  {
    XmString item = XmStringCreateSimple("Add L8590_1");
    XmListAddItem(w, item, 0);
    XmStringFree(item);
  }
}
Ejemplo n.º 5
0
	/*****************************************************************
	 * TclAddTag:
	 * Add a tag name to a node
	 *****************************************************************/
int   TclAddTag()		/* Return: status			*/
   {
    int nid;
    int sts;
    static DYNAMIC_DESCRIPTOR(dsc_nodnam);
    static DYNAMIC_DESCRIPTOR(dsc_tagnam);

    cli_get_value("NODE",&dsc_nodnam);
    cli_get_value("TAGNAME",&dsc_tagnam);
    l2u(dsc_nodnam.dscA_pointer,0);
    l2u(dsc_tagnam.dscA_pointer,0);
    sts = TreeFindNode(dsc_nodnam.dscA_pointer,&nid);
    if (sts & 1)
        sts = TreeAddTag(nid,dsc_tagnam.dscA_pointer);
    if (!(sts & 1))
       {
        MdsMsg(sts,"Error adding tag %s",dsc_tagnam.dscA_pointer);
#ifdef vms
        lib$signal(sts,0);
#endif
       }
    return sts;
   }
Ejemplo n.º 6
0
static int ReadChannel(InStoreStruct *setup, int chunk,int samples,unsigned short *buffer,int *samples_read,int *nid,float *calib)
{
  int chunk_address =  0x0B000 | chunk;
  int points_to_read;
  int status=1;
  int tries;
  for (points_to_read = chunksize; status & 1 && points_to_read; points_to_read = chunksize)
  {
    struct { unsigned short status;
             unsigned short bytcnt;
             unsigned int   dummy;} iosb = {0,0};
    int try;
    static DESCRIPTOR_A(calib_a, sizeof(*calib), DTYPE_NATIVE_FLOAT, 0, 2*sizeof(*calib));
    static DESCRIPTOR_NID(nid_dsc,0);
    void *arglist[] = {0,&nid_dsc,&calib_a MDS_END_ARG};
    calib_a.pointer = (char *)calib;
    nid_dsc.pointer = (char *)nid;
    arglist[0] = (void *)(sizeof(arglist)/sizeof(arglist[0]));
    AccessTraq(setup,chunk_address,24,arglist,TdiData);
    pio(8,0,0);
    for (try = 0;(try < 20) && (!(CamQ(0)&1)) && (status & 1);try++) {pio(8,0,0);}
    pio(10,0,0);
    return_on_error(DevCamChk(CamQstopw(setup->name,0,2,points_to_read,buffer + *samples_read,16,(short *)&iosb),&one,0),status);
    status = status & 1 ? iosb.status : status;
    *samples_read += iosb.bytcnt/2;
    if (iosb.bytcnt/2 != points_to_read) break;
    chunk_address += max_chunks_per_io;
  }
  return status;
}

static int AccessTraq(InStoreStruct *setup, int data,int memsize,void *arglist,int (*routine)())
{ int try;
  int status;
  int called = 0;
  if (max_time > 0) {
    if ((time(0)-start_time) > max_time) {
      printf("T4012 AccessTraq timeout, data=%d\n",data);
      return DEV$_BAD_MODE;
    }
  }
  piomem(17,0,&data,memsize);
  for (try = 0;(try < 30) && (!(CamQ(0)&1)) && (status &1);try++) 
  {
    if (arglist && !called) {
      called = 1;
      LibCallg(arglist,routine);
    }
    else
      DevWait((float).001);
    piomem(17,0,&data,memsize);
  }
  if (try == 30) status = DEV$_CAM_NOSQ;
  if (arglist &&!called) LibCallg(arglist,routine);
  return status;
}

int t4012__dw_setup( struct descriptor *niddsc, struct descriptor *methoddsc, Widget parent)
{ 
  static String uids[] = {"T4012.uid"};
  static int nid;
  static MrmRegisterArg uilnames[] = {{"nid",(XtPointer)0},{"Load",(XtPointer)Load}};
  static NCI_ITM   nci[] = {{4, NciCONGLOMERATE_NIDS, (unsigned char *)&nid, 0}, {0, NciEND_OF_LIST, 0, 0}};
  TreeGetNci(*(int *)niddsc->pointer, nci);
  uilnames[0].value = (char *)0+nid;
  return XmdsDeviceSetup(parent, (int *)niddsc->pointer, uids, XtNumber(uids), "T4012", uilnames, XtNumber(uilnames), 0);
}

static void Load(Widget w)
{
  char *t4012name;
  char dignam[512];
  int i;
  XtPointer user_data;
  int nid;
  int found = False;
  XtVaGetValues(w, XmNuserData, &user_data, NULL);
  nid = (intptr_t)user_data;
  t4012name = TreeGetPath(nid);
  strcpy(dignam,t4012name);
  strcat(dignam,":T28%%_");
  TreeFree(t4012name);
  XmListDeleteAllItems(w);
  for (i=1;i<17;i++)
  {
    int dig_nid;
    int status;
    XmString item;
    int len = strlen(dignam);
    dignam[len++]=i<10 ? '0' : '1';
    dignam[len++]='0'+(i % 10);
    dignam[len++]=0;
    status = TreeFindNode(dignam,&dig_nid);
    if (status & 1)
    {
      NCI_ITM itmlst[] = {{512,NciNODE_NAME,0,0},{0,0,0,0}};
      itmlst[0].pointer = dignam;
      TreeGetNci(dig_nid,itmlst);
      item = XmStringCreateSimple(dignam);
      XmListAddItem(w, item, 0);
      XmStringFree(item);
      found = True;
    }
    else
      break;
  }
  if (!found)
  {
    XmString item = XmStringCreateSimple("Add T28xx_01");
    XmListAddItem(w, item, 0);
    XmStringFree(item);
  }
}
Ejemplo n.º 7
0
	/****************************************************************
	 * TclDoMethod:
	 ****************************************************************/
int TclDoMethod()
   {
    int   i;
    int   argc;
    int   sts;
    unsigned char  do_it;
    struct descriptor_xd xdarg[255];
    static int   nid;
    static unsigned short boolVal;
    static struct descriptor_s bool_dsc =
                    {sizeof(boolVal), DTYPE_W, CLASS_S, (char *)&boolVal};
    static struct descriptor nid_dsc = {4,DTYPE_NID,CLASS_S,(char *)&nid};
    static struct descriptor_xd empty_xd = {0,DTYPE_DSC,CLASS_XD,0,0};
    static DYNAMIC_DESCRIPTOR(arg);
    static DYNAMIC_DESCRIPTOR(if_clause);
    static DYNAMIC_DESCRIPTOR(method);
    static DYNAMIC_DESCRIPTOR(object);
    static void  *arglist[256] = {(void *)2,&nid_dsc,&method};

    cli_get_value("OBJECT",&object);
    sts = TreeFindNode(object.dscA_pointer,&nid);
    if (sts & 1)
       {
        do_it = (TreeIsOn(nid) | cli_present("OVERRIDE")) & 1;
        if (cli_present("IF") & 1)
           {
            cli_get_value("IF",&if_clause);
            sts = TdiExecute(&if_clause,&bool_dsc MDS_END_ARG);
            if (sts & 1)
                do_it = do_it && boolVal;
            else
                do_it = 0;
           }
        if (do_it)
           {
            int dometh_stat;
            DESCRIPTOR_LONG(dometh_stat_d,0);
            cli_get_value("METHOD",&method);
            argc = 0;
            if (cli_present("ARGUMENT") & 1)
               {
                while (cli_get_value("ARGUMENT",&arg) & 1)
                   {
                    xdarg[argc] = empty_xd;
                    sts = TdiCompile(&arg,&xdarg[argc] MDS_END_ARG);
                    if (sts & 1)
                       {
                        arglist[argc + 3] = xdarg[argc].dscA_pointer;
                        argc++;
                       }
                    else
                        break;
                   }
               }
            if (sts & 1)
               {
#ifdef vms
                arglist[0] = (void *)(argc + 2);
#else
                dometh_stat_d.dscA_pointer = (char *)&dometh_stat;
                arglist[argc+3] = &dometh_stat_d;
                arglist[argc+4] = MdsEND_ARG;
                arglist[0] = (argc + 4)+(char *)0;
#endif

		sts = (char *)LibCallg(arglist,TreeDoMethod)-(char *)0;
                if (sts & 1) sts = dometh_stat;
               }
            str_free1_dx(&arg);
            str_free1_dx(&method);
            for (i = 0; i < argc; i++)
                MdsFree1Dx(&xdarg[i],NULL);
           }
       }
    str_free1_dx(&object);
#ifdef vms
    if (!(sts & 1)) lib$signal(sts,0);
#else
	if (!(sts & 1))
	{
		char msg[512];
		sprintf(msg,"Error executing method - %s",MdsGetMsg(sts));
		TclTextOut(msg);
	}
#endif
    return sts;
   }
Ejemplo n.º 8
0
void AddTreeNode(CBTType *treeNode)
{
   CBTType *pnode,*parent;
   DATA data;
   char menusel;

   if(pnode=(CBTType *)malloc(sizeof(CBTType)))     //分配内存
   {
	printf("输入二叉树节点数据:\n");
	fflush(stdin);   //清空输入缓冲区
	scanf("%s",&pnode->data);
	pnode->left = NULL;
	pnode->right = NULL;

	printf("输入该节点的父节点数据:");
	fflush(stdin);
	scanf("%s",&data);
	parent = TreeFindNode(treeNode,data);    //查找指定数据的节点
	if(!parent)
	{
		printf("未找到该父节点!\n");
		free(pnode);                   //释放创建的节点内存
		return;
	}
	printf("1.添加该节点到左子树\n2.添加该节点到右子树\n");
		do{
		
			menusel = getch();          //输入选择项
			menusel-='0';
			if(menusel == 1 || menusel == 2)
			{
				if(parent == NULL)
				{
					printf("不存在父节点,请先设置父节点!\n");
				}
				else
				{
					switch(menusel)
					{
					case 1:                //添加到左节点
						if(parent->left)          //左节点不为空
						{
							printf("左子树节点不为空!\n");
						}
						else
						{
							parent->left = pnode;
						}
						break;
					case 2:                      //添加到右节点
						if(parent->right)    //右子树不为空
						{
							printf("右子树节点不为空!\n");
						}
						else
						{
							parent->right = pnode;
						}
						break;
					default:
						printf("无效参加!\n");
					}
				}
			}
		}while(menusel!=1 && menusel !=2);
   }
}