3 * Break a Viewlogic metafile into a million little pieces
6 * Copyright (C) 1998-2010 Mike Jarabek
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
38 int main(int argc
, char **argv
)
41 FILE *megafile
, *output
;
44 char buffer
[127]; /* buffer for megafile index entries */
45 char output_name
[127];
51 fprintf( stderr
, "Usage:\n %s <megafile>\n\n"
52 "Where <megafile> is the name of a viewlogic megafile\n"
53 "whithout any extensions. The file <megafile>.lib and \n"
54 "<megafile>.tbl must exist in the same directory\n",
64 megafile
= fopen(name
, "r");
66 if( megafile
== NULL
)
68 fprintf(stderr
, "Error: unable to open magefile `%s' for reading\n",
73 /* create a subdir to hold the exploded files */
78 mkdir(argv
[1], 0777); /* try to be friendly */
81 /* read each table entry and extract the file from the megafile */
82 while(!feof(megafile
))
84 if(fread(buffer
, RECLEN
, 1, megafile
) == 0) break; /* end of file? */
86 /* null terminate buffer */
89 /*printf("%s\n",buffer);*/
91 /* extract the name and size from the entry */
92 sscanf(buffer
,"%s %d",name
,&len
);
94 printf("%s:%d\n",name
,len
);
96 /* slurp in the required data and spit it out into the
100 /* allocate some memory to hold the file */
101 extracted_file
= malloc(len
);
103 fread(extracted_file
, len
, 1, megafile
);
105 /* open up a file to dump in */
106 strcpy(output_name
, argv
[1]);
107 strcat(output_name
, "/");
108 strcat(output_name
, name
);
109 output
= fopen(output_name
,"wb");
113 fprintf(stderr
,"Error: unable to open file `%s' for writing\n",
119 /* dump to the file */
120 fwrite(extracted_file
, len
, 1, output
);