Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-2-2
Commits
4c835cb9
Commit
4c835cb9
authored
Oct 25, 2013
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
help: wrap Unicode text correctly (fixes #5417)
parent
02633e29
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
43 deletions
+74
-43
src/config/help.c
src/config/help.c
+74
-43
No files found.
src/config/help.c
View file @
4c835cb9
...
...
@@ -25,6 +25,8 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <wchar.h>
#include <wctype.h>
#include <vlc_common.h>
#include <vlc_charset.h>
...
...
@@ -37,6 +39,7 @@
#if defined( _WIN32 ) && !VLC_WINSTORE_APP
static
void
ShowConsole
(
void
);
static
void
PauseConsole
(
void
);
# define wcwidth(cp) (cp, 1)
/* LOL */
#else
# define ShowConsole() (void)0
# define PauseConsole() (void)0
...
...
@@ -249,60 +252,88 @@ static void print_section(const module_t *m, const module_config_t **sect,
module_gettext
(
m
,
item
->
psz_longtext
));
}
static
void
print_desc
(
/*const XXX*/
char
*
text
,
unsigned
margin
,
bool
color
)
static
void
print_desc
(
const
char
*
str
,
unsigned
margin
,
bool
color
)
{
unsigned
width
=
ConsoleWidth
()
-
margin
;
size_t
i_cur_width
=
width
;
if
(
text
[
0
]
==
'\0'
)
strcpy
(
text
,
" "
);
if
(
color
)
fputs
(
BLUE
,
stdout
);
while
(
*
text
)
{
char
*
psz_parser
,
*
psz_word
;
size_t
i_end
=
strlen
(
text
)
;
const
char
*
word
=
str
;
int
wordlen
=
0
,
wordwidth
=
0
;
unsigned
offset
=
0
;
bool
newline
=
true
;
/* If the remaining text fits in a line, print it. */
if
(
i_end
<=
i_cur_width
)
{
printf
(
color
?
BLUE
"%s
\n
"
GRAY
:
"%s
\n
"
,
text
);
while
(
str
[
0
])
{
uint32_t
cp
;
size_t
charlen
=
vlc_towc
(
str
,
&
cp
);
if
(
unlikely
(
charlen
==
(
size_t
)
-
1
))
break
;
}
/* Otherwise, eat as many words as possible */
psz_parser
=
text
;
do
{
psz_word
=
psz_parser
;
psz_parser
=
strchr
(
psz_word
,
' '
);
/* If no space was found, we reached the end of the text
* block; otherwise, we skip the space we just found. */
psz_parser
=
psz_parser
?
psz_parser
+
1
:
text
+
i_end
;
int
charwidth
=
wcwidth
(
cp
);
if
(
charwidth
<
0
)
charwidth
=
0
;
}
while
(
(
size_t
)(
psz_parser
-
text
)
<=
i_cur_width
);
/* We cut a word in one of these cases:
* - it's the only word in the line and it's too long.
* - we used less than 80% of the width and the word we are
* going to wrap is longer than 40% of the width, and even
* if the word would have fit in the next line. */
if
(
psz_word
==
text
||
(
(
size_t
)(
psz_word
-
text
)
<
80
*
i_cur_width
/
100
&&
(
size_t
)(
psz_parser
-
psz_word
)
>
40
*
i_cur_width
/
100
)
)
str
+=
charlen
;
if
(
iswspace
(
cp
))
{
char
c
=
text
[
i_cur_width
];
text
[
i_cur_width
]
=
'\0'
;
printf
(
color
?
BLUE
"%s
\n
%*s"
GRAY
:
"%s
\n
%*s"
,
text
,
margin
,
""
);
text
+=
i_cur_width
;
text
[
0
]
=
c
;
if
(
!
newline
)
{
fputc
(
' '
,
stdout
);
/* insert space */
charwidth
=
1
;
}
fwrite
(
word
,
1
,
wordlen
,
stdout
);
/* write complete word */
word
=
str
;
wordlen
=
0
;
wordwidth
=
0
;
newline
=
false
;
}
else
{
psz_word
[
-
1
]
=
'\0'
;
printf
(
color
?
BLUE
"%s
\n
%*s"
GRAY
:
"%s
\n
%*s"
,
text
,
margin
,
""
);
text
=
psz_word
;
wordlen
+=
charlen
;
wordwidth
+=
charwidth
;
}
offset
+=
charwidth
;
if
(
offset
>=
width
)
{
if
(
newline
)
{
/* overflow (word wider than line) */
fwrite
(
word
,
1
,
wordlen
-
charlen
,
stdout
);
word
=
str
-
charlen
;
wordlen
=
charlen
;
wordwidth
=
charwidth
;
}
printf
(
"
\n
%*s"
,
margin
,
""
);
/* new line */
offset
=
wordwidth
;
newline
=
true
;
}
}
if
(
!
newline
)
fputc
(
' '
,
stdout
);
printf
(
color
?
"%s
\n
"
GRAY
:
"%s
\n
"
,
word
);
}
static
int
vlc_swidth
(
const
char
*
str
)
{
for
(
int
total
=
0
;;)
{
uint32_t
cp
;
size_t
charlen
=
vlc_towc
(
str
,
&
cp
);
if
(
charlen
==
0
)
return
total
;
if
(
charlen
==
(
size_t
)
-
1
)
return
-
1
;
str
+=
charlen
;
int
w
=
wcwidth
(
cp
);
if
(
w
==
-
1
)
return
-
1
;
total
+=
w
;
}
}
...
...
@@ -423,9 +454,9 @@ static void print_item(const module_t *m, const module_config_t *item,
/* Wrap description */
int
offset
=
PADDING_SPACES
-
strlen
(
item
->
psz_name
)
-
strlen
(
bra
)
-
strlen
(
type
)
-
strlen
(
ket
)
-
1
;
-
strlen
(
bra
)
-
vlc_swidth
(
type
)
-
strlen
(
ket
)
-
1
;
if
(
CONFIG_CLASS
(
item
->
i_type
)
==
CONFIG_ITEM_BOOL
)
offset
-=
strlen
(
item
->
psz_name
)
+
strlen
(
prefix
);
offset
-=
strlen
(
item
->
psz_name
)
+
vlc_swidth
(
prefix
);
if
(
offset
<
0
)
{
fputc
(
'\n'
,
stdout
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment