summaryrefslogtreecommitdiff
path: root/command_line/CmdLine/Src/MacEmul/ResourceStrings.c
blob: bdf3735863d7e05dfa041ccfcc05d91be7777dd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "mwcc_decomp.h"

typedef struct {
    const char *name;
    SInt16 rsrcid;
    const char **strings;
} Res;

static Res rlist[16];

void Res_Initialize() {
    memset(rlist, 0, sizeof(rlist));
}

int Res_AddResource(const char *name, SInt16 rsrcid, const char **strings) {
    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;
}

void Res_Cleanup() {
}