APWTCL Arnulf's Preferred Web Tcl

Diff
Login

Diff

Differences From Artifact [5b239a7c87]:

To Artifact [eb0794a7e6]:


58
59
60
61
62
63
64
65
66


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

83
84
85

86
87
88
89
90
91
92
58
59
60
61
62
63
64


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

82
83
84

85
86
87
88
89
90
91
92







-
-
+
+















-
+


-
+







  /* ==================== toDebugString ===================================== */
  public String toDebugString() {
    StringBuffer str = new StringBuffer(mySelf()+"\n");
    return str.toString();
  }

  /* ==================== addOption ===================================== */
  public void addOption(String option_name, int option_code, boolean has_opt_value, 
		  ArrayList<ApwtclObj> default_value, HashMap<String, Integer>allowed_option_values) {
  public void addOption(String option_name, int option_code, int has_opt_value, 
	ArrayList<ApwtclObj> default_value, HashMap<String, Integer>allowed_option_values) {
    CommandOption option = new CommandOption(interp, option_name, option_code, has_opt_value, default_value, 
    		allowed_option_values);
    option_list.put(option_name, option);
    opt_code2opt_name.put(option_code, option_name);
  }

  /* ==================== hasOption ===================================== */
  public boolean hasOption(String option_name) {
    if (option_list.get(option_name) != null) {
      return true;
    }
    return false;
  }

  /* ==================== optionHasValue ===================================== */
  public boolean optionHasValue(String option_name) {
  public int optionHasValue(String option_name) {
    CommandOption option = option_list.get(option_name);
    if (option == null) {
      return false;
      return 0;
    }
    return option.opt_has_value;
  }

  /* ==================== optionCode ===================================== */
  public int optionCode(String option_name) {
    CommandOption option = option_list.get(option_name);
169
170
171
172
173
174
175

176
177
178
179
180
181
182
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183







+







  public void resetOptionValues() {
    option_values = new HashMap<String, ApwtclObj>();
  }

  /* ==================== parseOptions ===================================== */
  public int parseOptions(ArrayList<ApwtclObj> args, int start_idx, String msg_start) {
    String option;
    int option_has_value;

    num_processed_args = 0;
    option_flags = 0;
    err_msg = "";

    for (int i = start_idx; i < args.size(); i++) {
      option = args.get(i).getString();
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
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







-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







           sep = ", ";
        }
        err_msg = msg.toString();
        return ERROR;
      }
      num_processed_args++;
      option_flags |= option_info.opt_code;
      if (optionHasValue(option)) {
        i++;
        if (i == args.size()) {
          err_msg = msg_start+" must be an even number of option name and option value";
          return ERROR;
        }
        num_processed_args++;
        if (option_info.allowed_option_values != null) {
          if (option_info.allowed_option_values.get(args.get(i).getString()) == null) {
            err_msg = msg_start+" bad value for option \""+option+"\" must be: "+option_info.getAllowedOptionValues();
            return ERROR;
	  }
	}
        option_values.put(option, args.get(i));
      option_has_value = optionHasValue(option);
      if (option_has_value != OPTION_HAS_NO_VALUE) {
    	/* check for option_has_value -1, if the next argument does not start with "-", then it is a value */
        if (option_has_value == OPTION_CAN_HAVE_VALUE && args.get(i + 1).getString().charAt(0) != '-') {
          option_has_value = OPTION_HAS_VALUE;
        }
        if (option_has_value == OPTION_HAS_VALUE) {
    	  i++;
          if (i == args.size()) {
            err_msg = msg_start+" must be an even number of option name and option value";
            return ERROR;
          }
          num_processed_args++;
          if (option_info.allowed_option_values != null) {
            if (option_info.allowed_option_values.get(args.get(i).getString()) == null) {
              err_msg = msg_start+" bad value for option \""+option+"\" must be: "+option_info.getAllowedOptionValues();
              return ERROR;
	        }
	      }
          option_values.put(option, args.get(i));
        }
      }
    }
//print("num_processed_args!"+num_processed_args+"!");
    return OK;
  }

}