00001
00041 #include "soarkernel.h"
00042 #include "soarapi.h"
00043 #include "soarapiUtils.h"
00044 #include "soarapiCallbacks.h"
00045 #include "scheduler.h"
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 int soar_ReInitSoar(int argc, const char *argv[], soarResult * res)
00070 {
00071
00072 argv = argv;
00073 argc = argc;
00074
00075 clearSoarResultResult(res);
00076 soar_cReInitSoar();
00077
00078 return SOAR_OK;
00079
00080 }
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 int soar_CreateAgent(int argc, const char *argv[], soarResult * res)
00091 {
00092 char too_few[] = "Too few arguments, a name must be supplied.";
00093 char too_many[] = "Too many arguments, only a name may be supplied.";
00094
00095 if (argc < 2) {
00096 setSoarResultResult(res, too_few);
00097 return SOAR_ERROR;
00098 }
00099
00100 if (argc > 3) {
00101 setSoarResultResult(res, too_many);
00102 return SOAR_ERROR;
00103 }
00104
00105 soar_cCreateAgent(argv[1]);
00106 clearSoarResultResult(res);
00107 return SOAR_OK;
00108
00109 }
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 int soar_Run(int argc, const char *argv[], soarResult * res)
00120 {
00121 agent *the_agent;
00122 cons *c;
00123 int parse_result;
00124 long go_number;
00125 enum go_type_enum go_type;
00126 Symbol *go_slot_attr;
00127 goal_stack_level go_slot_level;
00128 bool self_only = FALSE;
00129 bool single_agent = FALSE;
00130
00131 static bool executing = FALSE;
00132
00133 if (executing == TRUE) {
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 clearSoarResultResult(res);
00147 return SOAR_OK;
00148 } else {
00149 executing = TRUE;
00150 }
00151
00152 the_agent = soar_agent;
00153
00154 c = all_soar_agents;
00155 if (c->rest == NIL)
00156 single_agent = TRUE;
00157
00158 go_number = 1;
00159 go_type = GO_DECISION;
00160
00161
00162
00163 parse_result = parse_run_command(argc, argv, &go_number, &go_type, &go_slot_attr, &go_slot_level, &self_only, res);
00164 if (parse_result == SOAR_OK) {
00165
00166 if ((self_only) || (single_agent)) {
00167
00168 run_current_agent(go_number, go_type, go_slot_attr, go_slot_level);
00169 } else {
00170
00171
00172
00173
00174
00175 run_all_agents(go_number, go_type, go_slot_attr, go_slot_level);
00176 }
00177 executing = FALSE;
00178 clearSoarResultResult(res);
00179 return SOAR_OK;
00180 } else {
00181 executing = FALSE;
00182 return SOAR_ERROR;
00183 }
00184
00185 }
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 int soar_DestroyAgent(int argc, const char *argv[], soarResult * res)
00196 {
00197
00198 if (argc > 2) {
00199 setSoarResultResult(res, "Too many arguments");
00200 return SOAR_ERROR;
00201 }
00202
00203 if (argc < 2) {
00204 setSoarResultResult(res, "Expected agent name but none given.");
00205 return SOAR_ERROR;
00206 }
00207
00208 soar_cDestroyAgentByName(argv[1]);
00209 clearSoarResultResult(res);
00210 return SOAR_OK;
00211
00212 }
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 int soar_Quit(int argc, const char *argv[], soarResult * res)
00223 {
00224
00225 argv = argv;
00226 argc = argc;
00227 res = res;
00228
00229 soar_cQuit();
00230 return SOAR_OK;
00231 }
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 int soar_ReteNet(int argc, const char *argv[], soarResult * res)
00254 {
00255
00256 if (argc < 3) {
00257 setSoarResultResult(res, "Too few arguments.\nUsage: rete-net {-save | -load} filename.");
00258 return SOAR_ERROR;
00259 }
00260
00261 if (argc > 3) {
00262 setSoarResultResult(res, "Too many arguments.\nUsage: rete-net {-save | -load} filename.");
00263 return SOAR_ERROR;
00264 }
00265
00266 if (string_match("-save", argv[1])) {
00267 if (!soar_cSaveReteNet(argv[2])) {
00268 clearSoarResultResult(res);
00269 return SOAR_OK;
00270 }
00271
00272
00273
00274 setSoarResultResult(res, "Failed to save rete net\n");
00275 return SOAR_ERROR;
00276 } else if (string_match("-load", argv[1])) {
00277 if (!soar_cLoadReteNet(argv[2])) {
00278 clearSoarResultResult(res);
00279 return SOAR_OK;
00280 }
00281
00282
00283
00284 setSoarResultResult(res, "Failed to load rete net\n");
00285 return SOAR_ERROR;
00286 } else {
00287 setSoarResultResult(res, "Unrecognized argument to ReteNet command: %s. Should be -save|-load", argv[1]);
00288 return SOAR_ERROR;
00289 }
00290
00291 }
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301 int soar_AddWme(int argc, const char *argv[], soarResult * res)
00302 {
00303
00304 static char *too_few_args = "Too few arguments.\nUsage: add-wme id [^] { attribute | '*'} { value | '*' } [+]";
00305 static char *too_many_args = "Too many arguments.\nUsage: add-wme id [^] { attribute | '*'} { value | '*' } [+]";
00306
00307 int attr_index;
00308 bool acceptable;
00309 psoar_wme psw;
00310
00311
00312 if (argc < 4) {
00313 setSoarResultResult(res, too_few_args);
00314 return SOAR_ERROR;
00315 }
00316
00317 if (string_match(argv[2], "^"))
00318 attr_index = 3;
00319 else
00320 attr_index = 2;
00321
00322 if (argc < (attr_index + 2)) {
00323 setSoarResultResult(res, too_few_args);
00324 return SOAR_ERROR;
00325 }
00326
00327 if (argc > (attr_index + 3)) {
00328 setSoarResultResult(res, too_many_args);
00329 return SOAR_ERROR;
00330 }
00331
00332 acceptable = FALSE;
00333
00334 if (argc > (attr_index + 2)) {
00335 if (string_match("+", argv[attr_index + 2])) {
00336 acceptable = TRUE;
00337 } else {
00338 setSoarResultResult(res, "Expected acceptable preference (+) or nothing, got %s\n", argv[attr_index + 2]);
00339 return SOAR_ERROR;
00340 }
00341
00342 }
00343
00344 if (soar_cAddWme(argv[1], argv[attr_index], argv[attr_index + 1], acceptable, &psw) <= 0) {
00345 return SOAR_ERROR;
00346 }
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367 setSoarResultResult(res, "%lu: ", ((wme *) psw)->timetag);
00368 appendSymbolsToSoarResultResult(res, "%y ^%y %y", ((wme *) psw)->id, ((wme *) psw)->attr, ((wme *) psw)->value);
00369 if (((wme *) psw)->acceptable)
00370 appendSoarResultResult(res, " +");
00371
00372 return SOAR_OK;
00373 }
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383 int soar_RemoveWme(int argc, const char *argv[], soarResult * res)
00384 {
00385 int num;
00386
00387 if (argc == 1) {
00388 setSoarResultResult(res, "Too few arguments, should be: remove-wme integer");
00389 return SOAR_ERROR;
00390 }
00391
00392 if (argc > 2) {
00393 setSoarResultResult(res, "Too many arguments, should be: remove-wme integer");
00394 return SOAR_ERROR;
00395 }
00396
00397 if (getInt(argv[1], &num) == SOAR_OK) {
00398 switch (soar_cRemoveWmeUsingTimetag(num)) {
00399
00400 case -1:
00401 setSoarResultResult(res, "No wme with timetag %d", num);
00402 return SOAR_ERROR;
00403 break;
00404
00405 case -2:
00406 setSoarResultResult(res, "Failed to remove wme with timetag %d", num);
00407 return SOAR_ERROR;
00408 break;
00409 }
00410
00411 } else {
00412 setSoarResultResult(res, "Unrecognized argument to remove-wme command: %s", argv[1]);
00413 return SOAR_ERROR;
00414 }
00415
00416 clearSoarResultResult(res);
00417 return SOAR_OK;
00418 }
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428 int soar_Excise(int argc, const char *argv[], soarResult * res)
00429 {
00430 int i;
00431
00432 if (argc == 1) {
00433 setSoarResultResult(res,
00434 "No arguments given.\nUsage: excise production-name | -chunks | -default | -task | -user | -all");
00435 return SOAR_ERROR;
00436 }
00437
00438 for (i = 1; i < argc; i++) {
00439 if (string_match_up_to(argv[i], "-chunks", 2)) {
00440 soar_cExciseAllProductionsOfType(CHUNK_PRODUCTION_TYPE);
00441 soar_cExciseAllProductionsOfType(JUSTIFICATION_PRODUCTION_TYPE);
00442 } else if (string_match_up_to(argv[i], "-default", 2))
00443 soar_cExciseAllProductionsOfType(DEFAULT_PRODUCTION_TYPE);
00444 else if (string_match_up_to(argv[i], "-task", 2))
00445 soar_cExciseAllTaskProductions();
00446 else if (string_match_up_to(argv[i], "-user", 2))
00447 soar_cExciseAllProductionsOfType(USER_PRODUCTION_TYPE);
00448 else if (string_match_up_to(argv[i], "-all", 2))
00449 soar_cExciseAllProductions();
00450 else if (soar_cExciseProductionByName(argv[i])) {
00451 setSoarResultResult(res, "Unrecognized Production name or argument: %s", argv[i]);
00452 return SOAR_ERROR;
00453 }
00454 }
00455 clearSoarResultResult(res);
00456 return SOAR_OK;
00457 }
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469 #ifdef USE_CAPTURE_REPLAY
00470
00471
00472
00473
00474
00475
00476
00477
00478 int soar_CaptureInput(int argc, const char *argv[], soarResult * res)
00479 {
00480
00481 char *too_many = "Too many arguments, should be: capture-input [-open pathname | -query | -close]";
00482 char *too_few = "Too few arguments, should be: capture-input [-open pathname | -query | -close]";
00483
00484 print(" %d args\n", argc);
00485 if (argc < 2) {
00486 setSoarResultResult(res, "The capture file is ");
00487
00488 if (current_agent(capture_fileID)) {
00489 appendSoarResultResult(res, "open. Use capture-input -close to close the file.");
00490 } else {
00491 appendSoarResultResult(res, "closed.");
00492 }
00493 return SOAR_OK;
00494 }
00495
00496 if (argc > 3) {
00497 setSoarResultResult(res, too_many);
00498 return SOAR_ERROR;
00499 }
00500
00501 if (string_match_up_to("-query", argv[1], 2)) {
00502 if (argc == 2) {
00503 if (current_agent(capture_fileID)) {
00504 setSoarResultResult(res, "open");
00505 } else {
00506 setSoarResultResult(res, "closed");
00507 }
00508 } else {
00509 setSoarResultResult(res, too_many);
00510 return SOAR_ERROR;
00511 }
00512 } else if (string_match_up_to("-close", argv[1], 2)) {
00513 if (argc == 2) {
00514 if (current_agent(capture_fileID)) {
00515 if (!(soar_ecCaptureInput(NIL))) {
00516 setSoarResultResult(res, "capture file closed");
00517 return SOAR_OK;
00518 }
00519 setSoarResultResult(res, "Error closing file");
00520 return SOAR_ERROR;
00521
00522 } else {
00523 setSoarResultResult(res, "Attempt to close non-existant capture file");
00524 return SOAR_ERROR;
00525 }
00526 } else if (argc > 2) {
00527 setSoarResultResult(res, too_many);
00528 return SOAR_ERROR;
00529 }
00530 } else if (string_match_up_to("-open", argv[1], 2)) {
00531 if (argc == 3) {
00532 if (current_agent(capture_fileID)) {
00533 setSoarResultResult(res, "Attempt to open new capture file before closing an old capture file");
00534 return SOAR_ERROR;
00535 } else {
00536 if (!soar_ecCaptureInput(argv[2])) {
00537 return SOAR_OK;
00538 }
00539 setSoarResultResult(res, "Error opening file.");
00540 return SOAR_ERROR;
00541 }
00542 } else {
00543 setSoarResultResult(res, too_few);
00544 return SOAR_ERROR;
00545 }
00546 } else {
00547 setSoarResultResult(res, "Invalid Arguments. Use: capture-input [-open pathname | -query | -close]");
00548 return SOAR_ERROR;
00549 }
00550
00551 return SOAR_ERROR;
00552 }
00553
00554
00555
00556
00557
00558
00559
00560
00561 int soar_ReplayInput(int argc, const char *argv[], soarResult * res)
00562 {
00563
00564 char *too_few = "Too few arguments, should be: replay-input [-open pathname | -query | -close]";
00565 char *too_many = "Too many arguments, should be: replay-input [-open pathname | -query | -close]";
00566
00567 if (argc < 2) {
00568 setSoarResultResult(res, "The replay file is ");
00569 if (current_agent(replay_fileID)) {
00570 appendSoarResultResult(res, "open. Use replay-input -close to close the file.");
00571 } else {
00572 appendSoarResultResult(res, "closed.");
00573 }
00574
00575 return SOAR_OK;
00576 }
00577 if (argc > 3) {
00578 setSoarResultResult(res, too_many);
00579 return SOAR_ERROR;
00580 }
00581
00582 if (string_match_up_to("-query", argv[1], 2)) {
00583 if (argc == 2) {
00584 if (current_agent(replay_fileID)) {
00585 setSoarResultResult(res, "open");
00586 } else {
00587 setSoarResultResult(res, "closed");
00588 }
00589 } else {
00590 setSoarResultResult(res, too_many);
00591 return SOAR_ERROR;
00592 }
00593 }
00594
00595 else if (string_match_up_to("-close", argv[1], 2)) {
00596 if (argc == 2) {
00597
00598 if (!soar_ecReplayInput(NIL)) {
00599 setSoarResultResult(res, "Replay Terminated.");
00600 return SOAR_OK;
00601 } else {
00602 setSoarResultResult(res, "Error Terminating Replay");
00603 return SOAR_ERROR;
00604 }
00605 } else if (argc > 2) {
00606 setSoarResultResult(res, too_many);
00607 return SOAR_ERROR;
00608 }
00609 } else {
00610
00611 if (string_match_up_to("-open", argv[1], 2)) {
00612 if (argc < 3) {
00613 setSoarResultResult(res, too_few);
00614 return SOAR_ERROR;
00615 } else if (!soar_ecReplayInput(argv[2])) {
00616 setSoarResultResult(res, "opened.");
00617 return SOAR_OK;
00618 } else {
00619 setSoarResultResult(res, "Error opening replay-file.");
00620 return SOAR_ERROR;
00621 }
00622 }
00623 }
00624 setSoarResultResult(res, "Invalid arguments");
00625 return SOAR_ERROR;
00626 }
00627
00628 #endif
00629
00630
00631
00632
00633
00634
00635
00636
00637 int soar_ChunkNameFormat(int argc, const char *argv[], soarResult * res)
00638 {
00639 unsigned long tmp_chunk_count;
00640 int i;
00641 bool seen_long_or_short;
00642
00643 if (argc == 1) {
00644 setSoarResultResult(res,
00645 "No arguments given.\nUsage: chunk-name-format [-short|-long] [-prefix [<prefix>]] [-count [<start-chunk-number>]]");
00646 return SOAR_ERROR;
00647 }
00648
00649 seen_long_or_short = FALSE;
00650 for (i = 1; i < argc; i++) {
00651
00652 if (string_match_up_to(argv[i], "-short", 2)) {
00653 if (seen_long_or_short) {
00654 setSoarResultResult(res, "-long and -short are exclusive options", argv[i]);
00655 return SOAR_ERROR;
00656 } else {
00657 seen_long_or_short = TRUE;
00658 soar_cSetChunkNameLong(FALSE);
00659 }
00660
00661 } else if (string_match_up_to(argv[i], "-long", 2)) {
00662 if (seen_long_or_short) {
00663 setSoarResultResult(res, "-long and -short are exclusive options", argv[i]);
00664 return SOAR_ERROR;
00665 } else {
00666 seen_long_or_short = TRUE;
00667 soar_cSetChunkNameLong(TRUE);
00668 }
00669
00670 } else if (string_match_up_to(argv[i], "-prefix", 2)) {
00671 if ((i + 1 >= argc) || (*argv[i + 1] == '-'))
00672 print("%s\n", current_agent(chunk_name_prefix));
00673
00674 else if (soar_cSetChunkNamePrefix(argv[++i]) == SOAR_ERROR) {
00675 setSoarResultResult(res, "Prefix-string contains illegal characters.");
00676 return SOAR_ERROR;
00677 }
00678
00679 } else if (string_match_up_to(argv[i], "-count", 2)) {
00680 if ((i + 1 >= argc) || (*argv[i + 1] == '-'))
00681 print("%lu\n", current_agent(chunk_count));
00682 else if (sscanf(argv[i + 1], "%lu", &tmp_chunk_count) == 1) {
00683 i++;
00684
00685 if (soar_cSetChunkNameCount(tmp_chunk_count))
00686 setSoarResultResult(res, "chunk-name-format: couldn't do that");
00687 return SOAR_ERROR;
00688
00689 } else {
00690 setSoarResultResult(res, "chunk-name-format: expected number after -count; got \"%s\"", argv[i]);
00691 return SOAR_ERROR;
00692 }
00693 } else {
00694 setSoarResultResult(res, "Unrecognized argument: %s", argv[i]);
00695 return SOAR_ERROR;
00696 }
00697 }
00698 clearSoarResultResult(res);
00699 return SOAR_OK;
00700 }
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712 #define SOAR_LEARN_BUFF_SIZE 1024
00713 int soar_Learn(int argc, const char *argv[], soarResult * res)
00714 {
00715
00716 if (argc == 1) {
00717 print_current_learn_settings();
00718 clearSoarResultResult(res);
00719 return SOAR_OK;
00720 }
00721
00722 {
00723 int i;
00724
00725 for (i = 1; i < argc; i++) {
00726 if (string_match("-on", argv[i]))
00727 soar_cSetLearning(ON);
00728 else if (string_match_up_to("-only", argv[i], 3))
00729 soar_cSetLearning(ONLY);
00730 else if (string_match_up_to("-except", argv[i], 2))
00731 soar_cSetLearning(EXCEPT);
00732 else if (string_match_up_to("-off", argv[i], 3))
00733 soar_cSetLearning(OFF);
00734 else if (string_match_up_to("-all-levels", argv[i], 2))
00735 soar_cSetLearning(ALL_LEVELS);
00736 else if (string_match_up_to("-bottom-up", argv[i], 2))
00737 soar_cSetLearning(BOTTOM_UP);
00738 else if (string_match_up_to("-list", argv[i], 2)) {
00739 cons *c;
00740 char buff[SOAR_LEARN_BUFF_SIZE];
00741
00742 print_current_learn_settings();
00743 setSoarResultResult(res, "force-learn states (when learn = -only):\n");
00744 for (c = current_agent(chunky_problem_spaces); c != NIL; c = c->rest) {
00745 symbol_to_string((Symbol *) (c->first), TRUE, buff, SOAR_LEARN_BUFF_SIZE);
00746 appendSoarResultResult(res, buff);
00747 }
00748 appendSoarResultResult(res, "\ndont-learn states (when learn = -except):\n");
00749 for (c = current_agent(chunk_free_problem_spaces); c != NIL; c = c->rest) {
00750 symbol_to_string((Symbol *) (c->first), TRUE, buff, SOAR_LEARN_BUFF_SIZE);
00751 appendSoarResultResult(res, buff);
00752 }
00753 return SOAR_OK;
00754 } else {
00755 setSoarResultResult(res, "Unrecognized argument to learn command: %s", argv[i]);
00756 return SOAR_ERROR;
00757 }
00758 }
00759 }
00760 clearSoarResultResult(res);
00761 return SOAR_OK;
00762 }
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772 int soar_MaxElaborations(int argc, const char *argv[], soarResult * res)
00773 {
00774 int num;
00775
00776 if (argc == 1) {
00777 setSoarResultResult(res, "%ld", current_agent(sysparams)[MAX_ELABORATIONS_SYSPARAM]);
00778 return SOAR_OK;
00779 }
00780
00781 if (argc > 2) {
00782 setSoarResultResult(res, "Too many arguments, should be: max-elaborations [integer]");
00783 return SOAR_ERROR;
00784 }
00785
00786 if (getInt(argv[1], &num) == SOAR_OK) {
00787 set_sysparam(MAX_ELABORATIONS_SYSPARAM, num);
00788 } else {
00789 setSoarResultResult(res, "Expected integer for new maximum elaborations count: %s", argv[1]);
00790 return SOAR_ERROR;
00791 }
00792 clearSoarResultResult(res);
00793 return SOAR_OK;
00794 }
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804 int soar_MaxChunks(int argc, const char *argv[], soarResult * res)
00805 {
00806 int num;
00807
00808 if (argc == 1) {
00809 setSoarResultResult(res, "%ld", current_agent(sysparams)[MAX_CHUNKS_SYSPARAM]);
00810 return SOAR_OK;
00811 }
00812
00813 if (argc > 2) {
00814 setSoarResultResult(res, "Too many arguments, should be: max-chunks [integer]");
00815 return SOAR_ERROR;
00816 }
00817
00818 if (getInt(argv[1], &num) == SOAR_OK) {
00819 set_sysparam(MAX_CHUNKS_SYSPARAM, num);
00820 } else {
00821 setSoarResultResult(res, "Expected integer for new maximum chunks count: %s", argv[1]);
00822 return SOAR_OK;
00823 }
00824
00825 clearSoarResultResult(res);
00826 return SOAR_OK;
00827 }
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838 #define SOAR_OPERAND2_BUFFER_SIZE 1024
00839 int soar_Operand2(int argc, const char *argv[], soarResult * res)
00840 {
00841
00842 #ifndef SOAR_8_ONLY
00843 char buffer[SOAR_OPERAND2_BUFFER_SIZE];
00844 bool turnOn;
00845
00846 if (argc == 1) {
00847 setSoarResultResult(res, "Soar8 Mode is %s", (current_agent(operand2_mode) == TRUE) ? "ON" : "OFF");
00848 return SOAR_OK;
00849 }
00850
00851 if (argc != 2) {
00852 setSoarResultResult(res, "argument should be -on|-off\n");
00853 return SOAR_ERROR;
00854 }
00855
00856 if (string_match("-on", argv[1]))
00857 turnOn = TRUE;
00858 else if (string_match("-off", argv[1]))
00859 turnOn = FALSE;
00860 else {
00861 setSoarResultResult(res, "unrecognized argument, should be -on|-off\n");
00862 return SOAR_ERROR;
00863 }
00864
00865 if (!soar_cSetOperand2(turnOn)) {
00866
00867 if (turnOn) {
00868
00869 #if MICRO_VERSION_NUMBER > 0
00870 snprintf(buffer, SOAR_OPERAND2_BUFFER_SIZE,
00871 "Soar%d.%d.%d %s on : reinitializing Soar",
00872 MAJOR_VERSION_NUMBER, MINOR_VERSION_NUMBER, MICRO_VERSION_NUMBER, OPERAND2_MODE_NAME);
00873 buffer[SOAR_OPERAND2_BUFFER_SIZE - 1] = 0;
00874 #else
00875 snprintf(buffer, SOAR_OPERAND2_BUFFER_SIZE,
00876 "Soar%d.%d %s on : reinitializing Soar",
00877 MAJOR_VERSION_NUMBER, MINOR_VERSION_NUMBER, OPERAND2_MODE_NAME);
00878 buffer[SOAR_OPERAND2_BUFFER_SIZE - 1] = 0;
00879 #endif
00880
00881 } else {
00882
00883 #if MICRO_VERSION_NUMBER > 0
00884 snprintf(buffer, SOAR_OPERAND2_BUFFER_SIZE,
00885 "Soar%d.%d.%d - running in Soar7 mode: reinitializing Soar",
00886 MAJOR_VERSION_NUMBER, MINOR_VERSION_NUMBER, MICRO_VERSION_NUMBER);
00887 buffer[SOAR_OPERAND2_BUFFER_SIZE - 1] = 0;
00888 #else
00889 snprintf(buffer, SOAR_OPERAND2_BUFFER_SIZE,
00890 "Soar%d.%d - running in Soar7 mode: reinitializing Soar",
00891 MAJOR_VERSION_NUMBER, MINOR_VERSION_NUMBER);
00892 buffer[SOAR_OPERAND2_BUFFER_SIZE - 1] = 0;
00893 #endif
00894
00895 }
00896 print("%s\n", buffer);
00897 return SOAR_OK;
00898 }
00899 setSoarResultResult(res, "Failed to set Operand2 Mode");
00900 return SOAR_ERROR;
00901
00902 #else
00903
00904 if (argc == 1) {
00905 setSoarResultResult(res, "Soar8 Mode is ON");
00906 return SOAR_OK;
00907 }
00908
00909 if (argc == 2 && string_match(argv[2], "-on")) {
00910 setSoarResultResult(res, "Soar8 Mode is already ON");
00911 return SOAR_OK;
00912 } else {
00913 setSoarResultResult(res, "Soar8 Mode must remain on in this build");
00914 return SOAR_ERROR;
00915 }
00916
00917 #endif
00918
00919 }
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932 int soar_WaitSNC(int argc, const char *argv[], soarResult * res)
00933 {
00934
00935 if (argc == 1) {
00936 print("waitsnc is %s\n\n", (current_agent(waitsnc) == TRUE) ? "ON" : "OFF");
00937 return SOAR_OK;
00938 }
00939
00940 {
00941 int i;
00942
00943 for (i = 1; i < argc; i++) {
00944 if (string_match("-on", argv[i])) {
00945 soar_cSetWaitSNC(TRUE);
00946 print("waitsnc is ON\n\n");
00947 }
00948
00949 else if (string_match_up_to("-off", argv[i], 3)) {
00950 soar_cSetWaitSNC(FALSE);
00951 print("waitsnc is OFF\n\n");
00952
00953 } else {
00954 setSoarResultResult(res, "Unrecognized argument to the WaitSNC command: %s", argv[i]);
00955 return SOAR_ERROR;
00956 }
00957 }
00958 }
00959
00960 return SOAR_OK;
00961 }
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973 int soar_InputPeriod(int argc, const char *argv[], soarResult * res)
00974 {
00975 int period;
00976
00977 if (argc == 1) {
00978 setSoarResultResult(res, "%d", soar_cGetInputPeriod());
00979 return SOAR_OK;
00980 }
00981
00982 if (argc > 2) {
00983 setSoarResultResult(res, "Too many arguments, should be: input-period [integer]");
00984 return SOAR_ERROR;
00985 }
00986
00987 if (getInt(argv[1], &period) == SOAR_OK) {
00988
00989 if (soar_cSetInputPeriod(period) < 0) {
00990 setSoarResultResult(res, "Integer for new input period must be >= 0, not %s", argv[1]);
00991 return SOAR_ERROR;
00992 }
00993 } else {
00994 setSoarResultResult(res, "Expected integer for new input period: %s", argv[1]);
00995 return SOAR_ERROR;
00996 }
00997
00998 clearSoarResultResult(res);
00999 return SOAR_OK;
01000
01001 }
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011 int soar_MultiAttributes(int argc, const char *argv[], soarResult * res)
01012 {
01013 int num;
01014
01015 if (argc == 1) {
01016 print_multi_attribute_symbols();
01017 clearSoarResultResult(res);
01018 return SOAR_OK;
01019 }
01020
01021 if (argc > 3) {
01022 setSoarResultResult(res, "Too many arguments, should be: multi-attribute [symbol] [value]");
01023 return SOAR_ERROR;
01024 }
01025
01026 if (argc < 3) {
01027
01028 if (soar_cMultiAttributes(argv[1], 10) == -1) {
01029 setSoarResultResult(res, "Expected symbolic constant for symbol but got: %s", argv[1]);
01030 return SOAR_ERROR;
01031 }
01032 } else {
01033 if (getInt(argv[2], &num) != SOAR_OK) {
01034 setSoarResultResult(res, "Non-integer given for attribute count: %s", argv[2]);
01035 return SOAR_ERROR;
01036 } else if (soar_cMultiAttributes(argv[1], num) != 0) {
01037
01038 setSoarResultResult(res, "Invalid arguments. Usage: multi-attributes <attr> <val>");
01039 return SOAR_ERROR;
01040 }
01041
01042 }
01043 clearSoarResultResult(res);
01044 return SOAR_OK;
01045 }
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055 int soar_NumericIndifferentMode(int argc, const char *argv[], soarResult * res)
01056 {
01057
01058 if (argc > 2) {
01059 setSoarResultResult(res, "Too many arguments.\nUsage: numeric-indifferent-mode -sum | -avg");
01060 return SOAR_ERROR;
01061 }
01062
01063 if (argc == 2) {
01064 if (string_match_up_to("-sum", argv[1], 2)) {
01065 current_agent(numeric_indifferent_mode) = NUMERIC_INDIFFERENT_MODE_SUM;
01066 } else if (string_match_up_to("-avg", argv[1], 2)) {
01067 current_agent(numeric_indifferent_mode) = NUMERIC_INDIFFERENT_MODE_AVG;
01068 } else {
01069 setSoarResultResult(res,
01070 "Unrecognized argument to %s: %s. either '-avg' or '-sum' was expected.",
01071 argv[0], argv[1]);
01072 return SOAR_ERROR;
01073 }
01074 }
01075
01076 switch (current_agent(numeric_indifferent_mode)) {
01077 case NUMERIC_INDIFFERENT_MODE_SUM:
01078 setSoarResultResult(res, "-sum");
01079 break;
01080 case NUMERIC_INDIFFERENT_MODE_AVG:
01081 setSoarResultResult(res, "-avg");
01082 break;
01083 default:
01084 setSoarResultResult(res, "???");
01085 break;
01086 }
01087
01088 return SOAR_OK;
01089 }
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099 int soar_OSupportMode(int argc, const char *argv[], soarResult * res)
01100 {
01101
01102 if (argc > 2) {
01103 setSoarResultResult(res, "Too many arguments.\nUsage: o-support-mode 0|1|2|3");
01104 return SOAR_ERROR;
01105 }
01106
01107 if (argc == 2) {
01108 if (!strcmp(argv[1], "0")) {
01109 current_agent(o_support_calculation_type) = 0;
01110 } else if (!strcmp(argv[1], "1")) {
01111 current_agent(o_support_calculation_type) = 1;
01112 } else if (!strcmp(argv[1], "2")) {
01113 current_agent(o_support_calculation_type) = 2;
01114 } else if (!strcmp(argv[1], "3")) {
01115 current_agent(o_support_calculation_type) = 3;
01116 } else if (!strcmp(argv[1], "4")) {
01117 current_agent(o_support_calculation_type) = 4;
01118 } else {
01119 setSoarResultResult(res,
01120 "Unrecognized argument to %s: %s. Integer 0, 1, 2, or 3 expected.", argv[0], argv[1]);
01121 return SOAR_ERROR;
01122 }
01123 }
01124
01125 setSoarResultResult(res, "%d", current_agent(o_support_calculation_type));
01126 return SOAR_OK;
01127 }
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139 int soar_ExplainBacktraces(int argc, const char *argv[], soarResult * res)
01140 {
01141
01142 if (argc == 1) {
01143 explain_list_chunks();
01144 clearSoarResultResult(res);
01145 return SOAR_OK;
01146 }
01147
01148 {
01149 int cond_num;
01150
01151 get_lexeme_from_string(argv[1]);
01152
01153 if (current_agent(lexeme).type == SYM_CONSTANT_LEXEME) {
01154 if (argc > 2) {
01155 if (string_match("-full", argv[2])) {
01156
01157
01158 soar_ecExplainChunkTrace(current_agent(lexeme.string));
01159 } else if (getInt(argv[2], &cond_num) == SOAR_OK) {
01160
01161
01162 soar_ecExplainChunkCondition(current_agent(lexeme.string), cond_num);
01163 } else {
01164 setSoarResultResult(res,
01165 "Unexpected argument to %s %s: %s. Should be -full or integer.",
01166 argv[0], argv[1], argv[2]);
01167 return SOAR_ERROR;
01168 }
01169 } else {
01170
01171
01172 soar_ecExplainChunkConditionList(current_agent(lexeme.string));
01173 }
01174 } else {
01175 setSoarResultResult(res,
01176 "Unexpected argument to %s: %s. Should be symbolic constant or integer.",
01177 argv[0], argv[1]);
01178 return SOAR_ERROR;
01179 }
01180 }
01181 clearSoarResultResult(res);
01182 return SOAR_OK;
01183 }
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193 int soar_FiringCounts(int argc, const char *argv[], soarResult * res)
01194 {
01195 int num_requested = 0;
01196
01197 res = res;
01198
01199 if (argc > 1) {
01200 if (getInt(argv[1], &num_requested) != SOAR_OK) {
01201 int i;
01202
01203 for (i = 1; i < argc; i++) {
01204 soar_ecPrintFiringsForProduction(argv[i]);
01205 }
01206
01207 return SOAR_OK;
01208 }
01209 }
01210
01211 soar_ecPrintTopProductionFirings((argc == 1) ? 20 : num_requested);
01212 return SOAR_OK;
01213
01214 }
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224 int soar_FormatWatch(int argc, const char *argv[], soarResult * res)
01225 {
01226 static char *too_few_args =
01227 "Too few arguments.\nUsage: format-watch {-object | -stack} [{{ -add {s|o|*} [name] \"format\" }|{-remove {s|o|*} [name]}}]";
01228 static char *too_many_args =
01229 "Too many arguments.\nUsage: format-watch {-object | -stack} [{{ -add {s|o|*} [name] \"format\" }|{-remove {s|o|*} [name]}}]";
01230
01231 bool stack_trace;
01232 int type_restriction;
01233 Symbol *name_restriction = NIL;
01234 bool remove;
01235 int format_arg = 0;
01236
01237 if (argc == 1) {
01238 setSoarResultResult(res, too_few_args);
01239 return SOAR_ERROR;
01240 }
01241
01242
01243 if (string_match("-stack", argv[1])) {
01244 stack_trace = TRUE;
01245 } else if (string_match("-object", argv[1])) {
01246 stack_trace = FALSE;
01247 } else {
01248 setSoarResultResult(res, "Unrecognized option to format-watch : %s", argv[1]);
01249 return SOAR_ERROR;
01250 }
01251
01252
01253
01254 if (argc == 2) {
01255 print_all_trace_formats(stack_trace);
01256 clearSoarResultResult(res);
01257 return SOAR_OK;
01258 }
01259
01260
01261 if (string_match("-add", argv[2])) {
01262 remove = FALSE;
01263 } else if (string_match("-remove", argv[2])) {
01264 remove = TRUE;
01265 } else {
01266 setSoarResultResult(res, "Unrecognized option to format-watch %s: %s", argv[1], argv[2]);
01267 return SOAR_ERROR;
01268 }
01269
01270 if (argc == 3) {
01271 setSoarResultResult(res, too_few_args);
01272 return SOAR_ERROR;
01273 }
01274
01275
01276
01277 if (string_match("s", argv[3])) {
01278 type_restriction = FOR_STATES_TF;
01279 } else if (string_match("o", argv[3])) {
01280 type_restriction = FOR_OPERATORS_TF;
01281 } else if (string_match("*", argv[3])) {
01282 type_restriction = FOR_ANYTHING_TF;
01283 } else {
01284 setSoarResultResult(res, "Unrecognized option to %s %s %s: %s", argv[0], argv[1], argv[2], argv[3]);
01285 return SOAR_ERROR;
01286 }
01287
01288 if (argc > 4) {
01289 get_lexeme_from_string(argv[4]);
01290
01291
01292 if (current_agent(lexeme).type == SYM_CONSTANT_LEXEME) {
01293 name_restriction = make_sym_constant(argv[4]);
01294 format_arg = 5;
01295 } else {
01296 format_arg = 4;
01297 }
01298
01299 if ((remove && (argc > format_arg))
01300 || (!remove && (argc > (format_arg + 1)))) {
01301 setSoarResultResult(res, too_many_args);
01302 return SOAR_ERROR;
01303 }
01304 }
01305
01306
01307 if (remove) {
01308 remove_trace_format(stack_trace, type_restriction, name_restriction);
01309 } else {
01310 if (argc == (format_arg + 1)) {
01311 add_trace_format(stack_trace, type_restriction, name_restriction, argv[format_arg]);
01312 } else {
01313 if (name_restriction) {
01314 symbol_remove_ref(name_restriction);
01315 }
01316
01317 setSoarResultResult(res, "Missing format string");
01318
01319 return SOAR_ERROR;
01320 }
01321 }
01322
01323 if (name_restriction) {
01324 symbol_remove_ref(name_restriction);
01325 }
01326
01327 clearSoarResultResult(res);
01328 return SOAR_OK;
01329 }
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342 int soar_IndifferentSelection(int argc, const char *argv[], soarResult * res)
01343 {
01344
01345 if (argc > 2) {
01346 setSoarResultResult(res,
01347 "Too many arguments, should be: indifferent-selection [-first | -last | -ask | -random ]");
01348 return SOAR_ERROR;
01349 }
01350 if (argc == 2) {
01351 if (string_match_up_to(argv[1], "-ask", 2)) {
01352 set_sysparam(USER_SELECT_MODE_SYSPARAM, USER_SELECT_ASK);
01353 } else if (string_match_up_to(argv[1], "-first", 2)) {
01354 set_sysparam(USER_SELECT_MODE_SYSPARAM, USER_SELECT_FIRST);
01355 } else if (string_match_up_to(argv[1], "-last", 2)) {
01356 set_sysparam(USER_SELECT_MODE_SYSPARAM, USER_SELECT_LAST);
01357 } else if (string_match_up_to(argv[1], "-random", 2)) {
01358 set_sysparam(USER_SELECT_MODE_SYSPARAM, USER_SELECT_RANDOM);
01359 } else {
01360 setSoarResultResult(res, "Unrecognized argument to indifferent-selection: %s", argv[1]);
01361 return SOAR_ERROR;
01362 }
01363 }
01364
01365 switch (current_agent(sysparams)[USER_SELECT_MODE_SYSPARAM]) {
01366
01367 case USER_SELECT_FIRST:
01368 setSoarResultResult(res, "-first");
01369 break;
01370 case USER_SELECT_LAST:
01371 setSoarResultResult(res, "-last");
01372 break;
01373 case USER_SELECT_ASK:
01374 setSoarResultResult(res, "-ask");
01375 break;
01376 case USER_SELECT_RANDOM:
01377 setSoarResultResult(res, "-random");
01378 break;
01379
01380 }
01381
01382 return SOAR_OK;
01383 }
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393 int soar_InternalSymbols(int argc, const char *argv[], soarResult * res)
01394 {
01395
01396 argv = argv;
01397
01398 if (argc > 1) {
01399 setSoarResultResult(res, "Too many arguments, should be: internal-symbols");
01400 return SOAR_ERROR;
01401 }
01402
01403 soar_ecPrintInternalSymbols();
01404
01405 clearSoarResultResult(res);
01406 return SOAR_OK;
01407 }
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417 int soar_Matches(int argc, const char *argv[], soarResult * res)
01418 {
01419 wme_trace_type wtt = NONE_WME_TRACE;
01420 ms_trace_type mst = MS_ASSERT_RETRACT;
01421 int curr_arg = 1;
01422 int prod_arg = 0;
01423
01424 while (curr_arg < argc) {
01425 if (string_match_up_to("-assertions", argv[curr_arg], 2)) {
01426 mst = MS_ASSERT;
01427 } else if (string_match_up_to("-retractions", argv[curr_arg], 2)) {
01428 mst = MS_RETRACT;
01429 } else if (string_match_up_to("-names", argv[curr_arg], 2)
01430 || string_match_up_to("-count", argv[curr_arg], 2)
01431 || string_match("0", argv[curr_arg])) {
01432 wtt = NONE_WME_TRACE;
01433 } else if (string_match_up_to("-timetags", argv[curr_arg], 2)
01434 || string_match("1", argv[curr_arg])) {
01435 wtt = TIMETAG_WME_TRACE;
01436 } else if (string_match_up_to("-wmes", argv[curr_arg], 2)
01437 || string_match("2", argv[curr_arg])) {
01438 wtt = FULL_WME_TRACE;
01439 } else {
01440 prod_arg = curr_arg;
01441 }
01442 curr_arg++;
01443 }
01444
01445 if (prod_arg) {
01446 if (soar_ecPrintMatchInfoForProduction(argv[prod_arg], wtt)) {
01447 setSoarResultResult(res, "There is no production named %s\n", argv[prod_arg]);
01448 return SOAR_ERROR;
01449 }
01450 } else {
01451 soar_ecPrintMatchSet(wtt, mst);
01452 }
01453 clearSoarResultResult(res);
01454 return SOAR_OK;
01455 }
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465 int soar_Memories(int argc, const char *argv[], soarResult * res)
01466 {
01467 int i;
01468 int num;
01469 int num_items = -1;
01470 int mems_to_print[NUM_PRODUCTION_TYPES];
01471 bool set_mems = FALSE;
01472 production *prod;
01473
01474 for (i = 0; i < NUM_PRODUCTION_TYPES; i++)
01475 mems_to_print[i] = FALSE;
01476
01477 for (i = 1; i < argc; i++) {
01478 if (string_match_up_to(argv[i], "-chunks", 2)) {
01479 mems_to_print[CHUNK_PRODUCTION_TYPE] = TRUE;
01480 set_mems = TRUE;
01481
01482 } else if (string_match_up_to(argv[i], "-user", 2)) {
01483 mems_to_print[USER_PRODUCTION_TYPE] = TRUE;
01484 set_mems = TRUE;
01485
01486 } else if (string_match_up_to(argv[i], "-defaults", 2)) {
01487 mems_to_print[DEFAULT_PRODUCTION_TYPE] = TRUE;
01488 set_mems = TRUE;
01489
01490 } else if (string_match_up_to(argv[i], "-justifications", 2)) {
01491 mems_to_print[JUSTIFICATION_PRODUCTION_TYPE] = TRUE;
01492 set_mems = TRUE;
01493
01494 } else {
01495 prod = name_to_production(argv[i]);
01496 if (prod) {
01497 print("\n Memory use for %s: %ld\n\n", argv[i], count_rete_tokens_for_production(prod));
01498 set_mems = TRUE;
01499
01500 } else if (getInt(argv[i], &num) == SOAR_OK) {
01501 if (num <= 0) {
01502 setSoarResultResult(res, "Count argument to memories must be a positive integer, not: %s", argv[i]);
01503 return SOAR_ERROR;
01504 } else {
01505 num_items = num;
01506 }
01507
01508 } else {
01509 setSoarResultResult(res, "Unrecognized argument to memories: %s", argv[i]);
01510 return SOAR_ERROR;
01511 }
01512 }
01513 }
01514
01515 if (!set_mems) {
01516 mems_to_print[JUSTIFICATION_PRODUCTION_TYPE] = TRUE;
01517 mems_to_print[CHUNK_PRODUCTION_TYPE] = TRUE;
01518 mems_to_print[USER_PRODUCTION_TYPE] = TRUE;
01519 mems_to_print[DEFAULT_PRODUCTION_TYPE] = TRUE;
01520 }
01521
01522
01523
01524
01525
01526
01527 soar_ecPrintMemories(num_items, mems_to_print);
01528 clearSoarResultResult(res);
01529 return SOAR_OK;
01530 }
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540 int soar_ProductionFind(int argc, const char *argv[], soarResult * res)
01541 {
01542 int i;
01543
01544 list *current_pf_list = NIL;
01545
01546 bool lhs = TRUE;
01547 bool rhs = FALSE;
01548 bool show_bindings = FALSE;
01549 bool just_chunks = FALSE;
01550 bool no_chunks = FALSE;
01551 bool clause_found = FALSE;
01552
01553 if (argc == 1) {
01554 setSoarResultResult(res,
01555 "No arguments given.\nUsage: production-find [-rhs|-lhs] [-chunks|-nochunks] [-show-bindings] {clauses}");
01556 return SOAR_ERROR;
01557 }
01558
01559
01560
01561
01562
01563 for (i = 1; i < argc; i++) {
01564 if (string_match_up_to(argv[i], "-lhs", 2)) {
01565 lhs = TRUE;
01566 } else if (string_match_up_to(argv[i], "-rhs", 2)) {
01567 rhs = TRUE;
01568 lhs = FALSE;
01569 } else if (string_match_up_to(argv[i], "-show-bindings", 2)) {
01570 show_bindings = TRUE;
01571 } else if (string_match_up_to(argv[i], "-chunks", 2)) {
01572 just_chunks = TRUE;
01573 } else if (string_match_up_to(argv[i], "-nochunks", 2)) {
01574 no_chunks = TRUE;
01575 } else if (strchr(argv[i], '(') != 0)
01576
01577 {
01578
01579 clause_found = TRUE;
01580 break;
01581 } else {
01582 setSoarResultResult(res, "Unrecognized argument to %s command: %s", argv[0], argv[i]);
01583 return SOAR_ERROR;
01584 }
01585 }
01586
01587 if (!clause_found) {
01588 setSoarResultResult(res,
01589 "No clause found.\nUsage: production-find [-rhs|-lhs] [-chunks|-nochunks] [-show-bindings] {clauses}");
01590 return SOAR_ERROR;
01591 }
01592
01593 if ((*argv[i] == '-') || (strchr(argv[i], '(') != 0)) {
01594 if (argc > i + 1) {
01595 setSoarResultResult(res,
01596 "Too many arguments given.\nUsage: production-find [-rhs|-lhs] [-chunks|-nochunks] [-show-bindings] {clauses}");
01597 return SOAR_ERROR;
01598 }
01599 if ((*argv[i] == '-') && (argc < i + 1)) {
01600 setSoarResultResult(res,
01601 "Too few arguments given.\nUsage: production-find [-rhs|-lhs] [-chunks|-nochunks] [-show-bindings] {clauses}");
01602 return SOAR_ERROR;
01603 }
01604 if (lhs) {
01605
01606
01607
01608 current_agent(alternate_input_string) = argv[i];
01609 current_agent(alternate_input_suffix) = ") ";
01610
01611
01612
01613
01614
01615
01616 get_lexeme();
01617 read_pattern_and_get_matching_productions(¤t_pf_list, show_bindings, just_chunks, no_chunks);
01618
01619 current_agent(current_char) = ' ';
01620 }
01621 if (rhs) {
01622
01623
01624
01625 current_agent(alternate_input_string) = argv[i];
01626 current_agent(alternate_input_suffix) = ") ";
01627
01628
01629
01630
01631
01632 get_lexeme();
01633 read_rhs_pattern_and_get_matching_productions(¤t_pf_list, show_bindings, just_chunks, no_chunks);
01634
01635 current_agent(current_char) = ' ';
01636
01637 }
01638 if (current_pf_list == NIL) {
01639 print("No matches.\n");
01640 }
01641
01642 free_list(current_pf_list);
01643 } else {
01644 setSoarResultResult(res, "Unknown argument to %s command: %s", argv[0], argv[i]);
01645 return SOAR_ERROR;
01646 }
01647
01648 clearSoarResultResult(res);
01649 return SOAR_OK;
01650 }
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661 #define SOAR_PREFERENCES_BUFF_SIZE 128
01662 int soar_Preferences(int argc, const char *argv[], soarResult * res)
01663 {
01664
01665 static char *too_many_args = "Too many arguments.\nUsage: preferences [id] [attribute] [detail]";
01666 static char *wrong_args = "Usage: preferences [id] [attribute] [detail]";
01667
01668 Symbol *id, *id_tmp, *attr, *attr_tmp;
01669 bool print_productions;
01670 wme_trace_type wtt;
01671 char buff1[SOAR_PREFERENCES_BUFF_SIZE];
01672 char buff2[SOAR_PREFERENCES_BUFF_SIZE];
01673
01674
01675 id = current_agent(bottom_goal);
01676 id_tmp = NIL;
01677 attr = current_agent(operator_symbol);
01678 attr_tmp = NIL;
01679 print_productions = FALSE;
01680 wtt = NONE_WME_TRACE;
01681
01682
01683 switch (argc) {
01684 case 1:
01685
01686 break;
01687 case 2:
01688
01689 if ((read_id_or_context_var_from_string(argv[1], &id_tmp)
01690 == SOAR_ERROR)
01691 && (read_attribute_from_string(id, argv[1], &attr_tmp)
01692 == SOAR_ERROR)
01693 && (read_pref_detail_from_string(argv[1], &print_productions, &wtt)
01694 == SOAR_ERROR)) {
01695 setSoarResultResult(res, wrong_args);
01696 return SOAR_ERROR;
01697 }
01698 break;
01699 case 3:
01700
01701 if (read_id_or_context_var_from_string(argv[1], &id_tmp) == SOAR_ERROR) {
01702 id_tmp = id;
01703 if (read_attribute_from_string(id, argv[1], &attr_tmp) == SOAR_ERROR) {
01704 setSoarResultResult(res, wrong_args);
01705 return SOAR_ERROR;
01706 }
01707 }
01708 if ((read_attribute_from_string(id_tmp, argv[2], &attr_tmp)
01709 == SOAR_ERROR)
01710 && (read_pref_detail_from_string(argv[2], &print_productions, &wtt)
01711 == SOAR_ERROR)) {
01712 setSoarResultResult(res, wrong_args);
01713 return SOAR_ERROR;
01714 }
01715 break;
01716
01717 case 4:
01718
01719 if ((read_id_or_context_var_from_string(argv[1], &id_tmp)
01720 == SOAR_ERROR)
01721 || (read_attribute_from_string(id_tmp, argv[2], &attr_tmp)
01722 == SOAR_ERROR)
01723 || (read_pref_detail_from_string(argv[3], &print_productions, &wtt)
01724 == SOAR_ERROR)) {
01725 setSoarResultResult(res, wrong_args);
01726 return SOAR_ERROR;
01727 }
01728 break;
01729 default:
01730
01731 setSoarResultResult(res, too_many_args);
01732 return SOAR_ERROR;
01733 break;
01734 }
01735
01736
01737
01738
01739 if (id_tmp != NIL)
01740 id = id_tmp;
01741 if (attr_tmp != NIL)
01742 attr = attr_tmp;
01743
01744 if (id == NIL) {
01745 clearSoarResultResult(res);
01746 return (SOAR_OK);
01747 }
01748
01749
01750
01751
01752
01753
01754 symbol_to_string(id, TRUE, buff1, SOAR_PREFERENCES_BUFF_SIZE);
01755 symbol_to_string(attr, TRUE, buff2, SOAR_PREFERENCES_BUFF_SIZE);
01756 if (soar_ecPrintPreferences(buff1, buff2, print_productions, wtt)) {
01757 setSoarResultResult(res, "An Error occured trying to print the prefs.");
01758 return SOAR_ERROR;
01759 }
01760 clearSoarResultResult(res);
01761 return SOAR_OK;
01762 }
01763
01764
01765
01766
01767
01768
01769
01770
01771
01772 int soar_Print(int argc, const char *argv[], soarResult * res)
01773 {
01774 static char *too_few_args = "Too few arguments.\nUsage: print [-depth n] [-internal] arg*";
01775
01776 bool internal;
01777 bool name_only, full_prod;
01778 bool output_arg;
01779 bool print_filename;
01780
01781 int depth;
01782 Symbol *id;
01783 wme *w;
01784 list *wmes;
01785 cons *c;
01786 int i, next_arg;
01787
01788 internal = FALSE;
01789 depth = current_agent(default_wme_depth);
01790 name_only = FALSE;
01791 full_prod = FALSE;
01792 print_filename = FALSE;
01793 output_arg = FALSE;
01794
01795 if (argc == 1) {
01796 setSoarResultResult(res, too_few_args);
01797 return SOAR_ERROR;
01798 }
01799
01800 clearSoarResultResult(res);
01801
01802 next_arg = 1;
01803
01804
01805 if (string_match_up_to("-stack", argv[next_arg], 4)) {
01806 bool print_states;
01807 bool print_operators;
01808
01809
01810
01811 if (argc == 2) {
01812 print_states = TRUE;
01813 print_operators = TRUE;
01814 } else {
01815 int i;
01816
01817 print_states = FALSE;
01818 print_operators = FALSE;
01819
01820 next_arg++;
01821 for (i = next_arg; i < argc; i++) {
01822 if (string_match_up_to(argv[i], "-states", 2))
01823 print_states = TRUE;
01824 else if (string_match_up_to(argv[i], "-operators", 2))
01825 print_operators = TRUE;
01826 else {
01827 setSoarResultResult(res,
01828 "Unknown option passed to print -stack: (%s).\nUsage print -stack [-state | -operator]*",
01829 argv[next_arg]);
01830 return SOAR_ERROR;
01831 }
01832 }
01833 }
01834
01835 {
01836 Symbol *g;
01837
01838 for (g = current_agent(top_goal); g != NIL; g = g->id.lower_goal) {
01839 if (print_states) {
01840 print_stack_trace(g, g, FOR_STATES_TF, FALSE);
01841 print("\n");
01842 }
01843 if (print_operators && g->id.operator_slot->wmes) {
01844 print_stack_trace(g->id.operator_slot->wmes->value, g, FOR_OPERATORS_TF, FALSE);
01845 print("\n");
01846 }
01847 }
01848 }
01849
01850 return SOAR_OK;
01851 }
01852
01853
01854
01855 while (next_arg < argc) {
01856
01857
01858 if (string_match_up_to("-depth", argv[next_arg], 4)) {
01859 if ((argc - next_arg) <= 1) {
01860 setSoarResultResult(res, too_few_args);
01861 return SOAR_ERROR;
01862 } else {
01863 if (getInt(argv[++next_arg], &depth) != SOAR_OK) {
01864 setSoarResultResult(res, "Integer expected after %s, not %s.", argv[next_arg - 1], argv[next_arg]);
01865 return SOAR_ERROR;
01866 }
01867 }
01868 }
01869
01870
01871 else if (string_match_up_to("-internal", argv[next_arg], 2)) {
01872 internal = TRUE;
01873 }
01874
01875
01876
01877
01878 else if (string_match_up_to("-filename", argv[next_arg], 2)) {
01879 print_filename = TRUE;
01880 }
01881
01882
01883
01884 else if (string_match_up_to("-name", argv[next_arg], 2)) {
01885 name_only = TRUE;
01886 full_prod = FALSE;
01887 }
01888
01889 else if (string_match_up_to("-full", argv[next_arg], 2)) {
01890 full_prod = TRUE;
01891 name_only = FALSE;
01892 } else if (string_match_up_to("-all", argv[next_arg], 2)) {
01893 output_arg = TRUE;
01894 for (i = 0; i < NUM_PRODUCTION_TYPES; i++) {
01895 soar_ecPrintAllProductionsOfType(i, internal, print_filename, full_prod);
01896 }
01897 } else if (string_match_up_to("-defaults", argv[next_arg], 4)) {
01898 output_arg = TRUE;
01899
01900
01901
01902 soar_ecPrintAllProductionsOfType(DEFAULT_PRODUCTION_TYPE, internal, print_filename, full_prod);
01903
01904 } else if (string_match_up_to("-user", argv[next_arg], 2)) {
01905 output_arg = TRUE;
01906 soar_ecPrintAllProductionsOfType(USER_PRODUCTION_TYPE, internal, print_filename, full_prod);
01907 } else if (string_match_up_to("-chunks", argv[next_arg], 2)) {
01908 output_arg = TRUE;
01909 soar_ecPrintAllProductionsOfType(CHUNK_PRODUCTION_TYPE, internal, print_filename, full_prod);
01910 } else if (string_match_up_to("-justifications", argv[next_arg], 2)) {
01911 output_arg = TRUE;
01912 soar_ecPrintAllProductionsOfType(JUSTIFICATION_PRODUCTION_TYPE, internal, print_filename, full_prod);
01913 } else if (string_match_up_to("-", argv[next_arg], 1)) {
01914 setSoarResultResult(res, "Unrecognized option to print command: %s", argv[next_arg]);
01915 return SOAR_ERROR;
01916 } else {
01917
01918 get_lexeme_from_string(argv[next_arg]);
01919
01920 switch (current_agent(lexeme).type) {
01921 case SYM_CONSTANT_LEXEME:
01922 output_arg = TRUE;
01923 if (!name_only || print_filename) {
01924
01925 do_print_for_production_name(argv[next_arg], internal, print_filename, full_prod);
01926 } else {
01927 print("%s\n", argv[next_arg]);
01928 }
01929 break;
01930
01931 case INT_CONSTANT_LEXEME:
01932 output_arg = TRUE;
01933 for (w = current_agent(all_wmes_in_rete); w != NIL; w = w->rete_next)
01934
01935 if (w->timetag == (unsigned long) current_agent(lexeme).int_val)
01936 break;
01937
01938
01939 if (w) {
01940 do_print_for_wme(w, depth, internal);
01941 } else {
01942 setSoarResultResult(res, "No wme %ld in working memory", current_agent(lexeme).int_val);
01943 return SOAR_ERROR;
01944 }
01945 break;
01946
01947 case IDENTIFIER_LEXEME:
01948 case VARIABLE_LEXEME:
01949
01950 output_arg = TRUE;
01951 id = read_identifier_or_context_variable();
01952 if (id)
01953 do_print_for_identifier(id, depth, internal);
01954 break;
01955
01956 case QUOTED_STRING_LEXEME:
01957 output_arg = TRUE;
01958
01959 soar_alternate_input(soar_agent, argv[next_arg], ") ", TRUE);
01960
01961
01962
01963
01964 get_lexeme();
01965 wmes = read_pattern_and_get_matching_wmes();
01966 soar_alternate_input(soar_agent, NIL, NIL, FALSE);
01967 current_agent(current_char) = ' ';
01968 for (c = wmes; c != NIL; c = c->rest)
01969 do_print_for_wme(c->first, depth, internal);
01970 free_list(wmes);
01971 break;
01972
01973 default:
01974 setSoarResultResult(res, "Unrecognized argument to %s command: %s", argv[0], argv[next_arg]);
01975 return SOAR_ERROR;
01976 }
01977 output_arg = TRUE;
01978 }
01979 next_arg++;
01980 }
01981
01982
01983 if (!output_arg) {
01984 setSoarResultResult(res, too_few_args);
01985 return SOAR_ERROR;
01986 } else
01987 return SOAR_OK;
01988
01989 }
01990
01991
01992
01993
01994
01995
01996
01997
01998
01999 #ifndef TRACE_CONTEXT_DECISIONS_ONLY
02000
02001 int soar_PWatch(int argc, const char *argv[], soarResult * res)
02002 {
02003 bool trace_productions = TRUE;
02004 int next_arg = 1;
02005
02006 clearSoarResultResult(res);
02007 if (argc == 1) {
02008 cons *c;
02009
02010 for (c = current_agent(productions_being_traced); c != NIL; c = c->rest)
02011 print_with_symbols(" %y\n", ((production *) (c->first))->name);
02012
02013 return SOAR_OK;
02014 }
02015
02016
02017
02018 if (string_match_up_to(argv[1], "-on", 3)) {
02019 trace_productions = TRUE;
02020 next_arg++;
02021 }
02022 if (string_match_up_to(argv[1], "-off", 3)) {
02023 trace_productions = FALSE;
02024 next_arg++;
02025 }
02026
02027 if ((argc == 2) && (next_arg != 1)) {
02028
02029
02030 if (trace_productions) {
02031
02032 soar_ecPrintProductionsBeingTraced();
02033 return SOAR_OK;
02034 } else {
02035
02036 soar_ecStopAllProductionTracing();
02037 return SOAR_OK;
02038 }
02039 }
02040
02041
02042 {
02043
02044 if (trace_productions) {
02045 if (soar_ecBeginTracingProductions((argc - next_arg), &argv[next_arg])) {
02046 setSoarResultResult(res, "Could not begin tracing");
02047 return SOAR_ERROR;
02048 }
02049
02050 } else {
02051 if (soar_ecStopTracingProductions((argc - next_arg), &argv[next_arg])) {
02052 setSoarResultResult(res, "Could not stop tracing");
02053 return SOAR_ERROR;
02054 }
02055 }
02056
02057 return SOAR_OK;
02058 }
02059
02060 }
02061
02062 #endif
02063
02064 #ifdef USE_DEBUG_UTILS
02065
02066
02067 #define TLD 4
02068
02069 int soar_Pool(int argc, const char *argv[], soarResult * res)
02070 {
02071
02072 bool print_free;
02073 int pool_arg;
02074
02075 if (argc < 2) {
02076 setSoarResultResult(res, "Need more arguments.");
02077 return SOAR_ERROR;
02078 }
02079
02080 if (argc < 3) {
02081 print_free = FALSE;
02082 pool_arg = 1;
02083 } else {
02084 if (string_match("-all", argv[1])) {
02085 pool_arg = 2;
02086 print_free = TRUE;
02087 } else {
02088 setSoarResultResult(res, "Bad args.");
02089 return SOAR_ERROR;
02090 }
02091 }
02092
02093 if (string_match_up_to("-wme", argv[pool_arg], TLD)) {
02094 examine_memory_pool(¤t_agent(wme_pool));
02095 print_all_wmes_in_block(0, print_free);
02096 } else if (string_match_up_to("-condition", argv[pool_arg], TLD)) {
02097 examine_memory_pool(¤t_agent(condition_pool));
02098 print_all_conditions_in_block(0, print_free);
02099 } else if (string_match_up_to("-preference", argv[pool_arg], TLD)) {
02100 examine_memory_pool(¤t_agent(preference_pool));
02101 print_all_preferences_in_block(0, print_free);
02102
02103 } else if (string_match_up_to("-instantiation", argv[pool_arg], TLD)) {
02104 examine_memory_pool(¤t_agent(instantiation_pool));
02105
02106 if (argc < (pool_arg + 1)) {
02107 setSoarResultResult(res, "Need more arguments for -instantiation. Either -none|-full");
02108 return SOAR_ERROR;
02109 }
02110 if (string_match_up_to("-none", argv[pool_arg + 1], 2)) {
02111 print_all_instantiations_in_block(0, NONE_WME_TRACE, print_free);
02112 } else if (string_match_up_to("-full", argv[pool_arg + 1], 2)) {
02113 print_all_instantiations_in_block(0, FULL_WME_TRACE, print_free);
02114
02115 }
02116 } else if (string_match_up_to("-identifier", argv[pool_arg], TLD)) {
02117 examine_memory_pool(¤t_agent(identifier_pool));
02118 print_all_identifiers_in_block(0, print_free);
02119 } else if (string_match_up_to("-production", argv[pool_arg], TLD)) {
02120 examine_memory_pool(¤t_agent(production_pool));
02121
02122 if (argc < (pool_arg + 1)) {
02123 setSoarResultResult(res, "Need more arguments for -production. Either -name|-full");
02124 return SOAR_ERROR;
02125 }
02126 if (string_match_up_to("-name", argv[pool_arg + 1], 2)) {
02127 print_all_productions_in_block(0, FALSE, print_free);
02128 } else if (string_match_up_to("-full", argv[pool_arg + 1], 2)) {
02129 print_all_productions_in_block(0, TRUE, print_free);
02130
02131 } else {
02132 setSoarResultResult(res, "Argument for -production must be either -name|-full");
02133 return SOAR_ERROR;
02134 }
02135 }
02136
02137 else {
02138 setSoarResultResult(res, "Don't know what to do with your arg: %s", argv[pool_arg]);
02139 return SOAR_ERROR;
02140 }
02141 clearSoarResultResult(res);
02142 return SOAR_OK;
02143 }
02144
02145 #endif
02146
02147
02148
02149
02150
02151
02152
02153
02154
02155 int soar_Sp(int argc, const char *argv[], soarResult * res)
02156 {
02157
02158 if (argc == 1) {
02159 setSoarResultResult(res, "Too few arguments.\nUsage: sp {rule} sourceFile.");
02160 return SOAR_ERROR;
02161 }
02162
02163 if (argc > 3) {
02164 setSoarResultResult(res, "Too many arguments.\nUsage: sp {rule} sourceFile.");
02165 return SOAR_ERROR;
02166 }
02167
02168 if (argc == 2)
02169 soar_ecSp(argv[1], NULL);
02170 else
02171 soar_ecSp(argv[1], argv[2]);
02172
02173
02174 clearSoarResultResult(res);
02175 return SOAR_OK;
02176 }
02177
02178
02179
02180
02181
02182
02183
02184
02185
02186 int soar_Stats(int argc, const char *argv[], soarResult * res)
02187 {
02188
02189 if ((argc == 1)
02190 || string_match_up_to("-system", argv[1], 2)) {
02191 return parse_system_stats(argc, argv, res);
02192 } else if (string_match_up_to("-memory", argv[1], 2)) {
02193 return parse_memory_stats(argc, argv, res);
02194 } else if (string_match_up_to("-rete", argv[1], 2)) {
02195 return parse_rete_stats(argc, argv, res);
02196 }
02197 #ifdef DC_HISTOGRAM
02198 else if (string_match_up_to("-dc_histogram", argv[1], 2)) {
02199 return soar_ecPrintDCHistogram();
02200 }
02201 #endif
02202 #ifdef KT_HISTOGRAM
02203 else if (string_match_up_to("-kt_histogram", argv[1], 2)) {
02204 return soar_ecPrintKTHistogram();
02205 }
02206 #endif
02207 #ifndef NO_TIMING_STUFF
02208 else if (string_match_up_to("-timers", argv[1], 2)) {
02209 return printTimingInfo();
02210 }
02211 #endif
02212 else {
02213 setSoarResultResult(res, "Unrecognized argument to stats: %s", argv[1]);
02214 return SOAR_ERROR;
02215 }
02216 }
02217
02218
02219
02220
02221
02222
02223
02224
02225
02226 int soar_Stop(int argc, const char *argv[], soarResult * res)
02227 {
02228 const char *reason;
02229
02230 if (argc > 3) {
02231 setSoarResultResult(res, "Too many arguments, should be:\n\t stop-soar [-s[elf] {reason_string}");
02232
02233 return SOAR_ERROR;
02234 }
02235
02236 if (argc == 1) {
02237 soar_cStopAllAgents();
02238 } else if (string_match_up_to("-self", argv[1], 1)) {
02239
02240 if (argc == 3)
02241 reason = argv[2];
02242 else
02243 reason = NIL;
02244
02245 soar_cStopCurrentAgent(reason);
02246
02247 } else {
02248 setSoarResultResult(res, "Unrecognized argument to stop-soar: %s", argv[1]);
02249 return SOAR_ERROR;
02250 }
02251 clearSoarResultResult(res);
02252 return SOAR_OK;
02253 }
02254
02255
02256
02257
02258
02259
02260
02261
02262
02263 int soar_Verbose(int argc, const char *argv[], soarResult * res)
02264 {
02265 int i;
02266
02267 clearSoarResultResult(res);
02268 if (argc == 1) {
02269 print("VERBOSE is %s\n\n", (soar_cGetVerbosity() == TRUE) ? "ON" : "OFF");
02270 return SOAR_OK;
02271 }
02272
02273 for (i = 1; i < argc; i++) {
02274 if (string_match("-on", argv[i])) {
02275 soar_cSetVerbosity(TRUE);
02276 print("VERBOSE is %s\n\n", (soar_cGetVerbosity() == TRUE) ? "ON" : "OFF");
02277 }
02278
02279 else if (string_match_up_to("-off", argv[i], 3)) {
02280 soar_cSetVerbosity(FALSE);
02281 print("VERBOSE is %s\n\n", (soar_cGetVerbosity() == TRUE) ? "ON" : "OFF");
02282 } else {
02283 setSoarResultResult(res, "Unrecognized argument to the VERBOSE command: %s", argv[i]);
02284 return SOAR_ERROR;
02285 }
02286 }
02287
02288 return SOAR_OK;
02289 }
02290
02291
02292
02293
02294
02295
02296
02297
02298
02299
02300
02301 int soar_Warnings(int argc, const char *argv[], soarResult * res)
02302 {
02303
02304 if (argc == 1) {
02305 setSoarResultResult(res, "%s", current_agent(sysparams)[PRINT_WARNINGS_SYSPARAM]
02306 ? "on" : "off");
02307 return SOAR_OK;
02308 }
02309
02310 if (argc > 2) {
02311 setSoarResultResult(res, "Too many arguments, should be: warnings [-on | -off]");
02312 return SOAR_ERROR;
02313 }
02314
02315 if (string_match_up_to(argv[1], "-on", 3)) {
02316 set_sysparam(PRINT_WARNINGS_SYSPARAM, TRUE);
02317 } else if (string_match_up_to(argv[1], "-off", 3)) {
02318 set_sysparam(PRINT_WARNINGS_SYSPARAM, FALSE);
02319 } else {
02320 setSoarResultResult(res, "Unrecognized option to warnings command: %s", argv[1]);
02321 return SOAR_ERROR;
02322 }
02323
02324 setSoarResultResult(res, "%s", current_agent(sysparams)[PRINT_WARNINGS_SYSPARAM]
02325 ? "on" : "off");
02326 return SOAR_OK;
02327 }
02328
02329
02330
02331
02332
02333
02334
02335
02336
02337 int soar_Log(int argc, const char *argv[], soarResult * res)
02338 {
02339 char *too_few =
02340 "Too few arguments, should be: log [-new | -existing] pathname | log -add string | log -query | log -off";
02341 char *too_many =
02342 "Too many arguments, should be: log [-new | -existing] pathname | log -add string | log -query | log -off";
02343
02344 if (argc < 2) {
02345 setSoarResultResult(res, "The log file is ");
02346
02347 if (soar_exists_callback(soar_agent, LOG_CALLBACK)) {
02348 appendSoarResultResult(res, "open. Use log -off to close the file.");
02349 } else {
02350 appendSoarResultResult(res, "closed.");
02351 }
02352
02353 return SOAR_OK;
02354 }
02355
02356 if (argc > 3) {
02357 setSoarResultResult(res, too_many);
02358 return SOAR_ERROR;
02359 }
02360
02361 if (string_match_up_to("-add", argv[1], 2)) {
02362 if (argc == 3) {
02363 soar_invoke_first_callback(soar_agent, LOG_CALLBACK, argv[2]);
02364 } else if (argc < 3) {
02365 setSoarResultResult(res, too_few);
02366 return SOAR_ERROR;
02367 } else {
02368 setSoarResultResult(res, too_many);
02369 return SOAR_ERROR;
02370 }
02371
02372 } else if (string_match_up_to("-query", argv[1], 2)) {
02373 if (argc == 2) {
02374 if (soar_exists_callback(soar_agent, LOG_CALLBACK)) {
02375 setSoarResultResult(res, "open");
02376 } else {
02377 setSoarResultResult(res, "closed");
02378 }
02379
02380 } else {
02381 setSoarResultResult(res, too_many);
02382 return SOAR_ERROR;
02383 }
02384
02385 } else if (string_match_up_to("-off", argv[1], 2)) {
02386 if (argc == 2) {
02387 if (soar_ecCloseLog() == 0) {
02388 setSoarResultResult(res, "log file closed");
02389 } else {
02390 setSoarResultResult(res, "Attempt to close non-existant log file");
02391 }
02392 } else if (argc > 2) {
02393 setSoarResultResult(res, too_many);
02394 return SOAR_ERROR;
02395 }
02396
02397 } else {
02398 const char *filename;
02399 char *mode;
02400
02401 if (argc == 2) {
02402 filename = argv[1];
02403 mode = "w";
02404 } else if (string_match_up_to("-new", argv[1], 2)) {
02405 filename = argv[2];
02406 mode = "w";
02407 } else if (string_match_up_to("-new", argv[2], 2)) {
02408 filename = argv[1];
02409 mode = "w";
02410 } else if (string_match_up_to("-existing", argv[1], 2)) {
02411 filename = argv[2];
02412 mode = "a";
02413 } else if (string_match_up_to("-existing", argv[2], 2)) {
02414 filename = argv[1];
02415 mode = "a";
02416 } else {
02417 setSoarResultResult(res, "log: unrecognized arguments: %s %s", argv[1], argv[2]);
02418 return SOAR_ERROR;
02419 }
02420
02421 if (soar_ecOpenLog(filename, mode) == 0) {
02422
02423 setSoarResultResult(res, "log file '%s' opened", filename);
02424
02425 } else {
02426 setSoarResultResult(res, "log: Error: unable to open '%s'", filename);
02427 return SOAR_ERROR;
02428 }
02429 }
02430
02431 return SOAR_OK;
02432 }
02433
02434
02435
02436
02437
02438
02439
02440
02441
02442 int soar_AttributePreferencesMode(int argc, const char *argv[], soarResult * res)
02443 {
02444
02445 int i;
02446
02447 if (argc > 2) {
02448 setSoarResultResult(res, "Too many arguments, expected single integer 0|1|2\n");
02449 return SOAR_ERROR;
02450 }
02451
02452 if (argc == 2) {
02453 if (getInt(argv[1], &i) == SOAR_ERROR) {
02454 setSoarResultResult(res, "Expected a single integer argument 0|1|2\n");
02455 return SOAR_ERROR;
02456 }
02457 switch (soar_cAttributePreferencesMode(i)) {
02458 case 0:
02459 return SOAR_OK;
02460
02461 case -1:
02462 setSoarResultResult(res, "Attribute Preferences Mode must be 2 when using Soar 8\n");
02463 return SOAR_ERROR;
02464
02465 case -2:
02466 setSoarResultResult(res, "Expected a single integer argument 0|1|2\n");
02467 return SOAR_ERROR;
02468 }
02469 return SOAR_ERROR;
02470
02471 }
02472
02473 setSoarResultResult(res, "%d", current_agent(attribute_preferences_mode));
02474 return SOAR_OK;
02475
02476 }
02477
02478
02479
02480
02481
02482
02483
02484
02485
02486 int soar_Watch(int argc, const char *argv[], soarResult * res)
02487 {
02488
02489 clearSoarResultResult(res);
02490 if (argc == 1) {
02491 print_current_watch_settings();
02492 }
02493
02494 {
02495 int i;
02496
02497 for (i = 1; i < argc; i++) {
02498 if (string_match("none", argv[i]) || string_match("0", argv[i])) {
02499 if (soar_ecWatchLevel(0)) {
02500 setSoarResultResultStdError(res);
02501 return SOAR_ERROR;
02502 }
02503 } else if (string_match("1", argv[i])) {
02504 if (soar_ecWatchLevel(1)) {
02505 return SOAR_ERROR;
02506 }
02507 } else if (string_match("decisions", argv[i])) {
02508
02509 if ((i + 1) < argc) {
02510 if ((string_match("-on", argv[i + 1])) ||
02511 (string_match("-off", argv[i + 1])) || (string_match_up_to("-inclusive", argv[i + 1], 3))) {
02512 if (set_watch_setting(TRACE_CONTEXT_DECISIONS_SYSPARAM, argv[i], argv[++i], res)
02513 != SOAR_OK) {
02514 return SOAR_ERROR;
02515 }
02516 } else {
02517
02518 if (soar_ecWatchLevel(1)) {
02519 return SOAR_ERROR;
02520 }
02521 }
02522 } else {
02523
02524 if (soar_ecWatchLevel(1)) {
02525 return SOAR_ERROR;
02526 }
02527 }
02528 } else if (string_match("2", argv[i])) {
02529 if (soar_ecWatchLevel(2)) {
02530 return SOAR_ERROR;
02531 }
02532 } else if (string_match("phases", argv[i])) {
02533
02534 if ((i + 1) < argc) {
02535 if ((string_match("-on", argv[i + 1])) ||
02536 (string_match("-off", argv[i + 1])) || (string_match_up_to("-inclusive", argv[i + 1], 3))) {
02537 if (set_watch_setting(TRACE_PHASES_SYSPARAM, argv[i], argv[++i], res)
02538 != SOAR_OK) {
02539 return SOAR_ERROR;
02540 }
02541 } else {
02542
02543 if (soar_ecWatchLevel(2)) {
02544 return SOAR_ERROR;
02545 }
02546 }
02547 } else {
02548
02549 if (soar_ecWatchLevel(2)) {
02550 return SOAR_ERROR;
02551 }
02552 }
02553 } else if (string_match("3", argv[i])) {
02554 if (soar_ecWatchLevel(3)) {
02555 return SOAR_ERROR;
02556 }
02557 } else if (string_match("productions", argv[i])) {
02558 int t;
02559
02560
02561
02562
02563 if ((i + 1) < argc) {
02564 if (string_match("-on", argv[i + 1])) {
02565 for (t = 0; t < NUM_PRODUCTION_TYPES; t++)
02566 set_sysparam(TRACE_FIRINGS_OF_USER_PRODS_SYSPARAM + t, TRUE);
02567 i++;
02568 } else if (string_match("-off", argv[i + 1])) {
02569 for (t = 0; t < NUM_PRODUCTION_TYPES; t++)
02570 set_sysparam(TRACE_FIRINGS_OF_USER_PRODS_SYSPARAM + t, FALSE);
02571 i++;
02572 } else if (string_match_up_to("-inclusive", argv[i + 1], 3)) {
02573 if (soar_ecWatchLevel(3)) {
02574 return SOAR_ERROR;
02575 }
02576 i++;
02577 }
02578
02579
02580
02581 else if ((string_match("-all", argv[i + 1])) || (string_match("-a", argv[i + 1]))) {
02582 i++;
02583 t = i + 1;
02584 set_watch_prod_group_setting(0, argv[i], argv[t], res);
02585 i++;
02586 } else if ((string_match("-chunks", argv[i + 1])) || (string_match("-c", argv[i + 1]))) {
02587 i++;
02588 t = i + 1;
02589 set_watch_prod_group_setting(1, argv[i], argv[t], res);
02590 i++;
02591 } else if ((string_match("-defaults", argv[i + 1])) || (string_match("-d", argv[i + 1]))) {
02592 i++;
02593 t = i + 1;
02594 set_watch_prod_group_setting(2, argv[i], argv[t], res);
02595 i++;
02596 } else if ((string_match("-justifications", argv[i + 1])) || (string_match("-j", argv[i + 1]))) {
02597 i++;
02598 t = i + 1;
02599 set_watch_prod_group_setting(3, argv[i], argv[t], res);
02600 i++;
02601 } else if ((string_match("-user", argv[i + 1])) || (string_match("-u", argv[i + 1]))) {
02602 i++;
02603 t = i + 1;
02604 set_watch_prod_group_setting(4, argv[i], argv[t], res);
02605 i++;
02606 }
02607
02608 else {
02609
02610 if (soar_ecWatchLevel(3)) {
02611 return SOAR_ERROR;
02612 }
02613 }
02614 } else {
02615
02616 if (soar_ecWatchLevel(3)) {
02617 return SOAR_ERROR;
02618 }
02619 }
02620 } else if (string_match("4", argv[i])) {
02621 print("Receive Watch 4\n");
02622
02623 if (soar_ecWatchLevel(4)) {
02624
02625 return SOAR_ERROR;
02626 }
02627 } else if (string_match("wmes", argv[i])) {
02628
02629 char *wmes_option_syntax_msg = "\
02630 watch wmes syntax:\n\
02631 wmes [ -on |\n\
02632 -off |\n\
02633 -inc[lusive] |\n\
02634 {-add-filter type filter} |\n\
02635 {-remove-filter type filter} |\n\
02636 {-reset-filter type} |\n\
02637 {-list-filter type} ]\n\
02638 where\n\
02639 type = -adds|-removes|-both\n\
02640 filter = {id|*} {attribute|*} {value|*}";
02641
02642 if (i + 1 >= argc) {
02643 if (soar_ecWatchLevel(4)) {
02644 return SOAR_ERROR;
02645 }
02646 } else if ((string_match(argv[i + 1], "-on")) ||
02647 (string_match(argv[i + 1], "-off")) || (string_match_up_to("-inclusive", argv[i + 1], 3))) {
02648 if (set_watch_setting(TRACE_WM_CHANGES_SYSPARAM, argv[i], argv[i + 1], res)
02649 != SOAR_OK)
02650 return SOAR_ERROR;
02651 else
02652 i += 1;
02653 } else if (i + 2 >= argc) {
02654 setSoarResultResult(res, wmes_option_syntax_msg);
02655 return SOAR_ERROR;
02656 } else if (string_match(argv[i + 1], "-add-filter")) {
02657 bool forAdds, forRemoves;
02658 if ((i + 5 >= argc)
02659 || (parse_filter_type(argv[i + 2], &forAdds, &forRemoves) == SOAR_ERROR)) {
02660 appendSoarResultResult(res, wmes_option_syntax_msg);
02661 return SOAR_ERROR;
02662 } else {
02663 if (soar_ecAddWmeFilter(argv[i + 3], argv[i + 4], argv[i + 5], forAdds, forRemoves) != 0) {
02664 setSoarResultResult(res, "Error: Filter not added.");
02665 return SOAR_ERROR;
02666 } else {
02667 setSoarResultResult(res, "Filter added.");
02668 }
02669 }
02670 i += 5;
02671 } else if (string_match(argv[i + 1], "-remove-filter")) {
02672 bool forAdds, forRemoves;
02673 if ((i + 5 >= argc)
02674 || (parse_filter_type(argv[i + 2], &forAdds, &forRemoves) == SOAR_ERROR)) {
02675 appendSoarResultResult(res, wmes_option_syntax_msg);
02676 return SOAR_ERROR;
02677 } else {
02678 if (soar_ecRemoveWmeFilter(argv[i + 3], argv[i + 4], argv[i + 5], forAdds, forRemoves) != 0) {
02679 setSoarResultResult(res, "Error: Bad args or filter not found");
02680 return SOAR_ERROR;
02681 } else {
02682 appendSoarResultResult(res, "Filter removed.");
02683 }
02684 }
02685 i += 5;
02686 } else if (string_match(argv[i + 1], "-reset-filter")) {
02687 bool forAdds, forRemoves;
02688 if ((i + 2 >= argc)
02689 || (parse_filter_type(argv[i + 2], &forAdds, &forRemoves) == SOAR_ERROR)) {
02690 appendSoarResultResult(res, wmes_option_syntax_msg);
02691 return SOAR_ERROR;
02692 } else {
02693 if (soar_ecResetWmeFilters(forAdds, forRemoves) != 0) {
02694 appendSoarResultResult(res, "No filters were removed.");
02695 return SOAR_ERROR;
02696 }
02697 }
02698 i += 2;
02699 } else if (string_match(argv[i + 1], "-list-filter")) {
02700 bool forAdds, forRemoves;
02701 if ((i + 2 >= argc) || (parse_filter_type(argv[i + 2], &forAdds, &forRemoves) == SOAR_ERROR)) {
02702
02703 appendSoarResultResult(res, wmes_option_syntax_msg);
02704 return SOAR_ERROR;
02705 } else {
02706 soar_ecListWmeFilters(forAdds, forRemoves);
02707 }
02708 i += 2;
02709 }
02710 }
02711
02712
02713
02714
02715
02716 else if (string_match("5", argv[i])) {
02717 if (soar_ecWatchLevel(5)) {
02718 return SOAR_ERROR;
02719 }
02720 } else if (string_match("preferences", argv[i])) {
02721
02722 if ((i + 1) < argc) {
02723 if ((string_match("-on", argv[i + 1])) ||
02724 (string_match("-off", argv[i + 1])) || (string_match_up_to("-inclusive", argv[i + 1], 3))) {
02725 if (set_watch_setting(TRACE_FIRINGS_PREFERENCES_SYSPARAM, argv[i], argv[++i], res)
02726 != SOAR_OK) {
02727 return SOAR_ERROR;
02728 }
02729 } else {
02730
02731 if (soar_ecWatchLevel(5)) {
02732 return SOAR_ERROR;
02733 }
02734 }
02735 } else {
02736
02737 if (soar_ecWatchLevel(5)) {
02738 return SOAR_ERROR;
02739 }
02740 }
02741 } else if ((string_match("-all", argv[i])) || (string_match("-a", argv[i]))) {
02742 int t = i + 1;
02743 set_watch_prod_group_setting(0, argv[i], argv[t], res);
02744 i++;
02745 } else if ((string_match("-chunks", argv[i])) || (string_match("-c", argv[i]))) {
02746 int t = i + 1;
02747 set_watch_prod_group_setting(1, argv[i], argv[t], res);
02748 i++;
02749 } else if ((string_match("-defaults", argv[i])) || (string_match("-d", argv[i]))) {
02750 int t = i + 1;
02751 set_watch_prod_group_setting(2, argv[i], argv[t], res);
02752 i++;
02753 } else if ((string_match("-justifications", argv[i])) || (string_match("-j", argv[i]))) {
02754 int t = i + 1;
02755 set_watch_prod_group_setting(3, argv[i], argv[t], res);
02756 i++;
02757 } else if ((string_match("-user", argv[i])) || (string_match("-u", argv[i]))) {
02758 int t = i + 1;
02759 set_watch_prod_group_setting(4, argv[i], argv[t], res);
02760 i++;
02761 } else if (string_match_up_to("-nowmes", argv[i], 4)) {
02762 set_sysparam(TRACE_FIRINGS_WME_TRACE_TYPE_SYSPARAM, NONE_WME_TRACE);
02763 } else if (string_match_up_to("-timetags", argv[i], 3)) {
02764 set_sysparam(TRACE_FIRINGS_WME_TRACE_TYPE_SYSPARAM, TIMETAG_WME_TRACE);
02765 } else if (string_match_up_to("-fullwmes", argv[i], 6)) {
02766 set_sysparam(TRACE_FIRINGS_WME_TRACE_TYPE_SYSPARAM, FULL_WME_TRACE);
02767 } else if (string_match_up_to("-prefs", argv[i], 4)) {
02768 set_sysparam(TRACE_FIRINGS_PREFERENCES_SYSPARAM, TRUE);
02769 } else if (string_match_up_to("-noprefs", argv[i], 6)) {
02770 set_sysparam(TRACE_FIRINGS_PREFERENCES_SYSPARAM, FALSE);
02771 }
02772
02773 else if (string_match_up_to("-soar8", argv[i], 6)) {
02774 set_sysparam(TRACE_OPERAND2_REMOVALS_SYSPARAM, TRUE);
02775 } else if (string_match_up_to("-nosoar8", argv[i], 6)) {
02776 set_sysparam(TRACE_OPERAND2_REMOVALS_SYSPARAM, FALSE);
02777 }
02778
02779 else if (string_match_up_to("learning", argv[i], 2)) {
02780
02781 if ((i + 1) < argc) {
02782 if (string_match("-print", argv[i + 1])) {
02783 set_sysparam(TRACE_CHUNK_NAMES_SYSPARAM, TRUE);
02784 set_sysparam(TRACE_CHUNKS_SYSPARAM, FALSE);
02785 set_sysparam(TRACE_JUSTIFICATION_NAMES_SYSPARAM, TRUE);
02786 set_sysparam(TRACE_JUSTIFICATIONS_SYSPARAM, FALSE);
02787 i++;
02788 } else if (string_match("-noprint", argv[i + 1])) {
02789 set_sysparam(TRACE_CHUNK_NAMES_SYSPARAM, FALSE);
02790 set_sysparam(TRACE_CHUNKS_SYSPARAM, FALSE);
02791 set_sysparam(TRACE_JUSTIFICATION_NAMES_SYSPARAM, FALSE);
02792 set_sysparam(TRACE_JUSTIFICATIONS_SYSPARAM, FALSE);
02793 i++;
02794 } else if (string_match_up_to("-fullprint", argv[i + 1], 3)) {
02795 set_sysparam(TRACE_CHUNK_NAMES_SYSPARAM, TRUE);
02796 set_sysparam(TRACE_CHUNKS_SYSPARAM, TRUE);
02797 set_sysparam(TRACE_JUSTIFICATION_NAMES_SYSPARAM, TRUE);
02798 set_sysparam(TRACE_JUSTIFICATIONS_SYSPARAM, TRUE);
02799 i++;
02800 } else {
02801 setSoarResultResult(res,
02802 "Missing setting for watch learning, should be -noprint|-print|-fullprint");
02803 return SOAR_ERROR;
02804 }
02805 } else {
02806 setSoarResultResult(res,
02807 "Missing setting for watch learning, should be -noprint|-print|-fullprint");
02808 return SOAR_ERROR;
02809 }
02810 } else if (string_match("backtracing", argv[i])) {
02811 if (set_watch_setting(TRACE_BACKTRACING_SYSPARAM, argv[i], argv[++i], res)
02812 != SOAR_OK) {
02813 return SOAR_ERROR;
02814 }
02815 } else if (string_match("loading", argv[i])) {
02816 if (set_watch_setting(TRACE_LOADING_SYSPARAM, argv[i], argv[++i], res)
02817 != SOAR_OK) {
02818 return SOAR_ERROR;
02819 }
02820 } else if (string_match("indifferent-selection", argv[i])) {
02821 if (set_watch_setting(TRACE_INDIFFERENT_SYSPARAM, argv[i], argv[++i], res)
02822 != SOAR_OK) {
02823 return SOAR_ERROR;
02824 }
02825 }
02826
02827
02828
02829
02830
02831
02832
02833
02834
02835
02836
02837
02838
02839
02840
02841
02842
02843
02844
02845
02846
02847
02848
02849
02850
02851
02852
02853
02854 else {
02855 setSoarResultResult(res, "Unrecognized argument to watch command: %s", argv[i]);
02856 return SOAR_ERROR;
02857 }
02858 }
02859 }
02860
02861 return SOAR_OK;
02862 }
02863
02864
02865
02866
02867
02868
02869
02870
02871
02872 int soar_DefaultWmeDepth(int argc, const char *argv[], soarResult * res)
02873 {
02874 int depth;
02875
02876 if (argc == 1) {
02877 setSoarResultResult(res, "%d", current_agent(default_wme_depth));
02878 return SOAR_OK;
02879 }
02880
02881 if (argc > 2) {
02882 setSoarResultResult(res, "Too many arguments, should be: default-wme-depth [integer]");
02883 return SOAR_ERROR;
02884 }
02885
02886 if (getInt(argv[1], &depth) == SOAR_OK) {
02887 soar_ecSetDefaultWmeDepth(depth);
02888 } else {
02889 setSoarResultResult(res, "Expected integer for new default print depth: %s", argv[1]);
02890 return SOAR_ERROR;
02891 }
02892
02893 clearSoarResultResult(res);
02894 return SOAR_OK;
02895 }
02896
02897
02898
02899
02900
02901
02902
02903
02904
02905 int soar_BuildInfo(int argc, const char *argv[], soarResult * res)
02906 {
02907
02908 argv = argv;
02909 argc = argc;
02910
02911 soar_ecBuildInfo();
02912 setSoarResultResult(res, soar_version_string);
02913 return SOAR_OK;
02914 }
02915
02916
02917
02918
02919
02920
02921
02922
02923
02924 int soar_ExcludedBuildInfo(int argc, const char *argv[], soarResult * res)
02925 {
02926
02927 argv = argv;
02928 argc = argc;
02929
02930 soar_ecExcludedBuildInfo();
02931 setSoarResultResult(res, soar_version_string);
02932 return SOAR_OK;
02933 }
02934
02935
02936
02937
02938
02939
02940
02941
02942
02943 int soar_GDSPrint(int argc, const char *argv[], soarResult * res)
02944 {
02945
02946 res = res;
02947 argc = argc;
02948 argv = argv;
02949
02950 soar_ecGDSPrint();
02951 return SOAR_OK;
02952 }
02953
02954
02955
02956
02957
02958
02959
02960
02961
02962 int soar_Interrupt(int argc, const char *argv[], soarResult * res)
02963 {
02964 enum soar_apiInterruptSetting interrupt_setting;
02965 Symbol *sym;
02966 production *prod;
02967 bool valid_args;
02968 int i;
02969
02970 clearSoarResultResult(res);
02971
02972 if(argc > 3) {
02973 setSoarResultResult(res, "Too many arguments\n");
02974 }
02975 if (argc == 1 || argc > 3) {
02976 appendSoarResultResult(res, "Usage: interrupt [-on|-off] [production name]");
02977 return SOAR_ERROR;
02978 }
02979
02980 interrupt_setting = INTERRUPT_PRINT;
02981 prod = NULL;
02982 valid_args = TRUE;
02983
02984 for (i = 1; i < argc; i++) {
02985 if (string_match("-on", argv[i])) {
02986 interrupt_setting = INTERRUPT_ON;
02987 } else if (string_match("-off", argv[i])) {
02988 interrupt_setting = INTERRUPT_OFF;
02989 } else {
02990 sym = find_sym_constant(argv[i]);
02991 if (sym && sym->sc.production) {
02992 prod = sym->sc.production;
02993 } else {
02994 setSoarResultResult(res, "Can't find production named %s", argv[i]);
02995 valid_args = FALSE;
02996 break;
02997 }
02998 }
02999 }
03000
03001 if(!valid_args) {
03002 return SOAR_ERROR;
03003 } else {
03004 if(prod) {
03005 if(interrupt_setting == INTERRUPT_ON) {
03006 prod->interrupt = TRUE;
03007 } else if(interrupt_setting == INTERRUPT_OFF) {
03008 prod->interrupt = FALSE;
03009 } else {
03010 print("%s%s", prod->name->var.name, ": ");
03011 if(prod->interrupt) {
03012 print("%s\n", "on");
03013 } else {
03014 print("%s\n", "off");
03015 }
03016 }
03017 } else {
03018 soar_ecPrintAllProductionsWithInterruptSetting(interrupt_setting);
03019 }
03020 }
03021
03022 return SOAR_OK;
03023 }