/****************************************************************************1* Copyright (c) 1998 Free Software Foundation, Inc. *2* *3* Permission is hereby granted, free of charge, to any person obtaining a *4* copy of this software and associated documentation files (the *5* "Software"), to deal in the Software without restriction, including *6* without limitation the rights to use, copy, modify, merge, publish, *7* distribute, distribute with modifications, sublicense, and/or sell *8* copies of the Software, and to permit persons to whom the Software is *9* furnished to do so, subject to the following conditions: *10* *11* The above copyright notice and this permission notice shall be included *12* in all copies or substantial portions of the Software. *13* *14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *15* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *16* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *17* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *20* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *21* *22* Except as contained in this notice, the name(s) of the above copyright *23* holders shall not be used in advertising or otherwise to promote the *24* sale, use or other dealings in this Software without prior written *25* authorization. *26****************************************************************************/2728/****************************************************************************29* Author: Juergen Pfeifer <[email protected]> 1995,1997 *30****************************************************************************/3132#include "form.priv.h"3334MODULE_ID("$Id$")3536static FIELDTYPE const default_fieldtype = {370, /* status */380L, /* reference count */39(FIELDTYPE *)0, /* pointer to left operand */40(FIELDTYPE *)0, /* pointer to right operand */41NULL, /* makearg function */42NULL, /* copyarg function */43NULL, /* freearg function */44NULL, /* field validation function */45NULL, /* Character check function */46NULL, /* enumerate next function */47NULL /* enumerate previous function */48};4950const FIELDTYPE* _nc_Default_FieldType = &default_fieldtype;5152/*---------------------------------------------------------------------------53| Facility : libnform54| Function : FIELDTYPE *new_fieldtype(55| bool (* const field_check)(FIELD *,const void *),56| bool (* const char_check) (int, const void *) )57|58| Description : Create a new fieldtype. The application programmer must59| write a field_check and a char_check function and give60| them as input to this call.61| If an error occurs, errno is set to62| E_BAD_ARGUMENT - invalid arguments63| E_SYSTEM_ERROR - system error (no memory)64|65| Return Values : Fieldtype pointer or NULL if error occurred66+--------------------------------------------------------------------------*/67FIELDTYPE *new_fieldtype(68bool (* const field_check)(FIELD *,const void *),69bool (* const char_check) (int,const void *) )70{71FIELDTYPE *nftyp = (FIELDTYPE *)0;7273if ( (field_check) || (char_check) )74{75nftyp = (FIELDTYPE *)malloc(sizeof(FIELDTYPE));76if (nftyp)77{78*nftyp = default_fieldtype;79nftyp->fcheck = field_check;80nftyp->ccheck = char_check;81}82else83{84SET_ERROR( E_SYSTEM_ERROR );85}86}87else88{89SET_ERROR( E_BAD_ARGUMENT );90}91return nftyp;92}9394/*---------------------------------------------------------------------------95| Facility : libnform96| Function : int free_fieldtype(FIELDTYPE *typ)97|98| Description : Release the memory associated with this fieldtype.99|100| Return Values : E_OK - success101| E_CONNECTED - there are fields referencing the type102| E_BAD_ARGUMENT - invalid fieldtype pointer103+--------------------------------------------------------------------------*/104int free_fieldtype(FIELDTYPE *typ)105{106if (!typ)107RETURN(E_BAD_ARGUMENT);108109if (typ->ref!=0)110RETURN(E_CONNECTED);111112if (typ->status & _RESIDENT)113RETURN(E_CONNECTED);114115if (typ->status & _LINKED_TYPE)116{117if (typ->left ) typ->left->ref--;118if (typ->right) typ->right->ref--;119}120free(typ);121RETURN(E_OK);122}123124/* fld_newftyp.c ends here */125126127