Changeset 550 for abuse/trunk
- Timestamp:
- Apr 29, 2011, 12:24:47 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/tool/abuse-tool.cpp
r548 r550 30 30 CMD_PUT, 31 31 CMD_RENAME, 32 CMD_TYPE, 32 33 CMD_GETPCX, 33 34 CMD_PUTPCX, … … 48 49 : !strcmp(argv[2], "move") ? CMD_MOVE 49 50 : !strcmp(argv[2], "rename") ? CMD_RENAME 51 : !strcmp(argv[2], "type") ? CMD_TYPE 50 52 : !strcmp(argv[2], "getpcx") ? CMD_GETPCX 51 53 : !strcmp(argv[2], "putpcx") ? CMD_PUTPCX … … 78 80 break; 79 81 case CMD_RENAME: 82 minargc = 5; 83 break; 84 case CMD_TYPE: 80 85 minargc = 5; 81 86 break; … … 218 223 dir.entries[dst] = tmp; 219 224 } 220 else if (cmd == CMD_RENAME )225 else if (cmd == CMD_RENAME || cmd == CMD_TYPE) 221 226 { 222 227 int id = atoi(argv[3]); … … 229 234 230 235 dir.FullyLoad(&fp); 231 dir.entries[id]->name = argv[4]; 236 if (cmd == CMD_RENAME) 237 dir.entries[id]->name = argv[4]; 238 else 239 dir.entries[id]->type = (uint8_t)atoi(argv[4]); 232 240 } 233 241 else if (cmd == CMD_DEL) … … 246 254 247 255 dir.FullyLoad(&fp); 256 } 257 else if (cmd == CMD_PUT || cmd == CMD_PUTPCX) 258 { 259 int id = atoi(argv[3]); 260 uint8_t type = atoi(argv[4]); 261 262 if (id == -1) 263 id = dir.total; 264 265 if (id < 0 || id > dir.total) 266 { 267 fprintf(stderr, "abuse-tool: id %i out of range\n", id); 268 return EXIT_FAILURE; 269 } 270 271 dir.FullyLoad(&fp); 272 dir.total++; 273 dir.entries = (spec_entry **)realloc(dir.entries, 274 dir.total * sizeof(spec_entry *)); 275 for (int i = id + 1; i < dir.total; i++) 276 dir.entries[i] = dir.entries[i - 1]; 277 278 char *name = strrchr(argv[5], '/'); 279 if (!name) 280 name = argv[5]; 281 282 uint8_t *data; 283 size_t len; 284 285 if (cmd == CMD_PUT) 286 { 287 jFILE fp2(argv[5], "rb"); 288 if (fp2.open_failure()) 289 { 290 fprintf(stderr, "abuse-tool: cannot open %s\n", argv[5]); 291 return EXIT_FAILURE; 292 } 293 len = fp2.file_size(); 294 data = (uint8_t *)malloc(len); 295 fp2.read(data, len); 296 } 297 else 298 { 299 palette *pal = NULL; 300 image *im = read_PCX(argv[5], pal); 301 if (!im) 302 { 303 fprintf(stderr, "abuse-tool: cannot open %s\n", argv[5]); 304 return EXIT_FAILURE; 305 } 306 vec2i size = im->Size(); 307 len = 2 * sizeof(uint16_t) + size.x * size.y; 308 data = (uint8_t *)malloc(len); 309 uint16_t x = lltl((uint16_t)size.x); 310 uint16_t y = lltl((uint16_t)size.y); 311 memcpy(data, &x, sizeof(x)); 312 memcpy(data + 2, &y, sizeof(y)); 313 memcpy(data + 4, im->scan_line(0), size.x * size.y); 314 } 315 dir.entries[id] = new spec_entry(type, name, NULL, len, 0); 316 dir.entries[id]->data = data; 248 317 } 249 318 else … … 266 335 { 267 336 fprintf(stderr, "%s", 268 "Usage: abuse-tool <spec_file> <command> [args...]\n" 269 "List of available commands:\n" 270 " list list the contents of a SPEC file\n" 271 " get <id> dump entry <id> to stdout\n" 272 " getpcx <id> dump PCX image <id> to stdout\n" 273 " del <id> delete entry <id>\n" 274 " rename <id> <name> rename entry <id> to <name>\n" 275 " move <id1> <id2> move entry <id1> to <id2>\n"); 337 "Usage: abuse-tool <spec_file> <command> [args...]\n" 338 "\n" 339 "abuse-tool is a low-level tool to edit Abuse SPEC (.spe) files.\n" 340 "\n" 341 "Commands:\n" 342 " list list the contents of a SPEC file\n" 343 " get <id> dump entry <id> to stdout\n" 344 " getpcx <id> dump PCX image <id> to stdout\n" 345 " put <id> <type> <name> insert file <name> of type <type> at position\n" 346 " <id>\n" 347 " putpcx <id> <type> <name> insert PCX image <name> of type <type> at\n" 348 " position <id>\n" 349 " rename <id> <name> rename entry <id> to <name>\n" 350 " type <id> <type> set entry <id> type to <type>\n" 351 " move <id1> <id2> move entry <id1> to position <id2>\n" 352 " del <id> delete entry <id>\n" 353 "See the abuse-tool(6) manual page for more information.\n"); 276 354 } 277 355
Note: See TracChangeset
for help on using the changeset viewer.