OSDN Git Service

Remove <windows.h> dependency
authorsdottaka <none@none>
Sat, 8 Sep 2012 14:37:59 +0000 (23:37 +0900)
committersdottaka <none@none>
Sat, 8 Sep 2012 14:37:59 +0000 (23:37 +0900)
Src/Common/Utf8FileDetect.cpp
Src/Common/Utf8FileDetect.h
Src/CompareOptions.cpp
Src/DiffList.cpp
Src/DiffList.h
Src/charsets.c
Src/codepage_detect.cpp

index 7b3e4c9..650e8a9 100644 (file)
@@ -22,7 +22,6 @@
 // ID line follows -- this is updated by SVN
 // $Id$
 
-#include <windows.h>
 #include "Utf8FileDetect.h"
 
 // Algorithm originally from:
  * @param [in] size Size of the buffer in bytes.
  * @return true if invalid bytes found, false otherwise.
  */
-bool CheckForInvalidUtf8(LPBYTE pBuffer, int size)
+bool CheckForInvalidUtf8(const char *pBuffer, int size)
 {
-       UINT8 * pVal2 = (UINT8 *)pBuffer;
+       unsigned char * pVal2 = (unsigned char *)pBuffer;
        for (int j = 0; j < size; ++j)
        {
                if ((*pVal2 == 0xC0) || (*pVal2 == 0xC1) || (*pVal2 >= 0xF5))
                        return true;
                pVal2++;
        }
-       pVal2 = (UINT8 *)pBuffer;
+       pVal2 = (unsigned char *)pBuffer;
        bool bUTF8 = false;
        for (int i = 0; i < (size - 3); ++i)
        {
index a7c85fb..e83a20e 100644 (file)
@@ -25,6 +25,6 @@
 #ifndef _UTF8FILEDETECT_H_
 #define _UTF8FILEDETECT_H_
 
-bool CheckForInvalidUtf8(LPBYTE pBuffer, int size);
+bool CheckForInvalidUtf8(const char *pBuffer, int size);
 
 #endif // _UTF8FILEDETECT_H_
index ea5a299..e1c327c 100644 (file)
@@ -6,10 +6,8 @@
 // ID line follows -- this is updated by SVN
 // $Id: ByteComparator.h 3397 2006-07-27 10:41:24Z kimmov $
 
-#include <windows.h>
-#include <crtdbg.h>
-#include "DIFF.H"
 #include "CompareOptions.h"
+#include "DIFF.H"
 
 // Global defined in diffutils code
 extern int recursive;
@@ -71,7 +69,7 @@ void CompareOptions::SetFromDiffOptions(const DIFFOPTIONS &options)
                m_ignoreWhitespace = WHITESPACE_IGNORE_ALL;
                break;
        default:
-               _RPTF0(_CRT_ERROR, "Unknown whitespace ignore value!");
+               throw "Unknown whitespace ignore value!";
                break;
        }
        m_bIgnoreBlankLines = options.bIgnoreBlankLines;
@@ -144,7 +142,7 @@ void DiffutilsOptions::SetToDiffUtils()
                output_style = OUTPUT_HTML;
                break;
        default:
-               _RPTF0(_CRT_ERROR, "Unknown output style!");
+               throw "Unknown output style!";
                break;
        }
 
@@ -216,7 +214,7 @@ void DiffutilsOptions::GetAsDiffOptions(DIFFOPTIONS &options)
                options.nIgnoreWhitespace = 2;
                break;
        default:
-               _RPTF0(_CRT_ERROR, "Unknown whitespace ignore value!");
+               throw "Unknown whitespace ignore value!";
                break;
        }
 }
index fb880f2..f44411f 100644 (file)
 // ID line follows -- this is updated by SVN
 // $Id: DiffList.cpp 7105 2010-01-14 21:14:22Z kimmov $
 
-#include <windows.h>
-#include <crtdbg.h>
-#include <assert.h>
+#include <cassert>
+#include <string>
+#include <sstream>
 #include "DiffList.h"
-#include "coretools.h"
 
 using std::swap;
 using std::vector;
@@ -244,7 +243,7 @@ bool DiffList::SetDiff(int nDiff, const DIFFRANGE & di)
  * @return -1 if line is before diff, 0 if line is in diff and
  * 1 if line is after diff.
  */
-int DiffList::LineRelDiff(UINT nLine, UINT nDiff) const
+int DiffList::LineRelDiff(unsigned int nLine, unsigned int nDiff) const
 {
        const DIFFRANGE * dfi = DiffRangeAt(nDiff);
        if (nLine < dfi->dbegin[0])
@@ -261,7 +260,7 @@ int DiffList::LineRelDiff(UINT nLine, UINT nDiff) const
  * @param [in] nDiff Index to diff table
  * @return TRUE if line is inside given difference.
  */
-bool DiffList::LineInDiff(UINT nLine, UINT nDiff) const
+bool DiffList::LineInDiff(unsigned int nLine, unsigned int nDiff) const
 {
        const DIFFRANGE * dfi = DiffRangeAt(nDiff);
        if (nLine >= dfi->dbegin[0] && nLine <= dfi->dend[0])
@@ -275,7 +274,7 @@ bool DiffList::LineInDiff(UINT nLine, UINT nDiff) const
  * @param [in] nLine Linenumber, 0-based.
  * @return Index to diff table, -1 if line is not inside any diff.
  */
-int DiffList::LineToDiff(UINT nLine) const
+int DiffList::LineToDiff(unsigned int nLine) const
 {
        const int nDiffCount = (int) m_diffs.size();
        if (nDiffCount == 0)
@@ -308,9 +307,12 @@ int DiffList::LineToDiff(UINT nLine) const
                        left = middle + 1;
                        break;
                default:
-                       _RPTF1(_CRT_ERROR, "Invalid return value %d from LineRelDiff(): "
-                               "-1, 0 or 1 expected!", result); 
+                       {
+                       std::stringstream s;
+                       s << "Invalid return value " << result << " from LineRelDiff(): -1, 0 or 1 expected!";
+                       throw s.str();
                        break;
+                       }
                }
        }
        return -1;
@@ -393,7 +395,7 @@ bool DiffList::HasSignificantDiffs() const
  * @param [in] nLine First line searched.
  * @return Index for next difference or -1 if no difference is found.
  */
-int DiffList::PrevSignificantDiffFromLine(UINT nLine) const
+int DiffList::PrevSignificantDiffFromLine(unsigned int nLine) const
 {
        int nDiff = -1;
        const int size = (int) m_diffs.size();
@@ -415,7 +417,7 @@ int DiffList::PrevSignificantDiffFromLine(UINT nLine) const
  * @param [in] nLine First line searched.
  * @return Index for previous difference or -1 if no difference is found.
  */
-int DiffList::NextSignificantDiffFromLine(UINT nLine) const
+int DiffList::NextSignificantDiffFromLine(unsigned int nLine) const
 {
        int nDiff = -1;
        const int nDiffCount = (int) m_diffs.size();
@@ -571,7 +573,7 @@ const DIFFRANGE * DiffList::LastSignificantDiffRange() const
  * @param [in] nLine First line searched.
  * @return Index for next difference or -1 if no difference is found.
  */
-int DiffList::PrevSignificant3wayDiffFromLine(UINT nLine, int nDiffType) const
+int DiffList::PrevSignificant3wayDiffFromLine(unsigned int nLine, int nDiffType) const
 {
        for (int i = m_diffs.size() - 1; i >= 0 ; i--)
        {
@@ -612,7 +614,7 @@ int DiffList::PrevSignificant3wayDiffFromLine(UINT nLine, int nDiffType) const
  * @param [in] nLine First line searched.
  * @return Index for previous difference or -1 if no difference is found.
  */
-int DiffList::NextSignificant3wayDiffFromLine(UINT nLine, int nDiffType) const
+int DiffList::NextSignificant3wayDiffFromLine(unsigned int nLine, int nDiffType) const
 {
        const int nDiffCount = m_diffs.size();
 
@@ -879,7 +881,7 @@ void DiffList::GetExtraLinesCounts(int nFiles, int extras[])
                for (file = 0; file < nFiles; file++)
                {
                        nline[file] = curDiff.end[file]-curDiff.begin[file]+1;
-                       nmaxline = max(nmaxline, nline[file]);
+                       nmaxline = std::max(nmaxline, nline[file]);
                }
                for (file = 0; file < nFiles; file++)
                        extras[file] += nmaxline - nline[file];
index a8aa361..58866ea 100644 (file)
@@ -138,22 +138,22 @@ public:
        int GetSignificantIndex(int nDiff) const;
        bool GetDiff(int nDiff, DIFFRANGE & di) const;
        bool SetDiff(int nDiff, const DIFFRANGE & di);
-       int LineRelDiff(UINT nLine, UINT nDiff) const;
-       bool LineInDiff(UINT nLine, UINT nDiff) const;
-       int LineToDiff(UINT nLine) const;
+       int LineRelDiff(unsigned int nLine, unsigned int nDiff) const;
+       bool LineInDiff(unsigned int nLine, unsigned int nDiff) const;
+       int LineToDiff(unsigned int nLine) const;
        bool GetPrevDiff(int nLine, int & nDiff) const;
        bool GetNextDiff(int nLine, int & nDiff) const;
        bool HasSignificantDiffs() const;
-       int PrevSignificantDiffFromLine(UINT nLine) const;
-       int NextSignificantDiffFromLine(UINT nLine) const;
+       int PrevSignificantDiffFromLine(unsigned int nLine) const;
+       int NextSignificantDiffFromLine(unsigned int nLine) const;
        int FirstSignificantDiff() const;
        int NextSignificantDiff(int nDiff) const;
        int PrevSignificantDiff(int nDiff) const;
        int LastSignificantDiff() const;
        const DIFFRANGE * FirstSignificantDiffRange() const;
        const DIFFRANGE * LastSignificantDiffRange() const;
-       int PrevSignificant3wayDiffFromLine(UINT nLine, int nDiffType) const;
-       int NextSignificant3wayDiffFromLine(UINT nLine, int nDiffType) const;
+       int PrevSignificant3wayDiffFromLine(unsigned int nLine, int nDiffType) const;
+       int NextSignificant3wayDiffFromLine(unsigned int nLine, int nDiffType) const;
        int FirstSignificant3wayDiff(int nDiffType) const;
        int NextSignificant3wayDiff(int nDiff, int nDiffType) const;
        int PrevSignificant3wayDiff(int nDiff, int nDiffType) const;
index 5912691..03d81a6 100644 (file)
   easily plug into a Win32 application that does not use Tidy elsewhere.
   Runtime-allocated indexes have been added to improve lookup speed.
 */
-
-#include <windows.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#ifndef _WIN32
+#include <strings.h>
+#endif
 #include "charsets.h"
 
+#ifdef _WIN32
+#define strcasecmp(a, b) stricmp((a), (b))
+#endif
+
 enum { no, yes };
 
 /* todo: documentation of table and data       */
@@ -975,7 +983,7 @@ static int CompareByName(const void *elem1, const void *elem2)
 {
        const struct _charsetInfo *p = *(const struct _charsetInfo **)elem1;
        const struct _charsetInfo *q = *(const struct _charsetInfo **)elem2;
-       return lstrcmpiA(p->charset, q->charset);
+       return strcasecmp(p->charset, q->charset);
 }
 
 static int CompareByCodePage(const void *elem1, const void *elem2)
index 7292005..aaf1aa9 100644 (file)
@@ -209,7 +209,7 @@ static unsigned GuessEncoding_from_bytes(LPCTSTR ext, const char *src, size_t le
        }
        else
        {
-               if (!CheckForInvalidUtf8((LPBYTE)src, len))
+               if (!CheckForInvalidUtf8(src, len))
                        cp = CP_UTF8;
        }
        if (guessEncodingType & 1)