File: floor.cpp

package info (click to toggle)
sludge 2.2.2-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,852 kB
  • sloc: cpp: 32,432; sh: 1,237; makefile: 634; xml: 284
file content (58 lines) | stat: -rw-r--r-- 1,884 bytes parent folder | download | duplicates (7)
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
#include <stdio.h>
#include <string.h>

#include "moreio.h"
#include "splitter.hpp"
#include "messbox.h"

bool convertFloor (char * filename) {
	char * wholeFile = grabWholeFile (filename);
	if (! wholeFile) return false;

	filename[strlen (filename) - 1] = 'z';
	stringArray * knownCo = NULL;
	stringArray * splitBits;
	stringArray * sA;

	FILE * outFile = fopen (filename, "wb");
	if (! outFile) return addComment (ERRORTYPE_SYSTEMERROR, "Can't write compiled floor file", filename, NULL, 0);

	sA = splitString (wholeFile, '*');

	destroyFirst (sA);

	fputc (countElements (sA), outFile);
	while (sA) {
		while (trimEnd (sA -> string, '\n') || trimEnd (sA -> string, '\r')) {;}
		splitBits = splitString (sA -> string, ';');
		fputc (countElements (splitBits), outFile);
		while (splitBits) {
			put2bytes (findOrAdd (knownCo, splitBits -> string), outFile);
			destroyFirst (splitBits);
		}
		destroyFirst (sA);
	}

	put2bytes (countElements (knownCo), outFile);
	int i;
	while (knownCo) {
		splitBits = splitString (knownCo -> string, ',');
		i = stringToInt (splitBits -> string, ERRORTYPE_PROJECTERROR);
		if (i < 0) {
			addComment (ERRORTYPE_PROJECTWARNING, "Error processing floor: X co-ordinate is not a positive integer. I'm pretending it's a zero.", knownCo -> string, filename, 0);
			i = 0;
		}
		put2bytes (i, outFile);
		if (! destroyFirst (splitBits)) return addComment (ERRORTYPE_PROJECTERROR, "Error processing floor: No comma in co-ordinate pair", knownCo -> string, filename, 0);
		i = stringToInt (splitBits -> string, ERRORTYPE_PROJECTERROR);
		if (i < 0) {
			addComment (ERRORTYPE_PROJECTWARNING, "Error processing floor: Y co-ordinate is not a positive integer. I'm pretending it's a zero.", knownCo -> string, filename, 0);
			i = 0;
		}
		put2bytes (i, outFile);
		destroyFirst (splitBits);
		destroyFirst (knownCo);
	}
	fclose (outFile);
	return true;
}