[Extractor-gtk-cvslog] SF.net SVN: extractor-gtk:[105] trunk/extractor/solidsub.c
Extract files from unusual archive formats
Brought to you by:
someone-guy
|
From: <som...@us...> - 2008-08-22 16:11:43
|
Revision: 105
http://extractor-gtk.svn.sourceforge.net/extractor-gtk/?rev=105&view=rev
Author: someone-guy
Date: 2008-08-22 16:11:41 +0000 (Fri, 22 Aug 2008)
Log Message:
-----------
Add pbm header
Modified Paths:
--------------
trunk/extractor/solidsub.c
Modified: trunk/extractor/solidsub.c
===================================================================
--- trunk/extractor/solidsub.c 2008-08-22 16:11:25 UTC (rev 104)
+++ trunk/extractor/solidsub.c 2008-08-22 16:11:41 UTC (rev 105)
@@ -26,9 +26,10 @@
while (!feof(in) && cnt < MAX_FILES) {
uint32_t size = read_le32(in);
if (!size) continue;
- add_entry_nr(&list, cnt, namenr, img ? "img" : "txt");
+ add_entry_nr(&list, cnt, namenr, img ? "pbm" : "txt");
list[cnt].start = ftell(in);
list[cnt].len = size;
+ list[cnt].priv = (void *)(intptr_t)img;
cnt++;
fseek(in, size, SEEK_CUR);
if (img) namenr++;
@@ -37,6 +38,38 @@
return list;
}
+static const char pbm_string[] =
+ "P4\n"
+ "# PBM header added by extractor, original data follows the third newline\n"
+ "48 %i\n";
+
+static int extract_file(FILE *in, const file_t *file, FILE *out) {
+ int len, len2;
+ // not an image file
+ if (!file->priv) return default_extract_file(in, file, out);
+ len = fprintf(out, pbm_string, (int)file->len / 6);
+ if (len <= 0) return len;
+ fseek(in, file->start, SEEK_SET);
+ len2 = fcopy(in, out, file->len);
+ if (len2 <= 0) return len2;
+ return len + len2;
+}
+
+static int extract_mem(FILE *in, const file_t *file, uint8_t *out, int size) {
+ int len, len2;
+ // not an image file
+ if (!file->priv) return default_extract_mem(in, file, out, size);
+ len = snprintf(out, size, pbm_string, (int)file->len / 6);
+ if (len >= size) return size;
+ out += len;
+ size -= len;
+ if (size > file->len) size = file->len;
+ fseek(in, file->start, SEEK_SET);
+ len2 = fread(out, 1, size, in);
+ if (len2 <= 0) return len2;
+ return len + len2;
+}
+
const fmt_desc_t solidsub_fmt = {
"solidsub",
"MetalGear Solid: TS subtitles",
@@ -45,6 +78,6 @@
check_file,
get_list,
default_free_list,
- default_extract_file,
- default_extract_mem,
+ extract_file,
+ extract_mem,
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|