/***************************************************** Routine to return a new tag search data structure. ******************************************************/ static TAG_SEARCH *NewTagSearch(char *tagnam_ptr) { static DESCRIPTOR(top, "TOP"); static DESCRIPTOR(colons, "::"); TAG_SEARCH *ctx = (TAG_SEARCH *) malloc(sizeof(TAG_SEARCH)); static struct descriptor_d empty = {0, DTYPE_T, CLASS_D, 0}; struct descriptor tag_dsc = {0, DTYPE_T, CLASS_S, 0}; unsigned short tree_len; char *cptr; static unsigned short one = 1; tag_dsc.length = strlen(tagnam_ptr); tag_dsc.pointer = tagnam_ptr; ctx->search_tag = empty; ctx->search_tree = empty; ctx->next_tag = -1; ctx->this_tree_info = 0; ctx->remote = 0; if (*(char *) tag_dsc.pointer == '\\') { tag_dsc.length--; (char *) tag_dsc.pointer++; } if ((cptr = strstr(tagnam_ptr,"::")) != 0) { tree_len = cptr - tagnam_ptr; StrCopyR(&ctx->search_tree, &tree_len, tag_dsc.pointer); tag_dsc.length -= (tree_len + 2); tag_dsc.pointer += (tree_len + 2); } else StrCopyR(&ctx->search_tree, &one, "*"); if (tag_dsc.length) StrCopyDx(&ctx->search_tag, &tag_dsc); else StrCopyR(&ctx->search_tag, &one, "*"); StrUpcase(&ctx->search_tree,&ctx->search_tree); StrUpcase(&ctx->search_tag,&ctx->search_tag); ctx->top_match = StrMatchWild(&top, &ctx->search_tag) & 1; return ctx; }
/*------------------------------------------------------------------- Use a different default, shot, or experiment. USING(expression, [DEFAULT], [SHOTID], [EXPT]) Note that DEFAULT may be NID/PATH and will not be data at same. */ STATIC_ROUTINE int fixup_nid(int *pin, /* NID pointer */ int arg, struct descriptor_d *pout) { int status = 0; char *path = TreeGetPath(*pin); if (path != NULL) { unsigned short len = (unsigned short)strlen(path); StrCopyR(pout, &len, path); TreeFree(path); status = 1; } return status; }
STATIC_ROUTINE int fixup_path(struct descriptor *pin, int arg, struct descriptor_d *pout) { int status = 0; char *pathin = MdsDescrToCstring(pin); char *path = TreeAbsPath(pathin); MdsFree(pathin); if (path != NULL) { unsigned short len = (unsigned short)strlen(path); StrCopyR(pout, &len, path); TreeFree(path); status = 1; } return status; }
int Tdi1Using(int opcode, int narg, struct descriptor *list[], struct descriptor_xd *out_ptr) { int status = 1; void *ctx; int reset_ctx = 0; int nid, shot, stat1; struct descriptor def = { 0, DTYPE_T, CLASS_D, 0 }, expt = def; unsigned char omits[] = { DTYPE_PATH, 0 }; /********************** Evaluate with current. Use current if omitted. Must get expt if shot. **********************/ if (narg > 1 && status & 1) { if (list[1]) { struct descriptor_xd xd = EMPTY_XD; status = TdiGetData(omits, list[1], &xd); if (status & 1 && xd.pointer) switch (xd.pointer->dtype) { case DTYPE_T: case DTYPE_PATH: status = StrCopyDx(&def, xd.pointer); break; default: status = TdiINVDTYDSC; break; } MdsFree1Dx(&xd, NULL); } if (!list[1] || def.length == 0) { DBI_ITM def_itm[] = { {0, DbiDEFAULT, 0, 0} , EOL }; status = TreeGetDbi(def_itm); if (def_itm[0].pointer == NULL) { STATIC_CONSTANT DESCRIPTOR(top, "\\TOP"); StrCopyDx(&def, &top); status = 1; } else { unsigned short len = (unsigned short)strlen((char *)def_itm[0].pointer); StrCopyR(&def, &len, def_itm[0].pointer); TreeFree(def_itm[0].pointer); } if (status & 1) { stat1 = StrPosition(&def, &coloncolon, 0) + 1; status = StrRight(&def, &def, &stat1); } if (status & 1) *def.pointer = '\\'; } } if ((narg > 2) && ((list[2] != 0) || ((narg > 3) && (list[3] != 0))) && ((status & 1) != 0)) { if (list[2]) status = TdiGetLong(list[2], &shot); else { DBI_ITM shot_itm[] = { {sizeof(shot), DbiSHOTID, 0, 0} , EOL }; shot_itm[0].pointer = (unsigned char *)&shot; status = TreeGetDbi(shot_itm); } if (status & 1) { if (narg > 3 && list[3]) status = TdiData(list[3], &expt MDS_END_ARG); else { DBI_ITM expt_itm[] = { {0, DbiNAME, 0, 0} , EOL }; status = TreeGetDbi(expt_itm); if (expt_itm[0].pointer) { unsigned short len = (unsigned short)strlen((char *)expt_itm[0].pointer); StrCopyR(&expt, &len, expt_itm[0].pointer); TreeFree(expt_itm[0].pointer); } } } /********************* Set new tree and path. Allow some rel paths. *********************/ if (status & 1) { char *tree = MdsDescrToCstring(&expt); ctx = TreeSwitchDbid(0); reset_ctx = 1; status = TreeOpen(tree, shot, 1); MdsFree(tree); } } if (narg > 1) { char *path = MdsDescrToCstring(&def); if (status & 1) status = TreeSetDefault(path, &nid); MdsFree(path); if (narg > 2) StrFree1Dx(&expt); StrFree1Dx(&def); } /*********************** Evaluate with temporary. ***********************/ if (status & 1) { struct descriptor_xd tmp = EMPTY_XD; status = TdiEvaluate(list[0], &tmp MDS_END_ARG); if (status & 1) status = MdsCopyDxXdZ((struct descriptor *)&tmp, out_ptr, NULL, fixup_nid, NULL, fixup_path, NULL); MdsFree1Dx(&tmp, NULL); } if (reset_ctx) { while (TreeClose(0, 0) & 1) ; TreeFreeDbid(TreeSwitchDbid(ctx)); } return status; }