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

📄 config.c

📁 一个开源著名的TDE编辑器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
      newkey = parse_key( buf );      if (key == ERROR || newkey == ERROR)         return( config22 );      scancode_map[KEY( key )] = KEY( newkey ) | 256; /* in case of modifiers */   } while (line != NULL);   return( NULL );}/* * Name:    parse_cmdline_macro * Purpose: process the startup macro from the command line * Author:  Jason Hood * Date:    October 24, 2002 * Passed:  line:        the line or file to process *          prompt_line: line for error messages * Returns: nothing, but sets g_status.errmsg if an error occurs. * Notes:   if line is a file, read the macro from the file contents; *           otherwise treat line as a macro.  In the unlikely event *           that you want a single command that is also an existing file, *           simply add a space to the definition, eg: '-e " filefunction"'. *          Use the unavailable Control-Break key to store it. * * jmh 031026: use the local/global option value. */void parse_cmdline_macro( char *line, int prompt_line ){FILE *fp;   macro_key = g_option.macro;   line_no = 0;   if (file_exists( line ) == ERROR) {      parse_macro( line, prompt_line );      return;   }   if ((fp = fopen( line, "r" )) == NULL) {      combine_strings( line_out, main7a, line, main7b );      g_status.errmsg = line_out;      return;   }   /*    * Force the start of a multi-line macro definition.    */   parse_macro( "", prompt_line );   while (g_status.errmsg == NULL  &&  read_line( fp ) != EOF) {      /*       * use negative line numbers to prevent parse_macro() from       * displaying error messages.       */      --line_no;      parse_macro( line_in, prompt_line );   }   fclose( fp );   /*    * Force the end of a multi-line macro definition.    */   parse_macro( (char *)func_str[RecordMacro], prompt_line );}/* * Name:    new_user_menu * Purpose: add an item to the User (Language) menu * Author:  Jason Hood * Date:    November 29, 2003 * Passed:  line:   current line position *          token:  name of the menu, as well as buffer for key *          shl:    TRUE if creating Language sub-menu * Returns: NULL if okay, pointer to error message if not. * Notes:   requires user_menu to point to the appropriate menu. *          if the name already exists, overwrite the current. */const char *new_user_menu( char *line, char *token, int shl ){int  rc = OK;MINOR_STR *mnu;char *name;int  cnt;long key;int  twokey;int  len;int  i;static int exists = FALSE;   if (token == NULL || *token == '\0' || (*token == '-' && token[1] == '\0')) {      if (exists == TRUE) {         /*          * The previous item already exists, so assume          * this separator also already exists after it.          */         return( NULL );      }      i = len = 0;   } else {      len = strlen( token ) + 1;      cnt = user_menu->minor_cnt - ((shl) ? 2 : 4);      if (cnt == 1 && !shl &&          strcmp( user_menu->minor[1].minor_name, config32 ) == 0) {         i = 1;         exists = ERROR;      } else {         for (i = cnt; i >= 1; --i) {            name = user_menu->minor[i].minor_name;            if (name != NULL)               if (memcmp( name, token, len ) == 0)                  break;         }         exists = (i > 0);      }   }   if (!exists) {      if (user_menu->minor_cnt == 0) {         i   = TRUE;         cnt = (shl) ? 3 : 5;      } else {         i   = FALSE;         cnt = user_menu->minor_cnt + 1;      }      mnu = realloc( user_menu->minor, cnt * sizeof(MINOR_STR) );      if (mnu == NULL)         return( main4 );      user_menu->minor = mnu;      user_menu->minor_cnt = cnt;      if (i) {         user_menu->minor[0].line = NULL;         for (i = 0; i < cnt; ++i) {            user_menu->minor[i].minor_name = NULL;            user_menu->minor[i].minor_func = ERROR;            user_menu->minor[i].pop_out    = NULL;            user_menu->minor[i].disabled   = FALSE;         }         if (!shl) {            user_menu->minor[3].minor_name = (char *)config33; /* Language */            user_menu->minor[3].minor_func = 0;         }         i = 1;      } else {         if (shl) {            user_menu->minor[cnt-1] = user_menu->minor[cnt-2];            i = cnt - 2;         } else for (i = cnt - 1; i >= cnt - 3; --i)            user_menu->minor[i] = user_menu->minor[i-1];      }   }   if (i) {      if (exists != TRUE) {         user_menu->minor[i].minor_name = my_malloc( len, &rc );         if (rc == ERROR)            return( main4 );         memcpy( user_menu->minor[i].minor_name, token, len );      }      if (line != NULL) {         line = parse_token( line, token );         if (*token != '\0') {            key = parse_key( token );            if (key == ERROR) {               key = search( token, valid_func, CFG_FUNCS );               if (key == ERROR) {                  if (strlen( token ) != 2 || (text_t)token[0] <= ' ' ||                                              (text_t)token[1] <= ' ')                     return( config31 );                  key = (unsigned)(((text_t)token[0] << 8) | (text_t)token[1]);               } else                  key |= _FUNCTION;            } else if (key_func[KEY_IDX( key )] == TwoCharKey) {               if (line == NULL)                  return( config28 );               parse_token( line, token );               twokey = parse_key( token );               if (twokey == ERROR)                  return( config22 );               key = CREATE_TWOKEY( key, twokey );            }            user_menu->minor[i].minor_func = key;         }      }   }   return( NULL );}/* * Name:    process_menu * Purpose: handle the Menu configuration option * Author:  Jason Hood * Date:    July 22, 2005 * Passed:  line:  current line position *          token: what to do * Returns: NULL if okay, pointer to error message if not * Notes:   token is reused as a buffer. *          all names are case sensitive. */static const char *process_menu( char *line, char *token ){int  opt;char *hdr;int  i;static MENU_STR *cmenu = NULL;static MENU_LIST *popout = NULL;static int  erred = FALSE;   opt = search( token, valid_menu, VALID_MENU_DEFS );   /*    * if it doesn't exist, treat it as the name of a header    */   if (opt == ERROR)      opt = MENU_HEADER;   else      line = parse_token( line, token );   switch (opt) {      case MENU_CLEAR :         cmenu = NULL;         popout = NULL;         if (*token == '\0') {            for (i = 0; i < menu_cnt; ++i) {               free_menu( &menu[i].menu );               if (*menu[i].major_name != '\0')                  my_free( menu[i].major_name );            }            menu_cnt = 0;            user_idx = -1;            user_menu = NULL;            break;         }         /* fall through */      case MENU_HEADER :         if (*token == '\0')            return( config1 );         cmenu = NULL;         popout = NULL;         erred = FALSE;         for (i = 0; i < menu_cnt; ++i) {            hdr = menu[i].major_name;            if (*hdr == '\0')               ++hdr;            if (strcmp( hdr, token ) == 0) {               cmenu = &menu[i].menu;               if (opt == MENU_CLEAR) {                  free_menu( cmenu );                  if (i == user_idx) {                     user_idx = -1;                     user_menu = NULL;                  }               }               break;            }         }         if (cmenu == NULL) {            /*             * find an empty menu, assuming it was just cleared to be renamed             */            for (i = 0; i < menu_cnt; ++i) {               if (menu[i].menu.minor_cnt == 0  &&  i != user_idx)                  break;            }            if (i == MAJOR_MAX)               return( config34 );      /* too many menus */            menu[i].major_name = my_strdup( token );            if (menu[i].major_name == NULL)               return( main4 );            cmenu = &menu[i].menu;            if (token == "User" ||                (parse_token( line, token ), stricmp( token, "User" )) == 0) {               user_idx = i;               user_menu = &menu[user_idx].menu;            }            if (i == menu_cnt)               ++menu_cnt;         }         break;      case MENU_ITEM :         if (popout)            popout = NULL;         if (cmenu)            return( new_menu_item( cmenu, line, token ) );         /*          * menu item not in a menu          */         if (!erred) {            erred = TRUE;            return( config35 );         }         break;      case MENU_POPOUT :         if (cmenu) {            const char *errmsg = new_menu_item( cmenu, NULL, token );            if (errmsg != NULL)               return( errmsg );            popout = my_calloc( sizeof(MENU_LIST) );            if (popout == NULL)               return( main4 );            popout->next = popout_menu;            popout_menu = popout;            cmenu->minor[cmenu->minor_cnt-2].pop_out = &popout->popout;            cmenu->minor[cmenu->minor_cnt-2].minor_func = 0;            break;         }         if (!erred) {            erred = TRUE;            return( config35 );         }         break;      case MENU_POPITEM :         if (popout)            return( new_menu_item( &popout->popout, line, token ) );         if (!erred) {            erred = TRUE;            return( config35 );         }         break;   }   return( NULL );}/* * Name:    new_menu_item * Purpose: add an item to a menu * Author:  Jason Hood * Date:    July 23, 2005 * Passed:  mnu:    menu being updated *          line:   line containing item details *          token:  name of the item, as well as buffer for key/function * Returns: NULL if okay, pointer to error message if not. * Notes:   if the key/function already exists, replace the name. */static const char *new_menu_item( MENU_STR *mnu, char *line, char *token ){char *name;int  cnt;long key;int  twokey;int  i;MINOR_STR *minor;   /*    * "Menu Item" and "Menu Item -" both generate a separator, but    * "Menu Item - func" will treat "-" as an item name, not separator    */   if (*token == '-' && token[1] == '\0' && line == NULL)      *token = '\0';   if (*token) {      name = my_strdup( token );      if (name == NULL)         return( main4 );   } else      name = NULL;   key = ERROR;   line = parse_token( line, token );   if (*token) {      key = parse_key( token );      if (key == ERROR) {         key = search( token, valid_func, CFG_FUNCS );         if (key == ERROR) {            if (strlen( token ) != 2 || (text_t)token[0] <= ' ' ||                                        (text_t)token[1] <= ' ') {               my_free( name );               return( config31 );            }            key = (unsigned)(((text_t)token[0] << 8) | (text_t)token[1]);         } else            key |= _FUNCTION;      } else if (key_func[KEY_IDX( key )] == TwoCharKey) {         if (line == NULL) {            my_free( name );            return( config28 );         }         parse_token( line, token );         twokey = parse_key( token );         if (twokey == ERROR) {            my_free( name );            return( config22 );         }         key = CREATE_TWOKEY( key, twokey );      }   }   if (key != ERROR) {      for (i = mnu->minor_cnt - 1; i >= 1; --i) {         if (mnu->minor[i].minor_func == key) {            if (*mnu->minor[i].minor_name != '\0')               my_free( mnu->minor[i].minor_name );            mnu->minor[i].minor_name = name;            return( NULL );         }      }   }   if (mnu->minor_cnt == 0) {      i   = TRUE;      cnt = 3;      minor = malloc( cnt * sizeof(MINOR_STR) );   } else {      i   = FALSE;      cnt = mnu->minor_cnt + 1;      if (mnu->minor[0].minor_func == ERROR)         minor = realloc( mnu->minor, cnt * sizeof(MINOR_STR) );      else {         minor = malloc( cnt * sizeof(MINOR_STR) );         if (minor) {            memcpy( minor, mnu->minor, mnu->minor_cnt * sizeof(MINOR_STR) );            minor[0].minor_func = ERROR;         }      }   }   if (minor == NULL) {      my_free( name );   

⌨️ 快捷键说明

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