|
5 | 5 | #include <limits.h> /* PATH_MAX */ |
6 | 6 | #include <stdint.h> |
7 | 7 | #include <math.h> |
| 8 | +#include <stdbool.h> |
8 | 9 | #include "objex.h" |
9 | 10 | #include "zobj.h" |
10 | 11 | #include "texture.h" |
|
14 | 15 | #include "collision.h" |
15 | 16 | #include "doc.h" |
16 | 17 |
|
| 18 | +void fprintf_safe(FILE *dst, const char *fmt, ...) |
| 19 | +{ |
| 20 | + if (!dst) |
| 21 | + return; |
| 22 | + |
| 23 | + va_list args; |
| 24 | + va_start(args, fmt); |
| 25 | +#if defined(_WIN32) && defined(_UNICODE) |
| 26 | + char buf[4096]; |
| 27 | + vsprintf(buf, fmt, args); |
| 28 | + wchar_t *wc = wow_utf8_to_wchar_die(buf); |
| 29 | + setlocale(LC_ALL, ""); |
| 30 | + fwprintf(dst, L"%ls", wc); |
| 31 | + free(wc); |
| 32 | +#else |
| 33 | + vfprintf(dst, fmt, args); |
| 34 | +#endif |
| 35 | + va_end(args); |
| 36 | +} |
| 37 | + |
17 | 38 | #define DSTDERR docs |
18 | 39 |
|
19 | 40 | /* revisions: |
@@ -1153,6 +1174,8 @@ const char *z64convert( |
1153 | 1174 | int playAs = 0; |
1154 | 1175 | const char *namHeader = 0; |
1155 | 1176 | const char *namLinker = 0; |
| 1177 | + bool shouldPrintDocs = (docs == stdout || docs == stderr) ? false : true; |
| 1178 | + bool shouldHotfixOutput = false; |
1156 | 1179 |
|
1157 | 1180 | for (int i = 1; i < argc; ++i) |
1158 | 1181 | { |
@@ -1222,10 +1245,28 @@ const char *z64convert( |
1222 | 1245 | { |
1223 | 1246 | namLinker = argv[++i]; |
1224 | 1247 | } |
| 1248 | + else if (streq(argv[i], "--docs")) |
| 1249 | + { |
| 1250 | + shouldPrintDocs = true; |
| 1251 | + } |
1225 | 1252 | else |
1226 | 1253 | fail("unknown argument '%.64s'", argv[i]); |
1227 | 1254 | } |
1228 | 1255 |
|
| 1256 | + // --docs cli and gui output hotfix |
| 1257 | + if (shouldPrintDocs && (!namLinker || !namHeader)) |
| 1258 | + { |
| 1259 | + shouldHotfixOutput = true; |
| 1260 | + namLinker = ".z64convert.ld"; |
| 1261 | + namHeader = ".z64convert.h"; |
| 1262 | + } |
| 1263 | + |
| 1264 | + // TODO this feature |
| 1265 | + shouldPrintDocs = true; |
| 1266 | + |
| 1267 | + if (!shouldPrintDocs) |
| 1268 | + docs = 0; |
| 1269 | + |
1229 | 1270 | if (!in) |
1230 | 1271 | return "no in file specified"; |
1231 | 1272 | if (!out) |
@@ -1303,6 +1344,29 @@ const char *z64convert( |
1303 | 1344 | /* cleanup */ |
1304 | 1345 | L_cleanup: |
1305 | 1346 | model_free(model); |
| 1347 | + |
| 1348 | + // --docs cli and gui output hotfix |
| 1349 | + if (shouldHotfixOutput) |
| 1350 | + { |
| 1351 | + const char *files[] = { namHeader, namLinker }; |
| 1352 | + |
| 1353 | + for (int i = 0; i < 2; ++i) |
| 1354 | + { |
| 1355 | + FILE *fp; |
| 1356 | + for (fp = fopen(files[i], "rb"); fp; ) { |
| 1357 | + int c = fgetc(fp); |
| 1358 | + if (feof(fp)) |
| 1359 | + break; |
| 1360 | + fputc(c, docs); |
| 1361 | + } |
| 1362 | + if (fp) |
| 1363 | + fclose(fp); |
| 1364 | + } |
| 1365 | + |
| 1366 | + remove(namLinker); |
| 1367 | + remove(namHeader); |
| 1368 | + } |
| 1369 | + |
1306 | 1370 | return sgRval; |
1307 | 1371 | } |
1308 | 1372 |
|
|
0 commit comments