3 * args.c - Client/Server Runtime - command line parsing
5 * ReactOS Operating System
7 * --------------------------------------------------------------------
9 * This software is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
14 * This software is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this software; see the file COPYING.LIB. If not, write
21 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
24 * --------------------------------------------------------------------
31 /**********************************************************************
33 * CsrParseCommandLine/2
35 NTSTATUS FASTCALL
CsrParseCommandLine (PPEB Peb
,
36 PCOMMAND_LINE_ARGUMENT Argument
)
38 HANDLE ProcessHeap
= Peb
->ProcessHeap
;
39 PRTL_USER_PROCESS_PARAMETERS RtlProcessParameters
= RtlNormalizeProcessParams (Peb
->ProcessParameters
);
41 INT afterlastspace
= 0;
44 DPRINT("CSR: %s called\n", __FUNCTION__
);
46 RtlZeroMemory (Argument
, sizeof (COMMAND_LINE_ARGUMENT
));
48 Argument
->Vector
= (PWSTR
*) RtlAllocateHeap (ProcessHeap
,
50 (CSRP_MAX_ARGUMENT_COUNT
* sizeof Argument
->Vector
[0]));
51 if(NULL
== Argument
->Vector
)
53 DPRINT("CSR: %s: no memory for Argument->Vector\n", __FUNCTION__
);
54 return STATUS_NO_MEMORY
;
57 Argument
->Buffer
.Length
=
58 Argument
->Buffer
.MaximumLength
=
59 RtlProcessParameters
->CommandLine
.Length
60 + sizeof Argument
->Buffer
.Buffer
[0]; /* zero terminated */
61 Argument
->Buffer
.Buffer
=
62 (PWSTR
) RtlAllocateHeap (ProcessHeap
,
64 Argument
->Buffer
.MaximumLength
);
65 if(NULL
== Argument
->Buffer
.Buffer
)
67 DPRINT("CSR: %s: no memory for Argument->Buffer.Buffer\n", __FUNCTION__
);
68 return STATUS_NO_MEMORY
;
71 RtlCopyMemory (Argument
->Buffer
.Buffer
,
72 RtlProcessParameters
->CommandLine
.Buffer
,
73 RtlProcessParameters
->CommandLine
.Length
);
75 while (Argument
->Buffer
.Buffer
[i
])
77 if (Argument
->Buffer
.Buffer
[i
] == L
' ')
80 Argument
->Buffer
.Buffer
[i
] = L
'\0';
81 Argument
->Vector
[Argument
->Count
- 1] = & (Argument
->Buffer
.Buffer
[afterlastspace
]);
83 while (Argument
->Buffer
.Buffer
[i
] == L
' ')
95 if (Argument
->Buffer
.Buffer
[afterlastspace
] != L
'\0')
98 Argument
->Buffer
.Buffer
[i
] = L
'\0';
99 Argument
->Vector
[Argument
->Count
- 1] = & (Argument
->Buffer
.Buffer
[afterlastspace
]);
102 for (i
=0; i
<Argument
->Count
; i
++)
104 DPRINT("CSR: Argument[%d] = '%S'\n", i
, Argument
->Vector
[i
]);
107 return STATUS_SUCCESS
;
109 /**********************************************************************
111 * CsrFreeCommandLine/2
114 VOID FASTCALL
CsrFreeCommandLine (PPEB Peb
,
115 PCOMMAND_LINE_ARGUMENT Argument
)
117 DPRINT("CSR: %s called\n", __FUNCTION__
);
119 RtlFreeHeap (Peb
->ProcessHeap
,
122 RtlFreeHeap (Peb
->ProcessHeap
,
124 Argument
->Buffer
.Buffer
);