LYCharSet_UC[I->value_cs].MIMEname : "<UNKNOWN>"));
LYCharSet_UC[I->value_cs].MIMEname : "<UNKNOWN>")));
PUBLIC int HText_beginInput ARGS3(	HText *,		text,	BOOL,			underline,	InputFieldData *,	I){    TextAnchor * a = (TextAnchor *) calloc(1, sizeof(*a));    FormInfo * f = (FormInfo *) calloc(1, sizeof(*f));    CONST char *cp_option = NULL;    char *IValue = NULL;    unsigned char *tmp = NULL;    int i, j;    CTRACE(tfp,"Entering HText_beginInput\n");    if (a == NULL || f == NULL)	outofmem(__FILE__, "HText_beginInput");    a->start = text->chars + text->last_line->size;    a->inUnderline = underline;    a->line_num = text->Lines;    a->line_pos = text->last_line->size;    /*     *  If this is a radio button, or an OPTION we're converting     *  to a radio button, and it's the first with this name, make     *  sure it's checked by default.  Otherwise, if it's checked,     *  uncheck the default or any preceding radio button with this     *  name that was checked. - FM     */    if (I->type != NULL && !strcmp(I->type,"OPTION") &&	HTCurSelectGroupType == F_RADIO_TYPE && LYSelectPopups == FALSE) {	I->type = "RADIO";	I->name = HTCurSelectGroup;	I->name_cs = HTCurSelectGroupCharset;    }    if (I->name && I->type && !strcasecomp(I->type, "radio")) {	if (!text->last_anchor) {	    I->checked = TRUE;	} else {	    TextAnchor * b = text->first_anchor;	    int i2 = 0;	    while (b) {		if (b->link_type == INPUT_ANCHOR &&		    b->input_field->type == F_RADIO_TYPE &&		    b->input_field->number == HTFormNumber) {		    if (!strcmp(b->input_field->name, I->name)) {			if (I->checked && b->input_field->num_value) {			    b->input_field->num_value = 0;			    StrAllocCopy(b->input_field->orig_value, "0");			    break;			}			i2++;		    }		}		if (b == text->last_anchor) {		    if (i2 == 0)		       I->checked = TRUE;		    break;		}		b = b->next;	    }	}    }    a->next = 0;    a->anchor = NULL;    a->link_type = INPUT_ANCHOR;    a->show_anchor = YES;    a->hightext = NULL;    a->extent = 2;    a->input_field = f;    f->select_list = 0;    f->number = HTFormNumber;    f->disabled = (HTFormDisabled ? TRUE : I->disabled);    f->no_cache = NO;    HTFormFields++;    /*     *  Set the no_cache flag if the METHOD is POST. - FM     */    if (HTFormMethod == URL_POST_METHOD)	f->no_cache = TRUE;    /*     *  Set up VALUE.     */    if (I->value)	StrAllocCopy(IValue, I->value);    if (IValue && HTCJK != NOCJK) {	if ((tmp = (unsigned char *)calloc(1, (strlen(IValue) + 1)))) {	    if (kanji_code == EUC) {		TO_EUC((unsigned char *)IValue, tmp);		I->value_cs = current_char_set;	    } else if (kanji_code == SJIS) {		TO_SJIS((unsigned char *)IValue, tmp);		I->value_cs = current_char_set;	    } else {		for (i = 0, j = 0; IValue[i]; i++) {		    if (IValue[i] != CH_ESC) {  /* S/390 -- gil -- 1621 */			tmp[j++] = IValue[i];		    }		}	    }	    StrAllocCopy(IValue, (CONST char *)tmp);	    FREE(tmp);	}    }    /*     *  Special case of OPTION.     *  Is handled above if radio type and LYSelectPopups is FALSE.     */    /* set the values and let the parsing below do the work */    if (I->type != NULL && !strcmp(I->type,"OPTION")) {	cp_option = I->type;	if (HTCurSelectGroupType == F_RADIO_TYPE)	    I->type = "OPTION_LIST";	else	    I->type = "CHECKBOX";	I->name = HTCurSelectGroup;	I->name_cs = HTCurSelectGroupCharset;	/*	 *  The option's size parameter actually gives the length and not	 *    the width of the list.  Perform the conversion here	 *    and get rid of the allocated HTCurSelect....	 *  0 is ok as it means any length (arbitrary decision).	 */	if (HTCurSelectGroupSize != NULL) {	    f->size_l = atoi(HTCurSelectGroupSize);	    FREE(HTCurSelectGroupSize);	}    }    /*     *  Set SIZE.     */    if (I->size != NULL) {	f->size = atoi(I->size);	/*	 *  Leave at zero for option lists.	 */	if (f->size == 0 && cp_option == NULL) {	   f->size = 20;  /* default */	}    } else {	f->size = 20;  /* default */    }    /*     *  Set MAXLENGTH.     */    if (I->maxlength != NULL) {	f->maxlength = atoi(I->maxlength);    } else {	f->maxlength = 0;  /* 0 means infinite */    }    /*     *  Set CHECKED     *  (num_value is only relevant to check and radio types).     */    if (I->checked == TRUE)	f->num_value = 1;    else	f->num_value = 0;    /*     *  Set TYPE.     */    if (I->type != NULL) {	if (!strcasecomp(I->type,"password")) {	    f->type = F_PASSWORD_TYPE;	} else if (!strcasecomp(I->type,"checkbox")) {	    f->type = F_CHECKBOX_TYPE;	} else if (!strcasecomp(I->type,"radio")) {	    f->type = F_RADIO_TYPE;	} else if (!strcasecomp(I->type,"submit")) {	    f->type = F_SUBMIT_TYPE;	} else if (!strcasecomp(I->type,"image")) {	    f->type = F_IMAGE_SUBMIT_TYPE;	} else if (!strcasecomp(I->type,"reset")) {	    f->type = F_RESET_TYPE;	} else if (!strcasecomp(I->type,"OPTION_LIST")) {	    f->type = F_OPTION_LIST_TYPE;	} else if (!strcasecomp(I->type,"hidden")) {	    f->type = F_HIDDEN_TYPE;	    HTFormFields--;	    f->size = 0;	} else if (!strcasecomp(I->type,"textarea")) {	    f->type = F_TEXTAREA_TYPE;	} else if (!strcasecomp(I->type,"range")) {	    f->type = F_RANGE_TYPE;	} else if (!strcasecomp(I->type,"file")) {	    f->type = F_FILE_TYPE;	} else if (!strcasecomp(I->type,"keygen")) {	    f->type = F_KEYGEN_TYPE;	} else {	    /*	     *  Note that TYPE="scribble" defaults to TYPE="text". - FM	     */	    f->type = F_TEXT_TYPE; /* default */	}    } else {	f->type = F_TEXT_TYPE;    }    /*     *  Set NAME.     */    if (I->name != NULL) {	StrAllocCopy(f->name,I->name);	f->name_cs = I->name_cs;    } else {	if (f->type == F_RESET_TYPE ||	    f->type == F_SUBMIT_TYPE ||	    f->type == F_IMAGE_SUBMIT_TYPE) {	    /*	     *  Set name to empty string.	     */	    StrAllocCopy(f->name, "");	} else {	    /*	     *  Error!  NAME must be present.	     */	    CTRACE(tfp,		  "GridText: No name present in input field; not displaying\n");	    FREE(a);	    FREE(f);	    FREE(IValue);	    return(0);	}    }    /*     *  Add this anchor to the anchor list     */    if (text->last_anchor) {	text->last_anchor->next = a;    } else {	text->first_anchor = a;    }    /*     *  Set VALUE, if it exists.  Otherwise, if it's not     *  an option list make it a zero-length string. - FM     */    if (IValue != NULL) {	/*	 *  OPTION VALUE is not actually the value to be seen but is to	 *    be sent....	 */	if (f->type == F_OPTION_LIST_TYPE ||	    f->type == F_CHECKBOX_TYPE) {	    /*	     *  Fill both with the value.  The f->value may be	     *  overwritten in HText_setLastOptionValue....	     */	    StrAllocCopy(f->value, IValue);	    StrAllocCopy(f->cp_submit_value, IValue);	} else {	    StrAllocCopy(f->value, IValue);	}	f->value_cs = I->value_cs;    } else if (f->type != F_OPTION_LIST_TYPE) {	StrAllocCopy(f->value, "");	/*	 *  May be an empty INPUT field.  The text entered will then	 *  probably be in the current display character set. - kw	 */	f->value_cs = current_char_set;    }    /*     *  Run checks and fill in necessary values.     */    if (f->type == F_RESET_TYPE) {	if (f->value && *f->value != '\0') {	    f->size = strlen(f->value);	} else {	    StrAllocCopy(f->value, "Reset");	    f->size = 5;	}    } else if (f->type == F_IMAGE_SUBMIT_TYPE ||	       f->type == F_SUBMIT_TYPE) {	if (f->value && *f->value != '\0') {	    f->size = strlen(f->value);	} else if (f->type == F_IMAGE_SUBMIT_TYPE) {	    StrAllocCopy(f->value, "[IMAGE]-Submit");	    f->size = 14;	} else {	    StrAllocCopy(f->value, "Submit");	    f->size = 6;	}	f->submit_action = NULL;	StrAllocCopy(f->submit_action, HTFormAction);	if (HTFormEnctype != NULL)	    StrAllocCopy(f->submit_enctype, HTFormEnctype);	if (HTFormTitle != NULL)	    StrAllocCopy(f->submit_title, HTFormTitle);	f->submit_method = HTFormMethod;    } else if (f->type == F_RADIO_TYPE || f->type == F_CHECKBOX_TYPE) {	f->size=3;	if (IValue == NULL)	   StrAllocCopy(f->value, (f->type == F_CHECKBOX_TYPE ? "on" : ""));    }    FREE(IValue);    /*     *  Set original values.     */    if (f->type == F_RADIO_TYPE || f->type == F_CHECKBOX_TYPE ) {	if (f->num_value)	    StrAllocCopy(f->orig_value, "1");	else	    StrAllocCopy(f->orig_value, "0");    } else if (f->type == F_OPTION_LIST_TYPE) {	f->orig_value = NULL;    } else {	StrAllocCopy(f->orig_value, f->value);    }    /*     *  Store accept-charset if present, converting to lowercase     *  and collapsing spaces. - kw     */    if (I->accept_cs) {	StrAllocCopy(f->accept_cs, I->accept_cs);	LYRemoveBlanks(f->accept_cs);	LYLowerCase(f->accept_cs);    }    /*     *  Add numbers to form fields if needed. - LE & FM     */    switch (f->type) {	/*	 *  Do not supply number for hidden fields, nor	 *  for types that are not yet implemented.	 */	case F_HIDDEN_TYPE:	case F_FILE_TYPE:	case F_RANGE_TYPE:	case F_KEYGEN_TYPE:	    a->number = 0;	    break;	default:	    if (keypad_mode == LINKS_AND_FORM_FIELDS_ARE_NUMBERED)		a->number = ++(text->last_anchor_number);	    else		a->number = 0;	    break;    }    if (keypad_mode == LINKS_AND_FORM_FIELDS_ARE_NUMBERED && a->number > 0) {	char marker[16];	if (f->type != F_OPTION_LIST_TYPE)	    /*	     *  '[' was already put out for a popup menu	     *  designator.  See HTML.c.	     */	    HText_appendCharacter(text, '[');	sprintf(marker,"%d]", a->number);	HText_appendText(text, marker);	if (f->type == F_OPTION_LIST_TYPE)	    /*	     *  Add option list designation char.	     */	    HText_appendCharacter(text, '[');	a->start = text->chars + text->last_line->size;	a->line_num = text->Lines;	a->line_pos = text->last_line->size;    }    /*     *  Restrict SIZE to maximum allowable size.     */    switch (f->type) {	int MaximumSize;	case F_SUBMIT_TYPE:	case F_IMAGE_SUBMIT_TYPE:	case F_RESET_TYPE:	case F_TEXT_TYPE:	case F_TEXTAREA_TYPE:	    /*	     *  For submit and reset buttons, and for text entry	     *  fields and areas, we limit the size element to that	     *  of one line for the current style because that's	     *  the most we could highlight on overwrites, and/or	     *  handle in the line editor.  The actual values for	     *  text entry lines can be long, and will be scrolled	     *  horizontally within the editing window. - FM	     */	    MaximumSize = (LYcols - 1) -			  (int)text->style->leftIndent -			  (int)text->style->rightIndent;	    /*	     *  If we are numbering form links, take that into	     *  account as well. - FM	     */	    if (keypad_mode == LINKS_AND_FORM_FIELDS_ARE_NUMBERED)		MaximumSize -= ((a->number/10) + 3);	    if (f->size > MaximumSize)		f->size = MaximumSize;	    /*	     *  Save value for submit/reset buttons so they	     *  will be visible when printing the page. - LE	     */	    I->value = f->value;	    break;	default:	    /*	     *  For all other fields we limit the size element to	     *  10 less than the screen width, because either they	     *  are types with small placeholders, and/or are a	     *  type which is handled via a popup window. - FM	     */	    if (f->size > LYcols-10)		f->size = LYcols-10;  /* maximum */	    break;    }    /*     *  Add this anchor to the anchor list     */    text->last_anchor = a;    if (HTCurrentForm) {	/* should always apply! - kw */	if (!HTCurrentForm->first_field) {	    HTCurrentForm->first_field = f;	}	HTCurrentForm->last_field = f;	HTCurrentForm->nfields++; /* will count hidden fields - kw */	/*	 *  Propagate form field's accept-charset attribute to enclosing	 *  form if the form itself didn't have an accept-charset - kw	 */	if (f->accept_cs && !HTFormAcceptCharset) {	    StrAllocCopy(HTFormAcceptCharset, f->accept_cs);	}	if (!text->forms) {	    text->forms = HTList_new();	}    } else {	CTRACE(tfp, "beginInput: HTCurrentForm is missing!\n");    }    CTRACE(tfp, "Input link: name=%s\nvalue=%s\nsize=%d\n",			f->name,			((f->value != NULL) ? f->value : ""),			f->size);    CTRACE(tfp, "Input link: name_cs=%d \"%s\" (from %d \"%s\")\n",			f->name_cs,			(f->name_cs >= 0 ?			 LYCharSet_UC[f->name_cs].MIMEname : "<UNKNOWN>"),			I->name_cs,			(I->name_cs >= 0 ?			 LYCharSet_UC[I->name_cs].MIMEname : "<UNKNOWN>"));    CTRACE(tfp, "            value_cs=%d \"%s\" (from %d \"%s\")\n",			f->value_cs,			(f->value_cs >= 0 ?			 LYCharSet_UC[f->value_cs].MIMEname : "<UNKNOWN>"),			I->value_cs,			(I->value_cs >= 0 ?			 LYCharSet_UC[I->value_cs].MIMEname : "<UNKNOWN>"));    /*     *  Return the SIZE of the input field.     */    return(f->size);}