]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - form/frm_driver.c
ncurses 5.4
[ncurses.git] / form / frm_driver.c
index c9275f7e51625e0fea28eb7b0799aed67c9b5a13..9de28eeabbd3aa8770d2bbfc6a9aa137cad8d35f 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2002,2003 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            *
 
 /****************************************************************************
  *   Author:  Juergen Pfeifer, 1995,1997                                    *
- *   Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en             *
  ****************************************************************************/
+
 #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.45 2003/12/06 17:22:42 tom Exp $")
 
 /*----------------------------------------------------------------------------
   This is the core module of the form library. It contains the majority
@@ -42,7 +42,7 @@ MODULE_ID("$Id: frm_driver.c,v 1.39 2002/07/06 15:33:27 juergen Exp $")
   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:
 
@@ -55,10 +55,10 @@ MODULE_ID("$Id: frm_driver.c,v 1.39 2002/07/06 15:33:27 juergen Exp $")
    c)   Intra-Field Navigation     ( all functions prefixed by IFN_ )
         The current position in the current field is changed. 
    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_ )
-        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
@@ -79,11 +79,11 @@ 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,
-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.
 
-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
@@ -91,9 +91,9 @@ 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.
 */
 
-/* Implement a more user-friendly previous/next word behaviour */
+/* Implement a more user-friendly previous/next word behavior */
 #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)
@@ -150,7 +150,7 @@ static int FE_Delete_Previous(FORM *);
 #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) || \
@@ -316,7 +316,7 @@ INLINE static void Adjust_Cursor_Position(FORM * form, const char * pos)
 |                                      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.
 |
@@ -642,7 +642,7 @@ _nc_Refresh_Current_Field (FORM * form)
                      0);
            }
          else
-           { /* A multiline, i.e. vertical scrolling field */
+           { /* A multi-line, i.e. vertical scrolling field */
              int row_after_bottom,first_modified_row,first_unmodified_row;
 
              if (field->drows > field->rows)
@@ -918,7 +918,7 @@ static int Synchronize_Field(FIELD * field)
 |   
 |   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
 |                    E_BAD_ARGUMENT      - invalid field pointer 
@@ -1012,7 +1012,7 @@ _nc_Synchronize_Attributes (FIELD * field)
 |   
 |   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
 |                    E_BAD_ARGUMENT      - invalid field pointer 
@@ -1089,7 +1089,7 @@ _nc_Synchronize_Options
              (!single_line_field && (field->drows < field->maxgrow)))
            {
              field->status |= _MAY_GROW;
-             /* a field with justification now changes its behaviour,
+             /* a field with justification now changes its behavior,
                 so we must redisplay it */
              if (single_line_field                 &&
                  (field->just != NO_JUSTIFICATION) &&
@@ -1217,7 +1217,7 @@ _nc_Set_Current_Field
 |   Facility      :  libnform  
 |   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
@@ -1255,7 +1255,7 @@ static int IFN_Next_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 
+|                    multi-line field this wraps and the beginning of the 
 |                    line.
 |
 |   Return Values :  E_OK                - success
@@ -1342,7 +1342,7 @@ static int IFN_Next_Word(FORM * form)
   Synchronize_Buffer(form);
 
   /* Go to the first whitespace after the current position (including
-     current position). This is then the startpoint to look for the
+     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));
@@ -1436,7 +1436,7 @@ static int IFN_Beginning_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
-|                    the buffer, the cursos is positioned on the last 
+|                    the buffer, the cursor is positioned on the last 
 |                    character.
 |
 |   Return Values :  E_OK              - success
@@ -1656,7 +1656,7 @@ static int VSC_Generic(FORM *form, int lines)
 |   
 |   Description   :  Performs the generic vertical scrolling routines. 
 |                    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
 +--------------------------------------------------------------------------*/
@@ -2056,7 +2056,7 @@ static int Insert_String(FORM *form, int row, char *txt, int len)
 |                    the wrapping.
 |
 |   Return Values :  E_OK              - no wrapping required or wrapping
-|                                        was successfull
+|                                        was successful
 |                    E_REQUEST_DENIED  -
 |                    E_SYSTEM_ERROR    - some system error
 +--------------------------------------------------------------------------*/
@@ -2130,7 +2130,7 @@ static int Wrapping_Not_Necessary_Or_Wrapping_Ok(FORM * form)
 |   
 |   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.
 |
@@ -2141,7 +2141,7 @@ static int Field_Editing(int (* const fct) (FORM *), FORM * form)
   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.
+     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.
@@ -2205,6 +2205,7 @@ static int FE_New_Line(FORM * form)
        {
          if (!(form->opts & O_NL_OVERLOAD))
            return(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,
@@ -2221,6 +2222,7 @@ static int FE_New_Line(FORM * form)
                 a single-line field */
              return(E_SYSTEM_ERROR);
            }
+         wmove(form->w,form->currow,form->curcol);
          wclrtoeol(form->w);
          form->currow++;
          form->curcol = 0;
@@ -2248,6 +2250,7 @@ static int FE_New_Line(FORM * form)
          
          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++;
          form->curcol=0;
@@ -2338,6 +2341,7 @@ static int FE_Insert_Line(FORM * form)
 +--------------------------------------------------------------------------*/
 static int FE_Delete_Character(FORM * form)
 {
+  wmove(form->w,form->currow,form->curcol);
   wdelch(form->w);
   return E_OK;
 }
@@ -2378,6 +2382,7 @@ static int FE_Delete_Previous(FORM * form)
       if ((int)(this_end-this_line) > 
          (field->cols-(int)(prev_end-prev_line))) 
        return E_REQUEST_DENIED;
+      wmove(form->w,form->currow,form->curcol);
       wdeleteln(form->w);
       Adjust_Cursor_Position(form,prev_end);
       wmove(form->w,form->currow,form->curcol);
@@ -2455,20 +2460,22 @@ static int FE_Delete_Word(FORM * form)
 +--------------------------------------------------------------------------*/
 static int FE_Clear_To_End_Of_Line(FORM * form)
 {
+  wmove(form->w,form->currow,form->curcol);
   wclrtoeol(form->w);
   return E_OK;
 }
 
 /*---------------------------------------------------------------------------
 |   Facility      :  libnform  
-|   Function      :  static int FE_Clear_To_End_Of_Form(FORM * form)
+|   Function      :  static int FE_Clear_To_End_Of_Field(FORM * form)
 |   
-|   Description   :  Clear to end of form.
+|   Description   :  Clear to end of field.
 |
 |   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)
 {
+  wmove(form->w,form->currow,form->curcol);
   wclrtobot(form->w);
   return E_OK;
 }
@@ -2903,20 +2910,20 @@ INLINE static FIELD *Sorted_Previous_Field(FIELD * field)
 
 /*---------------------------------------------------------------------------
 |   Facility      :  libnform  
-|   Function      :  static FIELD *Left_Neighbour_Field(FIELD * field)
+|   Function      :  static FIELD *Left_Neighbor_Field(FIELD * field)
 |   
-|   Description   :  Get the left neighbour of the field on the same line
+|   Description   :  Get the left neighbor of the field on the same 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)
+INLINE static FIELD *Left_Neighbor_Field(FIELD * 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
-     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).
   */
   do
@@ -2929,18 +2936,18 @@ INLINE static FIELD *Left_Neighbour_Field(FIELD * field)
 
 /*---------------------------------------------------------------------------
 |   Facility      :  libnform  
-|   Function      :  static FIELD *Right_Neighbour_Field(FIELD * field)
+|   Function      :  static FIELD *Right_Neighbor_Field(FIELD * field)
 |   
-|   Description   :  Get the right neighbour of the field on the same line
+|   Description   :  Get the right neighbor of the field on the same line
 |                    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)
+INLINE static FIELD *Right_Neighbor_Field(FIELD * 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);
@@ -2951,18 +2958,18 @@ INLINE static FIELD *Right_Neighbour_Field(FIELD * field)
 
 /*---------------------------------------------------------------------------
 |   Facility      :  libnform  
-|   Function      :  static FIELD *Upper_Neighbour_Field(FIELD * field)
+|   Function      :  static FIELD *Upper_Neighbor_Field(FIELD * field)
 |   
 |   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.
 |
-|   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;
@@ -2998,18 +3005,18 @@ static FIELD *Upper_Neighbour_Field(FIELD * field)
 
 /*---------------------------------------------------------------------------
 |   Facility      :  libnform  
-|   Function      :  static FIELD *Down_Neighbour_Field(FIELD * field)
+|   Function      :  static FIELD *Down_Neighbor_Field(FIELD * field)
 |   
 |   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.
 |
-|   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;
@@ -3053,7 +3060,7 @@ static FIELD *Down_Neighbour_Field(FIELD * field)
 |                                           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.
@@ -3216,7 +3223,7 @@ static int FN_Sorted_Last_Field(FORM * form)
 static int FN_Left_Field(FORM * form)
 {
   return _nc_Set_Current_Field(form,
-                              Left_Neighbour_Field(form->current));
+                              Left_Neighbor_Field(form->current));
 }
 
 /*---------------------------------------------------------------------------
@@ -3232,16 +3239,16 @@ static int FN_Left_Field(FORM * form)
 static int FN_Right_Field(FORM * form)
 {
   return _nc_Set_Current_Field(form,
-                              Right_Neighbour_Field(form->current));
+                              Right_Neighbor_Field(form->current));
 }
 
 /*---------------------------------------------------------------------------
 |   Facility      :  libnform  
 |   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
-|                    Upper_Neighbour_Field function to understand how
+|                    Upper_Neighbor_Field function to understand how
 |                    'upper' is defined. 
 |
 |   Return Values :  E_OK            - success
@@ -3250,16 +3257,16 @@ static int FN_Right_Field(FORM * form)
 static int FN_Up_Field(FORM * form)
 {
   return _nc_Set_Current_Field(form,
-                              Upper_Neighbour_Field(form->current));
+                              Upper_Neighbor_Field(form->current));
 }
 
 /*---------------------------------------------------------------------------
 |   Facility      :  libnform  
 |   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
-|                    Down_Neighbour_Field function to understand how
+|                    Down_Neighbor_Field function to understand how
 |                    'down' is defined. 
 |
 |   Return Values :  E_OK            - success
@@ -3268,7 +3275,7 @@ static int FN_Up_Field(FORM * form)
 static int FN_Down_Field(FORM * form)
 {
   return _nc_Set_Current_Field(form,
-                              Down_Neighbour_Field(form->current));
+                              Down_Neighbor_Field(form->current));
 }
 /*----------------------------------------------------------------------------
   END of Field Navigation routines 
@@ -3284,7 +3291,7 @@ static int FN_Down_Field(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
@@ -3366,7 +3373,7 @@ INLINE static int Previous_Page_Number(const FORM * form)
 |                                               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,
@@ -3598,7 +3605,7 @@ 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_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_OVL_MODE     |ID_EM  ,EM_Overlay_Mode},
@@ -3785,7 +3792,7 @@ set_field_buffer
                           (int)(1 + (vlen-len)/((field->rows+field->nrow)*field->cols))))
            RETURN(E_SYSTEM_ERROR);
 
-         /* in this case we also have to check, wether or not the remaining
+         /* in this case we also have to check, whether or not the remaining
             characters in value are also printable for buffer 0. */
          if (buffer==0)
            {
@@ -3802,7 +3809,7 @@ set_field_buffer
   p   = Address_Of_Nth_Buffer(field,buffer);
 
 #if HAVE_MEMCCPY
-  s = memccpy(p,value,0,len);
+  s = (char *) memccpy(p, value, 0, len);
 #else
   for(s=(char *)value; *s && (s < (value+len)); s++)
     p[s-value] = *s;