150276Speter/****************************************************************************
2262685Sdelphij * Copyright (c) 1998-2010,2012 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
35262685SdelphijMODULE_ID("$Id: fld_ftlink.c,v 1.15 2012/06/10 00:27:49 tom Exp $")
3650276Speter
3750276Speter/*---------------------------------------------------------------------------
3850276Speter|   Facility      :  libnform
3950276Speter|   Function      :  FIELDTYPE *link_fieldtype(
4050276Speter|                                FIELDTYPE *type1,
4150276Speter|                                FIELDTYPE *type2)
4250276Speter|
4350276Speter|   Description   :  Create a new fieldtype built from the two given types.
4450276Speter|                    They are connected by an logical 'OR'.
4550276Speter|                    If an error occurs, errno is set to
4650276Speter|                       E_BAD_ARGUMENT  - invalid arguments
4750276Speter|                       E_SYSTEM_ERROR  - system error (no memory)
4850276Speter|
49166124Srafan|   Return Values :  Fieldtype pointer or NULL if error occurred.
5050276Speter+--------------------------------------------------------------------------*/
5176726SpeterNCURSES_EXPORT(FIELDTYPE *)
52166124Srafanlink_fieldtype(FIELDTYPE *type1, FIELDTYPE *type2)
5350276Speter{
5450276Speter  FIELDTYPE *nftyp = (FIELDTYPE *)0;
5550276Speter
56262629Sdelphij  T((T_CALLED("link_fieldtype(%p,%p)"), (void *)type1, (void *)type2));
57166124Srafan  if (type1 && type2)
5850276Speter    {
59174993Srafan      nftyp = typeMalloc(FIELDTYPE, 1);
60166124Srafan
6150276Speter      if (nftyp)
6250276Speter	{
63262629Sdelphij	  T((T_CREATE("fieldtype %p"), (void *)nftyp));
6450276Speter	  *nftyp = *_nc_Default_FieldType;
65262685Sdelphij	  SetStatus(nftyp, _LINKED_TYPE);
66166124Srafan	  if ((type1->status & _HAS_ARGS) || (type2->status & _HAS_ARGS))
67262685Sdelphij	    SetStatus(nftyp, _HAS_ARGS);
68166124Srafan	  if ((type1->status & _HAS_CHOICE) || (type2->status & _HAS_CHOICE))
69262685Sdelphij	    SetStatus(nftyp, _HAS_CHOICE);
70166124Srafan	  nftyp->left = type1;
71166124Srafan	  nftyp->right = type2;
7250276Speter	  type1->ref++;
7350276Speter	  type2->ref++;
7450276Speter	}
7550276Speter      else
7650276Speter	{
77166124Srafan	  SET_ERROR(E_SYSTEM_ERROR);
7850276Speter	}
7950276Speter    }
8050276Speter  else
8150276Speter    {
82166124Srafan      SET_ERROR(E_BAD_ARGUMENT);
8350276Speter    }
84166124Srafan  returnFieldType(nftyp);
8550276Speter}
8650276Speter
8750276Speter/* fld_ftlink.c ends here */
88