Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WCCL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Analysers
WCCL
Commits
1fde16fb
Commit
1fde16fb
authored
Dec 16, 2010
by
Adam Wardynski
Browse files
Options
Downloads
Patches
Plain Diff
Unicode support reading from Win Console in wcclparser tool.
parent
075930df
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
wcclparser/main.cpp
+78
-28
78 additions, 28 deletions
wcclparser/main.cpp
with
78 additions
and
28 deletions
wcclparser/main.cpp
+
78
−
28
View file @
1fde16fb
...
...
@@ -19,42 +19,26 @@
#include
<histedit.h>
#endif
#ifdef _WINDOWS
#define WIN32_LEAN_AND_MEAN
#include
<windows.h>
#endif
/**
* @desc A simple command line tester for testing operators
*/
namespace
{
const
char
*
_prompt
=
"Enter any operator expression: "
;
}
void
std_read_loop
(
boost
::
function
<
bool
(
const
std
::
string
&
)
>&
line_cb
)
{
while
(
std
::
cin
.
good
())
{
std
::
cout
<<
_prompt
<<
std
::
flush
;
std
::
string
s
;
getline
(
std
::
cin
,
s
);
if
(
line_cb
(
s
))
{
return
;
}
}
}
int
clear_screen
()
{
#ifdef _WINDOWS
return
std
::
system
(
"cls"
);
#else
return
std
::
system
(
"clear"
);
#endif
}
#if defined(HAVE_LIBEDIT) && !defined(_WINDOWS) //non-Windows libedit read loop
#ifdef HAVE_LIBEDIT
const
char
*
query_prompt
(
EditLine
*
)
{
return
_prompt
;
}
void
libedit_
read_loop
(
boost
::
function
<
bool
(
const
std
::
string
&
)
>&
line_cb
)
void
read_loop
(
boost
::
function
<
bool
(
const
std
::
string
&
)
>&
line_cb
)
{
EditLine
*
el
=
el_init
(
"wccl-parser"
,
stdin
,
stdout
,
stderr
);
el_set
(
el
,
EL_PROMPT
,
&
query_prompt
);
...
...
@@ -89,8 +73,78 @@ void libedit_read_loop(boost::function<bool (const std::string&)>& line_cb)
history_end
(
myhistory
);
el_end
(
el
);
}
#elif defined(_WINDOWS) // windows console read loop, doing UNICODE
struct
ConsoleCPSetter
{
UINT
original_CP
;
ConsoleCPSetter
(
UINT
cp
)
{
original_CP
=
GetConsoleCP
();
SetConsoleCP
(
cp
);
}
~
ConsoleCPSetter
()
{
SetConsoleCP
(
original_CP
);
}
};
void
read_loop
(
boost
::
function
<
bool
(
const
std
::
string
&
)
>&
line_cb
)
{
HANDLE
stdinhandle
=
GetStdHandle
(
STD_INPUT_HANDLE
);
WCHAR
buffer
[
1024
];
const
int
max
=
sizeof
(
buffer
)
/
sizeof
(
WCHAR
)
-
1
;
ConsoleCPSetter
cp
(
CP_UTF8
);
bool
more
=
true
;
while
(
more
)
{
std
::
cout
<<
_prompt
<<
std
::
flush
;
std
::
wstring
s
;
while
(
more
)
{
DWORD
read
;
if
(
ReadConsoleW
(
stdinhandle
,
buffer
,
max
,
&
read
,
NULL
))
{
buffer
[
read
]
=
NULL
;
while
(
buffer
[
read
-
1
]
==
L'\n'
||
buffer
[
read
-
1
]
==
L'\r'
)
{
buffer
[
--
read
]
=
0
;
}
more
=
(
read
==
max
);
s
+=
buffer
;
}
else
{
if
(
GetLastError
()
==
ERROR_INVALID_HANDLE
)
{
// assume stdin redirect, fallback to standard getline
getline
(
std
::
wcin
,
s
);
}
more
=
false
;
}
}
UnicodeString
us
(
s
.
c_str
());
more
=
!
line_cb
(
PwrNlp
::
to_utf8
(
us
));
}
}
#else // standard io read loop
void
read_loop
(
boost
::
function
<
bool
(
const
std
::
string
&
)
>&
line_cb
)
{
while
(
std
::
cin
.
good
())
{
std
::
cout
<<
_prompt
<<
std
::
flush
;
std
::
string
s
;
getline
(
std
::
cin
,
s
);
if
(
line_cb
(
s
))
{
return
;
}
}
}
#endif
int
clear_screen
()
{
#ifdef _WINDOWS
return
std
::
system
(
"cls"
);
#else
return
std
::
system
(
"clear"
);
#endif
}
bool
process_line
(
const
std
::
string
&
line
,
Wccl
::
Parser
&
parser
,
Wccl
::
SentenceContext
&
sc
,
bool
all_positions
,
bool
dump_variables
)
{
...
...
@@ -247,11 +301,7 @@ int main(int argc, char** argv)
boost
::
function
<
bool
(
const
std
::
string
&
)
>
f
;
f
=
boost
::
bind
(
&
process_line
,
_1
,
boost
::
ref
(
parser
),
boost
::
ref
(
sc
),
position
==
"all"
,
dump_variables
);
#ifdef HAVE_LIBEDIT
libedit_read_loop
(
f
);
#else
std_read_loop
(
f
);
#endif
read_loop
(
f
);
}
catch
(
PwrNlp
::
PwrNlpError
&
e
)
{
std
::
cerr
<<
e
.
info
()
<<
std
::
endl
;
return
2
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment