Skip to content

Commit ea94e34

Browse files
committed
gui version: hotfix to display symbols in output window
1 parent dea7af5 commit ea94e34

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

src/cli.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ static inline void showargs(void)
1717
fprintf(stderr, " --only 'l,i,s,t' * include or exclude\n");
1818
fprintf(stderr, " --except 'l,i,s,t' * groups named in list\n");
1919
fprintf(stderr, " --silent * print only errors\n");
20+
//fprintf(stderr, " --docs * print old docs format\n"); // TODO this feature
2021
fprintf(stderr, " --print-palettes * output palette addresses\n");
2122
fprintf(stderr, " --world-header 'x,y,z' * embed minimal game world headers\n");
2223
fprintf(stderr, " - xyz: player spawn coordinates\n");
@@ -27,7 +28,7 @@ static inline void showargs(void)
2728
fprintf(stderr, " - c: collisions\n");
2829
fprintf(stderr, " - s: skeletons\n");
2930
fprintf(stderr, " --header 'out.h' * write C header (--header - for stdout)\n");
30-
fprintf(stderr, " --linker 'out.ld' * write C linker (--header - for stdout)\n");
31+
fprintf(stderr, " --linker 'out.ld' * write C linker (--linker - for stdout)\n");
3132
}
3233

3334
int wow_main(argc, argv)

src/z64convert.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <limits.h> /* PATH_MAX */
66
#include <stdint.h>
77
#include <math.h>
8+
#include <stdbool.h>
89
#include "objex.h"
910
#include "zobj.h"
1011
#include "texture.h"
@@ -14,6 +15,26 @@
1415
#include "collision.h"
1516
#include "doc.h"
1617

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+
1738
#define DSTDERR docs
1839

1940
/* revisions:
@@ -1153,6 +1174,8 @@ const char *z64convert(
11531174
int playAs = 0;
11541175
const char *namHeader = 0;
11551176
const char *namLinker = 0;
1177+
bool shouldPrintDocs = (docs == stdout || docs == stderr) ? false : true;
1178+
bool shouldHotfixOutput = false;
11561179

11571180
for (int i = 1; i < argc; ++i)
11581181
{
@@ -1222,10 +1245,28 @@ const char *z64convert(
12221245
{
12231246
namLinker = argv[++i];
12241247
}
1248+
else if (streq(argv[i], "--docs"))
1249+
{
1250+
shouldPrintDocs = true;
1251+
}
12251252
else
12261253
fail("unknown argument '%.64s'", argv[i]);
12271254
}
12281255

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+
12291270
if (!in)
12301271
return "no in file specified";
12311272
if (!out)
@@ -1303,6 +1344,29 @@ const char *z64convert(
13031344
/* cleanup */
13041345
L_cleanup:
13051346
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+
13061370
return sgRval;
13071371
}
13081372

src/z64convert.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#define NAME "z64convert"
2-
#define VERSION "1.0.2"
2+
#define VERSION "1.0.3"
33
#define AUTHOR "<z64.me>"
44

5+
extern void fprintf_safe(FILE *dst, const char *fmt, ...);
6+
57
extern const char *z64convert(
68
int argc
79
, const char *argv[]

0 commit comments

Comments
 (0)