mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Core: LocalProcess now has (No)ConvertCharset option, fixes issue with usvn file history
git-svn-id: svn://ultimatepp.org/upp/trunk@3962 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
d94765efda
commit
6023477e37
4 changed files with 42 additions and 13 deletions
|
|
@ -21,6 +21,7 @@ void LocalProcess::Init() {
|
|||
output_read = false;
|
||||
#endif
|
||||
exit_code = Null;
|
||||
convertcharset = true;
|
||||
}
|
||||
|
||||
void LocalProcess::Free() {
|
||||
|
|
@ -339,7 +340,9 @@ bool LocalProcess::Read(String& res) {
|
|||
char buffer[1024];
|
||||
if(!ReadFile(hOutputRead, buffer, sizeof(buffer), &n, NULL))
|
||||
return false;
|
||||
res = FromSystemCharset(String(buffer, n));
|
||||
res = String(buffer, n);
|
||||
if(convertcharset)
|
||||
res = FromSystemCharset(res);
|
||||
return true;
|
||||
#endif
|
||||
#ifdef PLATFORM_POSIX
|
||||
|
|
@ -372,12 +375,16 @@ bool LocalProcess::Read(String& res) {
|
|||
}
|
||||
if(!was_running)
|
||||
output_read = true;
|
||||
if(convertcharset)
|
||||
res = FromSystemCharset(res);
|
||||
return !IsNull(res) || was_running;
|
||||
#endif
|
||||
}
|
||||
|
||||
void LocalProcess::Write(String s)
|
||||
{
|
||||
if(convertcharset)
|
||||
s = ToSystemCharset(s);
|
||||
#ifdef PLATFORM_WIN32
|
||||
dword n;
|
||||
WriteFile(hInputWrite, s, s.GetLength(), &n, NULL);
|
||||
|
|
@ -387,10 +394,11 @@ void LocalProcess::Write(String s)
|
|||
#endif
|
||||
}
|
||||
|
||||
int Sys(const char *cmd, String& out)
|
||||
int Sys(const char *cmd, String& out, bool convertcharset)
|
||||
{
|
||||
out.Clear();
|
||||
LocalProcess p;
|
||||
p.ConvertCharset(convertcharset);
|
||||
if(!p.Start(cmd))
|
||||
return -1;
|
||||
while(p.IsRunning()) {
|
||||
|
|
@ -401,10 +409,10 @@ int Sys(const char *cmd, String& out)
|
|||
return p.GetExitCode();
|
||||
}
|
||||
|
||||
String Sys(const char *cmd)
|
||||
String Sys(const char *cmd, bool convertcharset)
|
||||
{
|
||||
String r;
|
||||
return Sys(cmd, r) ? String::GetVoid() : r;
|
||||
return Sys(cmd, r, convertcharset) ? String::GetVoid() : r;
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ private:
|
|||
HANDLE hProcess;
|
||||
HANDLE hOutputRead;
|
||||
HANDLE hInputWrite;
|
||||
bool convertcharset;
|
||||
#endif
|
||||
#ifdef PLATFORM_POSIX
|
||||
Buffer<char> cmd_buf;
|
||||
|
|
@ -49,11 +50,14 @@ private:
|
|||
|
||||
public:
|
||||
bool Start(const char *cmdline, const char *envptr = NULL);
|
||||
|
||||
LocalProcess& ConvertCharset(bool b = true) { convertcharset = b; return *this; }
|
||||
LocalProcess& NoConvertCharset() { return ConvertCharset(false); }
|
||||
|
||||
LocalProcess() { Init(); }
|
||||
LocalProcess(const char *cmdline, const char *envptr = NULL) { Init(); Start(cmdline, envptr); }
|
||||
virtual ~LocalProcess() { Kill(); }
|
||||
};
|
||||
|
||||
int Sys(const char *cmd, String& output);
|
||||
String Sys(const char *cmd);
|
||||
int Sys(const char *cmd, String& out, bool convertcharset = true);
|
||||
String Sys(const char *cmd, bool convertcharset = true);
|
||||
|
|
|
|||
|
|
@ -76,8 +76,20 @@ onst]_[@(0.0.255) char]_`*[*@3 cmdline], [@(0.0.255) const]_[@(0.0.255) char]_`*
|
|||
]can provide a new environment for the process, if NULL, then
|
||||
the new process inherits caller`'s environment.&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:LocalProcess`:`:ConvertCharset`(bool`): [_^LocalProcess^ LocalProcess][@(0.0.255) `&
|
||||
]_[* ConvertCharset]([@(0.0.255) bool]_[*@3 b]_`=_[@(0.0.255) true])&]
|
||||
[s5;:LocalProcess`:`:NoConvertCharset`(`): [_^LocalProcess^ LocalProcess][@(0.0.255) `&]_
|
||||
[* NoConvertCharset]()&]
|
||||
[s2;%% Determines LocalProcess should convert encoding from system
|
||||
to application one. Default setting is true.&]
|
||||
[s0;%% &]
|
||||
[ {{10000F(128)G(128)@1 [s0;%% [* Constructor Detail]]}}&]
|
||||
[s3; &]
|
||||
[s5;:LocalProcess`:`:ConvertCharset`(bool`): [_^LocalProcess^ LocalProcess][@(0.0.255) `&
|
||||
]_[* ConvertCharset]([@(0.0.255) bool]_[*@3 b]_`=_[@(0.0.255) true])&]
|
||||
[s2;%% [%-*@3 b].&]
|
||||
[s3;%% &]
|
||||
[s4;H0; &]
|
||||
[s5;:LocalProcess`:`:LocalProcess`(`): [* LocalProcess]()&]
|
||||
[s2;%% Default constructor.&]
|
||||
|
|
@ -94,17 +106,22 @@ onst]_[@(0.0.255) char]_`*[*@3 cmdline], [@(0.0.255) const]_[@(0.0.255) char]_`*
|
|||
[s0; &]
|
||||
[ {{10000@(113.42.0) [s0;%% [*@7;4 Global functions related to LocalProcess]]}}&]
|
||||
[s3; &]
|
||||
[s5;:Sys`(const char`*`,String`&`): [@(0.0.255) int]_[* Sys]([@(0.0.255) const]_[@(0.0.255) c
|
||||
har]_`*[*@3 cmd], [_^String^ String][@(0.0.255) `&]_[*@3 output])&]
|
||||
[s5;:Sys`(const char`*`,String`&`,bool`): [@(0.0.255) int]_[* Sys]([@(0.0.255) const]_[@(0.0.255) c
|
||||
har]_`*[*@3 cmd], [_^String^ String][@(0.0.255) `&]_[*@3 out], [@(0.0.255) bool]_[*@3 convert
|
||||
charset]_`=_[@(0.0.255) true])&]
|
||||
[s2;%% Runs process defined by [%-*@3 cmd] command line, returns its
|
||||
standard output in [%-*@3 output].and its exit code as return value.
|
||||
If there was error invoking [%-*@3 cmd], returns `-1&]
|
||||
If there was error invoking [%-*@3 cmd], returns `-1. If [%-*@3 convertcharset]
|
||||
is true, output is converted from system character encoding to
|
||||
application encoding.&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:Sys`(const char`*`): [_^String^ String]_[* Sys]([@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 c
|
||||
md])&]
|
||||
[s5;:Sys`(const char`*`,bool`): [_^String^ String]_[* Sys]([@(0.0.255) const]_[@(0.0.255) cha
|
||||
r]_`*[*@3 cmd], [@(0.0.255) bool]_[*@3 convertcharset]_`=_[@(0.0.255) true])&]
|
||||
[s2;%% Runs process defined by [%-*@3 cmd] command line. If [%-*@3 cmd]
|
||||
was executed successfully and returned zero exit code, returns
|
||||
its standard output, otherwise returns String`::GetVoid().&]
|
||||
its standard output, otherwise returns String`::GetVoid(). If
|
||||
[%-*@3 convertcharset] is true, output is converted from system
|
||||
character encoding to application encoding.&]
|
||||
[s3; &]
|
||||
[s0; ]
|
||||
|
|
@ -61,7 +61,7 @@ void SvnDiff::Execute(const String& f)
|
|||
|
||||
void SvnDiff::Load()
|
||||
{
|
||||
diff.Set(LoadFile(editfile), extfile = Sys("svn cat " + editfile + '@' + AsString(~r)));
|
||||
diff.Set(LoadFile(editfile), extfile = Sys("svn cat " + editfile + '@' + AsString(~r), false));
|
||||
}
|
||||
|
||||
SvnDiff::SvnDiff()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue