File: makeobj.cc

package info (click to toggle)
simutrans 100.0%2Bds1-4
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 9,776 kB
  • ctags: 9,485
  • sloc: cpp: 72,459; ansic: 5,646; makefile: 450
file content (156 lines) | stat: -rw-r--r-- 3,877 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "../dataobj/tabfile.h"
#include "../simtypes.h"
#include "../simversion.h"
#include "../utils/cstring_t.h"
#include "../besch/writer/obj_pak_exception.h"
#include "../besch/writer/root_writer.h"
#include "../besch/writer/image_writer.h"



extern "C" {

// dummy definition, since we print to screen anyway
bool dr_fatal_notify(const char* msg, int choices)
{
	return false;
}

}


int main(int argc, char* argv[])
{
	argv++, argc--;

	init_logging( "stderr", true, true );

	if (argc && !STRICMP(argv[0], "quiet")) {
		argv++, argc--;
	} else {
		puts(
			"\nMakeobj version " MAKEOBJ_VERSION " for simutrans " VERSION_NUMBER " and higher\n"
			"(c) 2002-2006 V. Meyer , Hj. Malthaner, M. Pristovsek (markus@pristovsek.de)\n"
		);
	}

	if (argc && !STRICMP(argv[0], "capabilities")) {
		argv++, argc--;
		root_writer_t::instance()->capabilites();
		return 0;
	}

	if (argc && !STRICMP(argv[0], "pak")) {
		argv++, argc--;

		try {
			const char* dest;
			if (argc) {
				dest = argv[0];
				argv++, argc--;
			} else {
				dest = "./";
			}
			root_writer_t::instance()->write(dest, argc, argv);
		}
		catch (const obj_pak_exception_t& e) {
			fprintf(stderr, "ERROR IN CLASS %s: %s\n", e.get_class(), e.get_info());
			return 1;
		}
		return 0;
	}

	if (argc && STRNICMP(argv[0], "pak", 3) == 0) {
		int img_size = atoi(argv[0] + 3);

		if (img_size >= 16 && img_size < 256) {
			printf("Image size is set to %dx%d\n", img_size, img_size);

			image_writer_t::set_img_size(img_size);

			argv++, argc--;

			try {
				const char* dest;
				if (argc) {
					dest = argv[0];
					argv++, argc--;
				} else {
					dest = "./";
				}
				root_writer_t::instance()->write(dest, argc, argv);
			}
			catch (const obj_pak_exception_t& e) {
				fprintf(stderr, "ERROR IN CLASS %s: %s\n", e.get_class(), e.get_info());
				return 1;
			}

			// image_writer_t::dump_special_histogramm();
			return 0;
		}
	}

	if (argc > 1) {
		if (!STRICMP(argv[0], "dump")) {
			argv++, argc--;
			root_writer_t::instance()->dump(argc, argv);
			return 0;
		}
		if (!STRICMP(argv[0], "list")) {
			argv++, argc--;
			root_writer_t::instance()->list(argc, argv);
			return 0;
		}
		if (!STRICMP(argv[0], "extract")) {
			argv++, argc--;
			root_writer_t::instance()->uncopy(argv[0]);
			return 0;
		}
		if (!STRICMP(argv[0], "merge")) {
			argv++, argc--;
			try {
				const char* dest = argv[0];
				argv++, argc--;
				root_writer_t::instance()->copy(dest, argc, argv);
			}
			catch (const obj_pak_exception_t& e) {
				fprintf(stderr, "ERROR IN CLASS %s: %s\n", e.get_class(), e.get_info());
				return 1;
			}
			return 0;
		}
	}

	puts(
		"\n   Usage:\n"
		"      MakeObj CAPABILITIES\n"
		"         Gives the list of objects, this program can read\n"
		"      MakeObj PAK <pak file> <dat file(s)>\n"
		"         Creates a ready to use pak file for Simutrans from the dat files\n"
		"      MakeObj pak128 <pak file> <dat file(s)>\n"
		"         Creates a special pak file for with 128x128 images\n"
		"         Should work with PAK16 up to PAK255 but only 64 and 128 are tested\n"
		"      MakeObj LIST <pak file(s)>\n"
		"         Lists the contents ot the given pak files\n"
		"      MakeObj DUMP <pak file> <pak file(s)>\n"
		"         List the internal nodes of a file\n"
		"      MakeObj MERGE <pak file> <pak file(s)>\n"
		"         Merges multiple pak files into one new pak file\n"
		"      MakeObj EXTRACT <pak file archieve>\n"
		"         Creates single files from multiple pak file\n"
		"\n"
		"      with QUIET as first arg copyright message will be omitted\n"
		"      with a trailing slash a direcory is searched rather than a file\n"
		"      default for PAK is PAK ./ ./\n"
#if 0
		"      MakeObj DUMP <pak file(s)>\n"
		"         Dumps the node structure of the given pak files\n"
#endif
	);

	return 3;
}