Changeset 547
- Timestamp:
- Apr 28, 2011, 1:56:27 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/tool/abuse-tool.cpp
r543 r547 17 17 #include "specs.h" 18 18 #include "image.h" 19 #include "pcxread.h" 19 20 20 21 static void Usage(); … … 99 100 100 101 /* Open the SPEC file */ 102 char tmpfile[4096]; 101 103 char const *file = argv[1]; 104 snprintf(tmpfile, 4096, "%s.tmp", file); 102 105 103 106 jFILE fp(file, mode); … … 175 178 todo -= step; 176 179 } 180 return EXIT_SUCCESS; 181 } 182 183 if (cmd == CMD_GETPCX) 184 { 185 palette *pal; 186 int imgid = atoi(argv[3]); 187 int palid = argc > 4 ? atoi(argv[4]) : -1; 188 189 for (int i = 0; palid == -1 && i < dir.total; i++) 190 if (dir.entries[i]->type == SPEC_PALETTE) 191 palid = i; 192 193 if (palid == -1) 194 pal = new palette(256); 195 else 196 pal = new palette(dir.entries[palid], &fp); 197 198 image *im = new image(&fp, dir.entries[imgid]); 199 write_PCX(im, pal, "/dev/stdout"); 200 delete im; 201 delete pal; 202 return EXIT_SUCCESS; 203 } 204 205 if (cmd == CMD_MOVE) 206 { 207 int src = atoi(argv[3]); 208 int dst = atoi(argv[4]); 209 210 if (src < 0 || dst < 0 || src >= dir.total || dst >= dir.total) 211 { 212 fprintf(stderr, "abuse-tool: ids %i/%i out of range\n", src, dst); 213 return EXIT_FAILURE; 214 } 215 216 dir.FullyLoad(&fp); 217 218 spec_entry *tmp = dir.entries[src]; 219 for (int d = src < dst ? 1 : -1; src != dst; src += d) 220 dir.entries[src] = dir.entries[src + d]; 221 dir.entries[dst] = tmp; 222 223 dir.calc_offsets(); 224 fp.seek(0, SEEK_SET); // FIXME: create a new file 225 dir.write(&fp); 226 for (int i = 0; i < dir.total; i++) 227 fp.write(dir.entries[i]->data, dir.entries[i]->size); 177 228 } 178 229 … … 185 236 "Usage: abuse-tool <spec_file> <command> [args...]\n" 186 237 "List of available commands:\n" 187 " list list the contents of a SPEC file\n" 188 " get <id> dump entry <id> to stdout\n"); 238 " list list the contents of a SPEC file\n" 239 " get <id> dump entry <id> to stdout\n" 240 " getpcx <id> dump PCX image <id> to stdout\n" 241 " move <i1> <i2> move entry <i1> to <i2>\n"); 189 242 } 190 243
Note: See TracChangeset
for help on using the changeset viewer.