Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ken-martin/kwsys
  • isanych/kwsys
  • scivision/kwsys
  • nvartolomei/kwsys
  • alexy.pellegrini/kwsys
  • leha-bot/kwsys
  • utils/kwsys
  • lakor64/kwsys
  • dbahadir/kwsys
  • evansanita713/kwsys
  • chrstphrchvz/kwsys
  • robertmaynard/kwsys
  • shannonbooth/kwsys
  • brad.king/kwsys
  • eberge/kwsys
  • gjasny/kwsys
  • ben.boeckel/kwsys
  • madscientist/kwsys
  • ulatekh/kwsys
  • Joker-Van/kwsys
  • chuck.atkins/kwsys
  • egorpugin/kwsys
  • mwestphal/kwsys
  • purpleKarrot/kwsys
  • do-m-en/kwsys
  • nicber/kwsys
  • FloriansGit/kwsys
  • pa.solodovnikov/kwsys
  • sbwilson/kwsys
  • R2RT/kwsys
  • asit-dhal/kwsys
  • qarni/kwsys
  • nilsgladitz/kwsys
  • fwinkl/kwsys
  • leon-richardt/kwsys
  • jdavidberger/kwsys
  • seanm/kwsys
  • shawn.waldon/kwsys
  • svelez/kwsys
  • jrtc27/kwsys
  • bdvd/kwsys
  • multiplemonomials/kwsys
  • mwillers/kwsys
  • hernancmartinez/kwsys
  • semlanik/kwsys
  • jesusjcmtool/kwsys
  • vvs31415/kwsys
  • DerDakon/kwsys
  • metti/kwsys
  • dublet/kwsys
  • blowekamp/kwsys
  • bryonbean/kwsys
  • luzpaz/kwsys
  • kfitch42/kwsys
  • sebholt/kwsys
  • clinton/kwsys
  • volo-zyko/kwsys
  • hjmjohnson/kwsys
  • kyle.edwards/kwsys
  • sankhesh/kwsys
  • sebastianlipponer/kwsys
  • veprbl/kwsys
  • nekto1989/kwsys
  • todoooo/kwsys
  • spiros.tsalikis/kwsys
  • dnakamura/kwsys
  • dawesc/kwsys
  • orgads/kwsys
  • whoozle/kwsys
  • makise-homura/kwsys
  • LetWe/kwsys
  • lemniscati/kwsys
  • rleigh/kwsys
  • sjoubert/kwsys
  • dzenanz/kwsys
  • georg-emg/kwsys
  • marc.chevrier/kwsys
  • mstorsjo/kwsys
  • clemenswasser/kwsys
  • besser82/kwsys
  • thewtex/kwsys
  • yuriy-odonnell-epic/kwsys
  • huangguojun/kwsys
  • ceztko/kwsys
  • klossto/kwsys
  • cory.quammen/kwsys
  • cwarner-8702/kwsys
  • flagarde/kwsys
  • petk/kwsys
  • tstellar/kwsys
  • Lekensteyn/kwsys
  • crondog/kwsys
  • ihnorton/kwsys
  • albert-astals-cid-kdab/kwsys
  • alimpfard/kwsys
  • leibabarry/kwsys
  • jvanboxtel/kwsys
  • laurent.malka/kwsys
  • martin.duffy/kwsys
  • brad0/kwsys
  • jpr42/kwsys
  • neek78/kwsys
  • nnemkin/kwsys
  • Pospelove/kwsys
  • timblechmann/kwsys
  • nocnokneo/kwsys
  • hygonsoc/kwsys
  • dutow/kwsys
  • novas0x2a/kwsys
  • Markus87/kwsys
  • Xeonacid/kwsys
111 results
Show changes
Commits on Source (1515)
Showing with 2749 additions and 2331 deletions
---
# This configuration requires clang-format version 18 exactly.
BasedOnStyle: Mozilla
AlignOperands: false
AllowShortFunctionsOnASingleLine: InlineOnly
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterEnum: true
AfterFunction: true
AfterStruct: true
AfterUnion: true
BreakBeforeBraces: Custom
ColumnLimit: 79
IndentPPDirectives: AfterHash
QualifierAlignment: Right
SortUsingDeclarations: false
SpaceAfterTemplateKeyword: true
Standard: Cpp03
...
.git* export-ignore
# import off
.gitattributes -export-ignore
.hooks* export-ignore
# Custom attribute to mark sources as using the kwsys C code style.
[attr]kwsys-c-style whitespace=tab-in-indent format.clang-format=18
/GitSetup export-ignore
/*.sh export-ignore eol=lf
/*.bash export-ignore eol=lf
/.clang-format export-ignore
# import on
*.c kwsys-c-style
*.c.in kwsys-c-style
*.cxx kwsys-c-style
*.h kwsys-c-style
*.h.in kwsys-c-style
*.hxx kwsys-c-style
*.hxx.in kwsys-c-style
*.cmake whitespace=tab-in-indent
*.rst whitespace=tab-in-indent conflict-marker-size=79
*.txt whitespace=tab-in-indent
[hooks "chain"]
pre-commit = GitSetup/pre-commit
/*=========================================================================
Program: KWSys - Kitware System Library
Module: Base64.c
Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
#include "kwsysPrivate.h"
#include KWSYS_HEADER(Base64.h)
/* Work-around CMake dependency scanning limitation. This must
duplicate the above list of headers. */
#if 0
# include "Base64.h.in"
# include "Base64.h.in"
#endif
/*--------------------------------------------------------------------------*/
static const unsigned char kwsysBase64EncodeTable[65] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
/*--------------------------------------------------------------------------*/
static const unsigned char kwsysBase64DecodeTable[256] =
{
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0x3E,0xFF,0xFF,0xFF,0x3F,
0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,
0x3C,0x3D,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,
0xFF,0x00,0x01,0x02,0x03,0x04,0x05,0x06,
0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,
0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,
0x17,0x18,0x19,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,
0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,
0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,
0x31,0x32,0x33,0xFF,0xFF,0xFF,0xFF,0xFF,
static unsigned char const kwsysBase64EncodeTable[65] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
static unsigned char const kwsysBase64DecodeTable[256] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0x3E, 0xFF, 0xFF, 0xFF, 0x3F, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D,
0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
/*------------------------------------*/
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
/*--------------------------------------------------------------------------*/
static unsigned char kwsysBase64EncodeChar(int c)
{
return kwsysBase64EncodeTable[(unsigned char)c];
}
/*--------------------------------------------------------------------------*/
static unsigned char kwsysBase64DecodeChar(unsigned char c)
{
return kwsysBase64DecodeTable[c];
}
/*--------------------------------------------------------------------------*/
/* Encode 3 bytes into a 4 byte string. */
void kwsysBase64_Encode3(const unsigned char *src, unsigned char *dest)
void kwsysBase64_Encode3(unsigned char const* src, unsigned char* dest)
{
dest[0] = kwsysBase64EncodeChar((src[0] >> 2) & 0x3F);
dest[1] = kwsysBase64EncodeChar(((src[0] << 4) & 0x30)|((src[1] >> 4) & 0x0F));
dest[2] = kwsysBase64EncodeChar(((src[1] << 2) & 0x3C)|((src[2] >> 6) & 0x03));
dest[1] =
kwsysBase64EncodeChar(((src[0] << 4) & 0x30) | ((src[1] >> 4) & 0x0F));
dest[2] =
kwsysBase64EncodeChar(((src[1] << 2) & 0x3C) | ((src[2] >> 6) & 0x03));
dest[3] = kwsysBase64EncodeChar(src[2] & 0x3F);
}
/*--------------------------------------------------------------------------*/
/* Encode 2 bytes into a 4 byte string. */
void kwsysBase64_Encode2(const unsigned char *src, unsigned char *dest)
void kwsysBase64_Encode2(unsigned char const* src, unsigned char* dest)
{
dest[0] = kwsysBase64EncodeChar((src[0] >> 2) & 0x3F);
dest[1] = kwsysBase64EncodeChar(((src[0] << 4) & 0x30)|((src[1] >> 4) & 0x0F));
dest[1] =
kwsysBase64EncodeChar(((src[0] << 4) & 0x30) | ((src[1] >> 4) & 0x0F));
dest[2] = kwsysBase64EncodeChar(((src[1] << 2) & 0x3C));
dest[3] = '=';
}
/*--------------------------------------------------------------------------*/
/* Encode 1 bytes into a 4 byte string. */
void kwsysBase64_Encode1(const unsigned char *src, unsigned char *dest)
void kwsysBase64_Encode1(unsigned char const* src, unsigned char* dest)
{
dest[0] = kwsysBase64EncodeChar((src[0] >> 2) & 0x3F);
dest[1] = kwsysBase64EncodeChar(((src[0] << 4) & 0x30));
......@@ -106,7 +78,6 @@ void kwsysBase64_Encode1(const unsigned char *src, unsigned char *dest)
dest[3] = '=';
}
/*--------------------------------------------------------------------------*/
/* Encode 'length' bytes from the input buffer and store the
encoded stream into the output buffer. Return the length of the encoded
buffer (output). Note that the output buffer must be allocated by the caller
......@@ -117,90 +88,82 @@ void kwsysBase64_Encode1(const unsigned char *src, unsigned char *dest)
actually knowing how much data to expect (if the input is not a multiple of
3 bytes then the extra padding needed to complete the encode 4 bytes will
stop the decoding anyway). */
unsigned long kwsysBase64_Encode(const unsigned char *input,
unsigned long length,
unsigned char *output,
int mark_end)
size_t kwsysBase64_Encode(unsigned char const* input, size_t length,
unsigned char* output, int mark_end)
{
const unsigned char *ptr = input;
const unsigned char *end = input + length;
unsigned char *optr = output;
unsigned char const* ptr = input;
unsigned char const* end = input + length;
unsigned char* optr = output;
/* Encode complete triplet */
while ((end - ptr) >= 3)
{
while ((end - ptr) >= 3) {
kwsysBase64_Encode3(ptr, optr);
ptr += 3;
optr += 4;
}
}
/* Encodes a 2-byte ending into 3 bytes and 1 pad byte and writes. */
if (end - ptr == 2)
{
if (end - ptr == 2) {
kwsysBase64_Encode2(ptr, optr);
optr += 4;
}
}
/* Encodes a 1-byte ending into 2 bytes and 2 pad bytes */
else if (end - ptr == 1)
{
else if (end - ptr == 1) {
kwsysBase64_Encode1(ptr, optr);
optr += 4;
}
}
/* Do we need to mark the end */
else if (mark_end)
{
else if (mark_end) {
optr[0] = optr[1] = optr[2] = optr[3] = '=';
optr += 4;
}
}
return (unsigned long)(optr - output);
return (size_t)(optr - output);
}
/*--------------------------------------------------------------------------*/
/* Decode 4 bytes into a 3 byte string. */
int kwsysBase64_Decode3(const unsigned char *src, unsigned char *dest)
int kwsysBase64_Decode3(unsigned char const* src, unsigned char* dest)
{
unsigned char d0, d1, d2, d3;
unsigned char d0;
unsigned char d1;
unsigned char d2;
unsigned char d3;
d0 = kwsysBase64DecodeChar(src[0]);
d1 = kwsysBase64DecodeChar(src[1]);
d2 = kwsysBase64DecodeChar(src[2]);
d3 = kwsysBase64DecodeChar(src[3]);
/* Make sure all characters were valid */
if (d0 == 0xFF || d1 == 0xFF || d2 == 0xFF || d3 == 0xFF)
{
return 0;
}
if (d0 == 0xFF || d1 == 0xFF || d2 == 0xFF || d3 == 0xFF) {
return 0;
}
/* Decode the 3 bytes */
dest[0] = (unsigned char)(((d0 << 2) & 0xFC) | ((d1 >> 4) & 0x03));
dest[1] = (unsigned char)(((d1 << 4) & 0xF0) | ((d2 >> 2) & 0x0F));
dest[2] = (unsigned char)(((d2 << 6) & 0xC0) | ((d3 >> 0) & 0x3F));
/* Return the number of bytes actually decoded */
if (src[2] == '=')
{
return 1;
}
if (src[3] == '=')
{
return 2;
}
if (src[2] == '=') {
return 1;
}
if (src[3] == '=') {
return 2;
}
return 3;
}
/*--------------------------------------------------------------------------*/
/* Decode bytes from the input buffer and store the decoded stream
/* Decode bytes from the input buffer and store the decoded stream
into the output buffer until 'length' bytes have been decoded. Return the
real length of the decoded stream (which should be equal to 'length'). Note
that the output buffer must be allocated by the caller. If
......@@ -209,73 +172,57 @@ int kwsysBase64_Decode3(const unsigned char *src, unsigned char *dest)
'length' parameter is ignored. This enables the caller to decode a stream
without actually knowing how much decoded data to expect (of course, the
buffer must be large enough). */
unsigned long kwsysBase64_Decode(const unsigned char *input,
unsigned long length,
unsigned char *output,
unsigned long max_input_length)
size_t kwsysBase64_Decode(unsigned char const* input, size_t length,
unsigned char* output, size_t max_input_length)
{
const unsigned char *ptr = input;
unsigned char *optr = output;
unsigned char const* ptr = input;
unsigned char* optr = output;
/* Decode complete triplet */
if (max_input_length)
{
const unsigned char *end = input + max_input_length;
while (ptr < end)
{
if (max_input_length) {
unsigned char const* end = input + max_input_length;
while (ptr < end) {
int len = kwsysBase64_Decode3(ptr, optr);
optr += len;
if(len < 3)
{
return (unsigned long)(optr - output);
}
ptr += 4;
if (len < 3) {
return (size_t)(optr - output);
}
}
else
{
unsigned char *oend = output + length;
while ((oend - optr) >= 3)
{
ptr += 4;
}
} else {
unsigned char* oend = output + length;
while ((oend - optr) >= 3) {
int len = kwsysBase64_Decode3(ptr, optr);
optr += len;
if(len < 3)
{
return (unsigned long)(optr - output);
}
ptr += 4;
if (len < 3) {
return (size_t)(optr - output);
}
ptr += 4;
}
/* Decode the last triplet */
if (oend - optr == 2)
{
if (oend - optr == 2) {
unsigned char temp[3];
int len = kwsysBase64_Decode3(ptr, temp);
if(len >= 2)
{
if (len >= 2) {
optr[0] = temp[0];
optr[1] = temp[1];
optr += 2;
}
else if(len > 0)
{
} else if (len > 0) {
optr[0] = temp[0];
optr += 1;
}
}
else if (oend - optr == 1)
{
} else if (oend - optr == 1) {
unsigned char temp[3];
int len = kwsysBase64_Decode3(ptr, temp);
if(len > 0)
{
if (len > 0) {
optr[0] = temp[0];
optr += 1;
}
}
}
}
return (unsigned long)(optr - output);
return (size_t)(optr - output);
}
/*=========================================================================
Program: KWSys - Kitware System Library
Module: Base64.h.in
Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
#ifndef @KWSYS_NAMESPACE@_Base64_h
#define @KWSYS_NAMESPACE@_Base64_h
#include <@KWSYS_NAMESPACE@/Configure.h>
#include <stddef.h> /* size_t */
/* Redefine all public interface symbol names to be in the proper
namespace. These macros are used internally to kwsys only, and are
not visible to user code. Use kwsysHeaderDump.pl to reproduce
these macros after making changes to the interface. */
#if !defined(KWSYS_NAMESPACE)
# define kwsys_ns(x) @KWSYS_NAMESPACE@##x
# define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT
# define kwsys_ns(x) @KWSYS_NAMESPACE@##x
# define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT
#endif
#if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# define kwsysBase64 kwsys_ns(Base64)
# define kwsysBase64_Decode kwsys_ns(Base64_Decode)
# define kwsysBase64_Decode3 kwsys_ns(Base64_Decode3)
# define kwsysBase64_Encode kwsys_ns(Base64_Encode)
# define kwsysBase64_Encode1 kwsys_ns(Base64_Encode1)
# define kwsysBase64_Encode2 kwsys_ns(Base64_Encode2)
# define kwsysBase64_Encode3 kwsys_ns(Base64_Encode3)
#endif
#define kwsysBase64 kwsys_ns(Base64)
#define kwsysBase64_Decode kwsys_ns(Base64_Decode)
#define kwsysBase64_Decode3 kwsys_ns(Base64_Decode3)
#define kwsysBase64_Encode kwsys_ns(Base64_Encode)
#define kwsysBase64_Encode1 kwsys_ns(Base64_Encode1)
#define kwsysBase64_Encode2 kwsys_ns(Base64_Encode2)
#define kwsysBase64_Encode3 kwsys_ns(Base64_Encode3)
#if defined(__cplusplus)
extern "C"
{
extern "C" {
#endif
/**
* Encode 3 bytes into a 4 byte string.
*/
kwsysEXPORT void kwsysBase64_Encode3(const unsigned char *src,
unsigned char *dest);
kwsysEXPORT void kwsysBase64_Encode3(unsigned char const* src,
unsigned char* dest);
/**
* Encode 2 bytes into a 4 byte string.
*/
kwsysEXPORT void kwsysBase64_Encode2(const unsigned char *src,
unsigned char *dest);
kwsysEXPORT void kwsysBase64_Encode2(unsigned char const* src,
unsigned char* dest);
/**
* Encode 1 bytes into a 4 byte string.
*/
kwsysEXPORT void kwsysBase64_Encode1(const unsigned char *src,
unsigned char *dest);
kwsysEXPORT void kwsysBase64_Encode1(unsigned char const* src,
unsigned char* dest);
/**
* Encode 'length' bytes from the input buffer and store the encoded
......@@ -68,17 +60,16 @@ kwsysEXPORT void kwsysBase64_Encode1(const unsigned char *src,
* the extra padding needed to complete the encode 4 bytes will stop
* the decoding anyway).
*/
kwsysEXPORT unsigned long kwsysBase64_Encode(const unsigned char *input,
unsigned long length,
unsigned char *output,
int mark_end);
kwsysEXPORT size_t kwsysBase64_Encode(unsigned char const* input,
size_t length, unsigned char* output,
int mark_end);
/**
* Decode 4 bytes into a 3 byte string. Returns the number of bytes
* actually decoded.
*/
kwsysEXPORT int kwsysBase64_Decode3(const unsigned char *src,
unsigned char *dest);
kwsysEXPORT int kwsysBase64_Decode3(unsigned char const* src,
unsigned char* dest);
/**
* Decode bytes from the input buffer and store the decoded stream
......@@ -92,10 +83,9 @@ kwsysEXPORT int kwsysBase64_Decode3(const unsigned char *src,
* much decoded data to expect (of course, the buffer must be large
* enough).
*/
kwsysEXPORT unsigned long kwsysBase64_Decode(const unsigned char *input,
unsigned long length,
unsigned char *output,
unsigned long max_input_length);
kwsysEXPORT size_t kwsysBase64_Decode(unsigned char const* input,
size_t length, unsigned char* output,
size_t max_input_length);
#if defined(__cplusplus)
} /* extern "C" */
......@@ -104,15 +94,17 @@ kwsysEXPORT unsigned long kwsysBase64_Decode(const unsigned char *input,
/* If we are building a kwsys .c or .cxx file, let it use these macros.
Otherwise, undefine them to keep the namespace clean. */
#if !defined(KWSYS_NAMESPACE)
# undef kwsys_ns
# undef kwsysEXPORT
# undef kwsysBase64
# undef kwsysBase64_Decode
# undef kwsysBase64_Decode3
# undef kwsysBase64_Encode
# undef kwsysBase64_Encode1
# undef kwsysBase64_Encode2
# undef kwsysBase64_Encode3
# undef kwsys_ns
# undef kwsysEXPORT
# if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# undef kwsysBase64
# undef kwsysBase64_Decode
# undef kwsysBase64_Decode3
# undef kwsysBase64_Encode
# undef kwsysBase64_Encode1
# undef kwsysBase64_Encode2
# undef kwsysBase64_Encode3
# endif
#endif
#endif
@CMAKE_EMPTY_INPUT_FILE_CONTENT@
This diff is collapsed.
Contributing to KWSys
*********************
Patches
=======
KWSys is kept in its own Git repository and shared by several projects
via copies in their source trees. Changes to KWSys should not be made
directly in a host project, except perhaps in maintenance branches.
KWSys uses `Kitware's GitLab Instance`_ to manage development and code review.
To contribute patches:
#. Fork the upstream `KWSys Repository`_ into a personal account.
#. Base all new work on the upstream ``master`` branch.
#. Run ``./SetupForDevelopment.sh`` in new local work trees.
#. Create commits making incremental, distinct, logically complete changes.
#. Push a topic branch to a personal repository fork on GitLab.
#. Create a GitLab Merge Request targeting the upstream ``master`` branch.
Once changes are reviewed, tested, and integrated to KWSys upstream then
copies of KWSys within dependent projects can be updated to get the changes.
.. _`Kitware's GitLab Instance`: https://gitlab.kitware.com
.. _`KWSys Repository`: https://gitlab.kitware.com/utils/kwsys
Code Style
==========
We use `clang-format`_ version **18** to define our style for C++ code in
the KWSys source tree. See the `.clang-format`_ configuration file for
our style settings. Use the `clang-format.bash`_ script to format source
code. It automatically runs ``clang-format`` on the set of source files
for which we enforce style. The script also has options to format only
a subset of files, such as those that are locally modified.
.. _`clang-format`: https://clang.llvm.org/docs/ClangFormat.html
.. _`.clang-format`: .clang-format
.. _`clang-format.bash`: clang-format.bash
License
=======
We do not require any formal copyright assignment or contributor license
agreement. Any contributions intentionally sent upstream are presumed
to be offered under terms of the OSI-approved BSD 3-clause License.
See `Copyright.txt`_ for details.
.. _`Copyright.txt`: Copyright.txt
SET (CTEST_PROJECT_NAME "kwsys")
SET (CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
SET (CTEST_DART_SERVER_VERSION "2")
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing#kwsys for details.
set(CTEST_PROJECT_NAME "KWSys")
set(CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
set(CTEST_DROP_METHOD "https")
set(CTEST_DROP_SITE "open.cdash.org")
set(CTEST_DROP_LOCATION "/submit.php?project=KWSys")
set(CTEST_DROP_SITE_CDASH TRUE)
# kwsys.testProcess-10 involves sending SIGINT to a child process, which then
# exits abnormally via a call to _exit(). (On Windows, a call to ExitProcess).
# Naturally, this results in plenty of memory being "leaked" by this child
# process - the memory check results are not meaningful in this case.
#
# kwsys.testProcess-9 also tests sending SIGINT to a child process. However,
# normal operation of that test involves the child process timing out, and the
# host process kills (SIGKILL) it as a result. Since it was SIGKILL'ed, the
# resulting memory leaks are not logged by valgrind anyway. Therefore, we
# don't have to exclude it.
list(APPEND CTEST_CUSTOM_MEMCHECK_IGNORE
kwsys.testProcess-10
)
list(APPEND CTEST_CUSTOM_WARNING_EXCEPTION
"LICENSE WARNING"
)
# - Check if the source code provided in the SOURCE argument compiles.
# CHECK_CXX_SOURCE_COMPILES(SOURCE VAR)
# - macro which checks if the source code compiles\
# SOURCE - source code to try to compile
# VAR - variable to store size if the type exists.
#
# The following variables may be set before calling this macro to
# modify the way the check is run:
#
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
# CMAKE_REQUIRED_INCLUDES = list of include directories
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
MACRO(CHECK_CXX_SOURCE_RUNS SOURCE VAR COMMENT)
IF("HAVE_${VAR}" MATCHES "^HAVE_${VAR}$")
SET(MACRO_CHECK_FUNCTION_DEFINITIONS
"-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
IF(CMAKE_REQUIRED_LIBRARIES)
SET(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES
"-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
ELSE(CMAKE_REQUIRED_LIBRARIES)
SET(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES)
ENDIF(CMAKE_REQUIRED_LIBRARIES)
IF(CMAKE_REQUIRED_INCLUDES)
SET(CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES
"-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
ELSE(CMAKE_REQUIRED_INCLUDES)
SET(CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES)
ENDIF(CMAKE_REQUIRED_INCLUDES)
SET(CMAKE_EMPTY_INPUT_FILE_CONTENT "${SOURCE}")
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/CMakeEmptyInputFile.in"
"${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/src.cxx" IMMEDIATE)
MESSAGE(STATUS "Performing Test ${COMMENT}")
TRY_RUN(${VAR} HAVE_${VAR}
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/src.cxx
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
"${CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES}"
"${CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES}"
OUTPUT_VARIABLE OUTPUT)
IF(HAVE_${VAR})
SET(${VAR} 1 CACHE INTERNAL "Test ${COMMENT}")
MESSAGE(STATUS "Performing Test ${COMMENT} - Success")
FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeOutput.log
"Performing C++ SOURCE FILE Test ${COMMENT} succeded with the following output:\n"
"${OUTPUT}\n"
"Source file was:\n${SOURCE}\n")
ELSE(HAVE_${VAR})
MESSAGE(STATUS "Performing Test ${COMMENT} - Failed")
SET(${VAR} "" CACHE INTERNAL "Test ${COMMENT}")
FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeError.log
"Performing C++ SOURCE FILE Test ${COMMENT} failed with the following output:\n"
"${OUTPUT}\n"
"Source file was:\n${SOURCE}\n")
ENDIF(HAVE_${VAR})
ENDIF("HAVE_${VAR}" MATCHES "^HAVE_${VAR}$")
ENDMACRO(CHECK_CXX_SOURCE_RUNS)
This diff is collapsed.
/*=========================================================================
Program: KWSys - Kitware System Library
Module: CommandLineArguments.hxx.in
Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
#ifndef @KWSYS_NAMESPACE@_CommandLineArguments_hxx
#define @KWSYS_NAMESPACE@_CommandLineArguments_hxx
#include <@KWSYS_NAMESPACE@/Configure.h>
#include <@KWSYS_NAMESPACE@/Configure.hxx>
#include <@KWSYS_NAMESPACE@/stl/string>
#include <@KWSYS_NAMESPACE@/stl/vector>
#include <string>
#include <vector>
/* Define this macro temporarily to keep the code readable. */
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# define kwsys_stl @KWSYS_NAMESPACE@_stl
#endif
namespace @KWSYS_NAMESPACE@
{
namespace @KWSYS_NAMESPACE@ {
class CommandLineArgumentsInternal;
struct CommandLineArgumentsCallbackStructure;
......@@ -46,30 +29,31 @@ struct CommandLineArgumentsCallbackStructure;
*
* For the variable interface you associate variable with each argument. When
* the argument is specified, the variable is set to the specified value casted
* to the apropriate type. For boolean (NO_ARGUMENT), the value is "1".
* to the appropriate type. For boolean (NO_ARGUMENT), the value is "1".
*
* Both interfaces can be used at the same time.
* Both interfaces can be used at the same time.
*
* Possible argument types are:
* NO_ARGUMENT - The argument takes no value : --A
* CONCAT_ARGUMENT - The argument takes value after no space : --Aval
* SPACE_ARGUMENT - The argument takes value after space : --A val
* SPACE_ARGUMENT - The argument takes value after space : --A val
* EQUAL_ARGUMENT - The argument takes value after equal : --A=val
* MULTI_ARGUMENT - The argument takes values after space : --A val1 val2 val3 ...
* MULTI_ARGUMENT - The argument takes values after space : --A val1 val2
* val3 ...
*
* Example use:
*
* kwsys::CommandLineArguments arg;
* arg.Initialize(argc, argv);
* typedef kwsys::CommandLineArguments argT;
* arg.AddArgument("--something", argT::EQUAL_ARGUMENT, &some_variable,
* arg.AddArgument("--something", argT::EQUAL_ARGUMENT, &some_variable,
* "This is help string for --something");
* if ( !arg.Parse() )
* {
* kwsys_ios::cerr << "Problem parsing arguments" << kwsys_ios::endl;
* std::cerr << "Problem parsing arguments" << std::endl;
* res = 1;
* }
*
*
*/
class @KWSYS_NAMESPACE@_EXPORT CommandLineArguments
......@@ -78,10 +62,14 @@ public:
CommandLineArguments();
~CommandLineArguments();
CommandLineArguments(CommandLineArguments const&) = delete;
CommandLineArguments& operator=(CommandLineArguments const&) = delete;
/**
* Various argument types.
*/
enum ArgumentTypeEnum {
enum ArgumentTypeEnum
{
NO_ARGUMENT,
CONCAT_ARGUMENT,
SPACE_ARGUMENT,
......@@ -93,32 +81,33 @@ public:
* Various variable types. When using the variable interface, this specifies
* what type the variable is.
*/
enum VariableTypeEnum {
NO_VARIABLE_TYPE = 0, // The variable is not specified
INT_TYPE, // The variable is integer (int)
BOOL_TYPE, // The vairable is boolean (bool)
DOUBLE_TYPE, // The variable is float (double)
STRING_TYPE, // The variable is string (char*)
STL_STRING_TYPE, // The variable is string (char*)
VECTOR_INT_TYPE, // The variable is integer (int)
VECTOR_BOOL_TYPE, // The vairable is boolean (bool)
VECTOR_DOUBLE_TYPE, // The variable is float (double)
VECTOR_STRING_TYPE, // The variable is string (char*)
VECTOR_STL_STRING_TYPE, // The variable is string (char*)
enum VariableTypeEnum
{
NO_VARIABLE_TYPE = 0, // The variable is not specified
INT_TYPE, // The variable is integer (int)
BOOL_TYPE, // The variable is boolean (bool)
DOUBLE_TYPE, // The variable is float (double)
STRING_TYPE, // The variable is string (char*)
STL_STRING_TYPE, // The variable is string (char*)
VECTOR_INT_TYPE, // The variable is integer (int)
VECTOR_BOOL_TYPE, // The variable is boolean (bool)
VECTOR_DOUBLE_TYPE, // The variable is float (double)
VECTOR_STRING_TYPE, // The variable is string (char*)
VECTOR_STL_STRING_TYPE, // The variable is string (char*)
LAST_VARIABLE_TYPE
};
/**
* Prototypes for callbacks for callback interface.
*/
typedef int(*CallbackType)(const char* argument, const char* value,
void* call_data);
typedef int(*ErrorCallbackType)(const char* argument, void* client_data);
typedef int (*CallbackType)(char const* argument, char const* value,
void* call_data);
typedef int (*ErrorCallbackType)(char const* argument, void* client_data);
/**
* Initialize internal data structures. This should be called before parsing.
*/
void Initialize(int argc, const char* const argv[]);
void Initialize(int argc, char const* const argv[]);
void Initialize(int argc, char* argv[]);
/**
......@@ -127,10 +116,10 @@ public:
* are not available.
*/
void Initialize();
void ProcessArgument(const char* arg);
void ProcessArgument(char const* arg);
/**
* This method will parse arguments and call apropriate methods.
* This method will parse arguments and call appropriate methods.
*/
int Parse();
......@@ -140,56 +129,56 @@ public:
* argument help specifies the help string used with this option. The
* callback and call_data can be skipped.
*/
void AddCallback(const char* argument, ArgumentTypeEnum type,
CallbackType callback, void* call_data, const char* help);
void AddCallback(char const* argument, ArgumentTypeEnum type,
CallbackType callback, void* call_data, char const* help);
/**
* Add handler for argument which is going to set the variable to the
* specified value. If the argument is specified, the option is casted to the
* apropriate type.
* appropriate type.
*/
void AddArgument(const char* argument, ArgumentTypeEnum type,
bool* variable, const char* help);
void AddArgument(const char* argument, ArgumentTypeEnum type,
int* variable, const char* help);
void AddArgument(const char* argument, ArgumentTypeEnum type,
double* variable, const char* help);
void AddArgument(const char* argument, ArgumentTypeEnum type,
char** variable, const char* help);
void AddArgument(const char* argument, ArgumentTypeEnum type,
kwsys_stl::string* variable, const char* help);
void AddArgument(char const* argument, ArgumentTypeEnum type, bool* variable,
char const* help);
void AddArgument(char const* argument, ArgumentTypeEnum type, int* variable,
char const* help);
void AddArgument(char const* argument, ArgumentTypeEnum type,
double* variable, char const* help);
void AddArgument(char const* argument, ArgumentTypeEnum type,
char** variable, char const* help);
void AddArgument(char const* argument, ArgumentTypeEnum type,
std::string* variable, char const* help);
/**
* Add handler for argument which is going to set the variable to the
* specified value. If the argument is specified, the option is casted to the
* apropriate type. This will handle the multi argument values.
* appropriate type. This will handle the multi argument values.
*/
void AddArgument(const char* argument, ArgumentTypeEnum type,
kwsys_stl::vector<bool>* variable, const char* help);
void AddArgument(const char* argument, ArgumentTypeEnum type,
kwsys_stl::vector<int>* variable, const char* help);
void AddArgument(const char* argument, ArgumentTypeEnum type,
kwsys_stl::vector<double>* variable, const char* help);
void AddArgument(const char* argument, ArgumentTypeEnum type,
kwsys_stl::vector<char*>* variable, const char* help);
void AddArgument(const char* argument, ArgumentTypeEnum type,
kwsys_stl::vector<kwsys_stl::string>* variable, const char* help);
void AddArgument(char const* argument, ArgumentTypeEnum type,
std::vector<bool>* variable, char const* help);
void AddArgument(char const* argument, ArgumentTypeEnum type,
std::vector<int>* variable, char const* help);
void AddArgument(char const* argument, ArgumentTypeEnum type,
std::vector<double>* variable, char const* help);
void AddArgument(char const* argument, ArgumentTypeEnum type,
std::vector<char*>* variable, char const* help);
void AddArgument(char const* argument, ArgumentTypeEnum type,
std::vector<std::string>* variable, char const* help);
/**
* Add handler for boolean argument. The argument does not take any option
* and if it is specified, the value of the variable is true/1, otherwise it
* is false/0.
*/
void AddBooleanArgument(const char* argument,
bool* variable, const char* help);
void AddBooleanArgument(const char* argument,
int* variable, const char* help);
void AddBooleanArgument(const char* argument,
double* variable, const char* help);
void AddBooleanArgument(const char* argument,
char** variable, const char* help);
void AddBooleanArgument(const char* argument,
kwsys_stl::string* variable, const char* help);
void AddBooleanArgument(char const* argument, bool* variable,
char const* help);
void AddBooleanArgument(char const* argument, int* variable,
char const* help);
void AddBooleanArgument(char const* argument, double* variable,
char const* help);
void AddBooleanArgument(char const* argument, char** variable,
char const* help);
void AddBooleanArgument(char const* argument, std::string* variable,
char const* help);
/**
* Set the callbacks for error handling.
......@@ -216,8 +205,8 @@ public:
* Return string containing help. If the argument is specified, only return
* help for that argument.
*/
const char* GetHelp() { return this->Help.c_str(); }
const char* GetHelp(const char* arg);
char const* GetHelp() { return this->Help.c_str(); }
char const* GetHelp(char const* arg);
/**
* Get / Set the help line length. This length is used when generating the
......@@ -230,7 +219,7 @@ public:
* Get the executable name (argv0). This is only available when using
* Initialize with argc/argv.
*/
const char* GetArgv0();
char const* GetArgv0();
/**
* Get index of the last argument parsed. This is the last argument that was
......@@ -242,31 +231,34 @@ protected:
void GenerateHelp();
//! This is internal method that registers variable with argument
void AddArgument(const char* argument, ArgumentTypeEnum type,
VariableTypeEnum vtype, void* variable, const char* help);
void AddArgument(char const* argument, ArgumentTypeEnum type,
VariableTypeEnum vtype, void* variable, char const* help);
bool GetMatchedArguments(kwsys_stl::vector<kwsys_stl::string>* matches,
const kwsys_stl::string& arg);
bool GetMatchedArguments(std::vector<std::string>* matches,
std::string const& arg);
//! Populate individual variables
bool PopulateVariable(CommandLineArgumentsCallbackStructure* cs,
const char* value);
char const* value);
//! Populate individual variables of type ...
void PopulateVariable(bool* variable, const kwsys_stl::string& value);
void PopulateVariable(int* variable, const kwsys_stl::string& value);
void PopulateVariable(double* variable, const kwsys_stl::string& value);
void PopulateVariable(char** variable, const kwsys_stl::string& value);
void PopulateVariable(kwsys_stl::string* variable, const kwsys_stl::string& value);
void PopulateVariable(kwsys_stl::vector<bool>* variable, const kwsys_stl::string& value);
void PopulateVariable(kwsys_stl::vector<int>* variable, const kwsys_stl::string& value);
void PopulateVariable(kwsys_stl::vector<double>* variable, const kwsys_stl::string& value);
void PopulateVariable(kwsys_stl::vector<char*>* variable, const kwsys_stl::string& value);
void PopulateVariable(kwsys_stl::vector<kwsys_stl::string>* variable, const kwsys_stl::string& value);
void PopulateVariable(bool* variable, std::string const& value);
void PopulateVariable(int* variable, std::string const& value);
void PopulateVariable(double* variable, std::string const& value);
void PopulateVariable(char** variable, std::string const& value);
void PopulateVariable(std::string* variable, std::string const& value);
void PopulateVariable(std::vector<bool>* variable, std::string const& value);
void PopulateVariable(std::vector<int>* variable, std::string const& value);
void PopulateVariable(std::vector<double>* variable,
std::string const& value);
void PopulateVariable(std::vector<char*>* variable,
std::string const& value);
void PopulateVariable(std::vector<std::string>* variable,
std::string const& value);
typedef CommandLineArgumentsInternal Internal;
Internal* Internals;
kwsys_stl::string Help;
std::string Help;
unsigned int LineLength;
......@@ -275,14 +267,4 @@ protected:
} // namespace @KWSYS_NAMESPACE@
/* Undefine temporary macro. */
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# undef kwsys_stl
#endif
#endif
/*=========================================================================
Program: KWSys - Kitware System Library
Module: Configure.h.in
Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
#ifndef @KWSYS_NAMESPACE@_Configure_h
#define @KWSYS_NAMESPACE@_Configure_h
......@@ -18,82 +7,64 @@
namespace. When not building a kwsys source file these macros are
temporarily defined inside the headers that use them. */
#if defined(KWSYS_NAMESPACE)
# define kwsys_ns(x) @KWSYS_NAMESPACE@##x
# define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT
# define kwsys_ns(x) @KWSYS_NAMESPACE@##x
# define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT
#endif
/* Whether Large File Support is requested. */
#define @KWSYS_NAMESPACE@_LFS_REQUESTED @KWSYS_LFS_REQUESTED@
/* Whether Large File Support is available. */
#if @KWSYS_NAMESPACE@_LFS_REQUESTED
# define @KWSYS_NAMESPACE@_LFS_AVAILABLE @KWSYS_LFS_AVAILABLE@
#endif
/* Setup Large File Support if requested. */
#if @KWSYS_NAMESPACE@_LFS_REQUESTED
/* Since LFS is requested this header must be included before system
headers whether or not LFS is available. */
# if 0 && (defined(_SYS_TYPES_H) || defined(_SYS_TYPES_INCLUDED))
# error "@KWSYS_NAMESPACE@/Configure.h must be included before sys/types.h"
# endif
/* Enable the large file API if it is available. */
# if @KWSYS_NAMESPACE@_LFS_AVAILABLE && \
!defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINES)
# if !defined(_LARGEFILE_SOURCE) && \
!defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_LARGEFILE_SOURCE)
# define _LARGEFILE_SOURCE
# endif
# if !defined(_LARGEFILE64_SOURCE) && \
!defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_LARGEFILE64_SOURCE)
# define _LARGEFILE64_SOURCE
# endif
# if !defined(_LARGE_FILES) && \
!defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_LARGE_FILES)
# define _LARGE_FILES
# endif
# if !defined(_FILE_OFFSET_BITS) && \
!defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_FILE_OFFSET_BITS)
# define _FILE_OFFSET_BITS 64
/* Disable some warnings inside kwsys source files. */
#if defined(KWSYS_NAMESPACE)
# if defined(__INTEL_COMPILER)
# pragma warning(disable : 1572) /* floating-point equality test */
# endif
# if 0 && (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS < 64)
# error "_FILE_OFFSET_BITS must be defined to at least 64"
# if defined(__sgi) && !defined(__GNUC__)
# pragma set woff 3970 /* pointer to int conversion */
# pragma set woff 3968 /* 64 bit conversion */
# endif
# endif
#endif
/* Whether kwsys namespace is "kwsys". */
#define @KWSYS_NAMESPACE@_NAME_IS_KWSYS @KWSYS_NAME_IS_KWSYS@
/* Setup the export macro. */
#if defined(_WIN32) && @KWSYS_BUILD_SHARED@
# if defined(@KWSYS_NAMESPACE@_EXPORTS)
# define @KWSYS_NAMESPACE@_EXPORT __declspec(dllexport)
# else
# define @KWSYS_NAMESPACE@_EXPORT __declspec(dllimport)
# endif
#if @KWSYS_BUILD_SHARED@
# if defined(_WIN32) || defined(__CYGWIN__)
# if defined(@KWSYS_NAMESPACE@_EXPORTS)
# define @KWSYS_NAMESPACE@_EXPORT __declspec(dllexport)
# else
# define @KWSYS_NAMESPACE@_EXPORT __declspec(dllimport)
# endif
# elif __GNUC__ >= 4
# define @KWSYS_NAMESPACE@_EXPORT __attribute__((visibility("default")))
# else
# define @KWSYS_NAMESPACE@_EXPORT
# endif
#else
# define @KWSYS_NAMESPACE@_EXPORT
# define @KWSYS_NAMESPACE@_EXPORT
#endif
/* Enable warnings that are off by default but are useful. */
#if !defined(@KWSYS_NAMESPACE@_NO_WARNING_ENABLE)
# if defined(_MSC_VER)
# pragma warning ( default : 4263 ) /* no override, call convention differs */
# endif
# if defined(_MSC_VER)
# pragma warning(default : 4263) /* no override, call convention differs \
*/
# endif
#endif
/* Disable warnings that are on by default but occur in valid code. */
#if !defined(@KWSYS_NAMESPACE@_NO_WARNING_DISABLE)
# if defined(_MSC_VER)
# pragma warning (disable: 4097) /* typedef is synonym for class */
# pragma warning (disable: 4127) /* conditional expression is constant */
# pragma warning (disable: 4244) /* possible loss in conversion */
# pragma warning (disable: 4251) /* missing DLL-interface */
# pragma warning (disable: 4305) /* truncation from type1 to type2 */
# pragma warning (disable: 4309) /* truncation of constant value */
# pragma warning (disable: 4514) /* unreferenced inline function */
# pragma warning (disable: 4706) /* assignment in conditional expression */
# pragma warning (disable: 4710) /* function not inlined */
# pragma warning (disable: 4786) /* identifier truncated in debug info */
# endif
# if defined(_MSC_VER)
# pragma warning(disable : 4097) /* typedef is synonym for class */
# pragma warning(disable : 4127) /* conditional expression is constant */
# pragma warning(disable : 4244) /* possible loss in conversion */
# pragma warning(disable : 4251) /* missing DLL-interface */
# pragma warning(disable : 4305) /* truncation from type1 to type2 */
# pragma warning(disable : 4309) /* truncation of constant value */
# pragma warning(disable : 4514) /* unreferenced inline function */
# pragma warning(disable : 4706) /* assignment in conditional expression \
*/
# pragma warning(disable : 4710) /* function not inlined */
# pragma warning(disable : 4786) /* identifier truncated in debug info */
# endif
#endif
/* MSVC 6.0 in release mode will warn about code it produces with its
......@@ -101,10 +72,10 @@
configuration. Real warnings will be revealed by a debug build or
by other compilers. */
#if !defined(@KWSYS_NAMESPACE@_NO_WARNING_DISABLE_BOGUS)
# if defined(_MSC_VER) && (_MSC_VER < 1300) && defined(NDEBUG)
# pragma warning ( disable : 4701 ) /* Variable may be used uninitialized. */
# pragma warning ( disable : 4702 ) /* Unreachable code. */
# endif
# if defined(_MSC_VER) && (_MSC_VER < 1300) && defined(NDEBUG)
# pragma warning(disable : 4701) /* Variable may be used uninitialized. */
# pragma warning(disable : 4702) /* Unreachable code. */
# endif
#endif
#endif
/*=========================================================================
Program: KWSys - Kitware System Library
Module: Configure.hxx.in
Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
#ifndef @KWSYS_NAMESPACE@_Configure_hxx
#define @KWSYS_NAMESPACE@_Configure_hxx
/* Include C configuration. */
#include <@KWSYS_NAMESPACE@/Configure.h>
/* Whether kwsys namespace is "kwsys". */
#define @KWSYS_NAMESPACE@_NAME_IS_KWSYS @KWSYS_NAME_IS_KWSYS@
/* Whether ANSI C++ stream headers are to be used. */
#define @KWSYS_NAMESPACE@_IOS_USE_ANSI @KWSYS_IOS_USE_ANSI@
/* Whether ANSI C++ streams are in std namespace. */
#define @KWSYS_NAMESPACE@_IOS_HAVE_STD @KWSYS_IOS_HAVE_STD@
/* Whether ANSI C++ <sstream> header is to be used. */
#define @KWSYS_NAMESPACE@_IOS_USE_SSTREAM @KWSYS_IOS_USE_SSTREAM@
/* Whether old C++ <strstream.h> header is to be used. */
#define @KWSYS_NAMESPACE@_IOS_USE_STRSTREAM_H @KWSYS_IOS_USE_STRSTREAM_H@
/* Whether old C++ <strstrea.h> header is to be used. */
#define @KWSYS_NAMESPACE@_IOS_USE_STRSTREA_H @KWSYS_IOS_USE_STRSTREA_H@
/* Whether wstring is available. */
#define @KWSYS_NAMESPACE@_STL_HAS_WSTRING @KWSYS_STL_HAS_WSTRING@
/* Whether <ext/stdio_filebuf.h> is available. */
#define @KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H \
@KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H@
/* Whether STL is in std namespace. */
#define @KWSYS_NAMESPACE@_STL_HAVE_STD @KWSYS_STL_HAVE_STD@
/* Whether the STL string has operator<< for ostream. */
#define @KWSYS_NAMESPACE@_STL_STRING_HAVE_OSTREAM @KWSYS_STL_STRING_HAVE_OSTREAM@
/* Whether the STL string has operator>> for istream. */
#define @KWSYS_NAMESPACE@_STL_STRING_HAVE_ISTREAM @KWSYS_STL_STRING_HAVE_ISTREAM@
/* Whether the STL string has operator!= for char*. */
#define @KWSYS_NAMESPACE@_STL_STRING_HAVE_NEQ_CHAR @KWSYS_STL_STRING_HAVE_NEQ_CHAR@
/* Define the stl namespace macro. */
#if @KWSYS_NAMESPACE@_STL_HAVE_STD
# define @KWSYS_NAMESPACE@_stl std
#else
# define @KWSYS_NAMESPACE@_stl
#endif
/* Define the ios namespace macro. */
#if @KWSYS_NAMESPACE@_IOS_HAVE_STD
# define @KWSYS_NAMESPACE@_ios_namespace std
#else
# define @KWSYS_NAMESPACE@_ios_namespace
#endif
#if @KWSYS_NAMESPACE@_IOS_USE_SSTREAM
# define @KWSYS_NAMESPACE@_ios @KWSYS_NAMESPACE@_ios_namespace
#if defined(__SUNPRO_CC) && __SUNPRO_CC > 0x5130 && defined(__has_attribute)
# define @KWSYS_NAMESPACE@_has_cpp_attribute(x) __has_attribute(x)
#elif defined(__has_cpp_attribute)
# define @KWSYS_NAMESPACE@_has_cpp_attribute(x) __has_cpp_attribute(x)
#else
# define @KWSYS_NAMESPACE@_ios @KWSYS_NAMESPACE@_ios
# define @KWSYS_NAMESPACE@_has_cpp_attribute(x) 0
#endif
/* Whether the cstddef header is available. */
#define @KWSYS_NAMESPACE@_CXX_HAS_CSTDDEF @KWSYS_CXX_HAS_CSTDDEF@
/* Whether the compiler supports null template arguments. */
#define @KWSYS_NAMESPACE@_CXX_HAS_NULL_TEMPLATE_ARGS @KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS@
/* Define the null template arguments macro. */
#if @KWSYS_NAMESPACE@_CXX_HAS_NULL_TEMPLATE_ARGS
# define @KWSYS_NAMESPACE@_CXX_NULL_TEMPLATE_ARGS <>
#if __cplusplus >= 201103L
# define @KWSYS_NAMESPACE@_NULLPTR nullptr
#else
# define @KWSYS_NAMESPACE@_CXX_NULL_TEMPLATE_ARGS
# define @KWSYS_NAMESPACE@_NULLPTR 0
#endif
/* Whether the compiler supports member templates. */
#define @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES @KWSYS_CXX_HAS_MEMBER_TEMPLATES@
/* Whether the compiler supports argument dependent lookup. */
#define @KWSYS_NAMESPACE@_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP @KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP@
/* Whether the compiler supports standard full specialization syntax. */
#define @KWSYS_NAMESPACE@_CXX_HAS_FULL_SPECIALIZATION @KWSYS_CXX_HAS_FULL_SPECIALIZATION@
/* Define the specialization definition macro. */
#if @KWSYS_NAMESPACE@_CXX_HAS_FULL_SPECIALIZATION
# define @KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION template <>
#else
# define @KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
#ifndef @KWSYS_NAMESPACE@_FALLTHROUGH
# if __cplusplus >= 201703L && \
@KWSYS_NAMESPACE@_has_cpp_attribute(fallthrough)
# define @KWSYS_NAMESPACE@_FALLTHROUGH [[fallthrough]]
# elif __cplusplus >= 201103L && \
@KWSYS_NAMESPACE@_has_cpp_attribute(gnu::fallthrough)
# define @KWSYS_NAMESPACE@_FALLTHROUGH [[gnu::fallthrough]]
# elif __cplusplus >= 201103L && \
@KWSYS_NAMESPACE@_has_cpp_attribute(clang::fallthrough)
# define @KWSYS_NAMESPACE@_FALLTHROUGH [[clang::fallthrough]]
# endif
#endif
/* Define typename keyword macro for use in declarations. */
#if defined(_MSC_VER) && _MSC_VER < 1300
# define @KWSYS_NAMESPACE@_CXX_DECL_TYPENAME
#else
# define @KWSYS_NAMESPACE@_CXX_DECL_TYPENAME typename
#ifndef @KWSYS_NAMESPACE@_FALLTHROUGH
# define @KWSYS_NAMESPACE@_FALLTHROUGH static_cast<void>(0)
#endif
/* Whether the stl has iterator_traits. */
#define @KWSYS_NAMESPACE@_STL_HAS_ITERATOR_TRAITS @KWSYS_STL_HAS_ITERATOR_TRAITS@
/* Whether the stl has iterator_category. */
#define @KWSYS_NAMESPACE@_STL_HAS_ITERATOR_CATEGORY @KWSYS_STL_HAS_ITERATOR_CATEGORY@
/* Whether the stl has __iterator_category. */
#define @KWSYS_NAMESPACE@_STL_HAS___ITERATOR_CATEGORY @KWSYS_STL_HAS___ITERATOR_CATEGORY@
/* Whether the stl allocator is the standard template. */
#define @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_TEMPLATE @KWSYS_STL_HAS_ALLOCATOR_TEMPLATE@
/* Whether the stl allocator is not a template. */
#define @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_NONTEMPLATE @KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE@
/* Whether the stl allocator has rebind. */
#define @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_REBIND @KWSYS_STL_HAS_ALLOCATOR_REBIND@
/* Whether the stl allocator has a size argument for max_size. */
#define @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT @KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT@
/* Whether the stl containers support allocator objects. */
#define @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_OBJECTS @KWSYS_STL_HAS_ALLOCATOR_OBJECTS@
/* Whether struct stat has the st_mtim member for high resolution times. */
#define @KWSYS_NAMESPACE@_STAT_HAS_ST_MTIM @KWSYS_STAT_HAS_ST_MTIM@
#undef @KWSYS_NAMESPACE@_has_cpp_attribute
/* If building a C++ file in kwsys itself, give the source file
access to the macros without a configured namespace. */
#if defined(KWSYS_NAMESPACE)
# if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# define kwsys_stl @KWSYS_NAMESPACE@_stl
# define kwsys_ios @KWSYS_NAMESPACE@_ios
# define kwsys @KWSYS_NAMESPACE@
# endif
# define KWSYS_NAME_IS_KWSYS @KWSYS_NAMESPACE@_NAME_IS_KWSYS
# define KWSYS_STL_HAVE_STD @KWSYS_NAMESPACE@_STL_HAVE_STD
# define KWSYS_IOS_HAVE_STD @KWSYS_NAMESPACE@_IOS_HAVE_STD
# define KWSYS_IOS_USE_ANSI @KWSYS_NAMESPACE@_IOS_USE_ANSI
# define KWSYS_IOS_USE_SSTREAM @KWSYS_NAMESPACE@_IOS_USE_SSTREAM
# define KWSYS_IOS_USE_STRSTREAM_H @KWSYS_NAMESPACE@_IOS_USE_STRSTREAM_H
# define KWSYS_IOS_USE_STRSTREA_H @KWSYS_NAMESPACE@_IOS_USE_STRSTREA_H
# define KWSYS_STAT_HAS_ST_MTIM @KWSYS_NAMESPACE@_STAT_HAS_ST_MTIM
# define KWSYS_CXX_HAS_CSTDDEF @KWSYS_NAMESPACE@_CXX_HAS_CSTDDEF
# define KWSYS_STL_STRING_HAVE_OSTREAM @KWSYS_NAMESPACE@_STL_STRING_HAVE_OSTREAM
# define KWSYS_STL_STRING_HAVE_ISTREAM @KWSYS_NAMESPACE@_STL_STRING_HAVE_ISTREAM
# define KWSYS_STL_STRING_HAVE_NEQ_CHAR @KWSYS_NAMESPACE@_STL_STRING_HAVE_NEQ_CHAR
# define KWSYS_CXX_NULL_TEMPLATE_ARGS @KWSYS_NAMESPACE@_CXX_NULL_TEMPLATE_ARGS
# define KWSYS_CXX_HAS_MEMBER_TEMPLATES @KWSYS_NAMESPACE@_CXX_HAS_MEMBER_TEMPLATES
# define KWSYS_CXX_HAS_FULL_SPECIALIZATION @KWSYS_NAMESPACE@_CXX_HAS_FULL_SPECIALIZATION
# define KWSYS_CXX_DEFINE_SPECIALIZATION @KWSYS_NAMESPACE@_CXX_DEFINE_SPECIALIZATION
# define KWSYS_CXX_DECL_TYPENAME @KWSYS_NAMESPACE@_CXX_DECL_TYPENAME
# define KWSYS_STL_HAS_ALLOCATOR_REBIND @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_REBIND
# define KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT
# define KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP @KWSYS_NAMESPACE@_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP
# define KWSYS_STL_HAS_ITERATOR_TRAITS @KWSYS_NAMESPACE@_STL_HAS_ITERATOR_TRAITS
# define KWSYS_STL_HAS_ITERATOR_CATEGORY @KWSYS_NAMESPACE@_STL_HAS_ITERATOR_CATEGORY
# define KWSYS_STL_HAS___ITERATOR_CATEGORY @KWSYS_NAMESPACE@_STL_HAS___ITERATOR_CATEGORY
# define KWSYS_STL_HAS_ALLOCATOR_TEMPLATE @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_TEMPLATE
# define KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_NONTEMPLATE
# define KWSYS_STL_HAS_ALLOCATOR_OBJECTS @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_OBJECTS
# if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# define kwsys @KWSYS_NAMESPACE@
# endif
# define KWSYS_NAME_IS_KWSYS @KWSYS_NAMESPACE@_NAME_IS_KWSYS
# define KWSYS_STL_HAS_WSTRING @KWSYS_NAMESPACE@_STL_HAS_WSTRING
# define KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H \
@KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H
# define KWSYS_FALLTHROUGH @KWSYS_NAMESPACE@_FALLTHROUGH
#endif
#endif
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
#ifndef @KWSYS_NAMESPACE@_ConsoleBuf_hxx
#define @KWSYS_NAMESPACE@_ConsoleBuf_hxx
#include <@KWSYS_NAMESPACE@/Configure.hxx>
#include <@KWSYS_NAMESPACE@/Encoding.hxx>
#include <cstring>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#if defined(_WIN32)
# include <windows.h>
# if __cplusplus >= 201103L
# include <system_error>
# endif
#endif
namespace @KWSYS_NAMESPACE@ {
#if defined(_WIN32)
template <class CharT, class Traits = std::char_traits<CharT> >
class BasicConsoleBuf : public std::basic_streambuf<CharT, Traits>
{
public:
typedef typename Traits::int_type int_type;
typedef typename Traits::char_type char_type;
class Manager
{
public:
Manager(std::basic_ios<CharT, Traits>& ios, bool const err = false)
: m_consolebuf(0)
{
m_ios = &ios;
try {
m_consolebuf = new BasicConsoleBuf<CharT, Traits>(err);
m_streambuf = m_ios->rdbuf(m_consolebuf);
} catch (std::runtime_error const& ex) {
std::cerr << "Failed to create ConsoleBuf!" << std::endl
<< ex.what() << std::endl;
};
}
BasicConsoleBuf<CharT, Traits>* GetConsoleBuf() { return m_consolebuf; }
void SetUTF8Pipes()
{
if (m_consolebuf) {
m_consolebuf->input_pipe_codepage = CP_UTF8;
m_consolebuf->output_pipe_codepage = CP_UTF8;
m_consolebuf->activateCodepageChange();
}
}
~Manager()
{
if (m_consolebuf) {
delete m_consolebuf;
m_ios->rdbuf(m_streambuf);
}
}
private:
std::basic_ios<CharT, Traits>* m_ios;
std::basic_streambuf<CharT, Traits>* m_streambuf;
BasicConsoleBuf<CharT, Traits>* m_consolebuf;
};
BasicConsoleBuf(bool const err = false)
: flush_on_newline(true)
, input_pipe_codepage(0)
, output_pipe_codepage(0)
, input_file_codepage(CP_UTF8)
, output_file_codepage(CP_UTF8)
, m_consolesCodepage(0)
{
m_hInput = ::GetStdHandle(STD_INPUT_HANDLE);
checkHandle(true, "STD_INPUT_HANDLE");
if (!setActiveInputCodepage()) {
throw std::runtime_error("setActiveInputCodepage failed!");
}
m_hOutput = err ? ::GetStdHandle(STD_ERROR_HANDLE)
: ::GetStdHandle(STD_OUTPUT_HANDLE);
checkHandle(false, err ? "STD_ERROR_HANDLE" : "STD_OUTPUT_HANDLE");
if (!setActiveOutputCodepage()) {
throw std::runtime_error("setActiveOutputCodepage failed!");
}
_setg();
_setp();
}
~BasicConsoleBuf() throw() { sync(); }
bool activateCodepageChange()
{
return setActiveInputCodepage() && setActiveOutputCodepage();
}
protected:
virtual int sync()
{
bool success = true;
if (m_hInput && m_isConsoleInput &&
::FlushConsoleInputBuffer(m_hInput) == 0) {
success = false;
}
if (m_hOutput && !m_obuffer.empty()) {
std::wstring const wbuffer = getBuffer(m_obuffer);
if (m_isConsoleOutput) {
DWORD charsWritten;
success =
::WriteConsoleW(m_hOutput, wbuffer.c_str(), (DWORD)wbuffer.size(),
&charsWritten, nullptr) == 0
? false
: true;
} else {
DWORD bytesWritten;
std::string buffer;
success = encodeOutputBuffer(wbuffer, buffer);
if (success) {
success =
::WriteFile(m_hOutput, buffer.c_str(), (DWORD)buffer.size(),
&bytesWritten, nullptr) == 0
? false
: true;
}
}
}
m_ibuffer.clear();
m_obuffer.clear();
_setg();
_setp();
return success ? 0 : -1;
}
virtual int_type underflow()
{
if (this->gptr() >= this->egptr()) {
if (!m_hInput) {
_setg(true);
return Traits::eof();
}
if (m_isConsoleInput) {
// ReadConsole doesn't tell if there's more input available
// don't support reading more characters than this
wchar_t wbuffer[8192];
DWORD charsRead;
if (ReadConsoleW(m_hInput, wbuffer,
(sizeof(wbuffer) / sizeof(wbuffer[0])), &charsRead,
nullptr) == 0 ||
charsRead == 0) {
_setg(true);
return Traits::eof();
}
setBuffer(std::wstring(wbuffer, charsRead), m_ibuffer);
} else {
std::wstring wbuffer;
std::string strbuffer;
DWORD bytesRead;
LARGE_INTEGER size;
if (GetFileSizeEx(m_hInput, &size) == 0) {
_setg(true);
return Traits::eof();
}
char* buffer = new char[size.LowPart];
while (ReadFile(m_hInput, buffer, size.LowPart, &bytesRead, nullptr) ==
0) {
if (GetLastError() == ERROR_MORE_DATA) {
strbuffer += std::string(buffer, bytesRead);
continue;
}
_setg(true);
delete[] buffer;
return Traits::eof();
}
if (bytesRead > 0) {
strbuffer += std::string(buffer, bytesRead);
}
delete[] buffer;
if (!decodeInputBuffer(strbuffer, wbuffer)) {
_setg(true);
return Traits::eof();
}
setBuffer(wbuffer, m_ibuffer);
}
_setg();
}
return Traits::to_int_type(*this->gptr());
}
virtual int_type overflow(int_type ch = Traits::eof())
{
if (!Traits::eq_int_type(ch, Traits::eof())) {
char_type chr = Traits::to_char_type(ch);
m_obuffer += chr;
if ((flush_on_newline && Traits::eq(chr, '\n')) ||
Traits::eq_int_type(ch, 0x00)) {
sync();
}
return ch;
}
sync();
return Traits::eof();
}
public:
bool flush_on_newline;
UINT input_pipe_codepage;
UINT output_pipe_codepage;
UINT input_file_codepage;
UINT output_file_codepage;
private:
HANDLE m_hInput;
HANDLE m_hOutput;
std::basic_string<char_type> m_ibuffer;
std::basic_string<char_type> m_obuffer;
bool m_isConsoleInput;
bool m_isConsoleOutput;
UINT m_activeInputCodepage;
UINT m_activeOutputCodepage;
UINT m_consolesCodepage;
void checkHandle(bool input, std::string handleName)
{
if ((input && m_hInput == INVALID_HANDLE_VALUE) ||
(!input && m_hOutput == INVALID_HANDLE_VALUE)) {
std::string errmsg =
"GetStdHandle(" + handleName + ") returned INVALID_HANDLE_VALUE";
# if __cplusplus >= 201103L
throw std::system_error(::GetLastError(), std::system_category(),
errmsg);
# else
throw std::runtime_error(errmsg);
# endif
}
}
UINT getConsolesCodepage()
{
if (!m_consolesCodepage) {
m_consolesCodepage = GetConsoleCP();
if (!m_consolesCodepage) {
m_consolesCodepage = GetACP();
}
}
return m_consolesCodepage;
}
bool setActiveInputCodepage()
{
m_isConsoleInput = false;
switch (GetFileType(m_hInput)) {
case FILE_TYPE_DISK:
m_activeInputCodepage = input_file_codepage;
break;
case FILE_TYPE_CHAR:
// Check for actual console.
DWORD consoleMode;
m_isConsoleInput =
GetConsoleMode(m_hInput, &consoleMode) == 0 ? false : true;
if (m_isConsoleInput) {
break;
}
@KWSYS_NAMESPACE@_FALLTHROUGH;
case FILE_TYPE_PIPE:
m_activeInputCodepage = input_pipe_codepage;
break;
default:
return false;
}
if (!m_isConsoleInput && m_activeInputCodepage == 0) {
m_activeInputCodepage = getConsolesCodepage();
}
return true;
}
bool setActiveOutputCodepage()
{
m_isConsoleOutput = false;
switch (GetFileType(m_hOutput)) {
case FILE_TYPE_DISK:
m_activeOutputCodepage = output_file_codepage;
break;
case FILE_TYPE_CHAR:
// Check for actual console.
DWORD consoleMode;
m_isConsoleOutput =
GetConsoleMode(m_hOutput, &consoleMode) == 0 ? false : true;
if (m_isConsoleOutput) {
break;
}
@KWSYS_NAMESPACE@_FALLTHROUGH;
case FILE_TYPE_PIPE:
m_activeOutputCodepage = output_pipe_codepage;
break;
default:
return false;
}
if (!m_isConsoleOutput && m_activeOutputCodepage == 0) {
m_activeOutputCodepage = getConsolesCodepage();
}
return true;
}
void _setg(bool empty = false)
{
if (!empty) {
this->setg((char_type*)m_ibuffer.data(), (char_type*)m_ibuffer.data(),
(char_type*)m_ibuffer.data() + m_ibuffer.size());
} else {
this->setg((char_type*)m_ibuffer.data(),
(char_type*)m_ibuffer.data() + m_ibuffer.size(),
(char_type*)m_ibuffer.data() + m_ibuffer.size());
}
}
void _setp()
{
this->setp((char_type*)m_obuffer.data(),
(char_type*)m_obuffer.data() + m_obuffer.size());
}
bool encodeOutputBuffer(std::wstring const wbuffer, std::string& buffer)
{
if (wbuffer.size() == 0) {
buffer = std::string();
return true;
}
int const length =
WideCharToMultiByte(m_activeOutputCodepage, 0, wbuffer.c_str(),
(int)wbuffer.size(), nullptr, 0, nullptr, nullptr);
char* buf = new char[length];
bool const success =
WideCharToMultiByte(m_activeOutputCodepage, 0, wbuffer.c_str(),
(int)wbuffer.size(), buf, length, nullptr,
nullptr) > 0
? true
: false;
buffer = std::string(buf, length);
delete[] buf;
return success;
}
bool decodeInputBuffer(std::string const buffer, std::wstring& wbuffer)
{
size_t length = buffer.length();
if (length == 0) {
wbuffer = std::wstring();
return true;
}
int actualCodepage = m_activeInputCodepage;
char const BOM_UTF8[] = { char(0xEF), char(0xBB), char(0xBF) };
char const* data = buffer.data();
size_t const BOMsize = sizeof(BOM_UTF8);
if (length >= BOMsize && std::memcmp(data, BOM_UTF8, BOMsize) == 0) {
// PowerShell uses UTF-8 with BOM for pipes
actualCodepage = CP_UTF8;
data += BOMsize;
length -= BOMsize;
}
size_t const wlength = static_cast<size_t>(MultiByteToWideChar(
actualCodepage, 0, data, static_cast<int>(length), nullptr, 0));
wchar_t* wbuf = new wchar_t[wlength];
bool const success =
MultiByteToWideChar(actualCodepage, 0, data, static_cast<int>(length),
wbuf, static_cast<int>(wlength)) > 0
? true
: false;
wbuffer = std::wstring(wbuf, wlength);
delete[] wbuf;
return success;
}
std::wstring getBuffer(std::basic_string<char> const buffer)
{
return Encoding::ToWide(buffer);
}
std::wstring getBuffer(std::basic_string<wchar_t> const buffer)
{
return buffer;
}
void setBuffer(std::wstring const wbuffer, std::basic_string<char>& target)
{
target = Encoding::ToNarrow(wbuffer);
}
void setBuffer(std::wstring const wbuffer,
std::basic_string<wchar_t>& target)
{
target = wbuffer;
}
}; // BasicConsoleBuf class
typedef BasicConsoleBuf<char> ConsoleBuf;
typedef BasicConsoleBuf<wchar_t> WConsoleBuf;
#endif
} // KWSYS_NAMESPACE
#endif
Copyright (c) 2000-2003 Kitware, Inc., Insight Consortium.
KWSys - Kitware System Library
Copyright 2000-2016 Kitware, Inc. and Contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the
distribution.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Kitware nor the names of any contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.
* Modified source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
* Neither the name of Kitware, Inc. nor the names of Contributors
may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------
The following individuals and institutions are among the Contributors:
* Insight Software Consortium <insightsoftwareconsortium.org>
See version control history for details of individual contributions.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.