[project @ 2004-05-21 10:25:42 by bursa]

Add form_new_control() and form_free_control().

svn path=/import/netsurf/; revision=878
This commit is contained in:
James Bursa 2004-05-21 10:25:42 +00:00
parent 5a79489248
commit 9412dfeaed
2 changed files with 71 additions and 4 deletions

View File

@ -21,6 +21,34 @@
static char *form_textarea_value(struct form_control *textarea);
/**
* Create a struct form_control.
*
* \param type control type
* \return a new structure, or 0 on memory exhaustion
*/
struct form_control *form_new_control(form_control_type type)
{
struct form_control *control;
control = malloc(sizeof *control);
if (!control)
return 0;
control->type = type;
control->name = 0;
control->value = 0;
control->initial_value = 0;
control->disabled = false;
control->form = 0;
control->box = 0;
control->prev = 0;
control->next = 0;
return control;
}
/**
* Add a control to the list of controls in a form.
*/
@ -40,6 +68,31 @@ void form_add_control(struct form *form, struct form_control *control)
}
/**
* Free a struct form_control.
*
* \param control structure to free
*/
void form_free_control(struct form_control *control)
{
free(control->name);
free(control->value);
free(control->initial_value);
if (control->type == GADGET_SELECT) {
struct form_option *option, *next;
for (option = control->data.select.items; option;
option = next) {
next = option->next;
free(option->text);
free(option->value);
free(option);
}
}
free(control);
}
/**
* Identify 'successful' controls.
*

View File

@ -32,12 +32,24 @@ struct form {
struct form_control *last_control; /**< Last control in list. */
};
/** Type of a struct form_control. */
typedef enum {
GADGET_HIDDEN,
GADGET_TEXTBOX,
GADGET_RADIO,
GADGET_CHECKBOX,
GADGET_SELECT,
GADGET_TEXTAREA,
GADGET_IMAGE,
GADGET_PASSWORD,
GADGET_SUBMIT,
GADGET_RESET,
GADGET_FILE
} form_control_type;
/** Form control. */
struct form_control {
enum { GADGET_HIDDEN, GADGET_TEXTBOX, GADGET_RADIO, GADGET_CHECKBOX,
GADGET_SELECT, GADGET_TEXTAREA, GADGET_IMAGE,
GADGET_PASSWORD, GADGET_SUBMIT, GADGET_RESET,
GADGET_FILE } type;
form_control_type type;
char *name;
char *value;
char *initial_value;
@ -88,7 +100,9 @@ struct form_successful_control {
struct form_successful_control *next; /**< Next in linked list. */
};
struct form_control *form_new_control(form_control_type type);
void form_add_control(struct form *form, struct form_control *control);
void form_free_control(struct form_control *control);
struct form_successful_control *form_successful_controls(struct form *form,
struct form_control *submit_button);
char *form_url_encode(struct form_successful_control *control);