GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libform/fld_current.c Lines: 0 21 0.0 %
Date: 2017-11-13 Branches: 0 36 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: fld_current.c,v 1.6 2015/01/23 22:48:51 krw Exp $	*/
2
/****************************************************************************
3
 * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc.              *
4
 *                                                                          *
5
 * Permission is hereby granted, free of charge, to any person obtaining a  *
6
 * copy of this software and associated documentation files (the            *
7
 * "Software"), to deal in the Software without restriction, including      *
8
 * without limitation the rights to use, copy, modify, merge, publish,      *
9
 * distribute, distribute with modifications, sublicense, and/or sell       *
10
 * copies of the Software, and to permit persons to whom the Software is    *
11
 * furnished to do so, subject to the following conditions:                 *
12
 *                                                                          *
13
 * The above copyright notice and this permission notice shall be included  *
14
 * in all copies or substantial portions of the Software.                   *
15
 *                                                                          *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19
 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22
 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23
 *                                                                          *
24
 * Except as contained in this notice, the name(s) of the above copyright   *
25
 * holders shall not be used in advertising or otherwise to promote the     *
26
 * sale, use or other dealings in this Software without prior written       *
27
 * authorization.                                                           *
28
 ****************************************************************************/
29
30
/****************************************************************************
31
 *   Author:  Juergen Pfeifer, 1995,1997                                    *
32
 ****************************************************************************/
33
34
#include "form.priv.h"
35
36
MODULE_ID("$Id: fld_current.c,v 1.6 2015/01/23 22:48:51 krw Exp $")
37
38
/*---------------------------------------------------------------------------
39
|   Facility      :  libnform
40
|   Function      :  int set_current_field(FORM  * form,FIELD * field)
41
|
42
|   Description   :  Set the current field of the form to the specified one.
43
|
44
|   Return Values :  E_OK              - success
45
|                    E_BAD_ARGUMENT    - invalid form or field pointer
46
|                    E_REQUEST_DENIED  - field not selectable
47
|                    E_BAD_STATE       - called from a hook routine
48
|                    E_INVALID_FIELD   - current field can't be left
49
|                    E_SYSTEM_ERROR    - system error
50
+--------------------------------------------------------------------------*/
51
NCURSES_EXPORT(int)
52
set_current_field(FORM *form, FIELD *field)
53
{
54
  int err = E_OK;
55
56
  T((T_CALLED("set_current_field(%p,%p)"), form, field));
57
  if (form == 0 || field == 0)
58
    {
59
      RETURN(E_BAD_ARGUMENT);
60
    }
61
  else if ((form != field->form) || Field_Is_Not_Selectable(field))
62
    {
63
      RETURN(E_REQUEST_DENIED);
64
    }
65
  else if ((form->status & _POSTED) == 0)
66
    {
67
      form->current = field;
68
      form->curpage = field->page;
69
    }
70
  else
71
    {
72
      if ((form->status & _IN_DRIVER) != 0)
73
	{
74
	  err = E_BAD_STATE;
75
	}
76
      else
77
	{
78
	  if (form->current != field)
79
	    {
80
	      if (!_nc_Internal_Validation(form))
81
		{
82
		  err = E_INVALID_FIELD;
83
		}
84
	      else
85
		{
86
		  Call_Hook(form, fieldterm);
87
		  if (field->page != form->curpage)
88
		    {
89
		      Call_Hook(form, formterm);
90
		      err = _nc_Set_Form_Page(form, (int)field->page, field);
91
		      Call_Hook(form, forminit);
92
		    }
93
		  else
94
		    {
95
		      err = _nc_Set_Current_Field(form, field);
96
		    }
97
		  Call_Hook(form, fieldinit);
98
		  (void)_nc_Refresh_Current_Field(form);
99
		}
100
	    }
101
	}
102
    }
103
  RETURN(err);
104
}
105
106
/*---------------------------------------------------------------------------
107
|   Facility      :  libnform
108
|   Function      :  FIELD *current_field(const FORM * form)
109
|
110
|   Description   :  Return the current field.
111
|
112
|   Return Values :  Pointer to the current field.
113
+--------------------------------------------------------------------------*/
114
NCURSES_EXPORT(FIELD *)
115
current_field(const FORM *form)
116
{
117
  T((T_CALLED("current_field(%p)"), form));
118
  returnField(Normalize_Form(form)->current);
119
}
120
121
/*---------------------------------------------------------------------------
122
|   Facility      :  libnform
123
|   Function      :  int field_index(const FIELD * field)
124
|
125
|   Description   :  Return the index of the field in the field-array of
126
|                    the form.
127
|
128
|   Return Values :  >= 0   : field index
129
|                    -1     : fieldpointer invalid or field not connected
130
+--------------------------------------------------------------------------*/
131
NCURSES_EXPORT(int)
132
field_index(const FIELD *field)
133
{
134
  T((T_CALLED("field_index(%p)"), field));
135
  returnCode((field != 0 && field->form != 0) ? (int)field->index : -1);
136
}
137
138
/* fld_current.c ends here */