home *** CD-ROM | disk | FTP | other *** search
- /*
- fntoggle.c 10/02/87
-
- % toggle_funcs
-
- Toggle Functions:
- A field has multiple choices.
- The Space bar changes the selection.
- The Variable is the number of the selected choice.
-
- The choices are contained in the field's second data pointer in
- the form "choice 1, choice 2, choice 3" (commas delimit).
-
- The cursor is turned off.
-
- Also toggles choice when clicked with a mouse.
- (if mouse handler is attached to sed)
-
- C-scape 3.2
- Copyright (c) 1986, 1987, 1988 by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 3/31/88 jmd Removed tinkering of static strings
- 4/06/88 jmd added call to sed_DoSpecial
- 4/13/88 jmd changed MAX_FIELD_LEN to MAX_CHOICE_LEN
- 9/15/88 jmd removed vid_Cursor calls
- 9/17/88 jmd added std_ funcs
- 10/09/88 jmd added SED_ABORT support
- 10/14/88 jdc added var_size element to field_funcs_struct
- 12/14/88 jdc removed pointer subtraction from toggle_GetNextChoice()
- 12/20/88 jmd fixed missing entry problem, added mouse support
-
- 2/07/89 jmd added char * cast
- 4/10/89 jmd added oakpriv.h
- 6/07/89 jmd added test for mouse code (later removed)
-
- 11/29/89 jmd added casts for DG
- 3/28/90 jmd ansi-fied
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
-
- #include "cscape.h"
- #include "fnfunc.h" /* for field functions */
- #include "scancode.h"
-
- #include "oakpriv.h" /* for memmove() macro */
-
- #define DELIMITER ','
-
- OSTATIC void toggle_GetNextChoice(char *list, char *string, char *curr, int slen);
-
- #define MAX_CHOICE_LEN 80 /* maximum length of a choice */
-
- OGLOBAL field_funcs_struct toggle_funcs = {
- stdNoCur_fenter,
- std_fexit,
- toggle_fkey,
- string_senter,
- string_sexit,
- VAR_STRING
- };
-
- void toggle_fkey(sed_type sed)
- /*
- Cycle through list of changes when the SPACE bar is pressed.
- (or when mouse is clicked on the field)
- */
- {
- int scancode;
- char s[MAX_CHOICE_LEN + 1];
- char *list;
- int fieldno;
-
- scancode = kb_Read();
-
- if (sed_DoSpecial(sed, scancode))
- return;
- if (special_key(sed, scancode))
- return;
- if (inter_field(sed, scancode))
- return;
- if (inter_page(sed, scancode))
- return;
-
- switch(scancode) {
- case 0: /* this case is just here to trick certain compilers */
- default:
- if (scancode == MOU_CLICK || (ascii(scancode)) == ' ') {
- fieldno = sed_GetFieldNo(sed);
- if ((list = (char *) sed_GetFieldData(sed, fieldno, 1)) != NULL) {
- toggle_GetNextChoice(list, s,
- sed_GetCurrRecord(sed), sed_GetRecordLen(sed, fieldno));
- sed_SetCurrRecord(sed, s);
- sed_UpdateCurrField(sed);
- }
- }
- }
-
- /* reset baton */
- sed_SetBaton(sed, -1);
- }
-
- static void toggle_GetNextChoice(char *list, char *string, char *curr, int slen)
- /*
- Copies the next choice from the list into string.
- Returns string.
- List is of the form:
- "choice 1,choice 2,choice 3" (commas delimit).
- Note: assumes that string is at least MAX_CHOICE_LEN + 1 chars long.
- */
- {
- int off, word_off;
- int len1, len;
- boolean found;
- char *start;
-
- /* skip leading DELIMITERS */
- for (off = 0; list[off] == DELIMITER; off++) {
- ;
- }
-
- start = &list[off];
-
- for (word_off = off, len1 = -1, found = FALSE;; off++) {
-
- if (list[off] == DELIMITER || list[off] == '\0') {
- if ( (len = off - word_off) > MAX_CHOICE_LEN ) {
- len = MAX_CHOICE_LEN;
- }
- if (len1 == -1) {
- /* remember length of first word */
- len1 = len;
- }
- memmove((VOID *) string, (VOID *) (list + word_off), len);
- string[len] = '\0';
-
- if (found) {
- return;
- }
- if (strncmp(string, curr, slen) == 0) {
- /* get the next choice */
- found = TRUE;
- }
-
- /* find next entry */
- /* point word_off to beginning of next entry */
- for (word_off = off + 1; list[word_off] == DELIMITER; word_off++, off++) {
- ;
- }
- if (list[word_off] == '\0') {
- break;
- }
- }
- if (list[off] == '\0') {
- break;
- }
- }
- /* curr not found or wrap-a-round, return first choice */
- if (len1 == -1) {
- string[0] = '\0';
- }
- else {
- memmove((VOID *) string, (VOID *) start, len1);
- string[len1] = '\0';
- }
- }
-