void MdsGetMsgDsc(int status, struct descriptor *out) { MdsGetMsg(status); (MdsShrGetThreadStatic())->MdsGetMsgDsc_tmp.length = strlen((MdsShrGetThreadStatic())->MdsGetMsgDsc_tmp.pointer); StrCopyDx(out,&(MdsShrGetThreadStatic())->MdsGetMsgDsc_tmp); return; }
static int ParseHistorian(char *line, struct descriptor *name, float *value, TIME *time) { char *format = "\"%d/%d/%d\",\"%d:%d:%d.%d\",\"%22c\",\"%5c\",\"%f \"\n"; int year,month,day,hrs,mins,secs,frac; static int skip_next_value = 0; int status=0; char what[6]; static char name_c[24]; static struct descriptor name_dsc = {sizeof(name_c), DTYPE_T, CLASS_S, name_c}; static float fval; static struct descriptor fval_dsc = {sizeof(float), DTYPE_NATIVE_FLOAT, CLASS_S, (char *)&fval}; if (sscanf(line, format, &month, &day, &year, &hrs, &mins, &secs, &frac, name_c, what, &fval) == 10) { if (strncmp(what,"START",5) == 0) skip_next_value = 1; else { if ((!skip_next_value && strncmp(what, "VALUE", 5) == 0) || strncmp(what, "END", 3) == 0) { struct tm time_v; int tim; time_v.tm_year = ((year > 80) ? year + 1900 : year+2000) - 1900; time_v.tm_mon = month; time_v.tm_mday = day; time_v.tm_hour = hrs; time_v.tm_min = mins; time_v.tm_sec = secs; tim = mktime(&time_v); if (tim > 0) { _int64 addin = LONG_LONG_CONSTANT(0x7c95674beb4000); _int64 qtime = ((_int64)tim)*10000000+addin; memcpy((void *)time,&qtime,sizeof(qtime)); } name_dsc.length = strlen(name_c); *value = fval; StrCopyDx(name, &name_dsc); status = 1; } skip_next_value = 0; } } else skip_next_value = 0; return status; }
/***************************************************** 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; }
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; }