FreeNOS
Echo.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2009 Alexander Schrijver
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include "Echo.h"
22
23Echo::Echo(int argc, char **argv)
24 : POSIXApplication(argc, argv)
25{
26 parser().setDescription("Echo standard input to output");
27 parser().registerPositional("STRING", "text string to echo", 0);
28 parser().registerFlag('n', "no-newline", "If set, do not print new line character");
29}
30
32{
33}
34
36{
37 const Vector<Argument *> & positionals = arguments().getPositionals();
38 const char *no_newline = arguments().get("no-newline");
39
40 // Loop positional arguments
41 for (Size i = 0; i < positionals.count(); i++)
42 printf("%s ", *(positionals[i]->getValue()));
43
44 // Print newline
45 if (no_newline == NULL)
46 printf("\n");
47
48 return Success;
49}
Result
Result codes.
Definition Application.h:54
const ArgumentContainer & arguments() const
Get program arguments.
ArgumentParser & parser()
Get program arguments parser.
const Vector< Argument * > & getPositionals() const
Get positional arguments.
const char * get(const char *name) const
Get argument by name.
void setDescription(const String &desc)
Set program description.
Result registerPositional(const char *name, const char *description, Size count=1)
Register a positional argument.
Result registerFlag(char arg, const char *name, const char *description)
Register a flag Argument.
virtual ~Echo()
Destructor.
Definition Echo.cpp:31
virtual Result exec()
Execute the application.
Definition Echo.cpp:35
Echo(int argc, char **argv)
Constructor.
Definition Echo.cpp:23
POSIX-compatible application.
Vectors are dynamically resizeable Arrays.
Definition Vector.h:42
virtual Size count() const
Returns the number of items inside the Vector.
Definition Vector.h:204
C int printf(const char *format,...)
Output a formatted string to standard output.
Definition printf.cpp:22
#define NULL
NULL means zero.
Definition Macros.h:39
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128