Skip to content

Commit

Permalink
Handle ioctl failure.
Browse files Browse the repository at this point in the history
Make ProgramArgs enum a class enum.
  • Loading branch information
abellgithub committed Feb 12, 2016
1 parent 83db43e commit c0e4eae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
37 changes: 15 additions & 22 deletions include/pdal/util/ProgramArgs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,26 @@ class arg_error
};


namespace
{
namespace PosType
{
/**
Description of an argument that can be parsed by \class ProgramArgs.
Stores information about each argument including the required "longname",
an optional single-character shortname, a description, and an indicator
of the positional-type of the argument.
*/
class Arg
{
public:
/**
Positional type. Either None, Optional or Required.
*/
enum Enum
enum class PosType
{
None, ///< Not positional
Required, ///< Required positional
Optional ///< Optional positional
};

} // namespace PosType
} // unnamed namespace

/**
Description of an argument that can be parsed by \class ProgramArgs.
Stores information about each argument including the required "longname",
an optional single-character shortname, a description, and an indicator
of the positional-type of the argument.
*/
class Arg
{
protected:
/**
Constructor.
Expand Down Expand Up @@ -175,7 +168,7 @@ class Arg
Returns the positional type of the argument.
\note Not intended to be called from user code.
*/
PosType::Enum positional() const
PosType positional() const
{ return m_positional; }

/**
Expand Down Expand Up @@ -227,7 +220,7 @@ class Arg
std::string m_rawVal;
bool m_set;
bool m_hidden;
PosType::Enum m_positional;
PosType m_positional;
};

/**
Expand Down Expand Up @@ -538,7 +531,7 @@ class VArg : public Arg
{
break;
}
if (cnt == 0 && m_positional == PosType::Required)
if (cnt == 0 && m_positional == Arg::PosType::Required)
{
std::ostringstream oss;

Expand Down Expand Up @@ -1065,9 +1058,9 @@ class ProgramArgs
for (auto ai = m_args.begin(); ai != m_args.end(); ++ai)
{
Arg *arg = ai->get();
if (arg->positional() == PosType::Optional)
if (arg->positional() == Arg::PosType::Optional)
opt = true;
if (opt && (arg->positional() == PosType::Required))
if (opt && (arg->positional() == Arg::PosType::Required))
throw arg_error("Found required positional argument after "
"optional positional argument.");
}
Expand Down
3 changes: 2 additions & 1 deletion src/util/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,8 @@ int Utils::screenWidth()
return 80;
#else
struct winsize ws;
ioctl(0, TIOCGWINSZ, &ws);
if (ioctl(0, TIOCGWINSZ, &ws))
return 80;

return ws.ws_col;
#endif
Expand Down

0 comments on commit c0e4eae

Please sign in to comment.