00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "setup.h"
00030
00031 #if OBJECT_SYSTEM
00032
00033 #include "argacces.h"
00034 #include "envrnmnt.h"
00035 #include "extnfunc.h"
00036 #include "insfun.h"
00037 #include "msgfun.h"
00038 #include "msgpass.h"
00039 #include "multifun.h"
00040 #include "router.h"
00041
00042 #define _INSMULT_SOURCE_
00043 #include "insmult.h"
00044
00045
00046
00047
00048
00049
00050 #define INSERT 0
00051 #define REPLACE 1
00052 #define DELETE_OP 2
00053
00054
00055
00056
00057
00058
00059
00060 static INSTANCE_TYPE *CheckMultifieldSlotInstance(void *,char *);
00061 static INSTANCE_SLOT *CheckMultifieldSlotModify(void *,int,char *,INSTANCE_TYPE *,
00062 EXPRESSION *,long *,long *,DATA_OBJECT *);
00063 static void AssignSlotToDataObject(DATA_OBJECT *,INSTANCE_SLOT *);
00064
00065
00066
00067
00068
00069
00070
00071 #if (! RUN_TIME)
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 globle void SetupInstanceMultifieldCommands(
00083 void *theEnv)
00084 {
00085
00086
00087
00088 EnvDefineFunction2(theEnv,"direct-mv-replace",'b',PTIEF DirectMVReplaceCommand,
00089 "DirectMVReplaceCommand","4**wii");
00090 EnvDefineFunction2(theEnv,"direct-mv-insert",'b',PTIEF DirectMVInsertCommand,
00091 "DirectMVInsertCommand","3**wi");
00092 EnvDefineFunction2(theEnv,"direct-mv-delete",'b',PTIEF DirectMVDeleteCommand,
00093 "DirectMVDeleteCommand","33iw");
00094 EnvDefineFunction2(theEnv,"mv-slot-replace",'u',PTIEF MVSlotReplaceCommand,
00095 "MVSlotReplaceCommand","5*uewii");
00096 EnvDefineFunction2(theEnv,"mv-slot-insert",'u',PTIEF MVSlotInsertCommand,
00097 "MVSlotInsertCommand","4*uewi");
00098 EnvDefineFunction2(theEnv,"mv-slot-delete",'u',PTIEF MVSlotDeleteCommand,
00099 "MVSlotDeleteCommand","44iew");
00100
00101
00102
00103
00104 EnvDefineFunction2(theEnv,"slot-direct-replace$",'b',PTIEF DirectMVReplaceCommand,
00105 "DirectMVReplaceCommand","4**wii");
00106 EnvDefineFunction2(theEnv,"slot-direct-insert$",'b',PTIEF DirectMVInsertCommand,
00107 "DirectMVInsertCommand","3**wi");
00108 EnvDefineFunction2(theEnv,"slot-direct-delete$",'b',PTIEF DirectMVDeleteCommand,
00109 "DirectMVDeleteCommand","33iw");
00110 EnvDefineFunction2(theEnv,"slot-replace$",'u',PTIEF MVSlotReplaceCommand,
00111 "MVSlotReplaceCommand","5*uewii");
00112 EnvDefineFunction2(theEnv,"slot-insert$",'u',PTIEF MVSlotInsertCommand,
00113 "MVSlotInsertCommand","4*uewi");
00114 EnvDefineFunction2(theEnv,"slot-delete$",'u',PTIEF MVSlotDeleteCommand,
00115 "MVSlotDeleteCommand","44iew");
00116 }
00117
00118 #endif
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 globle void MVSlotReplaceCommand(
00134 void *theEnv,
00135 DATA_OBJECT *result)
00136 {
00137 DATA_OBJECT newval,newseg,oldseg;
00138 INSTANCE_TYPE *ins;
00139 INSTANCE_SLOT *sp;
00140 long rb,re;
00141 EXPRESSION arg;
00142
00143 result->type = SYMBOL;
00144 result->value = EnvFalseSymbol(theEnv);
00145 ins = CheckMultifieldSlotInstance(theEnv,"slot-replace$");
00146 if (ins == NULL)
00147 return;
00148 sp = CheckMultifieldSlotModify(theEnv,REPLACE,"slot-replace$",ins,
00149 GetFirstArgument()->nextArg,&rb,&re,&newval);
00150 if (sp == NULL)
00151 return;
00152 AssignSlotToDataObject(&oldseg,sp);
00153 if (ReplaceMultiValueField(theEnv,&newseg,&oldseg,rb,re,&newval,"slot-replace$") == FALSE)
00154 return;
00155 arg.type = MULTIFIELD;
00156 arg.value = (void *) &newseg;
00157 arg.nextArg = NULL;
00158 arg.argList = NULL;
00159 DirectMessage(theEnv,sp->desc->overrideMessage,ins,result,&arg);
00160 }
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 globle void MVSlotInsertCommand(
00174 void *theEnv,
00175 DATA_OBJECT *result)
00176 {
00177 DATA_OBJECT newval,newseg,oldseg;
00178 INSTANCE_TYPE *ins;
00179 INSTANCE_SLOT *sp;
00180 long theIndex;
00181 EXPRESSION arg;
00182
00183 result->type = SYMBOL;
00184 result->value = EnvFalseSymbol(theEnv);
00185 ins = CheckMultifieldSlotInstance(theEnv,"slot-insert$");
00186 if (ins == NULL)
00187 return;
00188 sp = CheckMultifieldSlotModify(theEnv,INSERT,"slot-insert$",ins,
00189 GetFirstArgument()->nextArg,&theIndex,NULL,&newval);
00190 if (sp == NULL)
00191 return;
00192 AssignSlotToDataObject(&oldseg,sp);
00193 if (InsertMultiValueField(theEnv,&newseg,&oldseg,theIndex,&newval,"slot-insert$") == FALSE)
00194 return;
00195 arg.type = MULTIFIELD;
00196 arg.value = (void *) &newseg;
00197 arg.nextArg = NULL;
00198 arg.argList = NULL;
00199 DirectMessage(theEnv,sp->desc->overrideMessage,ins,result,&arg);
00200 }
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 globle void MVSlotDeleteCommand(
00215 void *theEnv,
00216 DATA_OBJECT *result)
00217 {
00218 DATA_OBJECT newseg,oldseg;
00219 INSTANCE_TYPE *ins;
00220 INSTANCE_SLOT *sp;
00221 long rb,re;
00222 EXPRESSION arg;
00223
00224 result->type = SYMBOL;
00225 result->value = EnvFalseSymbol(theEnv);
00226 ins = CheckMultifieldSlotInstance(theEnv,"slot-delete$");
00227 if (ins == NULL)
00228 return;
00229 sp = CheckMultifieldSlotModify(theEnv,DELETE_OP,"slot-delete$",ins,
00230 GetFirstArgument()->nextArg,&rb,&re,NULL);
00231 if (sp == NULL)
00232 return;
00233 AssignSlotToDataObject(&oldseg,sp);
00234 if (DeleteMultiValueField(theEnv,&newseg,&oldseg,rb,re,"slot-delete$") == FALSE)
00235 return;
00236 arg.type = MULTIFIELD;
00237 arg.value = (void *) &newseg;
00238 arg.nextArg = NULL;
00239 arg.argList = NULL;
00240 DirectMessage(theEnv,sp->desc->overrideMessage,ins,result,&arg);
00241 }
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252 globle intBool DirectMVReplaceCommand(
00253 void *theEnv)
00254 {
00255 INSTANCE_SLOT *sp;
00256 INSTANCE_TYPE *ins;
00257 long rb,re;
00258 DATA_OBJECT newval,newseg,oldseg;
00259
00260 if (CheckCurrentMessage(theEnv,"direct-slot-replace$",TRUE) == FALSE)
00261 return(FALSE);
00262 ins = GetActiveInstance(theEnv);
00263 sp = CheckMultifieldSlotModify(theEnv,REPLACE,"direct-slot-replace$",ins,
00264 GetFirstArgument(),&rb,&re,&newval);
00265 if (sp == NULL)
00266 return(FALSE);
00267 AssignSlotToDataObject(&oldseg,sp);
00268 if (ReplaceMultiValueField(theEnv,&newseg,&oldseg,rb,re,&newval,"direct-slot-replace$")
00269 == FALSE)
00270 return(FALSE);
00271 if (PutSlotValue(theEnv,ins,sp,&newseg,&newval,"function direct-slot-replace$"))
00272 return(TRUE);
00273 return(FALSE);
00274 }
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284 globle intBool DirectMVInsertCommand(
00285 void *theEnv)
00286 {
00287 INSTANCE_SLOT *sp;
00288 INSTANCE_TYPE *ins;
00289 long theIndex;
00290 DATA_OBJECT newval,newseg,oldseg;
00291
00292 if (CheckCurrentMessage(theEnv,"direct-slot-insert$",TRUE) == FALSE)
00293 return(FALSE);
00294 ins = GetActiveInstance(theEnv);
00295 sp = CheckMultifieldSlotModify(theEnv,INSERT,"direct-slot-insert$",ins,
00296 GetFirstArgument(),&theIndex,NULL,&newval);
00297 if (sp == NULL)
00298 return(FALSE);
00299 AssignSlotToDataObject(&oldseg,sp);
00300 if (InsertMultiValueField(theEnv,&newseg,&oldseg,theIndex,&newval,"direct-slot-insert$")
00301 == FALSE)
00302 return(FALSE);
00303 if (PutSlotValue(theEnv,ins,sp,&newseg,&newval,"function direct-slot-insert$"))
00304 return(TRUE);
00305 return(FALSE);
00306 }
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317 globle intBool DirectMVDeleteCommand(
00318 void *theEnv)
00319 {
00320 INSTANCE_SLOT *sp;
00321 INSTANCE_TYPE *ins;
00322 long rb,re;
00323 DATA_OBJECT newseg,oldseg;
00324
00325 if (CheckCurrentMessage(theEnv,"direct-slot-delete$",TRUE) == FALSE)
00326 return(FALSE);
00327 ins = GetActiveInstance(theEnv);
00328 sp = CheckMultifieldSlotModify(theEnv,DELETE_OP,"direct-slot-delete$",ins,
00329 GetFirstArgument(),&rb,&re,NULL);
00330 if (sp == NULL)
00331 return(FALSE);
00332 AssignSlotToDataObject(&oldseg,sp);
00333 if (DeleteMultiValueField(theEnv,&newseg,&oldseg,rb,re,"direct-slot-delete$")
00334 == FALSE)
00335 return(FALSE);
00336 if (PutSlotValue(theEnv,ins,sp,&newseg,&oldseg,"function direct-slot-delete$"))
00337 return(TRUE);
00338 return(FALSE);
00339 }
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356 static INSTANCE_TYPE *CheckMultifieldSlotInstance(
00357 void *theEnv,
00358 char *func)
00359 {
00360 INSTANCE_TYPE *ins;
00361 DATA_OBJECT temp;
00362
00363 if (EnvArgTypeCheck(theEnv,func,1,INSTANCE_OR_INSTANCE_NAME,&temp) == FALSE)
00364 {
00365 SetEvaluationError(theEnv,TRUE);
00366 return(NULL);
00367 }
00368 if (temp.type == INSTANCE_ADDRESS)
00369 {
00370 ins = (INSTANCE_TYPE *) temp.value;
00371 if (ins->garbage == 1)
00372 {
00373 StaleInstanceAddress(theEnv,func,0);
00374 SetEvaluationError(theEnv,TRUE);
00375 return(NULL);
00376 }
00377 }
00378 else
00379 {
00380 ins = FindInstanceBySymbol(theEnv,(SYMBOL_HN *) temp.value);
00381 if (ins == NULL)
00382 NoInstanceError(theEnv,ValueToString(temp.value),func);
00383 }
00384 return(ins);
00385 }
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415 static INSTANCE_SLOT *CheckMultifieldSlotModify(
00416 void *theEnv,
00417 int code,
00418 char *func,
00419 INSTANCE_TYPE *ins,
00420 EXPRESSION *args,
00421 long *rb,
00422 long *re,
00423 DATA_OBJECT *newval)
00424 {
00425 DATA_OBJECT temp;
00426 INSTANCE_SLOT *sp;
00427 int start;
00428
00429 start = (args == GetFirstArgument()) ? 1 : 2;
00430 EvaluationData(theEnv)->EvaluationError = FALSE;
00431 EvaluateExpression(theEnv,args,&temp);
00432 if (temp.type != SYMBOL)
00433 {
00434 ExpectedTypeError1(theEnv,func,start,"symbol");
00435 SetEvaluationError(theEnv,TRUE);
00436 return(NULL);
00437 }
00438 sp = FindInstanceSlot(theEnv,ins,(SYMBOL_HN *) temp.value);
00439 if (sp == NULL)
00440 {
00441 SlotExistError(theEnv,ValueToString(temp.value),func);
00442 return(NULL);
00443 }
00444 if (sp->desc->multiple == 0)
00445 {
00446 PrintErrorID(theEnv,"INSMULT",1,FALSE);
00447 EnvPrintRouter(theEnv,WERROR,"Function ");
00448 EnvPrintRouter(theEnv,WERROR,func);
00449 EnvPrintRouter(theEnv,WERROR," cannot be used on single-field slot ");
00450 EnvPrintRouter(theEnv,WERROR,ValueToString(sp->desc->slotName->name));
00451 EnvPrintRouter(theEnv,WERROR," in instance ");
00452 EnvPrintRouter(theEnv,WERROR,ValueToString(ins->name));
00453 EnvPrintRouter(theEnv,WERROR,".\n");
00454 SetEvaluationError(theEnv,TRUE);
00455 return(NULL);
00456 }
00457 EvaluateExpression(theEnv,args->nextArg,&temp);
00458 if (temp.type != INTEGER)
00459 {
00460 ExpectedTypeError1(theEnv,func,start+1,"integer");
00461 SetEvaluationError(theEnv,TRUE);
00462 return(NULL);
00463 }
00464 args = args->nextArg->nextArg;
00465 *rb = (long) ValueToLong(temp.value);
00466 if ((code == REPLACE) || (code == DELETE_OP))
00467 {
00468 EvaluateExpression(theEnv,args,&temp);
00469 if (temp.type != INTEGER)
00470 {
00471 ExpectedTypeError1(theEnv,func,start+2,"integer");
00472 SetEvaluationError(theEnv,TRUE);
00473 return(NULL);
00474 }
00475 *re = (long) ValueToLong(temp.value);
00476 args = args->nextArg;
00477 }
00478 if ((code == INSERT) || (code == REPLACE))
00479 {
00480 if (EvaluateAndStoreInDataObject(theEnv,1,args,newval,TRUE) == FALSE)
00481 return(NULL);
00482 }
00483 return(sp);
00484 }
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496 static void AssignSlotToDataObject(
00497 DATA_OBJECT *theDataObject,
00498 INSTANCE_SLOT *theSlot)
00499 {
00500 theDataObject->type = (unsigned short) theSlot->type;
00501 theDataObject->value = theSlot->value;
00502 theDataObject->begin = 0;
00503 SetpDOEnd(theDataObject,GetInstanceSlotLength(theSlot));
00504 }
00505
00506 #endif
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517