home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name EDINITKY -- Initialize the edit key list.
- *
- * Synopsis ercode = edinitky();
- *
- * int ercode Error code indicating success or failure
- * of the operation.
- *
- * Description This procedure constructs the linked list of edit key
- * records, and points the global variable b_pkey_root
- * to the head of the list. The return value is
- * ED_NO_ERROR if successful, or ED_NO_MEMORY if there
- * was an error allocating space for the list.
- *
- * Returns ercode Possible values:
- * ED_NO_ERROR No errors.
- * ED_NO_MEMORY Insufficient memory for
- * key list.
- * b_pkey_root Pointer to the head of the key list.
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1989
- *
- **/
- #include <butil.h>
- #include <bkeys.h>
- #include <bedit.h>
-
-
- /* Default edit key records. They are placed in the */
- /* linked list of edit keys at initialization. */
- ED_DEF_KEY b_defkeys[] =
- {
- {ED_ABORT, {0x1B, 0x01}}, /* Quit with no edit - ESC. */
- {ED_LEFT, {0x00, 0x4B}}, /* Move left - pad 4. */
- {ED_LEFT, {0xE0, 0x4B}}, /* Move left - left arrow. */
- {ED_RIGHT, {0x00, 0x4D}}, /* Move right - pad 6. */
- {ED_RIGHT, {0xE0, 0x4D}}, /* Move right - right arrow. */
- {ED_UP, {0x00, 0x48}}, /* Move up - pad 6. */
- {ED_UP, {0x38, 0x48}}, /* Move up - up arrow. */
- {ED_DOWN, {0x00, 0x50}}, /* Move down - pad 6. */
- {ED_DOWN, {0x32, 0x50}}, /* Move down - down arrow. */
- {ED_FRONT, {0x00, 0x47}}, /* Move to front - pad 7. */
- {ED_FRONT, {0xE0, 0x47}}, /* Move to front - Home. */
- {ED_END, {0x00, 0x4F}}, /* Move to end - pad 1. */
- {ED_END, {0xE0, 0x4F}}, /* Move to end - End. */
- {ED_TEXT_END, {0x00, 0x75}}, /* Move to text end - C/End. */
- {ED_NEXT_WORD, {0x06, 0x21}}, /* Forward word - C/F. */
- {ED_PREV_WORD, {0x01, 0x1E}}, /* Back word - C/A. */
- {ED_DEL_WORD, {0x14, 0x14}}, /* Delete word - C/T. */
- {ED_BEGIN_WORD, {0x2D, 0x4A}}, /* Begin word - pad '-'. */
- {ED_END_WORD, {0x2B, 0x4E}}, /* End word - pad '+'. */
- {ED_NEXT_WHITE, {0x00, 0x3C}}, /* Next whitespace - F2. */
- {ED_PREV_WHITE, {0x00, 0x3B}}, /* Previous whitespace - F1. */
- {ED_NEXT_NONWHITE,{0x00, 0x3E}},/* Next non whitespace - F4. */
- {ED_PREV_NONWHITE,{0x00, 0x3D}},/* Previous non whitespace - F3.*/
- {ED_DELETE, {0x00, 0x53}}, /* Delete char - pad period. */
- {ED_DELETE, {0xE0, 0x53}}, /* Delete character - Delete. */
- {ED_RUBOUT, {0x08, 0x0E}}, /* Move left delete - Backspace.*/
- {ED_DELLEFT, {0x08, 0x23}}, /* Delete char left - C/H. */
- {ED_CLEAR, {0x00, 0x77}}, /* Clear buffer - C/pad 7. */
- {ED_CLEAR, {0xE0, 0x77}}, /* Clear buffer - C/Home. */
- {ED_CLEAREOL, {0x00, 0x74}}, /* Clear to end - C/pad 6. */
- {ED_CLEAREOL, {0xE0, 0x74}}, /* Clear to end - C/Right. */
- {ED_INSERT, {0x00, 0x12}}, /* Insert mode - Alt/E. */
- {ED_REPLACE, {0x00, 0x13}}, /* Replace mode - Alt/R. */
- {ED_INSTOGGLE, {0x00, 0x52}}, /* Toggle INS mode - pad 0. */
- {ED_INSTOGGLE, {0xE0, 0x52}}, /* Toggle INS mode - Insert. */
- {ED_UNDO, {0x00, 0x2D}}, /* Restore buffer - Alt/X. */
- {ED_TRANSMIT, {0x0D, 0x1C}}, /* Finish edit - Enter. */
- {ED_TRANSMIT, {0x0D, 0xE0}}, /* Finish edit - pad Enter. */
- {ED_INVALID_ACTION, /* End of edit key entries. */
- {KBNDEF,KBNDEF}}
- };
-
- ED_LIST *b_pkey_root = NIL; /* Edit key list head. */
- int b_pkeys_init = 0; /* 0 = key list uninitialized. */
-
- int edinitky()
- {
- int i;
- ED_LIST *new_key_node;
-
- if (b_pkey_root != NIL)
- edzapkey();
-
- /* Initialize the list of default edit keys. For */
- /* each key in the default key table, a new record */
- /* is allocated, initialized and placed at the */
- /* beginning of the list. */
- i = 0;
- while (b_defkeys[i].action_code != ED_INVALID_ACTION)
- {
- new_key_node = malloc(sizeof(ED_LIST));
- if (new_key_node == NIL)
- return(ED_NO_MEMORY);
- new_key_node->edit_key.edit_actions.num_actions = 1;
- new_key_node->edit_key.edit_actions.pactions =
- malloc(sizeof(ED_ACTION));
- *new_key_node->edit_key.edit_actions.pactions =
- b_defkeys[i].action_code;
- new_key_node->edit_key.key_sequence =
- b_defkeys[i].key_sequence;
-
- if (b_pkey_root != NIL)
- {
- b_pkey_root->pprev = new_key_node;
- new_key_node->pnext = b_pkey_root;
- new_key_node->pprev = NIL;
- b_pkey_root = new_key_node;
- }
- else
- {
- new_key_node->pnext = NIL;
- new_key_node->pprev = NIL;
- b_pkey_root = new_key_node;
- }
-
- i++;
- }
-
- b_pkeys_init = 1; /* 1 = key list initialized. */
- return(ED_NO_ERROR);
- }