/* Read a resource entry, returns 0 when all resources are read */
static int
read_resource_entry (windres_bfd *wrbfd, rc_uint_type *off, rc_uint_type omax)
{
    rc_res_id type;
    rc_res_id name;
    rc_res_res_info resinfo;
    res_hdr reshdr;
    void *buff;

    rc_res_resource *r;
    struct bin_res_info l;

    off[0] = (off[0] + 3) & ~3;

    /* Read header */
    if ((off[0] + 8) > omax)
        return 0;
    read_res_data_hdr (wrbfd, off, omax, &reshdr);

    /* read resource type */
    read_res_id (wrbfd, off, omax, &type);
    /* read resource id */
    read_res_id (wrbfd, off, omax, &name);

    off[0] = (off[0] + 3) & ~3;

    /* Read additional resource header */
    read_res_data (wrbfd, off, omax, &l, BIN_RES_INFO_SIZE);
    resinfo.version = windres_get_32 (wrbfd, l.version, 4);
    resinfo.memflags = windres_get_16 (wrbfd, l.memflags, 2);
    resinfo.language = windres_get_16 (wrbfd, l.language, 2);
    /* resinfo.version2 = windres_get_32 (wrbfd, l.version2, 4); */
    resinfo.characteristics = windres_get_32 (wrbfd, l.characteristics, 4);

    off[0] = (off[0] + 3) & ~3;

    /* Allocate buffer for data */
    buff = res_alloc (reshdr.data_size);
    /* Read data */
    read_res_data (wrbfd, off, omax, buff, reshdr.data_size);
    /* Convert binary data to resource */
    r = bin_to_res (wrbfd, type, buff, reshdr.data_size);
    r->res_info = resinfo;
    /* Add resource to resource directory */
    res_add_resource (r, &type, &name, resinfo.language, 0);

    return 1;
}
Example #2
0
static resource_t* res_parse_cpuinfo(FILE *fp)
{
    struct cpuinfo {
        int processor;
        int physical;
        int siblings;
        int core_id;
        int num_cores;
    } info;
    char buf[BUFSIZ];
    resource_t *root = NULL;
    int i;

    memset(&info, 0, sizeof(info));

    while (fgets(buf, sizeof buf, fp)) {
        if (buf[0] == '\n') {
            resource_t *socket = NULL, *core = NULL, *proc = NULL;

            if (!root) {
                root = res_add_resource(NULL, Machine, 0, 0, 0, 0);
            }
            for (i = 0; i < root->num_children; ++i) {
                if (root->children[i]->physical == info.physical) {
                    socket = root->children[i];
                    break;
                }
            }
            if (socket == NULL) {
                socket = res_add_resource(root, Socket, 1, info.physical, info.physical, 0);
            }
            for (i = 0; i < socket->num_children; ++i) {
                if (socket->children[i]->physical == info.core_id) {
                    core = socket->children[i];
                    break;
                }
            }
            if (core == NULL) {
                core = res_add_resource(socket, Core, 2, info.core_id, info.core_id, 0);
            }
            for (i = 0; i < core->num_children; ++i) {
                if (core->children[i]->physical == info.processor) {
                    proc = core->children[i];
                    break;
                }
            }
            if (proc) {
                res_warn("%s: Duplicate processor %d\n", __func__, info.processor);
            } else {
                proc = res_add_resource(core, Proc, 3, info.processor, info.processor, 0);
            }
        } else {
            char* save = NULL;
            char* key = strtok_r(buf, ":", &save);
            char* val = strtok_r(NULL, "", &save);
            int* dest = NULL;

            if (EQ(key, "processor")) dest = &info.processor;
            else if (EQ(key, "physical id")) dest = &info.physical;
            else if (EQ(key, "siblings")) dest = &info.siblings;
            else if (EQ(key, "core id")) dest = &info.core_id;
            else if (EQ(key, "cpu cores")) dest = &info.num_cores;
            if (dest) {
                sscanf(val, " %d", dest);
            }
        }
    }
    if (root) {
        res_fix_logical(root);
    }
    return root;
}