ncurses 6.1 - patch 20180929
[ncurses.git] / form / frm_driver.c
index c9275f7e51625e0fea28eb7b0799aed67c9b5a13..9d0b7d3e7f29706edc972efd48ffa4d505ca2adc 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2017,2018 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
 
 /****************************************************************************
  *   Author:  Juergen Pfeifer, 1995,1997                                    *
 
 /****************************************************************************
  *   Author:  Juergen Pfeifer, 1995,1997                                    *
- *   Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en             *
  ****************************************************************************/
  ****************************************************************************/
+
 #include "form.priv.h"
 
 #include "form.priv.h"
 
-MODULE_ID("$Id: frm_driver.c,v 1.39 2002/07/06 15:33:27 juergen Exp $")
+MODULE_ID("$Id: frm_driver.c,v 1.127 2018/09/08 19:03:39 tom Exp $")
 
 /*----------------------------------------------------------------------------
   This is the core module of the form library. It contains the majority
 
 /*----------------------------------------------------------------------------
   This is the core module of the form library. It contains the majority
-  of the driver routines as well as the form_driver function. 
+  of the driver routines as well as the form_driver function.
 
   Essentially this module is nearly the whole library. This is because
   all the functions in this module depends on some others in the module,
   so it makes no sense to split them into separate files because they
   will always be linked together. The only acceptable concern is turnaround
 
   Essentially this module is nearly the whole library. This is because
   all the functions in this module depends on some others in the module,
   so it makes no sense to split them into separate files because they
   will always be linked together. The only acceptable concern is turnaround
-  time for this module, but now we have all Pentiums or Riscs, so what!
+  time for this module, but now we have all Pentiums or RISCs, so what!
 
   The driver routines are grouped into nine generic categories:
 
 
   The driver routines are grouped into nine generic categories:
 
@@ -53,12 +53,12 @@ MODULE_ID("$Id: frm_driver.c,v 1.39 2002/07/06 15:33:27 juergen Exp $")
         The current field of the form is left and some new field is
         entered.
    c)   Intra-Field Navigation     ( all functions prefixed by IFN_ )
         The current field of the form is left and some new field is
         entered.
    c)   Intra-Field Navigation     ( all functions prefixed by IFN_ )
-        The current position in the current field is changed. 
+        The current position in the current field is changed.
    d)   Vertical Scrolling         ( all functions prefixed by VSC_ )
    d)   Vertical Scrolling         ( all functions prefixed by VSC_ )
-        Esseantially this is a specialization of Intra-Field navigation.
+        Essentially this is a specialization of Intra-Field navigation.
         It has to check for a multi-line field.
    e)   Horizontal Scrolling       ( all functions prefixed by HSC_ )
         It has to check for a multi-line field.
    e)   Horizontal Scrolling       ( all functions prefixed by HSC_ )
-        Esseantially this is a specialization of Intra-Field navigation.
+        Essentially this is a specialization of Intra-Field navigation.
         It has to check for a single-line field.
    f)   Field Editing              ( all functions prefixed by FE_ )
         The content of the current field is changed
         It has to check for a single-line field.
    f)   Field Editing              ( all functions prefixed by FE_ )
         The content of the current field is changed
@@ -79,34 +79,46 @@ MODULE_ID("$Id: frm_driver.c,v 1.39 2002/07/06 15:33:27 juergen Exp $")
 
 /*
 Some options that may effect compatibility in behavior to SVr4 forms,
 
 /*
 Some options that may effect compatibility in behavior to SVr4 forms,
-but they are here to allow a more intuitive and user friendly behaviour of
+but they are here to allow a more intuitive and user friendly behavior of
 our form implementation. This doesn't affect the API, so we feel it is
 uncritical.
 
 our form implementation. This doesn't affect the API, so we feel it is
 uncritical.
 
-The initial implementation tries to stay very close with the behaviour
+The initial implementation tries to stay very close with the behavior
 of the original SVr4 implementation, although in some areas it is quite
 clear that this isn't the most appropriate way. As far as possible this
 sources will allow you to build a forms lib that behaves quite similar
 of the original SVr4 implementation, although in some areas it is quite
 clear that this isn't the most appropriate way. As far as possible this
 sources will allow you to build a forms lib that behaves quite similar
-to SVr4, but now and in the future we will give you better options. 
+to SVr4, but now and in the future we will give you better options.
 Perhaps at some time we will make this configurable at runtime.
 */
 
 Perhaps at some time we will make this configurable at runtime.
 */
 
-/* Implement a more user-friendly previous/next word behaviour */
+/* Implement a more user-friendly previous/next word behavior */
 #define FRIENDLY_PREV_NEXT_WORD (1)
 #define FRIENDLY_PREV_NEXT_WORD (1)
-/* Fix the wrong behaviour for forms with all fields inactive */
+/* Fix the wrong behavior for forms with all fields inactive */
 #define FIX_FORM_INACTIVE_BUG (1)
 /* Allow dynamic field growth also when navigating past the end */
 #define GROW_IF_NAVIGATE (1)
 
 #define FIX_FORM_INACTIVE_BUG (1)
 /* Allow dynamic field growth also when navigating past the end */
 #define GROW_IF_NAVIGATE (1)
 
+#if USE_WIDEC_SUPPORT
+#define myADDNSTR(w, s, n) wide_waddnstr(w, s, n)
+#define myINSNSTR(w, s, n) wide_winsnstr(w, s, n)
+#define myINNSTR(w, s, n)  wide_winnstr(w, s, n)
+#define myWCWIDTH(w, y, x) cell_width(w, y, x)
+#else
+#define myADDNSTR(w, s, n) waddnstr(w, s, n)
+#define myINSNSTR(w, s, n) winsnstr(w, s, n)
+#define myINNSTR(w, s, n)  winnstr(w, s, n)
+#define myWCWIDTH(w, y, x) 1
+#endif
+
 /*----------------------------------------------------------------------------
   Forward references to some internally used static functions
   --------------------------------------------------------------------------*/
 /*----------------------------------------------------------------------------
   Forward references to some internally used static functions
   --------------------------------------------------------------------------*/
-static int Inter_Field_Navigation ( int (* const fct) (FORM *), FORM * form );
-static int FN_Next_Field (FORM * form);
-static int FN_Previous_Field (FORM * form);
+static int Inter_Field_Navigation(int (*const fct) (FORM *), FORM *form);
+static int FN_Next_Field(FORM *form);
+static int FN_Previous_Field(FORM *form);
 static int FE_New_Line(FORM *);
 static int FE_Delete_Previous(FORM *);
 static int FE_New_Line(FORM *);
 static int FE_Delete_Previous(FORM *);
-\f
+
 /*----------------------------------------------------------------------------
   Macro Definitions.
 
 /*----------------------------------------------------------------------------
   Macro Definitions.
 
@@ -150,7 +162,7 @@ static int FE_Delete_Previous(FORM *);
 #define Address_Of_Current_Position_In_Buffer(form) \
   Address_Of_Current_Position_In_Nth_Buffer(form,0)
 
 #define Address_Of_Current_Position_In_Buffer(form) \
   Address_Of_Current_Position_In_Nth_Buffer(form,0)
 
-/* Logic to decide wether or not a field is actually a field with
+/* Logic to decide whether or not a field is actually a field with
    vertical or horizontal scrolling */
 #define Is_Scroll_Field(field)          \
    (((field)->drows > (field)->rows) || \
    vertical or horizontal scrolling */
 #define Is_Scroll_Field(field)          \
    (((field)->drows > (field)->rows) || \
@@ -160,29 +172,30 @@ static int FE_Delete_Previous(FORM *);
    instead of a derived window because it contains invisible parts.
    This is true for non-public fields and for scrollable fields. */
 #define Has_Invisible_Parts(field)     \
    instead of a derived window because it contains invisible parts.
    This is true for non-public fields and for scrollable fields. */
 #define Has_Invisible_Parts(field)     \
-  (!((field)->opts & O_PUBLIC)      || \
+  (!(Field_Has_Option(field, O_PUBLIC)) || \
    Is_Scroll_Field(field))
 
 /* Logic to decide whether or not a field needs justification */
 #define Justification_Allowed(field)        \
    (((field)->just != NO_JUSTIFICATION)  && \
     (Single_Line_Field(field))           && \
    Is_Scroll_Field(field))
 
 /* Logic to decide whether or not a field needs justification */
 #define Justification_Allowed(field)        \
    (((field)->just != NO_JUSTIFICATION)  && \
     (Single_Line_Field(field))           && \
-    (((field)->dcols == (field)->cols)   && \
-    ((field)->opts & O_STATIC))             )
+    ((Field_Has_Option(field, O_STATIC)  && \
+     ((field)->dcols == (field)->cols))  || \
+    Field_Has_Option(field, O_DYNAMIC_JUSTIFY)))
 
 /* Logic to determine whether or not a dynamic field may still grow */
 #define Growable(field) ((field)->status & _MAY_GROW)
 
 /* Macro to set the attributes for a fields window */
 #define Set_Field_Window_Attributes(field,win) \
 
 /* Logic to determine whether or not a dynamic field may still grow */
 #define Growable(field) ((field)->status & _MAY_GROW)
 
 /* Macro to set the attributes for a fields window */
 #define Set_Field_Window_Attributes(field,win) \
-(  wbkgdset((win),(chtype)((field)->pad | (field)->back)), \
-   wattrset((win),(field)->fore) )
+(  wbkgdset((win),(chtype)((chtype)((field)->pad) | (field)->back)), \
+   (void) wattrset((win), (int)(field)->fore) )
 
 /* Logic to decide whether or not a field really appears on the form */
 #define Field_Really_Appears(field)         \
   ((field->form)                          &&\
    (field->form->status & _POSTED)        &&\
 
 /* Logic to decide whether or not a field really appears on the form */
 #define Field_Really_Appears(field)         \
   ((field->form)                          &&\
    (field->form->status & _POSTED)        &&\
-   (field->opts & O_VISIBLE)              &&\
+   (Field_Has_Option(field, O_VISIBLE))   &&\
    (field->page == field->form->curpage))
 
 /* Logic to determine whether or not we are on the first position in the
    (field->page == field->form->curpage))
 
 /* Logic to determine whether or not we are on the first position in the
@@ -190,168 +203,343 @@ static int FE_Delete_Previous(FORM *);
 #define First_Position_In_Current_Field(form) \
   (((form)->currow==0) && ((form)->curcol==0))
 
 #define First_Position_In_Current_Field(form) \
   (((form)->currow==0) && ((form)->curcol==0))
 
-
 #define Minimum(a,b) (((a)<=(b)) ? (a) : (b))
 #define Maximum(a,b) (((a)>=(b)) ? (a) : (b))
 #define Minimum(a,b) (((a)<=(b)) ? (a) : (b))
 #define Maximum(a,b) (((a)>=(b)) ? (a) : (b))
-\f
+
+/*----------------------------------------------------------------------------
+  Useful constants
+  --------------------------------------------------------------------------*/
+static FIELD_CELL myBLANK = BLANK;
+static FIELD_CELL myZEROS;
+
+#ifdef TRACE
+static void
+check_pos(FORM *form, int lineno)
+{
+  int y, x;
+
+  if (form && form->w)
+    {
+      getyx(form->w, y, x);
+      if (y != form->currow || x != form->curcol)
+       {
+         T(("CHECKPOS %s@%d have position %d,%d vs want %d,%d",
+            __FILE__, lineno,
+            y, x,
+            form->currow, form->curcol));
+       }
+    }
+}
+#define CHECKPOS(form) check_pos(form, __LINE__)
+#else
+#define CHECKPOS(form)         /* nothing */
+#endif
+
+/*----------------------------------------------------------------------------
+  Wide-character special functions
+  --------------------------------------------------------------------------*/
+#if USE_WIDEC_SUPPORT
+/* add like waddnstr, but using cchar_t* rather than char*
+ */
+static int
+wide_waddnstr(WINDOW *w, const cchar_t *s, int n)
+{
+  int rc = OK;
+
+  while (n-- > 0)
+    {
+      if ((rc = wadd_wch(w, s)) != OK)
+       break;
+      ++s;
+    }
+  return rc;
+}
+
+/* insert like winsnstr, but using cchar_t* rather than char*
+ *
+ * X/Open Curses has no close equivalent; inserts are done only with wchar_t
+ * strings.
+ */
+static int
+wide_winsnstr(WINDOW *w, const cchar_t *s, int n)
+{
+  int code = ERR;
+  int y, x;
+
+  while (n-- > 0)
+    {
+      getyx(w, y, x);
+      if ((code = wins_wch(w, s++)) != OK)
+       break;
+      if ((code = wmove(w, y, x + 1)) != OK)
+       break;
+    }
+  return code;
+}
+
+/* retrieve like winnstr, but using cchar_t*, rather than char*.
+ *
+ * X/Open Curses' closest equivalent, win_wchnstr(), is inconsistent with
+ * winnstr(), since it returns OK rather than the number of items transferred.
+ */
+static int
+wide_winnstr(WINDOW *w, cchar_t *s, int n)
+{
+  int x;
+
+  win_wchnstr(w, s, n);
+  /*
+   * This function is used to extract the text only from the window.
+   * Strip attributes and color from the string so they will not be added
+   * back when copying the string to the window.
+   */
+  for (x = 0; x < n; ++x)
+    {
+      RemAttr(s[x], A_ATTRIBUTES);
+      SetPair(s[x], 0);
+    }
+  return n;
+}
+
+/*
+ * Returns the column of the base of the given cell.
+ */
+static int
+cell_base(WINDOW *win, int y, int x)
+{
+  int result = x;
+
+  while (LEGALYX(win, y, x))
+    {
+      cchar_t *data = &(win->_line[y].text[x]);
+
+      if (isWidecBase(CHDEREF(data)) || !isWidecExt(CHDEREF(data)))
+       {
+         result = x;
+         break;
+       }
+      --x;
+    }
+  return result;
+}
+
+/*
+ * Returns the number of columns needed for the given cell in a window.
+ */
+static int
+cell_width(WINDOW *win, int y, int x)
+{
+  int result = 1;
+
+  if (LEGALYX(win, y, x))
+    {
+      cchar_t *data = &(win->_line[y].text[x]);
+
+      if (isWidecExt(CHDEREF(data)))
+       {
+         /* recur, providing the number of columns to the next character */
+         result = cell_width(win, y, x - 1);
+       }
+      else
+       {
+         result = wcwidth(CharOf(CHDEREF(data)));
+       }
+    }
+  return result;
+}
+
+/*
+ * There is no wide-character function such as wdel_wch(), so we must find
+ * all of the cells that comprise a multi-column character and delete them
+ * one-by-one.
+ */
+static void
+delete_char(FORM *form)
+{
+  int cells = cell_width(form->w, form->currow, form->curcol);
+
+  form->curcol = cell_base(form->w, form->currow, form->curcol);
+  wmove(form->w, form->currow, form->curcol);
+  while (cells-- > 0)
+    {
+      wdelch(form->w);
+    }
+}
+#define DeleteChar(form) delete_char(form)
+#else
+#define DeleteChar(form) \
+         wmove((form)->w, (form)->currow, (form)->curcol), \
+         wdelch((form)->w)
+#endif
+
 /*---------------------------------------------------------------------------
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static char *Get_Start_Of_Data(char * buf, int blen)
 |   Function      :  static char *Get_Start_Of_Data(char * buf, int blen)
-|   
+|
 |   Description   :  Return pointer to first non-blank position in buffer.
 |                    If buffer is empty return pointer to buffer itself.
 |
 |   Return Values :  Pointer to first non-blank position in buffer
 +--------------------------------------------------------------------------*/
 |   Description   :  Return pointer to first non-blank position in buffer.
 |                    If buffer is empty return pointer to buffer itself.
 |
 |   Return Values :  Pointer to first non-blank position in buffer
 +--------------------------------------------------------------------------*/
-INLINE static char *Get_Start_Of_Data(char * buf, int blen)
+NCURSES_INLINE static FIELD_CELL *
+Get_Start_Of_Data(FIELD_CELL *buf, int blen)
 {
 {
-  char *p   = buf;
-  char *end = &buf[blen];
+  FIELD_CELL *p = buf;
+  FIELD_CELL *end = &buf[blen];
 
 
-  assert(buf && blen>=0);
-  while( (p < end) && is_blank(*p) ) 
+  assert(buf && blen >= 0);
+  while ((p < end) && ISBLANK(*p))
     p++;
     p++;
-  return( (p==end) ? buf : p );
+  return ((p == end) ? buf : p);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static char *After_End_Of_Data(char * buf, int blen)
 |   Function      :  static char *After_End_Of_Data(char * buf, int blen)
-|   
+|
 |   Description   :  Return pointer after last non-blank position in buffer.
 |                    If buffer is empty, return pointer to buffer itself.
 |
 |   Description   :  Return pointer after last non-blank position in buffer.
 |                    If buffer is empty, return pointer to buffer itself.
 |
-|   Return Values :  Pointer to position after last non-blank position in 
+|   Return Values :  Pointer to position after last non-blank position in
 |                    buffer.
 +--------------------------------------------------------------------------*/
 |                    buffer.
 +--------------------------------------------------------------------------*/
-INLINE static char *After_End_Of_Data(char * buf,int blen)
+NCURSES_INLINE static FIELD_CELL *
+After_End_Of_Data(FIELD_CELL *buf, int blen)
 {
 {
-  char *p   = &buf[blen];
-  
-  assert(buf && blen>=0);
-  while( (p>buf) && is_blank(p[-1]) ) 
+  FIELD_CELL *p = &buf[blen];
+
+  assert(buf && blen >= 0);
+  while ((p > buf) && ISBLANK(p[-1]))
     p--;
     p--;
-  return( p );
+  return (p);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static char *Get_First_Whitespace_Character(
 |                                     char * buf, int   blen)
 |   Function      :  static char *Get_First_Whitespace_Character(
 |                                     char * buf, int   blen)
-|   
+|
 |   Description   :  Position to the first whitespace character.
 |
 |   Return Values :  Pointer to first whitespace character in buffer.
 +--------------------------------------------------------------------------*/
 |   Description   :  Position to the first whitespace character.
 |
 |   Return Values :  Pointer to first whitespace character in buffer.
 +--------------------------------------------------------------------------*/
-INLINE static char *Get_First_Whitespace_Character(char * buf, int blen)
+NCURSES_INLINE static FIELD_CELL *
+Get_First_Whitespace_Character(FIELD_CELL *buf, int blen)
 {
 {
-  char *p   = buf;
-  char *end = &p[blen];
-  
-  assert(buf && blen>=0);
-  while( (p < end) && !is_blank(*p)) 
+  FIELD_CELL *p = buf;
+  FIELD_CELL *end = &p[blen];
+
+  assert(buf && blen >= 0);
+  while ((p < end) && !ISBLANK(*p))
     p++;
     p++;
-  return( (p==end) ? buf : p );
+  return ((p == end) ? buf : p);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static char *After_Last_Whitespace_Character(
 |                                     char * buf, int blen)
 |   Function      :  static char *After_Last_Whitespace_Character(
 |                                     char * buf, int blen)
-|   
+|
 |   Description   :  Get the position after the last whitespace character.
 |
 |   Description   :  Get the position after the last whitespace character.
 |
-|   Return Values :  Pointer to position after last whitespace character in 
+|   Return Values :  Pointer to position after last whitespace character in
 |                    buffer.
 +--------------------------------------------------------------------------*/
 |                    buffer.
 +--------------------------------------------------------------------------*/
-INLINE static char *After_Last_Whitespace_Character(char * buf, int blen)
+NCURSES_INLINE static FIELD_CELL *
+After_Last_Whitespace_Character(FIELD_CELL *buf, int blen)
 {
 {
-  char *p   = &buf[blen];
-  
-  assert(buf && blen>=0);
-  while( (p>buf) && !is_blank(p[-1]) ) 
+  FIELD_CELL *p = &buf[blen];
+
+  assert(buf && blen >= 0);
+  while ((p > buf) && !ISBLANK(p[-1]))
     p--;
     p--;
-  return( p );
+  return (p);
 }
 
 /* Set this to 1 to use the div_t version. This is a good idea if your
    compiler has an intrinsic div() support. Unfortunately GNU-C has it
 }
 
 /* Set this to 1 to use the div_t version. This is a good idea if your
    compiler has an intrinsic div() support. Unfortunately GNU-C has it
-   not yet. 
+   not yet.
    N.B.: This only works if form->curcol follows immediately form->currow
    N.B.: This only works if form->curcol follows immediately form->currow
-         and both are of type int. 
+         and both are of type int.
 */
 #define USE_DIV_T (0)
 
 /*---------------------------------------------------------------------------
 */
 #define USE_DIV_T (0)
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static void Adjust_Cursor_Position(
 |                                       FORM * form, const char * pos)
 |   Function      :  static void Adjust_Cursor_Position(
 |                                       FORM * form, const char * pos)
-|   
-|   Description   :  Set current row and column of the form to values 
+|
+|   Description   :  Set current row and column of the form to values
 |                    corresponding to the buffer position.
 |
 |   Return Values :  -
 +--------------------------------------------------------------------------*/
 |                    corresponding to the buffer position.
 |
 |   Return Values :  -
 +--------------------------------------------------------------------------*/
-INLINE static void Adjust_Cursor_Position(FORM * form, const char * pos)
+NCURSES_INLINE static void
+Adjust_Cursor_Position(FORM *form, const FIELD_CELL *pos)
 {
   FIELD *field;
   int idx;
 
   field = form->current;
 {
   FIELD *field;
   int idx;
 
   field = form->current;
-  assert( pos >= field->buf && field->dcols > 0);
-  idx = (int)( pos - field->buf );
+  assert(pos >= field->buf && field->dcols > 0);
+  idx = (int)(pos - field->buf);
 #if USE_DIV_T
 #if USE_DIV_T
-  *((div_t *)&(form->currow)) = div(idx,field->dcols);
+  *((div_t *) & (form->currow)) = div(idx, field->dcols);
 #else
   form->currow = idx / field->dcols;
   form->curcol = idx - field->cols * form->currow;
 #else
   form->currow = idx / field->dcols;
   form->curcol = idx - field->cols * form->currow;
-#endif  
-  if ( field->drows < form->currow )
+#endif
+  if (field->drows < form->currow)
     form->currow = 0;
 }
 
 /*---------------------------------------------------------------------------
     form->currow = 0;
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static void Buffer_To_Window(
 |                                      const FIELD  * field,
 |                                      WINDOW * win)
 |   Function      :  static void Buffer_To_Window(
 |                                      const FIELD  * field,
 |                                      WINDOW * win)
-|   
-|   Description   :  Copy the buffer to the window. If its a multiline
+|
+|   Description   :  Copy the buffer to the window. If it is a multi-line
 |                    field, the buffer is split to the lines of the
 |                    window without any editing.
 |
 |   Return Values :  -
 +--------------------------------------------------------------------------*/
 |                    field, the buffer is split to the lines of the
 |                    window without any editing.
 |
 |   Return Values :  -
 +--------------------------------------------------------------------------*/
-static void Buffer_To_Window(const FIELD  * field, WINDOW * win)
+static void
+Buffer_To_Window(const FIELD *field, WINDOW *win)
 {
   int width, height;
 {
   int width, height;
+  int y, x;
   int len;
   int row;
   int len;
   int row;
-  char *pBuffer;
+  FIELD_CELL *pBuffer;
 
   assert(win && field);
 
 
   assert(win && field);
 
-  width  = getmaxx(win);
+  getyx(win, y, x);
+  width = getmaxx(win);
   height = getmaxy(win);
 
   height = getmaxy(win);
 
-  for(row=0, pBuffer=field->buf; 
-      row < height; 
-      row++, pBuffer += width )
+  for (row = 0, pBuffer = field->buf;
+       row < height;
+       row++, pBuffer += width)
     {
     {
-      if ((len = (int)( After_End_Of_Data( pBuffer, width ) - pBuffer )) > 0)
+      if ((len = (int)(After_End_Of_Data(pBuffer, width) - pBuffer)) > 0)
        {
        {
-         wmove( win, row, 0 );
-         waddnstr( win, pBuffer, len );
+         wmove(win, row, 0);
+         myADDNSTR(win, pBuffer, len);
        }
        }
-    }  
+    }
+  wmove(win, y, x);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
-|   Function      :  static void Window_To_Buffer(
+|   Facility      :  libnform
+|   Function      :  void _nc_get_fieldbuffer(
 |                                          WINDOW * win,
 |                                          WINDOW * win,
-|                                          FIELD  * field)
-|   
+|                                          FIELD  * field,
+|                                          FIELD_CELL * buf)
+|
 |   Description   :  Copy the content of the window into the buffer.
 |                    The multiple lines of a window are simply
 |                    concatenated into the buffer. Pad characters in
 |   Description   :  Copy the content of the window into the buffer.
 |                    The multiple lines of a window are simply
 |                    concatenated into the buffer. Pad characters in
@@ -359,42 +547,71 @@ static void Buffer_To_Window(const FIELD  * field, WINDOW * win)
 |
 |   Return Values :  -
 +--------------------------------------------------------------------------*/
 |
 |   Return Values :  -
 +--------------------------------------------------------------------------*/
-static void Window_To_Buffer(WINDOW * win, FIELD  * field)
+NCURSES_EXPORT(void)
+_nc_get_fieldbuffer(FORM *form, FIELD *field, FIELD_CELL *buf)
 {
   int pad;
   int len = 0;
 {
   int pad;
   int len = 0;
-  char *p;
+  FIELD_CELL *p;
   int row, height;
   int row, height;
-  
-  assert(win && field && field->buf );
+  WINDOW *win;
+
+  assert(form && field && buf);
+
+  win = form->w;
+  assert(win);
 
   pad = field->pad;
 
   pad = field->pad;
-  p = field->buf;
+  p = buf;
   height = getmaxy(win);
 
   height = getmaxy(win);
 
-  for(row=0; (row < height) && (row < field->drows); row++ )
+  for (row = 0; (row < height) && (row < field->drows); row++)
     {
     {
-      wmove( win, row, 0 );
-      len += winnstr( win, p+len, field->dcols );
+      wmove(win, row, 0);
+      len += myINNSTR(win, p + len, field->dcols);
     }
     }
-  p[len] = '\0';
+  p[len] = myZEROS;
 
   /* replace visual padding character by blanks in buffer */
   if (pad != C_BLANK)
     {
       int i;
 
   /* replace visual padding character by blanks in buffer */
   if (pad != C_BLANK)
     {
       int i;
-      for(i=0; i<len; i++, p++)
+
+      for (i = 0; i < len; i++, p++)
        {
        {
-         if (*p==pad) 
-           *p = C_BLANK;
+         if ((unsigned long)CharOf(*p) == ChCharOf(pad)
+#if USE_WIDEC_SUPPORT
+             && p->chars[1] == 0
+#endif
+           )
+           *p = myBLANK;
        }
     }
 }
 
 /*---------------------------------------------------------------------------
        }
     }
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
+|   Function      :  static void Window_To_Buffer(
+|                                          FORM   * form,
+|                                          FIELD  * field)
+|
+|   Description   :  Copy the content of the window into the buffer.
+|                    The multiple lines of a window are simply
+|                    concatenated into the buffer. Pad characters in
+|                    the window will be replaced by blanks in the buffer.
+|
+|   Return Values :  -
++--------------------------------------------------------------------------*/
+static void
+Window_To_Buffer(FORM *form, FIELD *field)
+{
+  _nc_get_fieldbuffer(form, field, field->buf);
+}
+
+/*---------------------------------------------------------------------------
+|   Facility      :  libnform
 |   Function      :  static void Synchronize_Buffer(FORM * form)
 |   Function      :  static void Synchronize_Buffer(FORM * form)
-|   
+|
 |   Description   :  If there was a change, copy the content of the
 |                    window into the buffer, so the buffer is synchronized
 |                    with the windows content. We have to indicate that the
 |   Description   :  If there was a change, copy the content of the
 |                    window into the buffer, so the buffer is synchronized
 |                    with the windows content. We have to indicate that the
@@ -402,21 +619,22 @@ static void Window_To_Buffer(WINDOW * win, FIELD  * field)
 |
 |   Return Values :  -
 +--------------------------------------------------------------------------*/
 |
 |   Return Values :  -
 +--------------------------------------------------------------------------*/
-INLINE static void Synchronize_Buffer(FORM * form)
+NCURSES_INLINE static void
+Synchronize_Buffer(FORM *form)
 {
   if (form->status & _WINDOW_MODIFIED)
     {
 {
   if (form->status & _WINDOW_MODIFIED)
     {
-      form->status &= ~_WINDOW_MODIFIED;
-      form->status |=  _FCHECK_REQUIRED;
-      Window_To_Buffer(form->w,form->current);
-      wmove(form->w,form->currow,form->curcol);
+      ClrStatus(form, _WINDOW_MODIFIED);
+      SetStatus(form, _FCHECK_REQUIRED);
+      Window_To_Buffer(formform->current);
+      wmove(form->w, form->currow, form->curcol);
     }
 }
 
 /*---------------------------------------------------------------------------
     }
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static bool Field_Grown( FIELD *field, int amount)
 |   Function      :  static bool Field_Grown( FIELD *field, int amount)
-|   
+|
 |   Description   :  This function is called for growable dynamic fields
 |                    only. It has to increase the buffers and to allocate
 |                    a new window for this field.
 |   Description   :  This function is called for growable dynamic fields
 |                    only. It has to increase the buffers and to allocate
 |                    a new window for this field.
@@ -427,7 +645,8 @@ INLINE static void Synchronize_Buffer(FORM * form)
 |   Return Values :  TRUE     - field successfully increased
 |                    FALSE    - there was some error
 +--------------------------------------------------------------------------*/
 |   Return Values :  TRUE     - field successfully increased
 |                    FALSE    - there was some error
 +--------------------------------------------------------------------------*/
-static bool Field_Grown(FIELD * field, int amount)
+static bool
+Field_Grown(FIELD *field, int amount)
 {
   bool result = FALSE;
 
 {
   bool result = FALSE;
 
@@ -438,121 +657,167 @@ static bool Field_Grown(FIELD * field, int amount)
       int new_buflen;
       int old_dcols = field->dcols;
       int old_drows = field->drows;
       int new_buflen;
       int old_dcols = field->dcols;
       int old_drows = field->drows;
-      char *oldbuf  = field->buf;
-      char *newbuf;
+      FIELD_CELL *oldbuf = field->buf;
+      FIELD_CELL *newbuf;
 
       int growth;
       FORM *form = field->form;
 
       int growth;
       FORM *form = field->form;
-      bool need_visual_update = ((form != (FORM *)0)      &&
+      bool need_visual_update = ((form != (FORM *)0) &&
                                 (form->status & _POSTED) &&
                                 (form->status & _POSTED) &&
-                                (form->current==field));
-      
+                                (form->current == field));
+
       if (need_visual_update)
        Synchronize_Buffer(form);
       if (need_visual_update)
        Synchronize_Buffer(form);
-      
+
       if (single_line_field)
        {
          growth = field->cols * amount;
          if (field->maxgrow)
       if (single_line_field)
        {
          growth = field->cols * amount;
          if (field->maxgrow)
-           growth = Minimum(field->maxgrow - field->dcols,growth);
+           growth = Minimum(field->maxgrow - field->dcols, growth);
          field->dcols += growth;
          if (field->dcols == field->maxgrow)
          field->dcols += growth;
          if (field->dcols == field->maxgrow)
-           field->status &= ~_MAY_GROW;
+           ClrStatus(field, _MAY_GROW);
        }
       else
        {
          growth = (field->rows + field->nrow) * amount;
          if (field->maxgrow)
        }
       else
        {
          growth = (field->rows + field->nrow) * amount;
          if (field->maxgrow)
-           growth = Minimum(field->maxgrow - field->drows,growth);
+           growth = Minimum(field->maxgrow - field->drows, growth);
          field->drows += growth;
          if (field->drows == field->maxgrow)
          field->drows += growth;
          if (field->drows == field->maxgrow)
-           field->status &= ~_MAY_GROW;
+           ClrStatus(field, _MAY_GROW);
        }
       /* drows, dcols changed, so we get really the new buffer length */
       new_buflen = Buffer_Length(field);
        }
       /* drows, dcols changed, so we get really the new buffer length */
       new_buflen = Buffer_Length(field);
-      newbuf=(char *)malloc((size_t)Total_Buffer_Size(field));
+      newbuf = (FIELD_CELL *)malloc(Total_Buffer_Size(field));
       if (!newbuf)
       if (!newbuf)
-       { /* restore to previous state */
+       {
+         /* restore to previous state */
          field->dcols = old_dcols;
          field->drows = old_drows;
          field->dcols = old_dcols;
          field->drows = old_drows;
-         if (( single_line_field && (field->dcols!=field->maxgrow)) ||
-             (!single_line_field && (field->drows!=field->maxgrow)))
-           field->status |= _MAY_GROW;
-         return FALSE;
+         if ((single_line_field && (field->dcols != field->maxgrow)) ||
+             (!single_line_field && (field->drows != field->maxgrow)))
+           SetStatus(field, _MAY_GROW);
        }
       else
        }
       else
-       { /* Copy all the buffers. This is the reason why we can't
-            just use realloc().
-            */
-         int i;
-         char *old_bp;
-         char *new_bp;
-         
+       {
+         /* Copy all the buffers.  This is the reason why we can't just use
+          * realloc().
+          */
+         int i, j;
+         FIELD_CELL *old_bp;
+         FIELD_CELL *new_bp;
+
+         result = TRUE;        /* allow sharing of recovery on failure */
+
+         T((T_CREATE("fieldcell %p"), (void *)newbuf));
          field->buf = newbuf;
          field->buf = newbuf;
-         for(i=0;i<=field->nbuf;i++)
+         for (i = 0; i <= field->nbuf; i++)
            {
            {
-             new_bp = Address_Of_Nth_Buffer(field,i);
-             old_bp = oldbuf + i*(1+old_buflen);
-             memcpy(new_bp,old_bp,(size_t)old_buflen);
-             if (new_buflen > old_buflen)
-               memset(new_bp + old_buflen,C_BLANK,
-                      (size_t)(new_buflen - old_buflen));
-             *(new_bp + new_buflen) = '\0';
+             new_bp = Address_Of_Nth_Buffer(field, i);
+             old_bp = oldbuf + i * (1 + old_buflen);
+             for (j = 0; j < old_buflen; ++j)
+               new_bp[j] = old_bp[j];
+             while (j < new_buflen)
+               new_bp[j++] = myBLANK;
+             new_bp[new_buflen] = myZEROS;
            }
 
            }
 
-         if (need_visual_update)
-           {         
-             WINDOW *new_window = newpad(field->drows,field->dcols);
-             if (!new_window)
-               { /* restore old state */
-                 field->dcols = old_dcols;
-                 field->drows = old_drows;
-                 field->buf   = oldbuf;
-                 if (( single_line_field              && 
-                       (field->dcols!=field->maxgrow)) ||
-                     (!single_line_field              && 
-                      (field->drows!=field->maxgrow)))
-                   field->status |= _MAY_GROW;
-                 free( newbuf );
-                 return FALSE;
+#if USE_WIDEC_SUPPORT && NCURSES_EXT_FUNCS
+         if (wresize(field->working, 1, Buffer_Length(field) + 1) == ERR)
+           result = FALSE;
+#endif
+
+         if (need_visual_update && result)
+           {
+             WINDOW *new_window = newpad(field->drows, field->dcols);
+
+             if (new_window != 0)
+               {
+                 assert(form != (FORM *)0);
+                 if (form->w)
+                   delwin(form->w);
+                 form->w = new_window;
+                 Set_Field_Window_Attributes(field, form->w);
+                 werase(form->w);
+                 Buffer_To_Window(field, form->w);
+                 untouchwin(form->w);
+                 wmove(form->w, form->currow, form->curcol);
                }
                }
-             assert(form!=(FORM *)0);
-             if (form->w)
-               delwin(form->w);
-             form->w = new_window;
-             Set_Field_Window_Attributes(field,form->w);
-             werase(form->w);
-             Buffer_To_Window(field,form->w);
-             untouchwin(form->w);
-             wmove(form->w,form->currow,form->curcol);
+             else
+               result = FALSE;
            }
 
            }
 
-         free(oldbuf);
-         /* reflect changes in linked fields */
-         if (field != field->link)
+         if (result)
            {
            {
-             FIELD *linked_field;
-             for(linked_field = field->link;
-                 linked_field!= field;
-                 linked_field = linked_field->link)
+             free(oldbuf);
+             /* reflect changes in linked fields */
+             if (field != field->link)
                {
                {
-                 linked_field->buf   = field->buf;
-                 linked_field->drows = field->drows;
-                 linked_field->dcols = field->dcols;
+                 FIELD *linked_field;
+
+                 for (linked_field = field->link;
+                      linked_field != field;
+                      linked_field = linked_field->link)
+                   {
+                     linked_field->buf = field->buf;
+                     linked_field->drows = field->drows;
+                     linked_field->dcols = field->dcols;
+                   }
                }
            }
                }
            }
-         result = TRUE;
-       }       
+         else
+           {
+             /* restore old state */
+             field->dcols = old_dcols;
+             field->drows = old_drows;
+             field->buf = oldbuf;
+             if ((single_line_field &&
+                  (field->dcols != field->maxgrow)) ||
+                 (!single_line_field &&
+                  (field->drows != field->maxgrow)))
+               SetStatus(field, _MAY_GROW);
+             free(newbuf);
+           }
+       }
+    }
+  return (result);
+}
+
+#ifdef NCURSES_MOUSE_VERSION
+/*---------------------------------------------------------------------------
+|   Facility      :  libnform
+|   Function      :  int Field_encloses(FIELD *field, int ry, int rx)
+|
+|   Description   :  Check if the given coordinates lie within the given field.
+|
+|   Return Values :  E_OK              - success
+|                    E_BAD_ARGUMENT    - invalid form pointer
+|                    E_SYSTEM_ERROR    - form has no current field or
+|                                        field-window
++--------------------------------------------------------------------------*/
+static int
+Field_encloses(FIELD *field, int ry, int rx)
+{
+  T((T_CALLED("Field_encloses(%p)"), (void *)field));
+  if (field != 0
+      && field->frow <= ry
+      && (field->frow + field->rows) > ry
+      && field->fcol <= rx
+      && (field->fcol + field->cols) > rx)
+    {
+      RETURN(E_OK);
     }
     }
-  return(result);
+  RETURN(E_INVALID_FIELD);
 }
 }
+#endif
 
 /*---------------------------------------------------------------------------
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  int _nc_Position_Form_Cursor(FORM * form)
 |   Function      :  int _nc_Position_Form_Cursor(FORM * form)
-|   
+|
 |   Description   :  Position the cursor in the window for the current
 |   Description   :  Position the cursor in the window for the current
-|                    field to be in sync. with the currow and curcol 
+|                    field to be in sync. with the currow and curcol
 |                    values.
 |
 |   Return Values :  E_OK              - success
 |                    values.
 |
 |   Return Values :  E_OK              - success
@@ -561,39 +826,39 @@ static bool Field_Grown(FIELD * field, int amount)
 |                                        field-window
 +--------------------------------------------------------------------------*/
 NCURSES_EXPORT(int)
 |                                        field-window
 +--------------------------------------------------------------------------*/
 NCURSES_EXPORT(int)
-_nc_Position_Form_Cursor (FORM * form)
+_nc_Position_Form_Cursor(FORM *form)
 {
 {
-  FIELD  *field;
+  FIELD *field;
   WINDOW *formwin;
   WINDOW *formwin;
-  
+
   if (!form)
   if (!form)
-    return(E_BAD_ARGUMENT);
+    return (E_BAD_ARGUMENT);
 
 
-  if (!form->w || !form->current) 
-    return(E_SYSTEM_ERROR);
+  if (!form->w || !form->current)
+    return (E_SYSTEM_ERROR);
 
 
-  field    = form->current;
-  formwin  = Get_Form_Window(form);
+  field = form->current;
+  formwin = Get_Form_Window(form);
 
 
-  wmove( form->w, form->currow, form->curcol );
-  if ( Has_Invisible_Parts(field) )
+  wmove(form->w, form->currow, form->curcol);
+  if (Has_Invisible_Parts(field))
     {
       /* in this case fieldwin isn't derived from formwin, so we have
     {
       /* in this case fieldwin isn't derived from formwin, so we have
-        to move the cursor in formwin by hand... */
+         to move the cursor in formwin by hand... */
       wmove(formwin,
            field->frow + form->currow - form->toprow,
            field->fcol + form->curcol - form->begincol);
       wcursyncup(formwin);
     }
       wmove(formwin,
            field->frow + form->currow - form->toprow,
            field->fcol + form->curcol - form->begincol);
       wcursyncup(formwin);
     }
-  else 
+  else
     wcursyncup(form->w);
     wcursyncup(form->w);
-  return(E_OK);
+  return (E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  int _nc_Refresh_Current_Field(FORM * form)
 |   Function      :  int _nc_Refresh_Current_Field(FORM * form)
-|   
+|
 |   Description   :  Propagate the changes in the fields window to the
 |                    window of the form.
 |
 |   Description   :  Propagate the changes in the fields window to the
 |                    window of the form.
 |
@@ -601,225 +866,264 @@ _nc_Position_Form_Cursor (FORM * form)
 |                    E_BAD_ARGUMENT    - invalid form pointer
 |                    E_SYSTEM_ERROR    - general error
 +--------------------------------------------------------------------------*/
 |                    E_BAD_ARGUMENT    - invalid form pointer
 |                    E_SYSTEM_ERROR    - general error
 +--------------------------------------------------------------------------*/
+static bool move_after_insert = true;
 NCURSES_EXPORT(int)
 NCURSES_EXPORT(int)
-_nc_Refresh_Current_Field (FORM * form)
+_nc_Refresh_Current_Field(FORM *form)
 {
   WINDOW *formwin;
 {
   WINDOW *formwin;
-  FIELD  *field;
+  FIELD *field;
+  bool is_public;
+
+  T((T_CALLED("_nc_Refresh_Current_Field(%p)"), (void *)form));
 
   if (!form)
     RETURN(E_BAD_ARGUMENT);
 
 
   if (!form)
     RETURN(E_BAD_ARGUMENT);
 
-  if (!form->w || !form->current) 
+  if (!form->w || !form->current)
     RETURN(E_SYSTEM_ERROR);
 
     RETURN(E_SYSTEM_ERROR);
 
-  field    = form->current;
-  formwin  = Get_Form_Window(form);
+  field = form->current;
+  formwin = Get_Form_Window(form);
+
+  is_public = Field_Has_Option(field, O_PUBLIC);
 
 
-  if (field->opts & O_PUBLIC)
+  if (Is_Scroll_Field(field))
     {
     {
-      if (Is_Scroll_Field(field))
+      /* Again, in this case the fieldwin isn't derived from formwin,
+         so we have to perform a copy operation. */
+      if (Single_Line_Field(field))
        {
        {
-         /* Again, in this case the fieldwin isn't derived from formwin,
-            so we have to perform a copy operation. */
-         if (Single_Line_Field(field))
-           { /* horizontal scrolling */
-             if (form->curcol < form->begincol)
-                 form->begincol = form->curcol;
-             else
-               {
-                 if (form->curcol >= (form->begincol + field->cols))
-                     form->begincol = form->curcol - field->cols + 1;
-               }
-             copywin(form->w,
-                     formwin,
-                     0,
-                     form->begincol,
-                     field->frow,
-                     field->fcol,
-                     field->frow,
-                     field->cols + field->fcol - 1,
-                     0);
-           }
+         /* horizontal scrolling */
+         if (form->curcol < form->begincol)
+           form->begincol = form->curcol;
          else
          else
-           { /* A multiline, i.e. vertical scrolling field */
-             int row_after_bottom,first_modified_row,first_unmodified_row;
+           {
+             if (form->curcol >= (form->begincol + field->cols))
+               form->begincol = form->curcol - field->cols
+                 + (move_after_insert ? 1 : 0);
+           }
+         if (is_public)
+           copywin(form->w,
+                   formwin,
+                   0,
+                   form->begincol,
+                   field->frow,
+                   field->fcol,
+                   field->frow,
+                   field->cols + field->fcol - 1,
+                   0);
+       }
+      else
+       {
+         /* A multi-line, i.e. vertical scrolling field */
+         int row_after_bottom, first_modified_row, first_unmodified_row;
 
 
-             if (field->drows > field->rows)
+         if (field->drows > field->rows)
+           {
+             row_after_bottom = form->toprow + field->rows;
+             if (form->currow < form->toprow)
+               {
+                 form->toprow = form->currow;
+                 SetStatus(field, _NEWTOP);
+               }
+             if (form->currow >= row_after_bottom)
+               {
+                 form->toprow = form->currow - field->rows + 1;
+                 SetStatus(field, _NEWTOP);
+               }
+             if (field->status & _NEWTOP)
+               {
+                 /* means we have to copy whole range */
+                 first_modified_row = form->toprow;
+                 first_unmodified_row = first_modified_row + field->rows;
+                 ClrStatus(field, _NEWTOP);
+               }
+             else
                {
                {
-                 row_after_bottom = form->toprow + field->rows;
-                 if (form->currow < form->toprow)
+                 /* we try to optimize : finding the range of touched
+                    lines */
+                 first_modified_row = form->toprow;
+                 while (first_modified_row < row_after_bottom)
                    {
                    {
-                     form->toprow = form->currow;
-                     field->status |= _NEWTOP;
+                     if (is_linetouched(form->w, first_modified_row))
+                       break;
+                     first_modified_row++;
                    }
                    }
-                 if (form->currow >= row_after_bottom)
+                 first_unmodified_row = first_modified_row;
+                 while (first_unmodified_row < row_after_bottom)
                    {
                    {
-                     form->toprow = form->currow - field->rows + 1;
-                     field->status |= _NEWTOP;
-                   }
-                 if (field->status & _NEWTOP)
-                   { /* means we have to copy whole range */
-                     first_modified_row = form->toprow;
-                     first_unmodified_row = first_modified_row + field->rows;
-                     field->status &= ~_NEWTOP;
+                     if (!is_linetouched(form->w, first_unmodified_row))
+                       break;
+                     first_unmodified_row++;
                    }
                    }
-                 else 
-                   { /* we try to optimize : finding the range of touched
-                         lines */
-                     first_modified_row = form->toprow;
-                     while(first_modified_row < row_after_bottom)
-                       {
-                         if (is_linetouched(form->w,first_modified_row)) 
-                           break;
-                         first_modified_row++;
-                       }
-                     first_unmodified_row = first_modified_row;
-                     while(first_unmodified_row < row_after_bottom)
-                       {
-                         if (!is_linetouched(form->w,first_unmodified_row)) 
-                           break;
-                         first_unmodified_row++;
-                       }
-                   }
-               }
-             else
-               {
-                 first_modified_row   = form->toprow;
-                 first_unmodified_row = first_modified_row + field->rows;
                }
                }
-             if (first_unmodified_row != first_modified_row)
-               copywin(form->w,
-                       formwin,
-                       first_modified_row,
-                       0,
-                       field->frow + first_modified_row - form->toprow,
-                       field->fcol,
-                       field->frow + first_unmodified_row - form->toprow - 1,
-                       field->cols + field->fcol - 1,
-                       0);
            }
            }
-         wsyncup(formwin);
-       }
-      else
-       { /* if the field-window is simply a derived window, i.e. contains
-            no invisible parts, the whole thing is trivial 
-         */
-         wsyncup(form->w);
+         else
+           {
+             first_modified_row = form->toprow;
+             first_unmodified_row = first_modified_row + field->rows;
+           }
+         if (first_unmodified_row != first_modified_row && is_public)
+           copywin(form->w,
+                   formwin,
+                   first_modified_row,
+                   0,
+                   field->frow + first_modified_row - form->toprow,
+                   field->fcol,
+                   field->frow + first_unmodified_row - form->toprow - 1,
+                   field->cols + field->fcol - 1,
+                   0);
        }
        }
+      if (is_public)
+       wsyncup(formwin);
+    }
+  else
+    {
+      /* if the field-window is simply a derived window, i.e. contains no
+       * invisible parts, the whole thing is trivial
+       */
+      if (is_public)
+       wsyncup(form->w);
     }
   untouchwin(form->w);
     }
   untouchwin(form->w);
-  return _nc_Position_Form_Cursor(form);
+  returnCode(_nc_Position_Form_Cursor(form));
 }
 }
-       
+
 /*---------------------------------------------------------------------------
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static void Perform_Justification(
 |                                        FIELD  * field,
 |                                        WINDOW * win)
 |   Function      :  static void Perform_Justification(
 |                                        FIELD  * field,
 |                                        WINDOW * win)
-|   
-|   Description   :  Output field with requested justification 
+|
+|   Description   :  Output field with requested justification
 |
 |   Return Values :  -
 +--------------------------------------------------------------------------*/
 |
 |   Return Values :  -
 +--------------------------------------------------------------------------*/
-static void Perform_Justification(FIELD  * field, WINDOW * win)
+static void
+Perform_Justification(FIELD *field, WINDOW *win)
 {
 {
-  char *bp;
+  FIELD_CELL *bp;
   int len;
   int len;
-  int col  = 0;
+  int col = 0;
 
 
-  bp  = Get_Start_Of_Data(field->buf,Buffer_Length(field));
-  len = (int)(After_End_Of_Data(field->buf,Buffer_Length(field)) - bp);
+  bp = (Field_Has_Option(field, O_NO_LEFT_STRIP)
+       ? field->buf
+       : Get_Start_Of_Data(field->buf, Buffer_Length(field)));
+  len = (int)(After_End_Of_Data(field->buf, Buffer_Length(field)) - bp);
 
 
-  if (len>0)
+  if (len > 0)
     {
     {
-      assert(win && (field->drows == 1) && (field->dcols == field->cols));
-
-      switch(field->just)
-       {
-       case JUSTIFY_LEFT:
-         break;
-       case JUSTIFY_CENTER:
-         col = (field->cols - len)/2;
-         break;
-       case JUSTIFY_RIGHT:
-         col = field->cols - len;
-         break;
-       default:
-         break;
-       }
+      assert(win && (field->drows == 1));
+
+      if (field->cols - len >= 0)
+       switch (field->just)
+         {
+         case JUSTIFY_LEFT:
+           break;
+         case JUSTIFY_CENTER:
+           col = (field->cols - len) / 2;
+           break;
+         case JUSTIFY_RIGHT:
+           col = field->cols - len;
+           break;
+         default:
+           break;
+         }
 
 
-      wmove(win,0,col);
-      waddnstr(win,bp,len);
+      wmove(win, 0, col);
+      myADDNSTR(win, bp, len);
     }
 }
 
 /*---------------------------------------------------------------------------
     }
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static void Undo_Justification(
 |                                     FIELD  * field,
 |                                     WINDOW * win)
 |   Function      :  static void Undo_Justification(
 |                                     FIELD  * field,
 |                                     WINDOW * win)
-|   
+|
 |   Description   :  Display field without any justification, i.e.
 |                    left justified
 |
 |   Return Values :  -
 +--------------------------------------------------------------------------*/
 |   Description   :  Display field without any justification, i.e.
 |                    left justified
 |
 |   Return Values :  -
 +--------------------------------------------------------------------------*/
-static void Undo_Justification(FIELD  * field, WINDOW * win)
+static void
+Undo_Justification(FIELD *field, WINDOW *win)
 {
 {
-  char *bp;
+  FIELD_CELL *bp;
+  int y, x;
   int len;
 
   int len;
 
-  bp  = Get_Start_Of_Data(field->buf,Buffer_Length(field));
-  len = (int)(After_End_Of_Data(field->buf,Buffer_Length(field))-bp);
+  getyx(win, y, x);
 
 
-  if (len>0)
+  bp = (Field_Has_Option(field, O_NO_LEFT_STRIP)
+       ? field->buf
+       : Get_Start_Of_Data(field->buf, Buffer_Length(field)));
+  len = (int)(After_End_Of_Data(field->buf, Buffer_Length(field)) - bp);
+
+  if (len > 0)
     {
       assert(win);
     {
       assert(win);
-      wmove(win,0,0);
-      waddnstr(win,bp,len);
+      wmove(win, 0, 0);
+      myADDNSTR(win, bp, len);
     }
     }
+  wmove(win, y, x);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
-|   Function      :  static bool Check_Char(
+|   Facility      :  libnform
+|   Function      :  static bool Check_Char(FORM  *form,
+|                                           FIELD *field,
 |                                           FIELDTYPE * typ,
 |                                           int ch,
 |                                           TypeArgument *argp)
 |                                           FIELDTYPE * typ,
 |                                           int ch,
 |                                           TypeArgument *argp)
-|   
+|
 |   Description   :  Perform a single character check for character ch
 |   Description   :  Perform a single character check for character ch
-|                    according to the fieldtype instance.  
+|                    according to the fieldtype instance.
 |
 |   Return Values :  TRUE             - Character is valid
 |                    FALSE            - Character is invalid
 +--------------------------------------------------------------------------*/
 |
 |   Return Values :  TRUE             - Character is valid
 |                    FALSE            - Character is invalid
 +--------------------------------------------------------------------------*/
-static bool Check_Char(FIELDTYPE * typ, int ch, TypeArgument *argp)
+static bool
+Check_Char(FORM *form,
+          FIELD *field,
+          FIELDTYPE *typ,
+          int ch,
+          TypeArgument *argp)
 {
 {
-  if (typ) 
+  if (typ)
     {
       if (typ->status & _LINKED_TYPE)
        {
          assert(argp);
     {
       if (typ->status & _LINKED_TYPE)
        {
          assert(argp);
-         return(
-           Check_Char(typ->left ,ch,argp->left ) ||
-           Check_Char(typ->right,ch,argp->right) );
-       } 
-      else 
+         return (
+                  Check_Char(form, field, typ->left, ch, argp->left) ||
+                  Check_Char(form, field, typ->right, ch, argp->right));
+       }
+      else
        {
        {
+#if NCURSES_INTEROP_FUNCS
+         if (typ->charcheck.occheck)
+           {
+             if (typ->status & _GENERIC)
+               return typ->charcheck.gccheck(ch, form, field, (void *)argp);
+             else
+               return typ->charcheck.occheck(ch, (void *)argp);
+           }
+#else
          if (typ->ccheck)
          if (typ->ccheck)
-           return typ->ccheck(ch,(void *)argp);
+           return typ->ccheck(ch, (void *)argp);
+#endif
        }
     }
        }
     }
-  return (isprint((unsigned char)ch) ? TRUE : FALSE);
+  return (!iscntrl(UChar(ch)) ? TRUE : FALSE);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int Display_Or_Erase_Field(
 |                                           FIELD * field,
 |                                           bool bEraseFlag)
 |   Function      :  static int Display_Or_Erase_Field(
 |                                           FIELD * field,
 |                                           bool bEraseFlag)
-|   
+|
 |   Description   :  Create a subwindow for the field and display the
 |                    buffer contents (apply justification if required)
 |                    or simply erase the field.
 |   Description   :  Create a subwindow for the field and display the
 |                    buffer contents (apply justification if required)
 |                    or simply erase the field.
@@ -827,7 +1131,8 @@ static bool Check_Char(FIELDTYPE * typ, int ch, TypeArgument *argp)
 |   Return Values :  E_OK           - on success
 |                    E_SYSTEM_ERROR - some error (typical no memory)
 +--------------------------------------------------------------------------*/
 |   Return Values :  E_OK           - on success
 |                    E_SYSTEM_ERROR - some error (typical no memory)
 +--------------------------------------------------------------------------*/
-static int Display_Or_Erase_Field(FIELD * field, bool bEraseFlag)
+static int
+Display_Or_Erase_Field(FIELD *field, bool bEraseFlag)
 {
   WINDOW *win;
   WINDOW *fwin;
 {
   WINDOW *win;
   WINDOW *fwin;
@@ -836,30 +1141,34 @@ static int Display_Or_Erase_Field(FIELD * field, bool bEraseFlag)
     return E_SYSTEM_ERROR;
 
   fwin = Get_Form_Window(field->form);
     return E_SYSTEM_ERROR;
 
   fwin = Get_Form_Window(field->form);
-  win  = derwin(fwin,
-               field->rows,field->cols,field->frow,field->fcol);
+  win = derwin(fwin,
+              field->rows, field->cols, field->frow, field->fcol);
 
 
-  if (!win) 
+  if (!win)
     return E_SYSTEM_ERROR;
   else
     {
     return E_SYSTEM_ERROR;
   else
     {
-      if (field->opts & O_VISIBLE)
-       Set_Field_Window_Attributes(field,win);
+      if (Field_Has_Option(field, O_VISIBLE))
+       {
+         Set_Field_Window_Attributes(field, win);
+       }
       else
       else
-       wattrset(win,getattrs(fwin));
+       {
+         (void)wattrset(win, (int)WINDOW_ATTRS(fwin));
+       }
       werase(win);
     }
 
   if (!bEraseFlag)
     {
       werase(win);
     }
 
   if (!bEraseFlag)
     {
-      if (field->opts & O_PUBLIC)
+      if (Field_Has_Option(field, O_PUBLIC))
        {
          if (Justification_Allowed(field))
        {
          if (Justification_Allowed(field))
-           Perform_Justification(field,win);
+           Perform_Justification(field, win);
          else
          else
-           Buffer_To_Window(field,win);
+           Buffer_To_Window(field, win);
        }
        }
-      field->status &= ~_NEWTOP;
+      ClrStatus(field, _NEWTOP);
     }
   wsyncup(win);
   delwin(win);
     }
   wsyncup(win);
   delwin(win);
@@ -871,211 +1180,222 @@ static int Display_Or_Erase_Field(FIELD * field, bool bEraseFlag)
 #define Erase_Field(field)   Display_Or_Erase_Field(field,TRUE)
 
 /*---------------------------------------------------------------------------
 #define Erase_Field(field)   Display_Or_Erase_Field(field,TRUE)
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int Synchronize_Field(FIELD * field)
 |   Function      :  static int Synchronize_Field(FIELD * field)
-|   
+|
 |   Description   :  Synchronize the windows content with the value in
 |                    the buffer.
 |
 |   Return Values :  E_OK                - success
 |   Description   :  Synchronize the windows content with the value in
 |                    the buffer.
 |
 |   Return Values :  E_OK                - success
-|                    E_BAD_ARGUMENT      - invalid field pointer 
+|                    E_BAD_ARGUMENT      - invalid field pointer
 |                    E_SYSTEM_ERROR      - some severe basic error
 +--------------------------------------------------------------------------*/
 |                    E_SYSTEM_ERROR      - some severe basic error
 +--------------------------------------------------------------------------*/
-static int Synchronize_Field(FIELD * field)
+static int
+Synchronize_Field(FIELD *field)
 {
   FORM *form;
   int res = E_OK;
 
   if (!field)
 {
   FORM *form;
   int res = E_OK;
 
   if (!field)
-    return(E_BAD_ARGUMENT);
+    return (E_BAD_ARGUMENT);
 
 
-  if (((form=field->form) != (FORM *)0)
+  if (((form = field->form) != (FORM *)0)
       && Field_Really_Appears(field))
     {
       if (field == form->current)
       && Field_Really_Appears(field))
     {
       if (field == form->current)
-       { 
-         form->currow  = form->curcol = form->toprow = form->begincol = 0;
+       {
+         form->currow = form->curcol = form->toprow = form->begincol = 0;
          werase(form->w);
          werase(form->w);
-      
-         if ( (field->opts & O_PUBLIC) && Justification_Allowed(field) )
-           Undo_Justification( field, form->w );
+
+         if ((Field_Has_Option(field, O_PUBLIC)) && Justification_Allowed(field))
+           Undo_Justification(field, form->w);
          else
          else
-           Buffer_To_Window( field, form->w );
-         
-         field->status |= _NEWTOP;
-         res = _nc_Refresh_Current_Field( form );
+           Buffer_To_Window(field, form->w);
+
+         SetStatus(field, _NEWTOP);
+         res = _nc_Refresh_Current_Field(form);
        }
       else
        }
       else
-       res = Display_Field( field );
+       res = Display_Field(field);
     }
     }
-  field->status |= _CHANGED;
-  return(res);
+  SetStatus(field, _CHANGED);
+  return (res);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int Synchronize_Linked_Fields(FIELD * field)
 |   Function      :  static int Synchronize_Linked_Fields(FIELD * field)
-|   
+|
 |   Description   :  Propagate the Synchronize_Field function to all linked
 |                    fields. The first error that occurs in the sequence
 |   Description   :  Propagate the Synchronize_Field function to all linked
 |                    fields. The first error that occurs in the sequence
-|                    of updates is the returnvalue.
+|                    of updates is the return value.
 |
 |   Return Values :  E_OK                - success
 |
 |   Return Values :  E_OK                - success
-|                    E_BAD_ARGUMENT      - invalid field pointer 
+|                    E_BAD_ARGUMENT      - invalid field pointer
 |                    E_SYSTEM_ERROR      - some severe basic error
 +--------------------------------------------------------------------------*/
 |                    E_SYSTEM_ERROR      - some severe basic error
 +--------------------------------------------------------------------------*/
-static int Synchronize_Linked_Fields(FIELD * field)
+static int
+Synchronize_Linked_Fields(FIELD *field)
 {
   FIELD *linked_field;
   int res = E_OK;
   int syncres;
 
   if (!field)
 {
   FIELD *linked_field;
   int res = E_OK;
   int syncres;
 
   if (!field)
-    return(E_BAD_ARGUMENT);
+    return (E_BAD_ARGUMENT);
 
   if (!field->link)
 
   if (!field->link)
-    return(E_SYSTEM_ERROR);
+    return (E_SYSTEM_ERROR);
 
 
-  for(linked_field = field->link; 
-      linked_field!= field;
-      linked_field = linked_field->link )
+  for (linked_field = field->link;
+       (linked_field != field) && (linked_field != 0);
+       linked_field = linked_field->link)
     {
     {
-      if (((syncres=Synchronize_Field(linked_field)) != E_OK) &&
-         (res==E_OK))
+      if (((syncres = Synchronize_Field(linked_field)) != E_OK) &&
+         (res == E_OK))
        res = syncres;
     }
        res = syncres;
     }
-  return(res);
+  return (res);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  int _nc_Synchronize_Attributes(FIELD * field)
 |   Function      :  int _nc_Synchronize_Attributes(FIELD * field)
-|   
+|
 |   Description   :  If a fields visual attributes have changed, this
 |                    routine is called to propagate those changes to the
 |   Description   :  If a fields visual attributes have changed, this
 |                    routine is called to propagate those changes to the
-|                    screen.  
+|                    screen.
 |
 |   Return Values :  E_OK             - success
 |                    E_BAD_ARGUMENT   - invalid field pointer
 |                    E_SYSTEM_ERROR   - some severe basic error
 +--------------------------------------------------------------------------*/
 NCURSES_EXPORT(int)
 |
 |   Return Values :  E_OK             - success
 |                    E_BAD_ARGUMENT   - invalid field pointer
 |                    E_SYSTEM_ERROR   - some severe basic error
 +--------------------------------------------------------------------------*/
 NCURSES_EXPORT(int)
-_nc_Synchronize_Attributes (FIELD * field)
+_nc_Synchronize_Attributes(FIELD *field)
 {
   FORM *form;
   int res = E_OK;
   WINDOW *formwin;
 
 {
   FORM *form;
   int res = E_OK;
   WINDOW *formwin;
 
+  T((T_CALLED("_nc_Synchronize_Attributes(%p)"), (void *)field));
+
   if (!field)
   if (!field)
-    return(E_BAD_ARGUMENT);
+    returnCode(E_BAD_ARGUMENT);
 
 
-  if (((form=field->form) != (FORM *)0)
+  CHECKPOS(field->form);
+  if (((form = field->form) != (FORM *)0)
       && Field_Really_Appears(field))
       && Field_Really_Appears(field))
-    {    
-      if (form->current==field)
+    {
+      if (form->current == field)
        {
          Synchronize_Buffer(form);
        {
          Synchronize_Buffer(form);
-         Set_Field_Window_Attributes(field,form->w);
+         Set_Field_Window_Attributes(field, form->w);
          werase(form->w);
          werase(form->w);
-         if (field->opts & O_PUBLIC)
+         wmove(form->w, form->currow, form->curcol);
+
+         if (Field_Has_Option(field, O_PUBLIC))
            {
              if (Justification_Allowed(field))
            {
              if (Justification_Allowed(field))
-               Undo_Justification(field,form->w);
-             else 
-               Buffer_To_Window(field,form->w);
+               Undo_Justification(field, form->w);
+             else
+               Buffer_To_Window(field, form->w);
            }
            }
-         else 
+         else
            {
            {
-             formwin = Get_Form_Window(form); 
-             copywin(form->w,formwin,
-                     0,0,
-                     field->frow,field->fcol,
-                     field->rows-1,field->cols-1,0);
+             formwin = Get_Form_Window(form);
+             copywin(form->w, formwin,
+                     0, 0,
+                     field->frow, field->fcol,
+                     field->frow + field->rows - 1,
+                     field->fcol + field->cols - 1, 0);
              wsyncup(formwin);
              wsyncup(formwin);
-             Buffer_To_Window(field,form->w);
-             field->status |= _NEWTOP; /* fake refresh to paint all */
+             Buffer_To_Window(field, form->w);
+             SetStatus(field, _NEWTOP);        /* fake refresh to paint all */
              _nc_Refresh_Current_Field(form);
            }
        }
              _nc_Refresh_Current_Field(form);
            }
        }
-      else 
+      else
        {
          res = Display_Field(field);
        }
     }
        {
          res = Display_Field(field);
        }
     }
-  return(res);
+  CHECKPOS(form);
+  returnCode(res);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  int _nc_Synchronize_Options(FIELD * field,
 |                                                Field_Options newopts)
 |   Function      :  int _nc_Synchronize_Options(FIELD * field,
 |                                                Field_Options newopts)
-|   
+|
 |   Description   :  If a fields options have changed, this routine is
 |                    called to propagate these changes to the screen and
 |   Description   :  If a fields options have changed, this routine is
 |                    called to propagate these changes to the screen and
-|                    to really change the behaviour of the field.
+|                    to really change the behavior of the field.
 |
 |   Return Values :  E_OK                - success
 |
 |   Return Values :  E_OK                - success
-|                    E_BAD_ARGUMENT      - invalid field pointer 
+|                    E_BAD_ARGUMENT      - invalid field pointer
+|                    E_CURRENT           - field is the current one
 |                    E_SYSTEM_ERROR      - some severe basic error
 +--------------------------------------------------------------------------*/
 NCURSES_EXPORT(int)
 |                    E_SYSTEM_ERROR      - some severe basic error
 +--------------------------------------------------------------------------*/
 NCURSES_EXPORT(int)
-_nc_Synchronize_Options
-(FIELD *field, Field_Options newopts)
+_nc_Synchronize_Options(FIELD *field, Field_Options newopts)
 {
   Field_Options oldopts;
   Field_Options changed_opts;
   FORM *form;
   int res = E_OK;
 
 {
   Field_Options oldopts;
   Field_Options changed_opts;
   FORM *form;
   int res = E_OK;
 
+  T((T_CALLED("_nc_Synchronize_Options(%p,%#x)"), (void *)field, newopts));
+
   if (!field)
   if (!field)
-    return(E_BAD_ARGUMENT);
+    returnCode(E_BAD_ARGUMENT);
 
 
-  oldopts      = field->opts;
+  oldopts = field->opts;
   changed_opts = oldopts ^ newopts;
   changed_opts = oldopts ^ newopts;
-  field->opts  = newopts;
-  form         = field->form;
+  field->opts = newopts;
+  form = field->form;
 
   if (form)
     {
 
   if (form)
     {
-      if (form->current == field)
-       {
-         field->opts = oldopts;
-         return(E_CURRENT);
-       }
-
       if (form->status & _POSTED)
        {
       if (form->status & _POSTED)
        {
-         if ((form->curpage == field->page))
+         if (form->current == field)
+           {
+             field->opts = oldopts;
+             returnCode(E_CURRENT);
+           }
+         if (form->curpage == field->page)
            {
            {
-             if (changed_opts & O_VISIBLE)
+             if ((unsigned)changed_opts & O_VISIBLE)
                {
                {
-                 if (newopts & O_VISIBLE)
+                 if ((unsigned)newopts & O_VISIBLE)
                    res = Display_Field(field);
                  else
                    res = Erase_Field(field);
                }
              else
                {
                    res = Display_Field(field);
                  else
                    res = Erase_Field(field);
                }
              else
                {
-                 if ((changed_opts & O_PUBLIC) &&
-                     (newopts & O_VISIBLE))
+                 if (((unsigned)changed_opts & O_PUBLIC) &&
+                     ((unsigned)newopts & O_VISIBLE))
                    res = Display_Field(field);
                }
            }
        }
     }
 
                    res = Display_Field(field);
                }
            }
        }
     }
 
-  if (changed_opts & O_STATIC)
+  if ((unsigned)changed_opts & O_STATIC)
     {
       bool single_line_field = Single_Line_Field(field);
       int res2 = E_OK;
 
     {
       bool single_line_field = Single_Line_Field(field);
       int res2 = E_OK;
 
-      if (newopts & O_STATIC)
-       { /* the field becomes now static */
-         field->status &= ~_MAY_GROW;
+      if ((unsigned)newopts & O_STATIC)
+       {
+         /* the field becomes now static */
+         ClrStatus(field, _MAY_GROW);
          /* if actually we have no hidden columns, justification may
             occur again */
          /* if actually we have no hidden columns, justification may
             occur again */
-         if (single_line_field                 &&
-             (field->cols == field->dcols)     &&
+         if (single_line_field &&
+             (field->cols == field->dcols) &&
              (field->just != NO_JUSTIFICATION) &&
              Field_Really_Appears(field))
            {
              (field->just != NO_JUSTIFICATION) &&
              Field_Really_Appears(field))
            {
@@ -1083,121 +1403,151 @@ _nc_Synchronize_Options
            }
        }
       else
            }
        }
       else
-       { /* field is no longer static */
-         if ((field->maxgrow==0) ||
-             ( single_line_field && (field->dcols < field->maxgrow)) ||
+       {
+         /* field is no longer static */
+         if ((field->maxgrow == 0) ||
+             (single_line_field && (field->dcols < field->maxgrow)) ||
              (!single_line_field && (field->drows < field->maxgrow)))
            {
              (!single_line_field && (field->drows < field->maxgrow)))
            {
-             field->status |= _MAY_GROW;
-             /* a field with justification now changes its behaviour,
-                so we must redisplay it */
-             if (single_line_field                 &&
+             SetStatus(field, _MAY_GROW);
+             /* a field with justification now changes its behavior,
+                so we must redisplay it */
+             if (single_line_field &&
                  (field->just != NO_JUSTIFICATION) &&
                  Field_Really_Appears(field))
                {
                  res2 = Display_Field(field);
                  (field->just != NO_JUSTIFICATION) &&
                  Field_Really_Appears(field))
                {
                  res2 = Display_Field(field);
-               }        
-           }     
+               }
+           }
        }
       if (res2 != E_OK)
        res = res2;
     }
 
        }
       if (res2 != E_OK)
        res = res2;
     }
 
-  return(res);
+  returnCode(res);
 }
 
 }
 
-/*---------------------------------------------------------------------------
-|   Facility      :  libnform  
-|   Function      :  int _nc_Set_Current_Field(FORM  * form,
-|                                              FIELD * newfield)
-|   
-|   Description   :  Make the newfield the new current field.
-|
-|   Return Values :  E_OK                - success
-|                    E_BAD_ARGUMENT      - invalid form or field pointer 
-|                    E_SYSTEM_ERROR      - some severe basic error
-+--------------------------------------------------------------------------*/
-NCURSES_EXPORT(int)
-_nc_Set_Current_Field
-(FORM  *form, FIELD *newfield)
+/*
+ * Removes the focus from the current field of the form.
+ */
+void
+_nc_Unset_Current_Field(FORM *form)
 {
 {
-  FIELD  *field;
-  WINDOW *new_window;
+  FIELD *field = form->current;
 
 
-  if (!form || !newfield || !form->current || (newfield->form!=form))
-    return(E_BAD_ARGUMENT);
-
-  if ( (form->status & _IN_DRIVER) )
-    return(E_BAD_STATE);
-
-  if (!(form->field))
-    return(E_NOT_CONNECTED);
-
-  field = form->current;
-  if ((field!=newfield) || 
-      !(form->status & _POSTED))
+  _nc_Refresh_Current_Field(form);
+  if (Field_Has_Option(field, O_PUBLIC))
     {
     {
-      if ((form->w) && 
-         (field->opts & O_VISIBLE) &&
-         (field->form->curpage == field->page))
+      if (field->drows > field->rows)
        {
        {
-         _nc_Refresh_Current_Field(form);
-         if (field->opts & O_PUBLIC)
+         if (form->toprow == 0)
+           ClrStatus(field, _NEWTOP);
+         else
+           SetStatus(field, _NEWTOP);
+       }
+      else
+       {
+         if (Justification_Allowed(field))
            {
            {
-             if (field->drows > field->rows)
+             Window_To_Buffer(form, field);
+             werase(form->w);
+             Perform_Justification(field, form->w);
+             if (Field_Has_Option(field, O_DYNAMIC_JUSTIFY) &&
+                 (form->w->_parent == 0))
                {
                {
-                 if (form->toprow==0)
-                   field->status &= ~_NEWTOP;
-                 else 
-                   field->status |= _NEWTOP;
-               } 
-             else 
+                 copywin(form->w,
+                         Get_Form_Window(form),
+                         0,
+                         0,
+                         field->frow,
+                         field->fcol,
+                         field->frow,
+                         field->cols + field->fcol - 1,
+                         0);
+                 wsyncup(Get_Form_Window(form));
+               }
+             else
                {
                {
-                 if (Justification_Allowed(field))
-                   {
-                     Window_To_Buffer(form->w,field);
-                     werase(form->w);
-                     Perform_Justification(field,form->w);
-                     wsyncup(form->w);
-                   }
+                 wsyncup(form->w);
                }
            }
                }
            }
-         delwin(form->w);
-         form->w = (WINDOW *)0;
        }
        }
-      
+    }
+  delwin(form->w);
+  form->w = (WINDOW *)0;
+  form->current = 0;
+}
+
+/*---------------------------------------------------------------------------
+|   Facility      :  libnform
+|   Function      :  int _nc_Set_Current_Field(FORM  * form,
+|                                              FIELD * newfield)
+|
+|   Description   :  Make the newfield the new current field.
+|
+|   Return Values :  E_OK              - success
+|                    E_BAD_ARGUMENT    - invalid form or field pointer
+|                    E_SYSTEM_ERROR    - some severe basic error
+|                    E_NOT_CONNECTED   - no fields are connected to the form
++--------------------------------------------------------------------------*/
+NCURSES_EXPORT(int)
+_nc_Set_Current_Field(FORM *form, FIELD *newfield)
+{
+  FIELD *field;
+  WINDOW *new_window;
+
+  T((T_CALLED("_nc_Set_Current_Field(%p,%p)"), (void *)form, (void *)newfield));
+
+  if (!form || !newfield || (newfield->form != form))
+    returnCode(E_BAD_ARGUMENT);
+
+  if ((form->status & _IN_DRIVER))
+    returnCode(E_BAD_STATE);
+
+  if (!(form->field))
+    returnCode(E_NOT_CONNECTED);
+
+  field = form->current;
+
+  if ((field != newfield) ||
+      !(form->status & _POSTED))
+    {
+      if (field && (form->w) &&
+         (Field_Has_Option(field, O_VISIBLE)) &&
+         (field->form->curpage == field->page))
+       _nc_Unset_Current_Field(form);
+
       field = newfield;
 
       if (Has_Invisible_Parts(field))
       field = newfield;
 
       if (Has_Invisible_Parts(field))
-       new_window = newpad(field->drows,field->dcols);
-      else 
+       new_window = newpad(field->drows, field->dcols);
+      else
        new_window = derwin(Get_Form_Window(form),
        new_window = derwin(Get_Form_Window(form),
-                           field->rows,field->cols,field->frow,field->fcol);
+                           field->rows, field->cols, field->frow, field->fcol);
 
 
-      if (!new_window) 
-       return(E_SYSTEM_ERROR);
+      if (!new_window)
+       returnCode(E_SYSTEM_ERROR);
 
       form->current = field;
 
       if (form->w)
        delwin(form->w);
 
       form->current = field;
 
       if (form->w)
        delwin(form->w);
-      form->w       = new_window;
+      form->w = new_window;
 
 
-      form->status &= ~_WINDOW_MODIFIED;
-      Set_Field_Window_Attributes(field,form->w);
+      ClrStatus(form, _WINDOW_MODIFIED);
+      Set_Field_Window_Attributes(field, form->w);
 
       if (Has_Invisible_Parts(field))
        {
          werase(form->w);
 
       if (Has_Invisible_Parts(field))
        {
          werase(form->w);
-         Buffer_To_Window(field,form->w);
-       } 
-      else 
+         Buffer_To_Window(field, form->w);
+       }
+      else
        {
          if (Justification_Allowed(field))
            {
              werase(form->w);
        {
          if (Justification_Allowed(field))
            {
              werase(form->w);
-             Undo_Justification(field,form->w);
+             Undo_Justification(field, form->w);
              wsyncup(form->w);
            }
        }
              wsyncup(form->w);
            }
        }
@@ -1206,417 +1556,461 @@ _nc_Set_Current_Field
     }
 
   form->currow = form->curcol = form->toprow = form->begincol = 0;
     }
 
   form->currow = form->curcol = form->toprow = form->begincol = 0;
-  return(E_OK);
+  returnCode(E_OK);
 }
 }
-\f
+
 /*----------------------------------------------------------------------------
   Intra-Field Navigation routines
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
 /*----------------------------------------------------------------------------
   Intra-Field Navigation routines
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int IFN_Next_Character(FORM * form)
 |   Function      :  static int IFN_Next_Character(FORM * form)
-|   
-|   Description   :  Move to the next character in the field. In a multiline
+|
+|   Description   :  Move to the next character in the field. In a multi-line
 |                    field this wraps at the end of the line.
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - at the rightmost position
 +--------------------------------------------------------------------------*/
 |                    field this wraps at the end of the line.
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - at the rightmost position
 +--------------------------------------------------------------------------*/
-static int IFN_Next_Character(FORM * form)
+static int
+IFN_Next_Character(FORM *form)
 {
   FIELD *field = form->current;
 {
   FIELD *field = form->current;
-  
-  if ((++(form->curcol))==field->dcols)
+  int step = myWCWIDTH(form->w, form->currow, form->curcol);
+
+  T((T_CALLED("IFN_Next_Character(%p)"), (void *)form));
+  if ((form->curcol += step) == field->dcols)
     {
     {
-      if ((++(form->currow))==field->drows)
+      if ((++(form->currow)) == field->drows)
        {
 #if GROW_IF_NAVIGATE
        {
 #if GROW_IF_NAVIGATE
-         if (!Single_Line_Field(field) && Field_Grown(field,1)) {
-           form->curcol = 0;
-           return(E_OK);
-         }
+         if (!Single_Line_Field(field) && Field_Grown(field, 1))
+           {
+             form->curcol = 0;
+             returnCode(E_OK);
+           }
 #endif
          form->currow--;
 #if GROW_IF_NAVIGATE
 #endif
          form->currow--;
 #if GROW_IF_NAVIGATE
-         if (Single_Line_Field(field) && Field_Grown(field,1))
-           return(E_OK);
+         if (Single_Line_Field(field) && Field_Grown(field, 1))
+           returnCode(E_OK);
 #endif
 #endif
-         form->curcol--;
-         return(E_REQUEST_DENIED);
+         form->curcol -= step;
+         returnCode(E_REQUEST_DENIED);
        }
       form->curcol = 0;
     }
        }
       form->curcol = 0;
     }
-  return(E_OK);
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int IFN_Previous_Character(FORM * form)
 |   Function      :  static int IFN_Previous_Character(FORM * form)
-|   
-|   Description   :  Move to the previous character in the field. In a 
-|                    multiline field this wraps and the beginning of the 
+|
+|   Description   :  Move to the previous character in the field. In a
+|                    multi-line field this wraps and the beginning of the
 |                    line.
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - at the leftmost position
 +--------------------------------------------------------------------------*/
 |                    line.
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - at the leftmost position
 +--------------------------------------------------------------------------*/
-static int IFN_Previous_Character(FORM * form)
+static int
+IFN_Previous_Character(FORM *form)
 {
 {
-  if ((--(form->curcol))<0)
+  int amount = myWCWIDTH(form->w, form->currow, form->curcol - 1);
+  int oldcol = form->curcol;
+
+  T((T_CALLED("IFN_Previous_Character(%p)"), (void *)form));
+  if ((form->curcol -= amount) < 0)
     {
     {
-      if ((--(form->currow))<0)
+      if ((--(form->currow)) < 0)
        {
          form->currow++;
        {
          form->currow++;
-         form->curcol++;
-         return(E_REQUEST_DENIED);
+         form->curcol = oldcol;
+         returnCode(E_REQUEST_DENIED);
        }
       form->curcol = form->current->dcols - 1;
     }
        }
       form->curcol = form->current->dcols - 1;
     }
-  return(E_OK);
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int IFN_Next_Line(FORM * form)
 |   Function      :  static int IFN_Next_Line(FORM * form)
-|   
+|
 |   Description   :  Move to the beginning of the next line in the field
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - at the last line
 +--------------------------------------------------------------------------*/
 |   Description   :  Move to the beginning of the next line in the field
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - at the last line
 +--------------------------------------------------------------------------*/
-static int IFN_Next_Line(FORM * form)
+static int
+IFN_Next_Line(FORM *form)
 {
   FIELD *field = form->current;
 
 {
   FIELD *field = form->current;
 
-  if ((++(form->currow))==field->drows)
+  T((T_CALLED("IFN_Next_Line(%p)"), (void *)form));
+  if ((++(form->currow)) == field->drows)
     {
 #if GROW_IF_NAVIGATE
     {
 #if GROW_IF_NAVIGATE
-      if (!Single_Line_Field(field) && Field_Grown(field,1))
-       return(E_OK);
+      if (!Single_Line_Field(field) && Field_Grown(field, 1))
+       returnCode(E_OK);
 #endif
       form->currow--;
 #endif
       form->currow--;
-      return(E_REQUEST_DENIED);
+      returnCode(E_REQUEST_DENIED);
     }
   form->curcol = 0;
     }
   form->curcol = 0;
-  return(E_OK);
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int IFN_Previous_Line(FORM * form)
 |   Function      :  static int IFN_Previous_Line(FORM * form)
-|   
+|
 |   Description   :  Move to the beginning of the previous line in the field
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - at the first line
 +--------------------------------------------------------------------------*/
 |   Description   :  Move to the beginning of the previous line in the field
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - at the first line
 +--------------------------------------------------------------------------*/
-static int IFN_Previous_Line(FORM * form)
+static int
+IFN_Previous_Line(FORM *form)
 {
 {
-  if ( (--(form->currow)) < 0 )
+  T((T_CALLED("IFN_Previous_Line(%p)"), (void *)form));
+  if ((--(form->currow)) < 0)
     {
       form->currow++;
     {
       form->currow++;
-      return(E_REQUEST_DENIED);
+      returnCode(E_REQUEST_DENIED);
     }
   form->curcol = 0;
     }
   form->curcol = 0;
-  return(E_OK);
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int IFN_Next_Word(FORM * form)
 |   Function      :  static int IFN_Next_Word(FORM * form)
-|   
+|
 |   Description   :  Move to the beginning of the next word in the field.
 |
 |   Return Values :  E_OK             - success
 |                    E_REQUEST_DENIED - there is no next word
 +--------------------------------------------------------------------------*/
 |   Description   :  Move to the beginning of the next word in the field.
 |
 |   Return Values :  E_OK             - success
 |                    E_REQUEST_DENIED - there is no next word
 +--------------------------------------------------------------------------*/
-static int IFN_Next_Word(FORM * form)
+static int
+IFN_Next_Word(FORM *form)
 {
   FIELD *field = form->current;
 {
   FIELD *field = form->current;
-  char  *bp    = Address_Of_Current_Position_In_Buffer(form);
-  char  *s;
-  char  *t;
+  FIELD_CELL *bp = Address_Of_Current_Position_In_Buffer(form);
+  FIELD_CELL *s;
+  FIELD_CELL *t;
+
+  T((T_CALLED("IFN_Next_Word(%p)"), (void *)form));
 
   /* We really need access to the data, so we have to synchronize */
   Synchronize_Buffer(form);
 
   /* Go to the first whitespace after the current position (including
 
   /* We really need access to the data, so we have to synchronize */
   Synchronize_Buffer(form);
 
   /* Go to the first whitespace after the current position (including
-     current position). This is then the startpoint to look for the
-    next non-blank data */
-  s = Get_First_Whitespace_Character(bp,Buffer_Length(field) -
+     current position). This is then the starting point to look for the
+     next non-blank data */
+  s = Get_First_Whitespace_Character(bp, Buffer_Length(field) -
                                     (int)(bp - field->buf));
 
   /* Find the start of the next word */
                                     (int)(bp - field->buf));
 
   /* Find the start of the next word */
-  t = Get_Start_Of_Data(s,Buffer_Length(field) -
+  t = Get_Start_Of_Data(s, Buffer_Length(field) -
                        (int)(s - field->buf));
 #if !FRIENDLY_PREV_NEXT_WORD
                        (int)(s - field->buf));
 #if !FRIENDLY_PREV_NEXT_WORD
-  if (s==t) 
-    return(E_REQUEST_DENIED);
+  if (s == t)
+    returnCode(E_REQUEST_DENIED);
   else
 #endif
     {
   else
 #endif
     {
-      Adjust_Cursor_Position(form,t);
-      return(E_OK);
+      Adjust_Cursor_Position(form, t);
+      returnCode(E_OK);
     }
 }
 
 /*---------------------------------------------------------------------------
     }
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int IFN_Previous_Word(FORM * form)
 |   Function      :  static int IFN_Previous_Word(FORM * form)
-|   
+|
 |   Description   :  Move to the beginning of the previous word in the field.
 |
 |   Return Values :  E_OK             - success
 |                    E_REQUEST_DENIED - there is no previous word
 +--------------------------------------------------------------------------*/
 |   Description   :  Move to the beginning of the previous word in the field.
 |
 |   Return Values :  E_OK             - success
 |                    E_REQUEST_DENIED - there is no previous word
 +--------------------------------------------------------------------------*/
-static int IFN_Previous_Word(FORM * form)
+static int
+IFN_Previous_Word(FORM *form)
 {
   FIELD *field = form->current;
 {
   FIELD *field = form->current;
-  char  *bp    = Address_Of_Current_Position_In_Buffer(form);
-  char  *s;
-  char  *t;
-  bool  again = FALSE;
+  FIELD_CELL *bp = Address_Of_Current_Position_In_Buffer(form);
+  FIELD_CELL *s;
+  FIELD_CELL *t;
+  bool again = FALSE;
+
+  T((T_CALLED("IFN_Previous_Word(%p)"), (void *)form));
 
   /* We really need access to the data, so we have to synchronize */
   Synchronize_Buffer(form);
 
 
   /* We really need access to the data, so we have to synchronize */
   Synchronize_Buffer(form);
 
-  s = After_End_Of_Data(field->buf,(int)(bp-field->buf));
+  s = After_End_Of_Data(field->buf, (int)(bp - field->buf));
   /* s points now right after the last non-blank in the buffer before bp.
      If bp was in a word, s equals bp. In this case we must find the last
      whitespace in the buffer before bp and repeat the game to really find
      the previous word! */
   /* s points now right after the last non-blank in the buffer before bp.
      If bp was in a word, s equals bp. In this case we must find the last
      whitespace in the buffer before bp and repeat the game to really find
      the previous word! */
-  if (s==bp)
+  if (s == bp)
     again = TRUE;
     again = TRUE;
-  
+
   /* And next call now goes backward to look for the last whitespace
      before that, pointing right after this, so it points to the begin
   /* And next call now goes backward to look for the last whitespace
      before that, pointing right after this, so it points to the begin
-     of the previous word. 
-  */
-  t = After_Last_Whitespace_Character(field->buf,(int)(s - field->buf));
+     of the previous word.
+   */
+  t = After_Last_Whitespace_Character(field->buf, (int)(s - field->buf));
 #if !FRIENDLY_PREV_NEXT_WORD
 #if !FRIENDLY_PREV_NEXT_WORD
-  if (s==t) 
-    return(E_REQUEST_DENIED);
+  if (s == t)
+    returnCode(E_REQUEST_DENIED);
 #endif
   if (again)
 #endif
   if (again)
-    { /* and do it again, replacing bp by t */
-      s = After_End_Of_Data(field->buf,(int)(t - field->buf));
-      t = After_Last_Whitespace_Character(field->buf,(int)(s - field->buf));
+    {
+      /* and do it again, replacing bp by t */
+      s = After_End_Of_Data(field->buf, (int)(t - field->buf));
+      t = After_Last_Whitespace_Character(field->buf, (int)(s - field->buf));
 #if !FRIENDLY_PREV_NEXT_WORD
 #if !FRIENDLY_PREV_NEXT_WORD
-      if (s==t) 
-       return(E_REQUEST_DENIED);
+      if (s == t)
+       returnCode(E_REQUEST_DENIED);
 #endif
     }
 #endif
     }
-  Adjust_Cursor_Position(form,t);
-  return(E_OK);
+  Adjust_Cursor_Position(form, t);
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int IFN_Beginning_Of_Field(FORM * form)
 |   Function      :  static int IFN_Beginning_Of_Field(FORM * form)
-|   
+|
 |   Description   :  Place the cursor at the first non-pad character in
 |   Description   :  Place the cursor at the first non-pad character in
-|                    the field. 
+|                    the field.
 |
 |
-|   Return Values :  E_OK             - success            
+|   Return Values :  E_OK             - success
 +--------------------------------------------------------------------------*/
 +--------------------------------------------------------------------------*/
-static int IFN_Beginning_Of_Field(FORM * form)
+static int
+IFN_Beginning_Of_Field(FORM *form)
 {
   FIELD *field = form->current;
 
 {
   FIELD *field = form->current;
 
+  T((T_CALLED("IFN_Beginning_Of_Field(%p)"), (void *)form));
   Synchronize_Buffer(form);
   Adjust_Cursor_Position(form,
   Synchronize_Buffer(form);
   Adjust_Cursor_Position(form,
-                Get_Start_Of_Data(field->buf,Buffer_Length(field)));
-  return(E_OK);
+                        Get_Start_Of_Data(field->buf, Buffer_Length(field)));
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int IFN_End_Of_Field(FORM * form)
 |   Function      :  static int IFN_End_Of_Field(FORM * form)
-|   
+|
 |   Description   :  Place the cursor after the last non-pad character in
 |                    the field. If the field occupies the last position in
 |   Description   :  Place the cursor after the last non-pad character in
 |                    the field. If the field occupies the last position in
-|                    the buffer, the cursos is positioned on the last 
+|                    the buffer, the cursor is positioned on the last
 |                    character.
 |
 |   Return Values :  E_OK              - success
 +--------------------------------------------------------------------------*/
 |                    character.
 |
 |   Return Values :  E_OK              - success
 +--------------------------------------------------------------------------*/
-static int IFN_End_Of_Field(FORM * form)
+static int
+IFN_End_Of_Field(FORM *form)
 {
   FIELD *field = form->current;
 {
   FIELD *field = form->current;
-  char *pos;
+  FIELD_CELL *pos;
 
 
+  T((T_CALLED("IFN_End_Of_Field(%p)"), (void *)form));
   Synchronize_Buffer(form);
   Synchronize_Buffer(form);
-  pos = After_End_Of_Data(field->buf,Buffer_Length(field));
-  if (pos==(field->buf + Buffer_Length(field)))
+  pos = After_End_Of_Data(field->buf, Buffer_Length(field));
+  if (pos == (field->buf + Buffer_Length(field)))
     pos--;
     pos--;
-  Adjust_Cursor_Position(form,pos);
-  return(E_OK);
+  Adjust_Cursor_Position(form, pos);
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int IFN_Beginning_Of_Line(FORM * form)
 |   Function      :  static int IFN_Beginning_Of_Line(FORM * form)
-|   
+|
 |   Description   :  Place the cursor on the first non-pad character in
 |                    the current line of the field.
 |
 |   Return Values :  E_OK         - success
 +--------------------------------------------------------------------------*/
 |   Description   :  Place the cursor on the first non-pad character in
 |                    the current line of the field.
 |
 |   Return Values :  E_OK         - success
 +--------------------------------------------------------------------------*/
-static int IFN_Beginning_Of_Line(FORM * form)
+static int
+IFN_Beginning_Of_Line(FORM *form)
 {
   FIELD *field = form->current;
 
 {
   FIELD *field = form->current;
 
+  T((T_CALLED("IFN_Beginning_Of_Line(%p)"), (void *)form));
   Synchronize_Buffer(form);
   Adjust_Cursor_Position(form,
   Synchronize_Buffer(form);
   Adjust_Cursor_Position(form,
-                Get_Start_Of_Data(Address_Of_Current_Row_In_Buffer(form),
-                                  field->dcols));
-  return(E_OK);
+                        Get_Start_Of_Data(Address_Of_Current_Row_In_Buffer(form),
+                                          field->dcols));
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int IFN_End_Of_Line(FORM * form)
 |   Function      :  static int IFN_End_Of_Line(FORM * form)
-|   
+|
 |   Description   :  Place the cursor after the last non-pad character in the
 |   Description   :  Place the cursor after the last non-pad character in the
-|                    current line of the field. If the field occupies the 
+|                    current line of the field. If the field occupies the
 |                    last column in the line, the cursor is positioned on the
 |                    last character of the line.
 |
 |   Return Values :  E_OK        - success
 +--------------------------------------------------------------------------*/
 |                    last column in the line, the cursor is positioned on the
 |                    last character of the line.
 |
 |   Return Values :  E_OK        - success
 +--------------------------------------------------------------------------*/
-static int IFN_End_Of_Line(FORM * form)
+static int
+IFN_End_Of_Line(FORM *form)
 {
   FIELD *field = form->current;
 {
   FIELD *field = form->current;
-  char *pos;
-  char *bp;
+  FIELD_CELL *pos;
+  FIELD_CELL *bp;
 
 
+  T((T_CALLED("IFN_End_Of_Line(%p)"), (void *)form));
   Synchronize_Buffer(form);
   Synchronize_Buffer(form);
-  bp  = Address_Of_Current_Row_In_Buffer(form); 
-  pos = After_End_Of_Data(bp,field->dcols);
+  bp = Address_Of_Current_Row_In_Buffer(form);
+  pos = After_End_Of_Data(bp, field->dcols);
   if (pos == (bp + field->dcols))
     pos--;
   if (pos == (bp + field->dcols))
     pos--;
-  Adjust_Cursor_Position(form,pos);
-  return(E_OK);
+  Adjust_Cursor_Position(form, pos);
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int IFN_Left_Character(FORM * form)
 |   Function      :  static int IFN_Left_Character(FORM * form)
-|   
+|
 |   Description   :  Move one character to the left in the current line.
 |   Description   :  Move one character to the left in the current line.
-|                    This doesn't cycle.  
+|                    This doesn't cycle.
 |
 |   Return Values :  E_OK             - success
 |                    E_REQUEST_DENIED - already in first column
 +--------------------------------------------------------------------------*/
 |
 |   Return Values :  E_OK             - success
 |                    E_REQUEST_DENIED - already in first column
 +--------------------------------------------------------------------------*/
-static int IFN_Left_Character(FORM * form)
+static int
+IFN_Left_Character(FORM *form)
 {
 {
-  if ( (--(form->curcol)) < 0 )
+  int amount = myWCWIDTH(form->w, form->currow, form->curcol - 1);
+  int oldcol = form->curcol;
+
+  T((T_CALLED("IFN_Left_Character(%p)"), (void *)form));
+  if ((form->curcol -= amount) < 0)
     {
     {
-      form->curcol++;
-      return(E_REQUEST_DENIED);
+      form->curcol = oldcol;
+      returnCode(E_REQUEST_DENIED);
     }
     }
-  return(E_OK);
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int IFN_Right_Character(FORM * form)
 |   Function      :  static int IFN_Right_Character(FORM * form)
-|   
+|
 |   Description   :  Move one character to the right in the current line.
 |                    This doesn't cycle.
 |
 |   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - already in last column
 +--------------------------------------------------------------------------*/
 |   Description   :  Move one character to the right in the current line.
 |                    This doesn't cycle.
 |
 |   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - already in last column
 +--------------------------------------------------------------------------*/
-static int IFN_Right_Character(FORM * form)
+static int
+IFN_Right_Character(FORM *form)
 {
 {
-  if ( (++(form->curcol)) == form->current->dcols )
+  int amount = myWCWIDTH(form->w, form->currow, form->curcol);
+  int oldcol = form->curcol;
+
+  T((T_CALLED("IFN_Right_Character(%p)"), (void *)form));
+  if ((form->curcol += amount) >= form->current->dcols)
     {
 #if GROW_IF_NAVIGATE
       FIELD *field = form->current;
     {
 #if GROW_IF_NAVIGATE
       FIELD *field = form->current;
-      if (Single_Line_Field(field) && Field_Grown(field,1))
-       return(E_OK);
+
+      if (Single_Line_Field(field) && Field_Grown(field, 1))
+       returnCode(E_OK);
 #endif
 #endif
-      --(form->curcol);
-      return(E_REQUEST_DENIED);
+      form->curcol = oldcol;
+      returnCode(E_REQUEST_DENIED);
     }
     }
-  return(E_OK);
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int IFN_Up_Character(FORM * form)
 |   Function      :  static int IFN_Up_Character(FORM * form)
-|   
+|
 |   Description   :  Move one line up. This doesn't cycle through the lines
 |                    of the field.
 |
 |   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - already in last column
 +--------------------------------------------------------------------------*/
 |   Description   :  Move one line up. This doesn't cycle through the lines
 |                    of the field.
 |
 |   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - already in last column
 +--------------------------------------------------------------------------*/
-static int IFN_Up_Character(FORM * form)
+static int
+IFN_Up_Character(FORM *form)
 {
 {
-  if ( (--(form->currow)) < 0 )
+  T((T_CALLED("IFN_Up_Character(%p)"), (void *)form));
+  if ((--(form->currow)) < 0)
     {
       form->currow++;
     {
       form->currow++;
-      return(E_REQUEST_DENIED);
+      returnCode(E_REQUEST_DENIED);
     }
     }
-  return(E_OK);
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int IFN_Down_Character(FORM * form)
 |   Function      :  static int IFN_Down_Character(FORM * form)
-|   
+|
 |   Description   :  Move one line down. This doesn't cycle through the
 |                    lines of the field.
 |
 |   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - already in last column
 +--------------------------------------------------------------------------*/
 |   Description   :  Move one line down. This doesn't cycle through the
 |                    lines of the field.
 |
 |   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - already in last column
 +--------------------------------------------------------------------------*/
-static int IFN_Down_Character(FORM * form)
+static int
+IFN_Down_Character(FORM *form)
 {
   FIELD *field = form->current;
 
 {
   FIELD *field = form->current;
 
-  if ( (++(form->currow)) == field->drows )
+  T((T_CALLED("IFN_Down_Character(%p)"), (void *)form));
+  if ((++(form->currow)) == field->drows)
     {
 #if GROW_IF_NAVIGATE
     {
 #if GROW_IF_NAVIGATE
-      if (!Single_Line_Field(field) && Field_Grown(field,1))
-       return(E_OK);
+      if (!Single_Line_Field(field) && Field_Grown(field, 1))
+       returnCode(E_OK);
 #endif
       --(form->currow);
 #endif
       --(form->currow);
-      return(E_REQUEST_DENIED);
+      returnCode(E_REQUEST_DENIED);
     }
     }
-  return(E_OK);
+  returnCode(E_OK);
 }
 /*----------------------------------------------------------------------------
 }
 /*----------------------------------------------------------------------------
-  END of Intra-Field Navigation routines 
+  END of Intra-Field Navigation routines
   --------------------------------------------------------------------------*/
   --------------------------------------------------------------------------*/
-\f
+
 /*----------------------------------------------------------------------------
   Vertical scrolling helper routines
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
 /*----------------------------------------------------------------------------
   Vertical scrolling helper routines
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
-|   Function      :  static int VSC_Generic(FORM *form, int lines)
+|   Facility      :  libnform
+|   Function      :  static int VSC_Generic(FORM *form, int nlines)
 |
 |
-|   Description   :  Scroll multi-line field forward (lines>0) or
-|                    backward (lines<0) this many lines.
+|   Description   :  Scroll multi-line field forward (nlines>0) or
+|                    backward (nlines<0) this many lines.
 |
 |
-|   Return Values :  E_OK              - success 
+|   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - can't scroll
 +--------------------------------------------------------------------------*/
 |                    E_REQUEST_DENIED  - can't scroll
 +--------------------------------------------------------------------------*/
-static int VSC_Generic(FORM *form, int lines)
+static int
+VSC_Generic(FORM *form, int nlines)
 {
   FIELD *field = form->current;
   int res = E_REQUEST_DENIED;
 {
   FIELD *field = form->current;
   int res = E_REQUEST_DENIED;
-  int rows_to_go = (lines > 0 ? lines : -lines);
+  int rows_to_go = (nlines > 0 ? nlines : -nlines);
 
 
-  if (lines > 0)
+  if (nlines > 0)
     {
     {
-      if ( (rows_to_go + form->toprow) > (field->drows - field->rows) )
+      if ((rows_to_go + form->toprow) > (field->drows - field->rows))
        rows_to_go = (field->drows - field->rows - form->toprow);
 
       if (rows_to_go > 0)
        rows_to_go = (field->drows - field->rows - form->toprow);
 
       if (rows_to_go > 0)
@@ -1630,7 +2024,7 @@ static int VSC_Generic(FORM *form, int lines)
     {
       if (rows_to_go > form->toprow)
        rows_to_go = form->toprow;
     {
       if (rows_to_go > form->toprow)
        rows_to_go = form->toprow;
-      
+
       if (rows_to_go > 0)
        {
          form->currow -= rows_to_go;
       if (rows_to_go > 0)
        {
          form->currow -= rows_to_go;
@@ -1638,29 +2032,30 @@ static int VSC_Generic(FORM *form, int lines)
          res = E_OK;
        }
     }
          res = E_OK;
        }
     }
-  return(res);
+  return (res);
 }
 /*----------------------------------------------------------------------------
   End of Vertical scrolling helper routines
   --------------------------------------------------------------------------*/
 }
 /*----------------------------------------------------------------------------
   End of Vertical scrolling helper routines
   --------------------------------------------------------------------------*/
-\f
+
 /*----------------------------------------------------------------------------
   Vertical scrolling routines
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
 /*----------------------------------------------------------------------------
   Vertical scrolling routines
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int Vertical_Scrolling(
 |                                           int (* const fct) (FORM *),
 |                                           FORM * form)
 |   Function      :  static int Vertical_Scrolling(
 |                                           int (* const fct) (FORM *),
 |                                           FORM * form)
-|   
-|   Description   :  Performs the generic vertical scrolling routines. 
+|
+|   Description   :  Performs the generic vertical scrolling routines.
 |                    This has to check for a multi-line field and to set
 |                    This has to check for a multi-line field and to set
-|                    the _NEWTOP flag if scrolling really occured.
+|                    the _NEWTOP flag if scrolling really occurred.
 |
 |   Return Values :  Propagated error code from low-level driver calls
 +--------------------------------------------------------------------------*/
 |
 |   Return Values :  Propagated error code from low-level driver calls
 +--------------------------------------------------------------------------*/
-static int Vertical_Scrolling(int (* const fct) (FORM *), FORM * form)
+static int
+Vertical_Scrolling(int (*const fct) (FORM *), FORM *form)
 {
   int res = E_REQUEST_DENIED;
 
 {
   int res = E_REQUEST_DENIED;
 
@@ -1668,301 +2063,329 @@ static int Vertical_Scrolling(int (* const fct) (FORM *), FORM * form)
     {
       res = fct(form);
       if (res == E_OK)
     {
       res = fct(form);
       if (res == E_OK)
-       form->current->status |= _NEWTOP;
+       SetStatus(form->current, _NEWTOP);
     }
     }
-  return(res);
+  return (res);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int VSC_Scroll_Line_Forward(FORM * form)
 |   Function      :  static int VSC_Scroll_Line_Forward(FORM * form)
-|   
+|
 |   Description   :  Scroll multi-line field forward a line
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - no data ahead
 +--------------------------------------------------------------------------*/
 |   Description   :  Scroll multi-line field forward a line
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - no data ahead
 +--------------------------------------------------------------------------*/
-static int VSC_Scroll_Line_Forward(FORM * form)
+static int
+VSC_Scroll_Line_Forward(FORM *form)
 {
 {
-  return VSC_Generic(form,1);
+  T((T_CALLED("VSC_Scroll_Line_Forward(%p)"), (void *)form));
+  returnCode(VSC_Generic(form, 1));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int VSC_Scroll_Line_Backward(FORM * form)
 |   Function      :  static int VSC_Scroll_Line_Backward(FORM * form)
-|   
+|
 |   Description   :  Scroll multi-line field backward a line
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - no data behind
 +--------------------------------------------------------------------------*/
 |   Description   :  Scroll multi-line field backward a line
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - no data behind
 +--------------------------------------------------------------------------*/
-static int VSC_Scroll_Line_Backward(FORM * form)
+static int
+VSC_Scroll_Line_Backward(FORM *form)
 {
 {
-  return VSC_Generic(form,-1);
+  T((T_CALLED("VSC_Scroll_Line_Backward(%p)"), (void *)form));
+  returnCode(VSC_Generic(form, -1));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int VSC_Scroll_Page_Forward(FORM * form)
 |   Function      :  static int VSC_Scroll_Page_Forward(FORM * form)
-|   
+|
 |   Description   :  Scroll a multi-line field forward a page
 |
 |   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - no data ahead
 +--------------------------------------------------------------------------*/
 |   Description   :  Scroll a multi-line field forward a page
 |
 |   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - no data ahead
 +--------------------------------------------------------------------------*/
-static int VSC_Scroll_Page_Forward(FORM * form)
+static int
+VSC_Scroll_Page_Forward(FORM *form)
 {
 {
-  return VSC_Generic(form,form->current->rows);
+  T((T_CALLED("VSC_Scroll_Page_Forward(%p)"), (void *)form));
+  returnCode(VSC_Generic(form, form->current->rows));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int VSC_Scroll_Half_Page_Forward(FORM * form)
 |   Function      :  static int VSC_Scroll_Half_Page_Forward(FORM * form)
-|   
+|
 |   Description   :  Scroll a multi-line field forward half a page
 |
 |   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - no data ahead
 +--------------------------------------------------------------------------*/
 |   Description   :  Scroll a multi-line field forward half a page
 |
 |   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - no data ahead
 +--------------------------------------------------------------------------*/
-static int VSC_Scroll_Half_Page_Forward(FORM * form)
+static int
+VSC_Scroll_Half_Page_Forward(FORM *form)
 {
 {
-  return VSC_Generic(form,(form->current->rows + 1)/2);
+  T((T_CALLED("VSC_Scroll_Half_Page_Forward(%p)"), (void *)form));
+  returnCode(VSC_Generic(form, (form->current->rows + 1) / 2));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int VSC_Scroll_Page_Backward(FORM * form)
 |   Function      :  static int VSC_Scroll_Page_Backward(FORM * form)
-|   
+|
 |   Description   :  Scroll a multi-line field backward a page
 |
 |   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - no data behind
 +--------------------------------------------------------------------------*/
 |   Description   :  Scroll a multi-line field backward a page
 |
 |   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - no data behind
 +--------------------------------------------------------------------------*/
-static int VSC_Scroll_Page_Backward(FORM * form)
+static int
+VSC_Scroll_Page_Backward(FORM *form)
 {
 {
-  return VSC_Generic(form, -(form->current->rows));
+  T((T_CALLED("VSC_Scroll_Page_Backward(%p)"), (void *)form));
+  returnCode(VSC_Generic(form, -(form->current->rows)));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int VSC_Scroll_Half_Page_Backward(FORM * form)
 |   Function      :  static int VSC_Scroll_Half_Page_Backward(FORM * form)
-|   
+|
 |   Description   :  Scroll a multi-line field backward half a page
 |
 |   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - no data behind
 +--------------------------------------------------------------------------*/
 |   Description   :  Scroll a multi-line field backward half a page
 |
 |   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - no data behind
 +--------------------------------------------------------------------------*/
-static int VSC_Scroll_Half_Page_Backward(FORM * form)
+static int
+VSC_Scroll_Half_Page_Backward(FORM *form)
 {
 {
-  return VSC_Generic(form, -((form->current->rows + 1)/2));
+  T((T_CALLED("VSC_Scroll_Half_Page_Backward(%p)"), (void *)form));
+  returnCode(VSC_Generic(form, -((form->current->rows + 1) / 2)));
 }
 /*----------------------------------------------------------------------------
   End of Vertical scrolling routines
   --------------------------------------------------------------------------*/
 }
 /*----------------------------------------------------------------------------
   End of Vertical scrolling routines
   --------------------------------------------------------------------------*/
-\f
+
 /*----------------------------------------------------------------------------
   Horizontal scrolling helper routines
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
 /*----------------------------------------------------------------------------
   Horizontal scrolling helper routines
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
-|   Function      :  static int HSC_Generic(FORM *form, int columns)
+|   Facility      :  libnform
+|   Function      :  static int HSC_Generic(FORM *form, int ncolumns)
 |
 |
-|   Description   :  Scroll single-line field forward (columns>0) or
-|                    backward (columns<0) this many columns.
+|   Description   :  Scroll single-line field forward (ncolumns>0) or
+|                    backward (ncolumns<0) this many columns.
 |
 |
-|   Return Values :  E_OK              - success 
+|   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - can't scroll
 +--------------------------------------------------------------------------*/
 |                    E_REQUEST_DENIED  - can't scroll
 +--------------------------------------------------------------------------*/
-static int HSC_Generic(FORM *form, int columns)
+static int
+HSC_Generic(FORM *form, int ncolumns)
 {
   FIELD *field = form->current;
   int res = E_REQUEST_DENIED;
 {
   FIELD *field = form->current;
   int res = E_REQUEST_DENIED;
-  int cols_to_go = (columns > 0 ? columns : -columns);
+  int cols_to_go = (ncolumns > 0 ? ncolumns : -ncolumns);
 
 
-  if (columns > 0)
+  if (ncolumns > 0)
     {
       if ((cols_to_go + form->begincol) > (field->dcols - field->cols))
        cols_to_go = field->dcols - field->cols - form->begincol;
     {
       if ((cols_to_go + form->begincol) > (field->dcols - field->cols))
        cols_to_go = field->dcols - field->cols - form->begincol;
-      
+
       if (cols_to_go > 0)
        {
       if (cols_to_go > 0)
        {
-         form->curcol   += cols_to_go;
+         form->curcol += cols_to_go;
          form->begincol += cols_to_go;
          res = E_OK;
        }
     }
   else
     {
          form->begincol += cols_to_go;
          res = E_OK;
        }
     }
   else
     {
-      if ( cols_to_go > form->begincol )
+      if (cols_to_go > form->begincol)
        cols_to_go = form->begincol;
 
       if (cols_to_go > 0)
        {
        cols_to_go = form->begincol;
 
       if (cols_to_go > 0)
        {
-         form->curcol   -= cols_to_go;
+         form->curcol -= cols_to_go;
          form->begincol -= cols_to_go;
          res = E_OK;
        }
     }
          form->begincol -= cols_to_go;
          res = E_OK;
        }
     }
-  return(res);
+  return (res);
 }
 /*----------------------------------------------------------------------------
   End of Horizontal scrolling helper routines
   --------------------------------------------------------------------------*/
 }
 /*----------------------------------------------------------------------------
   End of Horizontal scrolling helper routines
   --------------------------------------------------------------------------*/
-\f
+
 /*----------------------------------------------------------------------------
   Horizontal scrolling routines
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
 /*----------------------------------------------------------------------------
   Horizontal scrolling routines
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int Horizontal_Scrolling(
 |                                          int (* const fct) (FORM *),
 |                                          FORM * form)
 |   Function      :  static int Horizontal_Scrolling(
 |                                          int (* const fct) (FORM *),
 |                                          FORM * form)
-|   
-|   Description   :  Performs the generic horizontal scrolling routines. 
+|
+|   Description   :  Performs the generic horizontal scrolling routines.
 |                    This has to check for a single-line field.
 |
 |   Return Values :  Propagated error code from low-level driver calls
 +--------------------------------------------------------------------------*/
 |                    This has to check for a single-line field.
 |
 |   Return Values :  Propagated error code from low-level driver calls
 +--------------------------------------------------------------------------*/
-static int Horizontal_Scrolling(int (* const fct) (FORM *), FORM * form)
+static int
+Horizontal_Scrolling(int (*const fct) (FORM *), FORM *form)
 {
   if (Single_Line_Field(form->current))
     return fct(form);
   else
 {
   if (Single_Line_Field(form->current))
     return fct(form);
   else
-    return(E_REQUEST_DENIED);
+    return (E_REQUEST_DENIED);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int HSC_Scroll_Char_Forward(FORM * form)
 |   Function      :  static int HSC_Scroll_Char_Forward(FORM * form)
-|   
+|
 |   Description   :  Scroll single-line field forward a character
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - no data ahead
 +--------------------------------------------------------------------------*/
 |   Description   :  Scroll single-line field forward a character
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - no data ahead
 +--------------------------------------------------------------------------*/
-static int HSC_Scroll_Char_Forward(FORM *form)
+static int
+HSC_Scroll_Char_Forward(FORM *form)
 {
 {
-  return HSC_Generic(form,1);
+  T((T_CALLED("HSC_Scroll_Char_Forward(%p)"), (void *)form));
+  returnCode(HSC_Generic(form, 1));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int HSC_Scroll_Char_Backward(FORM * form)
 |   Function      :  static int HSC_Scroll_Char_Backward(FORM * form)
-|   
+|
 |   Description   :  Scroll single-line field backward a character
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - no data behind
 +--------------------------------------------------------------------------*/
 |   Description   :  Scroll single-line field backward a character
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - no data behind
 +--------------------------------------------------------------------------*/
-static int HSC_Scroll_Char_Backward(FORM *form)
+static int
+HSC_Scroll_Char_Backward(FORM *form)
 {
 {
-  return HSC_Generic(form,-1);
+  T((T_CALLED("HSC_Scroll_Char_Backward(%p)"), (void *)form));
+  returnCode(HSC_Generic(form, -1));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int HSC_Horizontal_Line_Forward(FORM* form)
 |   Function      :  static int HSC_Horizontal_Line_Forward(FORM* form)
-|   
+|
 |   Description   :  Scroll single-line field forward a line
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - no data ahead
 +--------------------------------------------------------------------------*/
 |   Description   :  Scroll single-line field forward a line
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - no data ahead
 +--------------------------------------------------------------------------*/
-static int HSC_Horizontal_Line_Forward(FORM * form)
+static int
+HSC_Horizontal_Line_Forward(FORM *form)
 {
 {
-  return HSC_Generic(form,form->current->cols);
+  T((T_CALLED("HSC_Horizontal_Line_Forward(%p)"), (void *)form));
+  returnCode(HSC_Generic(form, form->current->cols));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int HSC_Horizontal_Half_Line_Forward(FORM* form)
 |   Function      :  static int HSC_Horizontal_Half_Line_Forward(FORM* form)
-|   
+|
 |   Description   :  Scroll single-line field forward half a line
 |
 |   Return Values :  E_OK               - success
 |                    E_REQUEST_DENIED   - no data ahead
 +--------------------------------------------------------------------------*/
 |   Description   :  Scroll single-line field forward half a line
 |
 |   Return Values :  E_OK               - success
 |                    E_REQUEST_DENIED   - no data ahead
 +--------------------------------------------------------------------------*/
-static int HSC_Horizontal_Half_Line_Forward(FORM * form)
+static int
+HSC_Horizontal_Half_Line_Forward(FORM *form)
 {
 {
-  return HSC_Generic(form,(form->current->cols + 1)/2);
+  T((T_CALLED("HSC_Horizontal_Half_Line_Forward(%p)"), (void *)form));
+  returnCode(HSC_Generic(form, (form->current->cols + 1) / 2));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int HSC_Horizontal_Line_Backward(FORM* form)
 |   Function      :  static int HSC_Horizontal_Line_Backward(FORM* form)
-|   
+|
 |   Description   :  Scroll single-line field backward a line
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - no data behind
 +--------------------------------------------------------------------------*/
 |   Description   :  Scroll single-line field backward a line
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - no data behind
 +--------------------------------------------------------------------------*/
-static int HSC_Horizontal_Line_Backward(FORM * form)
+static int
+HSC_Horizontal_Line_Backward(FORM *form)
 {
 {
-  return HSC_Generic(form,-(form->current->cols));
+  T((T_CALLED("HSC_Horizontal_Line_Backward(%p)"), (void *)form));
+  returnCode(HSC_Generic(form, -(form->current->cols)));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int HSC_Horizontal_Half_Line_Backward(FORM* form)
 |   Function      :  static int HSC_Horizontal_Half_Line_Backward(FORM* form)
-|   
+|
 |   Description   :  Scroll single-line field backward half a line
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - no data behind
 +--------------------------------------------------------------------------*/
 |   Description   :  Scroll single-line field backward half a line
 |
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - no data behind
 +--------------------------------------------------------------------------*/
-static int HSC_Horizontal_Half_Line_Backward(FORM * form)
+static int
+HSC_Horizontal_Half_Line_Backward(FORM *form)
 {
 {
-  return HSC_Generic(form,-((form->current->cols + 1)/2));
+  T((T_CALLED("HSC_Horizontal_Half_Line_Backward(%p)"), (void *)form));
+  returnCode(HSC_Generic(form, -((form->current->cols + 1) / 2)));
 }
 
 /*----------------------------------------------------------------------------
   End of Horizontal scrolling routines
   --------------------------------------------------------------------------*/
 }
 
 /*----------------------------------------------------------------------------
   End of Horizontal scrolling routines
   --------------------------------------------------------------------------*/
-\f
+
 /*----------------------------------------------------------------------------
   Helper routines for Field Editing
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
 /*----------------------------------------------------------------------------
   Helper routines for Field Editing
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static bool Is_There_Room_For_A_Line(FORM * form)
 |   Function      :  static bool Is_There_Room_For_A_Line(FORM * form)
-|   
+|
 |   Description   :  Check whether or not there is enough room in the
 |                    buffer to enter a whole line.
 |
 |   Return Values :  TRUE   - there is enough space
 |                    FALSE  - there is not enough space
 +--------------------------------------------------------------------------*/
 |   Description   :  Check whether or not there is enough room in the
 |                    buffer to enter a whole line.
 |
 |   Return Values :  TRUE   - there is enough space
 |                    FALSE  - there is not enough space
 +--------------------------------------------------------------------------*/
-INLINE static bool Is_There_Room_For_A_Line(FORM * form)
+NCURSES_INLINE static bool
+Is_There_Room_For_A_Line(FORM *form)
 {
   FIELD *field = form->current;
 {
   FIELD *field = form->current;
-  char *begin_of_last_line, *s;
-  
+  FIELD_CELL *begin_of_last_line, *s;
+
   Synchronize_Buffer(form);
   Synchronize_Buffer(form);
-  begin_of_last_line = Address_Of_Row_In_Buffer(field,(field->drows-1));
-  s  = After_End_Of_Data(begin_of_last_line,field->dcols);
-  return ((s==begin_of_last_line) ? TRUE : FALSE);
+  begin_of_last_line = Address_Of_Row_In_Buffer(field, (field->drows - 1));
+  s = After_End_Of_Data(begin_of_last_line, field->dcols);
+  return ((s == begin_of_last_line) ? TRUE : FALSE);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static bool Is_There_Room_For_A_Char_In_Line(FORM * form)
 |   Function      :  static bool Is_There_Room_For_A_Char_In_Line(FORM * form)
-|   
+|
 |   Description   :  Checks whether or not there is room for a new character
 |                    in the current line.
 |
 |   Return Values :  TRUE    - there is room
 |                    FALSE   - there is not enough room (line full)
 +--------------------------------------------------------------------------*/
 |   Description   :  Checks whether or not there is room for a new character
 |                    in the current line.
 |
 |   Return Values :  TRUE    - there is room
 |                    FALSE   - there is not enough room (line full)
 +--------------------------------------------------------------------------*/
-INLINE static bool Is_There_Room_For_A_Char_In_Line(FORM * form)
+NCURSES_INLINE static bool
+Is_There_Room_For_A_Char_In_Line(FORM *form)
 {
   int last_char_in_line;
 
 {
   int last_char_in_line;
 
-  wmove(form->w,form->currow,form->current->dcols-1);
-  last_char_in_line  = (int)(winch(form->w) & A_CHARTEXT);
-  wmove(form->w,form->currow,form->curcol);
+  wmove(form->w, form->currow, form->current->dcols - 1);
+  last_char_in_line = (int)(winch(form->w) & A_CHARTEXT);
+  wmove(form->w, form->currow, form->curcol);
   return (((last_char_in_line == form->current->pad) ||
           is_blank(last_char_in_line)) ? TRUE : FALSE);
 }
   return (((last_char_in_line == form->current->pad) ||
           is_blank(last_char_in_line)) ? TRUE : FALSE);
 }
@@ -1971,129 +2394,137 @@ INLINE static bool Is_There_Room_For_A_Char_In_Line(FORM * form)
   !Is_There_Room_For_A_Char_In_Line(f)
 
 /*---------------------------------------------------------------------------
   !Is_There_Room_For_A_Char_In_Line(f)
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int Insert_String(
 |                                             FORM * form,
 |                                             int row,
 |                                             char *txt,
 |                                             int  len )
 |   Function      :  static int Insert_String(
 |                                             FORM * form,
 |                                             int row,
 |                                             char *txt,
 |                                             int  len )
-|   
+|
 |   Description   :  Insert the 'len' characters beginning at pointer 'txt'
 |                    into the 'row' of the 'form'. The insertion occurs
 |                    on the beginning of the row, all other characters are
 |   Description   :  Insert the 'len' characters beginning at pointer 'txt'
 |                    into the 'row' of the 'form'. The insertion occurs
 |                    on the beginning of the row, all other characters are
-|                    moved to the right. After the text a pad character will 
+|                    moved to the right. After the text a pad character will
 |                    be inserted to separate the text from the rest. If
 |                    necessary the insertion moves characters on the next
 |                    line to make place for the requested insertion string.
 |
 |                    be inserted to separate the text from the rest. If
 |                    necessary the insertion moves characters on the next
 |                    line to make place for the requested insertion string.
 |
-|   Return Values :  E_OK              - success 
+|   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  -
 |                    E_SYSTEM_ERROR    - system error
 +--------------------------------------------------------------------------*/
 |                    E_REQUEST_DENIED  -
 |                    E_SYSTEM_ERROR    - system error
 +--------------------------------------------------------------------------*/
-static int Insert_String(FORM *form, int row, char *txt, int len)
-{ 
-  FIELD  *field    = form->current;
-  char *bp         = Address_Of_Row_In_Buffer(field,row);
-  int datalen      = (int)(After_End_Of_Data(bp,field->dcols) - bp);
-  int freelen      = field->dcols - datalen;
-  int requiredlen  = len+1;
-  char *split;
+static int
+Insert_String(FORM *form, int row, FIELD_CELL *txt, int len)
+{
+  FIELD *field = form->current;
+  FIELD_CELL *bp = Address_Of_Row_In_Buffer(field, row);
+  int datalen = (int)(After_End_Of_Data(bp, field->dcols) - bp);
+  int freelen = field->dcols - datalen;
+  int requiredlen = len + 1;
+  FIELD_CELL *split;
   int result = E_REQUEST_DENIED;
   int result = E_REQUEST_DENIED;
-  const char *Space = " ";
 
   if (freelen >= requiredlen)
     {
 
   if (freelen >= requiredlen)
     {
-      wmove(form->w,row,0);
-      winsnstr(form->w,txt,len);
-      wmove(form->w,row,len);
-      winsnstr(form->w,Space,1);
+      wmove(form->w, row, 0);
+      myINSNSTR(form->w, txt, len);
+      wmove(form->w, row, len);
+      myINSNSTR(form->w, &myBLANK, 1);
       return E_OK;
     }
   else
       return E_OK;
     }
   else
-    { /* we have to move characters on the next line. If we are on the
-        last line this may work, if the field is growable */
+    {
+      /* we have to move characters on the next line. If we are on the
+         last line this may work, if the field is growable */
       if ((row == (field->drows - 1)) && Growable(field))
        {
       if ((row == (field->drows - 1)) && Growable(field))
        {
-         if (!Field_Grown(field,1))
-           return(E_SYSTEM_ERROR);
+         if (!Field_Grown(field, 1))
+           return (E_SYSTEM_ERROR);
          /* !!!Side-Effect : might be changed due to growth!!! */
          /* !!!Side-Effect : might be changed due to growth!!! */
-         bp = Address_Of_Row_In_Buffer(field,row); 
+         bp = Address_Of_Row_In_Buffer(field, row);
        }
 
        }
 
-      if (row < (field->drows - 1)) 
-       { 
-         split = After_Last_Whitespace_Character(bp,
-                   (int)(Get_Start_Of_Data(bp + field->dcols - requiredlen ,
-                                           requiredlen) - bp));
+      if (row < (field->drows - 1))
+       {
+         split =
+           After_Last_Whitespace_Character(bp,
+                                           (int)(Get_Start_Of_Data(bp
+                                                                   + field->dcols
+                                                                   - requiredlen,
+                                                                   requiredlen)
+                                                 - bp));
          /* split points now to the first character of the portion of the
             line that must be moved to the next line */
          /* split points now to the first character of the portion of the
             line that must be moved to the next line */
-         datalen = (int)(split-bp); /* + freelen has to stay on this line   */
-         freelen = field->dcols - (datalen + freelen); /* for the next line */
+         datalen = (int)(split - bp);  /* + freelen has to stay on this line   */
+         freelen = field->dcols - (datalen + freelen);         /* for the next line */
 
 
-         if ((result=Insert_String(form,row+1,split,freelen))==E_OK) 
+         if ((result = Insert_String(form, row + 1, split, freelen)) == E_OK)
            {
            {
-             wmove(form->w,row,datalen);
+             wmove(form->w, row, datalen);
              wclrtoeol(form->w);
              wclrtoeol(form->w);
-             wmove(form->w,row,0);
-             winsnstr(form->w,txt,len);
-             wmove(form->w,row,len);
-             winsnstr(form->w,Space,1);
+             wmove(form->w, row, 0);
+             myINSNSTR(form->w, txt, len);
+             wmove(form->w, row, len);
+             myINSNSTR(form->w, &myBLANK, 1);
              return E_OK;
            }
        }
              return E_OK;
            }
        }
-      return(result);
+      return (result);
     }
 }
 
 /*---------------------------------------------------------------------------
     }
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int Wrapping_Not_Necessary_Or_Wrapping_Ok(
 |                                             FORM * form)
 |   Function      :  static int Wrapping_Not_Necessary_Or_Wrapping_Ok(
 |                                             FORM * form)
-|   
+|
 |   Description   :  If a character has been entered into a field, it may
 |                    be that wrapping has to occur. This routine checks
 |                    whether or not wrapping is required and if so, performs
 |                    the wrapping.
 |
 |   Return Values :  E_OK              - no wrapping required or wrapping
 |   Description   :  If a character has been entered into a field, it may
 |                    be that wrapping has to occur. This routine checks
 |                    whether or not wrapping is required and if so, performs
 |                    the wrapping.
 |
 |   Return Values :  E_OK              - no wrapping required or wrapping
-|                                        was successfull
+|                                        was successful
 |                    E_REQUEST_DENIED  -
 |                    E_SYSTEM_ERROR    - some system error
 +--------------------------------------------------------------------------*/
 |                    E_REQUEST_DENIED  -
 |                    E_SYSTEM_ERROR    - some system error
 +--------------------------------------------------------------------------*/
-static int Wrapping_Not_Necessary_Or_Wrapping_Ok(FORM * form)
+static int
+Wrapping_Not_Necessary_Or_Wrapping_Ok(FORM *form)
 {
 {
-  FIELD  *field = form->current;
+  FIELD *field = form->current;
   int result = E_REQUEST_DENIED;
   bool Last_Row = ((field->drows - 1) == form->currow);
 
   int result = E_REQUEST_DENIED;
   bool Last_Row = ((field->drows - 1) == form->currow);
 
-  if ( (field->opts & O_WRAP)                     &&  /* wrapping wanted     */
-      (!Single_Line_Field(field))                 &&  /* must be multi-line  */
-      (There_Is_No_Room_For_A_Char_In_Line(form)) &&  /* line is full        */
-      (!Last_Row || Growable(field))               )  /* there are more lines*/
+  if ((Field_Has_Option(field, O_WRAP)) &&     /* wrapping wanted     */
+      (!Single_Line_Field(field)) &&   /* must be multi-line  */
+      (There_Is_No_Room_For_A_Char_In_Line(form)) &&   /* line is full        */
+      (!Last_Row || Growable(field)))  /* there are more lines */
     {
     {
-      char *bp;
-      char *split;
+      FIELD_CELL *bp;
+      FIELD_CELL *split;
       int chars_to_be_wrapped;
       int chars_to_remain_on_line;
       int chars_to_be_wrapped;
       int chars_to_remain_on_line;
+
       if (Last_Row)
       if (Last_Row)
-       { /* the above logic already ensures, that in this case the field
+       {
+         /* the above logic already ensures, that in this case the field
             is growable */
             is growable */
-         if (!Field_Grown(field,1))
+         if (!Field_Grown(field, 1))
            return E_SYSTEM_ERROR;
        }
       bp = Address_Of_Current_Row_In_Buffer(form);
            return E_SYSTEM_ERROR;
        }
       bp = Address_Of_Current_Row_In_Buffer(form);
-      Window_To_Buffer(form->w,field);
-      split = After_Last_Whitespace_Character(bp,field->dcols);
+      Window_To_Buffer(formfield);
+      split = After_Last_Whitespace_Character(bp, field->dcols);
       /* split points to the first character of the sequence to be brought
          on the next line */
       chars_to_remain_on_line = (int)(split - bp);
       /* split points to the first character of the sequence to be brought
          on the next line */
       chars_to_remain_on_line = (int)(split - bp);
-      chars_to_be_wrapped     = field->dcols - chars_to_remain_on_line;
+      chars_to_be_wrapped = field->dcols - chars_to_remain_on_line;
       if (chars_to_remain_on_line > 0)
        {
       if (chars_to_remain_on_line > 0)
        {
-         if ((result=Insert_String(form,form->currow+1,split,
-                                   chars_to_be_wrapped)) == E_OK)
+         if ((result = Insert_String(form, form->currow + 1, split,
+                                     chars_to_be_wrapped)) == E_OK)
            {
            {
-             wmove(form->w,form->currow,chars_to_remain_on_line);
+             wmove(form->w, form->currow, chars_to_remain_on_line);
              wclrtoeol(form->w);
              if (form->curcol >= chars_to_remain_on_line)
                {
              wclrtoeol(form->w);
              if (form->curcol >= chars_to_remain_on_line)
                {
@@ -2105,61 +2536,61 @@ static int Wrapping_Not_Necessary_Or_Wrapping_Ok(FORM * form)
        }
       else
        return E_OK;
        }
       else
        return E_OK;
-      if (result!=E_OK)
+      if (result != E_OK)
        {
        {
-         wmove(form->w,form->currow,form->curcol);
-         wdelch(form->w);
-         Window_To_Buffer(form->w,field);
+         DeleteChar(form);
+         Window_To_Buffer(form, field);
          result = E_REQUEST_DENIED;
        }
     }
   else
          result = E_REQUEST_DENIED;
        }
     }
   else
-    result = E_OK; /* wrapping was not necessary */
-  return(result);
+    result = E_OK;             /* wrapping was not necessary */
+  return (result);
 }
 }
-\f
+
 /*----------------------------------------------------------------------------
   Field Editing routines
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
 /*----------------------------------------------------------------------------
   Field Editing routines
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int Field_Editing(
 |                                    int (* const fct) (FORM *),
 |                                    FORM * form)
 |   Function      :  static int Field_Editing(
 |                                    int (* const fct) (FORM *),
 |                                    FORM * form)
-|   
+|
 |   Description   :  Generic routine for field editing requests. The driver
 |                    routines are only called for editable fields, the
 |   Description   :  Generic routine for field editing requests. The driver
 |                    routines are only called for editable fields, the
-|                    _WINDOW_MODIFIED flag is set if editing occured.
+|                    _WINDOW_MODIFIED flag is set if editing occurred.
 |                    This is somewhat special due to the overload semantics
 |                    of the NEW_LINE and DEL_PREV requests.
 |
 |   Return Values :  Error code from low level drivers.
 +--------------------------------------------------------------------------*/
 |                    This is somewhat special due to the overload semantics
 |                    of the NEW_LINE and DEL_PREV requests.
 |
 |   Return Values :  Error code from low level drivers.
 +--------------------------------------------------------------------------*/
-static int Field_Editing(int (* const fct) (FORM *), FORM * form)
+static int
+Field_Editing(int (*const fct) (FORM *), FORM *form)
 {
   int res = E_REQUEST_DENIED;
 
 {
   int res = E_REQUEST_DENIED;
 
-  /* We have to deal here with the specific case of the overloaded 
-     behaviour of New_Line and Delete_Previous requests.
+  /* We have to deal here with the specific case of the overloaded
+     behavior of New_Line and Delete_Previous requests.
      They may end up in navigational requests if we are on the first
      character in a field. But navigation is also allowed on non-
      editable fields.
      They may end up in navigational requests if we are on the first
      character in a field. But navigation is also allowed on non-
      editable fields.
-  */ 
-  if ((fct==FE_Delete_Previous)            && 
-      (form->opts & O_BS_OVERLOAD)         &&
-      First_Position_In_Current_Field(form) )
+   */
+  if ((fct == FE_Delete_Previous) &&
+      ((unsigned)form->opts & O_BS_OVERLOAD) &&
+      First_Position_In_Current_Field(form))
     {
     {
-      res = Inter_Field_Navigation(FN_Previous_Field,form);
+      res = Inter_Field_Navigation(FN_Previous_Field, form);
     }
   else
     {
     }
   else
     {
-      if (fct==FE_New_Line)
+      if (fct == FE_New_Line)
        {
        {
-         if ((form->opts & O_NL_OVERLOAD)         &&
+         if (((unsigned)form->opts & O_NL_OVERLOAD) &&
              First_Position_In_Current_Field(form))
            {
              First_Position_In_Current_Field(form))
            {
-             res = Inter_Field_Navigation(FN_Next_Field,form);
+             res = Inter_Field_Navigation(FN_Next_Field, form);
            }
          else
            /* FE_New_Line deals itself with the _WINDOW_MODIFIED flag */
            }
          else
            /* FE_New_Line deals itself with the _WINDOW_MODIFIED flag */
@@ -2168,11 +2599,11 @@ static int Field_Editing(int (* const fct) (FORM *), FORM * form)
       else
        {
          /* From now on, everything must be editable */
       else
        {
          /* From now on, everything must be editable */
-         if (form->current->opts & O_EDIT)
+         if ((unsigned)form->current->opts & O_EDIT)
            {
              res = fct(form);
            {
              res = fct(form);
-             if (res==E_OK)
-               form->status |= _WINDOW_MODIFIED;
+             if (res == E_OK)
+               SetStatus(form, _WINDOW_MODIFIED);
            }
        }
     }
            }
        }
     }
@@ -2180,11 +2611,11 @@ static int Field_Editing(int (* const fct) (FORM *), FORM * form)
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FE_New_Line(FORM * form)
 |   Function      :  static int FE_New_Line(FORM * form)
-|   
+|
 |   Description   :  Perform a new line request. This is rather complex
 |   Description   :  Perform a new line request. This is rather complex
-|                    compared to other routines in this code due to the 
+|                    compared to other routines in this code due to the
 |                    rather difficult to understand description in the
 |                    manuals.
 |
 |                    rather difficult to understand description in the
 |                    manuals.
 |
@@ -2192,130 +2623,143 @@ static int Field_Editing(int (* const fct) (FORM *), FORM * form)
 |                    E_REQUEST_DENIED   - new line not allowed
 |                    E_SYSTEM_ERROR     - system error
 +--------------------------------------------------------------------------*/
 |                    E_REQUEST_DENIED   - new line not allowed
 |                    E_SYSTEM_ERROR     - system error
 +--------------------------------------------------------------------------*/
-static int FE_New_Line(FORM * form)
+static int
+FE_New_Line(FORM *form)
 {
 {
-  FIELD  *field = form->current;
-  char *bp, *t;
-  bool Last_Row = ((field->drows - 1)==form->currow);
-  
-  if (form->status & _OVLMODE) 
+  FIELD *field = form->current;
+  FIELD_CELL *bp, *t;
+  bool Last_Row = ((field->drows - 1) == form->currow);
+
+  T((T_CALLED("FE_New_Line(%p)"), (void *)form));
+  if (form->status & _OVLMODE)
     {
     {
-      if (Last_Row && 
+      if (Last_Row &&
          (!(Growable(field) && !Single_Line_Field(field))))
        {
          (!(Growable(field) && !Single_Line_Field(field))))
        {
-         if (!(form->opts & O_NL_OVERLOAD))
-           return(E_REQUEST_DENIED);
+         if (!((unsigned)form->opts & O_NL_OVERLOAD))
+           returnCode(E_REQUEST_DENIED);
+         wmove(form->w, form->currow, form->curcol);
          wclrtoeol(form->w);
          /* we have to set this here, although it is also
             handled in the generic routine. The reason is,
             that FN_Next_Field may fail, but the form is
             definitively changed */
          wclrtoeol(form->w);
          /* we have to set this here, although it is also
             handled in the generic routine. The reason is,
             that FN_Next_Field may fail, but the form is
             definitively changed */
-         form->status |= _WINDOW_MODIFIED;
-         return Inter_Field_Navigation(FN_Next_Field,form);
+         SetStatus(form, _WINDOW_MODIFIED);
+         returnCode(Inter_Field_Navigation(FN_Next_Field, form));
        }
        }
-      else 
+      else
        {
        {
-         if (Last_Row && !Field_Grown(field,1))
-           { /* N.B.: due to the logic in the 'if', LastRow==TRUE
-                means here that the field is growable and not
-                a single-line field */
-             return(E_SYSTEM_ERROR);
+         if (Last_Row && !Field_Grown(field, 1))
+           {
+             /* N.B.: due to the logic in the 'if', LastRow==TRUE
+                means here that the field is growable and not
+                a single-line field */
+             returnCode(E_SYSTEM_ERROR);
            }
            }
+         wmove(form->w, form->currow, form->curcol);
          wclrtoeol(form->w);
          form->currow++;
          form->curcol = 0;
          wclrtoeol(form->w);
          form->currow++;
          form->curcol = 0;
-         form->status |= _WINDOW_MODIFIED;
-         return(E_OK);
+         SetStatus(form, _WINDOW_MODIFIED);
+         returnCode(E_OK);
        }
     }
        }
     }
-  else 
-    { /* Insert Mode */
+  else
+    {
+      /* Insert Mode */
       if (Last_Row &&
          !(Growable(field) && !Single_Line_Field(field)))
        {
       if (Last_Row &&
          !(Growable(field) && !Single_Line_Field(field)))
        {
-         if (!(form->opts & O_NL_OVERLOAD))
-           return(E_REQUEST_DENIED);
-         return Inter_Field_Navigation(FN_Next_Field,form);
+         if (!((unsigned)form->opts & O_NL_OVERLOAD))
+           returnCode(E_REQUEST_DENIED);
+         returnCode(Inter_Field_Navigation(FN_Next_Field, form));
        }
        }
-      else 
+      else
        {
          bool May_Do_It = !Last_Row && Is_There_Room_For_A_Line(form);
        {
          bool May_Do_It = !Last_Row && Is_There_Room_For_A_Line(form);
-         
+
          if (!(May_Do_It || Growable(field)))
          if (!(May_Do_It || Growable(field)))
-           return(E_REQUEST_DENIED);
-         if (!May_Do_It && !Field_Grown(field,1))
-           return(E_SYSTEM_ERROR);
-         
-         bp= Address_Of_Current_Position_In_Buffer(form);
-         t = After_End_Of_Data(bp,field->dcols - form->curcol);
+           returnCode(E_REQUEST_DENIED);
+         if (!May_Do_It && !Field_Grown(field, 1))
+           returnCode(E_SYSTEM_ERROR);
+
+         bp = Address_Of_Current_Position_In_Buffer(form);
+         t = After_End_Of_Data(bp, field->dcols - form->curcol);
+         wmove(form->w, form->currow, form->curcol);
          wclrtoeol(form->w);
          form->currow++;
          wclrtoeol(form->w);
          form->currow++;
-         form->curcol=0;
-         wmove(form->w,form->currow,form->curcol);
+         form->curcol = 0;
+         wmove(form->w, form->currow, form->curcol);
          winsertln(form->w);
          winsertln(form->w);
-         waddnstr(form->w,bp,(int)(t-bp));
-         form->status |= _WINDOW_MODIFIED;
-         return E_OK;
+         myADDNSTR(form->w, bp, (int)(t - bp));
+         SetStatus(form, _WINDOW_MODIFIED);
+         returnCode(E_OK);
        }
     }
 }
 
 /*---------------------------------------------------------------------------
        }
     }
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FE_Insert_Character(FORM * form)
 |   Function      :  static int FE_Insert_Character(FORM * form)
-|   
+|
 |   Description   :  Insert blank character at the cursor position
 |
 |   Return Values :  E_OK
 |                    E_REQUEST_DENIED
 +--------------------------------------------------------------------------*/
 |   Description   :  Insert blank character at the cursor position
 |
 |   Return Values :  E_OK
 |                    E_REQUEST_DENIED
 +--------------------------------------------------------------------------*/
-static int FE_Insert_Character(FORM * form)
+static int
+FE_Insert_Character(FORM *form)
 {
   FIELD *field = form->current;
   int result = E_REQUEST_DENIED;
 
 {
   FIELD *field = form->current;
   int result = E_REQUEST_DENIED;
 
-  if (Check_Char(field->type,(int)C_BLANK,(TypeArgument *)(field->arg)))
+  T((T_CALLED("FE_Insert_Character(%p)"), (void *)form));
+  if (Check_Char(form, field, field->type, (int)C_BLANK,
+                (TypeArgument *)(field->arg)))
     {
       bool There_Is_Room = Is_There_Room_For_A_Char_In_Line(form);
 
       if (There_Is_Room ||
          ((Single_Line_Field(field) && Growable(field))))
        {
     {
       bool There_Is_Room = Is_There_Room_For_A_Char_In_Line(form);
 
       if (There_Is_Room ||
          ((Single_Line_Field(field) && Growable(field))))
        {
-         if (!There_Is_Room && !Field_Grown(field,1))
-           result =  E_SYSTEM_ERROR;
+         if (!There_Is_Room && !Field_Grown(field, 1))
+           result = E_SYSTEM_ERROR;
          else
            {
          else
            {
-             winsch(form->w,(chtype)C_BLANK);
+             winsch(form->w, (chtype)C_BLANK);
              result = Wrapping_Not_Necessary_Or_Wrapping_Ok(form);
            }
        }
     }
              result = Wrapping_Not_Necessary_Or_Wrapping_Ok(form);
            }
        }
     }
-  return result;
+  returnCode(result);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FE_Insert_Line(FORM * form)
 |   Function      :  static int FE_Insert_Line(FORM * form)
-|   
+|
 |   Description   :  Insert a blank line at the cursor position
 |
 |   Return Values :  E_OK               - success
 |                    E_REQUEST_DENIED   - line can not be inserted
 +--------------------------------------------------------------------------*/
 |   Description   :  Insert a blank line at the cursor position
 |
 |   Return Values :  E_OK               - success
 |                    E_REQUEST_DENIED   - line can not be inserted
 +--------------------------------------------------------------------------*/
-static int FE_Insert_Line(FORM * form)
+static int
+FE_Insert_Line(FORM *form)
 {
   FIELD *field = form->current;
   int result = E_REQUEST_DENIED;
 
 {
   FIELD *field = form->current;
   int result = E_REQUEST_DENIED;
 
-  if (Check_Char(field->type,(int)C_BLANK,(TypeArgument *)(field->arg)))
+  T((T_CALLED("FE_Insert_Line(%p)"), (void *)form));
+  if (Check_Char(form, field,
+                field->type, (int)C_BLANK, (TypeArgument *)(field->arg)))
     {
     {
-      bool Maybe_Done = (form->currow!=(field->drows-1)) && 
-                       Is_There_Room_For_A_Line(form);
+      bool Maybe_Done = (form->currow != (field->drows - 1)) &&
+      Is_There_Room_For_A_Line(form);
 
       if (!Single_Line_Field(field) &&
          (Maybe_Done || Growable(field)))
        {
 
       if (!Single_Line_Field(field) &&
          (Maybe_Done || Growable(field)))
        {
-         if (!Maybe_Done && !Field_Grown(field,1))
+         if (!Maybe_Done && !Field_Grown(field, 1))
            result = E_SYSTEM_ERROR;
          else
            {
            result = E_SYSTEM_ERROR;
          else
            {
@@ -2325,27 +2769,29 @@ static int FE_Insert_Line(FORM * form)
            }
        }
     }
            }
        }
     }
-  return result;
+  returnCode(result);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FE_Delete_Character(FORM * form)
 |   Function      :  static int FE_Delete_Character(FORM * form)
-|   
+|
 |   Description   :  Delete character at the cursor position
 |
 |   Return Values :  E_OK    - success
 +--------------------------------------------------------------------------*/
 |   Description   :  Delete character at the cursor position
 |
 |   Return Values :  E_OK    - success
 +--------------------------------------------------------------------------*/
-static int FE_Delete_Character(FORM * form)
+static int
+FE_Delete_Character(FORM *form)
 {
 {
-  wdelch(form->w);
-  return E_OK;
+  T((T_CALLED("FE_Delete_Character(%p)"), (void *)form));
+  DeleteChar(form);
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FE_Delete_Previous(FORM * form)
 |   Function      :  static int FE_Delete_Previous(FORM * form)
-|   
+|
 |   Description   :  Delete character before cursor. Again this is a rather
 |                    difficult piece compared to others due to the overloading
 |                    semantics of backspace.
 |   Description   :  Delete character before cursor. Again this is a rather
 |                    difficult piece compared to others due to the overloading
 |                    semantics of backspace.
@@ -2355,301 +2801,369 @@ static int FE_Delete_Character(FORM * form)
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - Character can't be deleted
 +--------------------------------------------------------------------------*/
 |   Return Values :  E_OK                - success
 |                    E_REQUEST_DENIED    - Character can't be deleted
 +--------------------------------------------------------------------------*/
-static int FE_Delete_Previous(FORM * form)
+static int
+FE_Delete_Previous(FORM *form)
 {
 {
-  FIELD  *field = form->current;
-  
+  FIELD *field = form->current;
+
+  T((T_CALLED("FE_Delete_Previous(%p)"), (void *)form));
   if (First_Position_In_Current_Field(form))
   if (First_Position_In_Current_Field(form))
-    return E_REQUEST_DENIED;
+    returnCode(E_REQUEST_DENIED);
 
 
-  if ( (--(form->curcol))<0 )
+  if ((--(form->curcol)) < 0)
     {
     {
-      char *this_line, *prev_line, *prev_end, *this_end;
-      
+      FIELD_CELL *this_line, *prev_line, *prev_end, *this_end;
+      int this_row = form->currow;
+
       form->curcol++;
       form->curcol++;
-      if (form->status & _OVLMODE) 
-       return E_REQUEST_DENIED;
-      
-      prev_line = Address_Of_Row_In_Buffer(field,(form->currow-1));
-      this_line = Address_Of_Row_In_Buffer(field,(form->currow));
+      if (form->status & _OVLMODE)
+       returnCode(E_REQUEST_DENIED);
+
+      prev_line = Address_Of_Row_In_Buffer(field, (form->currow - 1));
+      this_line = Address_Of_Row_In_Buffer(field, (form->currow));
       Synchronize_Buffer(form);
       Synchronize_Buffer(form);
-      prev_end = After_End_Of_Data(prev_line,field->dcols);
-      this_end = After_End_Of_Data(this_line,field->dcols);
-      if ((int)(this_end-this_line) > 
-         (field->cols-(int)(prev_end-prev_line))) 
-       return E_REQUEST_DENIED;
+      prev_end = After_End_Of_Data(prev_line, field->dcols);
+      this_end = After_End_Of_Data(this_line, field->dcols);
+      if ((int)(this_end - this_line) >
+         (field->cols - (int)(prev_end - prev_line)))
+       returnCode(E_REQUEST_DENIED);
+      wmove(form->w, form->currow, form->curcol);
       wdeleteln(form->w);
       wdeleteln(form->w);
-      Adjust_Cursor_Position(form,prev_end);
-      wmove(form->w,form->currow,form->curcol);
-      waddnstr(form->w,this_line,(int)(this_end-this_line));
-    } 
-  else 
+      Adjust_Cursor_Position(form, prev_end);
+      /*
+       * If we did not really move to the previous line, help the user a
+       * little.  It is however a little inconsistent.  Normally, when
+       * backspacing around the point where text wraps to a new line in a
+       * multi-line form, we absorb one keystroke for the wrapping point.  That
+       * is consistent with SVr4 forms.  However, SVr4 does not allow typing
+       * into the last column of the field, and requires the user to enter a
+       * newline to move to the next line.  Therefore it can consistently eat
+       * that keystroke.  Since ncurses allows the last column, it wraps
+       * automatically (given the proper options).  But we cannot eat the
+       * keystroke to back over the wrapping point, since that would put the
+       * cursor past the end of the form field.  In this case, just delete the
+       * character at the end of the field.
+       */
+      if (form->currow == this_row && this_row > 0)
+       {
+         form->currow -= 1;
+         form->curcol = field->dcols - 1;
+         DeleteChar(form);
+       }
+      else
+       {
+         wmove(form->w, form->currow, form->curcol);
+         myADDNSTR(form->w, this_line, (int)(this_end - this_line));
+       }
+    }
+  else
     {
     {
-      wmove(form->w,form->currow,form->curcol);
-      wdelch(form->w);
+      DeleteChar(form);
     }
     }
-  return E_OK;
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FE_Delete_Line(FORM * form)
 |   Function      :  static int FE_Delete_Line(FORM * form)
-|   
+|
 |   Description   :  Delete line at cursor position.
 |
 |   Return Values :  E_OK  - success
 +--------------------------------------------------------------------------*/
 |   Description   :  Delete line at cursor position.
 |
 |   Return Values :  E_OK  - success
 +--------------------------------------------------------------------------*/
-static int FE_Delete_Line(FORM * form)
+static int
+FE_Delete_Line(FORM *form)
 {
 {
+  T((T_CALLED("FE_Delete_Line(%p)"), (void *)form));
   form->curcol = 0;
   wdeleteln(form->w);
   form->curcol = 0;
   wdeleteln(form->w);
-  return E_OK;
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FE_Delete_Word(FORM * form)
 |   Function      :  static int FE_Delete_Word(FORM * form)
-|   
+|
 |   Description   :  Delete word at cursor position
 |
 |   Return Values :  E_OK               - success
 |                    E_REQUEST_DENIED   - failure
 +--------------------------------------------------------------------------*/
 |   Description   :  Delete word at cursor position
 |
 |   Return Values :  E_OK               - success
 |                    E_REQUEST_DENIED   - failure
 +--------------------------------------------------------------------------*/
-static int FE_Delete_Word(FORM * form)
+static int
+FE_Delete_Word(FORM *form)
 {
 {
-  FIELD  *field = form->current;
-  char   *bp = Address_Of_Current_Row_In_Buffer(form);
-  char   *ep = bp + field->dcols;
-  char   *cp = bp + form->curcol;
-  char *s;
-  
+  FIELD *field = form->current;
+  FIELD_CELL *bp = Address_Of_Current_Row_In_Buffer(form);
+  FIELD_CELL *ep = bp + field->dcols;
+  FIELD_CELL *cp = bp + form->curcol;
+  FIELD_CELL *s;
+
+  T((T_CALLED("FE_Delete_Word(%p)"), (void *)form));
   Synchronize_Buffer(form);
   Synchronize_Buffer(form);
-  if (is_blank(*cp)) 
-    return E_REQUEST_DENIED; /* not in word */
+  if (ISBLANK(*cp))
+    returnCode(E_REQUEST_DENIED);      /* not in word */
 
   /* move cursor to begin of word and erase to end of screen-line */
   Adjust_Cursor_Position(form,
 
   /* move cursor to begin of word and erase to end of screen-line */
   Adjust_Cursor_Position(form,
-                        After_Last_Whitespace_Character(bp,form->curcol)); 
-  wmove(form->w,form->currow,form->curcol);
+                        After_Last_Whitespace_Character(bp, form->curcol));
+  wmove(form->w, form->currow, form->curcol);
   wclrtoeol(form->w);
 
   /* skip over word in buffer */
   wclrtoeol(form->w);
 
   /* skip over word in buffer */
-  s = Get_First_Whitespace_Character(cp,(int)(ep-cp)); 
+  s = Get_First_Whitespace_Character(cp, (int)(ep - cp));
   /* to begin of next word    */
   /* to begin of next word    */
-  s = Get_Start_Of_Data(s,(int)(ep - s));
-  if ( (s!=cp) && !is_blank(*s))
+  s = Get_Start_Of_Data(s, (int)(ep - s));
+  if ((s != cp) && !ISBLANK(*s))
     {
       /* copy remaining line to window */
     {
       /* copy remaining line to window */
-      waddnstr(form->w,s,(int)(s - After_End_Of_Data(s,(int)(ep - s))));
+      myADDNSTR(form->w, s, (int)(s - After_End_Of_Data(s, (int)(ep - s))));
     }
     }
-  return E_OK;
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FE_Clear_To_End_Of_Line(FORM * form)
 |   Function      :  static int FE_Clear_To_End_Of_Line(FORM * form)
-|   
+|
 |   Description   :  Clear to end of current line.
 |
 |   Return Values :  E_OK   - success
 +--------------------------------------------------------------------------*/
 |   Description   :  Clear to end of current line.
 |
 |   Return Values :  E_OK   - success
 +--------------------------------------------------------------------------*/
-static int FE_Clear_To_End_Of_Line(FORM * form)
+static int
+FE_Clear_To_End_Of_Line(FORM *form)
 {
 {
+  T((T_CALLED("FE_Clear_To_End_Of_Line(%p)"), (void *)form));
+  wmove(form->w, form->currow, form->curcol);
   wclrtoeol(form->w);
   wclrtoeol(form->w);
-  return E_OK;
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
-|   Function      :  static int FE_Clear_To_End_Of_Form(FORM * form)
-|   
-|   Description   :  Clear to end of form.
+|   Facility      :  libnform
+|   Function      :  static int FE_Clear_To_End_Of_Field(FORM * form)
+|
+|   Description   :  Clear to end of field.
 |
 |   Return Values :  E_OK   - success
 +--------------------------------------------------------------------------*/
 |
 |   Return Values :  E_OK   - success
 +--------------------------------------------------------------------------*/
-static int FE_Clear_To_End_Of_Form(FORM * form)
+static int
+FE_Clear_To_End_Of_Field(FORM *form)
 {
 {
+  T((T_CALLED("FE_Clear_To_End_Of_Field(%p)"), (void *)form));
+  wmove(form->w, form->currow, form->curcol);
   wclrtobot(form->w);
   wclrtobot(form->w);
-  return E_OK;
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FE_Clear_Field(FORM * form)
 |   Function      :  static int FE_Clear_Field(FORM * form)
-|   
+|
 |   Description   :  Clear entire field.
 |
 |   Return Values :  E_OK   - success
 +--------------------------------------------------------------------------*/
 |   Description   :  Clear entire field.
 |
 |   Return Values :  E_OK   - success
 +--------------------------------------------------------------------------*/
-static int FE_Clear_Field(FORM * form)
+static int
+FE_Clear_Field(FORM *form)
 {
 {
+  T((T_CALLED("FE_Clear_Field(%p)"), (void *)form));
   form->currow = form->curcol = 0;
   werase(form->w);
   form->currow = form->curcol = 0;
   werase(form->w);
-  return E_OK;
+  returnCode(E_OK);
 }
 /*----------------------------------------------------------------------------
 }
 /*----------------------------------------------------------------------------
-  END of Field Editing routines 
+  END of Field Editing routines
   --------------------------------------------------------------------------*/
   --------------------------------------------------------------------------*/
-\f
+
 /*----------------------------------------------------------------------------
   Edit Mode routines
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
 /*----------------------------------------------------------------------------
   Edit Mode routines
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int EM_Overlay_Mode(FORM * form)
 |   Function      :  static int EM_Overlay_Mode(FORM * form)
-|   
+|
 |   Description   :  Switch to overlay mode.
 |
 |   Return Values :  E_OK   - success
 +--------------------------------------------------------------------------*/
 |   Description   :  Switch to overlay mode.
 |
 |   Return Values :  E_OK   - success
 +--------------------------------------------------------------------------*/
-static int EM_Overlay_Mode(FORM * form)
+static int
+EM_Overlay_Mode(FORM *form)
 {
 {
-  form->status |= _OVLMODE;
-  return E_OK;
+  T((T_CALLED("EM_Overlay_Mode(%p)"), (void *)form));
+  SetStatus(form, _OVLMODE);
+  returnCode(E_OK);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int EM_Insert_Mode(FORM * form)
 |   Function      :  static int EM_Insert_Mode(FORM * form)
-|   
+|
 |   Description   :  Switch to insert mode
 |
 |   Return Values :  E_OK   - success
 +--------------------------------------------------------------------------*/
 |   Description   :  Switch to insert mode
 |
 |   Return Values :  E_OK   - success
 +--------------------------------------------------------------------------*/
-static int EM_Insert_Mode(FORM * form)
+static int
+EM_Insert_Mode(FORM *form)
 {
 {
-  form->status &= ~_OVLMODE;
-  return E_OK;
+  T((T_CALLED("EM_Insert_Mode(%p)"), (void *)form));
+  ClrStatus(form, _OVLMODE);
+  returnCode(E_OK);
 }
 
 /*----------------------------------------------------------------------------
 }
 
 /*----------------------------------------------------------------------------
-  END of Edit Mode routines 
+  END of Edit Mode routines
   --------------------------------------------------------------------------*/
   --------------------------------------------------------------------------*/
-\f
+
 /*----------------------------------------------------------------------------
   Helper routines for Choice Requests
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
 /*----------------------------------------------------------------------------
   Helper routines for Choice Requests
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
-|   Function      :  static bool Next_Choice(
+|   Facility      :  libnform
+|   Function      :  static bool Next_Choice(FORM * form,
 |                                            FIELDTYPE * typ,
 |                                            FIELD * field,
 |                                            TypeArgument *argp)
 |                                            FIELDTYPE * typ,
 |                                            FIELD * field,
 |                                            TypeArgument *argp)
-|   
+|
 |   Description   :  Get the next field choice. For linked types this is
 |                    done recursively.
 |
 |   Return Values :  TRUE    - next choice successfully retrieved
 |                    FALSE   - couldn't retrieve next choice
 +--------------------------------------------------------------------------*/
 |   Description   :  Get the next field choice. For linked types this is
 |                    done recursively.
 |
 |   Return Values :  TRUE    - next choice successfully retrieved
 |                    FALSE   - couldn't retrieve next choice
 +--------------------------------------------------------------------------*/
-static bool Next_Choice(FIELDTYPE * typ, FIELD *field, TypeArgument *argp)
+static bool
+Next_Choice(FORM *form, FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
 {
 {
-  if (!typ || !(typ->status & _HAS_CHOICE)) 
+  if (!typ || !(typ->status & _HAS_CHOICE))
     return FALSE;
 
   if (typ->status & _LINKED_TYPE)
     {
       assert(argp);
     return FALSE;
 
   if (typ->status & _LINKED_TYPE)
     {
       assert(argp);
-      return(
-            Next_Choice(typ->left ,field,argp->left) ||
-            Next_Choice(typ->right,field,argp->right) );
-    } 
+      return (
+              Next_Choice(form, typ->left, field, argp->left) ||
+              Next_Choice(form, typ->right, field, argp->right));
+    }
   else
     {
   else
     {
+#if NCURSES_INTEROP_FUNCS
+      assert(typ->enum_next.onext);
+      if (typ->status & _GENERIC)
+       return typ->enum_next.gnext(form, field, (void *)argp);
+      else
+       return typ->enum_next.onext(field, (void *)argp);
+#else
       assert(typ->next);
       assert(typ->next);
-      return typ->next(field,(void *)argp);
+      return typ->next(field, (void *)argp);
+#endif
     }
 }
 
 /*---------------------------------------------------------------------------
     }
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
-|   Function      :  static bool Previous_Choice(
+|   Facility      :  libnform
+|   Function      :  static bool Previous_Choice(FORM * form,
 |                                                FIELDTYPE * typ,
 |                                                FIELD * field,
 |                                                TypeArgument *argp)
 |                                                FIELDTYPE * typ,
 |                                                FIELD * field,
 |                                                TypeArgument *argp)
-|   
+|
 |   Description   :  Get the previous field choice. For linked types this
 |                    is done recursively.
 |
 |   Return Values :  TRUE    - previous choice successfully retrieved
 |                    FALSE   - couldn't retrieve previous choice
 +--------------------------------------------------------------------------*/
 |   Description   :  Get the previous field choice. For linked types this
 |                    is done recursively.
 |
 |   Return Values :  TRUE    - previous choice successfully retrieved
 |                    FALSE   - couldn't retrieve previous choice
 +--------------------------------------------------------------------------*/
-static bool Previous_Choice(FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
+static bool
+Previous_Choice(FORM *form, FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
 {
 {
-  if (!typ || !(typ->status & _HAS_CHOICE)) 
+  if (!typ || !(typ->status & _HAS_CHOICE))
     return FALSE;
 
   if (typ->status & _LINKED_TYPE)
     {
       assert(argp);
     return FALSE;
 
   if (typ->status & _LINKED_TYPE)
     {
       assert(argp);
-      return(
-            Previous_Choice(typ->left ,field,argp->left) ||
-            Previous_Choice(typ->right,field,argp->right));
-    } 
-  else 
+      return (
+              Previous_Choice(form, typ->left, field, argp->left) ||
+              Previous_Choice(form, typ->right, field, argp->right));
+    }
+  else
     {
     {
+#if NCURSES_INTEROP_FUNCS
+      assert(typ->enum_prev.oprev);
+      if (typ->status & _GENERIC)
+       return typ->enum_prev.gprev(form, field, (void *)argp);
+      else
+       return typ->enum_prev.oprev(field, (void *)argp);
+#else
       assert(typ->prev);
       assert(typ->prev);
-      return typ->prev(field,(void *)argp);
+      return typ->prev(field, (void *)argp);
+#endif
     }
 }
 /*----------------------------------------------------------------------------
   End of Helper routines for Choice Requests
   --------------------------------------------------------------------------*/
     }
 }
 /*----------------------------------------------------------------------------
   End of Helper routines for Choice Requests
   --------------------------------------------------------------------------*/
-\f
+
 /*----------------------------------------------------------------------------
   Routines for Choice Requests
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
 /*----------------------------------------------------------------------------
   Routines for Choice Requests
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int CR_Next_Choice(FORM * form)
 |   Function      :  static int CR_Next_Choice(FORM * form)
-|   
+|
 |   Description   :  Get the next field choice.
 |
 |   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - next choice couldn't be retrieved
 +--------------------------------------------------------------------------*/
 |   Description   :  Get the next field choice.
 |
 |   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - next choice couldn't be retrieved
 +--------------------------------------------------------------------------*/
-static int CR_Next_Choice(FORM * form)
+static int
+CR_Next_Choice(FORM *form)
 {
   FIELD *field = form->current;
 {
   FIELD *field = form->current;
+
+  T((T_CALLED("CR_Next_Choice(%p)"), (void *)form));
   Synchronize_Buffer(form);
   Synchronize_Buffer(form);
-  return ((Next_Choice(field->type,field,(TypeArgument *)(field->arg))) ? 
-         E_OK : E_REQUEST_DENIED);
+  returnCode((Next_Choice(form, field->type, field, (TypeArgument *)(field->arg)))
+            ? E_OK
+            : E_REQUEST_DENIED);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int CR_Previous_Choice(FORM * form)
 |   Function      :  static int CR_Previous_Choice(FORM * form)
-|   
+|
 |   Description   :  Get the previous field choice.
 |
 |   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - prev. choice couldn't be retrieved
 +--------------------------------------------------------------------------*/
 |   Description   :  Get the previous field choice.
 |
 |   Return Values :  E_OK              - success
 |                    E_REQUEST_DENIED  - prev. choice couldn't be retrieved
 +--------------------------------------------------------------------------*/
-static int CR_Previous_Choice(FORM * form)
+static int
+CR_Previous_Choice(FORM *form)
 {
   FIELD *field = form->current;
 {
   FIELD *field = form->current;
+
+  T((T_CALLED("CR_Previous_Choice(%p)"), (void *)form));
   Synchronize_Buffer(form);
   Synchronize_Buffer(form);
-  return ((Previous_Choice(field->type,field,(TypeArgument *)(field->arg))) ? 
-         E_OK : E_REQUEST_DENIED);
+  returnCode((Previous_Choice(form, field->type, field, (TypeArgument *)(field->arg)))
+            ? E_OK
+            : E_REQUEST_DENIED);
 }
 /*----------------------------------------------------------------------------
   End of Routines for Choice Requests
   --------------------------------------------------------------------------*/
 }
 /*----------------------------------------------------------------------------
   End of Routines for Choice Requests
   --------------------------------------------------------------------------*/
-\f
+
 /*----------------------------------------------------------------------------
   Helper routines for Field Validations.
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
 /*----------------------------------------------------------------------------
   Helper routines for Field Validations.
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
-|   Function      :  static bool Check_Field(
+|   Facility      :  libnform
+|   Function      :  static bool Check_Field(FORM* form,
 |                                            FIELDTYPE * typ,
 |                                            FIELD * field,
 |                                            TypeArgument * argp)
 |                                            FIELDTYPE * typ,
 |                                            FIELD * field,
 |                                            TypeArgument * argp)
-|   
+|
 |   Description   :  Check the field according to its fieldtype and its
 |                    actual arguments. For linked fieldtypes this is done
 |                    recursively.
 |   Description   :  Check the field according to its fieldtype and its
 |                    actual arguments. For linked fieldtypes this is done
 |                    recursively.
@@ -2657,60 +3171,74 @@ static int CR_Previous_Choice(FORM * form)
 |   Return Values :  TRUE       - field is valid
 |                    FALSE      - field is invalid.
 +--------------------------------------------------------------------------*/
 |   Return Values :  TRUE       - field is valid
 |                    FALSE      - field is invalid.
 +--------------------------------------------------------------------------*/
-static bool Check_Field(FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
+static bool
+Check_Field(FORM *form, FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
 {
   if (typ)
     {
 {
   if (typ)
     {
-      if (field->opts & O_NULLOK)
+      if (Field_Has_Option(field, O_NULLOK))
        {
        {
-         char *bp = field->buf;
+         FIELD_CELL *bp = field->buf;
+
          assert(bp);
          assert(bp);
-         while(is_blank(*bp))
-           { bp++; }
-         if (*bp == '\0') 
+         while (ISBLANK(*bp))
+           {
+             bp++;
+           }
+         if (CharOf(*bp) == 0)
            return TRUE;
        }
 
       if (typ->status & _LINKED_TYPE)
        {
          assert(argp);
            return TRUE;
        }
 
       if (typ->status & _LINKED_TYPE)
        {
          assert(argp);
-         return
-                Check_Field(typ->left ,field,argp->left ) ||
-                Check_Field(typ->right,field,argp->right) );
+         return (
+                  Check_Field(form, typ->left, field, argp->left) ||
+                  Check_Field(form, typ->right, field, argp->right));
        }
        }
-      else 
+      else
        {
        {
+#if NCURSES_INTEROP_FUNCS
+         if (typ->fieldcheck.ofcheck)
+           {
+             if (typ->status & _GENERIC)
+               return typ->fieldcheck.gfcheck(form, field, (void *)argp);
+             else
+               return typ->fieldcheck.ofcheck(field, (void *)argp);
+           }
+#else
          if (typ->fcheck)
          if (typ->fcheck)
-           return typ->fcheck(field,(void *)argp);
+           return typ->fcheck(field, (void *)argp);
+#endif
        }
     }
   return TRUE;
 }
 
 /*---------------------------------------------------------------------------
        }
     }
   return TRUE;
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  bool _nc_Internal_Validation(FORM * form )
 |   Function      :  bool _nc_Internal_Validation(FORM * form )
-|   
-|   Description   :  Validate the current field of the form.  
+|
+|   Description   :  Validate the current field of the form.
 |
 |   Return Values :  TRUE  - field is valid
 |                    FALSE - field is invalid
 +--------------------------------------------------------------------------*/
 NCURSES_EXPORT(bool)
 |
 |   Return Values :  TRUE  - field is valid
 |                    FALSE - field is invalid
 +--------------------------------------------------------------------------*/
 NCURSES_EXPORT(bool)
-_nc_Internal_Validation (FORM *form)
+_nc_Internal_Validation(FORM *form)
 {
   FIELD *field;
 
 {
   FIELD *field;
 
-  field = form->current; 
-  
+  field = form->current;
+
   Synchronize_Buffer(form);
   if ((form->status & _FCHECK_REQUIRED) ||
   Synchronize_Buffer(form);
   if ((form->status & _FCHECK_REQUIRED) ||
-      (!(field->opts & O_PASSOK)))
+      (!(Field_Has_Option(field, O_PASSOK))))
     {
     {
-      if (!Check_Field(field->type,field,(TypeArgument *)(field->arg)))
+      if (!Check_Field(form, field->type, field, (TypeArgument *)(field->arg)))
        return FALSE;
        return FALSE;
-      form->status  &= ~_FCHECK_REQUIRED;
-      field->status |= _CHANGED;
+      ClrStatus(form, _FCHECK_REQUIRED);
+      SetStatus(field, _CHANGED);
       Synchronize_Linked_Fields(field);
     }
   return TRUE;
       Synchronize_Linked_Fields(field);
     }
   return TRUE;
@@ -2718,67 +3246,71 @@ _nc_Internal_Validation (FORM *form)
 /*----------------------------------------------------------------------------
   End of Helper routines for Field Validations.
   --------------------------------------------------------------------------*/
 /*----------------------------------------------------------------------------
   End of Helper routines for Field Validations.
   --------------------------------------------------------------------------*/
-\f
+
 /*----------------------------------------------------------------------------
   Routines for Field Validation.
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
 /*----------------------------------------------------------------------------
   Routines for Field Validation.
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FV_Validation(FORM * form)
 |   Function      :  static int FV_Validation(FORM * form)
-|   
+|
 |   Description   :  Validate the current field of the form.
 |
 |   Return Values :  E_OK             - field valid
 |                    E_INVALID_FIELD  - field not valid
 +--------------------------------------------------------------------------*/
 |   Description   :  Validate the current field of the form.
 |
 |   Return Values :  E_OK             - field valid
 |                    E_INVALID_FIELD  - field not valid
 +--------------------------------------------------------------------------*/
-static int FV_Validation(FORM * form)
+static int
+FV_Validation(FORM *form)
 {
 {
+  T((T_CALLED("FV_Validation(%p)"), (void *)form));
   if (_nc_Internal_Validation(form))
   if (_nc_Internal_Validation(form))
-    return E_OK;
+    returnCode(E_OK);
   else
   else
-    return E_INVALID_FIELD;
+    returnCode(E_INVALID_FIELD);
 }
 /*----------------------------------------------------------------------------
   End of routines for Field Validation.
   --------------------------------------------------------------------------*/
 }
 /*----------------------------------------------------------------------------
   End of routines for Field Validation.
   --------------------------------------------------------------------------*/
-\f
+
 /*----------------------------------------------------------------------------
   Helper routines for Inter-Field Navigation
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
 /*----------------------------------------------------------------------------
   Helper routines for Inter-Field Navigation
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static FIELD *Next_Field_On_Page(FIELD * field)
 |   Function      :  static FIELD *Next_Field_On_Page(FIELD * field)
-|   
-|   Description   :  Get the next field after the given field on the current 
+|
+|   Description   :  Get the next field after the given field on the current
 |                    page. The order of fields is the one defined by the
 |                    fields array. Only visible and active fields are
 |                    counted.
 |
 |   Return Values :  Pointer to the next field.
 +--------------------------------------------------------------------------*/
 |                    page. The order of fields is the one defined by the
 |                    fields array. Only visible and active fields are
 |                    counted.
 |
 |   Return Values :  Pointer to the next field.
 +--------------------------------------------------------------------------*/
-INLINE static FIELD *Next_Field_On_Page(FIELD * field)
+NCURSES_INLINE static FIELD *
+Next_Field_On_Page(FIELD *field)
 {
 {
-  FORM  *form = field->form;
+  FORM *form = field->form;
   FIELD **field_on_page = &form->field[field->index];
   FIELD **first_on_page = &form->field[form->page[form->curpage].pmin];
   FIELD **field_on_page = &form->field[field->index];
   FIELD **first_on_page = &form->field[form->page[form->curpage].pmin];
-  FIELD **last_on_page  = &form->field[form->page[form->curpage].pmax];
+  FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
 
   do
     {
 
   do
     {
-      field_on_page = 
-       (field_on_page==last_on_page) ? first_on_page : field_on_page + 1;
+      field_on_page =
+       (field_on_page == last_on_page) ? first_on_page : field_on_page + 1;
       if (Field_Is_Selectable(*field_on_page))
        break;
       if (Field_Is_Selectable(*field_on_page))
        break;
-    } while(field!=(*field_on_page));  
-  return(*field_on_page);
+    }
+  while (field != (*field_on_page));
+  return (*field_on_page);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  FIELD* _nc_First_Active_Field(FORM * form)
 |   Function      :  FIELD* _nc_First_Active_Field(FORM * form)
-|   
+|
 |   Description   :  Get the first active field on the current page,
 |                    if there are such. If there are none, get the first
 |                    visible field on the page. If there are also none,
 |   Description   :  Get the first active field on the current page,
 |                    if there are such. If there are none, get the first
 |                    visible field on the page. If there are also none,
@@ -2786,17 +3318,18 @@ INLINE static FIELD *Next_Field_On_Page(FIELD * field)
 |
 |   Return Values :  Pointer to calculated field.
 +--------------------------------------------------------------------------*/
 |
 |   Return Values :  Pointer to calculated field.
 +--------------------------------------------------------------------------*/
-NCURSES_EXPORT(FIELD*)
-_nc_First_Active_Field (FORM * form)
+NCURSES_EXPORT(FIELD *)
+_nc_First_Active_Field(FORM *form)
 {
   FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
   FIELD *proposed = Next_Field_On_Page(*last_on_page);
 
   if (proposed == *last_on_page)
 {
   FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
   FIELD *proposed = Next_Field_On_Page(*last_on_page);
 
   if (proposed == *last_on_page)
-    { /* there might be the special situation, where there is no 
-        active and visible field on the current page. We then select
-        the first visible field on this readonly page
-      */
+    {
+      /* there might be the special situation, where there is no
+         active and visible field on the current page. We then select
+         the first visible field on this readonly page
+       */
       if (Field_Is_Not_Selectable(proposed))
        {
          FIELD **field = &form->field[proposed->index];
       if (Field_Is_Not_Selectable(proposed))
        {
          FIELD **field = &form->field[proposed->index];
@@ -2804,66 +3337,72 @@ _nc_First_Active_Field (FORM * form)
 
          do
            {
 
          do
            {
-             field = (field==last_on_page) ? first : field + 1;
-             if (((*field)->opts & O_VISIBLE))
+             field = (field == last_on_page) ? first : field + 1;
+             if (Field_Has_Option(*field, O_VISIBLE))
                break;
                break;
-           } while(proposed!=(*field));
-         
+           }
+         while (proposed != (*field));
+
          proposed = *field;
 
          proposed = *field;
 
-         if ((proposed == *last_on_page) && !(proposed->opts&O_VISIBLE))
-           { /* This means, there is also no visible field on the page.
-                So we propose the first one and hope the very best... 
-                Some very clever user has designed a readonly and invisible
-                page on this form.
+         if ((proposed == *last_on_page) &&
+             !((unsigned)proposed->opts & O_VISIBLE))
+           {
+             /* This means, there is also no visible field on the page.
+                So we propose the first one and hope the very best...
+                Some very clever user has designed a readonly and invisible
+                page on this form.
               */
              proposed = *first;
            }
        }
     }
               */
              proposed = *first;
            }
        }
     }
-  return(proposed);
+  return (proposed);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static FIELD *Previous_Field_On_Page(FIELD * field)
 |   Function      :  static FIELD *Previous_Field_On_Page(FIELD * field)
-|   
-|   Description   :  Get the previous field before the given field on the 
-|                    current page. The order of fields is the one defined by 
+|
+|   Description   :  Get the previous field before the given field on the
+|                    current page. The order of fields is the one defined by
 |                    the fields array. Only visible and active fields are
 |                    counted.
 |
 |   Return Values :  Pointer to the previous field.
 +--------------------------------------------------------------------------*/
 |                    the fields array. Only visible and active fields are
 |                    counted.
 |
 |   Return Values :  Pointer to the previous field.
 +--------------------------------------------------------------------------*/
-INLINE static FIELD *Previous_Field_On_Page(FIELD * field)
+NCURSES_INLINE static FIELD *
+Previous_Field_On_Page(FIELD *field)
 {
 {
-  FORM  *form   = field->form;
+  FORM *form = field->form;
   FIELD **field_on_page = &form->field[field->index];
   FIELD **first_on_page = &form->field[form->page[form->curpage].pmin];
   FIELD **field_on_page = &form->field[field->index];
   FIELD **first_on_page = &form->field[form->page[form->curpage].pmin];
-  FIELD **last_on_page  = &form->field[form->page[form->curpage].pmax];
-  
+  FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
+
   do
     {
   do
     {
-      field_on_page = 
-       (field_on_page==first_on_page) ? last_on_page : field_on_page - 1;
+      field_on_page =
+       (field_on_page == first_on_page) ? last_on_page : field_on_page - 1;
       if (Field_Is_Selectable(*field_on_page))
        break;
       if (Field_Is_Selectable(*field_on_page))
        break;
-    } while(field!=(*field_on_page));
-  
+    }
+  while (field != (*field_on_page));
+
   return (*field_on_page);
 }
 
 /*---------------------------------------------------------------------------
   return (*field_on_page);
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static FIELD *Sorted_Next_Field(FIELD * field)
 |   Function      :  static FIELD *Sorted_Next_Field(FIELD * field)
-|   
-|   Description   :  Get the next field after the given field on the current 
+|
+|   Description   :  Get the next field after the given field on the current
 |                    page. The order of fields is the one defined by the
 |                    (row,column) geometry, rows are major.
 |
 |   Return Values :  Pointer to the next field.
 +--------------------------------------------------------------------------*/
 |                    page. The order of fields is the one defined by the
 |                    (row,column) geometry, rows are major.
 |
 |   Return Values :  Pointer to the next field.
 +--------------------------------------------------------------------------*/
-INLINE static FIELD *Sorted_Next_Field(FIELD * field)
+NCURSES_INLINE static FIELD *
+Sorted_Next_Field(FIELD *field)
 {
   FIELD *field_on_page = field;
 
 {
   FIELD *field_on_page = field;
 
@@ -2872,22 +3411,24 @@ INLINE static FIELD *Sorted_Next_Field(FIELD * field)
       field_on_page = field_on_page->snext;
       if (Field_Is_Selectable(field_on_page))
        break;
       field_on_page = field_on_page->snext;
       if (Field_Is_Selectable(field_on_page))
        break;
-    } while(field_on_page!=field);
-  
+    }
+  while (field_on_page != field);
+
   return (field_on_page);
 }
 
 /*---------------------------------------------------------------------------
   return (field_on_page);
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static FIELD *Sorted_Previous_Field(FIELD * field)
 |   Function      :  static FIELD *Sorted_Previous_Field(FIELD * field)
-|   
-|   Description   :  Get the previous field before the given field on the 
-|                    current page. The order of fields is the one defined 
+|
+|   Description   :  Get the previous field before the given field on the
+|                    current page. The order of fields is the one defined
 |                    by the (row,column) geometry, rows are major.
 |
 |   Return Values :  Pointer to the previous field.
 +--------------------------------------------------------------------------*/
 |                    by the (row,column) geometry, rows are major.
 |
 |   Return Values :  Pointer to the previous field.
 +--------------------------------------------------------------------------*/
-INLINE static FIELD *Sorted_Previous_Field(FIELD * field)
+NCURSES_INLINE static FIELD *
+Sorted_Previous_Field(FIELD *field)
 {
   FIELD *field_on_page = field;
 
 {
   FIELD *field_on_page = field;
 
@@ -2896,73 +3437,79 @@ INLINE static FIELD *Sorted_Previous_Field(FIELD * field)
       field_on_page = field_on_page->sprev;
       if (Field_Is_Selectable(field_on_page))
        break;
       field_on_page = field_on_page->sprev;
       if (Field_Is_Selectable(field_on_page))
        break;
-    } while(field_on_page!=field);
-  
+    }
+  while (field_on_page != field);
+
   return (field_on_page);
 }
 
 /*---------------------------------------------------------------------------
   return (field_on_page);
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
-|   Function      :  static FIELD *Left_Neighbour_Field(FIELD * field)
-|   
-|   Description   :  Get the left neighbour of the field on the same line
+|   Facility      :  libnform
+|   Function      :  static FIELD *Left_Neighbor_Field(FIELD * field)
+|
+|   Description   :  Get the left neighbor of the field on the same line
 |                    and the same page. Cycles through the line.
 |
 |                    and the same page. Cycles through the line.
 |
-|   Return Values :  Pointer to left neighbour field.
+|   Return Values :  Pointer to left neighbor field.
 +--------------------------------------------------------------------------*/
 +--------------------------------------------------------------------------*/
-INLINE static FIELD *Left_Neighbour_Field(FIELD * field)
+NCURSES_INLINE static FIELD *
+Left_Neighbor_Field(FIELD *field)
 {
   FIELD *field_on_page = field;
 
 {
   FIELD *field_on_page = field;
 
-  /* For a field that has really a left neighbour, the while clause
+  /* For a field that has really a left neighbor, the while clause
      immediately fails and the loop is left, positioned at the right
      immediately fails and the loop is left, positioned at the right
-     neighbour. Otherwise we cycle backwards through the sorted fieldlist
+     neighbor. Otherwise we cycle backwards through the sorted field list
      until we enter the same line (from the right end).
      until we enter the same line (from the right end).
-  */
+   */
   do
     {
       field_on_page = Sorted_Previous_Field(field_on_page);
   do
     {
       field_on_page = Sorted_Previous_Field(field_on_page);
-    } while(field_on_page->frow != field->frow);
-  
+    }
+  while (field_on_page->frow != field->frow);
+
   return (field_on_page);
 }
 
 /*---------------------------------------------------------------------------
   return (field_on_page);
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
-|   Function      :  static FIELD *Right_Neighbour_Field(FIELD * field)
-|   
-|   Description   :  Get the right neighbour of the field on the same line
+|   Facility      :  libnform
+|   Function      :  static FIELD *Right_Neighbor_Field(FIELD * field)
+|
+|   Description   :  Get the right neighbor of the field on the same line
 |                    and the same page.
 |
 |                    and the same page.
 |
-|   Return Values :  Pointer to right neighbour field.
+|   Return Values :  Pointer to right neighbor field.
 +--------------------------------------------------------------------------*/
 +--------------------------------------------------------------------------*/
-INLINE static FIELD *Right_Neighbour_Field(FIELD * field)
+NCURSES_INLINE static FIELD *
+Right_Neighbor_Field(FIELD *field)
 {
   FIELD *field_on_page = field;
 
 {
   FIELD *field_on_page = field;
 
-  /* See the comments on Left_Neighbour_Field to understand how it works */
+  /* See the comments on Left_Neighbor_Field to understand how it works */
   do
     {
       field_on_page = Sorted_Next_Field(field_on_page);
   do
     {
       field_on_page = Sorted_Next_Field(field_on_page);
-    } while(field_on_page->frow != field->frow);
-  
+    }
+  while (field_on_page->frow != field->frow);
+
   return (field_on_page);
 }
 
 /*---------------------------------------------------------------------------
   return (field_on_page);
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
-|   Function      :  static FIELD *Upper_Neighbour_Field(FIELD * field)
-|   
+|   Facility      :  libnform
+|   Function      :  static FIELD *Upper_Neighbor_Field(FIELD * field)
+|
 |   Description   :  Because of the row-major nature of sorting the fields,
 |   Description   :  Because of the row-major nature of sorting the fields,
-|                    its more difficult to define whats the upper neighbour
+|                    it is more difficult to define whats the upper neighbor
 |                    field really means. We define that it must be on a
 |                    'previous' line (cyclic order!) and is the rightmost
 |                    field laying on the left side of the given field. If
 |                    this set is empty, we take the first field on the line.
 |
 |                    field really means. We define that it must be on a
 |                    'previous' line (cyclic order!) and is the rightmost
 |                    field laying on the left side of the given field. If
 |                    this set is empty, we take the first field on the line.
 |
-|   Return Values :  Pointer to the upper neighbour field.
+|   Return Values :  Pointer to the upper neighbor field.
 +--------------------------------------------------------------------------*/
 +--------------------------------------------------------------------------*/
-static FIELD *Upper_Neighbour_Field(FIELD * field)
+static FIELD *
+Upper_Neighbor_Field(FIELD *field)
 {
   FIELD *field_on_page = field;
   int frow = field->frow;
 {
   FIELD *field_on_page = field;
   int frow = field->frow;
@@ -2971,45 +3518,48 @@ static FIELD *Upper_Neighbour_Field(FIELD * field)
   /* Walk back to the 'previous' line. The second term in the while clause
      just guarantees that we stop if we cycled through the line because
      there might be no 'previous' line if the page has just one line.
   /* Walk back to the 'previous' line. The second term in the while clause
      just guarantees that we stop if we cycled through the line because
      there might be no 'previous' line if the page has just one line.
-  */
+   */
   do
     {
       field_on_page = Sorted_Previous_Field(field_on_page);
   do
     {
       field_on_page = Sorted_Previous_Field(field_on_page);
-    } while(field_on_page->frow==frow && field_on_page->fcol!=fcol);
-  
-  if (field_on_page->frow!=frow)
-    { /* We really found a 'previous' line. We are positioned at the
+    }
+  while (field_on_page->frow == frow && field_on_page->fcol != fcol);
+
+  if (field_on_page->frow != frow)
+    {
+      /* We really found a 'previous' line. We are positioned at the
          rightmost field on this line */
          rightmost field on this line */
-      frow = field_on_page->frow; 
+      frow = field_on_page->frow;
 
 
-      /* We walk to the left as long as we are really right of the 
-        field. */
-      while(field_on_page->frow==frow && field_on_page->fcol>fcol)
+      /* We walk to the left as long as we are really right of the
+         field. */
+      while (field_on_page->frow == frow && field_on_page->fcol > fcol)
        field_on_page = Sorted_Previous_Field(field_on_page);
 
        field_on_page = Sorted_Previous_Field(field_on_page);
 
-      /* If we wrapped, just go to the right which is the first field on 
-        the row */
-      if (field_on_page->frow!=frow)
+      /* If we wrapped, just go to the right which is the first field on
+         the row */
+      if (field_on_page->frow != frow)
        field_on_page = Sorted_Next_Field(field_on_page);
     }
        field_on_page = Sorted_Next_Field(field_on_page);
     }
-  
+
   return (field_on_page);
 }
 
 /*---------------------------------------------------------------------------
   return (field_on_page);
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
-|   Function      :  static FIELD *Down_Neighbour_Field(FIELD * field)
-|   
+|   Facility      :  libnform
+|   Function      :  static FIELD *Down_Neighbor_Field(FIELD * field)
+|
 |   Description   :  Because of the row-major nature of sorting the fields,
 |   Description   :  Because of the row-major nature of sorting the fields,
-|                    its more difficult to define whats the down neighbour
+|                    its more difficult to define whats the down neighbor
 |                    field really means. We define that it must be on a
 |                    'next' line (cyclic order!) and is the leftmost
 |                    field laying on the right side of the given field. If
 |                    this set is empty, we take the last field on the line.
 |
 |                    field really means. We define that it must be on a
 |                    'next' line (cyclic order!) and is the leftmost
 |                    field laying on the right side of the given field. If
 |                    this set is empty, we take the last field on the line.
 |
-|   Return Values :  Pointer to the upper neighbour field.
+|   Return Values :  Pointer to the upper neighbor field.
 +--------------------------------------------------------------------------*/
 +--------------------------------------------------------------------------*/
-static FIELD *Down_Neighbour_Field(FIELD * field)
+static FIELD *
+Down_Neighbor_Field(FIELD *field)
 {
   FIELD *field_on_page = field;
   int frow = field->frow;
 {
   FIELD *field_on_page = field;
   int frow = field->frow;
@@ -3018,42 +3568,44 @@ static FIELD *Down_Neighbour_Field(FIELD * field)
   /* Walk forward to the 'next' line. The second term in the while clause
      just guarantees that we stop if we cycled through the line because
      there might be no 'next' line if the page has just one line.
   /* Walk forward to the 'next' line. The second term in the while clause
      just guarantees that we stop if we cycled through the line because
      there might be no 'next' line if the page has just one line.
-  */
+   */
   do
     {
       field_on_page = Sorted_Next_Field(field_on_page);
   do
     {
       field_on_page = Sorted_Next_Field(field_on_page);
-    } while(field_on_page->frow==frow && field_on_page->fcol!=fcol);
+    }
+  while (field_on_page->frow == frow && field_on_page->fcol != fcol);
 
 
-  if (field_on_page->frow!=frow)
-    { /* We really found a 'next' line. We are positioned at the rightmost
+  if (field_on_page->frow != frow)
+    {
+      /* We really found a 'next' line. We are positioned at the rightmost
          field on this line */
       frow = field_on_page->frow;
 
          field on this line */
       frow = field_on_page->frow;
 
-      /* We walk to the right as long as we are really left of the 
-        field. */
-      while(field_on_page->frow==frow && field_on_page->fcol<fcol)
+      /* We walk to the right as long as we are really left of the
+         field. */
+      while (field_on_page->frow == frow && field_on_page->fcol < fcol)
        field_on_page = Sorted_Next_Field(field_on_page);
 
        field_on_page = Sorted_Next_Field(field_on_page);
 
-      /* If we wrapped, just go to the left which is the last field on 
-        the row */
-      if (field_on_page->frow!=frow)
+      /* If we wrapped, just go to the left which is the last field on
+         the row */
+      if (field_on_page->frow != frow)
        field_on_page = Sorted_Previous_Field(field_on_page);
     }
        field_on_page = Sorted_Previous_Field(field_on_page);
     }
-  
-  return(field_on_page);
+
+  return (field_on_page);
 }
 }
-\f
+
 /*----------------------------------------------------------------------------
   Inter-Field Navigation routines
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
 /*----------------------------------------------------------------------------
   Inter-Field Navigation routines
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int Inter_Field_Navigation(
 |                                           int (* const fct) (FORM *),
 |                                           FORM * form)
 |   Function      :  static int Inter_Field_Navigation(
 |                                           int (* const fct) (FORM *),
 |                                           FORM * form)
-|   
-|   Description   :  Generic behaviour for changing the current field, the
+|
+|   Description   :  Generic behavior for changing the current field, the
 |                    field is left and a new field is entered. So the field
 |                    must be validated and the field init/term hooks must
 |                    be called.
 |                    field is left and a new field is entered. So the field
 |                    must be validated and the field init/term hooks must
 |                    be called.
@@ -3062,229 +3614,254 @@ static FIELD *Down_Neighbour_Field(FIELD * field)
 |                    E_INVALID_FIELD     - field is invalid
 |                    some other          - error from subordinate call
 +--------------------------------------------------------------------------*/
 |                    E_INVALID_FIELD     - field is invalid
 |                    some other          - error from subordinate call
 +--------------------------------------------------------------------------*/
-static int Inter_Field_Navigation(int (* const fct) (FORM *),FORM *form)
+static int
+Inter_Field_Navigation(int (*const fct) (FORM *), FORM *form)
 {
   int res;
 
 {
   int res;
 
-  if (!_nc_Internal_Validation(form)) 
+  if (!_nc_Internal_Validation(form))
     res = E_INVALID_FIELD;
   else
     {
     res = E_INVALID_FIELD;
   else
     {
-      Call_Hook(form,fieldterm);
+      Call_Hook(form, fieldterm);
       res = fct(form);
       res = fct(form);
-      Call_Hook(form,fieldinit);
+      Call_Hook(form, fieldinit);
     }
   return res;
 }
 
 /*---------------------------------------------------------------------------
     }
   return res;
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FN_Next_Field(FORM * form)
 |   Function      :  static int FN_Next_Field(FORM * form)
-|   
+|
 |   Description   :  Move to the next field on the current page of the form
 |
 |   Return Values :  E_OK                 - success
 |                    != E_OK              - error from subordinate call
 +--------------------------------------------------------------------------*/
 |   Description   :  Move to the next field on the current page of the form
 |
 |   Return Values :  E_OK                 - success
 |                    != E_OK              - error from subordinate call
 +--------------------------------------------------------------------------*/
-static int FN_Next_Field(FORM * form)
+static int
+FN_Next_Field(FORM *form)
 {
 {
-  return _nc_Set_Current_Field(form,
-                              Next_Field_On_Page(form->current));
+  T((T_CALLED("FN_Next_Field(%p)"), (void *)form));
+  returnCode(_nc_Set_Current_Field(form,
+                                  Next_Field_On_Page(form->current)));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FN_Previous_Field(FORM * form)
 |   Function      :  static int FN_Previous_Field(FORM * form)
-|   
-|   Description   :  Move to the previous field on the current page of the 
+|
+|   Description   :  Move to the previous field on the current page of the
 |                    form
 |
 |   Return Values :  E_OK                 - success
 |                    != E_OK              - error from subordinate call
 +--------------------------------------------------------------------------*/
 |                    form
 |
 |   Return Values :  E_OK                 - success
 |                    != E_OK              - error from subordinate call
 +--------------------------------------------------------------------------*/
-static int FN_Previous_Field(FORM * form)
+static int
+FN_Previous_Field(FORM *form)
 {
 {
-  return _nc_Set_Current_Field(form,
-                              Previous_Field_On_Page(form->current));
+  T((T_CALLED("FN_Previous_Field(%p)"), (void *)form));
+  returnCode(_nc_Set_Current_Field(form,
+                                  Previous_Field_On_Page(form->current)));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FN_First_Field(FORM * form)
 |   Function      :  static int FN_First_Field(FORM * form)
-|   
+|
 |   Description   :  Move to the first field on the current page of the form
 |
 |   Return Values :  E_OK                 - success
 |                    != E_OK              - error from subordinate call
 +--------------------------------------------------------------------------*/
 |   Description   :  Move to the first field on the current page of the form
 |
 |   Return Values :  E_OK                 - success
 |                    != E_OK              - error from subordinate call
 +--------------------------------------------------------------------------*/
-static int FN_First_Field(FORM * form)
+static int
+FN_First_Field(FORM *form)
 {
 {
-  return _nc_Set_Current_Field(form,
-      Next_Field_On_Page(form->field[form->page[form->curpage].pmax]));
+  T((T_CALLED("FN_First_Field(%p)"), (void *)form));
+  returnCode(_nc_Set_Current_Field(form,
+                                  Next_Field_On_Page(form->field[form->page[form->curpage].pmax])));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FN_Last_Field(FORM * form)
 |   Function      :  static int FN_Last_Field(FORM * form)
-|   
+|
 |   Description   :  Move to the last field on the current page of the form
 |
 |   Return Values :  E_OK                 - success
 |                    != E_OK              - error from subordinate call
 +--------------------------------------------------------------------------*/
 |   Description   :  Move to the last field on the current page of the form
 |
 |   Return Values :  E_OK                 - success
 |                    != E_OK              - error from subordinate call
 +--------------------------------------------------------------------------*/
-static int FN_Last_Field(FORM * form)
+static int
+FN_Last_Field(FORM *form)
 {
 {
-  return 
-    _nc_Set_Current_Field(form,
-       Previous_Field_On_Page(form->field[form->page[form->curpage].pmin]));
+  T((T_CALLED("FN_Last_Field(%p)"), (void *)form));
+  returnCode(
+             _nc_Set_Current_Field(form,
+                                   Previous_Field_On_Page(form->field[form->page[form->curpage].pmin])));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FN_Sorted_Next_Field(FORM * form)
 |   Function      :  static int FN_Sorted_Next_Field(FORM * form)
-|   
+|
 |   Description   :  Move to the sorted next field on the current page
 |                    of the form.
 |
 |   Return Values :  E_OK            - success
 |                    != E_OK         - error from subordinate call
 +--------------------------------------------------------------------------*/
 |   Description   :  Move to the sorted next field on the current page
 |                    of the form.
 |
 |   Return Values :  E_OK            - success
 |                    != E_OK         - error from subordinate call
 +--------------------------------------------------------------------------*/
-static int FN_Sorted_Next_Field(FORM * form)
+static int
+FN_Sorted_Next_Field(FORM *form)
 {
 {
-  return _nc_Set_Current_Field(form,
-                              Sorted_Next_Field(form->current));
+  T((T_CALLED("FN_Sorted_Next_Field(%p)"), (void *)form));
+  returnCode(_nc_Set_Current_Field(form,
+                                  Sorted_Next_Field(form->current)));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FN_Sorted_Previous_Field(FORM * form)
 |   Function      :  static int FN_Sorted_Previous_Field(FORM * form)
-|   
+|
 |   Description   :  Move to the sorted previous field on the current page
 |                    of the form.
 |
 |   Return Values :  E_OK            - success
 |                    != E_OK         - error from subordinate call
 +--------------------------------------------------------------------------*/
 |   Description   :  Move to the sorted previous field on the current page
 |                    of the form.
 |
 |   Return Values :  E_OK            - success
 |                    != E_OK         - error from subordinate call
 +--------------------------------------------------------------------------*/
-static int FN_Sorted_Previous_Field(FORM * form)
+static int
+FN_Sorted_Previous_Field(FORM *form)
 {
 {
-  return _nc_Set_Current_Field(form,
-                              Sorted_Previous_Field(form->current));
+  T((T_CALLED("FN_Sorted_Previous_Field(%p)"), (void *)form));
+  returnCode(_nc_Set_Current_Field(form,
+                                  Sorted_Previous_Field(form->current)));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FN_Sorted_First_Field(FORM * form)
 |   Function      :  static int FN_Sorted_First_Field(FORM * form)
-|   
+|
 |   Description   :  Move to the sorted first field on the current page
 |                    of the form.
 |
 |   Return Values :  E_OK            - success
 |                    != E_OK         - error from subordinate call
 +--------------------------------------------------------------------------*/
 |   Description   :  Move to the sorted first field on the current page
 |                    of the form.
 |
 |   Return Values :  E_OK            - success
 |                    != E_OK         - error from subordinate call
 +--------------------------------------------------------------------------*/
-static int FN_Sorted_First_Field(FORM * form)
+static int
+FN_Sorted_First_Field(FORM *form)
 {
 {
-  return _nc_Set_Current_Field(form,
-             Sorted_Next_Field(form->field[form->page[form->curpage].smax]));
+  T((T_CALLED("FN_Sorted_First_Field(%p)"), (void *)form));
+  returnCode(_nc_Set_Current_Field(form,
+                                  Sorted_Next_Field(form->field[form->page[form->curpage].smax])));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FN_Sorted_Last_Field(FORM * form)
 |   Function      :  static int FN_Sorted_Last_Field(FORM * form)
-|   
+|
 |   Description   :  Move to the sorted last field on the current page
 |                    of the form.
 |
 |   Return Values :  E_OK            - success
 |                    != E_OK         - error from subordinate call
 +--------------------------------------------------------------------------*/
 |   Description   :  Move to the sorted last field on the current page
 |                    of the form.
 |
 |   Return Values :  E_OK            - success
 |                    != E_OK         - error from subordinate call
 +--------------------------------------------------------------------------*/
-static int FN_Sorted_Last_Field(FORM * form)
+static int
+FN_Sorted_Last_Field(FORM *form)
 {
 {
-  return _nc_Set_Current_Field(form,
-          Sorted_Previous_Field(form->field[form->page[form->curpage].smin]));
+  T((T_CALLED("FN_Sorted_Last_Field(%p)"), (void *)form));
+  returnCode(_nc_Set_Current_Field(form,
+                                  Sorted_Previous_Field(form->field[form->page[form->curpage].smin])));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FN_Left_Field(FORM * form)
 |   Function      :  static int FN_Left_Field(FORM * form)
-|   
+|
 |   Description   :  Get the field on the left of the current field on the
 |                    same line and the same page. Cycles through the line.
 |
 |   Return Values :  E_OK            - success
 |                    != E_OK         - error from subordinate call
 +--------------------------------------------------------------------------*/
 |   Description   :  Get the field on the left of the current field on the
 |                    same line and the same page. Cycles through the line.
 |
 |   Return Values :  E_OK            - success
 |                    != E_OK         - error from subordinate call
 +--------------------------------------------------------------------------*/
-static int FN_Left_Field(FORM * form)
+static int
+FN_Left_Field(FORM *form)
 {
 {
-  return _nc_Set_Current_Field(form,
-                              Left_Neighbour_Field(form->current));
+  T((T_CALLED("FN_Left_Field(%p)"), (void *)form));
+  returnCode(_nc_Set_Current_Field(form,
+                                  Left_Neighbor_Field(form->current)));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FN_Right_Field(FORM * form)
 |   Function      :  static int FN_Right_Field(FORM * form)
-|   
+|
 |   Description   :  Get the field on the right of the current field on the
 |                    same line and the same page. Cycles through the line.
 |
 |   Return Values :  E_OK            - success
 |                    != E_OK         - error from subordinate call
 +--------------------------------------------------------------------------*/
 |   Description   :  Get the field on the right of the current field on the
 |                    same line and the same page. Cycles through the line.
 |
 |   Return Values :  E_OK            - success
 |                    != E_OK         - error from subordinate call
 +--------------------------------------------------------------------------*/
-static int FN_Right_Field(FORM * form)
+static int
+FN_Right_Field(FORM *form)
 {
 {
-  return _nc_Set_Current_Field(form,
-                              Right_Neighbour_Field(form->current));
+  T((T_CALLED("FN_Right_Field(%p)"), (void *)form));
+  returnCode(_nc_Set_Current_Field(form,
+                                  Right_Neighbor_Field(form->current)));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FN_Up_Field(FORM * form)
 |   Function      :  static int FN_Up_Field(FORM * form)
-|   
-|   Description   :  Get the upper neighbour of the current field. This
+|
+|   Description   :  Get the upper neighbor of the current field. This
 |                    cycles through the page. See the comments of the
 |                    cycles through the page. See the comments of the
-|                    Upper_Neighbour_Field function to understand how
-|                    'upper' is defined. 
+|                    Upper_Neighbor_Field function to understand how
+|                    'upper' is defined.
 |
 |   Return Values :  E_OK            - success
 |                    != E_OK         - error from subordinate call
 +--------------------------------------------------------------------------*/
 |
 |   Return Values :  E_OK            - success
 |                    != E_OK         - error from subordinate call
 +--------------------------------------------------------------------------*/
-static int FN_Up_Field(FORM * form)
+static int
+FN_Up_Field(FORM *form)
 {
 {
-  return _nc_Set_Current_Field(form,
-                              Upper_Neighbour_Field(form->current));
+  T((T_CALLED("FN_Up_Field(%p)"), (void *)form));
+  returnCode(_nc_Set_Current_Field(form,
+                                  Upper_Neighbor_Field(form->current)));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int FN_Down_Field(FORM * form)
 |   Function      :  static int FN_Down_Field(FORM * form)
-|   
-|   Description   :  Get the down neighbour of the current field. This
+|
+|   Description   :  Get the down neighbor of the current field. This
 |                    cycles through the page. See the comments of the
 |                    cycles through the page. See the comments of the
-|                    Down_Neighbour_Field function to understand how
-|                    'down' is defined. 
+|                    Down_Neighbor_Field function to understand how
+|                    'down' is defined.
 |
 |   Return Values :  E_OK            - success
 |                    != E_OK         - error from subordinate call
 +--------------------------------------------------------------------------*/
 |
 |   Return Values :  E_OK            - success
 |                    != E_OK         - error from subordinate call
 +--------------------------------------------------------------------------*/
-static int FN_Down_Field(FORM * form)
+static int
+FN_Down_Field(FORM *form)
 {
 {
-  return _nc_Set_Current_Field(form,
-                              Down_Neighbour_Field(form->current));
+  T((T_CALLED("FN_Down_Field(%p)"), (void *)form));
+  returnCode(_nc_Set_Current_Field(form,
+                                  Down_Neighbor_Field(form->current)));
 }
 /*----------------------------------------------------------------------------
 }
 /*----------------------------------------------------------------------------
-  END of Field Navigation routines 
+  END of Field Navigation routines
   --------------------------------------------------------------------------*/
   --------------------------------------------------------------------------*/
-\f
+
 /*----------------------------------------------------------------------------
   Helper routines for Page Navigation
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
 /*----------------------------------------------------------------------------
   Helper routines for Page Navigation
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  int _nc_Set_Form_Page(FORM * form,
 |                                          int page,
 |                                          FIELD * field)
 |   Function      :  int _nc_Set_Form_Page(FORM * form,
 |                                          int page,
 |                                          FIELD * field)
-|   
-|   Description   :  Make the given page nr. the current page and make
+|
+|   Description   :  Make the given page number the current page and make
 |                    the given field the current field on the page. If
 |                    for the field NULL is given, make the first field on
 |                    the page the current field. The routine acts only
 |                    the given field the current field on the page. If
 |                    for the field NULL is given, make the first field on
 |                    the page the current field. The routine acts only
@@ -3292,81 +3869,85 @@ static int FN_Down_Field(FORM * form)
 |
 |   Return Values :  E_OK                - success
 |                    != E_OK             - error from subordinate call
 |
 |   Return Values :  E_OK                - success
 |                    != E_OK             - error from subordinate call
+|                    E_BAD_ARGUMENT      - invalid field pointer
+|                    E_SYSTEM_ERROR      - some severe basic error
 +--------------------------------------------------------------------------*/
 NCURSES_EXPORT(int)
 +--------------------------------------------------------------------------*/
 NCURSES_EXPORT(int)
-_nc_Set_Form_Page
-(FORM * form, int page, FIELD * field)
+_nc_Set_Form_Page(FORM *form, int page, FIELD *field)
 {
   int res = E_OK;
 
 {
   int res = E_OK;
 
-  if ((form->curpage!=page))
+  if ((form->curpage != page))
     {
       FIELD *last_field, *field_on_page;
 
       werase(Get_Form_Window(form));
     {
       FIELD *last_field, *field_on_page;
 
       werase(Get_Form_Window(form));
-      form->curpage = page;
+      form->curpage = (short)page;
       last_field = field_on_page = form->field[form->page[page].smin];
       do
        {
       last_field = field_on_page = form->field[form->page[page].smin];
       do
        {
-         if (field_on_page->opts & O_VISIBLE)
-           if ((res=Display_Field(field_on_page))!=E_OK) 
-             return(res);
+         if ((unsigned)field_on_page->opts & O_VISIBLE)
+           if ((res = Display_Field(field_on_page)) != E_OK)
+             return (res);
          field_on_page = field_on_page->snext;
          field_on_page = field_on_page->snext;
-       } while(field_on_page != last_field);
+       }
+      while (field_on_page != last_field);
 
       if (field)
 
       if (field)
-       res = _nc_Set_Current_Field(form,field);
+       res = _nc_Set_Current_Field(form, field);
       else
        /* N.B.: we don't encapsulate this by Inter_Field_Navigation(),
           because this is already executed in a page navigation
       else
        /* N.B.: we don't encapsulate this by Inter_Field_Navigation(),
           because this is already executed in a page navigation
-          context that contains field navigation 
+          context that contains field navigation
         */
        res = FN_First_Field(form);
     }
         */
        res = FN_First_Field(form);
     }
-  return(res);
+  return (res);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int Next_Page_Number(const FORM * form)
 |   Function      :  static int Next_Page_Number(const FORM * form)
-|   
+|
 |   Description   :  Calculate the page number following the current page
 |                    number. This cycles if the highest page number is
 |   Description   :  Calculate the page number following the current page
 |                    number. This cycles if the highest page number is
-|                    reached.  
+|                    reached.
 |
 |   Return Values :  The next page number
 +--------------------------------------------------------------------------*/
 |
 |   Return Values :  The next page number
 +--------------------------------------------------------------------------*/
-INLINE static int Next_Page_Number(const FORM * form)
+NCURSES_INLINE static int
+Next_Page_Number(const FORM *form)
 {
   return (form->curpage + 1) % form->maxpage;
 }
 
 /*---------------------------------------------------------------------------
 {
   return (form->curpage + 1) % form->maxpage;
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int Previous_Page_Number(const FORM * form)
 |   Function      :  static int Previous_Page_Number(const FORM * form)
-|   
+|
 |   Description   :  Calculate the page number before the current page
 |                    number. This cycles if the first page number is
 |   Description   :  Calculate the page number before the current page
 |                    number. This cycles if the first page number is
-|                    reached.  
+|                    reached.
 |
 |   Return Values :  The previous page number
 +--------------------------------------------------------------------------*/
 |
 |   Return Values :  The previous page number
 +--------------------------------------------------------------------------*/
-INLINE static int Previous_Page_Number(const FORM * form)
+NCURSES_INLINE static int
+Previous_Page_Number(const FORM *form)
 {
 {
-  return (form->curpage!=0 ? form->curpage - 1 : form->maxpage - 1);
+  return (form->curpage != 0 ? form->curpage - 1 : form->maxpage - 1);
 }
 }
-\f
+
 /*----------------------------------------------------------------------------
 /*----------------------------------------------------------------------------
-  Page Navigation routines 
+  Page Navigation routines
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
   --------------------------------------------------------------------------*/
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int Page_Navigation(
 |                                               int (* const fct) (FORM *),
 |                                               FORM * form)
 |   Function      :  static int Page_Navigation(
 |                                               int (* const fct) (FORM *),
 |                                               FORM * form)
-|   
-|   Description   :  Generic behaviour for changing a page. This means
+|
+|   Description   :  Generic behavior for changing a page. This means
 |                    that the field is left and a new field is entered.
 |                    So the field must be validated and the field init/term
 |                    hooks must be called. Because also the page is changed,
 |                    that the field is left and a new field is entered.
 |                    So the field must be validated and the field init/term
 |                    hooks must be called. Because also the page is changed,
@@ -3376,192 +3957,314 @@ INLINE static int Previous_Page_Number(const FORM * form)
 |                    E_INVALID_FIELD     - field is invalid
 |                    some other          - error from subordinate call
 +--------------------------------------------------------------------------*/
 |                    E_INVALID_FIELD     - field is invalid
 |                    some other          - error from subordinate call
 +--------------------------------------------------------------------------*/
-static int Page_Navigation(int (* const fct) (FORM *), FORM * form)
+static int
+Page_Navigation(int (*const fct) (FORM *), FORM *form)
 {
   int res;
 
 {
   int res;
 
-  if (!_nc_Internal_Validation(form)) 
+  if (!_nc_Internal_Validation(form))
     res = E_INVALID_FIELD;
   else
     {
     res = E_INVALID_FIELD;
   else
     {
-      Call_Hook(form,fieldterm);
-      Call_Hook(form,formterm);
+      Call_Hook(form, fieldterm);
+      Call_Hook(form, formterm);
       res = fct(form);
       res = fct(form);
-      Call_Hook(form,forminit);
-      Call_Hook(form,fieldinit);
+      Call_Hook(form, forminit);
+      Call_Hook(form, fieldinit);
     }
   return res;
 }
 
 /*---------------------------------------------------------------------------
     }
   return res;
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int PN_Next_Page(FORM * form)
 |   Function      :  static int PN_Next_Page(FORM * form)
-|   
+|
 |   Description   :  Move to the next page of the form
 |
 |   Return Values :  E_OK                - success
 |                    != E_OK             - error from subordinate call
 +--------------------------------------------------------------------------*/
 |   Description   :  Move to the next page of the form
 |
 |   Return Values :  E_OK                - success
 |                    != E_OK             - error from subordinate call
 +--------------------------------------------------------------------------*/
-static int PN_Next_Page(FORM * form)
-{ 
-  return _nc_Set_Form_Page(form,Next_Page_Number(form),(FIELD *)0);
+static int
+PN_Next_Page(FORM *form)
+{
+  T((T_CALLED("PN_Next_Page(%p)"), (void *)form));
+  returnCode(_nc_Set_Form_Page(form, Next_Page_Number(form), (FIELD *)0));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int PN_Previous_Page(FORM * form)
 |   Function      :  static int PN_Previous_Page(FORM * form)
-|   
+|
 |   Description   :  Move to the previous page of the form
 |
 |   Return Values :  E_OK              - success
 |                    != E_OK           - error from subordinate call
 +--------------------------------------------------------------------------*/
 |   Description   :  Move to the previous page of the form
 |
 |   Return Values :  E_OK              - success
 |                    != E_OK           - error from subordinate call
 +--------------------------------------------------------------------------*/
-static int PN_Previous_Page(FORM * form)
+static int
+PN_Previous_Page(FORM *form)
 {
 {
-  return _nc_Set_Form_Page(form,Previous_Page_Number(form),(FIELD *)0);
+  T((T_CALLED("PN_Previous_Page(%p)"), (void *)form));
+  returnCode(_nc_Set_Form_Page(form, Previous_Page_Number(form), (FIELD *)0));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int PN_First_Page(FORM * form)
 |   Function      :  static int PN_First_Page(FORM * form)
-|   
+|
 |   Description   :  Move to the first page of the form
 |
 |   Return Values :  E_OK              - success
 |                    != E_OK           - error from subordinate call
 +--------------------------------------------------------------------------*/
 |   Description   :  Move to the first page of the form
 |
 |   Return Values :  E_OK              - success
 |                    != E_OK           - error from subordinate call
 +--------------------------------------------------------------------------*/
-static int PN_First_Page(FORM * form)
+static int
+PN_First_Page(FORM *form)
 {
 {
-  return _nc_Set_Form_Page(form,0,(FIELD *)0);
+  T((T_CALLED("PN_First_Page(%p)"), (void *)form));
+  returnCode(_nc_Set_Form_Page(form, 0, (FIELD *)0));
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static int PN_Last_Page(FORM * form)
 |   Function      :  static int PN_Last_Page(FORM * form)
-|   
+|
 |   Description   :  Move to the last page of the form
 |
 |   Return Values :  E_OK              - success
 |                    != E_OK           - error from subordinate call
 +--------------------------------------------------------------------------*/
 |   Description   :  Move to the last page of the form
 |
 |   Return Values :  E_OK              - success
 |                    != E_OK           - error from subordinate call
 +--------------------------------------------------------------------------*/
-static int PN_Last_Page(FORM * form)
+static int
+PN_Last_Page(FORM *form)
 {
 {
-  return _nc_Set_Form_Page(form,form->maxpage-1,(FIELD *)0);
+  T((T_CALLED("PN_Last_Page(%p)"), (void *)form));
+  returnCode(_nc_Set_Form_Page(form, form->maxpage - 1, (FIELD *)0));
 }
 }
+
 /*----------------------------------------------------------------------------
 /*----------------------------------------------------------------------------
-  END of Field Navigation routines 
+  END of Field Navigation routines
   --------------------------------------------------------------------------*/
   --------------------------------------------------------------------------*/
-\f
+
 /*----------------------------------------------------------------------------
   Helper routines for the core form driver.
   --------------------------------------------------------------------------*/
 
 /*----------------------------------------------------------------------------
   Helper routines for the core form driver.
   --------------------------------------------------------------------------*/
 
+# if USE_WIDEC_SUPPORT
 /*---------------------------------------------------------------------------
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
+|   Function      :  static int Data_Entry_w(FORM * form, wchar_t c)
+|
+|   Description   :  Enter the wide character c into at the current
+|                    position of the current field of the form.
+|
+|   Return Values :  E_OK              - success
+|                    E_REQUEST_DENIED  - driver could not process the request
+|                    E_SYSTEM_ERROR    -
++--------------------------------------------------------------------------*/
+static int
+Data_Entry_w(FORM *form, wchar_t c)
+{
+  FIELD *field = form->current;
+  int result = E_REQUEST_DENIED;
+
+  T((T_CALLED("Data_Entry(%p,%s)"), (void *)form, _tracechtype((chtype)c)));
+  if ((Field_Has_Option(field, O_EDIT))
+#if FIX_FORM_INACTIVE_BUG
+      && (Field_Has_Option(field, O_ACTIVE))
+#endif
+    )
+    {
+      wchar_t given[2];
+      cchar_t temp_ch;
+
+      given[0] = c;
+      given[1] = 0;
+      setcchar(&temp_ch, given, 0, 0, (void *)0);
+      if ((Field_Has_Option(field, O_BLANK)) &&
+         First_Position_In_Current_Field(form) &&
+         !(form->status & _FCHECK_REQUIRED) &&
+         !(form->status & _WINDOW_MODIFIED))
+       werase(form->w);
+
+      if (form->status & _OVLMODE)
+       {
+         wadd_wch(form->w, &temp_ch);
+       }
+      else
+       /* no _OVLMODE */
+       {
+         bool There_Is_Room = Is_There_Room_For_A_Char_In_Line(form);
+
+         if (!(There_Is_Room ||
+               ((Single_Line_Field(field) && Growable(field)))))
+           RETURN(E_REQUEST_DENIED);
+
+         if (!There_Is_Room && !Field_Grown(field, 1))
+           RETURN(E_SYSTEM_ERROR);
+
+         wins_wch(form->w, &temp_ch);
+       }
+
+      if ((result = Wrapping_Not_Necessary_Or_Wrapping_Ok(form)) == E_OK)
+       {
+         bool End_Of_Field = (((field->drows - 1) == form->currow) &&
+                              ((field->dcols - 1) == form->curcol));
+
+         form->status |= _WINDOW_MODIFIED;
+         if (End_Of_Field && !Growable(field) && (Field_Has_Option(field, O_AUTOSKIP)))
+           result = Inter_Field_Navigation(FN_Next_Field, form);
+         else
+           {
+             if (End_Of_Field && Growable(field) && !Field_Grown(field, 1))
+               result = E_SYSTEM_ERROR;
+             else
+               {
+                 /*
+                  * We have just added a byte to the form field.  It may have
+                  * been part of a multibyte character.  If it was, the
+                  * addch_used field is nonzero and we should not try to move
+                  * to a new column.
+                  */
+                 if (WINDOW_EXT(form->w, addch_used) == 0)
+                   IFN_Next_Character(form);
+
+                 result = E_OK;
+               }
+           }
+       }
+    }
+  RETURN(result);
+}
+# endif
+
+/*---------------------------------------------------------------------------
+|   Facility      :  libnform
 |   Function      :  static int Data_Entry(FORM * form,int c)
 |   Function      :  static int Data_Entry(FORM * form,int c)
-|   
+|
 |   Description   :  Enter character c into at the current position of the
 |                    current field of the form.
 |
 |   Description   :  Enter character c into at the current position of the
 |                    current field of the form.
 |
-|   Return Values :  E_OK              -
-|                    E_REQUEST_DENIED  -
+|   Return Values :  E_OK              - success
+|                    E_REQUEST_DENIED  - driver could not process the request
 |                    E_SYSTEM_ERROR    -
 +--------------------------------------------------------------------------*/
 |                    E_SYSTEM_ERROR    -
 +--------------------------------------------------------------------------*/
-static int Data_Entry(FORM * form, int c)
+static int
+Data_Entry(FORM *form, int c)
 {
 {
-  FIELD  *field = form->current;
+  FIELD *field = form->current;
   int result = E_REQUEST_DENIED;
 
   int result = E_REQUEST_DENIED;
 
-  if ( (field->opts & O_EDIT) 
+  T((T_CALLED("Data_Entry(%p,%s)"), (void *)form, _tracechtype((chtype)c)));
+  if ((Field_Has_Option(field, O_EDIT))
 #if FIX_FORM_INACTIVE_BUG
 #if FIX_FORM_INACTIVE_BUG
-       && (field->opts & O_ACTIVE) 
+      && (Field_Has_Option(field, O_ACTIVE))
 #endif
 #endif
-       )
+    )
     {
     {
-      if ( (field->opts & O_BLANK) &&
-          First_Position_In_Current_Field(form) &&
-          !(form->status & _FCHECK_REQUIRED) && 
-          !(form->status & _WINDOW_MODIFIED) )
+      if ((Field_Has_Option(field, O_BLANK)) &&
+         First_Position_In_Current_Field(form) &&
+         !(form->status & _FCHECK_REQUIRED) &&
+         !(form->status & _WINDOW_MODIFIED))
        werase(form->w);
 
       if (form->status & _OVLMODE)
        {
        werase(form->w);
 
       if (form->status & _OVLMODE)
        {
-         waddch(form->w,(chtype)c);
-       } 
-      else /* no _OVLMODE */ 
+         waddch(form->w, (chtype)c);
+       }
+      else
+       /* no _OVLMODE */
        {
          bool There_Is_Room = Is_There_Room_For_A_Char_In_Line(form);
 
          if (!(There_Is_Room ||
                ((Single_Line_Field(field) && Growable(field)))))
        {
          bool There_Is_Room = Is_There_Room_For_A_Char_In_Line(form);
 
          if (!(There_Is_Room ||
                ((Single_Line_Field(field) && Growable(field)))))
-             return E_REQUEST_DENIED;
+           RETURN(E_REQUEST_DENIED);
 
 
-         if (!There_Is_Room && !Field_Grown(field,1))
-           return E_SYSTEM_ERROR;
+         if (!There_Is_Room && !Field_Grown(field, 1))
+           RETURN(E_SYSTEM_ERROR);
 
 
-         winsch(form->w,(chtype)c);
+         winsch(form->w, (chtype)c);
        }
 
        }
 
-      if ((result=Wrapping_Not_Necessary_Or_Wrapping_Ok(form))==E_OK)
+      if ((result = Wrapping_Not_Necessary_Or_Wrapping_Ok(form)) == E_OK)
        {
        {
-         bool End_Of_Field= (((field->drows-1)==form->currow) &&
-                             ((field->dcols-1)==form->curcol));
-         form->status |= _WINDOW_MODIFIED;
-         if (End_Of_Field && !Growable(field) && (field->opts & O_AUTOSKIP))
-           result = Inter_Field_Navigation(FN_Next_Field,form);
+         bool End_Of_Field = (((field->drows - 1) == form->currow) &&
+                              ((field->dcols - 1) == form->curcol));
+
+         if (Field_Has_Option(field, O_EDGE_INSERT_STAY))
+           move_after_insert = !!(form->curcol
+                                  - form->begincol
+                                  - field->cols
+                                  + 1);
+
+         SetStatus(form, _WINDOW_MODIFIED);
+         if (End_Of_Field && !Growable(field) && (Field_Has_Option(field, O_AUTOSKIP)))
+           result = Inter_Field_Navigation(FN_Next_Field, form);
          else
            {
          else
            {
-             if (End_Of_Field && Growable(field) && !Field_Grown(field,1))
+             if (End_Of_Field && Growable(field) && !Field_Grown(field, 1))
                result = E_SYSTEM_ERROR;
              else
                {
                result = E_SYSTEM_ERROR;
              else
                {
+#if USE_WIDEC_SUPPORT
+                 /*
+                  * We have just added a byte to the form field.  It may have
+                  * been part of a multibyte character.  If it was, the
+                  * addch_used field is nonzero and we should not try to move
+                  * to a new column.
+                  */
+                 if (WINDOW_EXT(form->w, addch_used) == 0)
+                   IFN_Next_Character(form);
+#else
                  IFN_Next_Character(form);
                  IFN_Next_Character(form);
+#endif
                  result = E_OK;
                }
            }
        }
     }
                  result = E_OK;
                }
            }
        }
     }
-  return result;
+  RETURN(result);
 }
 }
-\f
+
 /* Structure to describe the binding of a request code to a function.
    The member keycode codes the request value as well as the generic
    routine to use for the request. The code for the generic routine
    is coded in the upper 16 Bits while the request code is coded in
 /* Structure to describe the binding of a request code to a function.
    The member keycode codes the request value as well as the generic
    routine to use for the request. The code for the generic routine
    is coded in the upper 16 Bits while the request code is coded in
-   the lower 16 bits. 
+   the lower 16 bits.
 
    In terms of C++ you might think of a request as a class with a
    virtual method "perform". The different types of request are
    derived from this base class and overload (or not) the base class
    implementation of perform.
 */
 
    In terms of C++ you might think of a request as a class with a
    virtual method "perform". The different types of request are
    derived from this base class and overload (or not) the base class
    implementation of perform.
 */
-typedef struct {
-  int keycode;           /* must be at least 32 bit: hi:mode, lo: key */
-  int (*cmd)(FORM *);    /* low level driver routine for this key     */
-} Binding_Info;
+typedef struct
+{
+  int keycode;                 /* must be at least 32 bit: hi:mode, lo: key */
+  int (*cmd) (FORM *);         /* low level driver routine for this key     */
+}
+Binding_Info;
 
 /* You may see this is the class-id of the request type class */
 
 /* You may see this is the class-id of the request type class */
-#define ID_PN    (0x00000000)    /* Page navigation           */
-#define ID_FN    (0x00010000)    /* Inter-Field navigation    */
-#define ID_IFN   (0x00020000)    /* Intra-Field navigation    */
-#define ID_VSC   (0x00030000)    /* Vertical Scrolling        */
-#define ID_HSC   (0x00040000)    /* Horizontal Scrolling      */
-#define ID_FE    (0x00050000)    /* Field Editing             */
-#define ID_EM    (0x00060000)    /* Edit Mode                 */
-#define ID_FV    (0x00070000)    /* Field Validation          */
-#define ID_CH    (0x00080000)    /* Choice                    */
+#define ID_PN    (0x00000000)  /* Page navigation           */
+#define ID_FN    (0x00010000)  /* Inter-Field navigation    */
+#define ID_IFN   (0x00020000)  /* Intra-Field navigation    */
+#define ID_VSC   (0x00030000)  /* Vertical Scrolling        */
+#define ID_HSC   (0x00040000)  /* Horizontal Scrolling      */
+#define ID_FE    (0x00050000)  /* Field Editing             */
+#define ID_EM    (0x00060000)  /* Edit Mode                 */
+#define ID_FV    (0x00070000)  /* Field Validation          */
+#define ID_CH    (0x00080000)  /* Choice                    */
 #define ID_Mask  (0xffff0000)
 #define Key_Mask (0x0000ffff)
 #define ID_Shft  (16)
 
 /* This array holds all the Binding Infos */
 #define ID_Mask  (0xffff0000)
 #define Key_Mask (0x0000ffff)
 #define ID_Shft  (16)
 
 /* This array holds all the Binding Infos */
-static const Binding_Info bindings[MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1] = 
+/* *INDENT-OFF* */
+static const Binding_Info bindings[MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1] =
 {
   { REQ_NEXT_PAGE    |ID_PN  ,PN_Next_Page},
   { REQ_PREV_PAGE    |ID_PN  ,PN_Previous_Page},
   { REQ_FIRST_PAGE   |ID_PN  ,PN_First_Page},
   { REQ_LAST_PAGE    |ID_PN  ,PN_Last_Page},
 {
   { REQ_NEXT_PAGE    |ID_PN  ,PN_Next_Page},
   { REQ_PREV_PAGE    |ID_PN  ,PN_Previous_Page},
   { REQ_FIRST_PAGE   |ID_PN  ,PN_First_Page},
   { REQ_LAST_PAGE    |ID_PN  ,PN_Last_Page},
-  
+
   { REQ_NEXT_FIELD   |ID_FN  ,FN_Next_Field},
   { REQ_PREV_FIELD   |ID_FN  ,FN_Previous_Field},
   { REQ_FIRST_FIELD  |ID_FN  ,FN_First_Field},
   { REQ_NEXT_FIELD   |ID_FN  ,FN_Next_Field},
   { REQ_PREV_FIELD   |ID_FN  ,FN_Previous_Field},
   { REQ_FIRST_FIELD  |ID_FN  ,FN_First_Field},
@@ -3574,7 +4277,7 @@ static const Binding_Info bindings[MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1] =
   { REQ_RIGHT_FIELD  |ID_FN  ,FN_Right_Field},
   { REQ_UP_FIELD     |ID_FN  ,FN_Up_Field},
   { REQ_DOWN_FIELD   |ID_FN  ,FN_Down_Field},
   { REQ_RIGHT_FIELD  |ID_FN  ,FN_Right_Field},
   { REQ_UP_FIELD     |ID_FN  ,FN_Up_Field},
   { REQ_DOWN_FIELD   |ID_FN  ,FN_Down_Field},
-  
+
   { REQ_NEXT_CHAR    |ID_IFN ,IFN_Next_Character},
   { REQ_PREV_CHAR    |ID_IFN ,IFN_Previous_Character},
   { REQ_NEXT_LINE    |ID_IFN ,IFN_Next_Line},
   { REQ_NEXT_CHAR    |ID_IFN ,IFN_Next_Character},
   { REQ_PREV_CHAR    |ID_IFN ,IFN_Previous_Character},
   { REQ_NEXT_LINE    |ID_IFN ,IFN_Next_Line},
@@ -3589,7 +4292,7 @@ static const Binding_Info bindings[MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1] =
   { REQ_RIGHT_CHAR   |ID_IFN ,IFN_Right_Character},
   { REQ_UP_CHAR      |ID_IFN ,IFN_Up_Character},
   { REQ_DOWN_CHAR    |ID_IFN ,IFN_Down_Character},
   { REQ_RIGHT_CHAR   |ID_IFN ,IFN_Right_Character},
   { REQ_UP_CHAR      |ID_IFN ,IFN_Up_Character},
   { REQ_DOWN_CHAR    |ID_IFN ,IFN_Down_Character},
-  
+
   { REQ_NEW_LINE     |ID_FE  ,FE_New_Line},
   { REQ_INS_CHAR     |ID_FE  ,FE_Insert_Character},
   { REQ_INS_LINE     |ID_FE  ,FE_Insert_Line},
   { REQ_NEW_LINE     |ID_FE  ,FE_New_Line},
   { REQ_INS_CHAR     |ID_FE  ,FE_Insert_Character},
   { REQ_INS_LINE     |ID_FE  ,FE_Insert_Line},
@@ -3598,36 +4301,37 @@ static const Binding_Info bindings[MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1] =
   { REQ_DEL_LINE     |ID_FE  ,FE_Delete_Line},
   { REQ_DEL_WORD     |ID_FE  ,FE_Delete_Word},
   { REQ_CLR_EOL      |ID_FE  ,FE_Clear_To_End_Of_Line},
   { REQ_DEL_LINE     |ID_FE  ,FE_Delete_Line},
   { REQ_DEL_WORD     |ID_FE  ,FE_Delete_Word},
   { REQ_CLR_EOL      |ID_FE  ,FE_Clear_To_End_Of_Line},
-  { REQ_CLR_EOF      |ID_FE  ,FE_Clear_To_End_Of_Form},
+  { REQ_CLR_EOF      |ID_FE  ,FE_Clear_To_End_Of_Field},
   { REQ_CLR_FIELD    |ID_FE  ,FE_Clear_Field},
   { REQ_CLR_FIELD    |ID_FE  ,FE_Clear_Field},
-  
+
   { REQ_OVL_MODE     |ID_EM  ,EM_Overlay_Mode},
   { REQ_INS_MODE     |ID_EM  ,EM_Insert_Mode},
   { REQ_OVL_MODE     |ID_EM  ,EM_Overlay_Mode},
   { REQ_INS_MODE     |ID_EM  ,EM_Insert_Mode},
-  
+
   { REQ_SCR_FLINE    |ID_VSC ,VSC_Scroll_Line_Forward},
   { REQ_SCR_BLINE    |ID_VSC ,VSC_Scroll_Line_Backward},
   { REQ_SCR_FPAGE    |ID_VSC ,VSC_Scroll_Page_Forward},
   { REQ_SCR_BPAGE    |ID_VSC ,VSC_Scroll_Page_Backward},
   { REQ_SCR_FHPAGE   |ID_VSC ,VSC_Scroll_Half_Page_Forward},
   { REQ_SCR_BHPAGE   |ID_VSC ,VSC_Scroll_Half_Page_Backward},
   { REQ_SCR_FLINE    |ID_VSC ,VSC_Scroll_Line_Forward},
   { REQ_SCR_BLINE    |ID_VSC ,VSC_Scroll_Line_Backward},
   { REQ_SCR_FPAGE    |ID_VSC ,VSC_Scroll_Page_Forward},
   { REQ_SCR_BPAGE    |ID_VSC ,VSC_Scroll_Page_Backward},
   { REQ_SCR_FHPAGE   |ID_VSC ,VSC_Scroll_Half_Page_Forward},
   { REQ_SCR_BHPAGE   |ID_VSC ,VSC_Scroll_Half_Page_Backward},
-  
+
   { REQ_SCR_FCHAR    |ID_HSC ,HSC_Scroll_Char_Forward},
   { REQ_SCR_BCHAR    |ID_HSC ,HSC_Scroll_Char_Backward},
   { REQ_SCR_HFLINE   |ID_HSC ,HSC_Horizontal_Line_Forward},
   { REQ_SCR_HBLINE   |ID_HSC ,HSC_Horizontal_Line_Backward},
   { REQ_SCR_HFHALF   |ID_HSC ,HSC_Horizontal_Half_Line_Forward},
   { REQ_SCR_HBHALF   |ID_HSC ,HSC_Horizontal_Half_Line_Backward},
   { REQ_SCR_FCHAR    |ID_HSC ,HSC_Scroll_Char_Forward},
   { REQ_SCR_BCHAR    |ID_HSC ,HSC_Scroll_Char_Backward},
   { REQ_SCR_HFLINE   |ID_HSC ,HSC_Horizontal_Line_Forward},
   { REQ_SCR_HBLINE   |ID_HSC ,HSC_Horizontal_Line_Backward},
   { REQ_SCR_HFHALF   |ID_HSC ,HSC_Horizontal_Half_Line_Forward},
   { REQ_SCR_HBHALF   |ID_HSC ,HSC_Horizontal_Half_Line_Backward},
-  
+
   { REQ_VALIDATION   |ID_FV  ,FV_Validation},
 
   { REQ_NEXT_CHOICE  |ID_CH  ,CR_Next_Choice},
   { REQ_PREV_CHOICE  |ID_CH  ,CR_Previous_Choice}
 };
   { REQ_VALIDATION   |ID_FV  ,FV_Validation},
 
   { REQ_NEXT_CHOICE  |ID_CH  ,CR_Next_Choice},
   { REQ_PREV_CHOICE  |ID_CH  ,CR_Previous_Choice}
 };
+/* *INDENT-ON* */
 
 /*---------------------------------------------------------------------------
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  int form_driver(FORM * form,int  c)
 |   Function      :  int form_driver(FORM * form,int  c)
-|   
+|
 |   Description   :  This is the workhorse of the forms system. It checks
 |                    to determine whether the character c is a request or
 |                    data. If it is a request, the form driver executes
 |   Description   :  This is the workhorse of the forms system. It checks
 |                    to determine whether the character c is a request or
 |                    data. If it is a request, the form driver executes
@@ -3646,213 +4350,655 @@ static const Binding_Info bindings[MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1] =
 |                    E_INVALID_FIELD   - field contents are invalid
 |                    E_BAD_STATE       - called from inside a hook routine
 |                    E_REQUEST_DENIED  - request failed
 |                    E_INVALID_FIELD   - field contents are invalid
 |                    E_BAD_STATE       - called from inside a hook routine
 |                    E_REQUEST_DENIED  - request failed
+|                    E_NOT_CONNECTED   - no fields are connected to the form
 |                    E_UNKNOWN_COMMAND - command not known
 +--------------------------------------------------------------------------*/
 NCURSES_EXPORT(int)
 |                    E_UNKNOWN_COMMAND - command not known
 +--------------------------------------------------------------------------*/
 NCURSES_EXPORT(int)
-form_driver (FORM * form, int  c)
+form_driver(FORM *form, int c)
 {
 {
-  const Binding_Info* BI = (Binding_Info *)0;
+  const Binding_Info *BI = (Binding_Info *) 0;
   int res = E_UNKNOWN_COMMAND;
 
   int res = E_UNKNOWN_COMMAND;
 
+  move_after_insert = true;
+
+  T((T_CALLED("form_driver(%p,%d)"), (void *)form, c));
+
   if (!form)
     RETURN(E_BAD_ARGUMENT);
 
   if (!form)
     RETURN(E_BAD_ARGUMENT);
 
-  if (!(form->field))
+  if (!(form->field) || !(form->current))
     RETURN(E_NOT_CONNECTED);
     RETURN(E_NOT_CONNECTED);
-  
+
   assert(form->page);
   assert(for