fprintf(tfp,"HText_setLastOptionValue:%s value=%s",
CTRACE((tfp, "HText_setLastOptionValue:%s value=%s",
PUBLIC char * HText_setLastOptionValue ARGS7(	HText *,	text,	char *,		value,	char*,		submit_value,	int,		order,	BOOLEAN,	checked,	int,		val_cs,	int,		submit_val_cs){    char *cp, *cp1;    char *ret_Value = NULL;    unsigned char *tmp = NULL;    int number = 0, i, j;    if (!(text && text->last_anchor &&	  text->last_anchor->link_type == INPUT_ANCHOR)) {	CTRACE(tfp, "HText_setLastOptionValue: invalid call!  value:%s!\n",		    (value ? value : "<NULL>"));	return NULL;    }    CTRACE(tfp, "Entering HText_setLastOptionValue: value:%s, checked:%s\n",		value, (checked ? "on" : "off"));    /*     *  Strip end spaces, newline is also whitespace.     */    if (*value) {	cp = &value[strlen(value)-1];	while ((cp >= value) && (isspace((unsigned char)*cp) ||				 IsSpecialAttrChar((unsigned char)*cp)))	    cp--;	*(cp+1) = '\0';    }    /*     *  Find first non space     */    cp = value;    while (isspace((unsigned char)*cp) ||	   IsSpecialAttrChar((unsigned char)*cp))	cp++;    if (HTCurSelectGroupType == F_RADIO_TYPE &&	LYSelectPopups &&	keypad_mode == LINKS_AND_FORM_FIELDS_ARE_NUMBERED) {	/*	 *  Collapse any space between the popup option	 *  prefix and actual value. - FM	 */	if ((cp1 = HText_skipOptionNumPrefix(cp)) > cp) {	    i = 0, j = (cp1 - cp);	    while (isspace((unsigned char)cp1[i]) ||		   IsSpecialAttrChar((unsigned char)cp1[i])) {		i++;	    }	    if (i > 0) {		while (cp1[i] != '\0')		    cp[j++] = cp1[i++];		cp[j] = '\0';	    }	}    }    if (HTCurSelectGroupType == F_CHECKBOX_TYPE) {	StrAllocCopy(text->last_anchor->input_field->value, cp);	text->last_anchor->input_field->value_cs = val_cs;	/*	 *  Put the text on the screen as well.	 */	HText_appendText(text, cp);    } else if (LYSelectPopups == FALSE) {	StrAllocCopy(text->last_anchor->input_field->value,		     (submit_value ? submit_value : cp));	text->last_anchor->input_field->value_cs = (submit_value ?						    submit_val_cs : val_cs);	/*	 *  Put the text on the screen as well.	 */	HText_appendText(text, cp);    } else {	/*	 *  Create a linked list of option values.	 */	OptionType * op_ptr = text->last_anchor->input_field->select_list;	OptionType * new_ptr = NULL;	BOOLEAN first_option = FALSE;	/*	 *  Deal with newlines or tabs.	 */	convert_to_spaces(value, FALSE);	if (!op_ptr) {	    /*	     *  No option items yet.	     */	    if (text->last_anchor->input_field->type != F_OPTION_LIST_TYPE) {		CTRACE(tfp, "HText_setLastOptionValue: last input_field not F_OPTION_LIST_TYPE (%d)\n",			    F_OPTION_LIST_TYPE);		CTRACE(tfp, "                          but %d, ignoring!\n",			    text->last_anchor->input_field->type);		return NULL;	    }	    new_ptr = text->last_anchor->input_field->select_list =				(OptionType *)calloc(1, sizeof(OptionType));	    if (new_ptr == NULL)		outofmem(__FILE__, "HText_setLastOptionValue");	    first_option = TRUE;	} else {	    while (op_ptr->next) {		number++;		op_ptr=op_ptr->next;	    }	    number++;  /* add one more */	    op_ptr->next = new_ptr =				(OptionType *)calloc(1, sizeof(OptionType));	    if (new_ptr == NULL)		outofmem(__FILE__, "HText_setLastOptionValue");	}	new_ptr->name = NULL;	new_ptr->cp_submit_value = NULL;	new_ptr->next = NULL;	/*	 *  Find first non-space again, convert_to_spaces above may have	 *  changed the string. - kw	 */	cp = value;	while (isspace((unsigned char)*cp) ||	       IsSpecialAttrChar((unsigned char)*cp))	    cp++;	for (i = 0, j = 0; cp[i]; i++) {	    if (cp[i] == HT_NON_BREAK_SPACE ||		cp[i] == HT_EN_SPACE) {		cp[j++] = ' ';	    } else if (cp[i] != LY_SOFT_HYPHEN &&		       !IsSpecialAttrChar((unsigned char)cp[i])) {		cp[j++] = cp[i];	    }	}	cp[j] = '\0';	if (HTCJK != NOCJK) {	    if (cp &&		(tmp = (unsigned char *)calloc(1, strlen(cp)+1))) {		if (kanji_code == EUC) {		    TO_EUC((unsigned char *)cp, tmp);		    val_cs = current_char_set;		} else if (kanji_code == SJIS) {		    TO_SJIS((unsigned char *)cp, tmp);		    val_cs = current_char_set;		} else {		    for (i = 0, j = 0; cp[i]; i++) {			if (cp[i] != CH_ESC) {	/* S/390 -- gil -- 1604 */			    tmp[j++] = cp[i];			}		    }		}		StrAllocCopy(new_ptr->name, (CONST char *)tmp);		FREE(tmp);	    }	} else {	    StrAllocCopy(new_ptr->name, cp);	}	StrAllocCopy(new_ptr->cp_submit_value,		     (submit_value ? submit_value :		      HText_skipOptionNumPrefix(new_ptr->name)));	new_ptr->value_cs = (submit_value ? submit_val_cs : val_cs);	if (first_option) {	    StrAllocCopy(HTCurSelectedOptionValue, new_ptr->name);	    text->last_anchor->input_field->num_value = 0;	    /*	     *  If this is the first option in a popup select list,	     *  HText_beginInput may have allocated the value and	     *  cp_submit_value fields, so free them now to avoid	     *  a memory leak. - kw	     */	    FREE(text->last_anchor->input_field->value);	    FREE(text->last_anchor->input_field->cp_submit_value);	    text->last_anchor->input_field->value =		text->last_anchor->input_field->select_list->name;	    text->last_anchor->input_field->orig_value =		text->last_anchor->input_field->select_list->name;	    text->last_anchor->input_field->cp_submit_value =		text->last_anchor->input_field->select_list->cp_submit_value;	    text->last_anchor->input_field->orig_submit_value =		text->last_anchor->input_field->select_list->cp_submit_value;	    text->last_anchor->input_field->value_cs =		new_ptr->value_cs;	} else {	    int newlen = strlen(new_ptr->name);	    int curlen = strlen(HTCurSelectedOptionValue);		/*		 *  Make the selected Option Value as long as		 *  the longest option.		 */	    if (newlen > curlen)		StrAllocCat(HTCurSelectedOptionValue,			    UNDERSCORES(newlen-curlen));	}	if (checked) {	    int curlen = strlen(new_ptr->name);	    int newlen = strlen(HTCurSelectedOptionValue);	    /*	     *  Set the default option as this one.	     */	    text->last_anchor->input_field->num_value = number;	    text->last_anchor->input_field->value = new_ptr->name;	    text->last_anchor->input_field->orig_value = new_ptr->name;	    text->last_anchor->input_field->cp_submit_value =				   new_ptr->cp_submit_value;	    text->last_anchor->input_field->orig_submit_value =				   new_ptr->cp_submit_value;	    text->last_anchor->input_field->value_cs =		new_ptr->value_cs;	    StrAllocCopy(HTCurSelectedOptionValue, new_ptr->name);	    if (newlen > curlen)		StrAllocCat(HTCurSelectedOptionValue,			    UNDERSCORES(newlen-curlen));	}	/*	 *  Return the selected Option value to be sent to the screen.	 */	if (order == LAST_ORDER) {	    /*	     *  Change the value.	     */	    text->last_anchor->input_field->size =				strlen(HTCurSelectedOptionValue);	    ret_Value = HTCurSelectedOptionValue;	}    }    if (TRACE) {	fprintf(tfp,"HText_setLastOptionValue:%s value=%s",		(order == LAST_ORDER) ? " LAST_ORDER" : "",		value);	fprintf(tfp,"            val_cs=%d \"%s\"",			val_cs,			(val_cs >= 0 ?			 LYCharSet_UC[val_cs].MIMEname : "<UNKNOWN>"));	if (submit_value) {	    fprintf(tfp, " (submit_val_cs %d \"%s\") submit_value%s=%s\n",		    submit_val_cs,		    (submit_val_cs >= 0 ?		     LYCharSet_UC[submit_val_cs].MIMEname : "<UNKNOWN>"),		    (HTCurSelectGroupType == F_CHECKBOX_TYPE) ?						  "(ignored)" : "",		    submit_value);	}	else {	    fprintf(tfp,"\n");	}    }    return(ret_Value);}