- Timestamp:
- Apr 23, 2011, 12:48:59 AM (12 years ago)
- Location:
- abuse/trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/imlib/specs.cpp
r529 r539 18 18 #include <math.h> 19 19 #include <unistd.h> 20 #if (defined(__MACH__) || !defined(__APPLE__)) 21 # include <sys/types.h> 22 # include <sys/stat.h> 23 #endif 20 #include <sys/types.h> 21 #include <sys/stat.h> 24 22 25 23 #include "common.h" … … 27 25 #include "image.h" 28 26 #include "palette.h" 27 #include "pcxread.h" 29 28 #include "specs.h" 30 29 #include "dprint.h" … … 964 963 } 965 964 965 void spec_directory::extract(char const *name) 966 { 967 jFILE fp(name, "rb"); 968 if (fp.open_failure()) 969 { 970 fprintf(stderr, "Spec: ERROR - could not open %s\n", name); 971 return; 972 } 973 974 spec_directory dir(&fp); 975 if (dir.total <= 0) 976 { 977 fprintf(stderr, "Spec: ERROR - no signature or no data in %s\n", name); 978 return; 979 } 980 981 char const *out = "SPEC.DIR"; 982 mkdir(out, S_IRUSR | S_IWUSR | S_IXUSR); 983 if (chdir(out)) 984 { 985 fprintf(stderr, "Spec: ERROR - could not create or cd to %s\n", out); 986 return; 987 } 988 989 palette *pal = NULL; 990 991 for (int i = 0; i < dir.total; i++) 992 { 993 spec_entry *se = dir.entries[i]; 994 995 FILE *fp2 = fopen(se->name, "wb"); 996 if (!fp2) 997 { 998 fprintf(stderr, "Spec: ERROR - could not write to %s\n", se->name); 999 continue; 1000 } 1001 1002 fp.seek(se->offset, SEEK_SET); 1003 uint8_t buf[1024]; 1004 size_t todo = se->size; 1005 while (todo > 0) 1006 { 1007 fp.read(buf, Min(todo, 1024)); 1008 fwrite(buf, Min(todo, 1024), 1, fp2); 1009 todo -= Min(todo, 1024); 1010 } 1011 fclose(fp2); 1012 1013 fprintf(stderr, "Spec: %s (type %i): %i bytes\n", 1014 se->name, se->type, (int)se->size); 1015 1016 /* If it's a palette, keep it */ 1017 if (!pal && se->type == SPEC_PALETTE) 1018 pal = new palette(se, &fp); 1019 } 1020 1021 /* If we have a palette, output all images */ 1022 for (int i = 0; pal && i < dir.total; i++) 1023 { 1024 char buf[1024]; 1025 spec_entry *se = dir.entries[i]; 1026 1027 switch (se->type) 1028 { 1029 case SPEC_IMAGE: 1030 case SPEC_FORETILE: 1031 case SPEC_BACKTILE: 1032 case SPEC_CHARACTER: 1033 case SPEC_CHARACTER2: 1034 sprintf(buf, "%s-export.pcx", se->name); 1035 image *im = new image(&fp, se); 1036 write_PCX(im, pal, buf); 1037 delete im; 1038 fprintf(stderr, "Spec: %s is an image\n", buf); 1039 break; 1040 } 1041 } 1042 1043 /* Clean up */ 1044 delete pal; 1045 } 1046 966 1047 void note_open_fd(int fd, char const *str) 967 1048 { -
abuse/trunk/src/imlib/specs.h
r534 r539 22 22 extern char const *spec_types[]; 23 23 24 #define SPEC_INVALID_TYPE 0 25 #define SPEC_COLOR_TABLE 1 26 #define SPEC_PALETTE 2 27 #define SPEC_IMAGE 4 28 #define SPEC_FORETILE 5 29 #define SPEC_BACKTILE 6 30 #define SPEC_CHARACTER 7 31 #define SPEC_MORPH_POINTS_8 8 32 #define SPEC_MORPH_POINTS_16 9 33 #define SPEC_GRUE_OBJS 10 34 #define SPEC_EXTERN_SFX 11 35 #define SPEC_DMX_MUS 12 36 #define SPEC_PATCHED_MORPH 13 37 #define SPEC_NORMAL_FILE 14 38 #define SPEC_COMPRESS1_FILE 15 39 #define SPEC_VECTOR_IMAGE 16 40 #define SPEC_LIGHT_LIST 17 41 #define SPEC_GRUE_FGMAP 18 42 #define SPEC_GRUE_BGMAP 19 43 #define SPEC_DATA_ARRAY 20 44 #define SPEC_CHARACTER2 21 45 #define SPEC_PARTICLE 22 46 #define SPEC_EXTERNAL_LCACHE 23 47 24 enum 25 { 26 SPEC_INVALID_TYPE = 0, 27 SPEC_COLOR_TABLE, 28 SPEC_PALETTE, 29 SPEC_, /* Unused */ 30 SPEC_IMAGE, 31 SPEC_FORETILE, 32 SPEC_BACKTILE, 33 SPEC_CHARACTER, 34 SPEC_MORPH_POINTS_8, 35 SPEC_MORPH_POINTS_16, 36 SPEC_GRUE_OBJS, 37 SPEC_EXTERN_SFX, 38 SPEC_DMX_MUS, 39 SPEC_PATCHED_MORPH, 40 SPEC_NORMAL_FILE, 41 SPEC_COMPRESS1_FILE, 42 SPEC_VECTOR_IMAGE, 43 SPEC_LIGHT_LIST, 44 SPEC_GRUE_FGMAP, 45 SPEC_GRUE_BGMAP, 46 SPEC_DATA_ARRAY, 47 SPEC_CHARACTER2, 48 SPEC_PARTICLE, 49 SPEC_EXTERNAL_LCACHE, 50 }; 48 51 49 52 #define SPEC_SIGNATURE "SPEC1.0" … … 56 59 #define SPEC_SEARCH_INSIDE_ONLY 3 57 60 58 /* file specs 59 8 signature 60 2 number entries 61 [entries] 62 1 entry type 63 1 entry name length 64 X entry name (with null terminator) 65 1 flags 66 if (flags&LINK) 67 1 link filename length 68 X link filename 69 else 70 4 data size 71 4 offset 72 */ 61 /* struct spec_header 62 * { 63 * char signature[8]; 64 * uint16_t entries_count; 65 * struct entry 66 * { 67 * uint8_t type; 68 * uint8_t name_length; 69 * char name[name_length]; 70 * uint8_t flags; 71 * if (flags & LINK) 72 * { 73 * uint8_t filename_length; 74 * char filename[filename_length]; 75 * } 76 * else 77 * { 78 * uint32_t data_size; 79 * uint32_t offset; 80 * } 81 * } entries[entries_count]; 82 * } 83 */ 73 84 74 85 void set_spec_main_file(char const *filename, int search_order=SPEC_SEARCH_OUTSIDE_INSIDE); … … 196 207 void delete_entries(); // if the directory was created by hand instead of by file 197 208 ~spec_directory(); 209 210 static void extract(char const *name); 198 211 } ; 199 212 -
abuse/trunk/src/sdlport/setup.cpp
r508 r539 336 336 } 337 337 } 338 else if (ii + 1 < argc && !strcasecmp(argv[ii], "-export")) 339 { 340 spec_directory::extract(argv[++ii]); 341 exit(0); 342 } 338 343 else if( !strcasecmp( argv[ii], "-h" ) || !strcasecmp( argv[ii], "--help" ) ) 339 344 {
Note: See TracChangeset
for help on using the changeset viewer.