#include "cwindows.h" #include #include #include #include #include #include #include #include "rti815.h" #include "winplus.h" #define SPACE ' ' int creat_virtual_screen(VSCREEN **v, unsigned width, unsigned height) { int i = 1; /* ATTEMPT TO ALLOCATE MEMORY FOR THE VIRTUAL SCREEN DESCRIPTOR BLOCK */ *v = (VSCREEN *) calloc(1,sizeof(VSCREEN)); if (*v == NULL) return (-1); /* ATTEMPT TO ALLOCATE MEMORY FOR OUR WINDOW */ /* allow for attribute byte */ /* here on the original it was a "farcalloc" call not defined in MSC */ (*v) -> p_buf = (char huge *) calloc((long) width*height,sizeof(int)); if ((*v)-> p_buf == NULL) { free(*v); return (-2); } (*v)->width = width; (*v)->height = height; (*v)->cursor_row = 0; (*v)->cursor_col = 0; while (vs_chain[i] != NULL && i < MAX_SCREENS) i++; if (i == MAX_SCREENS) return (-3); vs_chain[i] = *v; (*v)->id = i; /* 02/02/90 THESE ARE ADITIONAL INITIALIZATIONS NOT DONE ON THE ORIGINAL */ (*v)->vbegin = NULL; /* no position on the window assigned */ (*v)->wfcol = 0; (*v)->wfrow = 0; (*v)->p_colors = NULL; /* no colors yet */ (*v)->p_win = NULL; /* no window assigned yet */ (*v)->pf = NULL; /* no fields associatedd yet */ (*v)->cursor_top = 0; /* top scan line */ (*v)->cursor_bot = 0; /* bottom scan line */ (*v)->p_format = NULL; /* no format yet */ return (i); } int edit_err(char *errmes) { make_sound(784.0,0.25); } /* int edit_err(char *errmes) { WINDOW *erwin; COLORS ercols; BORDER erbord; SHADOW ershad; int erwidth, erheight, erxpos, erypos = 18; erwidth = strlen(errmes) + 6; erheight = 5; erxpos = 78-erwidth; cursor_off(); create_window (&erwin, erwidth, erheight); shadow_window(erwin, &ershad, BOTTOM_RIGHT, black, SPACE); border_window(erwin, &erbord, DOUBLE, SINGLE, black, white); clear_window(erwin, &ercols, black, white, SPACE); display_window(erwin, erxpos, erypos, 1); w_prints(erwin, CENTER, 1, red + blink, white, "E R R O R !!!"); w_prints(erwin, CENTER, 2, black, white, errmes); pause(2); hide_window(erwin); free_window_memory(erwin); clear_kbd(); return (FALSE); /* assign FALSE to OK } */ /**************************************************************************/ /* */ /* FUNCTION : */ /* */ /* ABSTRACT : */ /* */ /* ARGUMENTS : */ /* */ /* COMMENTS : */ /* */ /* CREATION : ver. 1.0 Efstratios D. Varkaris 12/08/87 */ /* */ /* REVISION : */ /* */ /**************************************************************************/ /* creat_field -- Creates a data-entry field in a virtual screen. Arguments: FIELD **pf -- a pointer to the address of the structure for this field. VSCREEN *vs -- pointer to the virtual screen to display field. COLORS *pc -- pointer to the colors for the field. int (*p_e)() -- pointer to the error routine. int *a_n -- pointer to the array of neutral keys; int id -- id of this field; char *fs -- ptr. to the format string. Return value: -1 FIELD structure does not exist; -2 VSCREEN structure does not exist; -3 insufficient memory; */ int creat_field(FIELD *pf, VSCREEN *vs, COLORS *pc, int (*p_e)(), int *a_n, int id, int col, int row, char *fs) { int i, j=0, count; char *literal, *lmark; /* CONFIRM THAT VIRTUAL SCREEN EXISTS */ if (vs == NULL) return (-2); /* CONFIRM THAT FIELD STRUCTURE EXISTS */ if (pf == NULL) return (-1); lmark = literal = (char *) calloc(1, MAX_COLS); if (lmark == NULL) return (-3); /* INITIALIZE THE STRUCTURE */ pf->pvs = vs; pf->p_colors = pc; pf->p_uerr = p_e; pf->a_n = a_n; pf->id = id; pf->template = fs; pf->ccol = 0; pf->len = MAX_COLS; /* temporary value */ pf->col = col; pf->row = row; /* 02/01/90 INIT THE NEXT POINTER AS WELL SO THAT SECOND RUN NO LOCK */ pf->next = NULL; /* 02/02/90 THE FOLLOWING FIELDS WERE NOT INITIALIZED IN THE ORIGINAL */ pf->bch = SPACE; /* default background char */ pf->secret = FALSE; /* no secret field otherwise crashes the f_putc_ */ pf->p_uentry = NULL; /* else crashes when try to execute */ pf->p_uexit = NULL; /* else crashes when try to execute */ pf->p_keys = NULL; /* later it takes a global array */ /* ADD A FORMAT STRING -- IF DESIRED */ vs_cursor(vs, pf->col, pf->row); while (*fs != NULL) { while (*fs != '%') { if (!*fs) break; *literal++ = *fs; f_putc_(pf, pc->fc, pc->bc, (int) *fs++); j++; } if (*fs != NULL) { if (isdigit(*++fs)) { /* here seems to be the problem */ /* count = (*fs & 0XF) - 1; */ /* convert to digit */ count = atoi(fs) -1; /* my statement */ for (i=0; i < count; i++) f_putc_(pf, pc->fc, pc->bc, SPACE); for (i=0; i < count; i++) *literal++ = SPACE; j+=count; fs++; } f_putc_(pf, pc->fc, pc->bc, SPACE); *literal++ = SPACE; j++; ++fs; if (*fs == '.') fs++; if (isdigit(*fs)) fs++; if (*fs == 'f') fs++; } } pf->len = j; /* CREATE MEMORY FOR THE STORED CONTENTS, LITERAL FIELD AND FIELD FRAME */ pf->text = (char *) calloc(1, pf->len+1); if (pf->text == NULL) { free(lmark); return (-3); } pf->frame = (char *) calloc(1, pf->len+1); if (pf->frame == NULL) { free(lmark); free(pf->text); return (-3); } pf->literal = (char *) calloc(1, pf->len+1); if (pf->literal == NULL) { free(lmark); free(pf->text); free(pf->frame); return (-3); } strncpy(pf->literal, lmark, (size_t) pf->len); free(lmark); add_field_(vs, pf); f_cursor(pf, 0, 0); return (0); } /**************************************************************************/ /* */ /* FUNCTION : */ /* */ /* ABSTRACT : */ /* */ /* ARGUMENTS : */ /* */ /* COMMENTS : */ /* */ /* CREATION : ver. 1.0 Efstratios D. Varkaris 12/08/87 */ /* */ /* REVISION : */ /* */ /**************************************************************************/ int read_field(FIELD *f, int fc, int bc, char *fs) { int width, subset, i, pos; int precision, OK, digit, addkey; char *pf, *psub; /* ptr. to format string and subset string */ char *pfr, *pl, *pt; /* ptr. to frame, literal and text of field */ int key; int scan; char *mark; /* pointer to mark a position in the format string */ /* array to handle in/out of fields with "." 01-15-90 Stratos */ static int infraction[25]; /* position the format string pointer on the first character */ pf = fs; pfr = f->frame; pl = f->literal; pt = f->text; f->template = fs; f_cursor(f, 0, 0); /* extra code to handle the "." for each field 01-15-90 */ if (f->text[0] == '\0') infraction[f->id] = FALSE; while (*pf) { adjust_cursor_size_(); /* find the beginning of the first format specification ("%") */ while (*pf != '%') { if (!*pf) return (0); f_putc_(f, fc, bc, (int) *pf); *pfr++ = '0'; *pl++ = *pf; ++pf; } ++pf; /* increment past '%' symbol */ *pfr = '1'; /* denote start of field in frame */ /* CHECK FOR A WIDTH FIELD */ digit = FALSE; width = 0; /* error !! with atoi */ /* if (isdigit(*pf)) while (isdigit(*pf)) { width += atoi(pf++); digit = TRUE; } */ if (isdigit(*pf)) { width = atoi(pf); digit = TRUE; while (isdigit(*pf)) pf++; } else width = 1; /* CHECK FOR A DECIMAL POINT */ /* error again */ /* precision = 0; if (*pf == '.') if (isdigit(*++pf)) precision = atoi(pf++); */ precision = 0; if (*pf == '.') { pf++; precision = atoi(pf); while (isdigit(*pf)) pf++; } /* CHECK FOR A SUBSET CHARACTER SPECIFIER */ subset = FALSE; if (*pf == '[') { psub = pf; psub++; while (*pf != ']') pf++; /* increment to closing brace */ pf++; /* increment to conversion operand */ subset = TRUE; } OK = addkey = FALSE; switch(*pf) { case 'c': /* character sought */ do { adjust_cursor_size_(); /* GET A KEYSTROKE */ scan = _bios_keybrd(_KEYBRD_READ); key = scan & 0XFF; /* EXECUTE THIS USER FUNCTION ON ENTRY */ if (f->p_uentry != NULL) addkey = (*f->p_uentry)(f, &scan, &key); else addkey = FALSE; if (!addkey) { /* ESCAPE KEY -- EXIT */ if (((scan == f->p_keys->esckey) || (scan == END) || (scan == ENTER) || (scan == UP_ARROW) || (scan == DOWN_ARROW)) && digit) { while (width--) if (*pl++ == SPACE) { if (*pfr != '1') *pfr = '2'; pfr++; } /* CHECK THAT WE CAN EXIT (NO SUBSEQUENT FIELDS */ mark = pf; while (*mark) if (*mark++ != '%') continue; if (*mark == '\0') return (scan); } /* LEFT ARROW KEY */ else if (scan == f->p_keys->left_key) {} /* RIGHT ARROW KEY */ else if (scan == f->p_keys->right_key) {} /* TEST FOR A NEUTRAL CHARACTER ENTERED */ else if (isneutral(f->a_n, scan, key)) OK = FALSE; /* TEST IF KEY IS IN A SUBSET (IF DECLARED) */ else if (subset) { addkey = in_set_(psub, key); if (addkey) f_putc_(f, fc, bc, key); else { if (f->p_uerr != NULL) { OK = (*f->p_uerr)(f, &scan, &key); } else { return (EOF); } } } else if (key) { f_putc_(f, fc, bc, key); addkey = TRUE; } } /* DECREMENT THE WIDTH AND ADD THE KEY TO THE FIELD */ if (OK || addkey) { width--; if (width) { OK = FALSE; digit = TRUE; } if (addkey) { *pt++ = (char) key; if (*pfr != '1') *pfr = '2'; *pl++ = (char) key; ++pfr; } } /* EXECUTE THIS USER FUNCTION ON EXIT */ if (f->p_uexit != NULL) (*f->p_uexit)(f, &scan, &key); } while (!OK && width); break; case 'd': /* disgit(s) sought */ do { /* get at least one valid key */ adjust_cursor_size_(); scan = _bios_keybrd(_KEYBRD_READ); key = scan & 0XFF; /* EXECUTE THIS USER FUNCTION ON ENTRY */ if (f->p_uentry != NULL) addkey = (*f->p_uentry)(f, &scan, &key); else addkey = FALSE; if (!addkey) { /* ESCAPE KEY -- EXIT ONLY IF AT LEAST ONE DIGIT ENTERED */ if (((scan == f->p_keys->esckey) || (scan == END) || (scan == ENTER) || (scan == UP_ARROW) || (scan == DOWN_ARROW)) && digit) { mark = pf; while (*mark) if (*mark++ != '%') continue; if (*mark == '\0') return (scan); else width = 0; /* force exit to next field */ } /* LEFT ARROW KEY */ else if (scan == f->p_keys->left_key) {} /* RIGHT ARROW KEY */ else if (scan == f->p_keys->right_key) {} /* TEST FOR A NEUTRAL CHARACTER ENTERED */ else if (isneutral(f->a_n, scan, key)) OK = FALSE; /* TEST IF KEY IS IN A SUBSET (IF DECLARED) */ else if (isdigit(key)) { if (subset) { addkey = in_set_(psub, key); /* validate */ if (addkey) f_putc_(f, fc, bc, key); else { if (f->p_uerr != NULL) OK = (*f->p_uerr)(f, &scan, &key); else return (EOF); } } else { f_putc_(f, fc, bc, key); addkey = TRUE; } } else { if (f->p_uerr != NULL) OK = (*f->p_uerr)(f, &scan, &key); else return (EOF); } } if (OK || addkey) { width--; if (width) { OK = FALSE; digit = TRUE; } if (addkey) { *pt++ = (char) key; if (*pfr != '1') *pfr = '2'; *pl++ = (char) key; pfr++; } } /* EXECUTE THIS USER FUNCTION ON EXIT */ if (f->p_uexit != NULL) (*f->p_uexit)(f, &scan, &key); } while (!OK && width); break; /****************************************/ /**************************************** * from this point on it's modified just * for the CAL lab requirements. * * 01-15-90 Stratos ****************************************/ case 'f': /*float sought */ do { /* get at least one valid key */ adjust_cursor_size_(); scan = _bios_keybrd(_KEYBRD_READ); key = scan & 0XFF; /* EXECUTE THIS USER FUNCTION ON ENTRY */ if (f->p_uentry != NULL) { addkey = (*f->p_uentry)(f, &scan, &key); } else { addkey = FALSE; } if (!addkey) { /* @@@ use more than one escape keys @@@/ /* ESCAPE KEY -- IMMEDIATE EXIT */ if (((scan == f->p_keys->esckey) || (scan == END) || (scan == ENTER) || (scan == UP_ARROW) || (scan == DOWN_ARROW)) && digit) { mark = pf; while (*mark) { if (*mark++ != '%') continue; } if (*mark == '\0') { return (scan); } else { width = 0; /* force exit to next field */ } /* TEST FOR A NEUTRAL CHARACTER ENTERED */ } else if (isneutral(f->a_n, scan, key)) { OK = FALSE; /* F1 ENTERED=> CALL HELP FUNCTION */ } else if (scan == F1) { OK = FALSE; display_help(); /* LEFT ARROW KEY */ } else if (scan == f->p_keys->left_key) { if (f->ccol == 0) { (*f->p_uerr)(f, &scan, &key); edit_err("You are at the beginning of the field"); } else { width++; pt--; pl--; f->ccol--; f_cursor(f, f->ccol, 0); } /* RIGHT ARROW KEY */ } else if (scan == f->p_keys->right_key) { if (*pt == '\0') { (*f->p_uerr)(f, &scan, &key); edit_err("No other characters to edit"); } else { width--; pt++; pl++; f->ccol++; f_cursor(f, f->ccol, 0); } /* DEL KEY -- SHIFT ALL CHARS TO THE LEFT */ } else if (scan == f->p_keys->delete_key) { i =f->ccol; pos = f->ccol; if (f->text[i] == '.') infraction[f->id] = FALSE; while ((f->text)[i] != '\0') { (f->text)[i] = (f->text)[i + 1]; (f->literal)[i] = (f->literal)[i + 1]; f_putc_(f, fc, bc, (f->text)[i]); i++; } f->ccol = pos; f_cursor(f, f->ccol, 0); /* BACKSPACE KEY -- MOVE LEFT ONCE AND APPLY DEL KEY */ } else if (scan == BCKSPACE) { if (f->ccol == 0) { (*f->p_uerr)(f, &scan, &key); edit_err("You are at the beginning of the field"); } else { width++; pt--; pl--; f->ccol--; f_cursor(f, f->ccol, 0); i =f->ccol; pos = f->ccol; if (f->text[i] == '.') infraction[f->id] = FALSE; while ((f->text)[i] != '\0') { (f->text)[i] = (f->text)[i + 1]; (f->literal)[i] = (f->literal)[i + 1]; f_putc_(f, fc, bc, (f->text)[i]); i++; } f->ccol = pos; f_cursor(f, f->ccol, 0); } /* SIGNS ENTERED CHECK IF AT THE BEGINNING OF THE FIELD */ } else if ((key == '-') || (key == '+')) { if (f->ccol != 0) { (*f->p_uerr)(f, &scan, &key); edit_err("Signs not allowed at this position"); } else { f_putc_(f, fc, bc, key); addkey = TRUE; if (*pt == '.') infraction[f->id] = FALSE; } /* A PERIOD -- START OF THE PRECISION */ } else if (key == '.') { if ((!infraction[f->id]) || (*pt == '.')) { infraction[f->id] = TRUE; f_putc_(f, fc, bc, key); addkey = TRUE; } else { (*f->p_uerr)(f, &scan, &key); edit_err("Must delete previous decimal point first"); } /* TEST IF KEY IS IN A SUBSET (IF DECLARED) */ } else if (isdigit(key)) { if (subset) { addkey = in_set_(psub, key); /* validate */ if (addkey) { f_putc_(f, fc, bc, key); } else { if (f->p_uerr != NULL) { OK = (*f->p_uerr)(f, &scan, &key); } else { return (EOF); } } } else { if (*pt == '.') infraction[f->id] = FALSE; f_putc_(f, fc, bc, key); addkey = TRUE; } /* UNACCEPTED CHARACTER: WARN THE USER */ } else { if (f->p_uerr != NULL) { OK = (*f->p_uerr)(f, &scan, &key); edit_err("Invalid key pressed"); } else { return (EOF); } } } /* end of if (!addkey) rules */ if (OK || addkey) { width--; /* for this work precision updating is disabled */ /* if (infraction[f->id]) { if (precision-- == 0) OK = TRUE; } */ if (addkey) { *pt++ = (char) key; if (*pfr != '1') *pfr = '2'; *pl++ = (char) key; pfr++; } } /* EXECUTE THIS USER FUNCTION ON EXIT */ if (f->p_uexit != NULL) (*f->p_uexit)(f, &scan, &key); } while (!OK && width); break; /* end of float */ default : break; } pf++; } return (scan); } /**************************************************************************/ /* */ /* FUNCTION : */ /* */ /* ABSTRACT : */ /* */ /* ARGUMENTS : */ /* */ /* COMMENTS : */ /* */ /* CREATION : ver. 1.0 Efstratios D. Varkaris 12/08/87 */ /* */ /* REVISION : */ /* */ /**************************************************************************/ FIELD_ATTRIB *store_attr(FIELD *f, int fcolor, int bcolor, char *ftemplat) { FIELD_ATTRIB *faptr; if ((faptr = (FIELD_ATTRIB *)malloc(1 * sizeof(FIELD_ATTRIB))) == NULL) { perror("Disaster! Out of memory allocating FIELD_ATTRIB\n"); exit(-1); } faptr->fieldptr = f; faptr->forcol = fcolor; faptr->backcol = bcolor; faptr->template = ftemplat; return(faptr); } int read_selection(WINDOW *wnum) { int scan, key; int i, j, DONE = FALSE; BYTE tchar; do { scan = _bios_keybrd(_KEYBRD_READ); key = scan & 0X00FF; /* ESCAPE */ if (scan == wnum->p_popup->p_keys->esckey) DONE = TRUE; /* CALL USER-DEFINED FUNCTION #1 */ else if (scan == wnum->p_popup->p_keys->user_key1) (*p_user_popup1)(wnum, (scan << 8) || key); /* CALL USER-DEFINED FUNCTION #2 */ else if (scan == wnum->p_popup->p_keys->user_key2) (*p_user_popup2)(wnum, (scan << 8) || key); /* TOP */ else if (scan == wnum->p_popup->p_keys->topkey) select_item(wnum, 0); /* BOTTOM */ else if (scan == wnum->p_popup->p_keys->bottomkey) select_item(wnum, wnum->p_popup->nod - 1); /* SELECT ITEM -- RETURN ITEM SELECTED */ else if (scan == wnum->p_popup->p_keys->selectkey) { if (wnum->p_vs) return (wnum->p_vs->wfrow + wnum->cursor_row); else return (wnum->cursor_row); } /* UP ONE ROW */ else if (scan == wnum->p_popup->p_keys->upkey) { if (wnum->cursor_row) select_item(wnum, wnum->cursor_row-1); else if (wnum->p_vs) { scroll_window(wnum, -1, 0, 0); select_item(wnum, wnum->cursor_row); } else select_item(wnum, wnum->p_popup->nod - 1); } /* DOWN ONE ROW */ else if (scan == wnum->p_popup->p_keys->downkey) { if (wnum->cursor_row < wnum->p_popup->nod - 1) select_item(wnum, wnum->cursor_row+1); else if (wnum->p_vs) { scroll_window(wnum, 1, 0, 0); select_item(wnum, wnum->cursor_row); } else select_item(wnum, 0); } /* UP ONE PAGE */ else if (scan == wnum->p_popup->p_keys->pgupkey) { if (wnum->p_vs) { scroll_window(wnum, -(wnum->p_popup->nod-1), 0, 0); select_item(wnum, wnum->cursor_row); } } /* DOWN ONE PAGE */ else if (scan == wnum->p_popup->p_keys->pgdnkey) { if (wnum->p_vs) { scroll_window(wnum, wnum->p_popup->nod-1, 0, 0); select_item(wnum, wnum->cursor_row); } } /* HIGHLIGHTED CHARACTER */ else if (!wnum->p_vs) for (i=0; i <= wnum->p_popup->max_item; i++) { if((*wnum->p_popup->hchar)[i] != EMPTY) { tchar = (BYTE) *((*wnum->p_popup->text)[i] + (*wnum->p_popup->hchar)[i]); if (toupper(key) == toupper(tchar)) { select_item(wnum, i); return (wnum->cursor_row); } } } else if (wnum->p_vs) { j = wnum->p_vs->wfrow; for (i=j; i < j + wnum->p_popup->nod; i++) { if((*wnum->p_popup->hchar)[i] != EMPTY) { tchar = (BYTE) *((*wnum->p_popup->text)[i] + (*wnum->p_popup->hchar)[i]); if (toupper(key) == toupper(tchar)) { select_item(wnum, i - j); return (wnum->p_vs->wfrow + wnum->cursor_row); } } } } /* UNKNOWN KEYSTROKE */ else { ERROR_KEY = TRUE; /* set global error flag */ return (scan); } } while (!DONE); return (-1); } void fre_virtual_screen_memory(VSCREEN *p_vs) { vs_chain[p_vs->id] = NULL; /* here in the original there was a "farfree" call not defined in MSC */ free((char huge *) p_vs->p_buf); /* free the buffer space */ free((VSCREEN *) p_vs); /* free the POPUP structure */ } /* ISNEUTRAL_ -- Tests whether key pressed is one that should NOT be printed but should NOT produce an error. Arguments: int *neutrals -- pointer to an array of the neutral characters; int scan -- key scan code; int key -- key ascii code; Return value: TRUE (non-zero) if the key is neutral; 0 otherwise; */ int isneutral(int *neutrals, int scan, int key) { do { if ((*neutrals == scan) || (*neutrals == key)) return(TRUE); } while (*(++neutrals)); return(FALSE); }