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) = (int)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_DATETIME:
00340
00341
00342
00343
00344 var->inOutStruct = (rodsLong_t *)malloc(sizeof(int));
00345 *((rodsLong_t *)var->inOutStruct) = RES_TIME_VAL(res);
00346 var->type = strdup(INT_MS_T);
00347 break;
00348 case T_CONS:
00349 if(strcmp(T_CONS_TYPE_NAME(res->exprType), LIST) == 0) {
00350 switch(getNodeType(T_CONS_TYPE_ARG(res->exprType, 0))) {
00351 case T_STRING:
00352 arr = (strArray_t *)malloc(sizeof(strArray_t));
00353 arr->len = res->degree;
00354 maxlen = 0;
00355 for(i=0;i<res->degree;i++) {
00356 int slen = RES_STRING_STR_LEN(res->subtrees[i]);
00357 maxlen = maxlen < slen? slen: maxlen;
00358 }
00359 arr->size = maxlen;
00360 arr->value = (char *)malloc(sizeof(char)*maxlen*(arr->len));
00361 for(i=0;i<res->degree;i++) {
00362 strcpy(arr->value + maxlen*i, res->subtrees[i]->text);
00363 }
00364 var->inOutStruct = arr;
00365 var->type = strdup(StrArray_MS_T);
00366 break;
00367 case T_INT:
00368 arr2 = (intArray_t *)malloc(sizeof(intArray_t));
00369 arr2->len = res->degree;
00370 arr2->value = (int *)malloc(sizeof(int)*(arr2->len));
00371 for(i=0;i<res->degree;i++) {
00372 arr2->value[i] = RES_INT_VAL(res);
00373 }
00374 var->inOutStruct = arr2;
00375 var->type = strdup(IntArray_MS_T);
00376 break;
00377
00378
00379
00380
00381
00382 default:
00383
00384
00385 addRErrorMsg(errmsg, RE_PACKING_ERROR, "no packing instruction for arbitrary collection type");
00386 return RE_PACKING_ERROR;
00387 }
00388 } else {
00389 addRErrorMsg(errmsg, RE_PACKING_ERROR, "no packing instruction for arbitrary constructed type");
00390 return RE_PACKING_ERROR;
00391 }
00392 break;
00393 case T_IRODS:
00394 var->inOutStruct = RES_UNINTER_STRUCT(res);
00395 var->inpOutBuf = RES_UNINTER_BUFFER(res);
00396 var->type = strdup(res->exprType->text);
00397 break;
00398 case T_UNSPECED:
00399 var->inOutStruct = NULL;
00400 var->type = NULL;
00401 break;
00402 default:
00403
00404 addRErrorMsg(errmsg, RE_PACKING_ERROR, "no packing instruction for arbitrary type");
00405 return RE_PACKING_ERROR;
00406 }
00407 return 0;
00408 }
00409 int updateResToMsParam(msParam_t *var, Res *res, rError_t *errmsg) {
00410 if(var->type != NULL && (strcmp(var->type, INT_MS_T) == 0 ||
00411 strcmp(var->type, DOUBLE_MS_T) == 0 ||
00412 strcmp(var->type, STR_MS_T) == 0)) {
00413
00414 if(var->inOutStruct!=NULL) {
00415 free(var->inOutStruct);
00416 }
00417 if(var->inpOutBuf!=NULL) {
00418 free(var->inpOutBuf);
00419 }
00420 }
00421 if(var->label!=NULL) {
00422 free(var->label);
00423 }
00424 return convertResToMsParam(var, res, errmsg);
00425 }
00426 int convertEnvToMsParamArray(msParamArray_t *var, Env *env, rError_t *errmsg, Region *r) {
00427 int ret;
00428 if(env->previous!=NULL) {
00429 if((ret = convertEnvToMsParamArray(var, env->previous, errmsg, r))!=0) {
00430 return ret;
00431 }
00432 }
00433 return convertHashtableToMsParamArray(var, env->current, errmsg, r);
00434 }
00435
00436 int convertHashtableToMsParamArray(msParamArray_t *var, Hashtable *env, rError_t *errmsg, Region *r) {
00437 int i;
00438 for(i=0;i<env->size;i++) {
00439 struct bucket *b = env->buckets[i];
00440 while(b!=NULL && !IS_TVAR_NAME(b->key)) {
00441 Res *res = (Res *)b->value;
00442 msParam_t *v = NULL;
00443 int varindex;
00444 int ret;
00445 for(varindex=0;varindex<var->len;varindex++) {
00446 if(var->msParam[varindex]->label!=NULL && strcmp(var->msParam[varindex]->label, b->key) == 0) {
00447 v = var->msParam[varindex];
00448 ret = updateResToMsParam(v, res, errmsg);
00449 break;
00450 }
00451 }
00452 if(v == NULL) {
00453 v = (msParam_t *) malloc(sizeof(msParam_t));
00454 ret = convertResToMsParam(v, res, errmsg);
00455 if(var->msParam == NULL) {
00456 var->len = 0;
00457 var->msParam = (msParam_t **) malloc(sizeof(msParam_t *)*(PTR_ARRAY_MALLOC_LEN));
00458 } else if(var->len % PTR_ARRAY_MALLOC_LEN == 0) {
00459 var->msParam = (msParam_t **) realloc(var->msParam, sizeof(msParam_t *)*(PTR_ARRAY_MALLOC_LEN + var->len));
00460 }
00461
00462 var->msParam[var->len++] = v;
00463 }
00464 v->label = strdup(b->key);
00465
00466 if(ret != 0) {
00467
00468
00469 free(v);
00470 return ret;
00471 }
00472
00473 b=b->next;
00474 }
00475 }
00476 return 0;
00477 }
00478 int convertMsParamArrayToEnv(msParamArray_t *var, Env *env, rError_t *errmsg, Region *r) {
00479 return updateMsParamArrayToEnv(var, env, errmsg, r);
00480 }
00481
00482 int convertMsParamArrayToEnvAndFreeNonIRODSType(msParamArray_t *var, Env *env, rError_t *errmsg, Region *r) {
00483 return updateMsParamArrayToEnvAndFreeNonIRODSType(var, env, errmsg, r);
00484 }
00485 int updateMsParamArrayToEnv(msParamArray_t *var, Env *env, rError_t *errmsg, Region *r) {
00486 int i;
00487 for(i=0;i<var->len;i++) {
00488 Res *res = newRes(r);
00489 int ret = convertMsParamToRes(var->msParam[i], res, errmsg, r);
00490 if(ret != 0) {
00491 return ret;
00492 }
00493 char *varName = var->msParam[i]->label;
00494 if(varName!=NULL) {
00495 updateInEnv(env, varName, res);
00496 }
00497 }
00498 return 0;
00499 }
00500 int updateMsParamArrayToEnvAndFreeNonIRODSType(msParamArray_t *var, Env *env, rError_t *errmsg, Region *r) {
00501 int i;
00502 for(i=0;i<var->len;i++) {
00503 Res *res = newRes(r);
00504 int ret = convertMsParamToResAndFreeNonIRODSType(var->msParam[i], res, errmsg, r);
00505 if(ret != 0) {
00506 return ret;
00507 }
00508 char *varName = var->msParam[i]->label;
00509 if(varName!=NULL) {
00510 updateInEnv(env, varName, res);
00511 }
00512 }
00513 return 0;
00514 }
00515
00516
00517 char* convertResToString(Res *res0) {
00518 char *res;
00519 char *type;
00520 int j;
00521 switch (getNodeType(res0)) {
00522
00523 case N_ERROR:
00524 res = (char *)malloc(sizeof(char)*1024);
00525 snprintf(res, 1024, "error %d", RES_ERR_CODE(res0));
00526 return res;
00527 case N_VAL:
00528 switch(TYPE(res0)) {
00529 case T_INT:
00530 case T_DOUBLE:
00531 res = (char *)malloc(sizeof(char)*1024);
00532 if(res0->dval==(int)res0->dval) {
00533 snprintf(res, 1024, "%d", (int)res0->dval);
00534 } else {
00535 snprintf(res, 1024, "%f", res0->dval);
00536 }
00537 return res;
00538 case T_STRING:
00539 if(res0->text == NULL) {
00540 res = strdup("<null>");
00541 } else {
00542 res = strdup(res0->text);
00543 }
00544 return res;
00545 case T_IRODS:
00546 res = (char *)malloc(sizeof(char)*1024);
00547 res[0] = 0;
00548 type = res0->exprType->text;
00549 if(strcmp(type, KeyValPair_MS_T)==0) {
00550 keyValPair_t *kvp = (keyValPair_t *) RES_UNINTER_STRUCT(res0);
00551 snprintf(res, 1024, "KeyValue[%d]:", kvp->len);
00552 int i;
00553 for(i=0;i<kvp->len;i++) {
00554 snprintf(res + strlen(res), 1024 - strlen(res), "%s=%s;", kvp->keyWord[i],kvp->value[i]);
00555 }
00556
00557 } else if (strcmp(type, BUF_LEN_MS_T) == 0 ) {
00558 snprintf(res + strlen(res), 1024 - strlen(res),"%d",*(int*)res0->param->inOutStruct);
00559 } else if (strcmp(type, DataObjInp_MS_T) == 0) {
00560 dataObjInp_t dataObjInp, *myDataObjInp;
00561 j = parseMspForDataObjInp (res0->param, &dataObjInp, &myDataObjInp, 0);
00562 if (j < 0)
00563 snprintf(res + strlen(res), 1024 - strlen(res), "<error>");
00564 else
00565 snprintf(res + strlen(res), 1024 - strlen(res), "%s",(char *) myDataObjInp->objPath);
00566 } else if (strcmp(type, CollInp_MS_T ) == 0) {
00567 collInp_t collCreateInp, *myCollCreateInp;
00568 j = parseMspForCollInp (res0->param, &collCreateInp, &myCollCreateInp, 0);
00569 if (j < 0)
00570 snprintf(res + strlen(res), 1024 - strlen(res), "<error>");
00571 else
00572 snprintf(res + strlen(res), 1024 - strlen(res), "%s", myCollCreateInp->collName);
00573 } else if (strcmp(type, DataObjCopyInp_MS_T) == 0) {
00574 dataObjCopyInp_t dataObjCopyInp, *myDataObjCopyInp;
00575 j = parseMspForDataObjCopyInp (res0->param, &dataObjCopyInp, &myDataObjCopyInp);
00576 if (j < 0)
00577 snprintf(res + strlen(res), 1024 - strlen(res), "<error>");
00578 else
00579 snprintf (res + strlen(res), 1024 - strlen(res), "COPY(%s,%s)",
00580 myDataObjCopyInp->srcDataObjInp.objPath, myDataObjCopyInp->destDataObjInp.objPath);
00581 } else if (strcmp(type, DataObjReadInp_MS_T) == 0
00582 || strcmp(type, DataObjCloseInp_MS_T) == 0
00583 || strcmp(type, DataObjWriteInp_MS_T) == 0 ) {
00584 openedDataObjInp_t *myDataObjReadInp;
00585 myDataObjReadInp = (openedDataObjInp_t *) res0->param->inOutStruct;
00586 snprintf (res + strlen(res), 1024 - strlen(res), "OPEN(%d)",myDataObjReadInp->len);
00587 } else if (strcmp(type, ExecCmd_MS_T ) == 0) {
00588 execCmd_t *execCmd;
00589 execCmd = (execCmd_t *) res0->param->inOutStruct;
00590 snprintf(res + strlen(res), 1024 - strlen(res), "%s", execCmd->cmd);
00591 } else {
00592 snprintf(res, 1024, "<value>");
00593 }
00594 return res;
00595 case T_BOOL:
00596 res = strdup(RES_BOOL_VAL(res0)?"true":"false");
00597 return res;
00598 case T_CONS:
00599 res = (char *)malloc(sizeof(char)*1024);
00600 sprintf(res, "[");
00601 int i;
00602 for(i=0;i<res0->degree;i++) {
00603 char *resElem = convertResToString(res0->subtrees[i]);
00604 if(resElem == NULL) {
00605 free(res);
00606 return NULL;
00607 } else {
00608 snprintf(res+strlen(res), 1024-strlen(res), "%s%s", i==0?"":",",resElem);
00609 free(resElem);
00610 }
00611 }
00612 snprintf(res+strlen(res), 1024-strlen(res), "]");
00613 return res;
00614 case T_DATETIME:
00615 res = (char *)malloc(sizeof(char)*1024);
00616 ttimestr(res, 1024-1, "", &RES_TIME_VAL(res0));
00617 return res;
00618 case T_UNSPECED:
00619 res = strdup("<undefined>");
00620 return res;
00621 default:
00622
00623 return NULL;
00624 }
00625 break;
00626 default:
00627 res = (char *)malloc(sizeof(char)*128);
00628 return typeToString(res0, NULL, res, 128);
00629 }
00630 }
00631
00632
00633 void printMsParamArray(msParamArray_t *msParamArray, char *buf2) {
00634 char buf3[MAX_NAME_LEN];
00635 sprintf(buf2, "len: %d\n", msParamArray->len);
00636 int i;
00637 for(i=0;i<msParamArray->len;i++) {
00638 msParam_t *mP = msParamArray->msParam[i];
00639 if(i!=0)strncat(buf2, ",", MAX_NAME_LEN - strlen(buf2));
00640 strncat(buf2, mP->label, MAX_NAME_LEN - strlen(buf2));
00641 strncat(buf2, "=", MAX_NAME_LEN - strlen(buf2));
00642 if(mP->inOutStruct == NULL) {
00643 strncat(buf2, "<null>", MAX_NAME_LEN - strlen(buf2));
00644 } else {
00645 if (strcmp(mP->type, DOUBLE_MS_T) == 0) {
00646 snprintf(buf3, MAX_NAME_LEN, "%f:",*(double *)mP->inOutStruct);
00647 } else if (strcmp(mP->type, INT_MS_T) == 0) {
00648 snprintf(buf3, MAX_NAME_LEN, "%d:",*(int *)mP->inOutStruct);
00649 } else if (strcmp(mP->type, STR_MS_T) == 0) {
00650 snprintf(buf3, MAX_NAME_LEN, "%s:",(char *)mP->inOutStruct);
00651 } else if(strcmp(mP->type, DATETIME_MS_T) == 0) {
00652 snprintf(buf3, MAX_NAME_LEN, "%ld:",(long)*(time_t *)mP->inOutStruct);
00653 } else {
00654 snprintf(buf3, MAX_NAME_LEN, "<value>:");
00655 }
00656 strncat(buf2, buf3, MAX_NAME_LEN - strlen(buf2));
00657 strncat(buf2, mP->type, MAX_NAME_LEN - strlen(buf2));
00658 }
00659 }
00660 return;
00661 }
00662
00663 void printHashtable(Hashtable *env, char* buf2) {
00664 int i;
00665 char typeNameBuf[128];
00666 sprintf(buf2, "len: %d\n", env->len);
00667 int k = 0;
00668 for (i = 0; i < env->size; i++) {
00669 struct bucket *b = env->buckets[i];
00670 while (b != NULL) {
00671 Res *res = (Res *) b->value;
00672 if (k != 0)strncat(buf2, "\n", MAX_NAME_LEN - strlen(buf2));
00673 strncat(buf2, b->key, MAX_NAME_LEN - strlen(buf2));
00674 strncat(buf2, "=", MAX_NAME_LEN - strlen(buf2));
00675 if (res == NULL) {
00676 strncat(buf2, "<null>", MAX_NAME_LEN - strlen(buf2));
00677 } else {
00678 char *buf4 = convertResToString(res);
00679 strncat(buf2, buf4, MAX_NAME_LEN - strlen(buf2));
00680 strncat(buf2, ":", MAX_NAME_LEN - strlen(buf2));
00681 strncat(buf2, res->exprType == NULL? "<null>" : typeToString(res->exprType, NULL, typeNameBuf, 128), MAX_NAME_LEN - strlen(buf2));
00682 free(buf4);
00683 }
00684 k++;
00685 b = b->next;
00686 }
00687 }
00688 }
00689
00690 int convertResToIntReturnValue(Res *res) {
00691 int retVal;
00692 if(getNodeType(res) == N_ERROR) {
00693 retVal = RES_ERR_CODE(res);
00694 } else {
00695 retVal = RES_INT_VAL(res);
00696 }
00697 return retVal;
00698
00699 }
00700