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
|
#include "command.ih"
bool Command::determineAction()
{
switch (int ch = d_arguments[0]) // Interpret the first character
{
case '0': // from parent 0 or cwd
d_action = FROM_CWD;
break;
case '.': // from HOME
d_action = FROM_HOME;
break;
case '/': // explicitly from the root
d_action = FROM_ROOT;
break; // breaks remove the 1st char from args
// start from a parent
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
d_parent = ch - '0';
d_action = FROM_PARENT;
break;
// other characters: 1st letter of directory
default:
{
bool firstIsSeparator = (ch == '_');
if (firstIsSeparator)
d_arguments.erase(0, 1); // remove the 1st char
d_action = FROM_CONFIG;
return firstIsSeparator;
}
}
d_arguments.erase(0, 1); // remove the 1st (location) character
return false;
}
|