52 UserInterface::UserInterface(
const QString &xmlfile,
int &argc,
65 FileName setup =
"$HOME/.Isis/history";
67 if ( !setup.fileExists() ) {
68 setup.dir().mkpath(
".");
81 p_gui = Gui::Create(*
this, argc, argv);
135 for (
unsigned int currArgument = 1; currArgument <
p_cmdline.size(); currArgument ++) {
137 vector<QString> paramValue;
143 if (paramName[0] ==
'-')
146 for (
unsigned int value = 0; value < paramValue.size(); value++) {
147 IString thisValue = paramValue[value];
148 QString token = thisValue.
Token(
"$").
ToQt();
152 while (thisValue !=
"") {
155 int j =
toInt( thisValue.substr(0, 1).c_str() ) - 1;
157 thisValue.replace(0, 1,
"");
170 paramValue[value] = newValue;
182 if(paramValue.size() == 1) {
183 cout <<
"=" << paramValue[0] <<
" ";
185 else if (paramValue.size() > 1) {
188 for (
unsigned int value = 0; value < paramValue.size(); value++) {
192 cout << paramValue[value] << endl;
219 os.open(fileName.toAscii().data(), std::ios::app);
223 QString msg =
"Unable to create error list [" +
p_errList
224 +
"] Disk may be full or directory permissions not writeable";
228 for (
int j = 0; j < (int)
p_batchList[i].size(); j++) {
247 if (grp[
"HistoryRecording"][0] ==
"Off")
267 if ( histFile.fileExists() ) {
268 hist.
read( histFile.expanded() );
278 while( hist.
groups() >
toInt(grp[
"HistoryLength"][0]) ) {
284 hist.
write( histFile.expanded() );
311 QString msg =
"The batchlist file [" + file +
"] could not be opened";
317 for (
int i = 0; i < temp.
LineCount(); i++) {
334 foreach (QString token, tokens) {
336 token = token.remove( QRegExp(
"[\"']") );
346 QString msg =
"The number of columns must be constant in batchlist";
352 QString msg =
"The list file [" + file +
"] does not contain any data";
379 if ( (argc == 1) && (file.name() !=
"unitTest") ) {
384 for (
int i = 0; i < argc; i++) {
389 vector<QString> options;
390 options.push_back(
"-GUI");
391 options.push_back(
"-NOGUI");
392 options.push_back(
"-BATCHLIST");
393 options.push_back(
"-LAST");
394 options.push_back(
"-RESTORE");
395 options.push_back(
"-WEBHELP");
396 options.push_back(
"-HELP");
397 options.push_back(
"-ERRLIST");
398 options.push_back(
"-ONERROR");
399 options.push_back(
"-SAVE");
400 options.push_back(
"-INFO");
401 options.push_back(
"-PREFERENCE");
402 options.push_back(
"-LOG");
403 options.push_back(
"-VERBOSE");
404 options.push_back(
"-PID");
406 bool usedDashLast =
false;
407 bool usedDashRestore =
false;
416 for (
unsigned int currArgument = 1; currArgument < (unsigned)argc; currArgument++) {
418 vector<QString> paramValue;
423 if (paramName[0] ==
'-') {
424 paramName = paramName.toUpper();
428 if (paramValue.size() > 1) {
429 QString msg =
"Invalid value for reserve parameter ["
439 if (paramName ==
"-LAST") {
446 if (paramName ==
"-RESTORE") {
447 usedDashRestore =
true;
451 QString realValue =
"";
453 if ( paramValue.size() ) {
454 realValue = paramValue[0];
472 || usedDashRestore) ) {
473 QString msg =
"-BATCHLIST cannot be used with -GUI, -SAVE, -RESTORE, ";
480 QString msg =
"-ERRLIST and -ONERROR=continue cannot be used without ";
481 msg +=
" the -BATCHLIST option";
500 if ( hist.fileExists() ) {
505 if (g >= 0 && lab.group(g).isNamed(
"UserParameters") ) {
507 for (
int k = 0; k < up.
keywords(); k++) {
508 QString keyword = up[k].
name();
510 vector<QString> values;
512 for (
int i = 0; i < up[k].size(); i++) {
513 values.push_back(up[k][i]);
518 bool matchesDefault =
false;
519 if (values.size() == 1 && paramData->internalDefault == values[0])
520 matchesDefault =
true;
522 if (!matchesDefault) {
524 (values.size() == paramData->defaultValues.size());
526 for (
int i = 0; matchesDefault && i < (int)values.size(); i++) {
527 matchesDefault = matchesDefault &&
528 values[i] == paramData->defaultValues[i];
538 for (
int o = lab.objects() - 1; o >= 0; o--) {
541 for (
int g = obj.
groups() - 1; g >= 0; g--) {
543 if ( up.
isNamed(
"UserParameters") ) {
544 for (
int k = 0; k < up.
keywords(); k++) {
545 QString keyword = up[k].
name();
546 QString value = up[k][0];
560 QString msg =
"The history file [" + file +
"] is corrupt, please fix or delete this file";
565 QString msg =
"The history file [" + file +
"] does not exist";
586 const QString value) {
588 bool unitTest =
false;
594 if (name ==
"-GUI") {
597 else if (name ==
"-NOGUI") {
600 else if (name ==
"-BATCHLIST") {
603 else if (name ==
"-LAST") {
616 else if(name ==
"-RESTORE") {
619 else if(name ==
"-WEBHELP") {
621 QString command = pref[
"GuiHelpBrowser"];
622 command +=
" $ISISROOT/doc/Application/presentation/Tabbed/";
627 "Evaluating -WEBHELP should only throw this exception during a unitTest",
636 else if (name ==
"-INFO") {
640 if (value.size() != 0) {
644 else if (name ==
"-HELP") {
645 if (value.size() == 0) {
788 "Evaluating -HELP should only throw this exception during a unitTest",
796 else if (name ==
"-PID") {
799 else if (name ==
"-ERRLIST") {
803 QString msg =
"-ERRLIST expects a file name";
811 else if (name ==
"-ONERROR") {
812 if (value.toUpper() ==
"CONTINUE") {
816 else if (value.toUpper() ==
"ABORT") {
821 QString msg =
"[" + value
822 +
"] is an invalid value for -ONERROR, options are ABORT or CONTINUE";
826 else if (name ==
"-SAVE") {
827 if (value.size() == 0) {
834 else if (name ==
"-PREFERENCE") {
837 else if (name ==
"-LOG") {
838 if( value.isEmpty() ) {
839 p.
findGroup(
"SessionLog")[
"FileOutput"].setValue(
"On");
842 p.
findGroup(
"SessionLog")[
"FileOutput"].setValue(
"On");
843 p.
findGroup(
"SessionLog")[
"FileName"].setValue(value);
847 else if (name ==
"-VERBOSE") {
848 p.
findGroup(
"SessionLog")[
"TerminalOutput"].setValue(
"On");
853 QString msg =
"-GUI and -PID are incompatible arguments";
872 std::vector<QString> &value) {
874 QString paramValue =
"";
879 if ( !paramName.contains(
"=") ) {
884 if (QString(
p_cmdline[curPos + 1]).compare(
"=") == 0) {
893 else if ( paramName.endsWith(
"=") ) {
894 paramName = paramName.mid(0, paramName.size() - 1);
904 else if (paramName.indexOf(
"=") > 0) {
905 QString parameterLiteral =
p_cmdline[curPos];
906 paramName = parameterLiteral.mid( 0, parameterLiteral.indexOf(
"=") );
907 paramValue = parameterLiteral.mid(parameterLiteral.indexOf(
"=") + 1);
912 QString msg =
"Unknown parameter [" + QString(
p_cmdline[curPos])
921 paramValue = paramValue.trimmed();
923 if (paramValue.length() > 0 && paramValue[0] !=
'(') {
928 if (paramValue.length() > 1 && paramValue.mid(0, 2) ==
"\\(") {
929 paramValue = paramValue.mid(1);
932 else if (paramValue.length() > 2 && paramValue.mid(0, 3) ==
"\\\\(") {
933 paramValue = paramValue.mid(1);
936 value.push_back(paramValue);
938 else if ( paramValue.length() ) {
958 std::vector<QString> &reservedParams) {
959 for (
unsigned int currArgument = 1; currArgument < (unsigned)
p_cmdline.size();
962 QString paramName =
p_cmdline[currArgument];
963 QString trueParamValue =
"";
964 vector<QString> paramValue;
967 if (paramName[0] ==
'-') {
971 paramName = paramName.toUpper();
974 if ( paramValue.size() ) {
975 trueParamValue = paramValue[0].toUpper();
982 if (fullReservedName == paramName) {
1004 std::vector<QString> values;
1006 bool inDoubleQuotes =
false;
1007 bool inSingleQuotes =
false;
1008 bool arrayClosed =
false;
1009 bool nextElementStarted =
false;
1010 QString currElement =
"";
1012 for (
int strPos = 0; strPos < arrayString.size(); strPos++) {
1014 if (arrayString[strPos] !=
'(') {
1015 QString msg =
"Invalid array format [" + arrayString +
"]";
1023 if ( arrayString[strPos] ==
'\\' && strPos + 1 < (
int)arrayString.size() ) {
1024 currElement += arrayString[strPos+1];
1029 else if (arrayString[strPos] ==
'\\') {
1030 QString msg =
"Invalid array format [" + arrayString +
"]";
1035 if (!inDoubleQuotes && !inSingleQuotes) {
1037 QString msg =
"Invalid array format [" + arrayString +
"]";
1041 nextElementStarted = (nextElementStarted || arrayString[strPos] !=
' ');
1043 if (!nextElementStarted) {
1047 if (arrayString[strPos] ==
'"') {
1048 inDoubleQuotes =
true;
1050 else if (arrayString[strPos] ==
'\'') {
1051 inSingleQuotes =
true;
1053 else if (arrayString[strPos] ==
',') {
1054 values.push_back(currElement);
1056 nextElementStarted =
false;
1058 else if (arrayString[strPos] ==
')') {
1059 values.push_back(currElement);
1062 nextElementStarted =
false;
1064 else if (nextElementStarted && arrayString[strPos] ==
' ') {
1066 bool onlyWhite =
true;
1067 int closingPos = strPos + 1;
1069 for(
int pos = strPos;
1070 onlyWhite && arrayString[pos] !=
',' && arrayString[pos] !=
')' &&
1071 pos < arrayString.size(); pos++) {
1073 onlyWhite &= (arrayString[pos] ==
' ');
1077 currElement += arrayString[strPos];
1080 else if (nextElementStarted) {
1081 currElement += arrayString[strPos];
1084 else if (inSingleQuotes) {
1085 if(arrayString[strPos] ==
'\'') {
1086 inSingleQuotes =
false;
1089 currElement += arrayString[strPos];
1094 if (arrayString[strPos] ==
'"') {
1095 inDoubleQuotes =
false;
1098 currElement += arrayString[strPos];
1103 if (!arrayClosed || currElement !=
"") {
1104 QString msg =
"Invalid array format [" + arrayString +
"]";
1131 std::vector<QString> &reservedParams,
1132 bool handleNoMatches) {
1134 int matchOption = -1;
1136 for (
int option = 0; option < (int)reservedParams.size(); option++) {
1139 if ( reservedParams[option].startsWith(unresolvedParam) ) {
1140 if (matchOption >= 0) {
1141 QString msg =
"Ambiguous Reserve Parameter ["
1142 + unresolvedParam +
"]. Please clarify.";
1146 matchOption = option;
1150 if (handleNoMatches) {
1152 if (matchOption < 0) {
1153 QString msg =
"Invalid Reserve Parameter Option ["
1154 + unresolvedParam +
"]. Choices are ";
1157 for (
int option = 0; option < (int)reservedParams.size(); option++) {
1159 if (reservedParams[option].compare(
"-PID") == 0) {
1163 msgOptions += reservedParams[option];
1176 msg +=
" [" + msgOptions +
"]";
1181 if (matchOption < 0) {
1185 return reservedParams[matchOption];