2 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net.
3 * Distributed under the terms of the MIT License.
17 #undef B_TRANSLATION_CONTEXT
18 #define B_TRANSLATION_CONTEXT "Terminal arguments parsing"
21 Arguments::Arguments(int defaultArgsNum
, const char* const* defaultArgs
)
22 : fUsageRequested(false),
23 fBounds(50, 50, 630, 435),
26 fShellArgumentCount(0),
27 fShellArguments(NULL
),
30 _SetShellArguments(defaultArgsNum
, defaultArgs
);
34 Arguments::~Arguments()
36 _SetShellArguments(0, NULL
);
41 Arguments::Parse(int argc
, const char* const* argv
)
44 for (argi
= 1; argi
< argc
; argi
++) {
45 const char* arg
= argv
[argi
];
48 if (strcmp(arg
, "-h") == 0 || strcmp(arg
, "--help") == 0)
49 fUsageRequested
= true;
50 else if (strcmp(arg
, "-t") == 0 || strcmp(arg
, "--title") == 0) {
53 fUsageRequested
= true;
55 fTitle
= argv
[++argi
];
57 } else if (strcmp(arg
, "-f") == 0 || strcmp(arg
, "--fullscreen")
62 fprintf(stderr
, B_TRANSLATE("Unrecognized option \"%s\"\n"),
64 fUsageRequested
= true;
67 // no option, so the remainder is the shell program with arguments
68 _SetShellArguments(argc
- argi
, argv
+ argi
);
70 fStandardShell
= false;
77 Arguments::GetShellArguments(int& argc
, const char* const*& argv
) const
79 argc
= fShellArgumentCount
;
80 argv
= fShellArguments
;
85 Arguments::_SetShellArguments(int argc
, const char* const* argv
)
87 // delete old arguments
88 for (int32 i
= 0; i
< fShellArgumentCount
; i
++)
89 free((void *)fShellArguments
[i
]);
90 delete[] fShellArguments
;
92 fShellArguments
= NULL
;
93 fShellArgumentCount
= 0;
96 if (argc
> 0 && argv
) {
97 fShellArguments
= new const char*[argc
+ 1];
98 for (int i
= 0; i
< argc
; i
++)
99 fShellArguments
[i
] = strdup(argv
[i
]);
101 fShellArguments
[argc
] = NULL
;
102 fShellArgumentCount
= argc
;