|
@@ -48,23 +48,19 @@ int OpenRaider::loadConfig(const char *config) {
|
48
|
48
|
return 0;
|
49
|
49
|
}
|
50
|
50
|
|
51
|
|
-int OpenRaider::command(std::string &command) {
|
52
|
|
- // Remove comment, if any
|
53
|
|
- size_t comment = command.find_first_of('#');
|
54
|
|
- if (comment != std::string::npos)
|
55
|
|
- command.erase(comment);
|
56
|
|
-
|
57
|
|
- // Execute command
|
58
|
|
- std::stringstream stream(command);
|
59
|
|
- return this->command(stream);
|
60
|
|
-}
|
61
|
|
-
|
62
|
51
|
int OpenRaider::command(const char *command) {
|
63
|
52
|
std::string tmp(command);
|
64
|
53
|
return this->command(tmp);
|
65
|
54
|
}
|
66
|
55
|
|
67
|
|
-int OpenRaider::command(std::stringstream &command) {
|
|
56
|
+int OpenRaider::command(std::string &c) {
|
|
57
|
+ // Remove comment, if any
|
|
58
|
+ size_t comment = c.find_first_of('#');
|
|
59
|
+ if (comment != std::string::npos)
|
|
60
|
+ c.erase(comment);
|
|
61
|
+
|
|
62
|
+ // Execute command
|
|
63
|
+ std::stringstream command(c);
|
68
|
64
|
std::string cmd;
|
69
|
65
|
command >> cmd;
|
70
|
66
|
|
|
@@ -575,35 +571,33 @@ char *OpenRaider::expandDirectoryNames(const char *s) {
|
575
|
571
|
assert(s != NULL);
|
576
|
572
|
assert(s[0] != '\0');
|
577
|
573
|
|
578
|
|
- if (mBaseDir != NULL) {
|
579
|
|
- const char *base = "$(basedir)";
|
580
|
|
- if (strstr(s, base) != NULL) {
|
581
|
|
- return stringReplace(s, base, mBaseDir);
|
582
|
|
- }
|
583
|
|
- }
|
|
574
|
+ char *result = bufferString("%s", s);
|
584
|
575
|
|
585
|
576
|
if (mPakDir != NULL) {
|
586
|
|
- const char *pak = "$(pakdir)";
|
587
|
|
- if (strstr(s, pak) != NULL) {
|
588
|
|
- return stringReplace(s, pak, mPakDir);
|
589
|
|
- }
|
|
577
|
+ char *tmp = stringReplace(s, "$(pakdir)", mPakDir);
|
|
578
|
+ delete [] result;
|
|
579
|
+ result = tmp;
|
590
|
580
|
}
|
591
|
581
|
|
592
|
582
|
if (mAudioDir != NULL) {
|
593
|
|
- const char *audio = "$(audiodir)";
|
594
|
|
- if (strstr(s, audio) != NULL) {
|
595
|
|
- return stringReplace(s, audio, mAudioDir);
|
596
|
|
- }
|
|
583
|
+ char *tmp = stringReplace(s, "$(audiodir)", mAudioDir);
|
|
584
|
+ delete [] result;
|
|
585
|
+ result = tmp;
|
597
|
586
|
}
|
598
|
587
|
|
599
|
588
|
if (mDataDir != NULL) {
|
600
|
|
- const char *data = "$(datadir)";
|
601
|
|
- if (strstr(s, data) != NULL) {
|
602
|
|
- return stringReplace(s, data, mDataDir);
|
603
|
|
- }
|
|
589
|
+ char *tmp = stringReplace(s, "$(datadir)", mDataDir);
|
|
590
|
+ delete [] result;
|
|
591
|
+ result = tmp;
|
604
|
592
|
}
|
605
|
593
|
|
606
|
|
- return NULL;
|
|
594
|
+ if (mBaseDir != NULL) {
|
|
595
|
+ char *tmp = stringReplace(result, "$(basedir)", mBaseDir);
|
|
596
|
+ delete [] result;
|
|
597
|
+ result = tmp;
|
|
598
|
+ }
|
|
599
|
+
|
|
600
|
+ return result;
|
607
|
601
|
}
|
608
|
602
|
|
609
|
603
|
#define CHANGE_DIR_WITH_EXPANSION(a) do { \
|
|
@@ -612,16 +606,12 @@ char *OpenRaider::expandDirectoryNames(const char *s) {
|
612
|
606
|
const char *value = temp.c_str(); \
|
613
|
607
|
char *quotes = stringRemoveQuotes(value); \
|
614
|
608
|
char *tmp = expandDirectoryNames(quotes); \
|
615
|
|
- if (tmp == NULL) { \
|
616
|
|
- a = fullPath(quotes, 0); \
|
617
|
|
- } else { \
|
618
|
|
- a = fullPath(tmp, 0); \
|
619
|
|
- delete [] tmp; \
|
620
|
|
- } \
|
|
609
|
+ a = fullPath(tmp, 0); \
|
|
610
|
+ delete [] tmp; \
|
621
|
611
|
delete [] quotes; \
|
622
|
612
|
} while(false)
|
623
|
613
|
|
624
|
|
-int OpenRaider::set(std::stringstream &command) {
|
|
614
|
+int OpenRaider::set(std::istream &command) {
|
625
|
615
|
std::string var;
|
626
|
616
|
command >> var >> std::boolalpha;
|
627
|
617
|
|
|
@@ -692,12 +682,8 @@ int OpenRaider::set(std::stringstream &command) {
|
692
|
682
|
const char *value = temp.c_str();
|
693
|
683
|
char *quotes = stringReplace(value, "\"", "");
|
694
|
684
|
char *tmp = expandDirectoryNames(quotes);
|
695
|
|
- if (tmp == NULL) {
|
696
|
|
- getWindow().setFont(quotes);
|
697
|
|
- } else {
|
698
|
|
- getWindow().setFont(tmp);
|
699
|
|
- delete [] tmp;
|
700
|
|
- }
|
|
685
|
+ getWindow().setFont(tmp);
|
|
686
|
+ delete [] tmp;
|
701
|
687
|
delete [] quotes;
|
702
|
688
|
} else {
|
703
|
689
|
getConsole().print("set-Error: Unknown variable (%s)", var.c_str());
|