/usr/include/sp/Options.cxx is in libsp1-dev 1.3.4-1.2.1-47.3ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | // Derived from comp.sources.unix/volume3/att_getopt.
#ifndef Options_DEF_INCLUDED
#define Options_DEF_INCLUDED 1
#ifndef OPTION_CHAR
#define OPTION_CHAR T('-')
#endif
#ifdef SP_NAMESPACE
namespace SP_NAMESPACE {
#endif
template<class T>
Options<T>::Options(int argc, T *const *argv, const T *opts)
: argc_(argc), argv_(argv), opts_(opts), ind_(1), sp_(1)
{
}
template<class T>
const T *Options<T>::search(T c) const
{
for (const T *s = opts_; *s; s++)
if (*s == c)
return s;
return 0;
}
template<class T>
bool Options<T>::get(T &c)
{
const T *cp;
if (sp_ == 1) {
if (ind_ >= argc_)
return false;
if ((
#ifdef OTHER_OPTION_CHAR
argv_[ind_][0] != OTHER_OPTION_CHAR &&
#endif
argv_[ind_][0] != OPTION_CHAR) || argv_[ind_][1] == 0) {
#ifdef REORDER_ARGS
int i;
for (i = ind_; i < argc_; i++)
if ((
#ifdef OTHER_OPTION_CHAR
argv_[i][0] == OTHER_OPTION_CHAR ||
#endif
argv_[i][0] == OPTION_CHAR) && argv_[i][1] != 0)
break;
if (i < argc_) {
c = argv_[i][1];
if (c != T(':') && c != OPTION_CHAR
&& (cp = search(c)) != 0
&& cp[1] == T(':') && argv_[i][2] == 0 && i < argc_ - 1) {
int j;
T *temp1 = argv_[i];
T *temp2 = argv_[i + 1];
for (j = i - 1; j >= ind_; j--)
argv_[j+2] = argv_[j];
argv_[ind_] = temp1;
argv_[ind_ + 1] = temp2;
}
else {
int j;
T *temp = argv_[i];
for (j = i - 1; j >= ind_; j--)
argv_[j+1] = argv_[j];
argv_[ind_] = temp;
}
}
else
#endif
return false;
}
if ((argv_[ind_][0] == OPTION_CHAR && argv_[ind_][1] == OPTION_CHAR
&& argv_[ind_][2] == 0)
#ifdef OTHER_OPTION_CHAR
|| (argv_[ind_][0] == OTHER_OPTION_CHAR
&& argv_[ind_][1] == OTHER_OPTION_CHAR
&& argv_[ind_][2] == 0)
#endif
) {
ind_++;
return false;
}
}
opt_ = c = argv_[ind_][sp_];
if (c == T(':') || (cp = search(c)) == 0) {
if (argv_[ind_][++sp_] == 0) {
ind_++;
sp_ = 1;
}
c = T('?');
return true;
}
if (*++cp == T(':')) {
if (argv_[ind_][sp_ + 1] != 0)
arg_ = &argv_[ind_++][sp_ + 1];
else if (++ind_ >= argc_) {
sp_ = 1;
c = (*opts_ == T(':') ? T(':') : T('?'));
return true;
}
else
arg_ = argv_[ind_++];
sp_ = 1;
}
else {
if (argv_[ind_][++sp_] == 0) {
sp_ = 1;
ind_++;
}
arg_ = 0;
}
return true;
}
#ifdef SP_NAMESPACE
}
#endif
#endif /* not Options_DEF_INCLUDED */
|