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

📄 commands.c

📁 功能强大的文本编辑器
💻 C
📖 第 1 页 / 共 3 页
字号:
#endif

               if (( *astr == function (*cbuf)) ||     /* characters match */
#if (WILDCARDS_HIGHSPEED)
                   (*astr == '?'))   /* or wild_card '?' */
#else
                   ((*astr == '?') && (wild_cards)))   /* or wild_card '?' */
                                /* ^^ kann entfallen !! */
#endif
               {
                  cbuf++;
                  p_len++;
                  astr++;
               }
               else
               {
#if (!WILDCARDS_HIGHSPEED)
                  if (!wild_cards)
                  { /* ^^ kann entfallen */
                     goto next_c1;
                  }
                  else
#endif
                  {
#if (!BUGFIX_28_09_94)
                     if (*astr == '*')
                     {
                        astr++;
                        bstr = astr;
                        t_rest -= (p_len + 1);
                        exp_search = 1;   /* from now on */
                        break;   /* for kk */
                     }
                     else
#endif
                     {
                        if ((perform_test_eol (cbuf, 0)) ||     /* end of line ? */
                            ((cbuf+p_rest) >= &buff[max_ind]))  /* end of text ? */
                        {
                           goto next_c1;                     /* stop search */
                        }
                        else
                        {
                           if (exp_search)
                           {                      /* expanded search mode */
                              if (astr == bstr)   /* NEU ! sonst probleme mit */
                              {                   /* text: DefaultSystemMenu  */
                                 cbuf++;          /* such: default*menu       */
                                 p_len++;
                              }
                              pp--;  /* one more try */
                              break;  /* for kk */
                           }
                           else
                           {
                              goto next_c1;
                           }
                        }  /* search not stopped */
                     }  /* != '*' */
                  }  /* wild_cards */
               }  /* if no match */
    
            }  /* for kk */
   
            t_len += p_len;
         }  /* for pp */
   
      /* found string inside range ? */
         if ((ii + (long)t_len) > i_limit)
            goto next_c1;  /* no: outside */
      }  /* wild_cards */
    
   /* string gefunden ! */
      if (!k_token)
      {
         found = 1;         /* o.k., abort search ! */
         break;    
      }
      else                  /* check, if token string ! */
      {
      /* char vor/hinter string */
         i1 = max (0L, (ii - 1));
         i2 = ii + t_len;

         if ((is_delimiter (buff[i1]) || (ii == 0L)) &&
             (is_delimiter (buff[i2])))
         {
            found = 1;
            break;
         }
      }

   next_c1:
      abuf += d_ii;
   }  /* for ii */

/* ii steht jetzt am anfang des gefundenen strings */
   if (direction)             /* vorwaerts-suche: */
      ii += t_len;       /* ende des strings */

/* ende suchvorgang */
   ss_len = t_len;
   if (found == 1)
      return ii;    /* act. zeiger */
   else
      return -1;    /* nothing found */

}  /* comm_find */

/* -FF-  */

#if (WITH_HEX_FIND)

long comm_find_byte (char FA_HU *buff, long index_1,
                     long max_ind, char byte_1, char byte_2)
{

/* Funktion sucht zwischen buff[index_1]...buff[max_ind] nach byte_1, */
/* wenn erfolgreich, return new byte_index, sonst -1.                   */

long index_0;
char FA_HU *buff_1;

   buff_1 = &buff[index_1];
   for (index_0 = index_1 ; index_0 < max_ind ; index_0++)
   {
   /* type cast (unsigned char) fuer z.B. 'H'ex 'F'ind "7e ff" */
      if (((unsigned char)(*buff_1) >= (unsigned char)(byte_1)) &&
          ((unsigned char)(*buff_1) <= (unsigned char)(byte_2)))
         return (index_0 + 1);
      buff_1++;
   }

   return -1;    /* nothing found */

}  /* comm_find_byte */

#endif

/* -FF-  */

long comm_lower_upper (char FA_HU *buff, long index_1,
                       long max_ind, int up_flag)
{

/* Funktion sucht zwischen buff[index_1]...buff[max_ind] nach dem 1. char, */
/* der kein delimiter ist, und ersetzt dann alle char mit tolower/toupper    */
/* bis zum 1. auftreten eines delimiters */

long ii, i1, i2;
char *abuf;

/* init */
   i1 = 0x7fffffff;
   i2 = -1;

/* search for start of next word */
   abuf = &buff[index_1];
   for (ii = index_1 ; ii < max_ind ; ii++)    /* excl. EOF !! */
   {
      if (!is_delimiter (*abuf))
      {
         i1 = ii;
         break;
      }
      abuf++;
   }

/* search for end of next word */
   abuf = &buff[i1];
   for (ii = i1 ; ii <= max_ind ; ii++)        /* incl. EOF !! */
   {
      if (is_delimiter (*abuf))
      {
         i2 = ii;
         break;
      }
      abuf++;
   }

/* found a valid string ? */
   if (i2 <= i1)
   {                        /* no */
      return -1;            /* return 'invalid' */
   }
   else
   {                        /* yes, convert all characters in between */
      abuf = &buff[i1];
      for (ii = i1 ; ii < i2 ; ii++)
      {
         if (is_german (*abuf))
         {
            lower_upper_umlaut (abuf, up_flag);
         }
         else
         {
            if (up_flag)
               *abuf = (char) toupper (*abuf);
            else
               *abuf = (char) tolower (*abuf);
         }

         abuf++;
      }
      return i2;            /* return new pointer */
   }

}  /* comm_lower_upper */

/* -FF-  */

int is_string_character (char FA_HU *buff, long index, long max_index)
{
/* check for string characters:
    "   yes
    \"  no

    '   yes, if delimiter before or behind (avoid Ada "ticks", e.g. Float'Image)
    \'  no ,       "
    \\' yes,       "
*/

    if  (
            (buff[        index    ] == '\"') &&
            (buff[max(0, (index-1))] != '\\')
        )
        return 1;    /* " */


    if (has_single_quote_string())
    {
        if  (
            (   buff[        index    ] == '\'') &&
                (
                    (buff[max(0, (index-1))] != '\\') ||
                    (buff[max(0, (index-2))] == '\\')
                ) &&
                (
                    (is_delimiter(buff[max(0, (index-1))])) ||    /* disable Ada ticks,    */
                    (is_delimiter(buff[       (index+1) ])) ||    /* e.g.: field'last      */
                    (buff[max(0        , (index-2))] == '\'') ||  /* enable short strings, */
                    (buff[min(max_index, (index+2))] == '\'')     /* e.g.: 'C'alc          */
                )
            )
            return 2;    /* ' */
    }


    return 0;       /* none */

}  /* is_string_character */

/* -FF-  */

static int is_visible_token (char FA_HU *buff, long start_index, long max_index,
                             int first, int direction)
{
/* check, if the found token is visible, i.e.: 
   a) not inside a string
   b) not inside a comment
*/

   return (!is_inside_string_or_comment (buff, start_index, max_index, first, direction));

}  /* is_visible_token */

/* -FF-  */

static char *get_strtok (char FA_HU *buff, long index_1, long max_ind, int direction,
                         int *start_ind)
{
/* isolate the token string around the actual index */

static char token[BUF_256];
int new_delim, old_delim;
int ii, i1, i2, len;


/* default */
   i1 = index_1;
   i2 = -1;
   

/* begin of token */
   old_delim = is_delimiter(buff[i1]);

   if (direction == -1)
   {
      for (ii = index_1 ; ii >= 0 ; ii--)   /* search backward */
      {
         new_delim = is_delimiter(buff[ii]);
         if (new_delim && !old_delim)
         {
            i1 = ii+1;      /* ii is the character before the token */
            break;
         } 
         old_delim = new_delim;
      }  /* for ii */
   }
   else
   {
      for (ii = index_1 ; ii <= max_ind ; ii++)   /* search forward */
      {
         new_delim = is_delimiter(buff[ii]);
         if (!new_delim)
         {
            i1 = ii;        /* this is the 1st character of the token */
            break;
         } 
      }  /* for ii */
   }


/* search end of token */
   old_delim = is_delimiter(buff[i1]);

   for (ii = i1+1 ; ii <= max_ind ; ii++)   /* search forward */
   {
      new_delim = is_delimiter(buff[ii]);
      if (new_delim && !old_delim)
      {
         i2 = ii;        /* this is 1 character behind the token */
         break;
      }
      old_delim = new_delim;
   }  /* for ii */


/* found valid token ? */
   if (i2 == -1)
   {
      return NULL;  /* no */
   }
   else
   {
      len = min((i2-i1), sizeof(token)-1);
      strncpy (token, &buff[i1], len);  /* yes */
      token[len] = '\0';
      *start_ind = i1;
      return token;
   }

}  /* get_strtok */

/* -FF-  */

long comm_ctrl_k (char FA_HU *buff, long index_1, long max_ind)
{

/* Funktion sucht zwischen buff[index_1]...buff[max_ind] nach der   */
/* korrespondierenden klammer. (){}[]                                 */
/* NEU ! Zusaetzlich zu den Klammern auch: #if <--> #else <--> #endif */

long ii, i1, i2;
int  level, start_level, start_ind, offset;
char found, klammer1 = 0, klammer2 = 0;

static int  direction, start_index;
static char *string_c [] =   { "#if",
                               "#else",
                               "#elif",
                               "#endif"
                             }; 

static char *string_ada1[] = { "if",
                               "else",
                               "elsif",
                               "end if"
                             }; 


static char end_string[] = {"end"};
static char *string_ptr;
static char token_string[BUF_256];



/* init direction on 1st run */
   if (direction == 0)
      direction = 1;

   start_level = 0;
   offset = 0;

/* suche nach erster klammer ueberhaupt */
/* NEW ! Check only the actual cursor position */
   found = 0;
   for (ii = index_1 ; ii <= index_1  /* ii < max_ind */ ; ii++)
   {
      if (is_visible_token(buff, ii, max_ind, 1, direction))
      {
      /* case 1 */
         if ((buff[ii] == '(') ||
             (buff[ii] == ')') ||
             (buff[ii] == '{') ||
             (buff[ii] == '}') ||
             (buff[ii] == '[') ||
             (buff[ii] == ']') ||
             (buff[ii] == '<') ||
             (buff[ii] == '>'))
         {
            klammer1 = buff[ii];
            found = 1;
            break;
         }

      /* case 2 */
         if (ii <= (max_ind - (long)strlen(string_c[3])))     /* strlen ("#endif") */
         {
            if ((strncmp(&buff[ii], string_c[0], strlen(string_c[0])) == 0) ||
                (strncmp(&buff[ii], string_c[1], strlen(string_c[1])) == 0) ||
                (strncmp(&buff[ii], string_c[2], strlen(string_c[2])) == 0) ||
                (strncmp(&buff[ii], string_c[3], strlen(string_c[3])) == 0))
            {
               klammer1 = buff[ii+2];   /* 'f', 'l' or 'n' */
               found = 2;
               break;
            }
         }

      /* case 3 */
         if (ii <= (max_ind - (long)strlen(string_ada1[3])))  /* strlen ("end if") */
         {
            if ((strnicmp(&buff[ii], string_ada1[0], strlen(string_ada1[0])) == 0) ||
                (strnicmp(&buff[ii], string_ada1[1], strlen(string_ada1[1])) == 0) ||
                (strnicmp(&buff[ii], string_ada1[2], strlen(string_ada1[2])) == 0) ||
                (strnicmp(&buff[ii], string_ada1[3], strlen(string_ada1[3])) == 0))
            {
               klammer1 = buff[ii+1];   /* 'f', 'l' or 'n' */
               found = 3;
               break;
            }
         }


⌨️ 快捷键说明

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