Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libform * Rototilled internals to make multiline fields ...



details:   https://anonhg.NetBSD.org/src/rev/87394fb6dcdb
branches:  trunk
changeset: 509746:87394fb6dcdb
user:      blymn <blymn%NetBSD.org@localhost>
date:      Fri May 11 14:04:48 2001 +0000

description:
* Rototilled internals to make multiline fields work correctly.  Some
  bugs remain such as vertical scrolling is not working and the field
  is not correctly redrawn after being cleared.  There are bound to be
  others.

diffstat:

 lib/libform/driver.c    |    5 +-
 lib/libform/field.c     |   29 +-
 lib/libform/form.c      |    9 +-
 lib/libform/form.h      |    7 +-
 lib/libform/internals.c |  722 +++++++++++++++++++++++++++++------------------
 lib/libform/internals.h |   16 +-
 6 files changed, 486 insertions(+), 302 deletions(-)

diffs (truncated from 1231 to 300 lines):

diff -r b9fbdb9d626c -r 87394fb6dcdb lib/libform/driver.c
--- a/lib/libform/driver.c      Fri May 11 13:59:43 2001 +0000
+++ b/lib/libform/driver.c      Fri May 11 14:04:48 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: driver.c,v 1.7 2001/04/06 04:40:43 blymn Exp $ */
+/*     $NetBSD: driver.c,v 1.8 2001/05/11 14:04:48 blymn Exp $ */
 
 /*-
  * Copyright (c) 1998-1999 Brett Lymn
@@ -119,7 +119,8 @@
        if (c < REQ_MIN_REQUEST) {
                if (isprint(c)) {
                        do {
-                               pos = fieldp->start_char + fieldp->cursor_xpos;
+                               pos = fieldp->start_char + fieldp->cursor_xpos
+              + fieldp->lines[fieldp->start_line + fieldp->cursor_ypos].start;
 
                              /* check if we are allowed to edit this field */
                                if ((fieldp->opts & O_EDIT) != O_EDIT)
diff -r b9fbdb9d626c -r 87394fb6dcdb lib/libform/field.c
--- a/lib/libform/field.c       Fri May 11 13:59:43 2001 +0000
+++ b/lib/libform/field.c       Fri May 11 14:04:48 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: field.c,v 1.9 2001/04/06 05:24:59 blymn Exp $  */
+/*     $NetBSD: field.c,v 1.10 2001/05/11 14:04:48 blymn Exp $ */
 /*-
  * Copyright (c) 1998-1999 Brett Lymn
  *                         (blymn%baea.com.au@localhost, brett_lymn%yahoo.com.au@localhost)
@@ -70,6 +70,8 @@
        NULL, /* type struct for the field */
        {NULL, NULL}, /* circle queue glue for sorting fields */
        NULL, /* args for field type. */
+       0,    /* number of allocated slots in lines array */
+       NULL, /* pointer to the array of lines structures. */
        NULL, /* array of buffers for the field */
 };
 
@@ -282,7 +284,8 @@
                return E_BAD_ARGUMENT;
 
        len = strlen(value);
-       if (((field->opts & O_STATIC) == O_STATIC) && (len > field->cols))
+       if (((field->opts & O_STATIC) == O_STATIC) && (len > field->cols)
+           && ((field->rows + field->nrows) == 1))
                len = field->cols;
                
        if ((field->buffers[buffer].string =
@@ -293,7 +296,10 @@
        field->buffers[buffer].length = len;
        field->buffers[buffer].allocated = len + 1;
        field->row_count = 1; /* must be at least one row */
-
+       field->lines[0].start = 0;
+       field->lines[0].end = (len > 0)? (len - 1) : 0;
+       field->lines[0].length = len;
+       
          /* we have to hope the wrap works - if it does not then the
             buffer is pretty much borked */
        status = _formi_wrap_field(field, 0);
@@ -592,12 +598,27 @@
          /* Initialise the strings to a zero length string */
        for (i = 0; i < nbuf + 1; i++) {
                if ((new->buffers[i].string =
-                    (char *) malloc(sizeof(char))) == NULL)
+                    (char *) malloc(sizeof(char))) == NULL) {
+                       free(new->buffers);
+                       free(new);
                        return NULL;
+               }
                new->buffers[i].string[0] = '\0';
                new->buffers[i].length = 0;
                new->buffers[i].allocated = 1;
        }
+
+       if ((new->lines = (_FORMI_FIELD_LINES *)
+            malloc(sizeof(struct _formi_field_lines))) == NULL) {
+               free(new->buffers);
+               free(new);
+               return NULL;
+       }
+
+       new->lines_alloced = 1;
+       new->lines[0].length = 0;
+       new->lines[0].start = 0;
+       new->lines[0].end = 0;
        
        return new;
 }
diff -r b9fbdb9d626c -r 87394fb6dcdb lib/libform/form.c
--- a/lib/libform/form.c        Fri May 11 13:59:43 2001 +0000
+++ b/lib/libform/form.c        Fri May 11 14:04:48 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: form.c,v 1.6 2001/04/06 05:24:59 blymn Exp $   */
+/*     $NetBSD: form.c,v 1.7 2001/05/11 14:04:48 blymn Exp $   */
 
 /*-
  * Copyright (c) 1998-1999 Brett Lymn
@@ -536,17 +536,14 @@
 data_ahead(FORM *form)
 {
        FIELD *cur;
-       int end;
        
        if ((form == NULL) || (form->fields == NULL)
            || (form->fields[0] == NULL))
                return FALSE;
 
        cur = form->fields[form->cur_field];
-       end = _formi_find_eol(cur->buffers[0].string,
-                             cur->start_char + cur->cursor_xpos);
-       if ((end - cur->start_char - cur->cursor_xpos)
-           > cur->cols)
+       
+       if (cur->lines[cur->start_line + cur->cursor_ypos].length > cur->cols)
                return TRUE;
 
        return FALSE;
diff -r b9fbdb9d626c -r 87394fb6dcdb lib/libform/form.h
--- a/lib/libform/form.h        Fri May 11 13:59:43 2001 +0000
+++ b/lib/libform/form.h        Fri May 11 14:04:48 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: form.h,v 1.11 2001/04/06 05:24:59 blymn Exp $  */
+/*     $NetBSD: form.h,v 1.12 2001/05/11 14:04:48 blymn Exp $  */
 
 /*-
  * Copyright (c) 1998-1999 Brett Lymn
@@ -182,6 +182,8 @@
 
 typedef struct _formi_page_struct _FORMI_PAGE_START;
 typedef struct formi_type_link_struct _FORMI_TYPE_LINK;
+typedef struct _formi_field_lines _FORMI_FIELD_LINES;
+
 
 typedef void (*Form_Hook)(FORM *);
 
@@ -221,6 +223,9 @@
        FIELDTYPE *type; /* type struct for the field */
        CIRCLEQ_ENTRY(_form_field) glue; /* circle queue glue for sorting fields */
        char *args; /* args for field type. */
+       unsigned int lines_alloced; /* number of slots allocated in lines
+                                      array */
+       _FORMI_FIELD_LINES *lines; /* array of the starts and ends of lines */
        FORM_STR *buffers; /* array of buffers for the field */
 };
 
diff -r b9fbdb9d626c -r 87394fb6dcdb lib/libform/internals.c
--- a/lib/libform/internals.c   Fri May 11 13:59:43 2001 +0000
+++ b/lib/libform/internals.c   Fri May 11 14:04:48 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: internals.c,v 1.14 2001/04/06 05:03:22 blymn Exp $     */
+/*     $NetBSD: internals.c,v 1.15 2001/05/11 14:04:48 blymn Exp $     */
 
 /*-
  * Copyright (c) 1998-1999 Brett Lymn
@@ -29,10 +29,12 @@
  *
  */
 
+#include <limits.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <strings.h>
+#include <assert.h>
 #include "internals.h"
 #include "form.h"
 
@@ -56,12 +58,15 @@
 #define JOIN_PREV    3
 #define JOIN_PREV_NW 4 /* previous join, don't wrap the joined line */
 
+/* for the bump_lines function... */
+#define _FORMI_USE_CURRENT -1 /* indicates current cursor pos to be used */
+
 static void
 _formi_do_char_validation(FIELD *field, FIELDTYPE *type, char c, int *ret_val);
 static void
 _formi_do_validation(FIELD *field, FIELDTYPE *type, int *ret_val);
 static int
-_formi_join_line(FIELD *field, char *str, unsigned int pos, int direction);
+_formi_join_line(FIELD *field, unsigned int pos, int direction);
 void
 _formi_hscroll_back(FIELD *field, unsigned int amt);
 void
@@ -73,7 +78,12 @@
 static int
 find_sow(char *str, unsigned int offset);
 static int
-find_cur_line(FIELD *cur);
+find_cur_line(FIELD *cur, unsigned pos);
+static int
+split_line(FIELD *field, unsigned pos);
+static void
+bump_lines(FIELD *field, int pos, int amt);
+
 
 /*
  * Open the debug file if it is not already open....
@@ -95,6 +105,57 @@
 #endif
 
 /*
+ * Bump the lines array elements in the given field by the given amount.
+ * The row to start acting on can either be inferred from the given position
+ * or if the special value _FORMI_USE_CURRENT is set then the row will be
+ * the row the cursor is currently on.
+ */
+static void
+bump_lines(FIELD *field, int pos, int amt)
+{
+       int i, row;
+#ifdef DEBUG
+       int dbg_ok = FALSE;
+#endif
+
+       if (pos == _FORMI_USE_CURRENT)
+               row = field->start_line + field->cursor_ypos;
+       else
+               row = find_cur_line(field, (unsigned) pos);
+
+#ifdef DEBUG
+       if (_formi_create_dbg_file() == E_OK) {
+               dbg_ok = TRUE;
+               fprintf(dbg, "bump_lines: bump starting at row %d\n", row);
+               fprintf(dbg,
+                       "bump_lines: len from %d to %d, end from %d to %d\n",
+                       field->lines[row].length,
+                       field->lines[row].length + amt,
+                       field->lines[row].end, field->lines[row].end + amt);
+       }
+#endif
+               
+       field->lines[row].length += amt;
+       if (field->lines[row].length > 1)
+               field->lines[row].end += amt;
+       for (i = row + 1; i < field->row_count; i++) {
+#ifdef DEBUG
+               if (dbg_ok) {
+                       fprintf(dbg,
+               "bump_lines: row %d: len from %d to %d, end from %d to %d\n",
+                               i, field->lines[i].start,
+                               field->lines[i].start + amt,
+                               field->lines[i].end,
+                               field->lines[i].end + amt);
+               }
+               fflush(dbg);
+#endif
+               field->lines[i].start += amt;
+               field->lines[i].end += amt;
+       }
+}
+
+/*
  * Set the form's current field to the first valid field on the page.
  * Assume the fields have been sorted and stitched.
  */
@@ -192,24 +253,27 @@
  * Find the line in a field that the cursor is currently on.
  */
 static int
-find_cur_line(FIELD *cur)
+find_cur_line(FIELD *cur, unsigned pos)
 {
-       unsigned start, end, pos, row;
-       const char *str;
+       unsigned row;
 
-       str = cur->buffers[0].string;
-       pos = cur->start_char + cur->cursor_xpos;
+         /* first check if pos is at the end of the string, if this
+          * is true then just return the last row since the pos may
+          * not have been added to the lines array yet.
+          */
+       if (pos == (cur->buffers[0].length - 1))
+               return (cur->row_count - 1);
        
-       start = 0;
-       end = 0;
-       
-       for (row = 1; row < cur->row_count; row++) {
-               start = _formi_find_bol(str, start);
-               end = _formi_find_eol(str, end);
-               if ((pos >= start) && (pos <= end))
+       for (row = 0; row < cur->row_count; row++) {
+               if ((pos >= cur->lines[row].start)
+                   && (pos <= cur->lines[row].end))
                        return row;
        }
 
+#ifdef DEBUG
+         /* barf if we get here, this should not be possible */
+       assert((row != row));
+#endif
        return 0;
 }
 
@@ -223,147 +287,235 @@
 int
 _formi_wrap_field(FIELD *field, unsigned int pos)
 {



Home | Main Index | Thread Index | Old Index