home *** CD-ROM | disk | FTP | other *** search
- /* ==( memo/inputt.c )== */
-
- /* ----------------------------------------------- */
- /* Pro-C Copyright (C) 1989 - 1990 Vestronix Inc. */
- /* Modification to this source is not supported */
- /* by Vestronix Inc. */
- /* All Rights Reserved */
- /* ----------------------------------------------- */
- /* Written JPK 1-May-89 */
- /* Modified Geo 12-Dec-89 See comments below */
- /* ----------------------------------------------- */
- /* %W% (%H% %T%) */
-
- /*
- * Modifications
- *
- * 16-Dec-89 JH - rewrite of input masks, bug fixes
- * 12-Dec-89 Geo - V2 version
- *
- */
-
- /*
- * Inputt.c contains the routines to implement text field inut. These include
- * mask validation, character input and validation and field formatting for
- * display.
- */
- # include <stdio.h>
- # include <bench.h>
- # include "field.h"
-
- # include <time.h>
-
- # ifndef MIN
- # define MIN(a,b) (a > b ? b : a)
- # endif
- # ifndef MAX
- # define MAX(a,b) (a < b ? b : a)
- # endif
-
- # ifdef ANSI
- static void int_disp_text(FIELD *, int, char *);
- static void expand_mask(char *, char *);
- static void build_display_buff(FIELD *, char *);
- static int power(int, int);
- static char *end_field(FIELD *, char *);
- static char *forward(FIELD *, char *);
- static char *backspace(FIELD *, char *);
- static void del_text_char(FIELD *);
- static void home_cursor(FIELD *);
- static void forward_cursor(FIELD *);
- static void back_cursor(FIELD *);
- static void put_cursor(FIELD *, int);
- static int check_char(int *, char *, FIELD *);
- static int realign_decimals(FIELD *, char *);
- static void scroll_field_left(FIELD *);
- static void scroll_field_right(void);
- static void set_negative_flag(char *);
- static void fill_mask(FIELD *, char *);
- static int endinput(int);
- static void setcur_shape(void);
- void home_field(FIELD *);
- int length_mask(FIELD *);
- static int text_mask(FIELD *, char);
- static void count_special_chars_in_mask(FIELD *, char *);
- # else
- static void int_disp_text();
- static void expand_mask();
- static void build_display_buff();
- static int power();
- static char *end_field();
- static char *forward();
- static char *backspace();
- static void del_text_char();
- static void home_cursor();
- static void forward_cursor();
- static void back_cursor();
- static void put_cursor();
- static int check_char();
- static int realign_decimals();
- static void scroll_field_left();
- static void scroll_field_right();
- static int text_mask();
- static void set_negative_flag();
- static void fill_mask();
- static int endinput();
- static void setcur_shape();
- void home_field();
- int length_mask();
- static void count_special_chars_in_mask();
- # endif
-
- int doing_memos = FALSE;
-
- /* static variables */
- static char *field_buffer; /* internal field buffer */
- static char display_buff[MAX_MASK]; /* display buff, should alloc dynamically */
- static char *disp_buff_ptr; /*points to current screen start of display_buff*/
- static int end_display; /* TRUE if leaving a field, display buffer in full*/
- static int field_negative;
- static int number_negative;
- static int num_special_chars_in_mask = 0;
-
- int field_overflow = FALSE;
- int cursor_col; /* column of cursor , used again in memo.c */
- int homed_field = FALSE;
-
- # ifdef MSDOS
- static int numlock_on;
- # endif
-
- extern int instos; /* inchar.c */
-
-
- static char *save_buff;
-
- # ifdef UNIX
- int input_wx(fld, va_alist)
- FIELD *fld;
- va_dcl
- # else
- int input_wx(FIELD *fld, int va_alist, ...)
- # endif
- {
- int key;
- int done = FALSE;
- va_list ap;
- int buff_len;
-
- /* save the fbuff, if K_ESC is hit we'll restore the buffer to its
- * previous contents
- */
- if (!doing_memos && (buff_len = strlen(fld->fbuff)) != 0)
- {
- /*
- * Coz' Jeff is an Egg. Memory got eaten.
- * This is pretty time consuming really, considering
- * this routine gets called many many times.
- */
- if (save_buff)
- free (save_buff);
- save_buff = (char *)alloc(buff_len + 1);
- bytecpy(save_buff, fld->fbuff, buff_len);
- }
-
- /* call the pre input function if it is defined */
- if (fld->f_pre)
- if ((*fld->f_pre)(fld) == FALSE)
- return(K_ESC);
-
- /* loop getting input until valid end key is pressed */
- while (TRUE)
- {
- if_bad_input:
- if (!fld->f_input)
- disp_text(fld, fld->fattrib_on);
- else
- ichar = (*fld->f_input)(fld);
-
- if (ichar == K_CR)
- {
- if (fld->f_val)
- if ((*fld->f_val)(fld) == FALSE)
- continue;
- break;
- }
- if (ichar == K_ESC)
- {
- if (!doing_memos && buff_len)
- bytecpy(fld->fbuff, save_buff, buff_len);
- break;
- }
-
- # ifdef UNIX
- va_start(ap);
- key = va_arg(ap, int);
- # else
- va_start(ap, va_alist);
- key = va_alist;
- # endif
-
- while (key != 0)
- {
- if (ichar == key)
- {
- if (fld->f_val)
- if ((*fld->f_val)(fld) == FALSE)
- goto if_bad_input;
- done = TRUE;
- }
- key = va_arg(ap, int);
- }
- va_end(ap);
-
-
- /* check if field has over flowed before continuing */
- if (field_overflow)
- done = TRUE;
-
- /* if we're done, then we're done - and I don't mean maybe */
- if (done)
- break;
-
- }
- if (ichar != K_ESC)
- {
- /* post input function */
- if (fld->f_post)
- (*fld->f_post)(fld);
- }
-
- /* set ichar to the exitcode and return */
- return(ichar);
- }
-
-
-
- /*
- * Display a field by building the output string and displaying it.
- */
- void disp_text(field, attr)
- FIELD *field;
- int attr;
- {
- char new_mask[256];
- int disp_length;
-
- if (!disp_buff_ptr)
- disp_buff_ptr = display_buff;
- num_special_chars_in_mask = 0;
-
- end_display = TRUE;
- expand_mask(field->fmask, new_mask);
- count_special_chars_in_mask(field, new_mask);
-
- /* need a routine to build the display string from the mask and the
- * buffer. Then simply display the buffer.
- */
- build_display_buff(field, new_mask);
- disp_length = length_mask(field);
-
- ndisp_w(field->frow, field->fcol, attr, disp_length, disp_buff_ptr);
- put_cursor(field, 0);
- }
-
- /*
- * disp_text for internal use only
- */
- static void int_disp_text(field, attr, mask)
- FIELD *field;
- int attr;
- char *mask;
- {
- int disp_length;
-
- /* need a routine to build the display string from the mask and the
- * buffer. Then simply display the buffer.
- */
- build_display_buff(field, mask);
- disp_length = length_mask(field);
-
- ndisp_w(field->frow, field->fcol, attr, disp_length, disp_buff_ptr);
- put_cursor(field, 0);
- }
-
-
- /*
- * Return a formatted string, built from the fields contents and mask.
- * Same as disp_text but don't display it
- */
- char *fmt_text(field)
- FIELD *field;
- {
- char new_mask[256];
-
- if (!disp_buff_ptr)
- disp_buff_ptr = display_buff;
-
- end_display = TRUE;
- expand_mask(field->fmask, new_mask);
-
- /* need a routine to build the display string from the mask and the
- * buffer. Then simply display the buffer.
- */
- build_display_buff(field, new_mask);
-
- return(disp_buff_ptr);
- }
-
-
- /*
- * Read in a text, numeric, date or memo field in from the keyboard
- */
- int text_input(field)
- FIELD *field;
- {
- char msk[MAX_MASK];
- char *mask;
- int c;
- int done = FALSE;
- int curstate;
- int did_money = FALSE; /* only bleep past first money symbol */
- int first_time_disp = TRUE;
-
- #ifdef MOUSE
-
- int mr, mc, mh, mw;
-
- abs_w(&mr, &mc, &mw, &mh);
- mouse_add_object(mr + field->frow, mc + field->fcol, mr + field->frow, mc + field->fcol + length_mask(field) - 1, 0, 0, "INPUT");
-
- #endif
-
- /* do the initial bits
- */
- curstate = cursor(ON);
- end_display = FALSE;
- field_overflow = FALSE;
- num_special_chars_in_mask = 0;
- disp_buff_ptr = display_buff;
- expand_mask(field->fmask, msk);
- mask = msk;
- set_negative_flag(mask);
- count_special_chars_in_mask(field, mask);
- if (field->ftype == F_TEXT)
- fill_mask(field, mask);
-
- if (field->ftype == F_NUMERIC && *field->fbuff == '-')
- {
- /* increment the fbuff past the negative sign, it gets in the way */
- move_text(field->fbuff, field->fbuff+1, strlen(field->fbuff)-1);
- number_negative = TRUE;
- }
- else
- number_negative = FALSE;
-
- clean_buffer(field);
- setcur_shape();
-
- if (!homed_field)
- home_field(field);
- else
- {
- int i;
- int fx;
- fx = field->fx;
- field->fx = 0;
-
- for (i=0; i<fx; i++)
- mask = forward(field, mask);
- homed_field = FALSE;
- }
-
-
- /* have a case for all of the characters possible for input
- */
- while (TRUE)
- {
-
- while (*mask)
- {
- int done = FALSE;
- char msk_sav = '\0';
-
- switch (text_mask(field, *mask))
- {
- case FILL :
- if (*mask == '*' && msk_sav == '*')
- {
- *mask = 'Z';
- done = TRUE;
- break;
- }
- msk_sav = *mask;
- forward_cursor(field);
-
- case SPECIAL :
- mask++;
- break;
-
- default :
- switch(*mask)
- {
- case '(' :
- case '-' :
- case ')' :
- if (*++mask)
- forward_cursor(field);
- break;
- case MASK_MONEY :
- if (!did_money)
- {
- if (*++mask)
- forward_cursor(field);
- did_money = TRUE;
- break;
- }
- default :
- done = TRUE;
- break;
- }
- break;
- }
- if (done)
- break;
- }
-
- int_disp_text(field, field->fattrib_on, msk);
- c = inchar();
-
- switch (c)
- {
- #ifdef MOUSE
- case M_PRESS :
- if (!mouse_check_bounds())
- break;
- case M_RELEASE :
- {
- int dummy;
- if (mouse_row == w_nrows)
- mouse_click(&dummy, c);
- else if (mouse_click(&dummy, M_PRESS))
- {
- if (c == M_PRESS)
- {
- dummy = cursor_col + mc;
- if (mouse_col > dummy)
- while (mouse_col > dummy++)
- {
- if (dummy > (mc + field->fcol + strlen(field->fbuff)))
- break;
- unget_inchar(K_RIGHT);
- }
- else if (mouse_col < dummy)
- while (mouse_col < dummy--)
- unget_inchar(K_LEFT);
- }
- }
- }
- break;
- #endif
- case K_HOME :
- if ((field->fcontrol&NO_HOME_END) != NO_HOME_END)
- {
- mask = msk;
- home_field(field);
- break;
- }
- else
- goto is_default;
-
- case K_END :
- if ((field->fcontrol&NO_HOME_END) != NO_HOME_END)
- {
- mask = msk;
- mask = end_field(field, mask);
- break;
- }
- else
- goto is_default;
-
- case K_RIGHT :
- if (!*field_buffer || field_buffer == field->fbuff + field->fieldlen + num_special_chars_in_mask || (doing_memos && field->fx == field->fieldlen+ num_special_chars_in_mask ))
- done = TRUE;
- else
- mask = forward(field, mask);
- break;
-
- case K_LEFT :
- case K_BS :
- if (field_buffer != field->fbuff)
- mask = backspace(field, mask);
- else
- done = TRUE;
- if (c == K_LEFT)
- break;
-
- case K_DEL :
- del_text_char(field);
- if (doing_memos && !strlen(field->fbuff))
- done = TRUE;
- break;
-
- case K_INS :
- instos ^= TRUE;
- setcur_shape();
- break;
-
- case K_F1 :
- help_msg(field->fhelp);
- break;
-
- case '-' :
- if (field->ftype ==F_NUMERIC && field_negative && c == '-')
- {
- number_negative ^= TRUE;
- break;
- }
-
- case '.' :
- /* make sure it is not a fall thru */
- if (field->ftype == F_NUMERIC && *mask != '.' && strchr(mask, '.') && c == '.')
- {
- /* move the data to the decimal */
- while (*mask != '.')
- {
- forward_cursor(field);
- mask++;
- }
- }
-
- case K_UP :
- case K_F4 :
- case K_DOWN :
- case K_F3 :
-
- default :
- is_default:
- if (endinput(c))
- {
- done = TRUE;
- end_display = TRUE;
- break;
- }
-
- if (*mask)
- {
- if (!check_char(&c, mask, field))
- {
- do_bell();
- break;
- }
- if (instos && strlen(field->fbuff) < field->fieldlen+ num_special_chars_in_mask )
- move_text(field_buffer+1, field_buffer, strlen(field_buffer)-1);
- }
- else
- {
- if ((field->fcontrol&OVERFLOW_RETURN) == OVERFLOW_RETURN)
- {
- field_overflow = TRUE;
- break;
- }
- else if ((field->fcontrol&CONFIRM_NEEDED) != CONFIRM_NEEDED)
- {
- /* quit and return K_CR to application */
- done = TRUE;
- c = K_CR;
- break;
- }
-
-
- mask = backspace(field, mask);
- if (!check_char(&c, mask, field))
- {
- errmsg("Invalid data entry - Please retry");
- mask = forward(field, mask);
- break;
- }
- }
- *field_buffer = (char) c;
- mask = forward(field, mask);
- if (!doing_memos && !*mask && (field->fcontrol&CONFIRM_NEEDED) != CONFIRM_NEEDED)
- /* last char in field, do overflow */
- field_overflow = TRUE;
- break;
- }
- if (done || field_overflow)
- break;
- }
- if (field->ftype == F_NUMERIC && !*field->fbuff)
- *field->fbuff = '0';
-
- disp_buff_ptr = display_buff;
- int_disp_text(field, field->fattrib_off, msk);
-
- if (number_negative)
- {
- move_text(field->fbuff+1, field->fbuff, strlen(field->fbuff)-1);
- *field->fbuff = '-';
- }
-
- # ifdef MOUSE
- mouse_delete_object(0, 0, "INPUT");
- # endif
- cursor(curstate);
- return c;
- }
-
- /*
- * Expand the mask field from any short forms to a string of format chars
- */
- static void expand_mask(mask, new_mask)
- char *mask;
- char *new_mask;
- {
- char *msk;
- char msk_sav;
- int num = 0;
- int i = 0;
-
- msk = mask;
- msk_sav = *msk;
-
- while(*msk)
- {
- if (*msk == '(' && *(msk-1) != HARDSPACE && *(msk-1) != MASK_SPECIAL && msk_sav != '(')
- {
- while (*msk && *msk != ')')
- msk++;
-
- /* parse format length out of msk string */
- msk--;
- while (*msk != '(')
- {
- num += (int)(*msk - '0') * power(10,i);
- msk--;
- i++;
- }
- while (*msk != ')')
- msk++;
-
- /* build up new format string */
- for (i=0; i<num-1; i++, new_mask++)
- *new_mask = msk_sav;
-
- i=0;
- num = 0;
- }
- else
- *new_mask++ = *msk;
-
- msk_sav = *msk++;
- }
- *new_mask = '\0';
-
- }
-
-
- /*
- * This routine takes the data buffer and together with the mask fills
- * the display buffer with the properly formatted data
- */
- static void build_display_buff(field, mask)
- FIELD *field;
- char *mask;
- {
- char *m = mask;
- char *b = field->fbuff;
- char *d = display_buff;
- char fill_char;
- int asterisk_fill = FALSE;
- int decimal_increment = 0;
- int save_decimal_inc = 0;
- int first_dollar = TRUE;
- int i;
-
- for (i=0; i<MAX_MASK; *d++ = HARDSPACE, i++);
- d = display_buff;
-
- if (field->ftype == F_NUMERIC)
- {
- decimal_increment = realign_decimals(field, m);
- save_decimal_inc = decimal_increment;
- }
-
- while (*m)
- {
- switch(text_mask(field, *m))
- {
- case TEMPLATE :
- switch (*m)
- {
- case MASK_YEAR :
- case MASK_MONTH :
- case MASK_DAY :
- case MASK_HOUR :
- case MASK_MINUTE :
- case MASK_SECOND :
- case MASK_WEEKDAY :
- case MASK_DAY_SUFFIX :
- if (field->ftype == F_DATE || field->ftype == F_TIME)
- *d++ = ( *b ? *b++ : *m);
- break;
-
- case MASK_8 :
- case MASK_z :
- case MASK_Z :
- if (field->ftype == F_NUMERIC)
- {
- if (asterisk_fill)
- fill_char = ASTERISK_FILL;
- else
- fill_char = HARDSPACE;
-
- *d++ = ( *b && *b != HARDSPACE && !decimal_increment ? *b : fill_char);
- if (*b && !decimal_increment)
- b++;
- if (decimal_increment)
- decimal_increment--;
- break;
- }
-
- case MASK_I :
- case MASK_C :
- case MASK_c :
- case MASK_P :
- case MASK_p :
- case MASK_Q :
- case MASK_A :
- case MASK_a :
- case MASK_B :
- case MASK_x :
- case MASK_X :
- case MASK_Y :
- *d++ = (*b && !decimal_increment ? *b : HARDSPACE);
- if (*b && !decimal_increment)
- b++;
- if (decimal_increment)
- decimal_increment--;
- break;
-
- case MASK_MONEY :
- /* the first one should always be reserved for DOLLAR_SIGN */
- if (first_dollar)
- {
- *d++ = DOLLAR_SIGN;
- first_dollar = FALSE;
- }
- else
- {
- *d++ = ( *b && !decimal_increment ? *b : DOLLAR_SIGN);
- if (*b && !decimal_increment)
- b++;
- }
- if (decimal_increment)
- decimal_increment--;
- break;
-
- case MASK_9 :
- if (end_display)
- fill_char = '0';
- else
- fill_char = HARDSPACE;
-
- if (field->ftype == F_NUMERIC)
- *d++ = ( *b && *b != HARDSPACE && !decimal_increment ?*b :fill_char);
- else
- *d++ = ( *b ? *b : HARDSPACE);
-
- if (*b && !decimal_increment)
- b++;
- if (decimal_increment)
- decimal_increment--;
- break;
-
- case '.' :
- *d++ = '.';
- if (*b && *b != '.')
- *display_buff = '?';
- if (*b)
- b++;
- break;
-
- case '(' :
- if (field->ftype ==F_NUMERIC &&field_negative &&number_negative)
- *d++ = '(';
- else
- *d++ = HARDSPACE;
- break;
-
- case ')' :
- if (field->ftype ==F_NUMERIC &&field_negative &&number_negative)
- *d++ = ')';
- else
- *d++ = HARDSPACE;
- break;
-
- case '-' :
- if (field->ftype ==F_NUMERIC &&field_negative &&number_negative)
- *d++ = '-';
- else
- *d++ = HARDSPACE;
- break;
-
- default :
- *d++ = HARDSPACE;
- break;
- }
- break;
-
- case PASSWORD :
- *d++ = ( *b ? '*' : HARDSPACE);
- if (*b)
- b++;
- break;
-
- case FILL :
- /* need bits here to handle fills and floats */
- if (field->ftype == F_NUMERIC && *m == '*' && *(m-1) == '*')
- {
- asterisk_fill = TRUE;
- *d++ = ( *b && !decimal_increment ? *b : '*');
- if (*b && !decimal_increment)
- b++;
- if (decimal_increment)
- decimal_increment--;
- }
- else if (*m == ',' && *(d-1) == HARDSPACE)
- *d++ = HARDSPACE;
- else if (*m == ',' && *(d-1) == DOLLAR_SIGN)
- *d++ = DOLLAR_SIGN;
- else if (*m == ',' && *(d-1) == '*')
- *d++ = '*';
- else
- *d++ = *m;
-
- case SPECIAL :
- default :
- break;
- }
- m++;
- }
- if (*b && isdigit(*b) && field->ftype == F_NUMERIC)
- *(display_buff+save_decimal_inc+1) = '?';
-
- *d = '\0';
- }
-
-
-
- /*
- * Simple routine to evaluate powers
- */
- static int power(x, y)
- int x, y;
- {
- int i = 0;
- int result = 1;
-
- while ( i<y )
- {
- result *= x;
- i++;
- }
- return(result);
- }
-
-
- /*
- * This routine calculates the character length of a mask
- */
- int length_mask(field)
- FIELD *field;
- {
- char new_mask[256];
- char *m;
- int msk_count = 0;
-
- /* if the mask has a ?(#) type of construction expand it */
- if (strchr(field->fmask, '('))
- expand_mask(field->fmask, new_mask);
- else
- strcpy(new_mask, field->fmask);
-
- m = new_mask;
-
- while (*m)
- {
- switch(text_mask(field, *m))
- {
- case PASSWORD :
- case TEMPLATE :
- if (field->ftype == F_NUMERIC)
- msk_count++;
- else
- if (*m != '(' && *m != ')' && *m != '-')
- msk_count++;
- break;
- case FILL :
- msk_count++;
- default :
- break;
- }
- m++;
- }
- return(msk_count);
- }
-
-
- /*
- * This routine moves the cursor to the beginning of the field
- */
- void home_field(field)
- FIELD *field;
- {
- field_buffer = field->fbuff;
- /*
- * start at column 0
- */
- field->fx = 0;
- disp_buff_ptr = display_buff;
-
- home_cursor(field);
- }
-
-
- /*
- * This routine moves the cursor to the end of the field
- */
- static char *end_field(field, mask)
- FIELD *field;
- char *mask;
- {
- field_buffer = field->fbuff;
- field->fx = 0;
- disp_buff_ptr = display_buff;
- home_cursor(field);
-
- /* forward() increments the field_buffer */
- while(*field_buffer && *mask && field->fx < field->fieldlen+ num_special_chars_in_mask )
- mask = forward(field, mask);
-
- return mask;
- }
-
-
- /*
- * This routine moves the cursor back one position
- */
- static char *backspace(field, mask)
- FIELD *field;
- char *mask;
- {
- field_buffer--;
- mask--;
- if (field->fx > 1)
- field->fx--;
-
- while (mask != field->fmask)
- {
- int done = FALSE;
-
- switch(text_mask(field, *mask))
- {
- case TEMPLATE :
- if (*mask == '-' || *mask == '(' || *mask == ')')
- mask--;
- else
- done = TRUE;
- break;
- case FILL :
- back_cursor(field);
- case SPECIAL :
- mask--;
- break;
- default :
- done = TRUE;
- break;
- }
- if (done)
- break;
- }
-
- /* scroll the text if possible */
- if ( cursor_col - field->fcol == 0)
- scroll_field_right();
- else
- {
- if (field_buffer == field->fbuff + field->fieldlen - 1)
- {
- if (cursor_col != field->fcol + MIN(field->fieldlen+ num_special_chars_in_mask, length_mask(field)) - 1)
- back_cursor(field);
- }
- else
- back_cursor(field);
- }
-
- return mask;
- }
-
-
- /*
- * This routine moves the cursor forward one space
- */
- static char *forward(field, mask)
- FIELD *field;
- char *mask;
- {
- field_buffer++;
- field->fx++;
-
- while (*mask)
- {
- int done = FALSE;
-
- switch(text_mask(field, *mask))
- {
- case FILL :
- forward_cursor(field);
- case SPECIAL :
- mask++;
- break;
- default :
- /* if it's negative move past that sign too */
- if (*mask == ')' || *mask == '(' || *mask == '-')
- {
- forward_cursor(field);
- mask++;
- }
- mask++;
- done = TRUE;
- break;
- }
- if (done)
- break;
- }
-
- /* if at end of display space do not move cursor,
- * scroll through field_buffer
- */
- if ( cursor_col - field->fcol + 1 >= length_mask(field))
- scroll_field_left(field);
- else if ( cursor_col - field->fcol +1 < length_mask(field))
- forward_cursor(field);
-
- return mask;
- }
-
-
- /*
- * This routine deletes a character from the buffer
- */
- static void del_text_char(field)
- FIELD *field;
- {
-
- int tmp_len;
-
- tmp_len = field->fieldlen + num_special_chars_in_mask - (field_buffer - field->fbuff) - 1;
- if (tmp_len < 0)
- tmp_len = 0;
-
- if (*field_buffer)
- {
- if (*field_buffer == '.')
- cursor_col = field->fcol + strlen(field->fbuff) - 1;
- if (tmp_len)
- move_text(field_buffer, field_buffer+1, tmp_len);
- field_buffer[tmp_len] = '\0';
- }
- }
-
-
- /*
- * The next two routines handle the scrolling. We have the display buffer
- * and a pointer to it. We increment and decrement the pointer to the
- * start of the display buffer and then display the buffer from the pointer
- */
- static void scroll_field_left(field)
- FIELD *field;
- {
- if (*disp_buff_ptr && strlen(disp_buff_ptr) > length_mask(field))
- disp_buff_ptr++;
- }
-
- static void scroll_field_right()
- {
- if (*disp_buff_ptr && disp_buff_ptr != display_buff)
- disp_buff_ptr--;
- }
-
-
-
- /*
- * The next 4 routines handle the cursor position. We keep the cursor
- * column in a static variable so that moving the cursor becomes
- * an elementary task, so long as the cursor_col variable does not
- * get screwed up.
- */
-
- static void put_cursor(field, pos)
- FIELD *field;
- int pos;
- {
- if (pos)
- cursor_col = pos;
- moveto_w(field->frow, cursor_col);
- }
-
- static void forward_cursor(field)
- FIELD *field;
- {
- cursor_col++;
- moveto_w(field->frow, cursor_col);
- }
-
- static void back_cursor(field)
- FIELD *field;
- {
- cursor_col--;
- moveto_w(field->frow, cursor_col);
- }
-
- static void home_cursor(field)
- FIELD *field;
- {
- cursor_col = field->fcol;
- moveto_w(field->frow, cursor_col);
- }
-
-
- /*
- * Check that an input character is valid by looking at the current mask
- * character.
- */
- static int check_char(c, mask, field)
- int *c;
- char *mask;
- FIELD *field;
- {
- if (*mask == MASK_I)
- return(TRUE);
-
- if (!isprint(*c))
- return(FALSE);
-
- switch(*mask)
- {
- case MASK_C :
- /* alphabetic - convert to lower case */
- if (isupper(*c))
- *c = tolower(*c);
- if (isalpha(*c))
- return(TRUE);
- return(FALSE);
- case MASK_c :
- /* alphanumeric - convert to lower case */
- if (isalpha(*c) && isupper(*c))
- *c = tolower(*c);
- if (isalpha(*c) || isdigit(*c) || *c == '_')
- return(TRUE);
- return(FALSE);
- case MASK_X :
- /* any character - convert to upper case */
- if (islower(*c))
- *c = toupper(*c);
- case MASK_x :
- /* any character */
- return(TRUE);
- case MASK_Y :
- /* any character - convert to lower case */
- if (isupper(*c))
- *c = tolower(*c);
- return(TRUE);
- case MASK_P :
- /* alphanumeric - convert to upper case */
- if (isalpha(*c) && islower(*c))
- *c = toupper(*c);
- case MASK_p :
- /* alphanumeric */
- if (isalpha(*c) || isdigit(*c) || *c == '_' || isspace(*c))
- return(TRUE);
- return(FALSE);
- case MASK_Q :
- /* alphanumeric - convert to lower case */
- if (isalpha(*c) && isupper(*c))
- *c = tolower(*c);
- if (isalpha(*c) || isdigit(*c) || *c == '_' || isspace(*c))
- return(TRUE);
- return(FALSE);
- case MASK_A :
- /* alphabetic - convert to upper case */
- if (islower(*c))
- *c = toupper(*c);
- case MASK_a :
- if (isalpha(*c) || isspace(*c))
- return(TRUE);
- return(FALSE);
- case MASK_B :
- /* alphabetic - convert to lower case */
- if (isupper(*c))
- *c = tolower(*c);
- if (isalpha(*c) || isspace(*c))
- return(TRUE);
- return(FALSE);
- case MASK_8 :
- if (isdigit(*c) || (*c == '.' && !strchr(field->fbuff, '.')))
- return(TRUE);
- return(FALSE);
- case MASK_MONEY :
- case MASK_9 :
- case MASK_Z :
- case MASK_z :
- /* numeric */
- if (isdigit(*c))
- return(TRUE);
- return(FALSE);
- case MASK_AT :
- return(TRUE);
- case MASK_PSWD :
- if (*c == HARDSPACE)
- return(FALSE);
- return(TRUE);
- case '.' :
- if (*c == '.')
- return(TRUE);
- return(FALSE);
- case MASK_YEAR :
- case MASK_MONTH :
- case MASK_DAY :
- case MASK_HOUR :
- case MASK_MINUTE :
- case MASK_SECOND :
- case MASK_WEEKDAY :
- case MASK_DAY_SUFFIX :
- if (isdigit(*c))
- return(TRUE);
- return(FALSE);
- default :
- return(FALSE);
- }
- }
-
-
- static int realign_decimals(field, mask)
- FIELD *field;
- char *mask;
- {
- int buf_count= 0;
- int msk_count= 0;
- int move_amount = 0;
- char *tmp1;
- char *m = mask;
-
- if (*field->fbuff)
- tmp1 = strchr(field->fbuff, '.');
- if (tmp1)
- buf_count = (int)(tmp1 - field->fbuff);
- else
- {
- if (end_display)
- buf_count = strlen(field->fbuff);
- else
- return 0;
- }
-
- while (*m)
- {
- int done = FALSE;
-
- switch (text_mask(field, *m))
- {
- case TEMPLATE :
- if (*m == '.' )
- done = TRUE;
- if (*m != '.' && *m != '-' && *m != ')' && *m != '(')
- msk_count++;
- break;
- case FILL :
- if (*m == '*' && *(m-1) == '*')
- msk_count++;
- default :
- break;
- }
- if (done)
- break;
- m++;
- }
-
- move_amount = msk_count - buf_count;
- if (move_amount < 0)
- move_amount = 0;
-
- return move_amount;
- }
-
- /*
- *
- */
- static void count_special_chars_in_mask(field, mask)
- FIELD *field;
- char *mask;
- {
- char *tmp_mask;
-
- tmp_mask = mask;
-
- while(*tmp_mask)
- {
- switch(*tmp_mask)
- {
- case '(' :
- case ')' :
- case '-' :
- case ' ' :
- if (field->ftype != F_DATE)
- num_special_chars_in_mask++;
- default:
- break;
- }
- tmp_mask++;
- }
-
- }
-
-
- /*
- * Check the front of the input mask to see if dollar or asterisk fill / float
- * are desired during input of a numeric or calculator field
- */
- static void set_negative_flag(smask)
- char *smask;
- {
-
- field_negative = FALSE;
-
- # ifdef MSDOS
- /* set numlock flag */
- numlock_on = FALSE;
- if (*smask == '&')
- {
- numlock_on = TRUE;
- smask++;
- }
- # endif
-
- /* set the negative flags */
- if (*smask == '-' || *smask == '(' || *(smask + strlen(smask) -1) == '-' )
- field_negative = TRUE;
-
- }
-
-
- void clean_buffer(field)
- FIELD *field;
- {
- char *b = field->fbuff;
- int fill_with_null = FALSE;
- int i;
- for (i=0; i<field->fieldlen && i<MAX_MASK; i++)
- {
- if (!*b || (field->ftype == F_NUMERIC && *b == ' '))
- fill_with_null = TRUE;
-
- *b = ( fill_with_null ? '\0' : *b);
- b++;
- }
- if (field->ftype == F_NUMERIC && *field->fbuff == '0')
- *field->fbuff = '\0';
- }
-
-
- static void fill_mask(field, mask)
- FIELD *field;
- char *mask;
- {
- char *m = mask;
- char msk_sav;
- int i;
-
- i = strlen(m);
- if (i > field->fieldlen + num_special_chars_in_mask)
- m[field->fieldlen + num_special_chars_in_mask] = '\0';
- else if ( i < field->fieldlen && i > 1)
- {
- m += i-1;
- msk_sav = *m++;
- while ( i < field->fieldlen && i < MAX_MASK)
- {
- *m++ = msk_sav;
- i++;
- }
- *m = '\0';
- }
-
- }
-
-
-
- /*
- * Check a character against all the valid mask characters for a text type
- * of field
- */
- static int text_mask(fld, c)
- FIELD *fld;
- char c;
- {
- static int special = FALSE;
-
- /* check if c is a valid mask character */
- if (fld->ftype == F_NUMERIC)
- {
- switch (c)
- {
- case MASK_8 :
- case MASK_MONEY :
- case MASK_9 :
- case MASK_Z :
- case MASK_z :
- return(special ? FILL : TEMPLATE);
- case MASK_SPECIAL :
- special ^= TRUE;
- return(SPECIAL);
- default :
- switch (c)
- {
- case '.' :
- case '-' :
- case '(' :
- case ')' :
- return(TEMPLATE);
- default :
- return(FILL);
- }
- }
- }
- else if (fld->ftype == F_TEXT)
- {
- switch (c)
- {
- case MASK_I :
- case MASK_C :
- case MASK_c :
- case MASK_x :
- case MASK_X :
- case MASK_Y :
- case MASK_P :
- case MASK_p :
- case MASK_Q :
- case MASK_a :
- case MASK_A :
- case MASK_B :
- case MASK_8 :
- case MASK_MONEY :
- case MASK_9 :
- case MASK_Z :
- case MASK_z :
- case MASK_AT :
- return(special ? FILL : TEMPLATE);
- case MASK_PSWD :
- return(special ? FILL : PASSWORD);
- case MASK_SPECIAL :
- special ^= TRUE;
- return(SPECIAL);
- default :
- return(FILL);
- }
- }
- else /* F_DATE or F_TIME */
- {
- switch (c)
- {
- case MASK_YEAR :
- case MASK_MONTH :
- case MASK_DAY :
- case MASK_HOUR :
- case MASK_MINUTE :
- case MASK_SECOND :
- case MASK_WEEKDAY :
- case MASK_DAY_SUFFIX :
- return(special ? FILL : TEMPLATE);
- case MASK_SPECIAL :
- special ^= TRUE;
- return(SPECIAL);
- default :
- return(FILL);
- }
- }
- }
-
-
- /*
- * Test to see if a character is a end of input character
- */
- static int endinput(c)
- int c;
- {
- switch (c)
- {
- case K_CR :
- case K_ESC :
- case K_UP :
- case K_DOWN :
- case K_RIGHT :
- case K_LEFT :
- case K_PGUP :
- case K_PGDN :
- case K_HOME :
- case K_END :
- case K_TAB :
- /*
- case K_BTAB :
- */
- case K_F1 :
- case K_F2 :
- case K_F3 :
- case K_F4 :
- case K_F5 :
- case K_F6 :
- case K_F7 :
- case K_F8 :
- case K_F9 :
- case K_F10 :
- return TRUE;
- default:
- return FALSE;
- }
- }
-
- /*
- * Set the cursor shape.
- */
- # ifdef MSDOS
- # include "../win/dos/pregs.h"
- # endif
-
- /* keep in os dependent code */
- static void setcur_shape()
- {
- # ifdef MSDOS
-
- RegStorage;
- unsigned int cursor_size;
-
- /* set instos for inchar() and set the shape of the cursor */
- cursor_size = (instos ? 0x0106 : 0x0607);
-
- Regs_ah = 0x01;
- Regs_cx = cursor_size;
- Video();
-
- # endif
- }
-
- /*
- * Move specified amount of text to destination from source. Do the move
- * intelligently by checking which memory location is greater.
- * (from GEO.)
- */
- void move_text(dest, src, cnt)
- char *dest;
- char *src;
- int cnt;
- {
- int i;
- if (src == NULL || dest == NULL)
- return;
- if (src == dest)
- return;
- if (src < dest)
- /* Move up */
- for (i = cnt; i >= 0; i--)
- *(dest+i) = *(src+i);
- else
- /* Move down */
- for (i = 0; i <= cnt; i++)
- *(dest+i) = *(src+i);
- }
-