home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / EDCHGKEY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  2.7 KB  |  98 lines

  1. /**
  2. *
  3. * Name        EDCHGKEY -- Change an existing edit key or add a new
  4. *                edit key to the edit key list.
  5. *
  6. * Synopsis    error = edchgkey(pkey_sequence, pactions);
  7. *
  8. *        int error          An error code indicating the
  9. *                      success or failure of the
  10. *                      requested operation.
  11. *        const KEY_SEQUENCE    The edit key sequence to be
  12. *              *pkey_sequence  changed, if it already exists, or
  13. *                      added, if it does not.
  14. *        const ED_ACTION_LIST  The key's new list of edit
  15. *              *pactions       actions.
  16. *
  17. * Description    EDCHGKEY searches the edit key list for the specified
  18. *        character and key codes.  If a matching key is found,
  19. *        the specified action list is copied over the key's
  20. *        existing list.    Otherwise, a new key definition is
  21. *        added to the list. If the edit key list has not yet
  22. *        been initialized, it is initialized before the search.
  23. *
  24. * Returns    int error    Error code. Possible values are:
  25. *                 ED_NO_ERROR   Operation successful.
  26. *                 ED_NO_MEMORY  Request for memory failed.
  27. *        b_pkey_root  Pointer to start of newly initialized edit
  28. *                 key list, if it was not already
  29. *                 initialized.
  30. *
  31. * Version    6.00 (C)Copyright Blaise Computing Inc.  1989
  32. *
  33. **/
  34. #include <bedit.h>
  35. #include <bkeys.h>
  36. #include <butil.h>
  37. #include <string.h>
  38.  
  39.  
  40. int edchgkey(pkey_sequence, paction_list)
  41. const KEY_SEQUENCE *pkey_sequence;
  42. const ED_ACTION_LIST *paction_list;
  43. {
  44.     ED_KEY    *pfound_key;
  45.     ED_LIST    *pedit_node;
  46.     ED_ACTION    *pnew_list;
  47.     int     action_list_size;
  48.  
  49.     pfound_key = edretkey(pkey_sequence);
  50.     action_list_size = paction_list->num_actions *
  51.                sizeof(ED_ACTION);
  52.  
  53.     if (pfound_key == NIL)
  54.     {
  55.         /* The specified key is not in the list, so add it. */
  56.  
  57.     pedit_node = malloc(sizeof(ED_KEY));
  58.     if (pedit_node == NIL)
  59.         return(ED_NO_MEMORY);
  60.  
  61.     pedit_node->edit_key.key_sequence = *pkey_sequence;
  62.  
  63.     pedit_node->edit_key.edit_actions.num_actions =
  64.         paction_list->num_actions;
  65.  
  66.     pnew_list = malloc(action_list_size);
  67.     if (pnew_list == NIL)
  68.         return(ED_NO_MEMORY);
  69.  
  70.     memmove(pnew_list, paction_list->pactions,
  71.         action_list_size);
  72.     pedit_node->edit_key.edit_actions.pactions = pnew_list;
  73.  
  74.     b_pkey_root->pprev = pedit_node;
  75.     pedit_node->pnext = b_pkey_root;
  76.     pedit_node->pprev = NIL;
  77.     b_pkey_root = pedit_node;
  78.     }
  79.     else
  80.     {
  81.         /* Change the action list for the specified key.    */
  82.  
  83.     pfound_key->edit_actions.num_actions =
  84.         paction_list->num_actions;
  85.  
  86.     pnew_list =
  87.         realloc(pfound_key->edit_actions.pactions,
  88.             action_list_size);
  89.     if (pnew_list == NIL)
  90.         return(ED_NO_MEMORY);
  91.  
  92.     memmove(pnew_list, paction_list->pactions, action_list_size);
  93.     pfound_key->edit_actions.pactions = pnew_list;
  94.     }
  95.  
  96.     return(ED_NO_ERROR);
  97. }
  98.