2022-10-19 20:16:13 +00:00
|
|
|
#include "cmdline.h"
|
2022-10-11 02:18:42 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
SInt16 rsrcid;
|
2022-10-19 20:16:13 +00:00
|
|
|
const char **strings;
|
2022-10-11 02:18:42 +00:00
|
|
|
} Res;
|
|
|
|
|
|
|
|
static Res rlist[16];
|
|
|
|
|
2023-01-11 22:29:53 +00:00
|
|
|
void Res_Initialize(void) {
|
2022-10-11 02:18:42 +00:00
|
|
|
memset(rlist, 0, sizeof(rlist));
|
|
|
|
}
|
|
|
|
|
2022-10-19 20:16:13 +00:00
|
|
|
int Res_AddResource(const char *name, SInt16 rsrcid, const char **strings) {
|
2022-10-11 02:18:42 +00:00
|
|
|
int scan;
|
|
|
|
|
|
|
|
for (scan = 0; scan < 16 && rlist[scan].rsrcid; scan++) {
|
|
|
|
if (rsrcid == rlist[scan].rsrcid) {
|
|
|
|
fprintf(stderr, "Resource %d is already added!\n", rsrcid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scan >= 16)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rlist[scan].name = name;
|
|
|
|
rlist[scan].rsrcid = rsrcid;
|
|
|
|
rlist[scan].strings = strings;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum { MaxRes = 16 };
|
|
|
|
|
|
|
|
const char *Res_GetResource(SInt16 rsrcid, SInt16 index) {
|
|
|
|
// Does not match, absolutely hopeless
|
|
|
|
int scan, find;
|
|
|
|
static char err[256];
|
|
|
|
|
|
|
|
scan = 0;
|
|
|
|
do {
|
|
|
|
if (rsrcid == rlist[scan].rsrcid) {
|
|
|
|
find = 0;
|
|
|
|
if ((SInt16) (index - 1) < 0) {
|
|
|
|
snprintf(err, sizeof(err), "[Illegal string index #%d in list '%s' (%d)]", (SInt16) (index - 1), rlist[scan].name, rsrcid);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (find <= (index - 1)) {
|
|
|
|
if (!rlist[scan].strings[find]) {
|
|
|
|
snprintf(err, sizeof(err), "[String #%d not found in resource '%s' (%d)]", (SInt16) (index - 1), rlist[scan].name, rsrcid);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if (find == (index - 1)) {
|
|
|
|
return rlist[scan].strings[find];
|
|
|
|
} else {
|
|
|
|
find++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (scan++ < MaxRes);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-11 22:29:53 +00:00
|
|
|
void Res_Cleanup(void) {
|
2022-10-11 02:18:42 +00:00
|
|
|
}
|