X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=form%2Ffrm_def.c;h=86500f239863f125c81c5178ac3c0896fd3d86ac;hp=c0a7855430e679658a8642e3a0d31daeb955c34b;hb=03f728e5bb3630a54fffc4a2ff2f8dbfcce9088e;hpb=5242fccf157e715ed878455a3efea6c82b840eb5 diff --git a/form/frm_def.c b/form/frm_def.c index c0a78554..86500f23 100644 --- a/form/frm_def.c +++ b/form/frm_def.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -32,7 +32,7 @@ #include "form.priv.h" -MODULE_ID("$Id: frm_def.c,v 1.21 2007/02/03 23:37:46 tom Exp $") +MODULE_ID("$Id: frm_def.c,v 1.25 2010/01/23 21:14:36 tom Exp $") /* this can't be readonly */ static FORM default_form = @@ -160,7 +160,7 @@ Connect_Fields(FORM *form, FIELD **fields) int maximum_row_in_field, maximum_col_in_field; _PAGE *pg; - T((T_CALLED("Connect_Fields(%p,%p)"), form, fields)); + T((T_CALLED("Connect_Fields(%p,%p)"), (void *)form, (void *)fields)); assert(form); @@ -186,9 +186,9 @@ Connect_Fields(FORM *form, FIELD **fields) RETURN(E_BAD_ARGUMENT); /* allocate page structures */ - if ((pg = (_PAGE *) malloc(page_nr * sizeof(_PAGE))) != (_PAGE *) 0) + if ((pg = typeMalloc(_PAGE, page_nr)) != (_PAGE *) 0) { - T((T_CREATE("_PAGE %p"), pg)); + T((T_CREATE("_PAGE %p"), (void *)pg)); form->page = pg; } else @@ -234,8 +234,16 @@ Connect_Fields(FORM *form, FIELD **fields) fields[j]->page = page_nr; fld = Insert_Field_By_Position(fields[j], fld); } - form->page[page_nr].smin = fld->index; - form->page[page_nr].smax = fld->sprev->index; + if (fld) + { + form->page[page_nr].smin = fld->index; + form->page[page_nr].smax = fld->sprev->index; + } + else + { + form->page[page_nr].smin = 0; + form->page[page_nr].smax = 0; + } } RETURN(E_OK); } @@ -275,7 +283,7 @@ Associate_Fields(FORM *form, FIELD **fields) /*--------------------------------------------------------------------------- | Facility : libnform -| Function : FORM *new_form( FIELD **fields ) +| Function : FORM *new_form_sp(SCREEN* sp, FIELD** fields ) | | Description : Create new form with given array of fields. | @@ -287,21 +295,31 @@ Associate_Fields(FORM *form, FIELD **fields) | E_SYSTEM_ERROR - not enough memory +--------------------------------------------------------------------------*/ NCURSES_EXPORT(FORM *) -new_form(FIELD **fields) +NCURSES_SP_NAME(new_form) (NCURSES_SP_DCLx FIELD **fields) { int err = E_SYSTEM_ERROR; + FORM *form = (FORM *)0; - FORM *form = (FORM *)malloc(sizeof(FORM)); + T((T_CALLED("new_form(%p,%p)"), (void *)SP_PARM, (void *)fields)); - T((T_CALLED("new_form(%p)"), fields)); - if (form) + if (IsValidScreen(SP_PARM)) { - T((T_CREATE("form %p"), form)); - *form = *_nc_Default_Form; - if ((err = Associate_Fields(form, fields)) != E_OK) + form = typeMalloc(FORM, 1); + + if (form) { - free_form(form); - form = (FORM *)0; + T((T_CREATE("form %p"), (void *)form)); + *form = *_nc_Default_Form; + /* This ensures win and sub are always non-null, + so we can derive always the SCREEN that this form is + running on. */ + form->win = StdScreen(SP_PARM); + form->sub = StdScreen(SP_PARM); + if ((err = Associate_Fields(form, fields)) != E_OK) + { + free_form(form); + form = (FORM *)0; + } } } @@ -311,6 +329,27 @@ new_form(FIELD **fields) returnForm(form); } +/*--------------------------------------------------------------------------- +| Facility : libnform +| Function : FORM* new_form(FIELD** fields ) +| +| Description : Create new form with given array of fields. +| +| Return Values : Pointer to form. NULL if error occurred. +! Set errno: +| E_OK - success +| E_BAD_ARGUMENT - Invalid form pointer or field array +| E_CONNECTED - a field is already connected +| E_SYSTEM_ERROR - not enough memory ++--------------------------------------------------------------------------*/ +#if NCURSES_SP_FUNCS +NCURSES_EXPORT(FORM *) +new_form(FIELD **fields) +{ + return NCURSES_SP_NAME(new_form) (CURRENT_SCREEN, fields); +} +#endif + /*--------------------------------------------------------------------------- | Facility : libnform | Function : int free_form( FORM *form ) @@ -324,7 +363,7 @@ new_form(FIELD **fields) NCURSES_EXPORT(int) free_form(FORM *form) { - T((T_CALLED("free_form(%p)"), form)); + T((T_CALLED("free_form(%p)"), (void *)form)); if (!form) RETURN(E_BAD_ARGUMENT); @@ -358,7 +397,7 @@ set_form_fields(FORM *form, FIELD **fields) FIELD **old; int res; - T((T_CALLED("set_form_fields(%p,%p)"), form, fields)); + T((T_CALLED("set_form_fields(%p,%p)"), (void *)form, (void *)fields)); if (!form) RETURN(E_BAD_ARGUMENT); @@ -386,7 +425,7 @@ set_form_fields(FORM *form, FIELD **fields) NCURSES_EXPORT(FIELD **) form_fields(const FORM *form) { - T((T_CALLED("form_field(%p)"), form)); + T((T_CALLED("form_field(%p)"), (const void *)form)); returnFieldPtr(Normalize_Form(form)->field); } @@ -401,7 +440,7 @@ form_fields(const FORM *form) NCURSES_EXPORT(int) field_count(const FORM *form) { - T((T_CALLED("field_count(%p)"), form)); + T((T_CALLED("field_count(%p)"), (const void *)form)); returnCode(Normalize_Form(form)->maxfield); }