8 #define ADS ":::AGSpack " VERSION "by rofl0r:::"
10 __attribute__((noreturn
))
11 void usage(char *argv0
) {
12 dprintf(2, ADS
"\nusage:\n%s directory target-pack\n\n", argv0
);
16 int main(int argc
, char** argv
) {
17 if(argc
< 3) usage(argv
[0]);
23 snprintf(fnbuf
, sizeof(fnbuf
), "%s/%s", dir
, "agspack.info");
24 if(!(fp
= fopen(fnbuf
, "r"))) {
25 dprintf(2, "couldnt open %s\n", fnbuf
);
29 struct AgsFile ags_b
, *ags
= &ags_b
;
30 AgsFile_init(ags
, pack
);
31 AgsFile_setSourceDir(ags
, dir
);
32 AgsFile_setDataFileCount(ags
, 1); //TODO
33 if(!AgsFile_setDataFile(ags
, 0, "AGSPACKv" VERSION
)) {
34 dprintf(2, "error: packname exceeds 20 chars");
37 while(fgets(line
, sizeof(line
), fp
)) {
38 size_t l
= strlen(line
);
39 if(l
) line
[l
- 1] = 0;
40 char *p
= strchr(line
, '=');
44 else if(strcmp(line
, "agsversion") == 0)
45 AgsFile_setVersion(ags
, atoi(p
));
46 else if(strcmp(line
, "filecount") == 0)
47 AgsFile_setFileCount(ags
, atoi(p
));
48 else if(isdigit(*line
))
49 if(!AgsFile_setFile(ags
, index
++, p
)) {
55 size_t l
= AgsFile_getFileCount(ags
);
56 for(index
= 0; index
< l
; index
++) {
57 // TODO read from input file, but it seems to be all 0 for some games.
58 AgsFile_setFileNumber(ags
, index
, 0);
60 int ret
= AgsFile_write(ags
);
61 if(!ret
) perror("write");