10e3d5408SPeter Wemm /**************************************************************************** 2e1865124SBaptiste Daroussin * Copyright 2020 Thomas E. Dickey * 3e1865124SBaptiste Daroussin * Copyright 1998-2010,2012 Free Software Foundation, Inc. * 40e3d5408SPeter Wemm * * 50e3d5408SPeter Wemm * Permission is hereby granted, free of charge, to any person obtaining a * 60e3d5408SPeter Wemm * copy of this software and associated documentation files (the * 70e3d5408SPeter Wemm * "Software"), to deal in the Software without restriction, including * 80e3d5408SPeter Wemm * without limitation the rights to use, copy, modify, merge, publish, * 90e3d5408SPeter Wemm * distribute, distribute with modifications, sublicense, and/or sell * 100e3d5408SPeter Wemm * copies of the Software, and to permit persons to whom the Software is * 110e3d5408SPeter Wemm * furnished to do so, subject to the following conditions: * 120e3d5408SPeter Wemm * * 130e3d5408SPeter Wemm * The above copyright notice and this permission notice shall be included * 140e3d5408SPeter Wemm * in all copies or substantial portions of the Software. * 150e3d5408SPeter Wemm * * 160e3d5408SPeter Wemm * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 170e3d5408SPeter Wemm * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 180e3d5408SPeter Wemm * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 190e3d5408SPeter Wemm * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 200e3d5408SPeter Wemm * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 210e3d5408SPeter Wemm * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 220e3d5408SPeter Wemm * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 230e3d5408SPeter Wemm * * 240e3d5408SPeter Wemm * Except as contained in this notice, the name(s) of the above copyright * 250e3d5408SPeter Wemm * holders shall not be used in advertising or otherwise to promote the * 260e3d5408SPeter Wemm * sale, use or other dealings in this Software without prior written * 270e3d5408SPeter Wemm * authorization. * 280e3d5408SPeter Wemm ****************************************************************************/ 290e3d5408SPeter Wemm 300e3d5408SPeter Wemm /**************************************************************************** 314a1a9510SRong-En Fan * Author: Juergen Pfeifer, 1995,1997 * 320e3d5408SPeter Wemm ****************************************************************************/ 330e3d5408SPeter Wemm 340e3d5408SPeter Wemm #include "form.priv.h" 350e3d5408SPeter Wemm 36*7a656419SBaptiste Daroussin MODULE_ID("$Id: fld_ftlink.c,v 1.17 2020/05/24 01:40:20 anonymous.maarten Exp $") 370e3d5408SPeter Wemm 380e3d5408SPeter Wemm /*--------------------------------------------------------------------------- 390e3d5408SPeter Wemm | Facility : libnform 400e3d5408SPeter Wemm | Function : FIELDTYPE *link_fieldtype( 410e3d5408SPeter Wemm | FIELDTYPE *type1, 420e3d5408SPeter Wemm | FIELDTYPE *type2) 430e3d5408SPeter Wemm | 440e3d5408SPeter Wemm | Description : Create a new fieldtype built from the two given types. 450e3d5408SPeter Wemm | They are connected by an logical 'OR'. 460e3d5408SPeter Wemm | If an error occurs, errno is set to 470e3d5408SPeter Wemm | E_BAD_ARGUMENT - invalid arguments 480e3d5408SPeter Wemm | E_SYSTEM_ERROR - system error (no memory) 490e3d5408SPeter Wemm | 504a1a9510SRong-En Fan | Return Values : Fieldtype pointer or NULL if error occurred. 510e3d5408SPeter Wemm +--------------------------------------------------------------------------*/ 52*7a656419SBaptiste Daroussin FORM_EXPORT(FIELDTYPE *) 534a1a9510SRong-En Fan link_fieldtype(FIELDTYPE *type1, FIELDTYPE *type2) 540e3d5408SPeter Wemm { 550e3d5408SPeter Wemm FIELDTYPE *nftyp = (FIELDTYPE *)0; 560e3d5408SPeter Wemm 5706bfebdeSXin LI T((T_CALLED("link_fieldtype(%p,%p)"), (void *)type1, (void *)type2)); 580e3d5408SPeter Wemm if (type1 && type2) 590e3d5408SPeter Wemm { 605ca44d1cSRong-En Fan nftyp = typeMalloc(FIELDTYPE, 1); 614a1a9510SRong-En Fan 620e3d5408SPeter Wemm if (nftyp) 630e3d5408SPeter Wemm { 6406bfebdeSXin LI T((T_CREATE("fieldtype %p"), (void *)nftyp)); 650e3d5408SPeter Wemm *nftyp = *_nc_Default_FieldType; 6673f0a83dSXin LI SetStatus(nftyp, _LINKED_TYPE); 670e3d5408SPeter Wemm if ((type1->status & _HAS_ARGS) || (type2->status & _HAS_ARGS)) 6873f0a83dSXin LI SetStatus(nftyp, _HAS_ARGS); 690e3d5408SPeter Wemm if ((type1->status & _HAS_CHOICE) || (type2->status & _HAS_CHOICE)) 7073f0a83dSXin LI SetStatus(nftyp, _HAS_CHOICE); 710e3d5408SPeter Wemm nftyp->left = type1; 720e3d5408SPeter Wemm nftyp->right = type2; 730e3d5408SPeter Wemm type1->ref++; 740e3d5408SPeter Wemm type2->ref++; 750e3d5408SPeter Wemm } 760e3d5408SPeter Wemm else 770e3d5408SPeter Wemm { 780e3d5408SPeter Wemm SET_ERROR(E_SYSTEM_ERROR); 790e3d5408SPeter Wemm } 800e3d5408SPeter Wemm } 810e3d5408SPeter Wemm else 820e3d5408SPeter Wemm { 830e3d5408SPeter Wemm SET_ERROR(E_BAD_ARGUMENT); 840e3d5408SPeter Wemm } 854a1a9510SRong-En Fan returnFieldType(nftyp); 860e3d5408SPeter Wemm } 870e3d5408SPeter Wemm 880e3d5408SPeter Wemm /* fld_ftlink.c ends here */ 89