aboutsummaryrefslogtreecommitdiff
path: root/engines/avalanche/sezxfr.cpp
blob: 79876930d498c5db2872aa0a4e5b367b03ba9e79 (plain)
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
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

/*
 * This code is based on the original source code of Lord Avalot d'Argent version 1.3.
 * Copyright (c) 1994-1995 Mike, Mark and Thomas Thurman.
 */

/*#include "Crt.h"*/
/*$V-*/

namespace Avalanche {

text t;
string x;
matrix<1, 100, 1, 2, string> data;
word dp, ip, fv;
array<1, 20, word> index1;
array<1, 20, varying_string<10> > names;
array<1, 1777, longint> thumb;
longint total;
untyped_file f;

void strip() {
	x = copy(x, 2, 255);
}

void squish(string &q) {
	string n;
	boolean ctrl;
	byte fv;
	ctrl = false;
	n = "";
	for (fv = 1; fv <= length(q); fv ++)
		if (q[fv] == '^')  ctrl = true;
		else {
			;     /* not a caret */
			if (ctrl)  q[fv] = chr(ord(upcase(q[fv])) - 64);
			n = n + q[fv];
			ctrl = false;
		}
	while (n[length(n)] == '\40')  n[0] -= 1; /* strip trailing spaces */
	for (fv = 1; fv <= length(n); fv ++) n[fv] += 177; /* scramble */
	q = n;
}

int main(int argc, const char *argv[]) {
	pio_initialize(argc, argv);
	dp = 0;
	ip = 0;
	fillchar(data, sizeof(data), '\0');
	fillchar(thumb, sizeof(thumb), '\261');
	fillchar(index1, sizeof(index1), '\3');
	assign(t, "v:sez.dat");
	reset(t);
	while (! eof(t)) {
		t >> x >> NL;
		switch (x[1]) {
		case ';': {
			textattr = lightred;
			strip();
		}
		break;
		case ':': {
			textattr = lightblue;
			strip();
			if (dp > 0)  squish(data[dp][2]);
			dp += 1;
			data[dp][1] = x;
			if (pos("*", x) > 0) {
				;     /* index */
				ip += 1;
				index1[ip] = dp;
				names[ip] = copy(x, 1, pos("*", x) - 1);
			}
		}
		break;
		default: {
			textattr = white;
			data[dp][2] = data[dp][2] + x + '\40';
		}
		}
		output << x << NL;
	}
	squish(data[dp][2]);

	total = 1;
	for (fv = 1; fv <= dp; fv ++) {
		thumb[fv] = total;
		total += length(data[fv][2]) + 1;
	}

	thumb[dp + 1] = total;

	/* save it all! Firstly, the Sez file... */

	assign(f, "v:avalot.sez");
	rewrite(f, 1);
	x = string("This is a Sez file for an Avvy game, and it's copyright!") + '\32';
	blockwrite(f, x[1], 57);
	blockwrite(f, dp, 2);
	blockwrite(f, ip, 2);
	blockwrite(f, index1, 40);
	blockwrite(f, thumb, dp * 4 + 4);
	for (fv = 1; fv <= dp; fv ++)
		blockwrite(f, data[fv][2], length(data[fv][2]) + 1);
	close(f);

	/* ...then the Sed file. */

	assign(t, "v:avalot.sed");
	rewrite(t);
	for (fv = 1; fv <= ip; fv ++) t << names[fv] << NL;
	for (fv = 1; fv <= dp; fv ++) t << data[fv][1] << NL;
	close(t);

	/* Done! */
	return EXIT_SUCCESS;
}

} // End of namespace Avalanche.