OWLNext
7.0
Borland's Object Windows Library for the modern age
Toggle main menu visibility
Loading...
Searching...
No Matches
cmdline.cpp
Go to the documentation of this file.
1
//----------------------------------------------------------------------------
2
// ObjectWindows
3
// Copyright (c) 1994, 1996 by Borland International, All Rights Reserved
4
//
5
///\file
6
/// class TCmdLine implementation
7
//----------------------------------------------------------------------------
8
#include <
owl/pch.h
>
9
#include <
owl/cmdline.h
>
10
#include <
owl/private/memory.h
>
11
12
namespace
owl
{
13
14
const
tchar
whitespace
[] =
_T
(
" \t"
);
15
const
tchar
terminator
[] =
_T
(
"=/ \t\""
);
// remove /- to dissallow separating there
16
17
TCmdLine::TCmdLine
(
const
tstring
& cmdLine)
18
{
19
Buffer =
new
tchar
[cmdLine.length() + 1];
20
::_tcscpy
(Buffer, cmdLine.c_str());
21
Reset
();
22
}
23
24
void
TCmdLine::Reset
()
25
{
26
Token = TokenStart = Buffer;
27
TokenLen = 0;
28
Kind =
Start
;
29
}
30
31
TCmdLine::~TCmdLine
()
32
{
33
delete
[] Buffer;
34
}
35
36
TCmdLine::TKind
TCmdLine::NextToken
(
bool
removeCurrent)
37
{
38
// Done parsing, no more tokens
39
//
40
if
(Kind ==
Done
)
41
return
Kind;
42
43
// Move Token ptr to next token, by copying over current token, or by ptr
44
// adjustment. TokenStart stays right past previous token
45
//
46
if
(removeCurrent) {
47
::_tcscpy
(TokenStart, Token+TokenLen);
48
Token = TokenStart;
49
}
50
else
{
51
Token += TokenLen;
52
TokenStart = Token;
53
}
54
55
// Adjust token ptr to begining of token & determine kind
56
//
57
Token +=
_tcsspn
(Token,
whitespace
);
// skip leading whitespace
58
switch
(*Token) {
59
case
0:
60
Kind =
Done
;
61
break
;
62
case
_T
(
'='
):
63
Kind =
Value
;
64
Token++;
65
break
;
66
case
_T
(
'-'
):
67
case
_T
(
'/'
):
68
Kind =
Option
;
69
Token++;
70
Token +=
_tcsspn
(Token,
whitespace
);
// skip any more whitespace
71
if
(*Token ==
_T
(
'\"'
)) {
72
Token++;
// skip the quote
73
TokenLen =
static_cast<
int
>
(
_tcscspn
(Token,
_T
(
"\""
)));
74
Token[TokenLen] = 0;
// remove quote
75
TokenLen++;
// next char
76
return
Kind;
77
}
78
break
;
79
case
_T
(
'\"'
):
80
Kind =
Name
;
81
Token++;
// skip the quote
82
TokenLen =
static_cast<
int
>
(
_tcscspn
(Token,
_T
(
"\""
)));
83
Token[TokenLen] = 0;
// remove quote
84
TokenLen++;
// next char
85
return
Kind;
86
default
:
87
Kind =
Name
;
88
}
89
Token +=
_tcsspn
(Token,
whitespace
);
// skip any more whitespace
90
TokenLen =
static_cast<
int
>
(
_tcscspn
(Token,
terminator
));
91
return
Kind;
92
}
93
94
tstring
TCmdLine::GetToken
()
const
95
{
96
if
(TokenLen > 0 && Token[TokenLen - 1] == 0)
97
return
tstring
(Token, TokenLen - 1);
// Trim trailing null character that was put when removing the enclosing double quotes
98
else
99
return
tstring
(Token, TokenLen);
100
}
101
102
103
104
}
// OWL namespace
105
/* ========================================================================== */
106
owl::TCmdLine::~TCmdLine
~TCmdLine()
Definition
cmdline.cpp:31
owl::TCmdLine::TCmdLine
TCmdLine(const tstring &cmdLine)
Definition
cmdline.cpp:17
owl::TCmdLine::TKind
TKind
Definition
cmdline.h:37
owl::TCmdLine::Option
@ Option
Option type token. Leading / or - skipped by Token.
Definition
cmdline.h:40
owl::TCmdLine::Value
@ Value
Value for name or option. Leading : or = skipped by Token.
Definition
cmdline.h:41
owl::TCmdLine::Start
@ Start
No tokens have been parsed yet.
Definition
cmdline.h:38
owl::TCmdLine::Done
@ Done
No more tokens.
Definition
cmdline.h:42
owl::TCmdLine::Name
@ Name
Name type token, has no leading / or -.
Definition
cmdline.h:39
owl::TCmdLine::GetToken
tstring GetToken() const
Definition
cmdline.cpp:94
owl::TCmdLine::Reset
void Reset()
Definition
cmdline.cpp:24
owl::TCmdLine::NextToken
TKind NextToken(bool removeCurrent=false)
Definition
cmdline.cpp:36
cmdline.h
Command line parsing class.
_tcscpy
#define _tcscpy
Definition
cygwin.h:79
_tcscspn
#define _tcscspn
Definition
cygwin.h:82
_T
#define _T(x)
Definition
cygwin.h:51
_tcsspn
#define _tcsspn
Definition
cygwin.h:81
pch.h
memory.h
Reliable platform independent header for common memory and string functions.
owl
Object Windows Library (OWLNext Core).
Definition
animctrl.h:22
owl::terminator
const tchar terminator[]
Definition
cmdline.cpp:15
owl::whitespace
const tchar whitespace[]
Definition
cmdline.cpp:14
owl::tchar
char tchar
Definition
defs.h:77
owl::tstring
std::string tstring
Definition
defs.h:79
source
owlcore
cmdline.cpp
Generated by
1.18.0