xref: /freebsd/contrib/ncurses/form/fld_ftlink.c (revision 5ca44d1c915a0e0c87f8f347e61f7bfa65d609af)
10e3d5408SPeter Wemm /****************************************************************************
25ca44d1cSRong-En Fan  * Copyright (c) 1998-2004,2007 Free Software Foundation, Inc.              *
30e3d5408SPeter Wemm  *                                                                          *
40e3d5408SPeter Wemm  * Permission is hereby granted, free of charge, to any person obtaining a  *
50e3d5408SPeter Wemm  * copy of this software and associated documentation files (the            *
60e3d5408SPeter Wemm  * "Software"), to deal in the Software without restriction, including      *
70e3d5408SPeter Wemm  * without limitation the rights to use, copy, modify, merge, publish,      *
80e3d5408SPeter Wemm  * distribute, distribute with modifications, sublicense, and/or sell       *
90e3d5408SPeter Wemm  * copies of the Software, and to permit persons to whom the Software is    *
100e3d5408SPeter Wemm  * furnished to do so, subject to the following conditions:                 *
110e3d5408SPeter Wemm  *                                                                          *
120e3d5408SPeter Wemm  * The above copyright notice and this permission notice shall be included  *
130e3d5408SPeter Wemm  * in all copies or substantial portions of the Software.                   *
140e3d5408SPeter Wemm  *                                                                          *
150e3d5408SPeter Wemm  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
160e3d5408SPeter Wemm  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
170e3d5408SPeter Wemm  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
180e3d5408SPeter Wemm  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
190e3d5408SPeter Wemm  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
200e3d5408SPeter Wemm  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
210e3d5408SPeter Wemm  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
220e3d5408SPeter Wemm  *                                                                          *
230e3d5408SPeter Wemm  * Except as contained in this notice, the name(s) of the above copyright   *
240e3d5408SPeter Wemm  * holders shall not be used in advertising or otherwise to promote the     *
250e3d5408SPeter Wemm  * sale, use or other dealings in this Software without prior written       *
260e3d5408SPeter Wemm  * authorization.                                                           *
270e3d5408SPeter Wemm  ****************************************************************************/
280e3d5408SPeter Wemm 
290e3d5408SPeter Wemm /****************************************************************************
304a1a9510SRong-En Fan  *   Author:  Juergen Pfeifer, 1995,1997                                    *
310e3d5408SPeter Wemm  ****************************************************************************/
320e3d5408SPeter Wemm 
330e3d5408SPeter Wemm #include "form.priv.h"
340e3d5408SPeter Wemm 
355ca44d1cSRong-En Fan MODULE_ID("$Id: fld_ftlink.c,v 1.13 2007/10/13 19:30:35 tom Exp $")
360e3d5408SPeter Wemm 
370e3d5408SPeter Wemm /*---------------------------------------------------------------------------
380e3d5408SPeter Wemm |   Facility      :  libnform
390e3d5408SPeter Wemm |   Function      :  FIELDTYPE *link_fieldtype(
400e3d5408SPeter Wemm |                                FIELDTYPE *type1,
410e3d5408SPeter Wemm |                                FIELDTYPE *type2)
420e3d5408SPeter Wemm |
430e3d5408SPeter Wemm |   Description   :  Create a new fieldtype built from the two given types.
440e3d5408SPeter Wemm |                    They are connected by an logical 'OR'.
450e3d5408SPeter Wemm |                    If an error occurs, errno is set to
460e3d5408SPeter Wemm |                       E_BAD_ARGUMENT  - invalid arguments
470e3d5408SPeter Wemm |                       E_SYSTEM_ERROR  - system error (no memory)
480e3d5408SPeter Wemm |
494a1a9510SRong-En Fan |   Return Values :  Fieldtype pointer or NULL if error occurred.
500e3d5408SPeter Wemm +--------------------------------------------------------------------------*/
517a69bbfbSPeter Wemm NCURSES_EXPORT(FIELDTYPE *)
524a1a9510SRong-En Fan link_fieldtype(FIELDTYPE *type1, FIELDTYPE *type2)
530e3d5408SPeter Wemm {
540e3d5408SPeter Wemm   FIELDTYPE *nftyp = (FIELDTYPE *)0;
550e3d5408SPeter Wemm 
564a1a9510SRong-En Fan   T((T_CALLED("link_fieldtype(%p,%p)"), type1, type2));
570e3d5408SPeter Wemm   if (type1 && type2)
580e3d5408SPeter Wemm     {
595ca44d1cSRong-En Fan       nftyp = typeMalloc(FIELDTYPE, 1);
604a1a9510SRong-En Fan 
610e3d5408SPeter Wemm       if (nftyp)
620e3d5408SPeter Wemm 	{
635ca44d1cSRong-En Fan 	  T((T_CREATE("fieldtype %p"), nftyp));
640e3d5408SPeter Wemm 	  *nftyp = *_nc_Default_FieldType;
650e3d5408SPeter Wemm 	  nftyp->status |= _LINKED_TYPE;
660e3d5408SPeter Wemm 	  if ((type1->status & _HAS_ARGS) || (type2->status & _HAS_ARGS))
670e3d5408SPeter Wemm 	    nftyp->status |= _HAS_ARGS;
680e3d5408SPeter Wemm 	  if ((type1->status & _HAS_CHOICE) || (type2->status & _HAS_CHOICE))
690e3d5408SPeter Wemm 	    nftyp->status |= _HAS_CHOICE;
700e3d5408SPeter Wemm 	  nftyp->left = type1;
710e3d5408SPeter Wemm 	  nftyp->right = type2;
720e3d5408SPeter Wemm 	  type1->ref++;
730e3d5408SPeter Wemm 	  type2->ref++;
740e3d5408SPeter Wemm 	}
750e3d5408SPeter Wemm       else
760e3d5408SPeter Wemm 	{
770e3d5408SPeter Wemm 	  SET_ERROR(E_SYSTEM_ERROR);
780e3d5408SPeter Wemm 	}
790e3d5408SPeter Wemm     }
800e3d5408SPeter Wemm   else
810e3d5408SPeter Wemm     {
820e3d5408SPeter Wemm       SET_ERROR(E_BAD_ARGUMENT);
830e3d5408SPeter Wemm     }
844a1a9510SRong-En Fan   returnFieldType(nftyp);
850e3d5408SPeter Wemm }
860e3d5408SPeter Wemm 
870e3d5408SPeter Wemm /* fld_ftlink.c ends here */
88