OSDN Git Service

RFE [ 897975 ] Syntax highlighting for INI files - Color "[...]"
authorKimmo Varis <kimmov@gmail.com>
Sun, 14 Mar 2004 12:06:17 +0000 (12:06 +0000)
committerKimmo Varis <kimmov@gmail.com>
Sun, 14 Mar 2004 12:06:17 +0000 (12:06 +0000)
Src/editlib/ini.cpp
Src/readme.txt

index 2f0a89f..8b27b9a 100644 (file)
@@ -1,9 +1,10 @@
 ///////////////////////////////////////////////////////////////////////////
 //  File:    ini.cpp
-//  Version: 1.1.0.4
-//  Updated: 19-Jul-1998
+//  Version: 1.1.
+//  Updated: 14-Mar-2004
 //
-//  Copyright:  Ferdinand Prantl, portions by Stcherbatchenko Andrei
+//  Copyright:  Ferdinand Prantl, portions by Stcherbatchenko Andrei,
+//              Tim Gerundt, Kimmo Varis
 //  E-mail:     prantl@ff.cuni.cz
 //
 //  INI syntax highlighing definition
 static char THIS_FILE[] = __FILE__;
 #endif
 
-//  C++ keywords (MSVC5.0 + POET5.0)
-static LPTSTR s_apszIniKeywordList[] =
-  {
-    _T ("["),
-    _T ("]"),
-    _T ("="),
-    NULL
-  };
-
-static BOOL
-IsXKeyword (LPTSTR apszKeywords[], LPCTSTR pszChars, int nLength)
-{
-  for (int L = 0; apszKeywords[L] != NULL; L++)
-    {
-      if (_tcsnicmp (apszKeywords[L], pszChars, nLength) == 0
-            && apszKeywords[L][nLength] == 0)
-        return TRUE;
-    }
-  return FALSE;
-}
-
-static BOOL
-IsIniKeyword (LPCTSTR pszChars, int nLength)
-{
-  return IsXKeyword (s_apszIniKeywordList, pszChars, nLength);
-}
-
 static BOOL
 IsIniNumber (LPCTSTR pszChars, int nLength)
 {
@@ -91,6 +65,7 @@ if (pBuf != NULL)\
 #define COOKIE_EXT_COMMENT      0x0004
 #define COOKIE_STRING           0x0008
 #define COOKIE_CHAR             0x0010
+#define COOKIE_SECTION          0x0020
 
 DWORD CCrystalTextView::
 ParseLineIni (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItems)
@@ -119,6 +94,10 @@ ParseLineIni (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItem
             {
               DEFINE_BLOCK (nPos, COLORINDEX_STRING);
             }
+          else if (dwCookie & COOKIE_SECTION)
+            {
+              DEFINE_BLOCK (nPos, COLORINDEX_FUNCNAME);
+            }
           else
             {
               if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (pszChars[nPos - 1]) && !xisalpha (pszChars[nPos + 1])))
@@ -170,6 +149,16 @@ out:
           continue;
         }
 
+      // Section header [...]
+      if (dwCookie & COOKIE_SECTION)
+        {
+          if (pszChars[I] == ']' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+            {
+              dwCookie &= ~COOKIE_SECTION;
+              bRedefineBlock = TRUE;
+            }
+          continue;
+        }
       if (pszChars[I] == ';')
         {
           DEFINE_BLOCK (I, COLORINDEX_COMMENT);
@@ -195,6 +184,17 @@ out:
             }
         }
 
+      // Section header [...]
+      if (pszChars[I] == '[')
+        {
+          if (!I || !xisalnum (pszChars[I - 1]))
+            {
+              DEFINE_BLOCK (I, COLORINDEX_FUNCNAME);
+              dwCookie |= COOKIE_SECTION;
+              continue;
+            }
+        }
+
       if (bFirstChar)
         {
           if (!_istspace (pszChars[I]))
@@ -214,11 +214,7 @@ out:
         {
           if (nIdentBegin >= 0)
             {
-              if (IsIniKeyword (pszChars + nIdentBegin, I - nIdentBegin))
-                {
-                  DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
-                }
-              else if (IsIniNumber (pszChars + nIdentBegin, I - nIdentBegin))
+              if (IsIniNumber (pszChars + nIdentBegin, I - nIdentBegin))
                 {
                   DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
                 }
@@ -251,11 +247,7 @@ out:
 
   if (nIdentBegin >= 0)
     {
-      if (IsIniKeyword (pszChars + nIdentBegin, I - nIdentBegin))
-        {
-          DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
-        }
-      else if (IsIniNumber (pszChars + nIdentBegin, I - nIdentBegin))
+      if (IsIniNumber (pszChars + nIdentBegin, I - nIdentBegin))
         {
           DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
         }
index 42346b3..9ecbc6f 100644 (file)
@@ -1,3 +1,8 @@
+2004-03-14 Kimmo
+ RFE [ 897975 ] Syntax highlighting for INI files
+  Color "[...]"
+  Src/editlib: ini.cpp
+
 2004-03-13 Kimmo
  Add User Manual draft to CVS
   Docs/Users/Manual: *.*