Author: spetreolle
Date: Fri Jan 21 20:29:45 2011
New Revision: 50454
URL:
http://svn.reactos.org/svn/reactos?rev=50454&view=rev
Log:
[CMAKE]
Use cmake subversion capabilities to generate buildno.h and version.h.
Added:
branches/cmake-bringup/include/reactos/buildno.h.cmake
branches/cmake-bringup/include/reactos/version.cmake
branches/cmake-bringup/include/reactos/version.h.cmake
branches/cmake-bringup/tools/getdate.cmd (with props)
Removed:
branches/cmake-bringup/tools/buildno/
branches/cmake-bringup/tools/xml.cpp
branches/cmake-bringup/tools/xml.h
Modified:
branches/cmake-bringup/CMakeLists.txt
branches/cmake-bringup/tools/CMakeLists.txt
Modified: branches/cmake-bringup/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/CMakeLists.txt?re…
==============================================================================
--- branches/cmake-bringup/CMakeLists.txt [iso-8859-1] (original)
+++ branches/cmake-bringup/CMakeLists.txt [iso-8859-1] Fri Jan 21 20:29:45 2011
@@ -1,6 +1,9 @@
cmake_minimum_required(VERSION 2.6)
project(REACTOS)
+
+#versioning
+include(include/reactos/version.cmake)
# Don't escape preprocessor definition values added via add_definitions
cmake_policy(SET CMP0005 OLD)
@@ -44,9 +47,9 @@
add_subdirectory(lib)
if(NOT MSVC)
- export(TARGETS widl nci buildno gendib cabman cdmake mkhive spec2def geninc FILE
${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- )
+ export(TARGETS widl nci gendib cabman cdmake mkhive spec2def geninc FILE
${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- )
else()
- export(TARGETS nci buildno gendib cabman cdmake mkhive spec2def geninc FILE
${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- )
+ export(TARGETS nci gendib cabman cdmake mkhive spec2def geninc FILE
${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- )
endif()
else()
@@ -221,11 +224,6 @@
file(MAKE_DIRECTORY ${REACTOS_BINARY_DIR}/include/reactos)
- add_custom_command(
- OUTPUT ${REACTOS_BINARY_DIR}/include/reactos/buildno.h
- COMMAND native-buildno ${REACTOS_BINARY_DIR}/include/reactos/buildno.h
- DEPENDS ${REACTOS_SOURCE_DIR}/include/reactos/version.h)
-
add_custom_target(buildno_header ALL DEPENDS
${REACTOS_BINARY_DIR}/include/reactos/buildno.h)
file(MAKE_DIRECTORY ${REACTOS_BINARY_DIR}/subsystems/win32/win32k/dib)
Added: branches/cmake-bringup/include/reactos/buildno.h.cmake
URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/include/reactos/b…
==============================================================================
--- branches/cmake-bringup/include/reactos/buildno.h.cmake (added)
+++ branches/cmake-bringup/include/reactos/buildno.h.cmake [iso-8859-1] Fri Jan 21
20:29:45 2011
@@ -1,0 +1,18 @@
+/* Do not edit - Machine generated */
+#ifndef _INC_REACTOS_BUILDNO
+#define _INC_REACTOS_BUILDNO
+#define KERNEL_VERSION_BUILD @KERNEL_VERSION_BUILD@
+#define KERNEL_VERSION_BUILD_HEX 0x@KERNEL_VERSION_BUILD_HEX@
+#define KERNEL_VERSION_BUILD_STR "@KERNEL_VERSION_BUILD@@REVISION@"
+#define KERNEL_VERSION_BUILD_RC "@KERNEL_VERSION_BUILD@@REVISION@\0"
+#define KERNEL_RELEASE_RC "@KERNEL_VERSION@\0"
+#define KERNEL_RELEASE_STR "@KERNEL_VERSION@"
+#define KERNEL_VERSION_RC "@KERNEL_VERSION@\0"
+#define KERNEL_VERSION_STR "@KERNEL_VERSION@"
+#define REACTOS_DLL_VERSION_MAJOR @REACTOS_DLL_VERSION_MAJOR@
+#define REACTOS_DLL_RELEASE_RC "@DLL_VERSION_STR@\0"
+#define REACTOS_DLL_RELEASE_STR "@DLL_VERSION_STR@"
+#define REACTOS_DLL_VERSION_RC "@DLL_VERSION_STR@\0"
+#define REACTOS_DLL_VERSION_STR "@DLL_VERSION_STR@"
+#endif
+/* EOF */
Added: branches/cmake-bringup/include/reactos/version.cmake
URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/include/reactos/v…
==============================================================================
--- branches/cmake-bringup/include/reactos/version.cmake (added)
+++ branches/cmake-bringup/include/reactos/version.cmake [iso-8859-1] Fri Jan 21 20:29:45
2011
@@ -1,0 +1,64 @@
+macro(today RESULT)
+ if (WIN32)
+ #execute_process(COMMAND "cmd" "/c" "date"
"/T" OUTPUT_VARIABLE ${RESULT})
+ #string(REGEX REPLACE "(..)/(..)/(....).*" "\\3\\2\\1"
${RESULT} ${${RESULT}})
+ execute_process(COMMAND "${REACTOS_SOURCE_DIR}/tools/getdate.cmd"
OUTPUT_VARIABLE ${RESULT})
+ string(STRIP ${${RESULT}} ${RESULT})
+ elseif(UNIX)
+ execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE
${${RESULT}})
+ else (WIN32)
+ message(SEND_ERROR "date not implemented")
+ set(${RESULT} 00000000)
+ endif (WIN32)
+endmacro(today)
+
+macro(inttohex INTVALUE OUTPUT_VARIABLE)
+ list(APPEND HEXLIST 0 1 2 3 4 5 6 7 8 9 a b c d e f)
+ list(GET HEXLIST ${INTVALUE} ${OUTPUT_VARIABLE})
+endmacro()
+
+macro(converttohex INTVALUE OUTPUT_VARIABLE)
+ set(REMAINING ${INTVALUE})
+ while(REMAINING)
+ math(EXPR REMAINDER "${REMAINING}%16")
+ inttohex(${REMAINDER} HEXCHAR)
+ math(EXPR REMAINING "${REMAINING}/16")
+ set(${OUTPUT_VARIABLE} "${HEXCHAR}${${OUTPUT_VARIABLE}}")
+ endwhile()
+endmacro()
+
+today(KERNEL_VERSION_BUILD)
+
+set(KERNEL_VERSION_MAJOR "0")
+set(KERNEL_VERSION_MINOR "4")
+set(KERNEL_VERSION_PATCH_LEVEL "0")
+set(COPYRIGHT_YEAR "2011")
+# KERNEL_VERSION_BUILD_TYPE is "SVN", "RC1", "RC2" or
"" (for the release)
+set(KERNEL_VERSION_BUILD_TYPE "SVN")
+
+
+set(KERNEL_VERSION "${KERNEL_VERSION_MAJOR}.${KERNEL_VERSION_MINOR}")
+if(KERNEL_VERSION_PATCH_LEVEL)
+ set(KERNEL_VERSION
"${KERNEL_VERSION}.${KERNEL_VERSION_PATCH_LEVEL}-${KERNEL_VERSION_BUILD_TYPE}")
+else()
+ set(KERNEL_VERSION "${KERNEL_VERSION}-${KERNEL_VERSION_BUILD_TYPE}")
+endif()
+
+math(EXPR REACTOS_DLL_VERSION_MAJOR "${KERNEL_VERSION_MAJOR}+42")
+set(DLL_VERSION_STR
"${REACTOS_DLL_VERSION_MAJOR}.${KERNEL_VERSION_MINOR}-${KERNEL_VERSION_BUILD_TYPE}")
+if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn")
+ find_package(Subversion)
+ if(Subversion_FOUND)
+ subversion_wc_info(${CMAKE_CURRENT_SOURCE_DIR} SVNINFO)
+ if(SVNINFO_WC_REVISION)
+ set(REVISION "-r${SVNINFO_WC_REVISION}")
+ converttohex(${SVNINFO_WC_REVISION} KERNEL_VERSION_BUILD_HEX)
+ endif()
+ endif()
+else()
+ set(REVISION "-rUNKNOWN")
+ set(HEXREVISION "0x0")
+endif()
+
+configure_file(include/reactos/version.h.cmake
${REACTOS_BINARY_DIR}/include/reactos/version.h)
+configure_file(include/reactos/buildno.h.cmake
${REACTOS_BINARY_DIR}/include/reactos/buildno.h)
Added: branches/cmake-bringup/include/reactos/version.h.cmake
URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/include/reactos/v…
==============================================================================
--- branches/cmake-bringup/include/reactos/version.h.cmake (added)
+++ branches/cmake-bringup/include/reactos/version.h.cmake [iso-8859-1] Fri Jan 21
20:29:45 2011
@@ -1,0 +1,31 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS kernel
+ * FILE: include/internal/version.h
+ * PURPOSE: Defines the current version
+ * PROGRAMMER: David Welch (welch(a)mcmail.com)
+ * REVISIONS:
+ * 1999-11-06 (ea)
+ * Moved from include/internal in include/reactos
+ * to be used by buildno.
+ * 2002-01-17 (ea)
+ * KERNEL_VERSION removed. Use
+ * reactos/buildno.h:KERNEL_VERSION_STR instead.
+ */
+
+#ifndef __VERSION_H
+#define __VERSION_H
+
+#define KERNEL_VERSION_MAJOR @KERNEL_VERSION_MAJOR@
+#define KERNEL_VERSION_MINOR @KERNEL_VERSION_MINOR@
+#define KERNEL_VERSION_PATCH_LEVEL @KERNEL_VERSION_PATCH_LEVEL@
+
+#define COPYRIGHT_YEAR "@COPYRIGHT_YEAR@"
+
+/* KERNEL_VERSION_BUILD_TYPE is L"SVN", L"RC1", L"RC2" or
L"" (for the release) */
+#define KERNEL_VERSION_BUILD_TYPE "@KERNEL_VERSION_BUILD_TYPE@"
+
+
+#endif
+
+/* EOF */
Modified: branches/cmake-bringup/tools/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/tools/CMakeLists.…
==============================================================================
--- branches/cmake-bringup/tools/CMakeLists.txt [iso-8859-1] (original)
+++ branches/cmake-bringup/tools/CMakeLists.txt [iso-8859-1] Fri Jan 21 20:29:45 2011
@@ -1,9 +1,6 @@
-
-add_library(xml xml.cpp)
#add_executable(pefixup pefixup.c)
-add_subdirectory(buildno)
add_subdirectory(cabman)
add_subdirectory(cdmake)
add_subdirectory(gendib)
Added: branches/cmake-bringup/tools/getdate.cmd
URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/tools/getdate.cmd…
==============================================================================
--- branches/cmake-bringup/tools/getdate.cmd (added)
+++ branches/cmake-bringup/tools/getdate.cmd [iso-8859-1] Fri Jan 21 20:29:45 2011
@@ -1,0 +1,44 @@
+@echo off
+goto test
+
+:get_date_yyyymmdd
+setlocal enableextensions enabledelayedexpansion
+set _RV=
+set _ERR=0
+set _CMD=reg query "HKCU\Control Panel\International" /v sShortDate
+for /f "usebackq skip=2 tokens=3,* delims= " %%i in (`%_CMD%`) do (
+rem Amsterdam/Houston servers:
+rem Short date format (%%i): M/d/yyyy
+rem Sample %DATE%: Thu 05/29/2009
+rem London servers:
+rem Short date format (%%i): dd/MM/yyyy
+rem Sample %DATE%: 29/05/2009
+set D=!DATE!
+rem Uncomment these for debug
+rem echo i: %%i
+rem echo D: !D!
+if "%%i"=="M/d/yyyy" (
+rem I'm assuming the day abbreviation will always be three chars
+rem (so we account for four in total, including the space). So
+rem far, I can attest that this is definitely the case on Wed &
+rem Thu ;-)
+set yyyy=!D:~-4!
+set mm=!D:~-10,-8!
+set dd=!D:~-7,-5!
+) else if "%%i"=="dd/MM/yyyy" (
+set yyyy=!D:~-4!
+set mm=!D:~-7,-5!
+set dd=!D:~-10,-8!
+) else (
+echo fatal: I don't understand this system's date format (%%i^)
+set _ERR=1
+)
+)
+set _RETVAL=!yyyy!!mm!!dd!
+endlocal & set _YYYYMMDD=%_RETVAL% & set _ERROR=%_ERR%
+exit /b %_ERROR%
+
+:test
+call :get_date_yyyymmdd
+rem echo formatted date: %_YYYYMMDD%
+echo %_YYYYMMDD%
Propchange: branches/cmake-bringup/tools/getdate.cmd
------------------------------------------------------------------------------
svn:eol-style = native
Removed: branches/cmake-bringup/tools/xml.cpp
URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/tools/xml.cpp?rev…
==============================================================================
--- branches/cmake-bringup/tools/xml.cpp [iso-8859-1] (original)
+++ branches/cmake-bringup/tools/xml.cpp (removed)
@@ -1,971 +1,0 @@
-/*
- * Copyright (C) 2005 Casper S. Hornstrup
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifdef _MSC_VER
-#pragma warning ( disable : 4786 )
-#pragma warning ( disable : 4996 )
-#endif//_MSC_VER
-
-#ifdef WIN32
- #include <direct.h>
- #include <io.h>
-#else
- #include <stdio.h>
- #include <sys/stat.h>
- #include <unistd.h>
-
- // Some hosts don't define PATH_MAX in unistd.h
- #if !defined(PATH_MAX)
- #include <limits.h>
- #endif
-
- #define MAX_PATH PATH_MAX
-#endif
-
-#include <assert.h>
-#include <ctype.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include "xml.h"
-
-#ifndef MAX_PATH
-#define MAX_PATH _MAX_PATH
-#endif
-
-using std::string;
-using std::vector;
-
-#ifdef WIN32
-#define getcwd _getcwd
-#endif//WIN32
-
-static const char* WS = " \t\r\n";
-static const char* WSEQ = " =\t\r\n";
-
-string working_directory;
-
-std::vector<char> vectorize(const std::string &str)
-{
- std::vector<char> result( str.size() + 1 );
- strcpy( &result[0], str.c_str() );
- return result;
-}
-
-void vectappend(std::vector<char> &strvec, const char *str)
-{
- if (*str) { strvec[strlen(&strvec[0])] = *str; str++; }
- while (*str)
- {
- strvec.push_back(*str);
- str++;
- }
- strvec.push_back(0);
-}
-
-void vectappend(std::vector<char> &strvec, const std::string &str)
-{
- vectappend(strvec, str.c_str());
-}
-
-void vectappend(std::vector<char> &strvec, char ch)
-{
- strvec[strlen(&strvec[0])] = ch;
- strvec.push_back(0);
-}
-
-XMLException::XMLException (
- const std::string& location,
- const char* format, ... )
-{
- va_list args;
- va_start ( args, format );
- SetExceptionV ( location, format, args );
- va_end ( args );
-}
-
-void XMLException::SetExceptionV ( const std::string& location, const char* format,
va_list args )
-{
- char buffer[1024];
- vsnprintf(buffer, sizeof(buffer)-1, format, args);
- _e = location + ": " + buffer;
-}
-
-void XMLException::SetException ( const std::string& location, const char* format,
... )
-{
- va_list args;
- va_start ( args, format );
- SetExceptionV ( location, format, args );
- va_end ( args );
-}
-
-XMLIncludes::~XMLIncludes()
-{
- for ( size_t i = 0; i < this->size(); i++ )
- delete (*this)[i];
-}
-
-void
-InitWorkingDirectory()
-{
- // store the current directory for path calculations
- working_directory.resize ( MAX_PATH );
- working_directory[0] = 0;
- getcwd ( &working_directory[0], working_directory.size() );
- working_directory.resize ( strlen ( working_directory.c_str() ) );
-}
-
-#ifdef _MSC_VER
-unsigned __int64
-#else
-unsigned long long
-#endif
-filelen ( FILE* f )
-{
-#ifdef WIN32
- return _filelengthi64 ( _fileno(f) );
-#else
-# if defined(__FreeBSD__) || defined(__APPLE__) || defined(__CYGWIN__)
- struct stat file_stat;
- if ( fstat(fileno(f), &file_stat) != 0 )
-# else
- struct stat64 file_stat;
- if ( fstat64(fileno(f), &file_stat) != 0 )
-# endif // __FreeBSD__
- return 0;
- return file_stat.st_size;
-#endif // WIN32
-}
-
-Path::Path()
-{
- if ( !working_directory.size() )
- InitWorkingDirectory();
- string s ( working_directory );
- const char* p = strtok ( &s[0], "/\\" );
- while ( p )
- {
- if ( *p )
- path.push_back ( p );
- p = strtok ( NULL, "/\\" );
- }
-}
-
-Path::Path ( const Path& cwd, const string& file )
-{
- string s ( cwd.Fixup ( file, false ) );
- const char* p = strtok ( &s[0], "/\\" );
- while ( p )
- {
- if ( *p )
- path.push_back ( p );
- p = strtok ( NULL, "/\\" );
- }
-}
-
-string
-Path::Fixup ( const string& file, bool include_filename ) const
-{
- if ( strchr ( "/\\", file[0] )
-#ifdef WIN32
- // this squirreliness is b/c win32 has drive letters and *nix doesn't...
- || file[1] == ':'
-#endif//WIN32
- )
- {
- return file;
- }
- vector<string> pathtmp ( path );
- vector<char> tmp = vectorize( file );
- const char* prev = strtok ( &tmp[0], "/\\" );
- const char* p = strtok ( NULL, "/\\" );
- while ( p )
- {
- if ( !strcmp ( prev, "." ) )
- ; // do nothing
- else if ( !strcmp ( prev, ".." ) )
- {
- // this squirreliness is b/c win32 has drive letters and *nix doesn't...
-#ifdef WIN32
- if ( pathtmp.size() > 1 )
-#else
- if ( pathtmp.size() )
-#endif
- pathtmp.resize ( pathtmp.size() - 1 );
- }
- else
- pathtmp.push_back ( prev );
- prev = p;
- p = strtok ( NULL, "/\\" );
- }
- if ( include_filename )
- pathtmp.push_back ( prev );
-
- // reuse tmp variable to return recombined path
- tmp = vectorize("");
- for ( size_t i = 0; i < pathtmp.size(); i++ )
- {
- // this squirreliness is b/c win32 has drive letters and *nix doesn't...
-#ifdef WIN32
- if ( i ) vectappend(tmp, "/");
-#else
- vectappend(tmp, "/");
-#endif
- vectappend(tmp, pathtmp[i]);
- }
- return &tmp[0];
-}
-
-string
-Path::RelativeFromWorkingDirectory ()
-{
- string out = "";
- for ( size_t i = 0; i < path.size(); i++ )
- {
- out += "/" + path[i];
- }
- return RelativeFromWorkingDirectory ( out );
-}
-
-string
-Path::RelativeFromWorkingDirectory ( const string& path )
-{
- return Path::RelativeFromDirectory ( path, working_directory );
-}
-
-string
-Path::RelativeFromDirectory (
- const string& path,
- const string& base_directory )
-{
- vector<string> vbase, vpath, vout;
- Path::Split ( vbase, base_directory, true );
- Path::Split ( vpath, path, true );
-#ifdef WIN32
- // this squirreliness is b/c win32 has drive letters and *nix doesn't...
- // not possible to do relative across different drive letters
- {
- char path_driveletter = (path[1] == ':') ? toupper(path[0]) : 0;
- char base_driveletter = (base_directory[1] == ':') ?
toupper(base_directory[0]) : 0;
- if ( path_driveletter != base_driveletter )
- return path;
- }
-#endif
- size_t i = 0;
- while ( i < vbase.size() && i < vpath.size() && vbase[i] ==
vpath[i] )
- ++i;
-
- // did we go through all of the path?
- if ( vbase.size() == vpath.size() && i == vpath.size() )
- return ".";
-
- if ( i < vbase.size() )
- {
- // path goes above our base directory, we will need some ..'s
- for ( size_t j = i; j < vbase.size(); j++ )
- vout.push_back ( ".." );
- }
-
- while ( i < vpath.size() )
- vout.push_back ( vpath[i++] );
-
- // now merge vout into a string again
- string out = vout[0];
- for ( i = 1; i < vout.size(); i++ )
- {
- out += "/" + vout[i];
- }
- return out;
-}
-
-void
-Path::Split (
- vector<string>& out,
- const string& path,
- bool include_last )
-{
- string s ( path );
- const char* prev = strtok ( &s[0], "/\\" );
- const char* p = strtok ( NULL, "/\\" );
- out.resize ( 0 );
- while ( p )
- {
- if ( strcmp ( prev, "." ) )
- out.push_back ( prev );
- prev = p;
- p = strtok ( NULL, "/\\" );
- }
- if ( include_last && strcmp ( prev, "." ) )
- out.push_back ( prev );
- // special-case where path only has "."
- // don't move this check up higher as it might miss
- // some funny paths...
- if ( !out.size() && !strcmp ( prev, "." ) )
- out.push_back ( "." );
-}
-
-XMLFile::XMLFile()
-{
-}
-
-void
-XMLFile::close()
-{
- _buf.resize(0);
- _p = _end = NULL;
-}
-
-bool
-XMLFile::open ( const string& filename_ )
-{
- close();
- FILE* f = fopen ( filename_.c_str(), "rb" );
- if ( !f )
- return false;
- unsigned long len = (unsigned long)filelen(f);
- _buf.resize ( len );
- fread ( &_buf[0], 1, len, f );
- fclose ( f );
- _p = _buf.c_str();
- _end = _p + len;
- _filename = filename_;
- next_token();
- return true;
-}
-
-// next_token() moves the pointer to next token, which may be
-// an xml element or a text element, basically it's a glorified
-// skipspace, normally the user of this class won't need to call
-// this function
-void
-XMLFile::next_token()
-{
- _p += strspn ( _p, WS );
-}
-
-bool
-XMLFile::next_is_text()
-{
- return *_p != '<';
-}
-
-bool
-XMLFile::more_tokens ()
-{
- return _p != _end;
-}
-
-// get_token() is used to return a token, and move the pointer
-// past the token
-bool
-XMLFile::get_token ( string& token )
-{
- const char* tokend;
- if ( !strncmp ( _p, "<!--", 4 ) )
- {
- tokend = strstr ( _p, "-->" );
- if ( !tokend )
- tokend = _end;
- else
- tokend += 3;
- }
- else if ( !strncmp ( _p, "<?", 2 ) )
- {
- tokend = strstr ( _p, "?>" );
- if ( !tokend )
- tokend = _end;
- else
- tokend += 2;
- }
- else if ( *_p == '<' )
- {
- tokend = strchr ( _p, '>' );
- if ( !tokend )
- tokend = _end;
- else
- ++tokend;
- }
- else
- {
- tokend = strchr ( _p, '<' );
- if ( !tokend )
- tokend = _end;
- while ( tokend > _p && isspace(tokend[-1]) )
- --tokend;
- }
- if ( tokend == _p )
- return false;
- token = string ( _p, tokend-_p );
- _p = tokend;
- next_token();
- return true;
-}
-
-bool
-XMLFile::get_token ( string& token, string& location )
-{
- location = Location();
- return get_token ( token );
-}
-
-string
-XMLFile::Location() const
-{
- int line = 1;
- char line_str[13];
- const char* p = strchr ( _buf.c_str(), '\n' );
- while ( p && p < _p )
- {
- ++line;
- p = strchr ( p+1, '\n' );
- }
- sprintf(line_str, "(%i)", line);
- return _filename + line_str;
-}
-
-XMLAttribute::XMLAttribute()
-{
-}
-
-XMLAttribute::XMLAttribute(
- const string& name_,
- const string& value_ )
- : name(name_), value(value_)
-{
-}
-
-XMLAttribute::XMLAttribute ( const XMLAttribute& src )
- : name(src.name), value(src.value)
-{
-
-}
-
-XMLAttribute& XMLAttribute::operator = ( const XMLAttribute& src )
-{
- name = src.name;
- value = src.value;
- return *this;
-}
-
-XMLElement::XMLElement (
- XMLFile* xmlFile,
- const string& location )
- : xmlFile ( xmlFile ),
- location ( location ),
- parentElement ( NULL )
-{
-}
-
-XMLElement::~XMLElement()
-{
- size_t i;
- for ( i = 0; i < attributes.size(); i++ )
- delete attributes[i];
- for ( i = 0; i < subElements.size(); i++ )
- delete subElements[i];
-}
-
-void
-XMLElement::AddSubElement ( XMLElement* e )
-{
- subElements.push_back ( e );
- e->parentElement = this;
-}
-
-// Parse()
-// This function takes a single xml tag ( i.e. beginning with '<' and
-// ending with '>', and parses out it's tag name and constituent
-// attributes.
-// Return Value: returns true if you need to look for a </tag> for
-// the one it just parsed...
-bool
-XMLElement::Parse (
- const string& token,
- bool& end_tag )
-{
- const char* p = token.c_str();
- assert ( *p == '<' );
- ++p;
- p += strspn ( p, WS );
-
- // check if this is a comment
- if ( !strncmp ( p, "!--", 3 ) )
- {
- name = "!--";
- end_tag = false;
- return false; // never look for end tag to a comment
- }
-
- end_tag = ( *p == '/' );
- if ( end_tag )
- {
- ++p;
- p += strspn ( p, WS );
- }
- const char* end = strpbrk ( p, WS );
- if ( !end )
- {
- end = strpbrk ( p, "/>" );
- assert ( end );
- }
- name = string ( p, end-p );
- p = end;
- p += strspn ( p, WS );
- while ( *p != '>' && *p != '/' )
- {
- end = strpbrk ( p, WSEQ );
- if ( !end )
- {
- end = strpbrk ( p, "/>" );
- assert ( end );
- }
- string attribute ( p, end-p ), value;
- p = end;
- p += strspn ( p, WS );
- if ( *p == '=' )
- {
- ++p;
- p += strspn ( p, WS );
- char quote = 0;
- if ( strchr ( "\"'", *p ) )
- {
- quote = *p++;
- end = strchr ( p, quote );
- }
- else
- {
- end = strpbrk ( p, WS );
- }
- if ( !end )
- {
- end = strchr ( p, '>' );
- assert(end);
- if ( end[-1] == '/' )
- end--;
- }
- value = string ( p, end-p );
- p = end;
- if ( quote && *p == quote )
- p++;
- p += strspn ( p, WS );
- }
- else if ( name[0] != '!' )
- {
- throw XMLSyntaxErrorException (
- location,
- "attributes must have values" );
- }
- attributes.push_back ( new XMLAttribute ( attribute, value ) );
- }
- return !( *p == '/' ) && !end_tag;
-}
-
-XMLAttribute*
-XMLElement::GetAttribute (
- const string& attribute,
- bool required )
-{
- // this would be faster with a tree-based container, but our attribute
- // lists are likely to stay so short as to not be an issue.
- for ( size_t i = 0; i < attributes.size(); i++ )
- {
- if ( attribute == attributes[i]->name )
- return attributes[i];
- }
- if ( required )
- {
- throw XMLRequiredAttributeNotFoundException (
- location,
- attribute,
- name );
- }
- return NULL;
-}
-
-const XMLAttribute*
-XMLElement::GetAttribute (
- const string& attribute,
- bool required ) const
-{
- // this would be faster with a tree-based container, but our attribute
- // lists are likely to stay so short as to not be an issue.
- for ( size_t i = 0; i < attributes.size(); i++ )
- {
- if ( attribute == attributes[i]->name )
- return attributes[i];
- }
- if ( required )
- {
- throw XMLRequiredAttributeNotFoundException (
- location,
- attribute,
- name );
- }
- return NULL;
-}
-
-int
-XMLElement::FindElement ( const std::string& type, int prev ) const
-{
- int done = subElements.size();
- while ( ++prev < done )
- {
- XMLElement* e = subElements[prev];
- if ( e->name == type )
- return prev;
- }
- return -1;
-}
-
-int
-XMLElement::GetElements (
- const std::string& type,
- std::vector<XMLElement*>& v )
-{
- int find = FindElement ( type );
- v.resize ( 0 );
- while ( find != -1 )
- {
- v.push_back ( subElements[find] );
- find = FindElement ( type, find );
- }
- return v.size();
-}
-
-int
-XMLElement::GetElements (
- const std::string& type,
- std::vector<const XMLElement*>& v ) const
-{
- int find = FindElement ( type );
- v.resize ( 0 );
- while ( find != -1 )
- {
- v.push_back ( subElements[find] );
- find = FindElement ( type, find );
- }
- return v.size();
-}
-
-// XMLParse()
-// This function reads a "token" from the file loaded in XMLFile
-// if it finds a tag that is non-singular, it parses sub-elements and/or
-// inner text into the XMLElement that it is building to return.
-// Return Value: an XMLElement allocated via the new operator that contains
-// it's parsed data. Keep calling this function until it returns NULL
-// (no more data)
-XMLElement*
-XMLParse (
- XMLFile& f,
- XMLIncludes* includes,
- const Path& path,
- bool* pend_tag = NULL )
-{
- string token, location;
- if ( !f.get_token(token,location) )
- return NULL;
- bool end_tag, is_include = false;
-
- while
- (
- token[0] != '<'
- || !strncmp ( token.c_str (), "<!--", 4 )
- || !strncmp ( token.c_str (), "<?", 2 )
- )
- {
- if ( token[0] != '<' )
- {
- throw XMLSyntaxErrorException (
- location,
- "expecting xml tag, not '%s'",
- token.c_str () );
- }
- if ( !f.get_token ( token, location ) )
- return NULL;
- }
-
- XMLElement* e = new XMLElement (
- &f,
- location );
- bool bNeedEnd = e->Parse ( token, end_tag );
-
- if ( e->name == "xi:include" && includes )
- {
- XMLAttribute* att;
- att = e->GetAttribute ( "href", true );
- assert ( att );
- string includeFile ( path.Fixup ( att->value, true ) );
- string topIncludeFile (
- Path::RelativeFromWorkingDirectory ( includeFile ) );
- includes->push_back (
- new XMLInclude ( e, path, topIncludeFile ) );
- is_include = true;
- }
-
- if ( !bNeedEnd )
- {
- if ( pend_tag )
- *pend_tag = end_tag;
- else if ( end_tag )
- {
- delete e;
- throw XMLSyntaxErrorException (
- location,
- "end tag '%s' not expected",
- token.c_str() );
- return NULL;
- }
- return e;
- }
- bool bThisMixingErrorReported = false;
- while ( f.more_tokens () )
- {
- if ( f.next_is_text () )
- {
- if ( !f.get_token ( token, location ) || token.size () == 0 )
- {
- throw XMLInvalidBuildFileException (
- location,
- "internal tool error - get_token() failed when more_tokens()
returned true" );
- break;
- }
- if ( e->subElements.size() && !bThisMixingErrorReported )
- {
- throw XMLSyntaxErrorException (
- location,
- "mixing of inner text with sub elements" );
- bThisMixingErrorReported = true;
- }
- if ( strchr ( token.c_str (), '>' ) )
- {
- throw XMLSyntaxErrorException (
- location,
- "invalid symbol '>'" );
- }
- if ( e->value.size() > 0 )
- {
- throw XMLSyntaxErrorException (
- location,
- "multiple instances of inner text" );
- e->value += " " + token;
- }
- else
- e->value = token;
- }
- else
- {
- XMLElement* e2 = XMLParse (
- f, is_include ? NULL : includes, path, &end_tag );
- if ( !e2 )
- {
- string e_location = e->location;
- string e_name = e->name;
- delete e;
- throw XMLInvalidBuildFileException (
- e_location,
- "end of file found looking for end tag: </%s>",
- e_name.c_str() );
- break;
- }
- if ( end_tag )
- {
- if ( e->name != e2->name )
- {
- string e2_location = e2->location;
- string e_name = e->name;
- string e2_name = e2->name;
- delete e;
- delete e2;
- throw XMLSyntaxErrorException (
- e2_location,
- "end tag name mismatch - found </%s> but was expecting
</%s>",
- e2_name.c_str(),
- e_name.c_str() );
- break;
- }
- delete e2;
- break;
- }
- if ( e->value.size () > 0 && !bThisMixingErrorReported )
- {
- string e_location = e->location;
- delete e;
- throw XMLSyntaxErrorException (
- e_location,
- "mixing of inner text with sub elements" );
- bThisMixingErrorReported = true;
- }
- e->AddSubElement ( e2 );
- }
- }
- return e;
-}
-
-void
-XMLReadFile (
- XMLFile& f,
- XMLElement& head,
- XMLIncludes& includes,
- const Path& path )
-{
- for ( ;; )
- {
- XMLElement* e = XMLParse ( f, &includes, path );
- if ( !e )
- return;
- head.AddSubElement ( e );
- }
-}
-
-XMLElement*
-XMLLoadInclude (
- XMLInclude& include,
- XMLIncludes& includes )
-{
- XMLAttribute* att;
- att = include.e->GetAttribute("href", true);
- assert(att);
-
- string file ( include.path.Fixup(att->value, true) );
- string top_file ( Path::RelativeFromWorkingDirectory ( file ) );
- include.e->attributes.push_back ( new XMLAttribute ( "top_href",
top_file ) );
- XMLFile* fInc = new XMLFile();
- if ( !fInc->open ( file ) )
- {
- include.fileExists = false;
- // look for xi:fallback element
- for ( size_t i = 0; i < include.e->subElements.size (); i++ )
- {
- XMLElement* e2 = include.e->subElements[i];
- if ( e2->name == "xi:fallback" )
- {
- // now look for xi:include below...
- for ( i = 0; i < e2->subElements.size (); i++ )
- {
- XMLElement* e3 = e2->subElements[i];
- if ( e3->name == "xi:include" )
- {
- att = e3->GetAttribute ( "href", true );
- assert ( att );
- string includeFile (
- include.path.Fixup ( att->value, true ) );
- string topIncludeFile (
- Path::RelativeFromWorkingDirectory ( includeFile ) );
- XMLInclude* fallbackInclude =
- new XMLInclude ( e3, include.path, topIncludeFile );
-
- XMLElement* value = XMLLoadInclude (*fallbackInclude, includes
);
- delete fallbackInclude;
- return value;
- }
- }
- throw XMLInvalidBuildFileException (
- e2->location,
- "<xi:fallback> must have a <xi:include>
sub-element" );
- return NULL;
- }
- }
- return NULL;
- }
- else
- {
- include.fileExists = true;
- XMLElement* new_e = new XMLElement (
- fInc,
- include.e->location );
- new_e->name = "xi:included";
- Path path2 ( include.path, att->value );
- XMLReadFile ( *fInc, *new_e, includes, path2 );
- return new_e;
- }
-}
-
-XMLElement*
-XMLLoadFile (
- const string& filename,
- const Path& path,
- XMLIncludes& includes )
-{
- XMLFile* f = new XMLFile();
-
- if ( !f->open ( filename ) )
- {
- delete f;
- throw XMLFileNotFoundException ( "(virtual)", filename );
- return NULL;
- }
-
- XMLElement* head = new XMLElement ( f, "(virtual)" );
-
- XMLReadFile ( *f, *head, includes, path );
-
- for ( size_t i = 0; i < includes.size (); i++ )
- {
- XMLElement* e = includes[i]->e;
- XMLElement* e2 = XMLLoadInclude ( *includes[i], includes );
- if ( !e2 )
- {
- throw XMLFileNotFoundException (
- f->Location(),
- e->GetAttribute ( "top_href", true )->value );
- }
- XMLElement* parent = e->parentElement;
- XMLElement** parent_container = NULL;
- if ( !parent )
- {
- string location = e->location;
- delete e;
- delete f;
- throw XMLException ( location, "internal tool error: xi:include
doesn't have a parent" );
- return NULL;
- }
- for ( size_t j = 0; j < parent->subElements.size (); j++ )
- {
- if ( parent->subElements[j] == e )
- {
- parent_container = &parent->subElements[j];
- break;
- }
- }
- if ( !parent_container )
- {
- string location = e->location;
- delete e;
- delete f;
- throw XMLException ( location, "internal tool error: couldn't find
xi:include in parent's sub-elements" );
- return NULL;
- }
- // replace inclusion tree with the imported tree
- e2->parentElement = e->parentElement;
- e2->name = e->name;
- e2->attributes = e->attributes;
- *parent_container = e2;
- e->attributes.resize ( 0 );
- delete e;
- }
- delete f;
- return head;
-}
-
-XMLElement*
-XMLLoadFile ( const string& filename )
-{
- Path path;
- XMLIncludes includes;
- return XMLLoadFile ( filename, path, includes );
-}
Removed: branches/cmake-bringup/tools/xml.h
URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/tools/xml.h?rev=5…
==============================================================================
--- branches/cmake-bringup/tools/xml.h [iso-8859-1] (original)
+++ branches/cmake-bringup/tools/xml.h (removed)
@@ -1,242 +1,0 @@
-/*
- * Copyright (C) 2005 Casper S. Hornstrup
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#pragma once
-
-#include <string>
-#include <vector>
-#include <stdarg.h>
-
-class XMLElement;
-
-extern std::string working_directory;
-
-void
-InitWorkingDirectory();
-
-#ifdef _MSC_VER
-unsigned __int64
-#else
-unsigned long long
-#endif
-filelen ( FILE* f );
-
-class XMLException
-{
-public:
- XMLException ( const std::string& location, const char* format, ... );
- const std::string& operator *() { return _e; }
-
-protected:
- XMLException() {}
- void SetExceptionV ( const std::string& location, const char* format, va_list args
);
- void SetException ( const std::string& location, const char* format, ... );
-
-private:
- std::string _e;
-};
-
-class XMLSyntaxErrorException : public XMLException
-{
-public:
- XMLSyntaxErrorException (
- const std::string& location,
- const char* format, ... )
- {
- va_list args;
- va_start ( args, format );
- SetExceptionV ( location, format, args );
- va_end ( args );
- }
-};
-
-class XMLRequiredAttributeNotFoundException : public XMLException
-{
-public:
- XMLRequiredAttributeNotFoundException (
- const std::string& location,
- const std::string& attributeName,
- const std::string& elementName )
- {
- SetException ( location, "Required attribute '%s' not found in element
'%s'",
- attributeName.c_str(),
- elementName.c_str() );
- }
-};
-
-class XMLInvalidBuildFileException : public XMLException
-{
-public:
- XMLInvalidBuildFileException (
- const std::string& location,
- const char* format,
- ... )
- {
- va_list args;
- va_start ( args, format );
- SetExceptionV ( location, format, args );
- va_end ( args );
- }
-};
-
-class XMLFileNotFoundException : public XMLException
-{
-public:
- XMLFileNotFoundException (
- const std::string& location,
- const std::string& filename )
- {
- SetException ( location, "Can't open file '%s'", filename.c_str()
);
- }
-};
-
-class Path
-{
- std::vector<std::string> path;
-public:
- Path(); // initializes path to getcwd();
- Path ( const Path& cwd, const std::string& filename );
- std::string Fixup ( const std::string& filename, bool include_filename ) const;
-
- std::string RelativeFromWorkingDirectory ();
- static std::string RelativeFromWorkingDirectory ( const std::string& path );
- static std::string RelativeFromDirectory ( const std::string& path, const
std::string& base_directory);
-
- static void Split (
- std::vector<std::string>& out,
- const std::string& path,
- bool include_last );
-};
-
-class XMLInclude
-{
-public:
- XMLElement *e;
- Path path;
- std::string topIncludeFilename;
- bool fileExists;
-
- XMLInclude (
- XMLElement* e_,
- const Path& path_,
- const std::string topIncludeFilename_ )
- : e ( e_ ),
- path ( path_ ),
- topIncludeFilename ( topIncludeFilename_ )
- {
- }
-};
-
-class XMLIncludes : public std::vector<XMLInclude*>
-{
-public:
- ~XMLIncludes();
-};
-
-class XMLFile
-{
- friend class XMLElement;
-public:
- XMLFile();
- void close();
- bool open(const std::string& filename);
- void next_token();
- bool next_is_text();
- bool more_tokens();
- bool get_token ( std::string& token );
- bool get_token ( std::string& token, std::string& location );
- const std::string& filename() { return _filename; }
- std::string Location() const;
-
-private:
- std::string _buf, _filename;
-
- const char *_p, *_end;
-};
-
-
-class XMLAttribute
-{
-public:
- std::string name;
- std::string value;
-
- XMLAttribute();
- XMLAttribute ( const std::string& name_, const std::string& value_ );
- XMLAttribute ( const XMLAttribute& );
- XMLAttribute& operator = ( const XMLAttribute& );
-};
-
-
-class XMLElement
-{
-public:
- XMLFile* xmlFile;
- std::string location;
- std::string name;
- std::vector<XMLAttribute*> attributes;
- XMLElement* parentElement;
- std::vector<XMLElement*> subElements;
- std::string value;
-
- XMLElement (
- XMLFile* xmlFile,
- const std::string& location );
-
- ~XMLElement();
-
- bool Parse (
- const std::string& token,
- bool& end_tag);
-
- void AddSubElement ( XMLElement* e );
-
- XMLAttribute* GetAttribute (
- const std::string& attribute,
- bool required);
-
- const XMLAttribute* GetAttribute (
- const std::string& attribute,
- bool required ) const;
-
- int FindElement (
- const std::string& type,
- int prev = -1 ) const;
-
- int GetElements (
- const std::string& type,
- std::vector<XMLElement*>& v );
-
- int GetElements (
- const std::string& type,
- std::vector<const XMLElement*>& v ) const;
-};
-
-XMLElement*
-XMLLoadFile (
- const std::string& filename,
- const Path& path,
- XMLIncludes& includes );
-
-XMLElement*
-XMLLoadFile ( const std::string& filename );
-
-std::vector<char> vectorize(const std::string &str);
-void vectappend(std::vector<char> &strvec, char ch);
-void vectappend(std::vector<char> &strvec, const char *charstr);
-void vectappend(std::vector<char> &strvec, const std::string &str);