150276Speter/****************************************************************************
2262629Sdelphij * Copyright (c) 1998-2004,2010 Free Software Foundation, Inc.              *
350276Speter *                                                                          *
450276Speter * Permission is hereby granted, free of charge, to any person obtaining a  *
550276Speter * copy of this software and associated documentation files (the            *
650276Speter * "Software"), to deal in the Software without restriction, including      *
750276Speter * without limitation the rights to use, copy, modify, merge, publish,      *
850276Speter * distribute, distribute with modifications, sublicense, and/or sell       *
950276Speter * copies of the Software, and to permit persons to whom the Software is    *
1050276Speter * furnished to do so, subject to the following conditions:                 *
1150276Speter *                                                                          *
1250276Speter * The above copyright notice and this permission notice shall be included  *
1350276Speter * in all copies or substantial portions of the Software.                   *
1450276Speter *                                                                          *
1550276Speter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
1650276Speter * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
1750276Speter * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
1850276Speter * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
1950276Speter * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
2050276Speter * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
2150276Speter * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
2250276Speter *                                                                          *
2350276Speter * Except as contained in this notice, the name(s) of the above copyright   *
2450276Speter * holders shall not be used in advertising or otherwise to promote the     *
2550276Speter * sale, use or other dealings in this Software without prior written       *
2650276Speter * authorization.                                                           *
2750276Speter ****************************************************************************/
2850276Speter
2950276Speter/****************************************************************************
30166124Srafan *   Author:  Juergen Pfeifer, 1995,1997                                    *
3150276Speter ****************************************************************************/
3250276Speter
3350276Speter#include "form.priv.h"
3450276Speter
35262629SdelphijMODULE_ID("$Id: fld_type.c,v 1.16 2010/01/23 21:14:36 tom Exp $")
3650276Speter
3750276Speter/*---------------------------------------------------------------------------
3850276Speter|   Facility      :  libnform
3950276Speter|   Function      :  int set_field_type(FIELD *field, FIELDTYPE *type,...)
4050276Speter|
4150276Speter|   Description   :  Associate the specified fieldtype with the field.
4250276Speter|                    Certain field types take additional arguments. Look
4350276Speter|                    at the spec of the field types !
4450276Speter|
4550276Speter|   Return Values :  E_OK           - success
4650276Speter|                    E_SYSTEM_ERROR - system error
4750276Speter+--------------------------------------------------------------------------*/
4876726SpeterNCURSES_EXPORT(int)
49166124Srafanset_field_type(FIELD *field, FIELDTYPE *type,...)
5050276Speter{
5150276Speter  va_list ap;
5250276Speter  int res = E_SYSTEM_ERROR;
5350276Speter  int err = 0;
5450276Speter
55262629Sdelphij  T((T_CALLED("set_field_type(%p,%p)"), (void *)field, (void *)type));
5650276Speter
57166124Srafan  va_start(ap, type);
58166124Srafan
5950276Speter  Normalize_Field(field);
6050276Speter  _nc_Free_Type(field);
6150276Speter
6250276Speter  field->type = type;
63166124Srafan  field->arg = (void *)_nc_Make_Argument(field->type, &ap, &err);
6450276Speter
6550276Speter  if (err)
6650276Speter    {
67166124Srafan      _nc_Free_Argument(field->type, (TypeArgument *)(field->arg));
6850276Speter      field->type = (FIELDTYPE *)0;
69166124Srafan      field->arg = (void *)0;
7050276Speter    }
7150276Speter  else
7250276Speter    {
7350276Speter      res = E_OK;
74166124Srafan      if (field->type)
7550276Speter	field->type->ref++;
7650276Speter    }
7750276Speter
7850276Speter  va_end(ap);
7950276Speter  RETURN(res);
8050276Speter}
8150276Speter
8250276Speter/*---------------------------------------------------------------------------
8350276Speter|   Facility      :  libnform
8450276Speter|   Function      :  FIELDTYPE *field_type(const FIELD *field)
8550276Speter|
8650276Speter|   Description   :  Retrieve the associated fieldtype for this field.
8750276Speter|
8850276Speter|   Return Values :  Pointer to fieldtype of NULL if none is defined.
8950276Speter+--------------------------------------------------------------------------*/
9076726SpeterNCURSES_EXPORT(FIELDTYPE *)
91166124Srafanfield_type(const FIELD *field)
9250276Speter{
93262629Sdelphij  T((T_CALLED("field_type(%p)"), (const void *)field));
94166124Srafan  returnFieldType(Normalize_Field(field)->type);
9550276Speter}
9650276Speter
9750276Speter/* fld_type.c ends here */
98