Skip to content

Commit 59fca87

Browse files
committed
Merge branch 'master' into asar_2_beta
2 parents ef1039d + e1e3949 commit 59fca87

37 files changed

+392
-367
lines changed

README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@ If you'd rather not build from source, check out the [Releases](https://github.c
1414
Asar can also be built as a DLL. This makes it easier and faster to use in other programs (such as a sprite insertion tool). You can find documentation on the DLL API in the respective bindings (asardll.h, asar.cs, asar.py).
1515

1616
## Asar as a static library
17-
Asar can also be build as a static library. All "out-facing" functions are in interface-lib.h. This is useful for embedding Asar in other programs which don't want to use DLLs. The easiest way to add asar as a static library to your project, assuming you are using CMake (at least 3.11), is to use [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) to fetch the source code, then add the following to your CMakeLists.txt:
17+
Asar can also be built as a static library. All "out-facing" functions are in interface-lib.h. This is useful for embedding Asar in other programs which don't want to use DLLs. The easiest way to add asar as a static library to your project is to add it as a git submodule
18+
19+
`git submodule add https://github.com/RPGHacker/asar <path-to-subdir>`
20+
21+
then add the following to your CMakeLists.txt:
1822
```CMake
19-
target_include_directories(YourTarget PUBLIC ${asar_SOURCE_DIR}/src)
23+
add_subdirectory(<path-to-subdir>/src)
24+
get_target_property(ASAR_INCLUDE_DIR asar-static INCLUDE_DIRECTORIES)
25+
include_directories(${ASAR_INCLUDE_DIR})
26+
target_link_libraries(YourTarget PUBLIC asar-static)
2027
```
21-
to be able to include the header files. It is also recommended to add `set(ASAR_TESTING_DISABLED TRUE)` to your CMakeLists.txt to disable building tests.
28+
to be able to include the header files. It is also recommended to turn off every build in target in asar except the static one using the appropriate CMake options. You will need to make sure that your project has an Asar compatible license.
2229

2330
## Folder layout
2431
* `docs` contains the source of the manual and changelog.
@@ -46,7 +53,7 @@ These two characters should precede each test line, so that Asar sees them as co
4653
* 2 hex digits - a byte for it to check for
4754
* You can specify more than one, like in the examples below, and it will automatically increment the offset.
4855
* A line starting with `+` tells the testing app to patch the SMW ROM instead of creating a new ROM
49-
* `errEXXXX` and `warnWXXXX` (where `XXXX` is an ID number) means that the test is expected to throw that specific error or warning while patching. The test will succeed only if the number and order of errors and warnings thrown exactly matches what's specified here. Be wary that Asar uses multiple passes and throws errors and warnings across multiple of them. This can make the actual order in which errors and warnings are thrown a bit unintuitive.
56+
* `errE{name}` and `warnW{name}` (where `{name}` is the name of an error or warning) means that the test is expected to throw that specific error or warning while patching. The test will succeed only if the number and order of errors and warnings thrown exactly matches what's specified here. Be wary that Asar uses multiple passes and throws errors and warnings across multiple of them. This can make the actual order in which errors and warnings are thrown a bit unintuitive.
5057

5158
In addition to the format mentioned above, it's also possible to check for user prints a patch is expected to output (by `print`, `error`, `warn` or `assert` commands). This is done by starting the line with one of the following sequences:
5259
```
@@ -68,17 +75,17 @@ This line tests that `22`, `20`, `80` and `90` were written to the ROM offset `0
6875
;`007606 22 20 80 90
6976
```
7077

71-
This line tests that assembling the patch throws error `5117` twice and warning `1030` once.
78+
This line tests that assembling the patch throws error `Eunknown_command` twice and warning `Wfeature_deprecated` once.
7279
```
73-
;`errE5117
74-
;`errE5117
75-
;`warnW1030
80+
;`errEunknown_command
81+
;`errEunknown_command
82+
;`warnWfeature_deprecated
7683
```
7784

78-
This line tests that the byte `FF` was written to the start of the ROM, that the string `This is a print.` was printed and that the string `This is a user error.` was output via the error command (which itself also causes error `E5159`to be thrown once).
85+
This line tests that the byte `FF` was written to the start of the ROM, that the string `This is a print.` was printed and that the string `This is a user error.` was output via the error command (which itself also causes error `Eerror_command` to be thrown once).
7986
```
8087
;`FF
8188
;P>This is a print.
8289
;E>This is a user error.
83-
;`errE5159
90+
;`errEerror_command
8491
```

docs/changelog/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ <h3>Deprecated features:</h3>
102102
<ul>
103103
</ul></div>
104104

105+
<h3>Deprecated features:</h3>
106+
<ul>
107+
<li>Warning and error IDs: Asar now uses named warnings and errors. (p4plus2, RPG Hacker)</li>
108+
</ul></div>
109+
105110
<hr />
106111

107112
<div><h2>v1.81</h2>

src/asar-tests/test.cpp

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,8 @@ int main(int argc, char * argv[])
714714

715715
int numiter = 1;
716716

717-
std::vector<int> expected_errors;
718-
std::vector<int> expected_warnings;
717+
std::vector<std::string> expected_errors;
718+
std::vector<std::string> expected_warnings;
719719
std::vector<std::string> expected_prints;
720720
std::vector<std::string> expected_error_prints;
721721
std::vector<std::string> expected_warn_prints;
@@ -771,30 +771,16 @@ int main(int argc, char * argv[])
771771
if (strncmp(cur_word.c_str(), token, strlen(token)) == 0)
772772
{
773773
const char* idstr = cur_word.c_str() + strlen(token);
774-
char* endpos = nullptr;
775-
long int id = strtol(idstr, &endpos, 10);
776774

777-
if (endpos == nullptr || *endpos != '\0')
778-
{
779-
dief("Error: Invalid %s declaration!\n", token);
780-
}
781-
782-
expected_errors.push_back((int)id);
775+
expected_errors.push_back(idstr-1);
783776
}
784777

785778
token = "warnW";
786779
if (strncmp(cur_word.c_str(), token, strlen(token)) == 0)
787780
{
788781
const char* idstr = cur_word.c_str() + strlen(token);
789-
char* endpos = nullptr;
790-
long int id = strtol(idstr, &endpos, 10);
791-
792-
if (endpos == nullptr || *endpos != '\0')
793-
{
794-
dief("Error: Invalid %s declaration!\n", token);
795-
}
796782

797-
expected_warnings.push_back((int)id);
783+
expected_warnings.push_back(idstr-1);
798784
}
799785

800786
if (pos > len) len = pos;
@@ -1022,8 +1008,8 @@ int main(int argc, char * argv[])
10221008
}
10231009
#endif
10241010

1025-
std::vector<int> actual_errors;
1026-
std::vector<int> actual_warnings;
1011+
std::vector<std::string> actual_errors;
1012+
std::vector<std::string> actual_warnings;
10271013
std::vector<std::string> actual_prints;
10281014
std::vector<std::string> actual_error_prints;
10291015
std::vector<std::string> actual_warn_prints;
@@ -1042,20 +1028,20 @@ int main(int argc, char * argv[])
10421028
size_t found = log_line.find(token);
10431029
if (found != std::string::npos)
10441030
{
1045-
char* endpos = nullptr;
1046-
long int num = strtol(log_line.c_str() + found + strlen(token), &endpos, 10);
1031+
size_t found_end = log_line.find(')', found + 1);
10471032

1048-
if (endpos == nullptr || *endpos != ')')
1033+
if (found_end == std::string::npos)
10491034
{
1050-
dief("Error: Failed parsing error code from Asar output!\n");
1035+
dief("Error: Failed parsing error name from Asar output!\n");
10511036
}
10521037

1053-
actual_errors.push_back(num);
1038+
size_t start_pos = found + strlen(token) - 1;
1039+
actual_errors.push_back(log_line.substr(start_pos, found_end - start_pos));
10541040

10551041
// RPG Hacker: Check if it's the error command. If so, we also need to add a print as well.
10561042
{
10571043
std::string command_token = ": error command: ";
1058-
std::string remainder = endpos;
1044+
std::string remainder = log_line.substr(found_end+1);
10591045
size_t command_found = remainder.find(command_token);
10601046

10611047
if (command_found != std::string::npos)
@@ -1067,7 +1053,7 @@ int main(int argc, char * argv[])
10671053
// RPG Hacker: Same goes for the assert command.
10681054
{
10691055
std::string command_token = ": Assertion failed: ";
1070-
std::string remainder = endpos;
1056+
std::string remainder = log_line.substr(found_end + 1);
10711057
size_t command_found = remainder.find(command_token);
10721058

10731059
if (command_found != std::string::npos)
@@ -1084,20 +1070,20 @@ int main(int argc, char * argv[])
10841070
found = log_line.find(token);
10851071
if (found != std::string::npos)
10861072
{
1087-
char* endpos = nullptr;
1088-
long int num = strtol(log_line.c_str() + found + strlen(token), &endpos, 10);
1073+
size_t found_end = log_line.find(')', found + 1);
10891074

1090-
if (endpos == nullptr || *endpos != ')')
1075+
if (found_end == std::string::npos)
10911076
{
10921077
dief("Error: Failed parsing warning code from Asar output!\n");
10931078
}
10941079

1095-
actual_warnings.push_back(num);
1080+
size_t start_pos = found + strlen(token) - 1;
1081+
actual_warnings.push_back(log_line.substr(start_pos, found_end - start_pos));
10961082

10971083
// RPG Hacker: Check if it's the warn command. If so, we also need to add a print as well.
10981084
{
10991085
std::string command_token = ": warn command: ";
1100-
std::string remainder = endpos;
1086+
std::string remainder = log_line.substr(found_end + 1);
11011087
size_t command_found = remainder.find(command_token);
11021088

11031089
if (command_found != std::string::npos)
@@ -1178,28 +1164,28 @@ int main(int argc, char * argv[])
11781164
printf("\nExpected errors: ");
11791165
for (auto it = expected_errors.begin(); it != expected_errors.end(); ++it)
11801166
{
1181-
printf("%sE%d", (it != expected_errors.begin() ? "," : ""), *it);
1167+
printf("%s%s", (it != expected_errors.begin() ? "," : ""), it->c_str());
11821168
}
11831169
printf("\n");
11841170

11851171
printf("Actual errors: ");
11861172
for (auto it = actual_errors.begin(); it != actual_errors.end(); ++it)
11871173
{
1188-
printf("%sE%d", (it != actual_errors.begin() ? "," : ""), *it);
1174+
printf("%s%s", (it != actual_errors.begin() ? "," : ""), it->c_str());
11891175
}
11901176
printf("\n");
11911177

11921178
printf("\nExpected warnings: ");
11931179
for (auto it = expected_warnings.begin(); it != expected_warnings.end(); ++it)
11941180
{
1195-
printf("%sW%d", (it != expected_warnings.begin() ? "," : ""), *it);
1181+
printf("%s%s", (it != expected_warnings.begin() ? "," : ""), it->c_str());
11961182
}
11971183
printf("\n");
11981184

11991185
printf("Actual warnings: ");
12001186
for (auto it = actual_warnings.begin(); it != actual_warnings.end(); ++it)
12011187
{
1202-
printf("%sW%d", (it != actual_warnings.begin() ? "," : ""), *it);
1188+
printf("%s%s", (it != actual_warnings.begin() ? "," : ""), it->c_str());
12031189
}
12041190
printf("\n");
12051191

@@ -1243,7 +1229,7 @@ int main(int argc, char * argv[])
12431229
memcpy(truerom, out_rom_data.data(), out_rom_data.size());
12441230
#endif
12451231
bool fail = false;
1246-
for (int i = 0;i < min(len, truelen);i++)
1232+
for (int i = 0;i < min(len, truelen); i++)
12471233
{
12481234
if (truerom[i] != expectedrom[i] && !(i >= 0x07FDC && i <= 0x07FDF && (expectedrom[i] == 0x00 || expectedrom[i] == smwrom[i])))
12491235
{

0 commit comments

Comments
 (0)