Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nx-libs
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dimbor
nx-libs
Commits
aadcac45
Commit
aadcac45
authored
Mar 13, 2017
by
Ulrich Sibiller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Keystroke.c: simplify parse_keystroke_file
parent
f97bb3f1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
36 deletions
+15
-36
Keystroke.c
nx-X11/programs/Xserver/hw/nxagent/Keystroke.c
+15
-36
No files found.
nx-X11/programs/Xserver/hw/nxagent/Keystroke.c
View file @
aadcac45
...
@@ -272,19 +272,17 @@ static void parse_keystroke_file(void)
...
@@ -272,19 +272,17 @@ static void parse_keystroke_file(void)
envvar
=
"NXAGENT_KEYSTROKEFILE"
;
envvar
=
"NXAGENT_KEYSTROKEFILE"
;
}
}
if
(
nxagentKeystrokeFile
!=
NULL
&&
access
(
nxagentKeystrokeFile
,
R_OK
)
==
0
)
if
(
nxagentKeystrokeFile
&&
access
(
nxagentKeystrokeFile
,
R_OK
)
==
0
)
{
{
filename
=
strdup
(
nxagentKeystrokeFile
);
if
(
!
(
filename
=
strdup
(
nxagentKeystrokeFile
)))
if
(
filename
==
NULL
)
{
{
fprintf
(
stderr
,
"malloc failed"
);
fprintf
(
stderr
,
"malloc failed"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
}
}
else
if
((
filename
=
getenv
(
envvar
))
!=
NULL
&&
access
(
filename
,
R_OK
)
==
0
)
else
if
((
filename
=
getenv
(
envvar
))
&&
access
(
filename
,
R_OK
)
==
0
)
{
{
filename
=
strdup
(
filename
);
if
(
!
(
filename
=
strdup
(
filename
)))
if
(
filename
==
NULL
)
{
{
fprintf
(
stderr
,
"malloc failed"
);
fprintf
(
stderr
,
"malloc failed"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -294,26 +292,15 @@ static void parse_keystroke_file(void)
...
@@ -294,26 +292,15 @@ static void parse_keystroke_file(void)
{
{
char
*
homedir
=
getenv
(
"HOME"
);
char
*
homedir
=
getenv
(
"HOME"
);
filename
=
NULL
;
filename
=
NULL
;
if
(
homedir
!=
NULL
)
if
(
homedir
)
{
{
homedir
=
strdup
(
homedir
);
if
(
!
(
filename
=
calloc
(
1
,
strlen
(
homefile
)
+
strlen
(
homedir
)
+
1
)))
if
(
homedir
==
NULL
)
{
fprintf
(
stderr
,
"malloc failed"
);
exit
(
EXIT_FAILURE
);
}
filename
=
calloc
(
1
,
strlen
(
homefile
)
+
strlen
(
homedir
)
+
1
);
if
(
filename
==
NULL
)
{
{
fprintf
(
stderr
,
"malloc failed"
);
fprintf
(
stderr
,
"malloc failed"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
strcpy
(
filename
,
homedir
);
strcpy
(
filename
,
homedir
);
strcpy
(
filename
+
strlen
(
homedir
),
homefile
);
strcpy
(
filename
+
strlen
(
homedir
),
homefile
);
if
(
homedir
)
{
free
(
homedir
);
}
}
}
if
(
access
(
filename
,
R_OK
)
==
0
)
if
(
access
(
filename
,
R_OK
)
==
0
)
...
@@ -322,10 +309,8 @@ static void parse_keystroke_file(void)
...
@@ -322,10 +309,8 @@ static void parse_keystroke_file(void)
}
}
else
if
(
access
(
etcfile
,
R_OK
)
==
0
)
else
if
(
access
(
etcfile
,
R_OK
)
==
0
)
{
{
if
(
filename
)
free
(
filename
);
free
(
filename
);
if
(
!
(
filename
=
strdup
(
etcfile
)))
filename
=
strdup
(
etcfile
);
if
(
filename
==
NULL
)
{
{
fprintf
(
stderr
,
"malloc failed"
);
fprintf
(
stderr
,
"malloc failed"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -333,8 +318,7 @@ static void parse_keystroke_file(void)
...
@@ -333,8 +318,7 @@ static void parse_keystroke_file(void)
}
}
else
else
{
{
if
(
filename
)
free
(
filename
);
free
(
filename
);
filename
=
NULL
;
filename
=
NULL
;
}
}
}
}
...
@@ -342,20 +326,15 @@ static void parse_keystroke_file(void)
...
@@ -342,20 +326,15 @@ static void parse_keystroke_file(void)
/* now we know which file to read, if any */
/* now we know which file to read, if any */
if
(
filename
)
if
(
filename
)
{
{
xmlDoc
*
doc
=
NULL
;
xmlNode
*
root
=
NULL
;
LIBXML_TEST_VERSION
LIBXML_TEST_VERSION
doc
=
xmlReadFile
(
filename
,
NULL
,
0
);
xmlDoc
*
doc
=
xmlReadFile
(
filename
,
NULL
,
0
);
if
(
doc
!=
NULL
)
if
(
doc
)
{
{
xmlNode
*
cur
=
NULL
;
for
(
xmlNode
*
cur
=
xmlDocGetRootElement
(
doc
);
cur
;
cur
=
cur
->
next
)
root
=
xmlDocGetRootElement
(
doc
);
for
(
cur
=
root
;
cur
;
cur
=
cur
->
next
)
{
{
if
(
cur
->
type
==
XML_ELEMENT_NODE
&&
strcmp
((
char
*
)
cur
->
name
,
"keystrokes"
)
==
0
)
if
(
cur
->
type
==
XML_ELEMENT_NODE
&&
strcmp
((
char
*
)
cur
->
name
,
"keystrokes"
)
==
0
)
{
{
xmlNode
*
bindings
=
NULL
;
xmlNode
*
bindings
;
int
num
=
0
;
int
num
=
0
;
int
idx
=
0
;
int
idx
=
0
;
...
@@ -369,8 +348,7 @@ static void parse_keystroke_file(void)
...
@@ -369,8 +348,7 @@ static void parse_keystroke_file(void)
#ifdef DEBUG
#ifdef DEBUG
fprintf
(
stderr
,
"%s: found %d keystrokes in %s
\n
"
,
__func__
,
num
,
filename
);
fprintf
(
stderr
,
"%s: found %d keystrokes in %s
\n
"
,
__func__
,
num
,
filename
);
#endif
#endif
map
=
calloc
(
num
+
1
,
sizeof
(
struct
nxagentSpecialKeystrokeMap
));
if
(
!
(
map
=
calloc
(
num
+
1
,
sizeof
(
struct
nxagentSpecialKeystrokeMap
))))
if
(
map
==
NULL
)
{
{
fprintf
(
stderr
,
"calloc failed"
);
fprintf
(
stderr
,
"calloc failed"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -402,6 +380,7 @@ static void parse_keystroke_file(void)
...
@@ -402,6 +380,7 @@ static void parse_keystroke_file(void)
#endif
#endif
}
}
free
(
filename
);
free
(
filename
);
filename
=
NULL
;
}
}
}
}
...
...
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