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

📄 config.c

📁 一个开源著名的TDE编辑器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
               break;            case CaseConvert :               mode_no = OK;               new_upper_lower( (text_ptr)key );               break;            case CharDef :               mode_no = OK;               new_bj_ctype( key );               break;            case FrameStyle :               mode_no = search( key, valid_frame, 3 );               if (mode_no == ERROR) {                  errmsg = config29;    /* invalid frame style */                  goto bad_config;               }               g_display.frame_style = mode_no;               break;            case KeyName :               mode_no = OK;               new_key_name( residue, key );               break;            case Scancode :               mode_no = OK;               errmsg = new_scancode_map( residue, key );               break;            case UserMenu :               mode_no = OK;               if (user_idx == -1)                  process_menu( NULL, "User" );               errmsg = new_user_menu( residue, key, FALSE );               break;            case HelpFile :               mode_no = OK;               get_full_path( key, mode.helpfile );               break;            case HelpTopic :               mode_no = OK;               assert( strlen( key ) < MAX_COLS );               strcpy( mode.helptopic, key );               break;            case Menu :               mode_no = OK;               errmsg = process_menu( residue, key );               break;         }         if (mode_no == ERROR)            errmsg = config19;          /* unknown mode */      }   }   if (!found)      errmsg = config20;   if (errmsg != NULL) {bad_config:      ERRORLINE( errmsg, key );   }}/* * Name:    parse_token * Purpose: given an input line, find the first token * Date:    June 5, 1994 * Passed:  line:  line that contains the text to parse *          token: buffer to hold token * Returns: pointer in line to start next token search. * Notes:   assume tokens are delimited by spaces. * * jmh:     September 9, 1997 - if line is NULL, *token is set to '\0'. *          This allows easier parsing in my syntax highlighting. * * jmh 980730: test for comments. If the line starts with ';', then token is *              set empty and return NULL. *             Test for trailing spaces and comments when returning residue. *             To include a ';', enclose it in quotes (eg. c+k ";" Macro ...). */char *parse_token( char *line, char *token ){   if (line == NULL) {      *token = '\0';      return( NULL );   }   /*    * skip over any leading spaces.    */   while (*line == ' ' || *line == '\t')      ++line;   if (*line == ';') {      *token = '\0';      return( NULL );   }   /*    * jmh 980521: test for literal strings.    */   if (*line == '\"') {      line = parse_literal( line, token );      if (line == NULL)         return( NULL );   } else {      /*       * put the characters into the token array until we run into a space       *   or the terminating '\0';       */      while (*line != ' ' && *line != '\t' && *line != '\0')         *token++ = *line++;      *token = '\0';   }   /*    * return what's left on the line, if anything.    */   while (*line == ' ' || *line == '\t')      ++line;   if (*line != ';' && *line != '\0')      return( line );   else      return( NULL );}/* * Name:    parse_literal * Purpose: get all letters in a literal * Date:    June 5, 1994 * Passed:  line:       current line position *          literal:    buffer to hold literal * Returns: pointer in line to start next token search. * Notes:   a literal begins with a '"'.  to include a '"', precede a '"' *           with a '"'. * jmh 980721: modified to return residue and display a warning. */char *parse_literal( char *line, char *literal ){int  end_quote = 0;     /* flag to indicate the end of the literal */char temp[10];          /* storage for the line number */int  prompt_line;   line++;   /*    * put the characters into the literal array until we run into the    *   end of literal or terminating '\0';    */   while (*line != '\0') {      if (*line == '\"') {         line++;         if (*line != '\"') {            ++end_quote;            break;         }      }      *literal++ = *line++;   }   *literal = '\0';   /*    * return what's left on the line, if anything.    */   if (*line != '\0')      return( line );   else {      if (!end_quote) {         prompt_line = (g_status.current_window == NULL) ? g_display.end_line :                       g_status.current_window->bottom_line;         ERRORLINE( config21, temp );   /* unterminated quote */      }      return( NULL );   }}/* * Name:    search * Purpose: binary search a CONFIG_DEFS structure * Date:    June 5, 1994 * Passed:  token:  token to search for *          list:   list of valid tokens *          num:    number of last valid token in list * Returns: value of token assigned to matching token. * Notes:   do a standard binary search. *          instead of returning mid, lets return the value of the token *          assigned to mid. */int  search( char *token, const CONFIG_DEFS list[], int num ){int  bot;int  mid;int  top;int  rc;   bot = 0;   top = num;   while (bot <= top) {      mid = (bot + top) / 2;      rc = stricmp( token, list[mid].key );      if (rc == 0)         return( list[mid].key_index );      else if (rc < 0)         top = mid - 1;      else         bot = mid + 1;   }   return( ERROR );}/* * Name:    clear_previous_macro * Purpose: clear any macro previously assigned to a key * Date:    June 5, 1994 * Passed:  macro_key:  key that we are a assigning a macro to * Notes:   rewritten by Jason Hood, July 19, 1998. */void clear_previous_macro( int macro_key ){MACRO **mac;   mac = &macro[KEY_IDX( macro_key )];   if (*mac != NULL) {      if ((*mac)->len > 1)         my_free( (*mac)->key.keys );      my_free( *mac );      *mac = NULL;   }}/* * Name:    parse_macro * Purpose: separate literals from keys in a macro definition * Date:    June 5, 1994 * Passed:  residue: pointer to macro defs * Notes:   for each token in macro def, find out if it's a literal or a *             function key. * jmh 980719: allow function names to be used and multi-line definitions. * jmh 980820: allow literals to contain escaped function shortcuts. * jmh 990429: continue processing multi-line macros when out of memory to *              avoid other error messages. * jmh 021024: modified error display to suit the startup macro. */int  parse_macro( char *residue, int prompt_line ){int  rc;char literal[1042];char temp[42];char *l;long key_no = 0;int  twokey;int  func;int  empty = TRUE;TREE *twokey_func;const char *errmsg;int  exit_code = OK;   /*    * allocate storage for the keys.    */   if (!process_macro)      if (initialize_macro( macro_key ) == NULL) {         stroke_count = -1;         exit_code = ERROR;         if (line_no == 0)            g_status.errmsg = main4;      }   while (residue != NULL) {      /*       * skip over any leading spaces.       */      while (*residue == ' ' || *residue == '\t')         ++residue;      /*       * done if we hit eol or a comment       */      if (*residue == ';' || *residue == '\0')         residue = NULL;      /*       * check for a literal.       */      else if (*residue == '\"') {         empty   = FALSE;         residue = parse_literal( residue, literal );         l  = literal;         rc = OK;         while (*l != '\0'  &&  rc == OK) {            func = 0;            if (*l == '\\' && *(l+1) != '\0') {               switch (*(++l)) {                  case MAC_BackSpace : func = BackSpace;   break;                  case MAC_CharLeft  : func = CharLeft;    break;                  case MAC_CharRight : func = CharRight;   break;                  case MAC_Pseudo    : func = PseudoMacro; break;                  case MAC_Rturn     : func = Rturn;       break;                  case MAC_Tab       : func = Tab;         break;                  case '0'           : func = MacroMark;   break;                  case '1'           : func = SetMark1;    break;                  case '2'           : func = SetMark2;    break;                  case '3'           : func = SetMark3;    break;                  case '\\'          : ++l;                break;               }               if (func == 0)                  --l;            }            rc = cfg_record_keys( mac, *l, func, prompt_line );            ++l;         }      } else {         /*          * check for a function.          */         errmsg  = NULL;         residue = parse_token( residue, literal );         func    = search( literal, valid_func, CFG_FUNCS );         if (func != ERROR) {            if (func == RecordMacro && process_macro) {               empty = process_macro = FALSE;               break;            }            if (func == PlayBack) {               key_no = macro_key;               if (key_no >= 0x2121 && key_no < 0x10000L) {                  cfg_record_keys( mac, (unsigned)key_no >> 8, 0, prompt_line );                  cfg_record_keys( mac, (int)key_no & 0xff, 0, prompt_line );                  func = PseudoMacro;               }               residue = NULL;               empty = process_macro = FALSE;            }         } else {            /*             * check for a function key.             */            key_no = parse_key( literal );            if (key_no == ERROR) {               /*                * check for mode definition.                */               key_no = search( literal, valid_macro_modes, NUM_MACRO_MODES );               if ((int)key_no != ERROR && mac != NULL) {                  if ((int)key_no & 0x8000)                     mac->flag |= (int)key_no & ~0x8000;                  else                     mac->mode[(int)key_no / 2] = (int)key_no & 1;                  continue;               }            } else {               func = 0;               if (key_func[KEY_IDX( key_no )] == TwoCharKey) {                  if (residue == NULL) {                     key_no = ERROR;                     errmsg = config28;                  } else {                     residue = parse_token( residue, literal );                     twokey = parse_key( literal );                     if (twokey != ERROR) {                        key_no = CREATE_TWOKEY( key_no, twokey );                        twokey_func = search_tree(key_no, cfg_key_tree->right);                        if (twokey_func != NULL)                           func = twokey_func->func;                     } else {                        key_no = ERROR;                        errmsg = config22;                     }                  }               }            }         }         if (key_no != ERROR) {            cfg_record_keys( mac, key_no, func, prompt_line );            empty = FALSE;         } else {            if (errmsg == NULL)               errmsg = config31;            if (line_no == 0)               g_status.errmsg = errmsg;            else {               combine_strings( line_out, errmsg, config0,                                my_ltoa( (line_no < 0) ? -line_no : line_no,                                         temp, 10 ) );               if (line_no > 0)                  error( WARNING, prompt_line, line_out );               else                  g_status.errmsg = line_out;            }         }      }   }   if (empty)      process_macro = TRUE;   if (!process_macro)      check_macro( mac );   return( exit_code );}/* * Name:    initialize_macro * Purpose: initialize the first key of a macro def * Date:    June 5, 1994 * Passed:  key:  key number of macro that we are initializing * Returns: pointer to macro or NULL if no memory. * Notes:   Rewritten by Jason Hood, July 19/31, 1998. */MACRO *initialize_macro( long key ){int  rc;   mac            = NULL;   branch         = NULL;   existing_macro = FALSE;   if (key >= 0x2121) {      branch = search_tree( key, cfg_key_tree );

⌨️ 快捷键说明

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