29 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
31 using namespace basis;
43 : _type(type), _text(new
astring) {}
46 : _type(type), _text(new
astring(text)) {}
49 : _type(VALUE), _text(new
astring)
61 if (
this == &to_copy)
return *
this;
62 _type = to_copy._type;
63 *_text = *to_copy._text;
72 static char option_prefixes[] = {
'-',
'\0' };
76 for (
int i = 0; option_prefixes[i]; i++)
77 if (to_test == option_prefixes[i])
return true;
83 class internal_cmd_line_array_of_parms :
public array<command_parameter> {};
91 : _implementation(new internal_cmd_line_array_of_parms),
100 string_list += to_store;
103 parse_string_array(string_list);
107 : _implementation(new internal_cmd_line_array_of_parms),
112 bool in_quote =
false;
118 for (
int i = 0; i < full_line.
length(); i++) {
119 char to_examine = full_line.
get(i);
120 if (to_examine ==
'"') {
133 if (parser_bits::white_space(to_examine)) {
135 if (!in_quote && accumulator.
t()) {
137 string_list += accumulator;
139 }
else if (in_quote) {
141 accumulator += to_examine;
145 accumulator += to_examine;
148 if (accumulator.
t()) string_list += accumulator;
151 *_program_name = directory::absolute_path(string_list[0]);
152 string_list.
zap(0, 0);
153 parse_string_array(string_list);
158 WHACK(_program_name);
159 WHACK(_implementation);
169 return _implementation->get(field);
176 if (cmd_line[0] ==
'\"') to_find =
'\"';
183 while (seek_posn < cmd_line.
length()) {
187 int indy = cmd_line.
find(to_find, seek_posn);
196 if (to_find ==
'\"') {
198 if (cmd_line[indy - 1] ==
'\\') {
200 seek_posn = indy + 1;
220 _implementation->zap(field, field);
226 #define COMPLAIN_CMDS(s) \
227 listo_cmds += "unknown"; \
237 #if defined(__UNIX__) || defined(__GNU_WINDOWS__)
240 temporary = application_configuration::get_cmdline_from_proc();
260 COMPLAIN_CMDS(
"this OS doesn't support getting the command line.");
273 while (posn < temporary.
length()) {
274 posn = temporary.
find(
' ', posn);
277 listo_cmds += temporary.
substring(last_posn + 1, posn - 1);
285 if (last_posn < temporary.
length() - 1) {
288 listo_cmds += temporary.
substring(last_posn + 1,
301 const astring EOL = parser_bits::platform_eol_to_chars();
302 for (
int i = 0; i <
entries(); i++) {
305 switch (curr.
type()) {
307 to_return +=
astring(
"<char flag> ") + curr.
text() + EOL;
310 to_return +=
astring(
"<string flag> ") + curr.
text() + EOL;
314 to_return +=
astring(
"<value> ") + curr.
text() + EOL;
322 bool case_sense)
const
324 astring opt(option_character, 1);
326 for (
int i = index; i <
entries(); i++) {
330 || (case_sense && (
get(i).text() == opt));
342 bool case_sense)
const
345 if (option_string.
length() && (option_string[0] ==
'-') )
346 LOG(
astring(
"found option string with dash! string is: ") + option_string);
348 for (
int i = index; i <
entries(); i++) {
350 bool success = (!case_sense &&
get(i).
text().
iequals(option_string))
351 || (case_sense && (
get(i).text() == option_string));
363 bool case_sense)
const
368 if (!
find(option_character, posn, case_sense))
return false;
372 if (posn >=
entries())
return false;
384 bool case_sense)
const
387 if (option_string.
length() && (option_string[0] ==
'-') )
388 LOG(
astring(
"found option string with dash! string is: ") + option_string);
392 if (!
find(option_string, posn, case_sense))
return false;
397 if (posn >=
entries())
return false;
411 void command_line::parse_string_array(
const string_array &to_parse)
413 bool still_looking_for_flags =
true;
415 for (
int i = 0; i < to_parse.
length(); i++) {
418 char c = to_parse[i].
get(index++);
422 bool gnu_type_of_flag =
false;
426 if ( (index >= to_parse[i].length())
427 || parser_bits::white_space(to_parse[i].
get(index))) {
431 still_looking_for_flags =
false;
434 gnu_type_of_flag =
true;
442 if (!gnu_type_of_flag) {
444 c = to_parse[i].
get(index++);
448 *_implementation += to_add;
452 c = to_parse[i].
get(index++);
454 gnu_accumulator += c;
457 if (gnu_accumulator.
t()) {
461 *_implementation += to_add;
467 *_implementation += to_add;
475 for (
int i = index; i <
entries(); i++) {
479 }
else to_return +=
get(i).
text();
int entries() const
Returns the number of fields found on the command line.
static structures::string_array get_command_line()
returns the command line passed to the program as a list of strings.
filesystem::filename program_name() const
Returns the program name found in the command line.
static void separate_command_line(const basis::astring &cmd_line, basis::astring &app, basis::astring &parms)
breaks apart a command line in "cmd_line" into "app" and "parms".
bool find(char option_character, int &index, bool case_sense=true) const
Returns true if the "option_character" is found in the parameters.
bool get_value(char option_character, basis::astring &value, bool case_sense=true) const
retrieves the "value" found for the option flag specified.
const command_parameter & get(int field) const
Returns the parameter at the "field" specified.
basis::astring text_form() const
returns a string with all the information we have for the command line.
basis::astring gather(int &index) const
coalesces parameters together until the next option flag.
bool zap(int field)
eats the entry at position "field".
command_line(int argc, char *argv[])
takes command line parameters in the form of "argc" and "argv".
const basis::astring & text() const
observes the string contents.
command_parameter(parameter_types type=BOGUS_ITEM)
default constructor initializes to mostly blank state.
parameter_types type() const
observes the type of the parameter.
a_sprintf is a specialization of astring that provides printf style support.
Represents a sequential, ordered, contiguous collection of objects.
const contents & get(int index) const
Accesses individual objects stored in "this" at the "index" position.
int length() const
Returns the current reported length of the allocated C array.
outcome zap(int start, int end)
Deletes from "this" the objects inclusively between "start" and "end".
Provides a dynamically resizable ASCII character string.
bool t() const
t() is a shortcut for the string being "true", as in non-empty.
virtual char get(int index) const
a constant peek at the string's internals at the specified index.
bool substring(astring &target, int start, int end) const
a version that stores the substring in an existing "target" string.
bool iequals(const astring &that) const
returns true if this is case-insensitively equal to "that".
int end() const
returns the index of the last (non-null) character in the string.
int length() const
Returns the current length of the string.
int find(char to_find, int position=0, bool reverse=false) const
Locates "to_find" in "this".
void to_lower()
to_lower modifies "this" by replacing capitals with lower-case.
Implements a scanner that finds all filenames in the directory specified.
Provides operations commonly needed on file names.
An array of strings with some additional helpful methods.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
#define bounds_return(value, low, high, to_return)
Verifies that "value" is between "low" and "high", inclusive.
Implements an application lock to ensure only one is running at once.
bool it_is_a_prefix_char(char to_test)
The guards collection helps in testing preconditions and reporting errors.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
bool non_negative(const type &a)
non_negative returns true if "a" is greater than or equal to zero.
bool negative(const type &a)
negative returns true if "a" is less than zero.
A platform independent way to obtain the timestamp of a file.
A logger that sends to the console screen using the standard output device.
A dynamic container class that holds any kind of object via pointers.
#define SAFE_STATIC_CONST(type, func_name, parms)
this version returns a constant object instead.