Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
56c34e1b
Commit
56c34e1b
authored
Apr 21, 2005
by
Peter Berg Larsen
Committed by
Alexandre Julliard
Apr 21, 2005
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewritten DoEnvironmentSubst16.
parent
08ae0d09
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
53 deletions
+61
-53
shell.c
dlls/shell32/shell.c
+61
-53
No files found.
dlls/shell32/shell.c
View file @
56c34e1b
...
...
@@ -363,74 +363,82 @@ SEGPTR WINAPI FindEnvironmentString16(LPSTR str)
* DoEnvironmentSubst [SHELL.37]
*
* Replace %KEYWORD% in the str with the value of variable KEYWORD
* from "DOS" environment.
* from "DOS" environment. If it is not found the %KEYWORD% is left
* intact. If the buffer is too small, str is not modified.
*
* str [I] '\0' terminated string with %keyword%.
* [O] '\0' terminated string with %keyword% substituted.
* length [I] size of str.
*
* Return
* str length in the LOWORD and 1 in HIWORD if subst was successful.
*/
DWORD
WINAPI
DoEnvironmentSubst16
(
LPSTR
str
,
WORD
length
)
{
LPSTR
lpEnv
=
MapSL
(
GetDOSEnvironment16
());
LPSTR
lpBuffer
=
HeapAlloc
(
GetProcessHeap
(),
0
,
length
);
LPSTR
lpstr
=
str
;
LPSTR
lpbstr
=
lpBuffer
;
LPSTR
lpend
;
LPSTR
lpBuffer
=
HeapAlloc
(
GetProcessHeap
(),
0
,
length
);
WORD
bufCnt
=
0
;
WORD
envKeyLen
;
LPSTR
lpKey
;
WORD
retStatus
=
0
;
WORD
retLength
=
length
;
CharToOemA
(
str
,
str
);
TRACE
(
"accept %s
\n
"
,
str
);
while
(
*
lpstr
&&
lpbstr
-
lpBuffer
<
length
)
{
LPSTR
lpend
=
lpstr
;
if
(
*
lpstr
==
'%'
)
{
do
{
lpend
++
;
}
while
(
*
lpend
&&
*
lpend
!=
'%'
);
if
(
*
lpend
==
'%'
&&
lpend
-
lpstr
>
1
)
/* found key */
{
LPSTR
lpKey
;
*
lpend
=
'\0'
;
lpKey
=
SHELL_FindString
(
lpEnv
,
lpstr
+
1
);
if
(
lpKey
)
/* found key value */
{
int
l
=
strlen
(
lpKey
);
if
(
l
>
length
-
(
lpbstr
-
lpBuffer
)
-
1
)
{
WARN
(
"-- Env subst aborted - string too short
\n
"
);
*
lpend
=
'%'
;
break
;
}
strcpy
(
lpbstr
,
lpKey
);
lpbstr
+=
l
;
}
else
break
;
*
lpend
=
'%'
;
lpstr
=
lpend
+
1
;
}
else
break
;
/* back off and whine */
continue
;
}
*
lpbstr
++
=
*
lpstr
++
;
}
*
lpbstr
=
'\0'
;
if
(
lpstr
-
str
==
strlen
(
str
)
)
{
strncpy
(
str
,
lpBuffer
,
length
);
length
=
1
;
}
else
length
=
0
;
while
(
*
lpstr
&&
bufCnt
<=
length
-
1
)
{
if
(
*
lpstr
!=
'%'
)
{
lpBuffer
[
bufCnt
++
]
=
*
lpstr
++
;
continue
;
}
for
(
lpend
=
lpstr
+
1
;
*
lpend
&&
*
lpend
!=
'%'
;
lpend
++
)
/**/
;
envKeyLen
=
lpend
-
lpstr
-
1
;
if
(
*
lpend
!=
'%'
||
envKeyLen
==
0
)
goto
err
;
/* "%\0" or "%%" found; back off and whine */
*
lpend
=
'\0'
;
lpKey
=
SHELL_FindString
(
lpEnv
,
lpstr
+
1
);
*
lpend
=
'%'
;
if
(
lpKey
)
{
int
l
=
strlen
(
lpKey
);
if
(
bufCnt
+
l
>
length
-
1
)
goto
err
;
memcpy
(
lpBuffer
+
bufCnt
,
lpKey
,
l
);
bufCnt
+=
l
;
}
else
{
/* Keyword not found; Leave the %KEYWORD% intact */
if
(
bufCnt
+
envKeyLen
+
2
>
length
-
1
)
goto
err
;
memcpy
(
lpBuffer
+
bufCnt
,
lpstr
,
envKeyLen
+
2
);
bufCnt
+=
envKeyLen
+
2
;
}
lpstr
=
lpend
+
1
;
}
if
(
!*
lpstr
&&
bufCnt
<=
length
-
1
)
{
memcpy
(
str
,
lpBuffer
,
bufCnt
);
str
[
bufCnt
]
=
'\0'
;
retLength
=
bufCnt
+
1
;
retStatus
=
1
;
}
err:
if
(
!
retStatus
)
WARN
(
"-- Env subst aborted - string too short or invalid input
\n
"
);
TRACE
(
"-- return %s
\n
"
,
str
);
OemToCharA
(
str
,
str
);
HeapFree
(
GetProcessHeap
(),
0
,
lpBuffer
);
/* Return str length in the LOWORD
* and 1 in HIWORD if subst was successful.
*/
return
(
DWORD
)
MAKELONG
(
strlen
(
str
),
length
);
return
(
DWORD
)
MAKELONG
(
retLength
,
retStatus
);
}
/*************************************************************************
...
...
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