⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 config.c

📁 一个开源著名的TDE编辑器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
      if (branch == NULL) {         branch = my_calloc( sizeof(TREE) );         if (branch == NULL)            return( NULL );         branch->key = key;      } else {         existing_macro = TRUE;         if (branch->macro != NULL) {            mac = branch->macro;            if (mac->len > 1)               my_free( mac->key.keys );            mac->len = 0;         }      }      branch->func = PlayBack;  /* required for the two-keys */   }   if (mac == NULL) {      mac = my_calloc( sizeof(MACRO) );      if (mac == NULL) {         if (!existing_macro)            my_free( branch );         return( NULL );      }      if (branch != NULL)         branch->macro = mac;   }   /*    * Try allocating STROKE_LIMIT first. If it fails, halve    * it each time and try again.    */   stroke_count = STROKE_LIMIT;   while ((mac->key.keys = my_malloc( stroke_count * sizeof(long), &rc ))                         == NULL  &&  stroke_count > 1)      stroke_count /= 2;   if (mac->key.keys == NULL) {      stroke_count = 0;      my_free( mac );      mac = NULL;      if (!existing_macro)         my_free( branch );   } else                       /* set default modes to: */      mac->mode[0] =            /* insert                */      mac->mode[1] =            /* smart tabs            */      mac->mode[2] = TRUE;      /* indent                */   return( mac );}/* * Name:    check_macro * Purpose: see if macro def has any valid key.  if not, clear macro * Date:    June 5, 1994 * Passed:  mac:  macro that we are checking * Notes:   Rewritten by Jason Hood, July 19, 1998. * jmh 990429: test for mac == NULL. */void check_macro( MACRO *mac ){long key;long *keys;int  rc;   if (mac == NULL)      return;   if (mac->len == 0) {      my_free( mac->key.keys );      my_free( mac );      if (!existing_macro)         my_free( branch );   } else {      if (mac->len == 1) {         key = *mac->key.keys;         my_free( mac->key.keys );         mac->key.key = key;      } else {         keys = my_realloc( mac->key.keys, mac->len * sizeof(long), &rc );         if (keys != NULL)            mac->key.keys = keys;      }      if (branch == NULL)         macro[KEY_IDX( macro_key )] = mac;      else if (!existing_macro)         add_branch( branch, cfg_key_tree );   }}/* * Name:    cfg_record_keys * Purpose: save keystrokes in keystroke buffer * Date:    June 5, 1994 * Passed:  line: line to display prompts * Notes:   Rewritten by Jason Hood, July 19, 1998. * * jmh 980826: when possible, store the function rather than the key. */int  cfg_record_keys( MACRO *mac, long key, int func, int prompt_line ){int  rc;char temp[42];   rc = OK;   if (stroke_count-- > 0) {      if (func != RecordMacro    && func != SaveMacro  &&          func != ClearAllMacros && func != LoadMacro) {         mac->key.keys[mac->len++] = (func == 0 || func == PlayBack)                                     ? key : (func | _FUNCTION);      }   } else {      rc = ERROR;      if (stroke_count == -1) {         ERRORLINE( config23, temp );   /* no more room in macro buffer */      }   }   return( rc );}/* * Name:    cfg_search_tree * Purpose: search the two-key tree for a function * Author:  Jason Hood * Date:    July 31, 1998 * Passed:  func: function to find *          tree: pointer to tree * Returns: key if found; ERROR if not found * Notes:   recursively traverse the tree. * jmh 020819: removed tail recursion. */long cfg_search_tree( int func, TREE *tree ){long key = ERROR;   while (tree != NULL) {      if (tree->func == func)         return( tree->key );      key = cfg_search_tree( func, tree->left );      if (key == ERROR)         tree = tree->right;      else         break;   }   return( key );}/* * Name:    new_sort_order * Purpose: change the sort order * Date:    October 31, 1992 * Notes:   New sort order starts from ! (ie. skips space and control chars) */void new_sort_order( text_ptr residue, text_ptr sort ){int  i;   sort += 33;   for (i = 33; *residue != '\0'  &&  i <= 255; i++)      *sort++ = *residue++;}/* * Name:    add_twokey * Purpose: find an open slot and insert the new two-key combination * Date:    April 1, 1993 * Passed:  key:  two-key *          func: function number to assign to this combo * Notes:   Rewritten by Jason Hood, July 30, 1998. */int  add_twokey( long key, int func ){TREE *twokey;int  rc = OK;   twokey = search_tree( key, cfg_key_tree->right );   if (twokey == NULL) {      twokey = my_calloc( sizeof(TREE) );      if (twokey == NULL)         rc = ERROR;      else {         twokey->key = key;         twokey->func = func;         add_branch( twokey, cfg_key_tree );      }   } else {      if (twokey->macro != NULL) {         if (twokey->macro->len > 1)            my_free( twokey->macro->key.keys );         my_free( twokey->macro );         twokey->macro = NULL;      }      twokey->func = func;   }   return( rc );}/* * Name:    new_upper_lower * Purpose: Define the conversion between upper and lower cases * Author:  Jason Hood * Date:    November 27, 1998 * Notes:   Ignores space and the control characters. *          Dot ('.') is used as a place filler. */void new_upper_lower( text_ptr residue ){int  i;   for (i = 33; *residue != '\0'  &&  i <= 255; i++) {      upper_lower[i] = (*residue == '.') ? 0 : *residue;      ++residue;   }   for (; i < 256; ++i)      upper_lower[i] = 0;}/* * Name:    new_bj_ctype * Purpose: Define the type of a character * Author:  Jason Hood * Date:    November 27, 1998 * Notes:   Space and the control characters are always the same. *          Dot ('.') is used as a place filler. */void new_bj_ctype( char *residue ){int  i;int  t;   for (i = 33; *residue != '\0'  &&  i <= 255; i++) {      switch (*residue) {         case 'L' : t = BJ_lower;             break;         case 'U' : t = BJ_upper;             break;         case 'D' : t = BJ_digit | BJ_xdigit; break;         case 'S' : t = BJ_space;             break;         case 'C' : t = BJ_cntrl;             break;         case 'P' : t = BJ_punct;             break;         case 's' : t = BJ_space | BJ_cntrl;  break;         case 'X' : t = BJ_upper | BJ_xdigit; break;         case 'x' : t = BJ_lower | BJ_xdigit; break;         default  : t = 0;      }      bj_ctype[i] = t;      ++residue;   }   for (; i < 256; ++i)      bj_ctype[i] = 0;}/* * Name:    parse_color * Purpose: to recognize color numbers, or color names * Author:  Jason Hood * Date:    April 20, 1999 * Passed:  line:        current line position *          key:         buffer to store tokens *          prompt_line: line to display error message *          not_color:   message to display if color is unrecognized * Returns: color number or ERROR if invalid *          line points to token after color * * jmh 020923: allow bright background. */int  parse_color( char **line, char *key,                  int prompt_line, const char *not_color ){int  fg,     bg = background;char *residue;   *line = parse_token( *line, key );   /*    * we found a color field and attribute.  now, make sure    *   everything is everything before we assign the attribute    *   to the color field.    */   if (bj_isdigit( *key )) {      fg = atoi( key );      if (fg < 0 || fg > 255){         ERRORLINE( config6, key );     /* color number out of range */         return( ERROR );      }      return( fg );   }   fg = search( key, valid_color, 20 );   if (fg == ERROR) {      ERRORLINE( not_color, key );      /* unrecognized color name */      return( ERROR );                  /* or unrecognized syntax setting */   }   if (fg >= 256)                       /* mono attribute */      return( fg - 256 );   if (*line != NULL) {      /*       * Check if there's a background.       */      residue = parse_token( *line, key );      if (residue != NULL && stricmp( key, off_on[1].key ) == 0) {         *line = parse_token( residue, key );         bg = search( key, valid_color, 20 );         if (bg == ERROR) {            ERRORLINE( config6a, key ); /* unrecognized color name */            return( ERROR );         }      }   }   return( fg | (bg << 4) );}/* * Name:    parse_key * Purpose: translate a config key string into a function key number * Author:  Jason Hood * Date:    August 19, 2002 * Passed:  key:  the string to parse * Returns: the function key or ERROR if unable to parse * Notes:   assumes key contains at least one character. */int  parse_key( char *key ){int  shift;int  key_no;int  c;   shift = 0;   for (; *++key == '+'; ++key) {      c = bj_tolower( *(key-1) );      if (c == 's')         shift |= _SHIFT;      else if (c == 'c')         shift |= _CTRL;      else if (c == 'a')         shift |= _ALT;      else         return( ERROR );   }   key_no = search( key-1, valid_keys, AVAIL_KEYS-1 );   if (key_no != ERROR)      key_no |= shift;   return( key_no );}/* * Name:    new_key_name * Purpose: set the key strings for the menu * Author:  Jason Hood * Date:    August 31, 2002 * Passed:  line:  the line containing the strings *          buf:   a buffer to store a string * Notes:   reads the strings in scancode order. *          use an empty string to leave the current key unchanged. *          if the string starts with '=' and is followed by a number, *           take that number as the next scancode. *          simply ignores extra keys. *          currently ignores memory problems (if there's no memory *           for this, there's probably no memory for anything). */static void new_key_name( char *line, char *buf ){char *tmp;int  num;   if (key_num >= MAX_KEYS)      return;   do {      line = parse_token( line, buf );      if (*buf  &&  strcmp( buf, key_word[key_num] ) != 0) {         if (*buf == '=') {            num = (int)strtol( buf+1, &tmp, 0 ) - 1;            if (*tmp == '\0'  &&  num >= 0 && num < MAX_KEYS) {               key_num = num;               continue;            }         }         tmp = my_strdup( buf );         if (tmp != NULL)            key_word[key_num] = tmp;      }      ++key_num;   } while (line != NULL);}/* * Name:    new_scancode_map * Purpose: redefine the keyboard hardware sequence * Author:  Jason Hood * Date:    September 3, 2002 * Passed:  line:  the line containing the strings *          buf:   a buffer to store a string * Returns: NULL or an error message * Notes:   translates pairs of keys - the first key is what TDE says it is *           (eg: via config/key.tdm); the second is the actual key. *          Eg: if you press Y on your keyboard, but TDE displays Z, you *              should add "Scancode Z Y" to your config file. *          Multiple pairs are allowed ("Scancode Z Y  Y Z"). */static const char *new_scancode_map( char *line, char *buf ){int  key;int  newkey;   do {      line = parse_token( line, buf );      if (line == NULL)         return( config30 );    /* scancode requires pairs */      key = parse_key( buf );      line = parse_token( line, buf );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -