00001
00002
00003 #include "arithmetics.h"
00004 #include "index.h"
00005 #include "datetime.h"
00006 #ifndef DEBUG
00007 #include "rodsType.h"
00008 #endif
00009
00010
00011 int addKeyVal(keyValPair_t *k, const char * key, const char *val);
00012 char * getAttrNameFromAttrId(int id);
00013
00014
00015
00016
00017
00018
00019 void convertStrValue(Res *res, char *val, Region *r) {
00020 if(val == NULL) {
00021 res->text = NULL;
00022 } else {
00023 int len = (strlen(val)+1)*sizeof(char);
00024 res->text = (char*)region_alloc(r, len);
00025 memcpy(res->text, val, len);
00026 RES_STRING_STR_LEN(res) = strlen(val);
00027 }
00028 res->exprType = newSimpType(T_STRING, r);
00029 }
00030
00031
00032
00033 void convertIntValue(Res *res, int inval, Region *r) {
00034 RES_INT_VAL_LVAL(res) = inval;
00035 res->exprType = newSimpType(T_INT, r);
00036 }
00037
00038
00039
00040 void convertDoubleValue(Res *res, double inval, Region *r) {
00041 RES_DOUBLE_VAL_LVAL(res) = inval;
00042 res->exprType = newSimpType(T_DOUBLE,r);
00043 }
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 Res* getValueFromCollection(char *typ, void *inPtr, int inx, Region *r) {
00060 Res *res;
00061 int i,j;
00062
00063 if (!strcmp(typ,StrArray_MS_T)) {
00064 strArray_t *strA;
00065
00066
00067 strA = (strArray_t *) inPtr;
00068 if (inx >= strA->len) {
00069 return NULL;
00070 }
00071 res = newStringRes(r, strA->value+inx * strA->size);
00072 return res;
00073 }
00074 else if (!strcmp(typ,IntArray_MS_T)) {
00075 res = newRes(r);
00076 res->exprType = newSimpType(T_INT, r);
00077 intArray_t *intA;
00078 intA = (intArray_t *) inPtr;
00079 if (inx >= intA->len) {
00080 return NULL;
00081 }
00082 RES_INT_VAL_LVAL(res) = intA->value[inx];
00083 return res;
00084 }
00085 else if (!strcmp(typ,GenQueryOut_MS_T)) {
00086 keyValPair_t *k;
00087 genQueryOut_t *g = (genQueryOut_t *) inPtr;
00088 char *cname, *aval;
00089 sqlResult_t *v;
00090 if (g->rowCnt == 0 || inx >= g->rowCnt) {
00091 return NULL;
00092 }
00093 k = (keyValPair_t *)malloc(sizeof(keyValPair_t));
00094 k->len = 0;
00095 k->keyWord = NULL;
00096 k->value = NULL;
00097 for (i = 0; i < g->attriCnt; i++) {
00098 v = g->sqlResult+i;
00099 cname = (char *) getAttrNameFromAttrId(v->attriInx);
00100 aval = v->value+ v->len*inx;
00101 j = addKeyVal (k, cname,aval);
00102 if (j < 0)
00103 return NULL;
00104 }
00105 res = newUninterpretedRes(r, KeyValPair_MS_T, k, NULL);
00106 return res;
00107 }
00108 else
00109 return NULL;
00110 }
00111 int getCollectionSize(char *typ, void *inPtr, Region *r) {
00112 if (!strcmp(typ,StrArray_MS_T)) {
00113 strArray_t *strA;
00114
00115
00116 strA = (strArray_t *) inPtr;
00117 return strA->len;
00118 }
00119 else if (!strcmp(typ,IntArray_MS_T)) {
00120 intArray_t *intA;
00121 intA = (intArray_t *) inPtr;
00122 return intA->len;
00123 }
00124 else if (!strcmp(typ,GenQueryOut_MS_T)) {
00125 genQueryOut_t *g = (genQueryOut_t *) inPtr;
00126 return g->rowCnt;
00127 }
00128 else
00129 return(USER_PARAM_TYPE_ERR);
00130 }
00131 int convertMsParamToRes(msParam_t *mP, Res *res, rError_t *errmsg, Region *r) {
00132 #ifdef DEBUG
00133 writeToTmp("relog.txt", "type: ");
00134 writeToTmp("relog.txt", mP->type);
00135 writeToTmp("relog.txt", "\n");
00136 #endif
00137 if(mP->type == NULL) {
00138 res->exprType = newSimpType(T_UNSPECED, r);
00139 return 0;
00140
00141 } else if (strcmp(mP->type, DOUBLE_MS_T) == 0) {
00142 convertDoubleValue(res, *(double *)mP->inOutStruct,r);
00143 return 0;
00144 } else if (strcmp(mP->type, INT_MS_T) == 0) {
00145
00146 if(res->exprType == NULL) {
00147 RES_INT_VAL_LVAL(res) = *(int *)mP->inOutStruct;
00148 res->exprType = newSimpType(T_INT, r);
00149 } else
00150 switch(TYPE(res)) {
00151 case T_INT:
00152 RES_INT_VAL_LVAL(res) = *(int *)mP->inOutStruct;
00153 break;
00154 case T_BOOL:
00155 RES_BOOL_VAL_LVAL(res) = *(int *)mP->inOutStruct;
00156 break;
00157 case T_DATETIME:
00158 RES_TIME_VAL(res) = *(rodsLong_t *)mP->inOutStruct;
00159 break;
00160 default:
00161 convertIntValue(res, *(int *)mP->inOutStruct,r);
00162 }
00163 return 0;
00164 } else if (strcmp(mP->type, STR_MS_T) == 0) {
00165 convertStrValue(res, (char *)mP->inOutStruct,r);
00166 return 0;
00167 } else if(strcmp(mP->type, DATETIME_MS_T) == 0) {
00168 RES_TIME_VAL(res) = *(rodsLong_t *)mP->inOutStruct;
00169 TYPE(res) = T_DATETIME;
00170 return 0;
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 } else {
00183 if(res->param==NULL) {
00184 res->param = newMsParam(mP->type, mP->inOutStruct, mP->inpOutBuf, r);
00185 } else {
00186 res->param->type = cpStringExt(mP->type, r);
00187 RES_UNINTER_STRUCT(res) = mP->inOutStruct;
00188 RES_UNINTER_BUFFER(res) = mP->inpOutBuf;
00189 }
00190 res->exprType = newIRODSType(mP->type,r);
00191 return 0;
00192 }
00193
00194
00195 }
00196 int convertMsParamToResAndFreeNonIRODSType(msParam_t *mP, Res *res, rError_t *errmsg, Region *r) {
00197 #ifdef DEBUG
00198 writeToTmp("relog.txt", "type: ");
00199 writeToTmp("relog.txt", mP->type);
00200 writeToTmp("relog.txt", "\n");
00201 #endif
00202 if(mP->type == NULL) {
00203 res->exprType = newSimpType(T_UNSPECED, r);
00204 return 0;
00205
00206 }
00207 else if (strcmp(mP->type, DOUBLE_MS_T) == 0) {
00208 convertDoubleValue(res, *(double *)mP->inOutStruct,r);
00209 free(mP->inOutStruct);
00210 mP->inOutStruct = NULL;
00211 return 0;
00212 } else if (strcmp(mP->type, INT_MS_T) == 0) {
00213
00214 if(res->exprType == NULL) {
00215 RES_INT_VAL_LVAL(res) = *(int *)mP->inOutStruct;
00216 res->exprType = newSimpType(T_INT, r);
00217 } else
00218 switch(TYPE(res)) {
00219 case T_INT:
00220 RES_INT_VAL_LVAL(res) = *(int *)mP->inOutStruct;
00221 break;
00222 case T_BOOL:
00223 RES_BOOL_VAL_LVAL(res) = *(int *)mP->inOutStruct;
00224 break;
00225 case T_DATETIME:
00226 RES_TIME_VAL(res) = *(rodsLong_t *)mP->inOutStruct;
00227 break;
00228 default:
00229 convertIntValue(res, *(int *)mP->inOutStruct,r);
00230 }
00231 free(mP->inOutStruct);
00232 mP->inOutStruct = NULL;
00233 return 0;
00234 } else if (strcmp(mP->type, STR_MS_T) == 0) {
00235 convertStrValue(res, (char *)mP->inOutStruct,r);
00236 free(mP->inOutStruct);
00237 mP->inOutStruct = NULL;
00238 return 0;
00239 } else if(strcmp(mP->type, DATETIME_MS_T) == 0) {
00240 RES_TIME_VAL(res) = *(rodsLong_t *)mP->inOutStruct;
00241 TYPE(res) = T_DATETIME;
00242 free(mP->inOutStruct);
00243 mP->inOutStruct = NULL;
00244 return 0;
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 } else {
00257 if(res->param==NULL) {
00258 res->param = newMsParam(mP->type, mP->inOutStruct, mP->inpOutBuf, r);
00259 } else {
00260 res->param->type = cpStringExt(mP->type, r);
00261 RES_UNINTER_STRUCT(res) = mP->inOutStruct;
00262 RES_UNINTER_BUFFER(res) = mP->inpOutBuf;
00263 }
00264 res->exprType = newIRODSType(mP->type,r);
00265 return 0;
00266 }
00267
00268
00269 }
00270
00271 ExprType *convertToExprType(char *type, Region *r) {
00272 if (strcmp(type, DOUBLE_MS_T) == 0) {
00273 return newSimpType(T_DOUBLE, r);
00274 } else if (strcmp(type, INT_MS_T) == 0) {
00275 return newSimpType(T_INT, r);
00276 } else if (strcmp(type, STR_MS_T) == 0) {
00277 return newSimpType(T_STRING, r);
00278
00279
00280
00281
00282 } else if(strcmp(type, StrArray_MS_T) == 0) {
00283 return newCollType(newSimpType(T_STRING, r), r);
00284 } else if(strcmp(type, IntArray_MS_T) == 0) {
00285 return newCollType(newSimpType(T_INT, r), r);
00286 } else if(strcmp(type, GenQueryOut_MS_T) == 0) {
00287 return newCollType(newIRODSType(KeyValPair_MS_T, r), r);
00288 } else {
00289 return newIRODSType(type, r);
00290 }
00291 }
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 int convertResToMsParam(msParam_t *var, Res *res, rError_t *errmsg) {
00313 strArray_t *arr = NULL;
00314 intArray_t *arr2 = NULL;
00315 int i = 0;
00316 int maxlen = 0;
00317 var->inpOutBuf = NULL;
00318 var->label = NULL;
00319 switch(TYPE(res)) {
00320 case T_ERROR:
00321 var->inOutStruct = (int *)malloc(sizeof(int));
00322 *((int *)var->inOutStruct) = RES_ERR_CODE(res);
00323 var->type = strdup(INT_MS_T);
00324 break;
00325 case T_DOUBLE:
00326 var->inOutStruct = (double *)malloc(sizeof(double));
00327 *((double *)var->inOutStruct) = RES_DOUBLE_VAL(res);
00328 var->type = strdup(DOUBLE_MS_T);
00329 break;
00330 case T_INT:
00331 var->inOutStruct = (int *)malloc(sizeof(int));
00332 *((int *)var->inOutStruct) = RES_INT_VAL(res);
00333 var->type = strdup(INT_MS_T);
00334 break;
00335 case T_STRING:
00336 var->inOutStruct = res->text == NULL? NULL : strdup(res->text);
00337 var->type = strdup(STR_MS_T);
00338 break;
00339 case T_PATH:
00340 var->inOutStruct = res->text == NULL? NULL : strdup(res->text);
00341 var->type = strdup(STR_MS_T);
00342 break;
00343 case T_DATETIME:
00344
00345
00346
00347
00348 var->inOutStruct = (rodsLong_t *)malloc(sizeof(int));
00349 *((rodsLong_t *)var->inOutStruct) = RES_TIME_VAL(res);
00350 var->type = strdup(INT_MS_T);
00351 break;
00352 case T_CONS:
00353 if(strcmp(T_CONS_TYPE_NAME(res->exprType), LIST) == 0) {
00354 switch(getNodeType(T_CONS_TYPE_ARG(res->exprType, 0))) {
00355 case T_STRING:
00356 arr = (strArray_t *)malloc(sizeof(strArray_t));
00357 arr->len = res->degree;
00358 maxlen = 0;
00359 for(i=0;i<res->degree;i++) {
00360 int slen = RES_STRING_STR_LEN(res->subtrees[i]);
00361 maxlen = maxlen < slen? slen: maxlen;
00362 }
00363 arr->size = maxlen;
00364 arr->value = (char *)malloc(sizeof(char)*maxlen*(arr->len));
00365 for(i=0;i<res->degree;i++) {
00366 strcpy(arr->value + maxlen*i, res->subtrees[i]->text);
00367 }
00368 var->inOutStruct = arr;
00369 var->type = strdup(StrArray_MS_T);
00370 break;
00371 case T_INT:
00372 arr2 = (intArray_t *)malloc(sizeof(intArray_t));
00373 arr2->len = res->degree;
00374 arr2->value = (int *)malloc(sizeof(int)*(arr2->len));
00375 for(i=0;i<res->degree;i++) {
00376 arr2->value[i] = RES_INT_VAL(res);
00377 }
00378 var->inOutStruct = arr2;
00379 var->type = strdup(IntArray_MS_T);
00380 break;
00381
00382
00383
00384
00385
00386 default:
00387
00388
00389 addRErrorMsg(errmsg, RE_PACKING_ERROR, "no packing instruction for arbitrary collection type");
00390 return RE_PACKING_ERROR;
00391 }
00392 } else {
00393 addRErrorMsg(errmsg, RE_PACKING_ERROR, "no packing instruction for arbitrary constructed type");
00394 return RE_PACKING_ERROR;
00395 }
00396 break;
00397 case T_IRODS:
00398 var->inOutStruct = RES_UNINTER_STRUCT(res);
00399 var->inpOutBuf = RES_UNINTER_BUFFER(res);
00400 var->type = strdup(res->exprType->text);
00401 break;
00402 case T_UNSPECED:
00403 var->inOutStruct = NULL;
00404 var->type = NULL;
00405 break;
00406 default:
00407
00408 addRErrorMsg(errmsg, RE_PACKING_ERROR, "no packing instruction for arbitrary type");
00409 return RE_PACKING_ERROR;
00410 }
00411 return 0;
00412 }
00413 int updateResToMsParam(msParam_t *var, Res *res, rError_t *errmsg) {
00414 if(var->type != NULL && (strcmp(var->type, INT_MS_T) == 0 ||
00415 strcmp(var->type, DOUBLE_MS_T) == 0 ||
00416 strcmp(var->type, STR_MS_T) == 0)) {
00417
00418 if(var->inOutStruct!=NULL) {
00419 free(var->inOutStruct);
00420 }
00421 if(var->inpOutBuf!=NULL) {
00422 free(var->inpOutBuf);
00423 }
00424 }
00425 if(var->label!=NULL) {
00426 free(var->label);
00427 }
00428 return convertResToMsParam(var, res, errmsg);
00429 }
00430 int convertEnvToMsParamArray(msParamArray_t *var, Env *env, rError_t *errmsg, Region *r) {
00431 int ret;
00432 if(env->previous!=NULL) {
00433 if((ret = convertEnvToMsParamArray(var, env->previous, errmsg, r))!=0) {
00434 return ret;
00435 }
00436 }
00437 return convertHashtableToMsParamArray(var, env->current, errmsg, r);
00438 }
00439
00440 int convertHashtableToMsParamArray(msParamArray_t *var, Hashtable *env, rError_t *errmsg, Region *r) {
00441 int i;
00442 for(i=0;i<env->size;i++) {
00443 struct bucket *b = env->buckets[i];
00444 while(b!=NULL && !IS_TVAR_NAME(b->key)) {
00445 Res *res = (Res *)b->value;
00446 msParam_t *v = NULL;
00447 int needToFree = 0;
00448 int varindex;
00449 int ret;
00450 for(varindex=0;varindex<var->len;varindex++) {
00451 if(var->msParam[varindex]->label!=NULL && strcmp(var->msParam[varindex]->label, b->key) == 0) {
00452 v = var->msParam[varindex];
00453 ret = updateResToMsParam(v, res, errmsg);
00454 break;
00455 }
00456 }
00457 if(v == NULL) {
00458 v = (msParam_t *) malloc(sizeof(msParam_t));
00459 needToFree = 1;
00460 ret = convertResToMsParam(v, res, errmsg);
00461 if(var->msParam == NULL) {
00462 var->len = 0;
00463 var->msParam = (msParam_t **) malloc(sizeof(msParam_t *)*(PTR_ARRAY_MALLOC_LEN));
00464 } else if(var->len % PTR_ARRAY_MALLOC_LEN == 0) {
00465 var->msParam = (msParam_t **) realloc(var->msParam, sizeof(msParam_t *)*(PTR_ARRAY_MALLOC_LEN + var->len));
00466 }
00467
00468 var->msParam[var->len++] = v;
00469 }
00470 v->label = strdup(b->key);
00471
00472 if(ret != 0) {
00473
00474
00475 if(needToFree) {
00476 free(v);
00477 }
00478 return ret;
00479 }
00480
00481 b=b->next;
00482 }
00483 }
00484 return 0;
00485 }
00486 int convertMsParamArrayToEnv(msParamArray_t *var, Env *env, rError_t *errmsg, Region *r) {
00487 return updateMsParamArrayToEnv(var, env, errmsg, r);
00488 }
00489
00490 int convertMsParamArrayToEnvAndFreeNonIRODSType(msParamArray_t *var, Env *env, rError_t *errmsg, Region *r) {
00491 return updateMsParamArrayToEnvAndFreeNonIRODSType(var, env, errmsg, r);
00492 }
00493 int updateMsParamArrayToEnv(msParamArray_t *var, Env *env, rError_t *errmsg, Region *r) {
00494 int i;
00495 for(i=0;i<var->len;i++) {
00496 Res *res = newRes(r);
00497 int ret = convertMsParamToRes(var->msParam[i], res, errmsg, r);
00498 if(ret != 0) {
00499 return ret;
00500 }
00501 char *varName = var->msParam[i]->label;
00502 if(varName!=NULL) {
00503 updateInEnv(env, varName, res);
00504 }
00505 }
00506 return 0;
00507 }
00508 int updateMsParamArrayToEnvAndFreeNonIRODSType(msParamArray_t *var, Env *env, rError_t *errmsg, Region *r) {
00509 int i;
00510 for(i=0;i<var->len;i++) {
00511 Res *res = newRes(r);
00512 int ret = convertMsParamToResAndFreeNonIRODSType(var->msParam[i], res, errmsg, r);
00513 if(ret != 0) {
00514 return ret;
00515 }
00516 char *varName = var->msParam[i]->label;
00517 if(varName!=NULL) {
00518 updateInEnv(env, varName, res);
00519 }
00520 }
00521 return 0;
00522 }
00523
00524
00525 char* convertResToString(Res *res0) {
00526 char *res;
00527 char *type;
00528 int j;
00529 switch (getNodeType(res0)) {
00530
00531 case N_ERROR:
00532 res = (char *)malloc(sizeof(char)*1024);
00533 snprintf(res, 1024, "error %d", RES_ERR_CODE(res0));
00534 return res;
00535 case N_VAL:
00536 switch(TYPE(res0)) {
00537 case T_INT:
00538 case T_DOUBLE:
00539 res = (char *)malloc(sizeof(char)*1024);
00540 if(res0->dval==(int)res0->dval) {
00541 snprintf(res, 1024, "%d", (int)res0->dval);
00542 } else {
00543 snprintf(res, 1024, "%f", res0->dval);
00544 }
00545 return res;
00546 case T_STRING:
00547 if(res0->text == NULL) {
00548 res = strdup("<null>");
00549 } else {
00550 res = strdup(res0->text);
00551 }
00552 return res;
00553 case T_PATH:
00554 if(res0->text == NULL) {
00555 res = strdup("<null>");
00556 } else {
00557 res = strdup(res0->text);
00558 }
00559 return res;
00560 case T_IRODS:
00561 res = (char *)malloc(sizeof(char)*1024);
00562 res[0] = 0;
00563 type = res0->exprType->text;
00564 if(strcmp(type, KeyValPair_MS_T)==0) {
00565 keyValPair_t *kvp = (keyValPair_t *) RES_UNINTER_STRUCT(res0);
00566 snprintf(res, 1024, "KeyValue[%d]:", kvp->len);
00567 int i;
00568 for(i=0;i<kvp->len;i++) {
00569 snprintf(res + strlen(res), 1024 - strlen(res), "%s=%s;", kvp->keyWord[i],kvp->value[i]);
00570 }
00571
00572 } else if (strcmp(type, BUF_LEN_MS_T) == 0 ) {
00573 snprintf(res + strlen(res), 1024 - strlen(res),"%d",*(int*)res0->param->inOutStruct);
00574 } else if (strcmp(type, DataObjInp_MS_T) == 0) {
00575 dataObjInp_t dataObjInp, *myDataObjInp;
00576 j = parseMspForDataObjInp (res0->param, &dataObjInp, &myDataObjInp, 0);
00577 if (j < 0)
00578 snprintf(res + strlen(res), 1024 - strlen(res), "<error>");
00579 else
00580 snprintf(res + strlen(res), 1024 - strlen(res), "%s",(char *) myDataObjInp->objPath);
00581 } else if (strcmp(type, CollInp_MS_T ) == 0) {
00582 collInp_t collCreateInp, *myCollCreateInp;
00583 j = parseMspForCollInp (res0->param, &collCreateInp, &myCollCreateInp, 0);
00584 if (j < 0)
00585 snprintf(res + strlen(res), 1024 - strlen(res), "<error>");
00586 else
00587 snprintf(res + strlen(res), 1024 - strlen(res), "%s", myCollCreateInp->collName);
00588 } else if (strcmp(type, DataObjCopyInp_MS_T) == 0) {
00589 dataObjCopyInp_t dataObjCopyInp, *myDataObjCopyInp;
00590 j = parseMspForDataObjCopyInp (res0->param, &dataObjCopyInp, &myDataObjCopyInp);
00591 if (j < 0)
00592 snprintf(res + strlen(res), 1024 - strlen(res), "<error>");
00593 else
00594 snprintf (res + strlen(res), 1024 - strlen(res), "COPY(%s,%s)",
00595 myDataObjCopyInp->srcDataObjInp.objPath, myDataObjCopyInp->destDataObjInp.objPath);
00596 } else if (strcmp(type, DataObjReadInp_MS_T) == 0
00597 || strcmp(type, DataObjCloseInp_MS_T) == 0
00598 || strcmp(type, DataObjWriteInp_MS_T) == 0 ) {
00599 openedDataObjInp_t *myDataObjReadInp;
00600 myDataObjReadInp = (openedDataObjInp_t *) res0->param->inOutStruct;
00601 snprintf (res + strlen(res), 1024 - strlen(res), "OPEN(%d)",myDataObjReadInp->len);
00602 } else if (strcmp(type, ExecCmd_MS_T ) == 0) {
00603 execCmd_t *execCmd;
00604 execCmd = (execCmd_t *) res0->param->inOutStruct;
00605 snprintf(res + strlen(res), 1024 - strlen(res), "%s", execCmd->cmd);
00606 } else {
00607 snprintf(res, 1024, "<value>");
00608 }
00609 return res;
00610 case T_BOOL:
00611 res = strdup(RES_BOOL_VAL(res0)?"true":"false");
00612 return res;
00613 case T_CONS:
00614 res = (char *)malloc(sizeof(char)*1024);
00615 sprintf(res, "[");
00616 int i;
00617 for(i=0;i<res0->degree;i++) {
00618 char *resElem = convertResToString(res0->subtrees[i]);
00619 if(resElem == NULL) {
00620 free(res);
00621 return NULL;
00622 } else {
00623 snprintf(res+strlen(res), 1024-strlen(res), "%s%s", i==0?"":",",resElem);
00624 free(resElem);
00625 }
00626 }
00627 snprintf(res+strlen(res), 1024-strlen(res), "]");
00628 return res;
00629 case T_DATETIME:
00630 res = (char *)malloc(sizeof(char)*1024);
00631 ttimestr(res, 1024-1, "", &RES_TIME_VAL(res0));
00632 return res;
00633 case T_UNSPECED:
00634 res = strdup("<undefined>");
00635 return res;
00636 default:
00637
00638 return NULL;
00639 }
00640 break;
00641 default:
00642 res = (char *)malloc(sizeof(char)*128);
00643 return typeToString(res0, NULL, res, 128);
00644 }
00645 }
00646
00647
00648 void printMsParamArray(msParamArray_t *msParamArray, char *buf2) {
00649 char buf3[MAX_NAME_LEN];
00650 sprintf(buf2, "len: %d\n", msParamArray->len);
00651 int i;
00652 for(i=0;i<msParamArray->len;i++) {
00653 msParam_t *mP = msParamArray->msParam[i];
00654 if(i!=0)strncat(buf2, ",", MAX_NAME_LEN - strlen(buf2));
00655 strncat(buf2, mP->label, MAX_NAME_LEN - strlen(buf2));
00656 strncat(buf2, "=", MAX_NAME_LEN - strlen(buf2));
00657 if(mP->inOutStruct == NULL) {
00658 strncat(buf2, "<null>", MAX_NAME_LEN - strlen(buf2));
00659 } else {
00660 if (strcmp(mP->type, DOUBLE_MS_T) == 0) {
00661 snprintf(buf3, MAX_NAME_LEN, "%f:",*(double *)mP->inOutStruct);
00662 } else if (strcmp(mP->type, INT_MS_T) == 0) {
00663 snprintf(buf3, MAX_NAME_LEN, "%d:",*(int *)mP->inOutStruct);
00664 } else if (strcmp(mP->type, STR_MS_T) == 0) {
00665 snprintf(buf3, MAX_NAME_LEN, "%s:",(char *)mP->inOutStruct);
00666 } else if(strcmp(mP->type, DATETIME_MS_T) == 0) {
00667 snprintf(buf3, MAX_NAME_LEN, "%ld:",(long)*(time_t *)mP->inOutStruct);
00668 } else {
00669 snprintf(buf3, MAX_NAME_LEN, "<value>:");
00670 }
00671 strncat(buf2, buf3, MAX_NAME_LEN - strlen(buf2));
00672 strncat(buf2, mP->type, MAX_NAME_LEN - strlen(buf2));
00673 }
00674 }
00675 return;
00676 }
00677
00678 void printHashtable(Hashtable *env, char* buf2) {
00679 int i;
00680 char typeNameBuf[128];
00681 sprintf(buf2, "len: %d\n", env->len);
00682 int k = 0;
00683 for (i = 0; i < env->size; i++) {
00684 struct bucket *b = env->buckets[i];
00685 while (b != NULL) {
00686 Res *res = (Res *) b->value;
00687 if (k != 0)strncat(buf2, "\n", MAX_NAME_LEN - strlen(buf2));
00688 strncat(buf2, b->key, MAX_NAME_LEN - strlen(buf2));
00689 strncat(buf2, "=", MAX_NAME_LEN - strlen(buf2));
00690 if (res == NULL) {
00691 strncat(buf2, "<null>", MAX_NAME_LEN - strlen(buf2));
00692 } else {
00693 char *buf4 = convertResToString(res);
00694 strncat(buf2, buf4, MAX_NAME_LEN - strlen(buf2));
00695 strncat(buf2, ":", MAX_NAME_LEN - strlen(buf2));
00696 strncat(buf2, res->exprType == NULL? "<null>" : typeToString(res->exprType, NULL, typeNameBuf, 128), MAX_NAME_LEN - strlen(buf2));
00697 free(buf4);
00698 }
00699 k++;
00700 b = b->next;
00701 }
00702 }
00703 }
00704
00705 int convertResToIntReturnValue(Res *res) {
00706 int retVal;
00707 if(getNodeType(res) == N_ERROR) {
00708 retVal = RES_ERR_CODE(res);
00709 } else {
00710 retVal = RES_INT_VAL(res);
00711 }
00712 return retVal;
00713
00714 }
00715