source: abuse/trunk/src/tool/abuse-tool.cpp @ 540

Last change on this file since 540 was 540, checked in by Sam Hocevar, 11 years ago

tool: get rid of the specfile additions and implement a general purpose
SPEC file edition tool.

  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1//
2// Abuse Tool - package manager for Abuse format
3//
4// Copyright: (c) 2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#include "config.h"
12
13#include <cstring>
14#include <cstdio>
15
16#include "common.h"
17#include "specs.h"
18#include "image.h"
19
20static void Usage();
21
22int main(int argc, char *argv[])
23{
24    if (argc < 3)
25    {
26        Usage();
27        return EXIT_FAILURE;
28    }
29
30    char *file = argv[1];
31    char *cmd = argv[2];
32
33    if (!strcmp(cmd, "list"))
34    {
35        jFILE fp(file, "rb");
36        if (fp.open_failure())
37        {
38            fprintf(stderr, "ERROR - could not open %s\n", file);
39            return EXIT_FAILURE;
40        }
41
42        printf("   id  type     size  name & information\n");
43        printf(" ----  ----  -------  ----------------------------\n");
44
45        spec_directory dir(&fp);
46        for (int i = 0; i < dir.total; i++)
47        {
48            spec_entry *se = dir.entries[i];
49
50            /* Print basic information */
51            printf("% 5i   % 3i % 8i  %s",
52                   i, se->type, (int)se->size, se->name);
53
54            /* Is there anything special to say? */
55            switch (se->type)
56            {
57            case SPEC_IMAGE:
58            case SPEC_FORETILE:
59            case SPEC_BACKTILE:
60            case SPEC_CHARACTER:
61            case SPEC_CHARACTER2:
62              {
63                image *im = new image(&fp, se);
64                printf(" (%i x %i pixels)", im->Size().x, im->Size().y);
65                delete im;
66                break;
67              }
68            case SPEC_PALETTE:
69              {
70                palette *pal = new palette(se, &fp);
71                printf(" (%i colors)", pal->pal_size());
72                delete pal;
73                break;
74              }
75            }
76
77            /* Finish line */
78            putchar('\n');
79        }
80    }
81    /* else if (...) */
82    else
83    {
84        fprintf(stderr, "abuse-tool: unknown command `%s'\n", cmd);
85    }
86
87    return EXIT_SUCCESS;
88}
89
90static void Usage()
91{
92    fprintf(stderr, "%s",
93            "Usage: abuse-tool <spec_file> <command> [args...]\n"
94            "List of available commands:\n"
95            "  list -- list the contents of a SPEC file\n");
96}
97
Note: See TracBrowser for help on using the repository browser.