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

  1. /**
  2. *
  3. * Name        EDINITKY -- Initialize the edit key list.
  4. *
  5. * Synopsis    ercode = edinitky();
  6. *
  7. *        int ercode  Error code indicating success or failure
  8. *                of the operation.
  9. *
  10. * Description    This procedure constructs the linked list of edit key
  11. *        records, and points the global variable b_pkey_root
  12. *        to the head of the list.  The return value is
  13. *        ED_NO_ERROR if successful, or ED_NO_MEMORY if there
  14. *        was an error allocating space for the list.
  15. *
  16. * Returns    ercode        Possible values:
  17. *                ED_NO_ERROR   No errors.
  18. *                ED_NO_MEMORY  Insufficient memory for
  19. *                          key list.
  20. *        b_pkey_root    Pointer to the head of the key list.
  21. *
  22. * Version    6.00 (C)Copyright Blaise Computing Inc.  1989
  23. *
  24. **/
  25. #include <butil.h>
  26. #include <bkeys.h>
  27. #include <bedit.h>
  28.  
  29.  
  30.         /* Default edit key records.  They are placed in the    */
  31.         /* linked list of edit keys at initialization.        */
  32. ED_DEF_KEY b_defkeys[] =
  33. {
  34.     {ED_ABORT,        {0x1B, 0x01}},  /* Quit with no edit - ESC.     */
  35.     {ED_LEFT,        {0x00, 0x4B}},  /* Move left - pad 4.        */
  36.     {ED_LEFT,        {0xE0, 0x4B}},  /* Move left - left arrow.        */
  37.     {ED_RIGHT,        {0x00, 0x4D}},  /* Move right - pad 6.        */
  38.     {ED_RIGHT,        {0xE0, 0x4D}},  /* Move right - right arrow.    */
  39.     {ED_UP,        {0x00, 0x48}},  /* Move up - pad 6.         */
  40.     {ED_UP,        {0x38, 0x48}},  /* Move up - up arrow.        */
  41.     {ED_DOWN,        {0x00, 0x50}},  /* Move down - pad 6.        */
  42.     {ED_DOWN,        {0x32, 0x50}},  /* Move down - down arrow.        */
  43.     {ED_FRONT,        {0x00, 0x47}},  /* Move to front - pad 7.        */
  44.     {ED_FRONT,        {0xE0, 0x47}},  /* Move to front - Home.        */
  45.     {ED_END,        {0x00, 0x4F}},  /* Move to end  - pad 1.        */
  46.     {ED_END,        {0xE0, 0x4F}},  /* Move to end  - End.        */
  47.     {ED_TEXT_END,   {0x00, 0x75}},  /* Move to text end  - C/End.   */
  48.     {ED_NEXT_WORD,  {0x06, 0x21}},  /* Forward word - C/F.        */
  49.     {ED_PREV_WORD,  {0x01, 0x1E}},  /* Back word - C/A.         */
  50.     {ED_DEL_WORD,   {0x14, 0x14}},  /* Delete word - C/T.        */
  51.     {ED_BEGIN_WORD, {0x2D, 0x4A}},  /* Begin word - pad '-'.        */
  52.     {ED_END_WORD,   {0x2B, 0x4E}},  /* End word - pad '+'.          */
  53.     {ED_NEXT_WHITE, {0x00, 0x3C}},  /* Next whitespace - F2.        */
  54.     {ED_PREV_WHITE, {0x00, 0x3B}},  /* Previous whitespace - F1.    */
  55.     {ED_NEXT_NONWHITE,{0x00, 0x3E}},/* Next non whitespace - F4.    */
  56.     {ED_PREV_NONWHITE,{0x00, 0x3D}},/* Previous non whitespace - F3.*/
  57.     {ED_DELETE,     {0x00, 0x53}},  /* Delete char - pad period.    */
  58.     {ED_DELETE,     {0xE0, 0x53}},  /* Delete character - Delete.   */
  59.     {ED_RUBOUT,     {0x08, 0x0E}},  /* Move left delete - Backspace.*/
  60.     {ED_DELLEFT,    {0x08, 0x23}},  /* Delete char left - C/H.        */
  61.     {ED_CLEAR,        {0x00, 0x77}},  /* Clear buffer - C/pad 7.        */
  62.     {ED_CLEAR,        {0xE0, 0x77}},  /* Clear buffer - C/Home.        */
  63.     {ED_CLEAREOL,   {0x00, 0x74}},  /* Clear to end - C/pad 6.        */
  64.     {ED_CLEAREOL,   {0xE0, 0x74}},  /* Clear to end - C/Right.        */
  65.     {ED_INSERT,     {0x00, 0x12}},  /* Insert mode - Alt/E.        */
  66.     {ED_REPLACE,    {0x00, 0x13}},  /* Replace mode - Alt/R.        */
  67.     {ED_INSTOGGLE,  {0x00, 0x52}},  /* Toggle INS mode - pad 0.     */
  68.     {ED_INSTOGGLE,  {0xE0, 0x52}},  /* Toggle INS mode - Insert.    */
  69.     {ED_UNDO,        {0x00, 0x2D}},  /* Restore buffer - Alt/X.        */
  70.     {ED_TRANSMIT,   {0x0D, 0x1C}},  /* Finish edit - Enter.        */
  71.     {ED_TRANSMIT,   {0x0D, 0xE0}},  /* Finish edit - pad Enter.     */
  72.     {ED_INVALID_ACTION,         /* End of edit key entries.     */
  73.             {KBNDEF,KBNDEF}}
  74. };
  75.  
  76. ED_LIST *b_pkey_root = NIL;        /* Edit key list head.        */
  77. int    b_pkeys_init = 0;        /* 0 = key list uninitialized.  */
  78.  
  79. int edinitky()
  80. {
  81.     int     i;
  82.     ED_LIST *new_key_node;
  83.  
  84.     if (b_pkey_root != NIL)
  85.     edzapkey();
  86.  
  87.         /* Initialize the list of default edit keys.  For   */
  88.         /* each key in the default key table, a new record  */
  89.         /* is allocated, initialized and placed at the        */
  90.         /* beginning of the list.                */
  91.     i = 0;
  92.     while (b_defkeys[i].action_code != ED_INVALID_ACTION)
  93.     {
  94.     new_key_node = malloc(sizeof(ED_LIST));
  95.     if (new_key_node == NIL)
  96.         return(ED_NO_MEMORY);
  97.     new_key_node->edit_key.edit_actions.num_actions = 1;
  98.     new_key_node->edit_key.edit_actions.pactions =
  99.         malloc(sizeof(ED_ACTION));
  100.     *new_key_node->edit_key.edit_actions.pactions =
  101.         b_defkeys[i].action_code;
  102.     new_key_node->edit_key.key_sequence =
  103.         b_defkeys[i].key_sequence;
  104.  
  105.     if (b_pkey_root != NIL)
  106.     {
  107.         b_pkey_root->pprev    = new_key_node;
  108.         new_key_node->pnext = b_pkey_root;
  109.         new_key_node->pprev = NIL;
  110.         b_pkey_root     = new_key_node;
  111.     }
  112.     else
  113.     {
  114.         new_key_node->pnext = NIL;
  115.         new_key_node->pprev = NIL;
  116.         b_pkey_root = new_key_node;
  117.     }
  118.  
  119.     i++;
  120.     }
  121.  
  122.     b_pkeys_init = 1;        /* 1 = key list initialized.        */
  123.     return(ED_NO_ERROR);
  124. }
  125.