home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name EDCHGKEY -- Change an existing edit key or add a new
- * edit key to the edit key list.
- *
- * Synopsis error = edchgkey(pkey_sequence, pactions);
- *
- * int error An error code indicating the
- * success or failure of the
- * requested operation.
- * const KEY_SEQUENCE The edit key sequence to be
- * *pkey_sequence changed, if it already exists, or
- * added, if it does not.
- * const ED_ACTION_LIST The key's new list of edit
- * *pactions actions.
- *
- * Description EDCHGKEY searches the edit key list for the specified
- * character and key codes. If a matching key is found,
- * the specified action list is copied over the key's
- * existing list. Otherwise, a new key definition is
- * added to the list. If the edit key list has not yet
- * been initialized, it is initialized before the search.
- *
- * Returns int error Error code. Possible values are:
- * ED_NO_ERROR Operation successful.
- * ED_NO_MEMORY Request for memory failed.
- * b_pkey_root Pointer to start of newly initialized edit
- * key list, if it was not already
- * initialized.
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1989
- *
- **/
- #include <bedit.h>
- #include <bkeys.h>
- #include <butil.h>
- #include <string.h>
-
-
- int edchgkey(pkey_sequence, paction_list)
- const KEY_SEQUENCE *pkey_sequence;
- const ED_ACTION_LIST *paction_list;
- {
- ED_KEY *pfound_key;
- ED_LIST *pedit_node;
- ED_ACTION *pnew_list;
- int action_list_size;
-
- pfound_key = edretkey(pkey_sequence);
- action_list_size = paction_list->num_actions *
- sizeof(ED_ACTION);
-
- if (pfound_key == NIL)
- {
- /* The specified key is not in the list, so add it. */
-
- pedit_node = malloc(sizeof(ED_KEY));
- if (pedit_node == NIL)
- return(ED_NO_MEMORY);
-
- pedit_node->edit_key.key_sequence = *pkey_sequence;
-
- pedit_node->edit_key.edit_actions.num_actions =
- paction_list->num_actions;
-
- pnew_list = malloc(action_list_size);
- if (pnew_list == NIL)
- return(ED_NO_MEMORY);
-
- memmove(pnew_list, paction_list->pactions,
- action_list_size);
- pedit_node->edit_key.edit_actions.pactions = pnew_list;
-
- b_pkey_root->pprev = pedit_node;
- pedit_node->pnext = b_pkey_root;
- pedit_node->pprev = NIL;
- b_pkey_root = pedit_node;
- }
- else
- {
- /* Change the action list for the specified key. */
-
- pfound_key->edit_actions.num_actions =
- paction_list->num_actions;
-
- pnew_list =
- realloc(pfound_key->edit_actions.pactions,
- action_list_size);
- if (pnew_list == NIL)
- return(ED_NO_MEMORY);
-
- memmove(pnew_list, paction_list->pactions, action_list_size);
- pfound_key->edit_actions.pactions = pnew_list;
- }
-
- return(ED_NO_ERROR);
- }