APWTCL Arnulf's Preferred Web Tcl

Check-in [3f365d7d4a]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:fixes and new code
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:3f365d7d4a830d11285e8e805fbe3ce8b6465040
User & Date: arnulf 2012-04-18 21:46:56
Context
2012-04-19
09:45
fixes and debug stuff check-in: bbfafd8d55 user: arnulf tags: trunk
2012-04-18
21:46
fixes and new code check-in: 3f365d7d4a user: arnulf tags: trunk
16:51
initial version check-in: ab46330ed7 user: arnulf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/TestApwtcl.java.

92
93
94
95
96
97
98



99
100
101
102
103
104
105
intp.source_obj_type.setSourceInfo(script_obj_ptr, intp.string_obj_type.newStringObj(fname, -1, "TestApwtcl_2"), 1);
script_obj_ptr.incrRefCount("TestApwtcl_3");

//intp.current_script_obj = script_obj_ptr;

intp.script_obj_type.setFromAny(script_obj_ptr, 0);
int ret_code = intp.eval_statement.evalObj(script_obj_ptr);




//if (ret_code != Defines.OK) {
//  System.out.println("source result!"+Token.getResultString(ret_code)+"!"+intp.result.getString()+"!");
//}
//System.out.println("evalStatement Done");

//ApwtclObj my_expr = intp.string_obj_type.newStringObj("1 > 2", -1, "MAIN_2");







>
>
>







92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
intp.source_obj_type.setSourceInfo(script_obj_ptr, intp.string_obj_type.newStringObj(fname, -1, "TestApwtcl_2"), 1);
script_obj_ptr.incrRefCount("TestApwtcl_3");

//intp.current_script_obj = script_obj_ptr;

intp.script_obj_type.setFromAny(script_obj_ptr, 0);
int ret_code = intp.eval_statement.evalObj(script_obj_ptr);
if (ret_code != Token.OK) {
System.out.println("ERROR!"+intp.getResult().getString()+"!");
}

//if (ret_code != Defines.OK) {
//  System.out.println("source result!"+Token.getResultString(ret_code)+"!"+intp.result.getString()+"!");
//}
//System.out.println("evalStatement Done");

//ApwtclObj my_expr = intp.string_obj_type.newStringObj("1 > 2", -1, "MAIN_2");

Changes to src/org/apwtcl/lang/ApwtclObj.java.

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
...
506
507
508
509
510
511
512




513
514
515
516
517
518
519
...
947
948
949
950
951
952
953

954


955
956


957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
  public static ApwtclObj live_obj_list = null;

  public long id;
  private Interp interp;
  private ApwtclObj next_obj_ptr;
  private ApwtclObj prev_obj_ptr;
  private ObjTypeBase obj_type_base;
  private Object value1;
  private Object value2;
  private Object value3;

  public StringBuffer bytes;
  public int len;
  public String allocated;
  public String freed;
  public ArrayList<String> incr_lst;
  public ArrayList<String> decr_lst;
................................................................................
//print("sourceValue_SetLineNumber!"+this.mySelf()+"!");
    value2 = (Object)line_number;
    return line_number;
  }

  /* ==================== strValue_GetCharLength ================================== */
  public int strValue_GetCharLength() {




    return (Integer)value2;
  }

  /* ==================== strValue_SetCharLength ================================== */
  public int strValue_SetCharLength(int char_length) {
//print("strValue_SetCharLength!"+this.mySelf()+"!");
    value2 = (Object)char_length;
................................................................................
if (!obj_type_base.haveUpdateString(obj_type)) {
print("obj!"+toDebugString()+"!");
}
      panic(obj_type == 0, "UpdateStringProc called against '<none>' type."+mySelf()+"!");
      panic(!obj_type_base.haveUpdateString(obj_type), "UpdateString called against '"+getObjTypeString(obj_type)+"' type."+mySelf()+"!");
      obj_type_base.callUpdateString(obj_type, this);
    }

    if (bytes == null) {


      return "";
    }


    return bytes.substring(0, len);
  }

  /* ==================== getStringLength ===================================== */
  public int getStringLength() {
    if (bytes == null) {
      /* Invalid string repr. Generate it. */
      panic(obj_type == 0, "UpdateStringProc called against '<none>' type."+mySelf()+"!");
      panic(obj_type_base.haveUpdateString(obj_type), "UpdateString called against '"+getObjTypeString(obj_type)+"' type.");
      obj_type_base.callUpdateString(obj_type, this);
    }
    return len;
  }

  /* ==================== getStringFromArray ===================================== */
  public String getStringFromArray(ArrayList<ApwtclObj> list, int nested) {







|
|
|







 







>
>
>
>







 







>

>
>


>
>








|







37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
...
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
...
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
  public static ApwtclObj live_obj_list = null;

  public long id;
  private Interp interp;
  private ApwtclObj next_obj_ptr;
  private ApwtclObj prev_obj_ptr;
  private ObjTypeBase obj_type_base;
  public Object value1;
  public Object value2;
  public Object value3;

  public StringBuffer bytes;
  public int len;
  public String allocated;
  public String freed;
  public ArrayList<String> incr_lst;
  public ArrayList<String> decr_lst;
................................................................................
//print("sourceValue_SetLineNumber!"+this.mySelf()+"!");
    value2 = (Object)line_number;
    return line_number;
  }

  /* ==================== strValue_GetCharLength ================================== */
  public int strValue_GetCharLength() {
    if (value2 == null) {
print("strValue_GetCharLength fix value2!");
      value2 = len;
    }
    return (Integer)value2;
  }

  /* ==================== strValue_SetCharLength ================================== */
  public int strValue_SetCharLength(int char_length) {
//print("strValue_SetCharLength!"+this.mySelf()+"!");
    value2 = (Object)char_length;
................................................................................
if (!obj_type_base.haveUpdateString(obj_type)) {
print("obj!"+toDebugString()+"!");
}
      panic(obj_type == 0, "UpdateStringProc called against '<none>' type."+mySelf()+"!");
      panic(!obj_type_base.haveUpdateString(obj_type), "UpdateString called against '"+getObjTypeString(obj_type)+"' type."+mySelf()+"!");
      obj_type_base.callUpdateString(obj_type, this);
    }
    
    if (bytes == null) {
      strValue_SetCharLength(0);
      strValue_SetMaxLength(0);
      return "";
    }
//    strValue_SetCharLength(len);
//    strValue_SetMaxLength(len);
    return bytes.substring(0, len);
  }

  /* ==================== getStringLength ===================================== */
  public int getStringLength() {
    if (bytes == null) {
      /* Invalid string repr. Generate it. */
      panic(obj_type == 0, "UpdateStringProc called against '<none>' type."+mySelf()+"!");
      panic(!obj_type_base.haveUpdateString(obj_type), "UpdateString called against '"+getObjTypeString(obj_type)+"' type.");
      obj_type_base.callUpdateString(obj_type, this);
    }
    return len;
  }

  /* ==================== getStringFromArray ===================================== */
  public String getStringFromArray(ArrayList<ApwtclObj> list, int nested) {

Changes to src/org/apwtcl/lang/Command.java.

185
186
187
188
189
190
191
192




193
194
195
196
197
198
199
...
262
263
264
265
266
267
268

269
270

271
272

273
274
275
276
277
278
279
//print("CMD0!"+name+"!"+args.toString()+"!"+getItclClassTypeString(class_type)+"!"+getCommandTypeString(command_type)+"!"+getItclFunctionTypeString(func_type)+"!");
//print("ensemble!"+ensemble+"!"+getCommandTypeString(command_type)+"!");
	if (command_type == COMMAND_ITCL_CLASS) {
//print("call COMMAND_ITCL_CLASS!"+toDebugString()+"!");
      return interp.itcl_obj_type.classCommand(args);
	}
	if (func_type == ITCL_OBJECT_COMMAND) {
//print("args!"+args+"!");




	  String my_cmd_name = args.get(1).getString();
	  ArrayList<ApwtclObj> my_args = new ArrayList<ApwtclObj>();
	  for (int i = 2; i < args.size(); i++) {
	    my_args.add(args.get(i));
	  }
//print("my_cmd_name!"+my_cmd_name+"!"+my_args+"!");
	  return interp.itcl_obj_type.callClassCommand(class_info.ns_ptr, my_cmd_name, class_object, my_args);
................................................................................
            interp.eval_statement.evalObj(trace_obj.script);
          } catch(Exception e) {
            print("error in executing enter trace: "+trace_obj.script.getString()+"!");
          }
        }
      }
    }

//print("=++Command.call!"+name+"!args!"+args.get(0)+"!"+args.size()+"!");
//print("cmd!"+toDebugString()+"!");

    Object r = null;
    try {

      r = cmd_method.invoke(cmd_instance, interp, args);
//print("++call!"+r+"!");
    } catch(Exception e) {
print("call exception!"+e.getMessage()+"!");
e.printStackTrace();
    }
//print("--Command.call2!"+name+"!"+r+"!");







|
>
>
>
>







 







>
|
|
>


>







185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
...
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
//print("CMD0!"+name+"!"+args.toString()+"!"+getItclClassTypeString(class_type)+"!"+getCommandTypeString(command_type)+"!"+getItclFunctionTypeString(func_type)+"!");
//print("ensemble!"+ensemble+"!"+getCommandTypeString(command_type)+"!");
	if (command_type == COMMAND_ITCL_CLASS) {
//print("call COMMAND_ITCL_CLASS!"+toDebugString()+"!");
      return interp.itcl_obj_type.classCommand(args);
	}
	if (func_type == ITCL_OBJECT_COMMAND) {
//print("args!"+args+"!"+args.size()+"!");
      if (args.size() < 2) {
        interp.setResultString("Command call! args.size < 2!"+args+"!");
        return ERROR;
      }
	  String my_cmd_name = args.get(1).getString();
	  ArrayList<ApwtclObj> my_args = new ArrayList<ApwtclObj>();
	  for (int i = 2; i < args.size(); i++) {
	    my_args.add(args.get(i));
	  }
//print("my_cmd_name!"+my_cmd_name+"!"+my_args+"!");
	  return interp.itcl_obj_type.callClassCommand(class_info.ns_ptr, my_cmd_name, class_object, my_args);
................................................................................
            interp.eval_statement.evalObj(trace_obj.script);
          } catch(Exception e) {
            print("error in executing enter trace: "+trace_obj.script.getString()+"!");
          }
        }
      }
    }
if (cmd_instance == null) {
print("=++Command.call!"+name+"!args!"+args.get(0)+"!"+args.size()+"!");
print("cmd!"+toDebugString()+"!");
}
    Object r = null;
    try {
//print("CCC!"+cmd_instance+"!");
      r = cmd_method.invoke(cmd_instance, interp, args);
//print("++call!"+r+"!");
    } catch(Exception e) {
print("call exception!"+e.getMessage()+"!");
e.printStackTrace();
    }
//print("--Command.call2!"+name+"!"+r+"!");

Changes to src/org/apwtcl/lang/CommandOptionList.java.

178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
    num_processed_args = 0;
    option_flags = 0;
    err_msg = "";

    for (int i = start_idx; i < args.size(); i++) {
      option = args.get(i).getString();
//print("option!"+option+"!");
      if (option.charAt(0) != '-') {
        /* seems to be end of options */
        break;
      }
      if (option.equals("--")) {
        /* end of options */
        num_processed_args++;
        i++;







|







178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
    num_processed_args = 0;
    option_flags = 0;
    err_msg = "";

    for (int i = start_idx; i < args.size(); i++) {
      option = args.get(i).getString();
//print("option!"+option+"!");
      if (option.length() == 0 || option.charAt(0) != '-') {
        /* seems to be end of options */
        break;
      }
      if (option.equals("--")) {
        /* end of options */
        num_processed_args++;
        i++;

Changes to src/org/apwtcl/lang/CoreCommandPackages.java.

203
204
205
206
207
208
209












210
211
212
213
214
215
216
    sub_cmds = new ArrayList<ApwtclObj>();
    sub_cmds.add(interp.string_obj_type.newStringObj("UnknownCommand ::unknown", -1, "CORE_COMMAND_PACKAGES_43"));
    cmds.put("unknown", sub_cmds);
    
    sub_cmds = new ArrayList<ApwtclObj>();
    sub_cmds.add(interp.string_obj_type.newStringObj("SubstCommand ::subst", -1, "CORE_COMMAND_PACKAGES_44"));
    cmds.put("subst", sub_cmds);












    
//print("core!"+cmds.keySet()+"!");    
    packages.put("core", cmds);
  }

  /* ==================== mySelf ================================== */
  public String mySelf() {







>
>
>
>
>
>
>
>
>
>
>
>







203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
    sub_cmds = new ArrayList<ApwtclObj>();
    sub_cmds.add(interp.string_obj_type.newStringObj("UnknownCommand ::unknown", -1, "CORE_COMMAND_PACKAGES_43"));
    cmds.put("unknown", sub_cmds);
    
    sub_cmds = new ArrayList<ApwtclObj>();
    sub_cmds.add(interp.string_obj_type.newStringObj("SubstCommand ::subst", -1, "CORE_COMMAND_PACKAGES_44"));
    cmds.put("subst", sub_cmds);
    
    sub_cmds = new ArrayList<ApwtclObj>();
    sub_cmds.add(interp.string_obj_type.newStringObj("JavadebugCommand ::javadebug", -1, "CORE_COMMAND_PACKAGES_45"));
    cmds.put("jsdebug", sub_cmds);
    
    sub_cmds = new ArrayList<ApwtclObj>();
    sub_cmds.add(interp.string_obj_type.newStringObj("ArrayCommand ::array", -1, "CORE_COMMAND_PACKAGES_46"));
    cmds.put("array", sub_cmds);
    
    sub_cmds = new ArrayList<ApwtclObj>();
    sub_cmds.add(interp.string_obj_type.newStringObj("SplitCommand ::split", -1, "CORE_COMMAND_PACKAGES_47"));
    cmds.put("split", sub_cmds);
    
//print("core!"+cmds.keySet()+"!");    
    packages.put("core", cmds);
  }

  /* ==================== mySelf ================================== */
  public String mySelf() {

Changes to src/org/apwtcl/lang/EvalStatement.java.

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
..
73
74
75
76
77
78
79

80
81
82
83
84
85
86
...
108
109
110
111
112
113
114

115







116
117

118
119
120
121
122
123
124
...
189
190
191
192
193
194
195

196
197
198
199
200
201
202
...
219
220
221
222
223
224
225

226
227
228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
...
314
315
316
317
318
319
320

321

322
323
324
325
326
327
328
...
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449


450
451
452
453
454
455
456
...
460
461
462
463
464
465
466
467

468

469
470
471
472
473
474
475
...
479
480
481
482
483
484
485

486
487



488
489
490





491
492
493
494
495
496
497
498
499
500









501
502
503
504
505
506
507
...
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
...
625
626
627
628
629
630
631

632

633
634
635
636
637





638
639
640
641

642

643
644
645




646


647

648
649
650
651
652
653
654
655
656
657
658
659
...
675
676
677
678
679
680
681

682

683
684
685
686
687
688
689
...
695
696
697
698
699
700
701

702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727

728
729
730


731
732
733
734
735
736
737
738
739
740
741
742
743
...
745
746
747
748
749
750
751

752
753

754

755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774

775




776
777
778
779
780

781
782
783
784
785
786
787

    this.interp = interp;
    level = 0;
    eval_level = 0;
    macro_cmd_level = 0;
    eval_subst_debug = 0;
    eval_ipol_debug = 0;
    eval_stmt_debug = 0;
    in_quotes = false;
    had_macro_cmd = false;
    call_frames = new ArrayList<CallFrame>();
  }

  /* ==================== mySelf ================================== */
  public String mySelf() {
................................................................................
  public int substOneToken (Script script, int idx, ArrayList<ApwtclObj> result_ptr) {
    ApwtclObj obj_ptr = null;
    ScriptToken token = script.script_object.tokens.get(idx);
    ArrayList<Variable> result_var_ptr = new ArrayList<Variable>();
    Variable result_var;
    
if (eval_subst_debug > 0) {

script.dumpToken(idx);
print("substOneToken!"+token.token+"!"+getTokenString(token.token)+"!"+token.obj_ptr.mySelf()+"!"+token.obj_ptr.getString()+"!");
}

    switch (token.token) {
    case TOKEN_QUOTE_ESC:
      in_quotes = true;
................................................................................
         * as "$var_name" instead
         */
        if (obj_ptr == null) {
          obj_ptr = interp.string_obj_type.newStringObj("$"+token.obj_ptr.getString(), -1, "EVAL_STATEMENT_2");
          interp.setResult(interp.empty_string_obj);
        } else {
          /* if we are expanding a macro and the variable is a list put it into {} to be safe */

          if (obj_ptr.obj_type == OBJ_TYPE_LIST) {







            obj_ptr = interp.string_obj_type.newStringObj("{"+obj_ptr.getString()+"}", -1, "EVAL_STATEMENT_3");
          }

        }
      } else {
//print("substone2b!"+eval_level+"!"+obj_ptr+"!");
        if (had_macro_cmd) {
//print("substone2c");
          obj_ptr = interp.string_obj_type.newStringObj("$"+token.obj_ptr.getString(), -1, "EVAL_STATEMENT_4");
        }
................................................................................
      break;
    }
    if (obj_ptr != null) {
      result_ptr.add(obj_ptr);
      return OK;
    }
print("SUBST3 ERROR!"+interp.getResult().getString()+"!"+interp.frame_ptr.ns_ptr.toDebugString()+"!");

script.dumpToken(idx);
    result_ptr.add(null);
    return ERROR;
  }

  /* ==================== interpolateTokens ===================================== */
  /* Interpolate the given tokens into a unique ApwtclObject returned by reference
................................................................................
    /* Compute every token forming the argument
     * in the intv2 objects vector. 
     */
    j = 0;
    for (i = 0; i < word_tokens; i++) {
if (eval_ipol_debug > 0) {
print("IPOL!"+i+"!"+idx+"!");

script.dumpToken(i+idx);
}
      if (script.script_object.tokens.get(i + idx).token == TOKEN_COMMENT) {
        continue;
      }
      result_ptr = new ArrayList<ApwtclObj>();
      retcode = substOneToken(script, idx + i, result_ptr);
      intv2.add(result_ptr.get(0));
if (eval_ipol_debug > 1) {
print("RES!"+result_ptr.get(0)+"!"+intv2.toString()+"!"+retcode+"!");

script.dumpToken(i+idx);
}
      if (intv2.get(j) != null) {
        intv2.get(j).incrRefCount("I_EVAL_STATEMENT_2");
      }
      switch(retcode) {
      case OK:
................................................................................
}
    in_quotes = my_in_quotes;
    return obj_ptr;
  }

  /* ==================== evalObj ===================================== */
  public int evalObj(ApwtclObj script_obj_ptr) {

//print("EVALOBJ!"+script_obj_ptr+"!");

    int i;
    Script script;
    ArrayList<ScriptToken> token;
    int retcode = OK;
    int line_no = 0;
    boolean had_comment = false;

................................................................................
      /* Populate the arguments objects.
       * If an error occurs, retcode will be set and
       * 'j' will be set to the number of args expanded
       */
      had_comment = false;
for (j = 0; j < argc; j++) {
if (eval_stmt_debug > 0) {
print("all J!"+j+"!"+getTokenString(token.get(i).token)+"!"+token.get(i).obj_ptr+"!");
}              
}
      for (j = 0; j < argc; j++) {
//print("J!"+j+"!"+argc+"!"+argv+"!");
        int word_tokens = 1;
        boolean expand = false;
        ApwtclObj word_obj_ptr = null;

if (eval_stmt_debug > 0) {
print("J!"+j+"!"+getTokenString(token.get(i).token)+"!"+token.get(i).obj_ptr+"!");
if (eval_stmt_debug > 1) {


print("J!"+j+"!"+getTokenString(token.get(i).token)+"!"+token.get(i).obj_ptr.toDebugString()+"!");
}
}
        if (token.get(i).token == TOKEN_WORD) {
//script.DumpToken(i);
          word_tokens = (int)token.get(i++).obj_ptr.wideValue_GetValue();
          if (word_tokens < 0) {
................................................................................
        }
            had_comment = false;
        if (word_tokens == 1) {
          /* Fast path if the token does not
           * need interpolation 
           */
//print("word_tokens 1!");
if (eval_stmt_debug > 0) {

script.dumpToken(i);

}
          switch (token.get(i).token) {
          case TOKEN_COMMENT:
            had_comment = true;
            num_comments++;
            break;
          case TOKEN_QUOTE_ESC:
................................................................................
            word_obj_ptr = token.get(i).obj_ptr;
            break;
          case TOKEN_VAR_ARRAY_NAME:
//print("stmt var_array_name");
            word_obj_ptr = interp.array_obj_type.expandArray(token.get(i).obj_ptr);
            break;
          case TOKEN_VAR:

            ArrayList<Variable> result_var_ptr = new ArrayList<Variable>();
            result_var_ptr.add(null);



            word_obj_ptr = interp.variable_obj_type.getVariable(token.get(i).obj_ptr, FUNCTION_FLAGS_LEAVE_ERR_MSG, result_var_ptr);
            Variable result_var = result_var_ptr.get(0);
            /* special case for ::itcl::type type variable !! */





            if (word_obj_ptr == null && result_var != null && token.get(i).obj_ptr.getString().equals("type")) {
              word_obj_ptr = interp.string_obj_type.newStringObj(result_var.namespace.full_name, -1, "EVAL_STATEMENT_7");
              word_obj_ptr.incrRefCount("I_EVAL_STATEMENT_5");
            }
            break;
          case TOKEN_EXPRSUGAR:
            word_obj_ptr = interp.expr_obj_type.expandExprSugar(token.get(i).obj_ptr);
            break;
          case TOKEN_BRACE:
            if (!in_quotes) {









              word_obj_ptr = token.get(i).obj_ptr;
            } else {
              ArrayList<ApwtclObj> result_ptr2 = new ArrayList<ApwtclObj>();
              retcode = interp.script_obj_type.substObj(token.get(i).obj_ptr, result_ptr2, FUNCTION_FLAGS_LEAVE_ERR_MSG);
              if (retcode == OK) {
                word_obj_ptr = result_ptr2.get(0);
              }
................................................................................
          if (!expand) {
            if (!had_comment) {
              argv.add(word_obj_ptr);
            }
          } else {
            /* Need to expand word_obj_ptr into multiple args from argv[j] ... */
            int len = interp.list_obj_type.listLength(word_obj_ptr);
            int newargc = argc + len - 1;
            int k;
  
//print(">>>EXPAND!"+argc+"!"+len+"!"+newargc+"!"+word_obj_ptr.toDebugString()+"!");
            /* Now copy in the expanded version */
            for (k = 0; k < len; k++) {
              argv.add(word_obj_ptr.listValue_GetElem().get(k));
              j++;
................................................................................
              for (int k = 1; k < argv.size(); k++) {
                    my_args.add(argv.get(k));
              }
                } else {
                  my_args = argv;
                }
            if (cmd.is_proc) {

//print("cp!"+cmd+"!"+my_args+"!");

              retcode = interp.command_obj_type.callProcedure(cmd, script.script_object.file_name_obj, 
                              line_no, argc, my_args);
//print("callProcedure!"+retcode+"!"+eval_level+"!");
//              ret = cmd.proc.cmd_proc.invoke(cmd.proc.instance, cmd, script.script_object.file_name_obj, 
//                              line_no, argc, my_args);





            } else {
              /* Check if there are too nested calls */
//print("FR!"+interp.frame_ptr.toDebugString()+"!"+interp.max_nesting_depth+"!");
              interp.cmd_priv_data = cmd.native_fcn.privdata;

//print("pp!"+eval_level+"!"+cmd+"!"+my_args+"!");

              Object ret2 = cmd.call(interp, my_args, /* ensemble_expand */ true);
              retcode = (Integer)ret2;
//print("pp retcode!"+eval_level+"!"+retcode+"!");




            }


          } catch (Exception e) {

            System.out.println ("EXCEPTION call!"+e.getMessage()+"!");
          }
//          if (ret2 == null) {
//            retcode = ERROR;
//          }
          cmd.decrCmdRefCount();
        } else {
          if (! (argc == 1 && argv.size() == 1 && argv.get(0).getString().equals(""))) {
print("UNK!"+argv.get(0)+"!"+argv.get(0).toDebugString()+"!");
//print("RETC!"+retcode+"!"+argc+"!"+argv+"!");
            /* Call [unknown] */
            retcode = interp.unknownFcn(argc, argv, script.script_object.file_name_obj, line_no);
................................................................................
    /* Note that we don't have to decrement ref_count, because the
     * following code transfers our use of the reference again to
     * the script object. */
    script_obj_ptr.freeIntRep();
    script_obj_ptr.obj_type = OBJ_TYPE_SCRIPT;
    script_obj_ptr.setIntRepPtr(script);
    script_obj_ptr.decrRefCount("D_EVAL_STATEMENT_8");

//print("EVALOBJ end level!"+stmt.eval_level+"!"+retcode+"!");

    if (macro_cmd_level == eval_level) {
      had_macro_cmd = false;
    }
    eval_level--;
    return retcode;
  }

................................................................................
   *
   * This is possible because the string representation of a
   * list object generated by the list_obj_type.UpdateString is made
   * in a way that ensures that every list element is a different
   * command argument. 
   */
  protected int _evalObjVector(int objc, ArrayList<ApwtclObj> objv, ApwtclObj file_name_obj, int line_no) {

    int i;
    int retcode = OK;
    Command cmd_ptr;

//print("_eOV1!");
    /* Incr refcount of arguments. */
    for (i = 0; i < objc; i++) {
      objv.get(i).incrRefCount("I_EVAL_STATEMENT_8");
    }
    /* Command lookup */
    ArrayList<ArrayList<ApwtclObj>> extra_args_ptr = new ArrayList<ArrayList<ApwtclObj>>();
    cmd_ptr = interp.getCommand(objv.get(0), FUNCTION_FLAGS_LEAVE_ERR_MSG, extra_args_ptr);
//print("EOV!"+cmd_ptr.ToDebugString()+"!");
    if (cmd_ptr == null) {
      retcode = interp.unknownFcn(objc, objv, file_name_obj, line_no);
    } else {
      if (cmd_ptr.command_type == COMMAND_ENSEMBLE) {
        i = 1;
        HashMap<String, Command> ens = cmd_ptr.ensemble;

        while (true) {
          boolean found = false;
int z = -1;
//          for (var z in ens) {
//            if (z == objv.get(i).getString()) {
//              found = true;

//              break;
//            }
//          }


          if (found) {
            if (ens.get(z).ensemble == null) {
              cmd_ptr = ens.get(z);
              break;
            } else {
              ens = ens.get(z).ensemble;
              i++;
            }
          } else {
            String str = "";

            for (int k = 0; k <= i; k++) {
              str += " "+objv.get(k);
................................................................................
            interp.setResultString("no such command!"+str+"!");
            return ERROR;
          }
        }
      }
      /* Call it -- Make sure result is an empty object. */
      cmd_ptr.incrCmdRefCount();

      interp.setEmptyResult();
      if (cmd_ptr.is_proc) {

        retcode = interp.command_obj_type.callProcedure(cmd_ptr, file_name_obj, line_no, objc, objv);

      } else {
        interp.cmd_priv_data = cmd_ptr.native_fcn.privdata;
        Object ret = null;
        try {
//          ret = cmd_ptr.native_fcn.cmd_proc.invoke(cmd_ptr.native_fcn.instance, interp, objv);
          retcode = (Integer)cmd_ptr.call(interp, objv, /* ensemble_expand */ true);
        } catch (Exception e) {
          e.printStackTrace();
System.out.println("Exception call2!"+e.getMessage()+"!");
        }
//        if (ret == null) {
//retcode = ERROR;
//        }
      }
      cmd_ptr.decrCmdRefCount();
    }
    /* Decr refcount of arguments and return the retcode */
    for (i = 0; i < objc; i++) {
      objv.get(i).decrRefCount("D_EVAL_STATEMENT_9");
    }

    return retcode;




  }

  /* ==================== evalObjVector ===================================== */
  public int evalObjVector(int objc, ArrayList<ApwtclObj> objv) {
    return _evalObjVector(objc, objv, interp.empty_string_obj, 1);

 }

  /* ==================== evalObjFromArray ===================================== */
  public int evalObjFromArray(ArrayList<String> args) {
    String my_str = "";
    ApwtclObj my_ptr;
    String sep = "";







|







 







>







 







>
|
>
>
>
>
>
>
>
|

>







 







>







 







>










>







 







>
|
>







 







|








|


>
>







 







|
>

>







 







>

|
>
>
>



>
>
>
>
>










>
>
>
>
>
>
>
>
>







 







<







 







>
|
>


<
<
|
>
>
>
>
>




>
|
>


<
>
>
>
>
|
>
>

>


<
<
<







 







>
|
>







 







>












|









|
|
|
|
>
|
<
<
>
>

|
|


|







 







>


>

>










<
<
<







>

>
>
>
>




|
>







42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
..
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
...
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
...
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
...
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
...
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
...
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
...
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
...
579
580
581
582
583
584
585

586
587
588
589
590
591
592
...
661
662
663
664
665
666
667
668
669
670
671
672


673
674
675
676
677
678
679
680
681
682
683
684
685
686
687

688
689
690
691
692
693
694
695
696
697
698



699
700
701
702
703
704
705
...
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
...
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778


779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
...
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817



818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843

    this.interp = interp;
    level = 0;
    eval_level = 0;
    macro_cmd_level = 0;
    eval_subst_debug = 0;
    eval_ipol_debug = 0;
    eval_stmt_debug = -2;
    in_quotes = false;
    had_macro_cmd = false;
    call_frames = new ArrayList<CallFrame>();
  }

  /* ==================== mySelf ================================== */
  public String mySelf() {
................................................................................
  public int substOneToken (Script script, int idx, ArrayList<ApwtclObj> result_ptr) {
    ApwtclObj obj_ptr = null;
    ScriptToken token = script.script_object.tokens.get(idx);
    ArrayList<Variable> result_var_ptr = new ArrayList<Variable>();
    Variable result_var;
    
if (eval_subst_debug > 0) {
print("substOneToken dump 1!");
script.dumpToken(idx);
print("substOneToken!"+token.token+"!"+getTokenString(token.token)+"!"+token.obj_ptr.mySelf()+"!"+token.obj_ptr.getString()+"!");
}

    switch (token.token) {
    case TOKEN_QUOTE_ESC:
      in_quotes = true;
................................................................................
         * as "$var_name" instead
         */
        if (obj_ptr == null) {
          obj_ptr = interp.string_obj_type.newStringObj("$"+token.obj_ptr.getString(), -1, "EVAL_STATEMENT_2");
          interp.setResult(interp.empty_string_obj);
        } else {
          /* if we are expanding a macro and the variable is a list put it into {} to be safe */
//          if (obj_ptr.obj_type == OBJ_TYPE_LIST || obj_ptr.obj_type == OBJ_TYPE_SOURCE || obj_ptr.len == 0) {
//          if (obj_ptr.obj_type == OBJ_TYPE_LIST || obj_ptr.len == 0) {
          if ((obj_ptr.obj_type == OBJ_TYPE_SOURCE) && (obj_ptr.len == 0)) {
//print(">> DOEXP1!"+obj_ptr.toDebugString()+"!");
        	  obj_ptr = interp.string_obj_type.newStringObj("{{}}", -1, "EVAL_STATEMENT_3a");
          }

          if ((obj_ptr.obj_type == OBJ_TYPE_LIST) && (obj_ptr.listValue_GetLen() == 1)) { 
//print(">> DOEXP2!"+obj_ptr.toDebugString()+"!");
            obj_ptr = interp.string_obj_type.newStringObj("{"+obj_ptr.toString()+"}", -1, "EVAL_STATEMENT_3");
          }
//print(">> exp!"+obj_ptr.toDebugString()+"!");
        }
      } else {
//print("substone2b!"+eval_level+"!"+obj_ptr+"!");
        if (had_macro_cmd) {
//print("substone2c");
          obj_ptr = interp.string_obj_type.newStringObj("$"+token.obj_ptr.getString(), -1, "EVAL_STATEMENT_4");
        }
................................................................................
      break;
    }
    if (obj_ptr != null) {
      result_ptr.add(obj_ptr);
      return OK;
    }
print("SUBST3 ERROR!"+interp.getResult().getString()+"!"+interp.frame_ptr.ns_ptr.toDebugString()+"!");
print("substOneToken dump 2!");
script.dumpToken(idx);
    result_ptr.add(null);
    return ERROR;
  }

  /* ==================== interpolateTokens ===================================== */
  /* Interpolate the given tokens into a unique ApwtclObject returned by reference
................................................................................
    /* Compute every token forming the argument
     * in the intv2 objects vector. 
     */
    j = 0;
    for (i = 0; i < word_tokens; i++) {
if (eval_ipol_debug > 0) {
print("IPOL!"+i+"!"+idx+"!");
print("interpolateTokens dump 1!");
script.dumpToken(i+idx);
}
      if (script.script_object.tokens.get(i + idx).token == TOKEN_COMMENT) {
        continue;
      }
      result_ptr = new ArrayList<ApwtclObj>();
      retcode = substOneToken(script, idx + i, result_ptr);
      intv2.add(result_ptr.get(0));
if (eval_ipol_debug > 1) {
print("RES!"+result_ptr.get(0)+"!"+intv2.toString()+"!"+retcode+"!");
print("interpolateTokens dump 2!");
script.dumpToken(i+idx);
}
      if (intv2.get(j) != null) {
        intv2.get(j).incrRefCount("I_EVAL_STATEMENT_2");
      }
      switch(retcode) {
      case OK:
................................................................................
}
    in_quotes = my_in_quotes;
    return obj_ptr;
  }

  /* ==================== evalObj ===================================== */
  public int evalObj(ApwtclObj script_obj_ptr) {
if (eval_stmt_debug > 0) {
print("EVALOBJ!"+script_obj_ptr+"!");
}
    int i;
    Script script;
    ArrayList<ScriptToken> token;
    int retcode = OK;
    int line_no = 0;
    boolean had_comment = false;

................................................................................
      /* Populate the arguments objects.
       * If an error occurs, retcode will be set and
       * 'j' will be set to the number of args expanded
       */
      had_comment = false;
for (j = 0; j < argc; j++) {
if (eval_stmt_debug > 0) {
print("all J!"+j+"!"+getTokenString(token.get(j+i).token)+"!"+token.get(j+i).obj_ptr+"!");
}              
}
      for (j = 0; j < argc; j++) {
//print("J!"+j+"!"+argc+"!"+argv+"!");
        int word_tokens = 1;
        boolean expand = false;
        ApwtclObj word_obj_ptr = null;

if (eval_stmt_debug > -2) {
print("J!"+j+"!"+getTokenString(token.get(i).token)+"!"+token.get(i).obj_ptr+"!");
if (eval_stmt_debug > 1) {
print("evalObj dump1 i!"+i+"!");
script.dumpToken(i);
print("J!"+j+"!"+getTokenString(token.get(i).token)+"!"+token.get(i).obj_ptr.toDebugString()+"!");
}
}
        if (token.get(i).token == TOKEN_WORD) {
//script.DumpToken(i);
          word_tokens = (int)token.get(i++).obj_ptr.wideValue_GetValue();
          if (word_tokens < 0) {
................................................................................
        }
            had_comment = false;
        if (word_tokens == 1) {
          /* Fast path if the token does not
           * need interpolation 
           */
//print("word_tokens 1!");
if (eval_stmt_debug > -2) {
print("evalObj dump2 i!"+i+"!");
script.dumpToken(i);
print("argv!"+argv+"!");
}
          switch (token.get(i).token) {
          case TOKEN_COMMENT:
            had_comment = true;
            num_comments++;
            break;
          case TOKEN_QUOTE_ESC:
................................................................................
            word_obj_ptr = token.get(i).obj_ptr;
            break;
          case TOKEN_VAR_ARRAY_NAME:
//print("stmt var_array_name");
            word_obj_ptr = interp.array_obj_type.expandArray(token.get(i).obj_ptr);
            break;
          case TOKEN_VAR:
//print("evalObj! VAR!"+token.get(i).obj_ptr+"!"+token.get(i).obj_ptr.getString()+"!"+interp.frame_ptr.ns_ptr.toDebugString()+"!");
            ArrayList<Variable> result_var_ptr = new ArrayList<Variable>();
//            result_var_ptr.add(null);
if (token.get(i).obj_ptr.getString().equals("type")) {
//interp.variable_obj_type.dbg = 1;
}
            word_obj_ptr = interp.variable_obj_type.getVariable(token.get(i).obj_ptr, FUNCTION_FLAGS_LEAVE_ERR_MSG, result_var_ptr);
            Variable result_var = result_var_ptr.get(0);
            /* special case for ::itcl::type type variable !! */
if (token.get(i).obj_ptr.getString().equals("type")) {
//print("result_var_ptr!"+result_var_ptr+"!");
//print("SPECTYPE0!"+token.get(i).obj_ptr+"!"+interp.frame_ptr.ns_ptr.toDebugString()+"!");
//print("SPECTYPE!"+word_obj_ptr+"!"+result_var+"!"+token.get(i).obj_ptr.getString().equals("type")+"!");
}
            if (word_obj_ptr == null && result_var != null && token.get(i).obj_ptr.getString().equals("type")) {
              word_obj_ptr = interp.string_obj_type.newStringObj(result_var.namespace.full_name, -1, "EVAL_STATEMENT_7");
              word_obj_ptr.incrRefCount("I_EVAL_STATEMENT_5");
            }
            break;
          case TOKEN_EXPRSUGAR:
            word_obj_ptr = interp.expr_obj_type.expandExprSugar(token.get(i).obj_ptr);
            break;
          case TOKEN_BRACE:
            if (!in_quotes) {
              if (argc == 1) {
                /* seems to be the special of setting a variable which is a list
                 * in a ::itcl::macro and then executing the variable!!
                 */
print("BRACE NOT in quotes!"+token.get(i).obj_ptr+"!");
                int ret = evalObj(token.get(i).obj_ptr);
                eval_level--;                
                return ret;
              }
              word_obj_ptr = token.get(i).obj_ptr;
            } else {
              ArrayList<ApwtclObj> result_ptr2 = new ArrayList<ApwtclObj>();
              retcode = interp.script_obj_type.substObj(token.get(i).obj_ptr, result_ptr2, FUNCTION_FLAGS_LEAVE_ERR_MSG);
              if (retcode == OK) {
                word_obj_ptr = result_ptr2.get(0);
              }
................................................................................
          if (!expand) {
            if (!had_comment) {
              argv.add(word_obj_ptr);
            }
          } else {
            /* Need to expand word_obj_ptr into multiple args from argv[j] ... */
            int len = interp.list_obj_type.listLength(word_obj_ptr);

            int k;
  
//print(">>>EXPAND!"+argc+"!"+len+"!"+newargc+"!"+word_obj_ptr.toDebugString()+"!");
            /* Now copy in the expanded version */
            for (k = 0; k < len; k++) {
              argv.add(word_obj_ptr.listValue_GetElem().get(k));
              j++;
................................................................................
              for (int k = 1; k < argv.size(); k++) {
                    my_args.add(argv.get(k));
              }
                } else {
                  my_args = argv;
                }
            if (cmd.is_proc) {
if (eval_stmt_debug > -2) {
print("cp!"+cmd+"!"+my_args+"!");
}
              retcode = interp.command_obj_type.callProcedure(cmd, script.script_object.file_name_obj, 
                              line_no, argc, my_args);


if (eval_stmt_debug > -2) {
print("callProcedure end retcode and level!"+getReturnCodeString(retcode)+"!"+eval_level+"!");
if (retcode != OK) {
print("result!"+interp.getResult().getString()+"!");
}
}
            } else {
              /* Check if there are too nested calls */
//print("FR!"+interp.frame_ptr.toDebugString()+"!"+interp.max_nesting_depth+"!");
              interp.cmd_priv_data = cmd.native_fcn.privdata;
if (eval_stmt_debug > -2) {
print("pp!"+eval_level+"!"+cmd+"!"+my_args+"!");
}
              Object ret2 = cmd.call(interp, my_args, /* ensemble_expand */ true);
              retcode = (Integer)ret2;

if (eval_stmt_debug > -2) {
print("pp retcode and level!"+eval_level+"!"+getReturnCodeString(retcode)+"!"+eval_level+"!");
if (retcode != OK) {
print("result!"+interp.getResult().getString()+"!");
}
}
            }
          } catch (Exception e) {
            e.printStackTrace();
            System.out.println ("EXCEPTION call!"+e.getMessage()+"!");
          }



          cmd.decrCmdRefCount();
        } else {
          if (! (argc == 1 && argv.size() == 1 && argv.get(0).getString().equals(""))) {
print("UNK!"+argv.get(0)+"!"+argv.get(0).toDebugString()+"!");
//print("RETC!"+retcode+"!"+argc+"!"+argv+"!");
            /* Call [unknown] */
            retcode = interp.unknownFcn(argc, argv, script.script_object.file_name_obj, line_no);
................................................................................
    /* Note that we don't have to decrement ref_count, because the
     * following code transfers our use of the reference again to
     * the script object. */
    script_obj_ptr.freeIntRep();
    script_obj_ptr.obj_type = OBJ_TYPE_SCRIPT;
    script_obj_ptr.setIntRepPtr(script);
    script_obj_ptr.decrRefCount("D_EVAL_STATEMENT_8");
if (eval_stmt_debug > 0) {
print("EVALOBJ end level!"+eval_level+"!"+retcode+"!");
}
    if (macro_cmd_level == eval_level) {
      had_macro_cmd = false;
    }
    eval_level--;
    return retcode;
  }

................................................................................
   *
   * This is possible because the string representation of a
   * list object generated by the list_obj_type.UpdateString is made
   * in a way that ensures that every list element is a different
   * command argument. 
   */
  protected int _evalObjVector(int objc, ArrayList<ApwtclObj> objv, ApwtclObj file_name_obj, int line_no) {
  try {
    int i;
    int retcode = OK;
    Command cmd_ptr;

//print("_eOV1!");
    /* Incr refcount of arguments. */
    for (i = 0; i < objc; i++) {
      objv.get(i).incrRefCount("I_EVAL_STATEMENT_8");
    }
    /* Command lookup */
    ArrayList<ArrayList<ApwtclObj>> extra_args_ptr = new ArrayList<ArrayList<ApwtclObj>>();
    cmd_ptr = interp.getCommand(objv.get(0), FUNCTION_FLAGS_LEAVE_ERR_MSG, extra_args_ptr);
//print("EOV!"+cmd_ptr.toDebugString()+"!");
    if (cmd_ptr == null) {
      retcode = interp.unknownFcn(objc, objv, file_name_obj, line_no);
    } else {
      if (cmd_ptr.command_type == COMMAND_ENSEMBLE) {
        i = 1;
        HashMap<String, Command> ens = cmd_ptr.ensemble;

        while (true) {
          boolean found = false;
          String z2 = null;
          for (String z: ens.keySet()) {
            if (z.equals(objv.get(i).getString())) {
              found = true;
              z2 = z;
              break;


            }
          }
          if (found) {
            if (ens.get(z2).ensemble == null) {
              cmd_ptr = ens.get(z2);
              break;
            } else {
              ens = ens.get(z2).ensemble;
              i++;
            }
          } else {
            String str = "";

            for (int k = 0; k <= i; k++) {
              str += " "+objv.get(k);
................................................................................
            interp.setResultString("no such command!"+str+"!");
            return ERROR;
          }
        }
      }
      /* Call it -- Make sure result is an empty object. */
      cmd_ptr.incrCmdRefCount();
//print("cmd_ptr!"+cmd_ptr+"!"+cmd_ptr.is_proc+"!");
      interp.setEmptyResult();
      if (cmd_ptr.is_proc) {
//print("call callProcedure!"+objc+"!"+objv+"!");
        retcode = interp.command_obj_type.callProcedure(cmd_ptr, file_name_obj, line_no, objc, objv);
//print("after callProcedure!");
      } else {
        interp.cmd_priv_data = cmd_ptr.native_fcn.privdata;
        Object ret = null;
        try {
//          ret = cmd_ptr.native_fcn.cmd_proc.invoke(cmd_ptr.native_fcn.instance, interp, objv);
          retcode = (Integer)cmd_ptr.call(interp, objv, /* ensemble_expand */ true);
        } catch (Exception e) {
          e.printStackTrace();
System.out.println("Exception call2!"+e.getMessage()+"!");
        }



      }
      cmd_ptr.decrCmdRefCount();
    }
    /* Decr refcount of arguments and return the retcode */
    for (i = 0; i < objc; i++) {
      objv.get(i).decrRefCount("D_EVAL_STATEMENT_9");
    }
//print("_evalObjVector end!"+retcode+"!");
    return retcode;
  } catch(Exception e) {
    e.printStackTrace();
    return ERROR;
  }
  }

  /* ==================== evalObjVector ===================================== */
  public int evalObjVector(int objc, ArrayList<ApwtclObj> objv) {
    int ret = _evalObjVector(objc, objv, interp.empty_string_obj, 1);
    return ret;
 }

  /* ==================== evalObjFromArray ===================================== */
  public int evalObjFromArray(ArrayList<String> args) {
    String my_str = "";
    ApwtclObj my_ptr;
    String sep = "";

Changes to src/org/apwtcl/lang/ItclDelegate.java.

22
23
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
..
42
43
44
45
46
47
48

49
50



51

52
53
54
55
56
57
58
..
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162







163
164
165
166

167
168

169

170
171
172
173
174
175
176
177
178
179

180
181


182
183
184
185

186


187
188
189
190
191
192

193
194
195
196


197

198
199
200

  private int id;
  private Interp interp;
  
  public String type;
  public String which;
  public ItclClass class_info;
  public String to_part;
  public String using_part;
  public String as_part;

  public String except_part;


  /* ==================== ItclDelegate ================================== */
  public ItclDelegate(Interp interp, String type, String which, ItclClass class_info) {
    oid++;
    id = oid;
    
................................................................................
    this.type = type;
    this.which = which;
    this.class_info = class_info;
    this.to_part = null;
    this.using_part = null;
    this.as_part = null;
    this.except_part = null;


  }





  /* ==================== mySelf ================================== */
  public String mySelf() {
    String str = "ItclDelegate!"+id+"!";
    return str;
  } 
      
  /* ==================== toString ===================================== */
................................................................................
  }

  /* ==================== storeDelegateInfo ================================== */
  public int storeDelegateInfo(ArrayList<ApwtclObj> args) {
    String part;

//print("storeDelegateInfo!"+args+"!");
//    switch (type.getString()) {
//    case "method":
//    case "option":
//      break;
//    default:
//      interp.setResultString("delegate: only method and option can be delegated!");
//      return ERROR;
//    }
//    for (int i = 0; i < args.length; i++) {
//      if (i + 1 >= args.size()) {
//        interp.setResultString("delegate: must be an even number of arguments!");
//        return ERROR;
//      }
//      part = args.get(i).getString();
//      switch (part) {
//      case "to":
//        if (to_part != null) {
//          interp.setResultString("delegate: \"to\" part already used!");
//          return ERROR;
//        }
//        i++;
//        i_delegate.to_part = args.get(i).getString();
//        break;
//      case "using":
//        if (using_part != null) {
//          interp.setResultString("delegate: \"using\" part already used!");
//          return ERROR;
//        }
//        i++;
//        using_part = args.get(i).getString();
//        break;
//      case "as":
//        if (as_part != null) {
//          interp.setResultString("delegate: \"as\" part already used!");
//          return ERROR;
//        }
//        i++;
//        as_part = args.get(i);
//        break;
//      case "except":
//        if (except_part != null) {
//          interp.setResultString("delegate: \"except\" part already used!");
//          return ERROR;
//        }
//        i++;
//        except_part = args.get(i).getString();
//        break;
//      default: 
//        interp.setResultString("delegate: funny part: \""+part+"\"");
//        return ERROR;
//      }
//    }
    return OK;
  }

  /* ==================== delegateCget ================================== */
  public int delegateCget(String option_name) {
//    var var_obj_ptr;
//    var var_ptr = new Array();
//    var objv = new Array();

//print("delegateCget!"+option_name+"!"+typeof i_delegate.to_part+"!");
//    if (i_delegate.which == option_name.getString() || i_delegate.which == '*') {
//      if (i_delegate.to_part != null) {
//        var_obj_ptr = i_delegate.interp.variable_obj_type.getVariable(i_delegate.to_part, i_delegate.FUNCTION_FLAGS_NONE, var_ptr);
//        if (var_obj_ptr == null) {
//          i_delegate.interp.setResultString("delegateCget to_part: \""+i_delegate.to_part.getString()+"\" not found");
//          return ERROR;
//        }
//        var_ptr = var_ptr[0];
//        objv.push(var_obj_ptr);
//        objv.push(i_delegate.interp.string_obj_type.newStringObj("cget", -1, "ITCL_DELEGATE_1"));
//        objv.push(option_name);
//        return interp.eval_statement.evalObjVector(objv.length, objv);
//      } else {
//        // FIXME need code here !!
//        i_delegate.interp.setResultString("delegateCget no to_part not yet implemented");
//        return ERROR;
//      }
//       
//    }
    interp.setResultString("delegateCget not yet implemented");
    return ERROR;







  }

  /* ==================== delegateConfigure ================================== */
  public int delegateConfigure(String option_name, ApwtclObj option_value) {

//    var var_obj_ptr;
//    var var_ptr = new Array();

//    var objv = new Array();


//print("delegateConfigure!"+option_name+"!"+option_value+"!"+typeof i_delegate.to_part+"!");
//    if (which == option_name.getString() || which.equals("*")) {
//      if (to_part != null) {
//        var_obj_ptr = interp.variable_obj_type.getVariable(to_part, FUNCTION_FLAGS_NONE, var_ptr);
//        if (var_obj_ptr == null) {
//          interp.setResultString("delegateConfigure to_part: \""+to_part.getString()+"\" not found");
//          return ERROR;
//        }
//        var_ptr = var_ptr[0];

//        objv.push(var_obj_ptr);
//        objv.push(interp.string_obj_type.newStringObj("configure", -1, "ITCL_DELEGATE_2"));


//        objv.push(option_name);
//        if (option_value != null) {
//          objv.push(option_value);
//        }

//        return interp.eval_statement.evalObjVector(objv.length, objv);


//      } else {
//        // FIXME need code here !!
//        interp.setResultString("delegateConfigure no to_part not yet implemented");
//        return ERROR;
//      }
       

//      interp.setResultString("delegateConfigure no to_part not yet implemented");
//      return ERROR;
//    }
    interp.setResultString("delegateConfigure not yet implemented");


    return ERROR;

  }
}








|
|
|
>
|







 







>
|
|
>
>
>
|
>







 







|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>




>
|
<
>
|
>

|
|
|
|
|
|
|
<
<
>
|
|
>
>
|
|
|
<
>
|
>
>
|
|
|
|
<
|
>
|
|
<
<
>
>

>



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
..
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
..
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181

182
183
184
185
186
187
188
189
190
191
192


193
194
195
196
197
198
199
200

201
202
203
204
205
206
207
208

209
210
211
212


213
214
215
216
217
218
219

  private int id;
  private Interp interp;
  
  public String type;
  public String which;
  public ItclClass class_info;
  public ApwtclObj to_part;
  public ApwtclObj using_part;
  public ApwtclObj as_part;
  public ApwtclObj except_part;
  public String my_name;


  /* ==================== ItclDelegate ================================== */
  public ItclDelegate(Interp interp, String type, String which, ItclClass class_info) {
    oid++;
    id = oid;
    
................................................................................
    this.type = type;
    this.which = which;
    this.class_info = class_info;
    this.to_part = null;
    this.using_part = null;
    this.as_part = null;
    this.except_part = null;
    this.my_name = "ItclDelegate";
  }

  /* ==================== getMyName ================================== */
  public String getMyName() {
    return this.my_name;
  } 
      
  /* ==================== mySelf ================================== */
  public String mySelf() {
    String str = "ItclDelegate!"+id+"!";
    return str;
  } 
      
  /* ==================== toString ===================================== */
................................................................................
  }

  /* ==================== storeDelegateInfo ================================== */
  public int storeDelegateInfo(ArrayList<ApwtclObj> args) {
    String part;

//print("storeDelegateInfo!"+args+"!");
    if (!type.equals("method") && !type.equals("option")) {
      interp.setResultString("delegate: only method and option can be delegated!");
      return ERROR;
    }
    for (int i = 0; i < args.size(); i++) {
      if (i + 1 >= args.size()) {
        interp.setResultString("delegate: must be an even number of arguments!");
        return ERROR;
      }
      part = args.get(i).getString();
      if (part.equals("to")) {
        if (to_part != null) {
          interp.setResultString("delegate: \"to\" part already used!");
          return ERROR;
        }
        i++;
        to_part = args.get(i);
      } else {
        if (part.equals("using")) {
          if (using_part != null) {
            interp.setResultString("delegate: \"using\" part already used!");
            return ERROR;
          }
          i++;
          using_part = args.get(i);
        } else {
          if (part.equals("as")) {
            if (as_part != null) {
              interp.setResultString("delegate: \"as\" part already used!");
              return ERROR;
            }
            i++;
            as_part = args.get(i);
          } else {
            if (part.equals("except")) {
              if (except_part != null) {
                interp.setResultString("delegate: \"except\" part already used!");
                return ERROR;
              }
              i++;
              except_part = args.get(i);
            } else {
              interp.setResultString("delegate: funny part: \""+part+"\"");
              return ERROR;
            }
          }
        }
      }
    }
    return OK;
  }

  /* ==================== delegateCget ================================== */
  public int delegateCget(String option_name) {
  try {
    ApwtclObj var_obj_ptr;
    ArrayList<Variable> var_ptr_ptr = new ArrayList<Variable>();
    ArrayList<ApwtclObj> objv = new ArrayList<ApwtclObj>();
    ApwtclObj option_name_ptr;

print("delegateCget!"+option_name+"!"+to_part+"!");
    if (which.equals(option_name) || which.equals("*")) {
      if (to_part != null) {
        var_obj_ptr = interp.variable_obj_type.getVariable(to_part, FUNCTION_FLAGS_NONE, var_ptr_ptr);
        if (var_obj_ptr == null) {
          interp.setResultString("delegateCget to_part: \""+to_part.getString()+"\" not found");
          return ERROR;
        }
        objv.add(var_obj_ptr);
        objv.add(interp.string_obj_type.newStringObj("cget", -1, "ITCL_DELEGATE_1"));
        option_name_ptr = interp.string_obj_type.newStringObj(option_name, -1, "ITCL_DELEGATE_2");
        option_name_ptr.incrRefCount("ITCL_DELEGATE_3");
        objv.add(option_name_ptr);
        int ret = interp.eval_statement.evalObjVector(objv.size(), objv);
print("delegate cget after evalObjVector");
//        option_name_ptr.decrRefCount("ITCL_DELEGATE_4");
print("delegate cget after evalObjVector2!"+ret+"!");
        return ret;
      } else {
        // FIXME need code here !!
        interp.setResultString("delegateCget no to_part not yet implemented");
        return ERROR;
      }       
    }
    interp.setResultString("delegateCget not yet implemented");
    return ERROR;
  } catch(Exception e) {
    e.printStackTrace();
    return ERROR;
  }
  }

  /* ==================== delegateConfigure ================================== */
  public int delegateConfigure(String option_name, ApwtclObj option_value) {
  try {
    ApwtclObj var_obj_ptr;

    ArrayList<Variable> var_ptr_ptr = new ArrayList<Variable>();
    ArrayList<ApwtclObj> objv = new ArrayList<ApwtclObj>();
    ApwtclObj option_name_ptr;

print("delegateConfigure!"+option_name+"!"+option_value+"!"+to_part+"!");
    if (which.equals(option_name) || which.equals("*")) {
      if (to_part != null) {
        var_obj_ptr = interp.variable_obj_type.getVariable(to_part, FUNCTION_FLAGS_NONE, var_ptr_ptr);
        if (var_obj_ptr == null) {
          interp.setResultString("delegateConfigure to_part: \""+to_part.getString()+"\" not found");
          return ERROR;


        }
        objv.add(var_obj_ptr);
        objv.add(interp.string_obj_type.newStringObj("configure", -1, "ITCL_DELEGATE_2"));
        option_name_ptr = interp.string_obj_type.newStringObj(option_name, -1, "ITCL_DELEGATE_5");
        option_name_ptr.incrRefCount("ITCL_DELEGATE_6");
        objv.add(option_name_ptr);
        if (option_value != null) {
          objv.add(option_value);

        }
        int ret = interp.eval_statement.evalObjVector(objv.size(), objv);
        option_name_ptr.decrRefCount("ITCL_DELEGATE_7");
        return ret;
      } else {
        // FIXME need code here !!
        interp.setResultString("delegateConfigure no to_part not yet implemented");
        return ERROR;

      }       
    }
    interp.setResultString("delegateConfigure not yet implemented");
    return ERROR;


  } catch(Exception e) {
    e.printStackTrace();
    return ERROR;
  }
  }
}

Changes to src/org/apwtcl/lang/ItclFunction.java.

230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
      cmd_obj.proc.body_obj_ptr = body_obj;
      cmd_obj.ns_ptr = class_info.ns_ptr;
      cmd_obj.function_info = this;
      cmd_obj.class_info = this.class_info;
      param_obj.incrRefCount("I_ITCL_FUNCTION_14");
      body_obj.incrRefCount("I_ITCL_FUNCTION_15");
//print("createClassCommand class_type!"+class_info.class_type+"!"+cmd_obj.toDebugString()+"!");
      interp.global_ns_ptr.registerCommand(fcn_name, cmd_obj, getItclClassTypeString(class_info.class_type), getCommandTypeString(type));
//print("createClassCommand2 class_type!"+class_info.class_type+"!"+type+"!"+cmd_obj.toDebugString()+"!");
//print("createClassCommand3!"+cmd_obj.name+"!"+class_info.class_type+"!"+type+"!"+getItclClassTypeString(class_info.class_type)+"!"+getCommandTypeString(type)+"!");
    }
    return OK;
  }

  /* ==================== changeBody ===================================== */







|







230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
      cmd_obj.proc.body_obj_ptr = body_obj;
      cmd_obj.ns_ptr = class_info.ns_ptr;
      cmd_obj.function_info = this;
      cmd_obj.class_info = this.class_info;
      param_obj.incrRefCount("I_ITCL_FUNCTION_14");
      body_obj.incrRefCount("I_ITCL_FUNCTION_15");
//print("createClassCommand class_type!"+class_info.class_type+"!"+cmd_obj.toDebugString()+"!");
      interp.global_ns_ptr.registerCommand(fcn_name, cmd_obj, getItclClassTypeString(class_info.class_type), getItclFunctionTypeString(type));
//print("createClassCommand2 class_type!"+class_info.class_type+"!"+type+"!"+cmd_obj.toDebugString()+"!");
//print("createClassCommand3!"+cmd_obj.name+"!"+class_info.class_type+"!"+type+"!"+getItclClassTypeString(class_info.class_type)+"!"+getCommandTypeString(type)+"!");
    }
    return OK;
  }

  /* ==================== changeBody ===================================== */

Changes to src/org/apwtcl/lang/ItclObject.java.

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
...
265
266
267
268
269
270
271
272
273
274

275
276
277
278
279
280
281
282

283
284
285
286
287
288
289
290
291
...
526
527
528
529
530
531
532

533
534
535

536
537
538
539
540
541
542

//print("initItclObject!"+toDebugString()+"!");
    /* add to class instances */
    my_obj_ptr = interp.string_obj_type.newStringObj(object_name, -1, "ITCL_OBJECT_1");
    my_obj_ptr.incrRefCount("I_ITCL_OBJECT_1");
    class_info.instances.add(my_obj_ptr);
    /* Create a new call frame */
print("initItclObject PUSF");
    ret_code = interp.namespace_obj_type.pushStackFrame(frame_ptr_ptr, class_info.ns_ptr, CALL_TYPE_PROC);
    if (ret_code != OK) {
      return ERROR;
    }
    interp.frame_ptr.class_object = this;
    this_variable = new Variable(interp, "this", "VAR_THIS_VAR", null, class_info.ns_ptr);
    this_variable.setProtection(PROTECTION_PROTECTED);
................................................................................
    }
    /* Destroy the call frame */
    interp.namespace_obj_type.popStackFrame();
    return ret_code;
  }

  /* ==================== getClassOptionObj ========================================== */
  public ItclOption getClassOptionObj(String option_name) {
    if (class_options.get(option_name) != null) {
      return class_options.get(option_name);

    } else {
      if (delegated_options.get(option_name) != null) {
//        return delegated_options.get(option_name);
//FIXME need a common class for option and delegated option!
return null;
      } else {
        if (class_info.options.get(option_name) != null) {
          return class_info.options.get(option_name);

        } else {
          return null;
        }
      }
    }
  }

  /* ==================== initClassOptionParts ========================================== */
  public int initClassOptionParts(Variable var_obj, ItclClass class_obj) {
................................................................................
      case ITCL_COMMON:
        var_type = "VAR_COMMON";
        break;
      default:
        interp.setResultString("bad variable type: \""+class_var_ptr.type+"\"");
        return ERROR;
      }

      var_ptr = new Variable(interp, var_name, var_type, null, class_info.ns_ptr);
      var_ptr.setProtection(class_var_ptr.protection);
      if (class_var_ptr.type == ITCL_TYPE_VARIABLE) {

        class_info.ns_ptr.variables.put(escapeKey(var_name), var_ptr);
      } else {
        variables.put(escapeKey(var_name), var_ptr);
      }
      if (class_var_ptr.init_val != null) {
        var_name_ptr = interp.string_obj_type.newStringObj(var_name, -1, "ITCL_OBJECT_12");
        var_name_ptr.incrRefCount("I_ITCL_OBJECT_14");







|







 







|

|
>


|
<
|


|
>

|







 







>



>







129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
...
265
266
267
268
269
270
271
272
273
274
275
276
277
278

279
280
281
282
283
284
285
286
287
288
289
290
291
292
...
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545

//print("initItclObject!"+toDebugString()+"!");
    /* add to class instances */
    my_obj_ptr = interp.string_obj_type.newStringObj(object_name, -1, "ITCL_OBJECT_1");
    my_obj_ptr.incrRefCount("I_ITCL_OBJECT_1");
    class_info.instances.add(my_obj_ptr);
    /* Create a new call frame */
//print("initItclObject PUSF");
    ret_code = interp.namespace_obj_type.pushStackFrame(frame_ptr_ptr, class_info.ns_ptr, CALL_TYPE_PROC);
    if (ret_code != OK) {
      return ERROR;
    }
    interp.frame_ptr.class_object = this;
    this_variable = new Variable(interp, "this", "VAR_THIS_VAR", null, class_info.ns_ptr);
    this_variable.setProtection(PROTECTION_PROTECTED);
................................................................................
    }
    /* Destroy the call frame */
    interp.namespace_obj_type.popStackFrame();
    return ret_code;
  }

  /* ==================== getClassOptionObj ========================================== */
  public int getClassOptionObj(String option_name, ArrayList<Object> option_ptr) {
    if (class_options.get(option_name) != null) {
      option_ptr.add(class_options.get(option_name));
      return ITCL_OPTION;
    } else {
      if (delegated_options.get(option_name) != null) {
        option_ptr.add(delegated_options.get(option_name));

        return ITCL_DELEGATE;
      } else {
        if (class_info.options.get(option_name) != null) {
          option_ptr.add(class_info.options.get(option_name));
          return ITCL_OPTION;
        } else {
          return -1;
        }
      }
    }
  }

  /* ==================== initClassOptionParts ========================================== */
  public int initClassOptionParts(Variable var_obj, ItclClass class_obj) {
................................................................................
      case ITCL_COMMON:
        var_type = "VAR_COMMON";
        break;
      default:
        interp.setResultString("bad variable type: \""+class_var_ptr.type+"\"");
        return ERROR;
      }
//print("CLASSVAR!"+var_name+"!"+var_type+"!"+getItclVariableTypeString(class_var_ptr.type)+"!"+class_info+"!");
      var_ptr = new Variable(interp, var_name, var_type, null, class_info.ns_ptr);
      var_ptr.setProtection(class_var_ptr.protection);
      if (class_var_ptr.type == ITCL_TYPE_VARIABLE) {
//print("TYPEVARIABLE!"+var_name+class_info.ns_ptr+"!");
        class_info.ns_ptr.variables.put(escapeKey(var_name), var_ptr);
      } else {
        variables.put(escapeKey(var_name), var_ptr);
      }
      if (class_var_ptr.init_val != null) {
        var_name_ptr = interp.string_obj_type.newStringObj(var_name, -1, "ITCL_OBJECT_12");
        var_name_ptr.incrRefCount("I_ITCL_OBJECT_14");

Changes to src/org/apwtcl/lang/ItclOption.java.

112
113
114
115
116
117
118





119
120
121
122
123
124
125
...
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
    }
    this.protection = protection;
    this.type = type;
    this.class_info = class_info;
    my_name = "ItclOption";
  }






  /* ==================== mySelf ================================== */
  public String mySelf() {
    String str = "ItclOption!"+id+"!";
    return str;
  } 
      
  /* ==================== toString ===================================== */
................................................................................
    int processed_args;
    int option_flags;
    ArrayList<ApwtclObj> my_args = new ArrayList<ApwtclObj>();

    for (int i = 1; i < args.size(); i++) {
      my_args.add(args.get(i));
    }
print("args!"+args+"!"+my_args+"!");
    command_option_list.resetOptionValues();
    if (command_option_list.parseOptions(my_args, 0, "itclOption") != OK) {
print("ERR!"+command_option_list.getErrorMsg()+"!");
      interp.setResultString(command_option_list.getErrorMsg());
      return ERROR;
    }
    option_flags = command_option_list.getOptionFlags();
    processed_args = command_option_list.getNumProcessedArgs();
print("storeOption2!"+args.size()+"!"+processed_args);
    if (args.size() - 1 != processed_args) {
      interp.setResultString("usage: option ?option value ...? ?result?");
print("storeopt err2");
      return ERROR;
    }
    /* take care of command as args[0] */
    processed_args++;







>
>
>
>
>







 







|








|







112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
    }
    this.protection = protection;
    this.type = type;
    this.class_info = class_info;
    my_name = "ItclOption";
  }

  /* ==================== getMyName ================================== */
  public String getMyName() {
    return this.my_name;
  } 
      
  /* ==================== mySelf ================================== */
  public String mySelf() {
    String str = "ItclOption!"+id+"!";
    return str;
  } 
      
  /* ==================== toString ===================================== */
................................................................................
    int processed_args;
    int option_flags;
    ArrayList<ApwtclObj> my_args = new ArrayList<ApwtclObj>();

    for (int i = 1; i < args.size(); i++) {
      my_args.add(args.get(i));
    }
//print("args!"+args+"!"+my_args+"!");
    command_option_list.resetOptionValues();
    if (command_option_list.parseOptions(my_args, 0, "itclOption") != OK) {
print("ERR!"+command_option_list.getErrorMsg()+"!");
      interp.setResultString(command_option_list.getErrorMsg());
      return ERROR;
    }
    option_flags = command_option_list.getOptionFlags();
    processed_args = command_option_list.getNumProcessedArgs();
//print("storeOption2!"+args.size()+"!"+processed_args);
    if (args.size() - 1 != processed_args) {
      interp.setResultString("usage: option ?option value ...? ?result?");
print("storeopt err2");
      return ERROR;
    }
    /* take care of command as args[0] */
    processed_args++;

Changes to src/org/apwtcl/lang/TclTest.java.

351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
//print("BDY!"+test_obj.mySelf()+"!"+body+"!");
//print("BDY!"+test_obj.mySelf()+"!"+test_name+"!");

    /* Create a new call frame */
    ArrayList<CallFrame> frame_ptr_ptr = new ArrayList<CallFrame>();
    ApwtclObj result;
    try {
print("tcltest runTest PUSF");
      ret_code = interp.namespace_obj_type.pushStackFrame(frame_ptr_ptr, interp.global_ns_ptr, CALL_TYPE_NAMESPACE);
    } catch(Exception e) {
print("TERR!"+e+"!");
    }
    if (ret_code != OK) {
      return ERROR;
    }
    try {
      ret_code = interp.eval_statement.evalObj(body);
    } catch(Exception e) {
print("internal ERR!"+e.getMessage()+"!"+body+"!");
e.printStackTrace();
       interp.setResultString("INTERNAL ERROR!"+e.getMessage()+"!");
       ret_code = -1;  /* signal internal error !! */
    }
    /* Destroy the call frame */
    interp.namespace_obj_type.popStackFrame();

    result = interp.getResult();







|











|







351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
//print("BDY!"+test_obj.mySelf()+"!"+body+"!");
//print("BDY!"+test_obj.mySelf()+"!"+test_name+"!");

    /* Create a new call frame */
    ArrayList<CallFrame> frame_ptr_ptr = new ArrayList<CallFrame>();
    ApwtclObj result;
    try {
//print("tcltest runTest PUSF");
      ret_code = interp.namespace_obj_type.pushStackFrame(frame_ptr_ptr, interp.global_ns_ptr, CALL_TYPE_NAMESPACE);
    } catch(Exception e) {
print("TERR!"+e+"!");
    }
    if (ret_code != OK) {
      return ERROR;
    }
    try {
      ret_code = interp.eval_statement.evalObj(body);
    } catch(Exception e) {
print("internal ERR!"+e.getMessage()+"!"+body+"!");
       e.printStackTrace();
       interp.setResultString("INTERNAL ERROR!"+e.getMessage()+"!");
       ret_code = -1;  /* signal internal error !! */
    }
    /* Destroy the call frame */
    interp.namespace_obj_type.popStackFrame();

    result = interp.getResult();

Changes to src/org/apwtcl/lang/cmd/AppendCommand.java.

25
26
27
28
29
30
31

32
33
34
35
36
37
38
..
65
66
67
68
69
70
71




72
73
74

  /* ==================== AppendCommand ================================== */
  public AppendCommand() {
  }

  /* ==================== appendCmd ================================== */
  public int appendCmd(Interp interp, ArrayList<ApwtclObj> args) {

    ApwtclObj string_obj_ptr;
    ArrayList<Variable> result_var_ptr = new ArrayList<Variable>();
    int i;

    if (args.size() < 2) {
      interp.wrongNumArgs(1, args, "varName ?value value ...?");
      return ERROR;
................................................................................
        }
        return ERROR;
      }
    }
//print("---append ptr!"+string_obj_ptr.toDebugString()+"!");
    interp.setResult(string_obj_ptr);
    return OK;




  }

}







>







 







>
>
>
>



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
..
66
67
68
69
70
71
72
73
74
75
76
77
78
79

  /* ==================== AppendCommand ================================== */
  public AppendCommand() {
  }

  /* ==================== appendCmd ================================== */
  public int appendCmd(Interp interp, ArrayList<ApwtclObj> args) {
  try {
    ApwtclObj string_obj_ptr;
    ArrayList<Variable> result_var_ptr = new ArrayList<Variable>();
    int i;

    if (args.size() < 2) {
      interp.wrongNumArgs(1, args, "varName ?value value ...?");
      return ERROR;
................................................................................
        }
        return ERROR;
      }
    }
//print("---append ptr!"+string_obj_ptr.toDebugString()+"!");
    interp.setResult(string_obj_ptr);
    return OK;
  } catch(Exception e) {
    e.printStackTrace();
    return ERROR;
  }
  }

}

Changes to src/org/apwtcl/lang/cmd/ItclCommand.java.

18
19
20
21
22
23
24

25
26
27
28
29
30
31
...
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
...
487
488
489
490
491
492
493

494
495
496
497
498
499
500
501
502
503
504
505

506
507
508
509

510


511

512
513
514
515
516
517
518
...
551
552
553
554
555
556
557

558
559
560
561
562
563
564
565

566
567
568
569
570
571
572
...
575
576
577
578
579
580
581

582
583
584
585
586
587
588
589
590

591
592


593
594
595
596
597
598
599
600


601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634





635
636
637

638
639
640

641

642

643

644
645

646
647
648
649
650
651
652
...
672
673
674
675
676
677
678


679

680
681
682
683
684
685
686
687
688




689
690
691
692
693
694
695
...
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
...
729
730
731
732
733
734
735

736

737

738

739
740
741
742
743
744
745
746
747
748
749
750
751
import java.util.ArrayList;

import org.apwtcl.lang.CallFrame;
import org.apwtcl.lang.Command;
import org.apwtcl.lang.Interp;
import org.apwtcl.lang.ApwtclObj;
import org.apwtcl.lang.ItclClass;

import org.apwtcl.lang.ItclFunction;
import org.apwtcl.lang.ItclMacro;
import org.apwtcl.lang.ItclObject;
import org.apwtcl.lang.ItclOption;
import org.apwtcl.lang.Namespace;
import org.apwtcl.lang.Token;
import org.apwtcl.lang.Variable;
................................................................................
    interp.itcl_obj_type.class_name = args.get(1);
    ret_code = interp.itcl_obj_type.setFromAny(args.get(2));
    return ret_code;
  }

  /* ==================== itclInternalSetCmd ================================== */
  public int itclInternalSetCmd(Interp interp, ArrayList<ApwtclObj> args) {
print("itcl internal set called!"+args+"!");
//print("::itcl::internal::set!"+args+"!"+interp.frame_ptr.ns_ptr+"!"+interp.itcl_obj_type.class_name+"!"+interp.itcl_obj_type.class_ns_ptr+"!");
    if (args.size() != 3) {
      interp.wrongNumArgs(1, args, "name value");
      return ERROR;
    }
    ApwtclObj name = args.get(1);
    ApwtclObj value = args.get(2);
................................................................................
  try {
//print("itcl internal classcget called!"+args+"!");
    ItclObject class_object = null;
    int ret_code = OK;
//    Variable var_ptr = null;
    ArrayList<Variable> var_ptr_ptr = null;
    ItclOption class_option_obj = null;

    ApwtclObj name_ptr = null;
    ApwtclObj obj_ptr = null;

    if (args.size() != 2) {
      interp.wrongNumArgs(1, args, "option_name");
      return ERROR;
    }
    class_object = interp.frame_ptr.getClassObject();
    ItclClass class_ptr = class_object.class_info;
    ApwtclObj option_name = args.get(1);
    class_option_obj = class_object.getClassOptionObj(option_name.getString());
    if (class_option_obj == null) {

      interp.setResultString("cget no such option: \""+option_name+"\"");
      return ERROR;
    }
    if (class_option_obj.my_name.equals("ItclDelegate")) {

      return class_option_obj.delegateCget(option_name);


    }

    ApwtclObj cget_method = class_option_obj.cget_method;
    if (cget_method == null) {
      /* look if cgetmethodvar is set */
      ApwtclObj cget_method_var = class_option_obj.cget_methodvar;
      if (cget_method_var == null) {
        /* just do "normal" cget */
        switch (class_ptr.class_type) {
................................................................................
    e.printStackTrace();
    return ERROR;
  }
  }

  /* ==================== itclInternalClassconfigureCmd ================================== */
  public int classconfigureCmd(Interp interp, ArrayList<ApwtclObj> args) {

print("itcl internal classconfigure called!"+args+"!");
    ItclClass class_ptr = null;
    ItclObject class_object;
    ApwtclObj configure_method = null;
    ApwtclObj configure_methodvar = null;
    ApwtclObj option_val = null;
    ApwtclObj option_name;
    ItclOption class_option_obj;

    String result;
    int ret_code = OK;
    ArrayList<ApwtclObj> my_args;
    ApwtclObj name_ptr;
    ApwtclObj obj_ptr = null;
    Namespace save_ns_ptr;
    ArrayList<Variable> var_ptr_ptr = null;
................................................................................

    if (args.size() < 2) {
      interp.wrongNumArgs(1, args, "option_name");
      return ERROR;
    }
    class_object = interp.frame_ptr.getClassObject();
    class_ptr = class_object.class_info;

    save_ns_ptr = interp.frame_ptr.ns_ptr;
    interp.frame_ptr.ns_ptr = class_ptr.ns_ptr;
    if (args.size() == 0) {
      /* return all option names */
      interp.setResultString("configure all not yet implemented!");
      interp.frame_ptr.ns_ptr = save_ns_ptr;
      return ERROR;
    } else {
      option_name = args.get(1);

      class_option_obj = class_object.getClassOptionObj(option_name.getString());
      if (class_option_obj == null) {


        interp.setResultString("configure no such option: \""+option_name+"\"");
        interp.frame_ptr.ns_ptr = save_ns_ptr;
        return ERROR;
      }
      result = "";
      if (args.size() == 2) {
        /* return info about an option */
        // FIXME for that case the configuremethod seems not to be relevant at least for type class


        configure_method = class_option_obj.configure_method;
//print("configure:get option!"+option_name+"!configure_method!"+configure_method+"!");
        if (configure_method == null) {
          /* look if configuremethodvar is set */
          // FIXME see above comment
          configure_methodvar = class_option_obj.configure_methodvar;
          if (configure_methodvar == null) {
            /* just do "normal" configure */
            switch (class_ptr.class_type) {
            case ITCL_TYPE_CLASS:
            case ITCL_WIDGET:
            case ITCL_WIDGETADAPTOR:
              name_ptr = interp.string_obj_type.newStringObj("options("+option_name.getString()+")", -1, "PKG_ITCLCMD_7");
              var_ptr_ptr = new ArrayList<Variable>();
              obj_ptr = interp.variable_obj_type.getVariable(name_ptr, FUNCTION_FLAGS_LEAVE_ERR_MSG, var_ptr_ptr);
//print("OP!"+option_name+"!"+name_ptr+"!"+obj_ptr.toDebugString()+"!"+var_ptr.toDebugString()+"!");
              break;
            case ITCL_EXTENDED_CLASS:
            case ITCL_CLASS:
              name_ptr = interp.string_obj_type.newStringObj("itcl_options("+option_name.getString()+")", -1, "PKG_ITCLCMD_8");
              var_ptr_ptr = new ArrayList<Variable>();
              obj_ptr = interp.variable_obj_type.getVariable(name_ptr, FUNCTION_FLAGS_NONE, var_ptr_ptr);
              break;
            }
            interp.setResult(obj_ptr);
            interp.frame_ptr.ns_ptr = save_ns_ptr;
            return OK;
          } else {
print("configure_method_var not yet implemented");
            /* get the method from the var */
// FIXME !!! need code here
          }
        } else {
print("configure_method not yet implemented");





        }
      } else {
        if (args.size() == 3) {

          /* set an option */
          option_val = args.get(2);
          if (class_option_obj.my_name.equals("ItclDelegate")) {

//print("configure:set option delegate!"+option_name+"!to!"+option_val+"!");

            int ret = class_option_obj.delegateConfigure(option_name, option_val);

            interp.frame_ptr.ns_ptr = save_ns_ptr;

            return ret;
          } else {

            configure_method = class_option_obj.configure_method;
//print("configure:set option!"+option_name+"!to!"+option_val+"!configure_method!"+configure_method+"!");
            if (configure_method == null) {
              /* look if configure_methodvar is set */
              configure_methodvar = class_option_obj.configure_methodvar;
              if (configure_methodvar == null) {
                /* just do "normal" configure */
................................................................................
              }
            } else {
              my_args = new ArrayList<ApwtclObj>();
              my_args.add(configure_method);
              my_args.add(option_name);
              my_args.add(option_val);
              interp.frame_ptr.ns_ptr = save_ns_ptr;


              ret_code = interp.eval_statement.evalObjVector(my_args.size(), my_args);

//              ret_code = interp.eval_statement.evalObjFromArray(my_args);
            }
          }
        }
      }
      interp.setResultString(result);
    }
    interp.frame_ptr.ns_ptr = save_ns_ptr;
    return ret_code;




  }

  /* ==================== itclInternalClassconfigurelistCmd =========================== */
  public int classconfigurelistCmd(Interp interp, ArrayList<ApwtclObj> args) {
print("itcl internal classconfigurelist called!"+args+"!");
    int lgth;
    int i;
................................................................................
    }
    lst_ptr = args.get(1);
    lgth = interp.list_obj_type.listLength(lst_ptr);
    if (lgth % 2 != 0) {
      interp.setResultString("must be an even number of elements in list");
      return ERROR;
    }
    ApwtclObj name_ptr = interp.string_obj_type.newStringObj("::itcl::internal::classconfigure", -1, "PKG_ITCLCMD_11");
    name_ptr.incrRefCount("I_PKG_ITCLCMD_6");
    ArrayList<ArrayList<ApwtclObj>> extra_args_ptr = new ArrayList<ArrayList<ApwtclObj>>();
    Command cmd_obj = interp.getCommand(name_ptr, FUNCTION_FLAGS_NONE, extra_args_ptr);
    if (cmd_obj == null) {
      interp.setResultString("no such command: \"::itcl::internal::classconfigure\"");
      return ERROR;
    }
................................................................................
        return ERROR;
      }
      opt_val = option_val_ptr.get(0);
      ArrayList<ApwtclObj> my_args = new ArrayList<ApwtclObj>();
      my_args.add(args.get(0));
      my_args.add(opt_name);
      my_args.add(opt_val);

      ret_code = (Integer)cmd_obj.call(interp, my_args, false);

    }

    name_ptr.decrRefCount("D_PKG_ITCLCMD_4");

    return ret_code;
  }

  /* ==================== itclInternalClassdestroyCmd =========================== */
  public int classdestroyCmd(Interp interp, ArrayList<ApwtclObj> args) {
print("itcl internal classdestroy called!"+args+"!");
print("WARNING! destroy not yet implemented!");
//interp.setResultString("WARNING! destroy not yet implemented!");
    return OK;
  }

  /* ==================== itclInternalClassinstallCmd =========================== */
  public int classinstallCmd(Interp interp, ArrayList<ApwtclObj> args) {







>







 







|







 







>










|
|
>



|
>
|
>
>

>







 







>







|
>







 







>









>
|
<
>
>








>
>
|

|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|



|
|
|
>
>
>
>
>



>


<
>

>
|
>

>


>







 







>
>

>









>
>
>
>







 







|







 







>

>

>

>





|







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
...
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
...
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
...
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
...
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602

603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659

660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
...
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
...
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
...
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
import java.util.ArrayList;

import org.apwtcl.lang.CallFrame;
import org.apwtcl.lang.Command;
import org.apwtcl.lang.Interp;
import org.apwtcl.lang.ApwtclObj;
import org.apwtcl.lang.ItclClass;
import org.apwtcl.lang.ItclDelegate;
import org.apwtcl.lang.ItclFunction;
import org.apwtcl.lang.ItclMacro;
import org.apwtcl.lang.ItclObject;
import org.apwtcl.lang.ItclOption;
import org.apwtcl.lang.Namespace;
import org.apwtcl.lang.Token;
import org.apwtcl.lang.Variable;
................................................................................
    interp.itcl_obj_type.class_name = args.get(1);
    ret_code = interp.itcl_obj_type.setFromAny(args.get(2));
    return ret_code;
  }

  /* ==================== itclInternalSetCmd ================================== */
  public int itclInternalSetCmd(Interp interp, ArrayList<ApwtclObj> args) {
//print("itcl internal set called!"+args+"!");
//print("::itcl::internal::set!"+args+"!"+interp.frame_ptr.ns_ptr+"!"+interp.itcl_obj_type.class_name+"!"+interp.itcl_obj_type.class_ns_ptr+"!");
    if (args.size() != 3) {
      interp.wrongNumArgs(1, args, "name value");
      return ERROR;
    }
    ApwtclObj name = args.get(1);
    ApwtclObj value = args.get(2);
................................................................................
  try {
//print("itcl internal classcget called!"+args+"!");
    ItclObject class_object = null;
    int ret_code = OK;
//    Variable var_ptr = null;
    ArrayList<Variable> var_ptr_ptr = null;
    ItclOption class_option_obj = null;
    ItclDelegate delegated_class_option_obj = null;
    ApwtclObj name_ptr = null;
    ApwtclObj obj_ptr = null;

    if (args.size() != 2) {
      interp.wrongNumArgs(1, args, "option_name");
      return ERROR;
    }
    class_object = interp.frame_ptr.getClassObject();
    ItclClass class_ptr = class_object.class_info;
    ApwtclObj option_name = args.get(1);
    ArrayList<Object> option_ptr = new ArrayList<Object>();
    int option_type = class_object.getClassOptionObj(option_name.getString(), option_ptr);
    if (option_type < 0) {
      interp.setResultString("cget no such option: \""+option_name+"\"");
      return ERROR;
    }
    if (option_type == ITCL_DELEGATE) {
      delegated_class_option_obj = (ItclDelegate)option_ptr.get(0);
      int ret = delegated_class_option_obj.delegateCget(option_name.getString());
print("after delegate cget!"+ret+"!");      
      return ret;
    }
    class_option_obj = (ItclOption)option_ptr.get(0);
    ApwtclObj cget_method = class_option_obj.cget_method;
    if (cget_method == null) {
      /* look if cgetmethodvar is set */
      ApwtclObj cget_method_var = class_option_obj.cget_methodvar;
      if (cget_method_var == null) {
        /* just do "normal" cget */
        switch (class_ptr.class_type) {
................................................................................
    e.printStackTrace();
    return ERROR;
  }
  }

  /* ==================== itclInternalClassconfigureCmd ================================== */
  public int classconfigureCmd(Interp interp, ArrayList<ApwtclObj> args) {
	try {
print("itcl internal classconfigure called!"+args+"!");
    ItclClass class_ptr = null;
    ItclObject class_object;
    ApwtclObj configure_method = null;
    ApwtclObj configure_methodvar = null;
    ApwtclObj option_val = null;
    ApwtclObj option_name;
    ItclOption class_option_obj = null;
    ItclDelegate delegated_class_option_obj = null;
    String result;
    int ret_code = OK;
    ArrayList<ApwtclObj> my_args;
    ApwtclObj name_ptr;
    ApwtclObj obj_ptr = null;
    Namespace save_ns_ptr;
    ArrayList<Variable> var_ptr_ptr = null;
................................................................................

    if (args.size() < 2) {
      interp.wrongNumArgs(1, args, "option_name");
      return ERROR;
    }
    class_object = interp.frame_ptr.getClassObject();
    class_ptr = class_object.class_info;
//print("CFG!"+class_ptr.toDebugString()+"!");
    save_ns_ptr = interp.frame_ptr.ns_ptr;
    interp.frame_ptr.ns_ptr = class_ptr.ns_ptr;
    if (args.size() == 0) {
      /* return all option names */
      interp.setResultString("configure all not yet implemented!");
      interp.frame_ptr.ns_ptr = save_ns_ptr;
      return ERROR;
    } else {
      option_name = args.get(1);
      ArrayList<Object> option_ptr = new ArrayList<Object>();
      int option_type = class_object.getClassOptionObj(option_name.getString(), option_ptr);

//print("CFG2!"+option_type+"!");
      if (option_type < 0) {
        interp.setResultString("configure no such option: \""+option_name+"\"");
        interp.frame_ptr.ns_ptr = save_ns_ptr;
        return ERROR;
      }
      result = "";
      if (args.size() == 2) {
        /* return info about an option */
        // FIXME for that case the configuremethod seems not to be relevant at least for type class
        if (option_type == ITCL_OPTION) {
          class_option_obj = (ItclOption)option_ptr.get(0);
          configure_method = class_option_obj.configure_method;
//print("configure:get option!"+option_name+"!configure_method!"+configure_method+"!");
          if (configure_method == null) {
            /* look if configuremethodvar is set */
            // FIXME see above comment
            configure_methodvar = class_option_obj.configure_methodvar;
            if (configure_methodvar == null) {
              /* just do "normal" configure */
              switch (class_ptr.class_type) {
              case ITCL_TYPE_CLASS:
              case ITCL_WIDGET:
              case ITCL_WIDGETADAPTOR:
                name_ptr = interp.string_obj_type.newStringObj("options("+option_name.getString()+")", -1, "PKG_ITCLCMD_7");
                var_ptr_ptr = new ArrayList<Variable>();
                obj_ptr = interp.variable_obj_type.getVariable(name_ptr, FUNCTION_FLAGS_LEAVE_ERR_MSG, var_ptr_ptr);
//print("OP!"+option_name+"!"+name_ptr+"!"+obj_ptr.toDebugString()+"!"+var_ptr.toDebugString()+"!");
                break;
              case ITCL_EXTENDED_CLASS:
              case ITCL_CLASS:
                name_ptr = interp.string_obj_type.newStringObj("itcl_options("+option_name.getString()+")", -1, "PKG_ITCLCMD_8");
                var_ptr_ptr = new ArrayList<Variable>();
                obj_ptr = interp.variable_obj_type.getVariable(name_ptr, FUNCTION_FLAGS_NONE, var_ptr_ptr);
                break;
              }
              interp.setResult(obj_ptr);
              interp.frame_ptr.ns_ptr = save_ns_ptr;
              return OK;
            } else {
print("configure_method_var not yet implemented");
            /* get the method from the var */
// FIXME !!! need code here
            }
          } else {
            print("configure_method not yet implemented");
          }
        } else {
print("configure delegegate not yet implemented!!");
          /* ITCL_DELEGATE */
          /* FIXME neeed code here !! */
        }
      } else {
        if (args.size() == 3) {
//print("setOption!"+option_type+"!");
          /* set an option */
          option_val = args.get(2);

          if (option_type == ITCL_DELEGATE) {
//print("configure:set option delegate!"+option_name+"!to!"+option_val+"!");
        	delegated_class_option_obj = (ItclDelegate)option_ptr.get(0);
            int ret = delegated_class_option_obj.delegateConfigure(option_name.getString(), option_val);
//print("after delegate configure!"+save_ns_ptr+"!");
            interp.frame_ptr.ns_ptr = save_ns_ptr;
//print("configure end!"+args+"!"+ret+"!");
            return ret;
          } else {
        	class_option_obj = (ItclOption)option_ptr.get(0);
            configure_method = class_option_obj.configure_method;
//print("configure:set option!"+option_name+"!to!"+option_val+"!configure_method!"+configure_method+"!");
            if (configure_method == null) {
              /* look if configure_methodvar is set */
              configure_methodvar = class_option_obj.configure_methodvar;
              if (configure_methodvar == null) {
                /* just do "normal" configure */
................................................................................
              }
            } else {
              my_args = new ArrayList<ApwtclObj>();
              my_args.add(configure_method);
              my_args.add(option_name);
              my_args.add(option_val);
              interp.frame_ptr.ns_ptr = save_ns_ptr;
//print("my_args!"+my_args+"!");
//print("call evalObjVector xxx");
              ret_code = interp.eval_statement.evalObjVector(my_args.size(), my_args);
//print("evalObjVector done xxx");
//              ret_code = interp.eval_statement.evalObjFromArray(my_args);
            }
          }
        }
      }
      interp.setResultString(result);
    }
    interp.frame_ptr.ns_ptr = save_ns_ptr;
    return ret_code;
	} catch(Exception e) {
      e.printStackTrace();
      return ERROR;
	}
  }

  /* ==================== itclInternalClassconfigurelistCmd =========================== */
  public int classconfigurelistCmd(Interp interp, ArrayList<ApwtclObj> args) {
print("itcl internal classconfigurelist called!"+args+"!");
    int lgth;
    int i;
................................................................................
    }
    lst_ptr = args.get(1);
    lgth = interp.list_obj_type.listLength(lst_ptr);
    if (lgth % 2 != 0) {
      interp.setResultString("must be an even number of elements in list");
      return ERROR;
    }
    ApwtclObj name_ptr = interp.string_obj_type.newStringObj("configure", -1, "PKG_ITCLCMD_11");
    name_ptr.incrRefCount("I_PKG_ITCLCMD_6");
    ArrayList<ArrayList<ApwtclObj>> extra_args_ptr = new ArrayList<ArrayList<ApwtclObj>>();
    Command cmd_obj = interp.getCommand(name_ptr, FUNCTION_FLAGS_NONE, extra_args_ptr);
    if (cmd_obj == null) {
      interp.setResultString("no such command: \"::itcl::internal::classconfigure\"");
      return ERROR;
    }
................................................................................
        return ERROR;
      }
      opt_val = option_val_ptr.get(0);
      ArrayList<ApwtclObj> my_args = new ArrayList<ApwtclObj>();
      my_args.add(args.get(0));
      my_args.add(opt_name);
      my_args.add(opt_val);
//print("configurelist!"+i+"!"+lgth+"!"+my_args+"!");
      ret_code = (Integer)cmd_obj.call(interp, my_args, false);
//print("configurelist after call!"+i+"!"+lgth+"!"+my_args+"!");
    }
//print("configurelist after for");
    name_ptr.decrRefCount("D_PKG_ITCLCMD_4");
//print("configurelist return!"+ret_code+"!");
    return ret_code;
  }

  /* ==================== itclInternalClassdestroyCmd =========================== */
  public int classdestroyCmd(Interp interp, ArrayList<ApwtclObj> args) {
//print("itcl internal classdestroy called!"+args+"!");
print("WARNING! destroy not yet implemented!");
//interp.setResultString("WARNING! destroy not yet implemented!");
    return OK;
  }

  /* ==================== itclInternalClassinstallCmd =========================== */
  public int classinstallCmd(Interp interp, ArrayList<ApwtclObj> args) {

Changes to src/org/apwtcl/lang/cmd/LsortCommand.java.

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
..
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
..
95
96
97
98
99
100
101

102
103
104
105

  /* ==================== LsortCommand ================================== */
  public LsortCommand() {
  }

  /* ==================== lsortCmd ================================== */
  public int lsortCmd(Interp interp, ArrayList<ApwtclObj> args) {
print("lsort called!"+args+"!");
    ApwtclObj res_obj;
    int i;
    int ret_code;
    SortInfo info = new SortInfo(interp);

    if (!initted) {
      command_option_list = new CommandOptionList(interp);
      command_option_list.addOption("-ascii", SORT_OPTION_ASCII, OPTION_HAS_NO_VALUE, null, null);
      command_option_list.addOption("-command", SORT_OPTION_COMMAND, OPTION_HAS_VALUE, null, null);
................................................................................

    if (args.size() < 2) {
      interp.wrongNumArgs(1, args, "?options? list");
      return ERROR;
    }
    command_option_list.resetOptionValues();
    if (command_option_list.parseOptions(args, 1, "lsort") != OK) {
print("lsort2!"+command_option_list.getErrorMsg()+"!");
      interp.setResultString(command_option_list.getErrorMsg());
      return ERROR;
    }
print("lsort3");
    int option_flags = command_option_list.getOptionFlags();

    info.type = SORT_OPTION_ASCII;
    if ((option_flags & SORT_OPTION_ASCII) != 0) {
      info.type = SORT_OPTION_ASCII;
    }
    if ((option_flags & SORT_OPTION_NOCASE) != 0) {
................................................................................
    res_obj = args.get(args.size() - 1).duplicateObj();
    ret_code = interp.list_obj_type.listSortElements(res_obj, info);
    if (ret_code == OK) {
      interp.setResult(res_obj);
    } else {
      res_obj.freeNewObj("LSORT_1");
    }

    return OK;
  }

}







|

<







 







|



|







 







>




29
30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
..
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
..
94
95
96
97
98
99
100
101
102
103
104
105

  /* ==================== LsortCommand ================================== */
  public LsortCommand() {
  }

  /* ==================== lsortCmd ================================== */
  public int lsortCmd(Interp interp, ArrayList<ApwtclObj> args) {
//print("lsort called!"+args+"!");
    ApwtclObj res_obj;

    int ret_code;
    SortInfo info = new SortInfo(interp);

    if (!initted) {
      command_option_list = new CommandOptionList(interp);
      command_option_list.addOption("-ascii", SORT_OPTION_ASCII, OPTION_HAS_NO_VALUE, null, null);
      command_option_list.addOption("-command", SORT_OPTION_COMMAND, OPTION_HAS_VALUE, null, null);
................................................................................

    if (args.size() < 2) {
      interp.wrongNumArgs(1, args, "?options? list");
      return ERROR;
    }
    command_option_list.resetOptionValues();
    if (command_option_list.parseOptions(args, 1, "lsort") != OK) {
//print("lsort2!"+command_option_list.getErrorMsg()+"!");
      interp.setResultString(command_option_list.getErrorMsg());
      return ERROR;
    }
//print("lsort3");
    int option_flags = command_option_list.getOptionFlags();

    info.type = SORT_OPTION_ASCII;
    if ((option_flags & SORT_OPTION_ASCII) != 0) {
      info.type = SORT_OPTION_ASCII;
    }
    if ((option_flags & SORT_OPTION_NOCASE) != 0) {
................................................................................
    res_obj = args.get(args.size() - 1).duplicateObj();
    ret_code = interp.list_obj_type.listSortElements(res_obj, info);
    if (ret_code == OK) {
      interp.setResult(res_obj);
    } else {
      res_obj.freeNewObj("LSORT_1");
    }
//print("lsort return OK!"+res_obj+"!");
    return OK;
  }

}

Changes to src/org/apwtcl/lang/cmd/NamespaceCommand.java.

631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
    String qualifiers = interp.namespace_obj_type.nsQualifiers(ns_name.getString());
    interp.setResultString(qualifiers);
    return OK;
  }

  /* ==================== namespaceTailCmd =========================== */
  public int namespaceTailCmd(Interp interp, ArrayList<ApwtclObj> args) {
print("namespace tail called");
    if (args.size() != 2) {
      interp.wrongNumArgs(1, args, "nsName");
      return ERROR;
    }
    ApwtclObj ns_name = args.get(1);
    String tail = interp.namespace_obj_type.nsTail(ns_name.getString());
    interp.setResultString(tail);







|







631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
    String qualifiers = interp.namespace_obj_type.nsQualifiers(ns_name.getString());
    interp.setResultString(qualifiers);
    return OK;
  }

  /* ==================== namespaceTailCmd =========================== */
  public int namespaceTailCmd(Interp interp, ArrayList<ApwtclObj> args) {
//print("namespace tail called");
    if (args.size() != 2) {
      interp.wrongNumArgs(1, args, "nsName");
      return ERROR;
    }
    ApwtclObj ns_name = args.get(1);
    String tail = interp.namespace_obj_type.nsTail(ns_name.getString());
    interp.setResultString(tail);

Changes to src/org/apwtcl/lang/cmd/ReturnCommand.java.

36
37
38
39
40
41
42

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
...
125
126
127
128
129
130
131




132
133
134

  /* ==================== ReturnCommand ================================== */
  public ReturnCommand() {
  }

  /* ==================== returnCmd ================================== */
  public int returnCmd(Interp interp, ArrayList<ApwtclObj> args) {

//print("return called!"+args+"!");
    ApwtclObj code_obj = null;
    int level = 1;
    int return_code = OK;
    ApwtclObj stack_trace_obj = null;
    ApwtclObj error_code_obj = null;
    ApwtclObj error_info_obj;
    ApwtclObj options_obj = null;
//    ApwtclObj r = null;
    int num_processed_args = 0;

    if (!initted) {
      command_option_list = new CommandOptionList(interp);
      command_option_list.addOption("-code", RETURN_OPTION_CODE, OPTION_HAS_VALUE, null, null);
      command_option_list.addOption("-errorcode", RETURN_OPTION_ERRORCODE, OPTION_HAS_VALUE, null, null);
      command_option_list.addOption("-errorinfo", RETURN_OPTION_ERRORINFO, OPTION_HAS_VALUE, null, null);
................................................................................
//print("return_code!"+return_code+"!");
    interp.return_level = level;
    if (num_processed_args == args.size() - 1) {
      interp.setResult(args.get(num_processed_args));
    }
//print("+++ RETURN");
    return RETURN;




  }

}







>








<







 







>
>
>
>



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

52
53
54
55
56
57
58
...
125
126
127
128
129
130
131
132
133
134
135
136
137
138

  /* ==================== ReturnCommand ================================== */
  public ReturnCommand() {
  }

  /* ==================== returnCmd ================================== */
  public int returnCmd(Interp interp, ArrayList<ApwtclObj> args) {
  try {
//print("return called!"+args+"!");
    ApwtclObj code_obj = null;
    int level = 1;
    int return_code = OK;
    ApwtclObj stack_trace_obj = null;
    ApwtclObj error_code_obj = null;
    ApwtclObj error_info_obj;
    ApwtclObj options_obj = null;

    int num_processed_args = 0;

    if (!initted) {
      command_option_list = new CommandOptionList(interp);
      command_option_list.addOption("-code", RETURN_OPTION_CODE, OPTION_HAS_VALUE, null, null);
      command_option_list.addOption("-errorcode", RETURN_OPTION_ERRORCODE, OPTION_HAS_VALUE, null, null);
      command_option_list.addOption("-errorinfo", RETURN_OPTION_ERRORINFO, OPTION_HAS_VALUE, null, null);
................................................................................
//print("return_code!"+return_code+"!");
    interp.return_level = level;
    if (num_processed_args == args.size() - 1) {
      interp.setResult(args.get(num_processed_args));
    }
//print("+++ RETURN");
    return RETURN;
  } catch(Exception e) {
    e.printStackTrace();
    return ERROR;
  }
  }

}

Changes to src/org/apwtcl/lang/cmd/StringCommand.java.

205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
...
225
226
227
228
229
230
231
232
233
234

235
236
237
238
239
240
241
    }
    interp.setResultInt(interp.string_obj_type.stringLast(needle_str, needle_len, haystack_str, haystack_len, idx));
    return OK;
  }

  /* ==================== stringMapCmd ===================================== */
  public int stringMapCmd(Interp interp, ArrayList<ApwtclObj> args) {
print("string map called");
    ApwtclObj obj_ptr;
    int no_case = 0;
    int idx = 1;

    if (args.size() != 3 && args.size() != 4) {
      interp.wrongNumArgs(1, args, "?-nocase? mapList string");
      return ERROR;
................................................................................
      } else {
        no_case = 1;
        idx++;
      }
    }
    obj_ptr = interp.string_obj_type.stringMap(args.get(idx), args.get(idx + 1), no_case);
    if (obj_ptr == null) {
        return ERROR;
    }
    interp.setResult(obj_ptr);

    return OK;
  }

  /* ==================== stringMatchCmd ===================================== */
  public int stringMatchCmd(Interp interp, ArrayList<ApwtclObj> args) {
//print("string match called");
    int opt_case = 0;







|







 







|


>







205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
...
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
    }
    interp.setResultInt(interp.string_obj_type.stringLast(needle_str, needle_len, haystack_str, haystack_len, idx));
    return OK;
  }

  /* ==================== stringMapCmd ===================================== */
  public int stringMapCmd(Interp interp, ArrayList<ApwtclObj> args) {
//print("string map called");
    ApwtclObj obj_ptr;
    int no_case = 0;
    int idx = 1;

    if (args.size() != 3 && args.size() != 4) {
      interp.wrongNumArgs(1, args, "?-nocase? mapList string");
      return ERROR;
................................................................................
      } else {
        no_case = 1;
        idx++;
      }
    }
    obj_ptr = interp.string_obj_type.stringMap(args.get(idx), args.get(idx + 1), no_case);
    if (obj_ptr == null) {
    	return ERROR;
    }
    interp.setResult(obj_ptr);
//print("string map result!"+obj_ptr+"!");
    return OK;
  }

  /* ==================== stringMatchCmd ===================================== */
  public int stringMatchCmd(Interp interp, ArrayList<ApwtclObj> args) {
//print("string match called");
    int opt_case = 0;

Changes to src/org/apwtcl/lang/cmd/TcltestCommand.java.

164
165
166
167
168
169
170

171
172
173
174
175
176
177
178
179

180
181
182
183
184
185
186
...
192
193
194
195
196
197
198
199
200
201
202
203

204
205
206
207
208
209
210
211
212
213
214
215
216
217







218
219
220
221
222
223
224
225
226
...
254
255
256
257
258
259
260




261
262
263
    TclTest tests_obj = interp.getTclTests();
    tests_obj.setProp("testdir", test_dir);
    return OK;
  }

  /* ==================== tcltestTestCmd ================================== */
  public int tcltestTestCmd(Interp interp, ArrayList<ApwtclObj> args) {

//print("tcltest test called!"+args+"!");
    int i = 1;
    String usage = "test name description ?-option value ...?";
    TestCase tcl_test_case;
    ApwtclObj test_name_ptr;
    ApwtclObj description_ptr;
    Pattern re;
    ApwtclObj option_obj;
    int start_idx;


    if (args.size() - i < 2) {
      interp.wrongNumArgs(2, args, usage);
      return ERROR;
    }
    tcl_test_case = new TestCase(interp);
    test_name_ptr = args.get(i);
................................................................................
    }
    description_ptr = args.get(i);
    i++;
    if (tcl_test_case.setTestProp("test_description", description_ptr) != OK) {
      interp.wrongNumArgs(2, args, usage);
      return ERROR;
    }
    if (args.size() == 6) {
      /* check for old style */
      if ((args.get(i).getString().charAt(0) != '-') && (args.get(i + 1).getString().charAt(0) != '-')) {
        option_obj = interp.string_obj_type.newStringObj("body", -1, "PKG_TCLTESTCMD_9");
        option_obj.incrRefCount("I_PKG_TCLTESTCMD_17");

        if (tcl_test_case.setTestProp(option_obj.getString(), args.get(i++)) != OK) {
          option_obj.decrRefCount("D_PKG_TCLTESTCMD_10");
          return ERROR;
        }
        option_obj.decrRefCount("D_PKG_TCLTESTCMD_11");
        option_obj = interp.string_obj_type.newStringObj("result", -1, "PKG_TCLTESTCMD_10");
        option_obj.incrRefCount("I_PKG_TCLTESTCMD_18");
        if (tcl_test_case.setTestProp(option_obj.getString(), args.get(i++)) != OK) {
          option_obj.decrRefCount("D_PKG_TCLTESTCMD_12");
          return ERROR;
        }
        option_obj.decrRefCount("D_PKG_TCLTESTCMD_13");
      }
    }







    re = Pattern.compile("^[-].*");
    if (args.size() - i  > 0) {
      for (start_idx = i; start_idx < args.size(); start_idx++) {
        String my_arg = args.get(start_idx).getString();
        Matcher m = re.matcher(my_arg);
        if (m.matches()) {
          if (my_arg.equals("--")) {
            start_idx++;
            break;
................................................................................
      } catch(Exception e) {
        interp.setResultString(e.getMessage());
        result = ERROR;
      }
      interp.frame_ptr.ns_ptr = save_ns;
    }
    return result;




  }

}







>









>







 







|

|
|
|
>
|
<
|
|
<
<
<
|
<
|
|
<
|
|
>
>
>
>
>
>
>

|







 







>
>
>
>



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
...
194
195
196
197
198
199
200
201
202
203
204
205
206
207

208
209



210

211
212

213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
...
258
259
260
261
262
263
264
265
266
267
268
269
270
271
    TclTest tests_obj = interp.getTclTests();
    tests_obj.setProp("testdir", test_dir);
    return OK;
  }

  /* ==================== tcltestTestCmd ================================== */
  public int tcltestTestCmd(Interp interp, ArrayList<ApwtclObj> args) {
  try {
//print("tcltest test called!"+args+"!");
    int i = 1;
    String usage = "test name description ?-option value ...?";
    TestCase tcl_test_case;
    ApwtclObj test_name_ptr;
    ApwtclObj description_ptr;
    Pattern re;
    ApwtclObj option_obj;
    int start_idx;
    boolean old_style = false;

    if (args.size() - i < 2) {
      interp.wrongNumArgs(2, args, usage);
      return ERROR;
    }
    tcl_test_case = new TestCase(interp);
    test_name_ptr = args.get(i);
................................................................................
    }
    description_ptr = args.get(i);
    i++;
    if (tcl_test_case.setTestProp("test_description", description_ptr) != OK) {
      interp.wrongNumArgs(2, args, usage);
      return ERROR;
    }
    if (args.size() == 5) {
      /* check for old style */
      ApwtclObj my_arg = args.get(i++);
      ApwtclObj my_arg2 = args.get(i++);
      if ((my_arg.getString().length() > 0) && (my_arg.getString().charAt(0) != '-')) {
    	if ((my_arg2.getString().length() == 0) || ((my_arg2.getString().length() > 0) && (my_arg2.getString().charAt(0) != '-'))) {
          if (tcl_test_case.setTestProp("body", my_arg) != OK) {

            return ERROR;
          }



          if (tcl_test_case.setTestProp("result", my_arg2) != OK) {

            return ERROR;
          }

    	}
      }
//      start_idx = i;
//      if (tcl_test_case.setTestProp(option_obj.getString(), args.get(start_idx + 1)) != OK) {
//          return ERROR;
//        }
//        start_idx++;
      old_style = true;
    }
    re = Pattern.compile("^[-].*");
    if (!old_style && args.size() - i  > 0) {
      for (start_idx = i; start_idx < args.size(); start_idx++) {
        String my_arg = args.get(start_idx).getString();
        Matcher m = re.matcher(my_arg);
        if (m.matches()) {
          if (my_arg.equals("--")) {
            start_idx++;
            break;
................................................................................
      } catch(Exception e) {
        interp.setResultString(e.getMessage());
        result = ERROR;
      }
      interp.frame_ptr.ns_ptr = save_ns;
    }
    return result;
  } catch(Exception e) {
    e.printStackTrace();
    return ERROR;
  }
  }

}

Changes to src/org/apwtcl/lang/objtype/CommandObjType.java.

434
435
436
437
438
439
440

441
442
443
444
445
446
447

448
449
450
451
452
453
454

455
456
457
458
459
460
461
...
516
517
518
519
520
521
522

523
524
525
526

527
528
529
530
531
532
533

//print("callProcedure CMD!"+cmd_ptr.toDebugString()+"!"+argc+"!"+argv+"!");
    /* Check arity */
//print("req_arity!"+argc+"!"+param_info.req_arity+"!");
    if (argc - 1 < param_info.req_arity ||
        (param_info.args_pos < 0 && argc - 1 > param_info.req_arity + param_info.opt_arity)) {
      setWrongArgs(argv.get(0), cmd_ptr);

      return ERROR;
    }

    /* Check if there are too nested calls */
//print("FR!"+intp.frame_ptr.toDebugString()+"!"+intp.max_nesting_depth+"!");
    if (interp.frame_ptr.level == interp.max_nesting_depth) {
      interp.setResultString("Too many nested calls. Infinite recursion?");

      return ERROR;
    }
    /* Create a new call frame */
    ArrayList<CallFrame> frame_ptr_ptr = new ArrayList<CallFrame>();
//print("commandObjType callProcedure PUSF!"+cmd_ptr+"!"+interp.frame_ptr+"!"+interp.var_frame_ptr+"!"+argv+"!");
    int result = interp.namespace_obj_type.pushStackFrame(frame_ptr_ptr, cmd_ptr.ns_ptr, CALL_TYPE_PROC);
    if (result != OK) {

      return ERROR;
    }
    call_frame_ptr = frame_ptr_ptr.get(0);
    call_frame_ptr.argv = argv;
    call_frame_ptr.argc = argc;
    call_frame_ptr.proc_args_obj_ptr = cmd_ptr.proc.arg_list_obj_ptr;
    call_frame_ptr.proc_body_obj_ptr = cmd_ptr.proc.body_obj_ptr;
................................................................................
        retcode = interp.variable_obj_type.setVariable(name_obj_ptr, param_info.arg_list.get(d).default_obj_ptr, var_ptr2);
      }
      if (retcode != OK) {
        bad_arg_set = true;
        break;
      }
    }

    if (!bad_arg_set) {
      /* Eval the body */
//print("commandObjType callProcedure evalObj!"+cmd_ptr+"!"+interp.frame_ptr+"!"+interp.var_frame_ptr+"!");
      retcode = interp.eval_statement.evalObj(cmd_ptr.proc.body_obj_ptr);

    }

    /* Destroy the call frame */
//print("commandObjType callProcedure POSF!");
    interp.namespace_obj_type.popStackFrame();
//    if (callFramePtr.vars.size != JIM_HT_INITIAL_SIZE) {
//        JimFreeCallFrame(interp, callFramePtr, JIM_FCF_NONE);







>







>







>







 







>




>







434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
...
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538

//print("callProcedure CMD!"+cmd_ptr.toDebugString()+"!"+argc+"!"+argv+"!");
    /* Check arity */
//print("req_arity!"+argc+"!"+param_info.req_arity+"!");
    if (argc - 1 < param_info.req_arity ||
        (param_info.args_pos < 0 && argc - 1 > param_info.req_arity + param_info.opt_arity)) {
      setWrongArgs(argv.get(0), cmd_ptr);
print("callProcedure err 1");
      return ERROR;
    }

    /* Check if there are too nested calls */
//print("FR!"+intp.frame_ptr.toDebugString()+"!"+intp.max_nesting_depth+"!");
    if (interp.frame_ptr.level == interp.max_nesting_depth) {
      interp.setResultString("Too many nested calls. Infinite recursion?");
print("callProcedure err 2");
      return ERROR;
    }
    /* Create a new call frame */
    ArrayList<CallFrame> frame_ptr_ptr = new ArrayList<CallFrame>();
//print("commandObjType callProcedure PUSF!"+cmd_ptr+"!"+interp.frame_ptr+"!"+interp.var_frame_ptr+"!"+argv+"!");
    int result = interp.namespace_obj_type.pushStackFrame(frame_ptr_ptr, cmd_ptr.ns_ptr, CALL_TYPE_PROC);
    if (result != OK) {
print("callProcedure err 3");
      return ERROR;
    }
    call_frame_ptr = frame_ptr_ptr.get(0);
    call_frame_ptr.argv = argv;
    call_frame_ptr.argc = argc;
    call_frame_ptr.proc_args_obj_ptr = cmd_ptr.proc.arg_list_obj_ptr;
    call_frame_ptr.proc_body_obj_ptr = cmd_ptr.proc.body_obj_ptr;
................................................................................
        retcode = interp.variable_obj_type.setVariable(name_obj_ptr, param_info.arg_list.get(d).default_obj_ptr, var_ptr2);
      }
      if (retcode != OK) {
        bad_arg_set = true;
        break;
      }
    }
//print("callProcedure bad_arg_set!"+bad_arg_set+"!");
    if (!bad_arg_set) {
      /* Eval the body */
//print("commandObjType callProcedure evalObj!"+cmd_ptr+"!"+interp.frame_ptr+"!"+interp.var_frame_ptr+"!");
      retcode = interp.eval_statement.evalObj(cmd_ptr.proc.body_obj_ptr);
//print("callProcedure retcode!"+retcode+"!"+cmd_ptr.proc.body_obj_ptr+"!");
    }

    /* Destroy the call frame */
//print("commandObjType callProcedure POSF!");
    interp.namespace_obj_type.popStackFrame();
//    if (callFramePtr.vars.size != JIM_HT_INITIAL_SIZE) {
//        JimFreeCallFrame(interp, callFramePtr, JIM_FCF_NONE);

Changes to src/org/apwtcl/lang/objtype/DictObjType.java.

560
561
562
563
564
565
566
567
568
569
570
        interp.dict_obj_type.dictKey(dict_obj_ptr, key_obj_ptr, res_obj_ptr, FUNCTION_FLAGS_NONE);
      }
    }
    return res_obj;
  }

  /* ==================== isDict ================================== */
  boolean isDict(ApwtclObj obj_ptr) {
    return (obj_ptr.obj_type == OBJ_TYPE_DICT);
  }
}







|



560
561
562
563
564
565
566
567
568
569
570
        interp.dict_obj_type.dictKey(dict_obj_ptr, key_obj_ptr, res_obj_ptr, FUNCTION_FLAGS_NONE);
      }
    }
    return res_obj;
  }

  /* ==================== isDict ================================== */
  public boolean isDict(ApwtclObj obj_ptr) {
    return (obj_ptr.obj_type == OBJ_TYPE_DICT);
  }
}

Changes to src/org/apwtcl/lang/objtype/ItclObjType.java.

338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361

362
363
364
365
366
367
368
369
370

371
372
373
374
375
376
377
378
379
380
381
382
...
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487




488
489
490
491
492
493
494
...
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
...
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
...
588
589
590
591
592
593
594

595

596
597
598
599
600
601
602
...
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
...
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
      if (interp.curr_class_info.variables.get(escapeKey(my_name)) != null) {
        interp.setResultString(kind+" "+my_name+" is already defined for "+getItclClassTypeString(class_info.class_type)+" \""+class_info.class_name+"\"");
        return ERROR;
      }
      ItclVariable var_info = new ItclVariable(interp, protection, kind_val, my_name, my_args, class_info);
      interp.curr_class_info.variables.put(escapeKey(my_name), var_info);
      break;
    case ITCL_PROC:
    case ITCL_TYPEMETHOD:
    case ITCL_METHOD:
      if (interp.curr_class_info.functions.get(escapeKey(my_name)) != null) {
        interp.setResultString(kind+" "+my_name+" is already defined for "+getItclClassTypeString(class_info.class_type)+" \""+class_info.class_name+"\"");
        return ERROR;
      }
      ItclFunction fcn_info = new ItclFunction(interp, protection, kind_val, my_name, class_info);
      if (fcn_info.storeFunctionInfo(my_args) != OK) {
        return ERROR;
      }
      interp.curr_class_info.functions.put(escapeKey(my_name), fcn_info);
      break;
    case ITCL_OPTION:
print("ITCL_OPTION1!");
      if (interp.curr_class_info.options.get(escapeKey(my_name)) != null) {
        interp.setResultString(kind+" "+my_name+" is already defined for "+getItclClassTypeString(class_info.class_type)+" \""+class_info.class_name+"\"");

        return ERROR;
      }
print("ITCL_OPTION2!");
      ItclOption opt_info = new ItclOption(interp, protection, kind_val, my_name_ptr, class_info);
      if (opt_info == null) {
        return ERROR;
      }
print("ITCL_OPTION3!");
      if (opt_info.storeOptionInfo(my_args) != OK) {

          return ERROR;
      }
print("ITCL_OPTION4!");
      interp.curr_class_info.options.put(escapeKey(opt_info.option_name), opt_info);
print("ITCL_OPTION5!");
      break;
    case ITCL_COMPONENT:
    case ITCL_TYPECOMPONENT:
      if (interp.curr_class_info.components.get(escapeKey(my_name)) != null) {
        interp.setResultString(kind+" "+my_name+" is already defined for "+getItclClassTypeString(class_info.class_type)+" \""+class_info.class_name+"\"");
        return ERROR;
      }
................................................................................
    if (args.size() == 0) {
      interp.setResultString(usage);
      return ERROR;
    }
//print("class_name!"+class_name+"!"+interp.frame_ptr.ns_ptr+"!"+interp.frame_ptr.ns_ptr.parent_namespace+"!");
    if (! (class_name.charAt(0) == ':' && class_name.charAt(1) == ':')) {
      ns_ptr = interp.global_ns_ptr.getNamespace(interp.frame_ptr.ns_ptr.full_name+"::"+class_name);
     if (ns_ptr == null) {
       /* try one namespace level up */
       String head = interp.namespace_obj_type.nsHead(interp.frame_ptr.ns_ptr.full_name);
      if (head.equals("::")) {
        ns_ptr = interp.global_ns_ptr.getNamespace(head+class_name);
      } else {
        ns_ptr = interp.global_ns_ptr.getNamespace(head+"::"+class_name);
      }
     }
    } else {
      ns_ptr = interp.global_ns_ptr.getNamespace(class_name);




    }
    class_name = ns_ptr.name;
    cmd_obj = interp.global_ns_ptr.getClassCommand(ns_ptr, cmd_name, class_only);
    if (cmd_obj == null) {
      /* command not found seems to be creation of a class */
      Pattern re = Pattern.compile("(.*)(#auto)(.*)");
      Matcher res = re.matcher(cmd_name);
................................................................................
        re = Pattern.compile("(.*)(%AUTO%)(.*)");
        res = re.matcher(cmd_name);
      }
      if (res.matches()) {
        String head = res.group(1);
        String trailer = res.group(3);
        class_name = this.class_name.getString();
        String my_class_name = class_name.substring(0,1).toLowerCase()+class_name.substring(1);
        while (true) {
          int cnt = ns_ptr.getAutoCount();
          cmd_obj = null;

          cmd_name = head+ns_ptr.name+cnt+trailer;
          try {
            cmd_obj = interp.command_obj_type.getCommand(cmd_name_ptr, 0);
................................................................................
      case ITCL_CLASS:
      case ITCL_EXTENDED_CLASS:
        break;
      }
    } else {
      Command cmd_ptr = null;
//print("classCommand 3!"+args+"!");
//print("cmd!"+cmd_obj+"!");
      if (cmd_obj.ns_ptr.resolve_commands.get(escapeKey(cmd_name)) != null) {
        cmd_ptr = cmd_obj.ns_ptr.resolve_commands.get(escapeKey(cmd_name));
      }
      if (cmd_ptr == null) {
        Namespace my_ns = interp.global_ns_ptr.getNamespace("::itcl::internal");
        HashMap<String, Command> commands = my_ns.cmd_procs;
        if (commands.get(escapeKey("class"+cmd_name)) != null) {
................................................................................
//print("CMD_PTR!"+cmd_ptr+"!"+itcl.interp.frame_ptr.toDebugString()+"!");
        if (cmd_ptr.is_proc) {
          my_args.add(args.get(1));
          for (int k = 2; k < args.size(); k++) {
            my_args.add(args.get(k));
            args.get(k).incrRefCount("I_ITCL_OBJ_TYPE_5");
          }

          retcode = (Integer)cmd_ptr.call(interp, my_args, /* ensemble_expand */ true);

          return retcode;
        } else {
           my_args.add(args.get(0));
           my_args.add(args.get(1));
           for (int k = 2; k < args.size(); k++) {
             my_args.add(args.get(k));
             args.get(k).incrRefCount("I_ITCL_OBJ_TYPE_6");
................................................................................
       * and if we have a delegation for methods
       */
      ItclClass class_ptr = class_object.class_info;
      String to_part = null;
      ItclDelegate dlg_info;
      if (class_ptr.delegated_methods.get(escapeKey(fcn_name)) != null) {
        dlg_info = class_ptr.delegated_methods.get(escapeKey(fcn_name));
        to_part = dlg_info.to_part;
      }
      if (class_ptr.delegated_methods.get("*") != null) {
        dlg_info = class_ptr.delegated_methods.get("*");
        to_part = dlg_info.to_part;
      }
      if (to_part != null) {
        Variable var_ptr = class_object.variables.get(escapeKey(to_part));
        ItclObject obj2 = interp.class_objects.get(escapeKey(var_ptr.obj_ptr.getString()));
        my_args = new ArrayList<ApwtclObj>();
        my_args.add(interp.string_obj_type.newStringObj(obj2.object_name, -1, "ITCL_OBJ_TYPE_4"));
        my_args.add(interp.string_obj_type.newStringObj(fcn_name, -1, "ITCL_OBJ_TYPE_5"));
................................................................................
//print("cmd_obj4!"+cmd_obj.toDebugString()+"!");
      if (cmd_obj.is_proc) {
//        ret_code = (Integer)cmd_obj.call(interp, my_args, /* ensemble_expand */ true);
        ret_code = interp.command_obj_type.callProcedure(cmd_obj, null, 0, my_args.size(), my_args);
      } else {
        /* Create a new call frame */
        ArrayList<CallFrame>frame_ptr_ptr = new ArrayList<CallFrame>();
print("itclObjType callClassCommand PUSF");
        int result = interp.namespace_obj_type.pushStackFrame(frame_ptr_ptr, ns_ptr, CALL_TYPE_PROC);
        if (result != OK) {
          return ERROR;
        }
        /* Check if there are too nested calls */
//print("FR!"+i_obj.intp.frame_ptr.toDebugString()+"!"+i_obj.interp.max_nesting_depth+"!");
        interp.cmd_priv_data = cmd_obj.native_fcn.privdata;







|
|












<


>


<

<
<
<
<

>


<

<







 







|
|
|
|
|
|
|
|
|


>
>
>
>







 







|







 







|







 







>
|
>







 







|



|







 







|







338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358

359
360
361
362
363

364




365
366
367
368

369

370
371
372
373
374
375
376
...
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
...
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
...
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
...
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
...
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
...
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
      if (interp.curr_class_info.variables.get(escapeKey(my_name)) != null) {
        interp.setResultString(kind+" "+my_name+" is already defined for "+getItclClassTypeString(class_info.class_type)+" \""+class_info.class_name+"\"");
        return ERROR;
      }
      ItclVariable var_info = new ItclVariable(interp, protection, kind_val, my_name, my_args, class_info);
      interp.curr_class_info.variables.put(escapeKey(my_name), var_info);
      break;
    case ITCL_TYPEMETHOD:
    case ITCL_PROC:
    case ITCL_METHOD:
      if (interp.curr_class_info.functions.get(escapeKey(my_name)) != null) {
        interp.setResultString(kind+" "+my_name+" is already defined for "+getItclClassTypeString(class_info.class_type)+" \""+class_info.class_name+"\"");
        return ERROR;
      }
      ItclFunction fcn_info = new ItclFunction(interp, protection, kind_val, my_name, class_info);
      if (fcn_info.storeFunctionInfo(my_args) != OK) {
        return ERROR;
      }
      interp.curr_class_info.functions.put(escapeKey(my_name), fcn_info);
      break;
    case ITCL_OPTION:

      if (interp.curr_class_info.options.get(escapeKey(my_name)) != null) {
        interp.setResultString(kind+" "+my_name+" is already defined for "+getItclClassTypeString(class_info.class_type)+" \""+class_info.class_name+"\"");
print("ITCL_OPTION err 2!");
        return ERROR;
      }

      ItclOption opt_info = new ItclOption(interp, protection, kind_val, my_name_ptr, class_info);




      if (opt_info.storeOptionInfo(my_args) != OK) {
print("ITCL_OPTION err 3!");
          return ERROR;
      }

      interp.curr_class_info.options.put(escapeKey(opt_info.option_name), opt_info);

      break;
    case ITCL_COMPONENT:
    case ITCL_TYPECOMPONENT:
      if (interp.curr_class_info.components.get(escapeKey(my_name)) != null) {
        interp.setResultString(kind+" "+my_name+" is already defined for "+getItclClassTypeString(class_info.class_type)+" \""+class_info.class_name+"\"");
        return ERROR;
      }
................................................................................
    if (args.size() == 0) {
      interp.setResultString(usage);
      return ERROR;
    }
//print("class_name!"+class_name+"!"+interp.frame_ptr.ns_ptr+"!"+interp.frame_ptr.ns_ptr.parent_namespace+"!");
    if (! (class_name.charAt(0) == ':' && class_name.charAt(1) == ':')) {
      ns_ptr = interp.global_ns_ptr.getNamespace(interp.frame_ptr.ns_ptr.full_name+"::"+class_name);
      if (ns_ptr == null) {
        /* try one namespace level up */
        String head = interp.namespace_obj_type.nsQualifiers(interp.frame_ptr.ns_ptr.full_name);
        if (head.equals("::")) {
          ns_ptr = interp.global_ns_ptr.getNamespace(head+class_name);
        } else {
          ns_ptr = interp.global_ns_ptr.getNamespace(head+"::"+class_name);
        }
      }
    } else {
      ns_ptr = interp.global_ns_ptr.getNamespace(class_name);
    }
    if (ns_ptr == null) {
      interp.setResultString("INTERNAL ERROR in classCommand: namespace not found for: "+class_name+"!");
      return ERROR;
    }
    class_name = ns_ptr.name;
    cmd_obj = interp.global_ns_ptr.getClassCommand(ns_ptr, cmd_name, class_only);
    if (cmd_obj == null) {
      /* command not found seems to be creation of a class */
      Pattern re = Pattern.compile("(.*)(#auto)(.*)");
      Matcher res = re.matcher(cmd_name);
................................................................................
        re = Pattern.compile("(.*)(%AUTO%)(.*)");
        res = re.matcher(cmd_name);
      }
      if (res.matches()) {
        String head = res.group(1);
        String trailer = res.group(3);
        class_name = this.class_name.getString();
//        String my_class_name = class_name.substring(0,1).toLowerCase()+class_name.substring(1);
        while (true) {
          int cnt = ns_ptr.getAutoCount();
          cmd_obj = null;

          cmd_name = head+ns_ptr.name+cnt+trailer;
          try {
            cmd_obj = interp.command_obj_type.getCommand(cmd_name_ptr, 0);
................................................................................
      case ITCL_CLASS:
      case ITCL_EXTENDED_CLASS:
        break;
      }
    } else {
      Command cmd_ptr = null;
//print("classCommand 3!"+args+"!");
print("classCommand cmd!"+cmd_obj+"!"+cmd_obj.ns_ptr+"!");
      if (cmd_obj.ns_ptr.resolve_commands.get(escapeKey(cmd_name)) != null) {
        cmd_ptr = cmd_obj.ns_ptr.resolve_commands.get(escapeKey(cmd_name));
      }
      if (cmd_ptr == null) {
        Namespace my_ns = interp.global_ns_ptr.getNamespace("::itcl::internal");
        HashMap<String, Command> commands = my_ns.cmd_procs;
        if (commands.get(escapeKey("class"+cmd_name)) != null) {
................................................................................
//print("CMD_PTR!"+cmd_ptr+"!"+itcl.interp.frame_ptr.toDebugString()+"!");
        if (cmd_ptr.is_proc) {
          my_args.add(args.get(1));
          for (int k = 2; k < args.size(); k++) {
            my_args.add(args.get(k));
            args.get(k).incrRefCount("I_ITCL_OBJ_TYPE_5");
          }
print("IOC!"+cmd_ptr+"!"+my_args+"!");
//          retcode = (Integer)cmd_ptr.call(interp, my_args, /* ensemble_expand */ true);
          retcode = (Integer)interp.command_obj_type.callProcedure(cmd_ptr, null, 0, my_args.size(), my_args);
          return retcode;
        } else {
           my_args.add(args.get(0));
           my_args.add(args.get(1));
           for (int k = 2; k < args.size(); k++) {
             my_args.add(args.get(k));
             args.get(k).incrRefCount("I_ITCL_OBJ_TYPE_6");
................................................................................
       * and if we have a delegation for methods
       */
      ItclClass class_ptr = class_object.class_info;
      String to_part = null;
      ItclDelegate dlg_info;
      if (class_ptr.delegated_methods.get(escapeKey(fcn_name)) != null) {
        dlg_info = class_ptr.delegated_methods.get(escapeKey(fcn_name));
        to_part = dlg_info.to_part.getString();
      }
      if (class_ptr.delegated_methods.get("*") != null) {
        dlg_info = class_ptr.delegated_methods.get("*");
        to_part = dlg_info.to_part.getString();
      }
      if (to_part != null) {
        Variable var_ptr = class_object.variables.get(escapeKey(to_part));
        ItclObject obj2 = interp.class_objects.get(escapeKey(var_ptr.obj_ptr.getString()));
        my_args = new ArrayList<ApwtclObj>();
        my_args.add(interp.string_obj_type.newStringObj(obj2.object_name, -1, "ITCL_OBJ_TYPE_4"));
        my_args.add(interp.string_obj_type.newStringObj(fcn_name, -1, "ITCL_OBJ_TYPE_5"));
................................................................................
//print("cmd_obj4!"+cmd_obj.toDebugString()+"!");
      if (cmd_obj.is_proc) {
//        ret_code = (Integer)cmd_obj.call(interp, my_args, /* ensemble_expand */ true);
        ret_code = interp.command_obj_type.callProcedure(cmd_obj, null, 0, my_args.size(), my_args);
      } else {
        /* Create a new call frame */
        ArrayList<CallFrame>frame_ptr_ptr = new ArrayList<CallFrame>();
//print("itclObjType callClassCommand PUSF");
        int result = interp.namespace_obj_type.pushStackFrame(frame_ptr_ptr, ns_ptr, CALL_TYPE_PROC);
        if (result != OK) {
          return ERROR;
        }
        /* Check if there are too nested calls */
//print("FR!"+i_obj.intp.frame_ptr.toDebugString()+"!"+i_obj.interp.max_nesting_depth+"!");
        interp.cmd_priv_data = cmd_obj.native_fcn.privdata;

Changes to src/org/apwtcl/lang/objtype/StringObjType.java.

75
76
77
78
79
80
81

82
83
84
85
86







87
88
89
90
91
92
93
94
...
176
177
178
179
180
181
182



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215

216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244

245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264

  /* ==================== getString ================================== */
  /* Return the string representation for obj_ptr. If the object
   * string representation is invalid, calls the method to create
   * a new one starting from the internal representation of the object.
   */
  public String getString(ApwtclObj obj_ptr) {

    if (obj_ptr.bytes == null) {
      /* Invalid string repr. Generate it. */
//      panic(obj_ptr.obj_type.updateString != "function", "UpdateStringProc called against '"+getObjTypeString(obj_ptr.obj_type));
      obj_ptr.updateString();
    }







    return obj_ptr.bytes.substring(0, obj_ptr.len);
  }

  /* ==================== getStringLength ================================== */
  public int getStringLength(ApwtclObj obj_ptr) {
    return obj_ptr.len;
  }

................................................................................
  /* ==================== appendString ================================== */
  /* Higher level API to append strings to objects. */
  public int appendString(ApwtclObj obj_ptr, String str, int len) {
    panic(obj_ptr.isShared(), "appendString called with shared object");
    if (obj_ptr.obj_type != OBJ_TYPE_STRING) {
      setFromAny(obj_ptr);
    }



    _appendString(obj_ptr, str, len);
    return OK;
  }
  /* ==================== stringMap ================================== */
  /* does the [string map] operation. On error null is returned,
   * otherwise a new string object with the result, having refcount = 0,
   * is returned.
   */

  public ApwtclObj stringMap(ApwtclObj map_list_obj_ptr, ApwtclObj obj_ptr, int no_case) {
/*
    int num_maps;
    String str;
    int no_match_start = 0;
    int str_len;
    int i;
    int idx = 0;
    ApwtclObj result_obj_ptr;

    num_maps = interp.list_obj_type.listLength(map_list_obj_ptr);
    if (num_maps % 2) {
      obj.interp.setResultString("list must contain an even number of elements");
      return null;
    }
    str = obj_ptr.getString();
    str_len = obj_ptr.utf8_length(obj_ptr);
    /* Map it */
/*
    result_obj_ptr = interp.string_obj_type.newStringObj("", 0, "STRING_OBJ_TYPE_1");
    while (str_len) {
      for (i = 0; i < num_maps; i += 2) {
        Object my_obj_ptr = new Array();
        int k;

        int kl;

        interp.list_obj_type.listIndex(map_list_obj_ptr, i, my_obj_ptr, FUNCTION_FLAGS_NONE);
        k = my_obj_ptr[0].getString();
        kl = my_obj_ptr[0].utf8_length(my_obj_ptr[0]);
        if (str_len >= kl && kl) {
          int rc;

          if (no_case) {
            rc = interp.default_obj.StringCompareNoCase(str.substring(idx), k, kl);
          } else {
            rc = interp.default_obj.StringCompare(str.substring(idx), kl, k, kl);
          }
          if (rc == 0) {
            if (no_match_start >= 0) {
              AppendString(result_obj_ptr, str.substring(no_match_start), idx - no_match_start);
              no_match_start = idx + kl;
            }
            obj.interp.list_obj_type.ListIndex(map_list_obj_ptr, i + 1, my_obj_ptr, FUNCTION_FLAGS_NONE);
            AppendObj(result_obj_ptr, my_obj_ptr[0]);
            idx += interp.default_obj.utf8_index(str.substring(idx), kl);
            str_len -= kl;
            break;
          }
        }
      }
      if (i == num_maps) {     /* no match */
/*
        Object c = new Array();

        if (no_match_start == -1) {
          no_match_start = 0;
	}
        idx += interp.default_obj.utf8_tounicode(str.substring(idx), c);
        str_len--;
      }
    }
    if (no_match_start >= 0) {
      AppendString(result_obj_ptr, str.substring(no_match_start), idx - no_match_start);
    }
    return result_obj_ptr;
*/
return null;
  }

  /* ==================== parseDouble ================================== */
/*
  public double parseDouble(String value) {
*/
//    value = value.match(/^-?\d*/)[0];







>
|


<
<
>
>
>
>
>
>
>
|







 







>
>
>










<









|
|





<

|

|
<
>



|
|
|


|
|

|



|


|
|







<
<
>


|
|




|


<
<







75
76
77
78
79
80
81
82
83
84
85


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201

202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217

218
219
220
221

222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249


250
251
252
253
254
255
256
257
258
259
260
261


262
263
264
265
266
267
268

  /* ==================== getString ================================== */
  /* Return the string representation for obj_ptr. If the object
   * string representation is invalid, calls the method to create
   * a new one starting from the internal representation of the object.
   */
  public String getString(ApwtclObj obj_ptr) {
return obj_ptr.getString();
//    if (obj_ptr.bytes == null) {
      /* Invalid string repr. Generate it. */
//      panic(obj_ptr.obj_type.updateString != "function", "UpdateStringProc called against '"+getObjTypeString(obj_ptr.obj_type));


//      obj_ptr.getString();
//print("OO!"+obj_ptr.toDebugString()+"!");
//      obj_ptr.bytes = new StringBuffer("");
//    }
//    if (obj_ptr.value2 == null) {
//      obj_ptr.strValue_SetCharLength(obj_ptr.len);	
//    }
//    return obj_ptr.bytes.substring(0, obj_ptr.len);
  }

  /* ==================== getStringLength ================================== */
  public int getStringLength(ApwtclObj obj_ptr) {
    return obj_ptr.len;
  }

................................................................................
  /* ==================== appendString ================================== */
  /* Higher level API to append strings to objects. */
  public int appendString(ApwtclObj obj_ptr, String str, int len) {
    panic(obj_ptr.isShared(), "appendString called with shared object");
    if (obj_ptr.obj_type != OBJ_TYPE_STRING) {
      setFromAny(obj_ptr);
    }
if (obj_ptr.value2 == null) {
print("VAL2 NULL!"+obj_ptr.toDebugString()+"!");
}
    _appendString(obj_ptr, str, len);
    return OK;
  }
  /* ==================== stringMap ================================== */
  /* does the [string map] operation. On error null is returned,
   * otherwise a new string object with the result, having refcount = 0,
   * is returned.
   */

  public ApwtclObj stringMap(ApwtclObj map_list_obj_ptr, ApwtclObj obj_ptr, int no_case) {

    int num_maps;
    String str;
    int no_match_start = 0;
    int str_len;
    int i;
    int idx = 0;
    ApwtclObj result_obj_ptr;

    num_maps = interp.list_obj_type.listLength(map_list_obj_ptr);
    if (num_maps % 2 != 0) {
      interp.setResultString("list must contain an even number of elements");
      return null;
    }
    str = obj_ptr.getString();
    str_len = obj_ptr.utf8_length(obj_ptr);
    /* Map it */

    result_obj_ptr = interp.string_obj_type.newStringObj("", 0, "STRING_OBJ_TYPE_1");
    while (str_len > 0) {
      for (i = 0; i < num_maps; i += 2) {
        ArrayList<ApwtclObj> my_obj_ptr = new ArrayList<ApwtclObj>();

        String k;
        int kl;

        interp.list_obj_type.listIndex(map_list_obj_ptr, i, my_obj_ptr, FUNCTION_FLAGS_NONE);
        k = my_obj_ptr.get(0).getString();
        kl = my_obj_ptr.get(0).utf8_length(my_obj_ptr.get(0));
        if (str_len >= kl && kl!= 0) {
          int rc;

          if (no_case != 0) {
            rc = interp.default_obj.stringCompareNoCase(str.substring(idx), k, kl);
          } else {
            rc = interp.default_obj.stringCompare(str.substring(idx), kl, k, kl);
          }
          if (rc == 0) {
            if (no_match_start >= 0) {
              appendString(result_obj_ptr, str.substring(no_match_start), idx - no_match_start);
              no_match_start = idx + kl;
            }
            interp.list_obj_type.listIndex(map_list_obj_ptr, i + 1, my_obj_ptr, FUNCTION_FLAGS_NONE);
            appendObj(result_obj_ptr, my_obj_ptr.get(0));
            idx += interp.default_obj.utf8_index(str.substring(idx), kl);
            str_len -= kl;
            break;
          }
        }
      }
      if (i == num_maps) {     /* no match */


        ArrayList<Character> c_ptr = new ArrayList<Character>();
        if (no_match_start == -1) {
          no_match_start = 0;
        }
        idx += interp.default_obj.utf8_tounicode(str.substring(idx), c_ptr);
        str_len--;
      }
    }
    if (no_match_start >= 0) {
      appendString(result_obj_ptr, str.substring(no_match_start), idx - no_match_start);
    }
    return result_obj_ptr;


  }

  /* ==================== parseDouble ================================== */
/*
  public double parseDouble(String value) {
*/
//    value = value.match(/^-?\d*/)[0];

Changes to src/org/apwtcl/lang/objtype/VariableObjType.java.

91
92
93
94
95
96
97

98

99
100
101
102
103
104
105
...
182
183
184
185
186
187
188
189
190
191
192
193

194
195
196
197
198
199
200
....
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
   * a variable name, but syntax glue for [dict] (array) i.e. the last
   * character is ')'
   */
  public int setFromAny(ApwtclObj obj_ptr, ArrayList<String>err_msg_ptr_ptr) {
    String var_name;
    CallFrame frame_ptr = interp.frame_ptr;


//print("varobjtype sFA1!"+obj_ptr+"!");

    /* Check if the object is already an uptodate variable */
    if (obj_ptr.obj_type == OBJ_TYPE_VARIABLE) {
//print("varobjtype sFA2!"+obj_ptr.varValue_GetNamespace()+"!"+obj_ptr.toDebugString()+"!");
      if ((obj_ptr.varValue_GetCallFrame() == frame_ptr)
          || (obj_ptr.varValue_GetNamespace() == frame_ptr.ns_ptr)) {
            var_name = obj_ptr.getString();
//print("varobjtype sFA3!"+interp.frame_ptr+"!"+Variable.oid+"!"+interp.frame_ptr.variable_cache+"!");
................................................................................

  public int setVariable(ApwtclObj name_obj_ptr, ApwtclObj val_obj_ptr, ArrayList<Variable> result_var_ptr) {
    String name;
    Variable var_ptr;
    boolean create = true;
    int err;
    ArrayList<String> err_msg_ptr = new ArrayList<String>();
if (name_obj_ptr.getString().equals("extrainits")) {
dbg = 0;
} else {
dbg = 0;
}

if (dbg != 0) {
print("setVariable1!"+name_obj_ptr+"!"+val_obj_ptr+"!"+interp.frame_ptr+"!"+interp.var_frame_ptr+"!");
}

    if ((err = setFromAny(name_obj_ptr, err_msg_ptr)) != OK) {
if (dbg != 0) {
print("setVariable NOT OK");
................................................................................
     *       "namespace eval" or "namespace inscope" command,
     *    4) the name has namespace qualifiers ("::"s).
     * Otherwise, if var_name is a local variable, search in the call frame variables
     *
     * If create and the variable isn't found, create the variable
     */
if (dbg != 0) {
print("LL!"+((flags & (NAMESPACE_LOOKUP_GLOBAL_ONLY | NAMESPACE_LOOKUP_NAMESPACE_ONLY)) != 0)+"!"+!var_frame_ptr.hasLocalVars()+"!"+var_name.matches("::.*")+"!");
print("CF!"+var_frame_ptr+"!");
}
    if (((flags & (NAMESPACE_LOOKUP_GLOBAL_ONLY | NAMESPACE_LOOKUP_NAMESPACE_ONLY)) != 0)
        || !var_frame_ptr.hasLocalVars()
        || var_name.matches("::.*")) {
      boolean look_global = ((flags & NAMESPACE_LOOKUP_GLOBAL_ONLY) != 0)
        || (ctx_ns_ptr == interp.global_ns_ptr)
        || ((var_name.charAt(0) == ':') && (var_name.charAt(1) == ':'));
if (variable_debug > 1 || dbg != 0) {
print("look_gobal!"+look_global+"!"+var_frame_ptr.hasLocalVars()+"!"+var_frame_ptr.toDebugString()+"!");
}
      if (look_global) {







>
|
>







 







|
|
|
|
<
>







 







|




|







91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
184
185
186
187
188
189
190
191
192
193
194

195
196
197
198
199
200
201
202
....
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
   * a variable name, but syntax glue for [dict] (array) i.e. the last
   * character is ')'
   */
  public int setFromAny(ApwtclObj obj_ptr, ArrayList<String>err_msg_ptr_ptr) {
    String var_name;
    CallFrame frame_ptr = interp.frame_ptr;

if (dbg != 0) {
print("varobjtype sFA1!"+obj_ptr+"!");
}
    /* Check if the object is already an uptodate variable */
    if (obj_ptr.obj_type == OBJ_TYPE_VARIABLE) {
//print("varobjtype sFA2!"+obj_ptr.varValue_GetNamespace()+"!"+obj_ptr.toDebugString()+"!");
      if ((obj_ptr.varValue_GetCallFrame() == frame_ptr)
          || (obj_ptr.varValue_GetNamespace() == frame_ptr.ns_ptr)) {
            var_name = obj_ptr.getString();
//print("varobjtype sFA3!"+interp.frame_ptr+"!"+Variable.oid+"!"+interp.frame_ptr.variable_cache+"!");
................................................................................

  public int setVariable(ApwtclObj name_obj_ptr, ApwtclObj val_obj_ptr, ArrayList<Variable> result_var_ptr) {
    String name;
    Variable var_ptr;
    boolean create = true;
    int err;
    ArrayList<String> err_msg_ptr = new ArrayList<String>();
//if (name_obj_ptr.getString().equals("extrainits")) {
//dbg = 0;
//} else {
//dbg = 0;

//}
if (dbg != 0) {
print("setVariable1!"+name_obj_ptr+"!"+val_obj_ptr+"!"+interp.frame_ptr+"!"+interp.var_frame_ptr+"!");
}

    if ((err = setFromAny(name_obj_ptr, err_msg_ptr)) != OK) {
if (dbg != 0) {
print("setVariable NOT OK");
................................................................................
     *       "namespace eval" or "namespace inscope" command,
     *    4) the name has namespace qualifiers ("::"s).
     * Otherwise, if var_name is a local variable, search in the call frame variables
     *
     * If create and the variable isn't found, create the variable
     */
if (dbg != 0) {
print("LL!"+((flags & (NAMESPACE_LOOKUP_GLOBAL_ONLY | NAMESPACE_LOOKUP_NAMESPACE_ONLY)) != 0)+"!"+!var_frame_ptr.hasLocalVars()+"!"+(var_name.indexOf("::") >= 0)+"!");
print("CF!"+var_frame_ptr+"!");
}
    if (((flags & (NAMESPACE_LOOKUP_GLOBAL_ONLY | NAMESPACE_LOOKUP_NAMESPACE_ONLY)) != 0)
        || !var_frame_ptr.hasLocalVars()
        || var_name.indexOf("::")>= 0) {
      boolean look_global = ((flags & NAMESPACE_LOOKUP_GLOBAL_ONLY) != 0)
        || (ctx_ns_ptr == interp.global_ns_ptr)
        || ((var_name.charAt(0) == ':') && (var_name.charAt(1) == ':'));
if (variable_debug > 1 || dbg != 0) {
print("look_gobal!"+look_global+"!"+var_frame_ptr.hasLocalVars()+"!"+var_frame_ptr.toDebugString()+"!");
}
      if (look_global) {