6 // Bootstrap for themes.
8 // Concatenate the resources onto the end of the target. Then write a
11 // Usage: bootstrap <target> <resource> * n
13 // The table of contents contains simply the filenames of the resources
16 // Initial startup with static resources:
17 // F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND
18 // 040 0 14623 14602 12 0 107512 28632 - S pts/2 0:00 ci
20 // -rwxr-xr-x 1 root root 736712 Dec 8 15:59 defaulttheme.plugin
23 // Initial startup with concatenated resources:
24 // F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND
25 // 040 0 23653 23644 12 0 111512 27520 - S pts/0 0:00 ci
27 // -rwxr-xr-x 1 root root 860924 Dec 8 22:33 defaulttheme.plugin
29 // At least the compile time is less.
32 void append_contents(char *path
,
41 for(i
= strlen(path
) - 1;
42 i
> 0 && path
[i
] && path
[i
] != '/';
46 if(path
[i
] == '/') i
++;
48 for(j
= 0; path
[i
] != 0; i
++, j
++)
53 strcpy(buffer
+ *buffer_size
, string
);
55 *buffer_size
+= strlen(string
) + 1;
57 *(int*)(buffer
+ *buffer_size
) = data_offset
;
58 *buffer_size
+= sizeof(int);
61 int main(int argc
, char *argv
[])
67 char *contents_buffer
;
68 int contents_size
= 0;
76 fprintf(stderr
, "Need 2 arguments you MOR-ON!\n");
82 if(!(dest
= fopen(argv
[1], "r")))
84 fprintf(stderr
, "While opening %s: %s\n", argv
[1], strerror(errno
));
89 fseek(dest
, 0, SEEK_END
);
90 dest_size
= ftell(dest
);
94 dest
= fopen(argv
[1], "a+");
95 total_resources
= argc
- 2;
97 if(!(data_buffer
= malloc(0x1000000)))
99 fprintf(stderr
, "Not enough memory to allocate data buffer.\n");
103 if(!(contents_buffer
= malloc(0x100000)))
105 fprintf(stderr
, "Not enough memory to allocate contents buffer.\n");
110 for(i
= 0; i
< total_resources
; i
++)
112 char *path
= argv
[2 + i
];
113 if(!(src
= fopen(path
, "r")))
115 fprintf(stderr
, "%s while opening %s\n", strerror(errno
), path
);
120 int size
, data_offset
;
121 fseek(src
, 0, SEEK_END
);
123 fseek(src
, 0, SEEK_SET
);
125 data_offset
= data_size
;
126 // Write size of image in data buffer
127 *(data_buffer
+ data_size
) = (size
& 0xff000000) >> 24;
129 *(data_buffer
+ data_size
) = (size
& 0xff0000) >> 16;
131 *(data_buffer
+ data_size
) = (size
& 0xff00) >> 8;
133 *(data_buffer
+ data_size
) = size
& 0xff;
136 fread(data_buffer
+ data_size
, 1, size
, src
);
141 append_contents(path
, data_offset
, dest_size
, contents_buffer
, &contents_size
);
145 fwrite(data_buffer
, 1, data_size
, dest
);
146 contents_offset
= ftell(dest
);
147 *(int*)(contents_buffer
+ contents_size
) = dest_size
;
148 contents_size
+= sizeof(int);
149 *(int*)(contents_buffer
+ contents_size
) = contents_offset
;
150 contents_size
+= sizeof(int);
151 fwrite(contents_buffer
, 1, contents_size
, dest
);