6 // Bootstrap for themes.
8 // Concatenates all the resources and a table of contents
9 // into a data file that must be converted to an object with objcopy.
10 // The user must then pass the name of the destination symbol
11 // _binary_destname_start
12 // to BC_Theme::set_data to set the image table.
15 // Usage: bootstrap <destname> <resource>...
20 void append_contents(char *path
,
28 for(i
= strlen(path
) - 1;
29 i
> 0 && path
[i
] && path
[i
] != '/';
33 if(path
[i
] == '/') i
++;
35 for(j
= 0; path
[i
] != 0; i
++, j
++)
40 strcpy(buffer
+ *buffer_size
, string
);
42 *buffer_size
+= strlen(string
) + 1;
44 *(int*)(buffer
+ *buffer_size
) = data_offset
;
45 *buffer_size
+= sizeof(int);
48 int main(int argc
, char *argv
[])
53 char *contents_buffer
;
54 int contents_size
= 0;
59 char system_command
[1024];
63 fprintf(stderr
, "Need 2 arguments you MOR-ON!\n");
68 // Make object filename
69 strcpy(temp_path
, argv
[1]);
71 if(!(dest
= fopen(temp_path
, "w")))
73 fprintf(stderr
, "Couldn't open dest file %s. %s\n",
79 if(!(data_buffer
= malloc(0x1000000)))
81 fprintf(stderr
, "Not enough memory to allocate data buffer.\n");
85 if(!(contents_buffer
= malloc(0x100000)))
87 fprintf(stderr
, "Not enough memory to allocate contents buffer.\n");
91 // Leave space for offset to data
92 contents_size
= sizeof(int);
94 // Read through all the resources, concatenate to dest file,
95 // and record the contents.
96 for(i
= 2; i
< argc
; i
++)
99 if(!(src
= fopen(path
, "r")))
101 fprintf(stderr
, "%s while opening %s\n", strerror(errno
), path
);
107 fseek(src
, 0, SEEK_END
);
109 fseek(src
, 0, SEEK_SET
);
111 data_offset
= data_size
;
113 // Write size of image in data buffer
114 *(data_buffer
+ data_size
) = (size
& 0xff000000) >> 24;
116 *(data_buffer
+ data_size
) = (size
& 0xff0000) >> 16;
118 *(data_buffer
+ data_size
) = (size
& 0xff00) >> 8;
120 *(data_buffer
+ data_size
) = size
& 0xff;
123 fread(data_buffer
+ data_size
, 1, size
, src
);
128 append_contents(path
,
135 // Finish off size of contents
136 *(int*)(contents_buffer
) = contents_size
;
138 fwrite(contents_buffer
, 1, contents_size
, dest
);
140 fwrite(data_buffer
, 1, data_size
, dest
);