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

📄 cfgfile.c

📁 该内容是《》一书的光盘内容
💻 C
📖 第 1 页 / 共 2 页
字号:
                              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 );
         }
      }
   }
}



char *parse_token( char *line, char *token )
{
   
   while (*line == ' ')
      ++line;

   
   while (*line != ' ' && *line != '\0' && *line != '\n')
      *token++ = *line++;
   *token = '\0';

   
   if (*line != '\0' && *line != '\n')
      return( line );
   else
      return( NULL );
}



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 );
}



void parse_macro( int macro_key, char *residue )
{
int  rc;
char literal[1042];
char *l;
int  key_no;

   
   initialize_macro( macro_key );
   while (residue != NULL) {
      
      while (*residue == ' ')
         ++residue;

     
      if (*residue == ';')
         residue = NULL;

     
      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 );
         }

      
      } 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 );
}



int  parse_literal( int macro_key, char *line, char *literal, char **residue )
{
int quote_state = 1;    

   line++;
   
   while (*line != '\0' && *line != '\n') {
      if (*line != '\"')
         *literal++ = *line++;
      else {
         if (*(line+1) == '\"') {
            *literal++ = '\"';
            line++;
            line++;
         } else {
            line++;
            --quote_state;
            break;
         }
      }
   }
   *literal = '\0';

   
   if (*line != '\0' && *line != '\n')
      *residue = line;
   else
      *residue = NULL;
   if (quote_state != 0) {
      *residue = NULL;
      return( ERROR );
   } else
      return( OK );
}



void initialize_macro( int macro_key )
{
register int next;
int  prev;

   next = macros.first_stroke[macro_key];

  
   if (next != STROKE_LIMIT+1) {
      do {
         prev = next;
         next = macros.strokes[next].next;
         macros.strokes[prev].key  = MAX_KEYS+1;
         macros.strokes[prev].next = STROKE_LIMIT+1;
         ++stroke_count;
      } while (next != -1);
   }

  
   for (next=0; macros.strokes[next].next != STROKE_LIMIT+1;)
      next++;
   macros.first_stroke[macro_key] = next;
   macros.strokes[next].key  = -1;
   macros.strokes[next].next = -1;
}



void clear_previous_macro( int macro_key )
{
register int next;
int prev;

   next = macros.first_stroke[macro_key];

   
   if (next != STROKE_LIMIT+1) {
      do {
         prev = next;
         next = macros.strokes[next].next;
         macros.strokes[prev].key  = MAX_KEYS+1;
         macros.strokes[prev].next = STROKE_LIMIT+1;
      } while (next != -1);
   }

   macros.first_stroke[macro_key] = STROKE_LIMIT+1;
}



void check_macro( int macro_key )
{
register int next;
register int key;

  
   key = macro_key;
   if (key != 0) {
      next = macros.first_stroke[key];
      if (macros.strokes[next].key == -1) {
         macros.strokes[next].key  = MAX_KEYS+1;
         macros.strokes[next].next = STROKE_LIMIT+1;
         macros.first_stroke[key-256] = STROKE_LIMIT+1;
         if (key_func.key[key] == PlayBack)
            key_func.key[key] = 0;
      }
   }
}



int  record_keys( int macro_key, int key )
{
register int next;
register int prev;
int func;
int rc;

   rc = OK;
   if (stroke_count == 0) {
      printf( "==> %s", line_in );
      printf( "No more room in macro buffer:  line %u\n",
               line_no );
      rc = ERROR;
   } else {
      func = getfunc( key );
      if (func != RecordMacro && func != SaveMacro && func != LoadMacro &&
          func != ClearAllMacros) {

         
         next = macros.first_stroke[macro_key];
         if (macros.strokes[next].next != STROKE_LIMIT+1) {
            while (macros.strokes[next].next != -1)
               next = macros.strokes[next].next;
         }
         prev = next;

       
         if (macros.strokes[next].key != -1) {
            for (; next < STROKE_LIMIT &&
                         macros.strokes[next].next != STROKE_LIMIT+1;)
               next++;
            if (next == STROKE_LIMIT) {
               for (next=0; next < prev &&
                            macros.strokes[next].next != STROKE_LIMIT+1;)
                  next++;
            }
         }
         if (next == prev && macros.strokes[prev].key != -1) {
            rc = ERROR;
         } else {
        
            macros.strokes[prev].next = next;
            macros.strokes[next].next = -1;
            macros.strokes[next].key  = key;
            stroke_count--;
         }
      }
   }
   return( rc );
}



void new_sort_order( unsigned char *residue, unsigned char *sort )
{
int i;

   sort += 33;
   for (i=33; *residue != '\0'  &&  *residue != '\n' && i <= 255; i++)
      *sort++ = *residue++;
}



int  get_stroke_count( void )
{
int count = 0;
int i;

   for (i=0; i<STROKE_LIMIT; i++)
      if (macros.strokes[i].next == STROKE_LIMIT+1)
         ++count;
   return( count );
}



etfunc( int c )
{
register int i = c;

   if (i <= 256)
      i = 0;
   else
      i = key_func.key[i-256];
   return( i );
}



void clear_previous_twokey( int two_key )
{
int i;

   for (i=0; i < MAX_TWO_KEYS; i++) {
      if (two_key == two_key_list.key[i].parent_key) {
         two_key_list.key[i].parent_key = 0;
         two_key_list.key[i].child_key  = 0;
         two_key_list.key[i].func       = 0;
      }
   }
}


int  insert_twokey( int parent_key, int child_key, int func_no )
{
register int i;
int  rc;

   for (i=0; i < MAX_TWO_KEYS; i++) {
      if (parent_key == two_key_list.key[i].parent_key) {
         if (child_key == two_key_list.key[i].child_key) {
            two_key_list.key[i].parent_key = 0;
            two_key_list.key[i].child_key  = 0;
            two_key_list.key[i].func       = 0;
         }
      }
   }
   for (i=0; i < MAX_TWO_KEYS; i++) {
      if (two_key_list.key[i].parent_key == 0) {
         two_key_list.key[i].parent_key = parent_key;
         two_key_list.key[i].child_key  = child_key;
         two_key_list.key[i].func       = func_no;
         break;
      }
   }
   rc = OK;
   if (i == MAX_TWO_KEYS)
      rc = ERROR;
   return( rc );
}

⌨️ 快捷键说明

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