BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / terminal / Arguments.cpp
blob99305ee5b4aeb23066f3822b504400deb26ae3ea
1 /*
2 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "Arguments.h"
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
13 #include <Catalog.h>
14 #include <Locale.h>
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),
24 fStandardShell(true),
25 fFullScreen(false),
26 fShellArgumentCount(0),
27 fShellArguments(NULL),
28 fTitle(NULL)
30 _SetShellArguments(defaultArgsNum, defaultArgs);
34 Arguments::~Arguments()
36 _SetShellArguments(0, NULL);
40 void
41 Arguments::Parse(int argc, const char* const* argv)
43 int argi;
44 for (argi = 1; argi < argc; argi ++) {
45 const char* arg = argv[argi];
47 if (*arg == '-') {
48 if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0)
49 fUsageRequested = true;
50 else if (strcmp(arg, "-t") == 0 || strcmp(arg, "--title") == 0) {
51 // title
52 if (argi >= argc)
53 fUsageRequested = true;
54 else
55 fTitle = argv[++argi];
57 } else if (strcmp(arg, "-f") == 0 || strcmp(arg, "--fullscreen")
58 == 0)
59 fFullScreen = true;
60 else {
61 // illegal option
62 fprintf(stderr, B_TRANSLATE("Unrecognized option \"%s\"\n"),
63 arg);
64 fUsageRequested = true;
66 } else {
67 // no option, so the remainder is the shell program with arguments
68 _SetShellArguments(argc - argi, argv + argi);
69 argi = argc;
70 fStandardShell = false;
76 void
77 Arguments::GetShellArguments(int& argc, const char* const*& argv) const
79 argc = fShellArgumentCount;
80 argv = fShellArguments;
84 void
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;
95 // copy new ones
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;