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

📄 cfgfile.c

📁 dos下一个强大的文本编辑器,支持多文档、多窗口、二进制文件编辑。
💻 C
📖 第 1 页 / 共 3 页
字号:
                     else {
                        printf( "==> %s", line_in );
                        printf( "Color number out of range: line %u  : number %s\n",
                                 line_no, key );
                     }
                  }
               }
            }
         }

         /*
          * valid color not found, now try a valid mode
          */
         if (!found) {
            mode_index = search( key, valid_modes, NUM_MODES-1 );
            if (mode_index != ERROR) {
               found = TRUE;

               /*
                * if we find a valid mode, we need to search different
                *   option arrays before we find a valid assignment.
                */
               if (residue != NULL) {
                  residue = parse_token( residue, key );
                  if (*key != '\0' && *key != ';') {
                     switch ( mode_index ) {
                        case Ins         :
                        case Ind         :
                        case Smart       :
                        case Trim        :
                        case Eol         :
                        case Backup      :
                        case Ruler       :
                        case InflateTabs :
                        case JustRM      :
                           mode_no = search( key, off_on, 1 );
                           if (mode_no == ERROR) {
                              printf( "==> %s", line_in );
                              printf( "Off/On error: " );
                           }
                           break;
                        case LTAB     :
                        case PTAB     :
                           mode_no = atoi( key );
                           if (mode_no > 520 || mode_no < 1) {
                              mode_no = ERROR;
                              printf( "==> %s", line_in );
                              printf( "Tab error: " );
                           }
                           break;
                        case Left    :
                           mode_no = atoi( key );
                           if (mode_no < 1 || mode_no > modes[Right]) {
                              mode_no = ERROR;
                              printf( "==> %s", line_in );
                              printf( "Left margin error: " );
                           } else
                              --mode_no;
                           break;
                        case Para    :
                           mode_no = atoi( key );
                           if (mode_no < 1 || mode_no > modes[Right]) {
                              mode_no = ERROR;
                              printf( "==> %s", line_in );
                              printf( "Paragraph margin error: " );
                           } else
                              --mode_no;
                           break;
                        case Right   :
                           mode_no = atoi( key );
                           if (mode_no < modes[Left] || mode_no > 1040) {
                              mode_no = ERROR;
                              printf( "==> %s", line_in );
                              printf( "Right margin error: " );
                           } else
                              --mode_no;
                           break;
                        case Crlf    :
                           mode_no = search( key, valid_crlf, 1 );
                           if (mode_no == ERROR) {
                              printf( "==> %s", line_in );
                              printf( "CRLF or LF error: " );
                           }
                           break;
                        case WW      :
                           mode_no = search( key, valid_wraps, 2 );
                           if (mode_no == ERROR) {
                              printf( "==> %s", line_in );
                              printf( "Word wrap error: " );
                           }
                           break;
                        case Size    :
                           mode_no = search( key, valid_cursor, 1 );
                           if (mode_no == ERROR) {
                              printf( "==> %s", line_in );
                              printf( "Cursor size error: " );
                           }
                           break;
                        case Write_Z :
                           mode_no = search( key, valid_z, 1 );
                           if (mode_no == ERROR) {
                              printf( "==> %s", line_in );
                              printf( "Control Z error: " );
                           }
                           break;
                        case Date    :
                           mode_no = search( key, valid_dates, 5 );
                           if (mode_no == ERROR) {
                              printf( "==> %s", line_in );
                              printf( "Date format error: " );
                           }
                           break;
                        case Time    :
                           mode_no = search( key, valid_times, 1 );
                           if (mode_no == ERROR) {
                              printf( "==> %s", line_in );
                              printf( "Time format error: " );
                           }
                           break;
                        case Initcase    :
                           mode_no = search( key, init_case_modes, 1 );
                           if (mode_no == ERROR) {
                              printf( "==> %s", line_in );
                              printf( "Initial Case Mode error: " );
                           }
                           break;
                        case Match   :
                           for (i=0; i<256; i++)
                              sort_order.match[i] = (char)i;
                           new_sort_order( key, sort_order.match );
                           break;
                        case Ignore  :
                           for (i=0; i<256; i++)
                              sort_order.ignore[i] = (char)i;
                           for (i=65; i<91; i++)
                              sort_order.ignore[i] = (char)(i + 32);
                           new_sort_order( key, sort_order.ignore );
                           break;
                     }
                     if (mode_no != ERROR)
                        modes[mode_index] = mode_no;
                     else
                        printf( " line = %u  :  unknown mode = %s\n",
                              line_no, key );
                  }
               }
            }
         }
         if (!found) {
            printf( "==> %s", line_in );
            printf( "Unrecognized editor setting: line %u  :  %s\n", line_no, key );
         }
      }
   }
}


/*
 * Name:    parse_token
 * Purpose: given an input line, find the first token
 * Date:    June 5, 1992
 * 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.
 */
char *parse_token( char *line, char *token )
{
   /*
    * skip over any leading spaces.
    */
   while (*line == ' ')
      ++line;

   /*
    * put the characters into the token array until we run into a space
    *   or the terminating '\0';
    */
   while (*line != ' ' && *line != '\0' && *line != '\n')
      *token++ = *line++;
   *token = '\0';

   /*
    * return what's left on the line, if anything.
    */
   if (*line != '\0' && *line != '\n')
      return( line );
   else
      return( NULL );
}


/*
 * Name:    search
 * Purpose: binary search a CONFIG_DEFS structure
 * Date:    June 5, 1992
 * Passed:  token:  token to search for
 *          list:   list of valid tokens
 *          num:    number of valid tokens 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, 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:    parse_macro
 * Purpose: separate literals from keys in a macro definition
 * Date:    June 5, 1992
 * Passed:  macro_key:  key that we are a assigning a macro to
 *          residue:    pointer to macro defs
 * Notes:   for each token in macro def, find out if it's a literal or a
 *             function key.
 *          a literal begins with a ".  to put a " in a macro def, precede
 *             a " with a ".
 */
void parse_macro( int macro_key, char *residue )
{
int  rc;
char literal[1042];
char *l;
int  key_no;

   /*
    * reset any previous macro def.
    */
   initialize_macro( macro_key );
   while (residue != NULL) {
      /*
       * skip over any leading spaces.
       */
      while (*residue == ' ')
         ++residue;

      /*
       * done if we hit a comment
       */
      if (*residue == ';')
         residue = NULL;

      /*
       * check for a literal.
       */
      else if (*residue == '\"') {
         rc = parse_literal( macro_key, residue, literal, &residue );
         if (rc == OK) {
            l = literal;
            while (*l != '\0'  &&  rc == OK) {
               rc = record_keys( macro_key, *l );
               ++l;
            }
         } else {
            printf( "==> %s", line_in );
            printf( "Literal not recognized: line %u  : literal  %s\n", line_no, literal );
         }

      /*
       * check for a function key.
       */
      } else {
         residue = parse_token( residue, literal );
         key_no = search( literal, valid_keys, AVAIL_KEYS );
         if (key_no != ERROR)
            record_keys( macro_key, key_no+256 );
         else {
            printf( "==> %s", line_in );
            printf( "Unrecognized key: line %u  : key %s\n", line_no, literal );
         }
      }
   }
   check_macro( macro_key );
}


/*
 * Name:    parse_literal
 * Purpose: get all letters in a literal
 * Date:    June 5, 1992
 * Passed:  macro_key:  key that we are a assigning a macro to
 *          line:       current line position
 *          literal:    buffer to hold literal
 *          residue:    pointer to next token in line
 * Notes:   a literal begins with a ".  to put a " in a macro def, precede
 *             a " with a ".
 */
int  parse_literal( int macro_key, char *line, char *literal, char **residue )
{
int quote_state = 1;    /* we've already seen one " before we get here */

   line++;
   /*

⌨️ 快捷键说明

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