APWTCL Arnulf's Preferred Web Tcl

Check-in [544886fc2f]
Login

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

Overview
Comment:fixes
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:544886fc2f678c853368bd7359284baef60f7893
User & Date: arnulf 2012-04-20 22:46:19
Context
2012-04-20
22:48
fixes. This version runs the wtk test suite completely with success check-in: 852e328e3b user: arnulf tags: trunk
22:46
fixes check-in: 544886fc2f user: arnulf tags: trunk
21:25
fixes and add separate namespace for every type instance as selfns check-in: de8a7b84ad user: arnulf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

1357
1358
1359
1360
1361
1362
1363

1364
1365
1366
1367
1368

1369
1370
1371
1372
1373
1374
1375
....
1387
1388
1389
1390
1391
1392
1393

1394
1395
1396
1397
1398
1399
1400
   * If maxchars is -1, compares to end of string.
   * Otherwise compares at most 'max_chars' characters.
   */
  public int stringCompareNoCase(String s1, String s2, int max_chars) {
    int idx1 = 0;
    int idx2 = 0;


    while (idx1 < s1.length() && idx2 < s2.length() && max_chars != 0) {
      ArrayList<Character> c1_ptr = new ArrayList<Character>();
      ArrayList<Character> c2_ptr = new ArrayList<Character>();
      idx1 += utf8_tounicode_case(s1.charAt(idx1), c1_ptr, 1);
      idx2 += utf8_tounicode_case(s2.charAt(idx2), c2_ptr, 1);

      if (c1_ptr.get(0) != c2_ptr.get(0)) {
        char c1 = c1_ptr.get(0);
        char c2 = c2_ptr.get(0);
        return getSign(c1 - c2);
      }
      max_chars--;
    }
................................................................................
  }

  /* ==================== stringCompare ===================================== */
  public int stringCompare(String s1, int l1, String s2, int l2) {
    int idx1 = 0;
    int idx2 = 0;


    while (idx1 < l1 && idx2 < l2) {
      ArrayList<Character> c1_ptr = new ArrayList<Character>();
      ArrayList<Character> c2_ptr = new ArrayList<Character>();
      idx1 += utf8_tounicode_case(s1.charAt(idx1), c1_ptr, 1);
      idx2 += utf8_tounicode_case(s2.charAt(idx2), c2_ptr, 1);
      if (c1_ptr.get(0) != c2_ptr.get(0)) {
        char c1 = c1_ptr.get(0);







>





>







 







>







1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
....
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
   * If maxchars is -1, compares to end of string.
   * Otherwise compares at most 'max_chars' characters.
   */
  public int stringCompareNoCase(String s1, String s2, int max_chars) {
    int idx1 = 0;
    int idx2 = 0;

//print("stringCompareNoCase");
    while (idx1 < s1.length() && idx2 < s2.length() && max_chars != 0) {
      ArrayList<Character> c1_ptr = new ArrayList<Character>();
      ArrayList<Character> c2_ptr = new ArrayList<Character>();
      idx1 += utf8_tounicode_case(s1.charAt(idx1), c1_ptr, 1);
      idx2 += utf8_tounicode_case(s2.charAt(idx2), c2_ptr, 1);
//print("idx1!"+idx1+"!"+idx2+"!"+c1_ptr.get(0)+"!"+c2_ptr.get(0)+"!");
      if (c1_ptr.get(0) != c2_ptr.get(0)) {
        char c1 = c1_ptr.get(0);
        char c2 = c2_ptr.get(0);
        return getSign(c1 - c2);
      }
      max_chars--;
    }
................................................................................
  }

  /* ==================== stringCompare ===================================== */
  public int stringCompare(String s1, int l1, String s2, int l2) {
    int idx1 = 0;
    int idx2 = 0;

//print("stringCompare!"+s1+"!"+l1+"!"+s2+"!"+l2+"!");
    while (idx1 < l1 && idx2 < l2) {
      ArrayList<Character> c1_ptr = new ArrayList<Character>();
      ArrayList<Character> c2_ptr = new ArrayList<Character>();
      idx1 += utf8_tounicode_case(s1.charAt(idx1), c1_ptr, 1);
      idx2 += utf8_tounicode_case(s2.charAt(idx2), c2_ptr, 1);
      if (c1_ptr.get(0) != c2_ptr.get(0)) {
        char c1 = c1_ptr.get(0);

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

205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
    }
    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;







|







205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
    }
    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!"+args+"!");
    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;

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

434
435
436
437
438
439
440
441
442
443
444
445
446
447
448

//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!"+cmd_ptr.toDebugString()+"!"+argv+"!");
      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?");







|







434
435
436
437
438
439
440
441
442
443
444
445
446
447
448

//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!"+cmd_ptr.toDebugString()+"!"+argv+"!");
      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?");

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

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
...
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

    if (len == -1) {
      len = str.length();
    }
    need_len = obj_ptr.len + len;
    /* next line: force string respresentation */
    obj_ptr.getString();
    if (obj_ptr.strValue_GetMaxLength() < need_len ||
      obj_ptr.strValue_GetMaxLength() == 0) {
      need_len *= 2;
      /* Inefficient to malloc() for less than 8 bytes */
      if (need_len < 7) {
        need_len = 7;
      }
      obj_ptr.strValue_SetMaxLength(need_len);
    }




    obj_ptr.bytes.append(str);
    if (obj_ptr.strValue_GetCharLength() >= 0) {
        /* Update the utf-8 char length */
//FIXME!!!
//        obj_ptr.strValue_SetCharLength(obj_ptr.strValue_GetCharLength() + obj.interp.default_obj.utf8_strlen(obj_ptr.bytes, obj_ptr.len, len);
    }
    obj_ptr.len += len;
    return OK;
  }

  /* ==================== appendString ================================== */
  /* Higher level API to append strings to objects. */
................................................................................
    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;
          }
        }







|
<







>
>
>
>



|
|







 







>










>


<



>



|












>







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
...
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

    if (len == -1) {
      len = str.length();
    }
    need_len = obj_ptr.len + len;
    /* next line: force string respresentation */
    obj_ptr.getString();
    if (obj_ptr.strValue_GetMaxLength() < need_len || obj_ptr.strValue_GetMaxLength() == 0) {

      need_len *= 2;
      /* Inefficient to malloc() for less than 8 bytes */
      if (need_len < 7) {
        need_len = 7;
      }
      obj_ptr.strValue_SetMaxLength(need_len);
    }
// FIXME this is just a hack!!
if (obj_ptr.len < obj_ptr.bytes.length()) {
obj_ptr.bytes.delete(obj_ptr.len, obj_ptr.bytes.length());
}
    obj_ptr.bytes.append(str);
    if (obj_ptr.strValue_GetCharLength() >= 0) {
        /* Update the utf-8 char length */
//        obj_ptr.strValue_SetCharLength(obj_ptr.strValue_GetCharLength() + interp.default_obj.utf8_strlen(obj_ptr.bytes.toString(), obj_ptr.len, len);
        obj_ptr.strValue_SetCharLength(obj_ptr.strValue_GetCharLength() + obj_ptr.bytes.toString().length());
    }
    obj_ptr.len += len;
    return OK;
  }

  /* ==================== appendString ================================== */
  /* Higher level API to append strings to objects. */
................................................................................
    int num_maps;
    String str;
    int no_match_start = 0;
    int str_len;
    int i;
    int idx = 0;
    ApwtclObj result_obj_ptr;
    ArrayList<ApwtclObj> my_obj_ptr = null;

    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");
//print("str!"+str+"!"+str_len+"!");
    while (str_len > 0) {
      for (i = 0; i < num_maps; i += 2) {

        String k;
        int kl;

        my_obj_ptr = new ArrayList<ApwtclObj>();
        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;
            }
            my_obj_ptr = new ArrayList<ApwtclObj>();
            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;
          }
        }