File: CompilerMain.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 (145 lines) | stat: -rw-r--r-- 3,673 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
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
/* -*- Mode: C++; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * CompilerMain.cpp
 *
 * Copyright (C) 2010 Tobias Hansen <tobias.han@gmx.de>
 *
 * 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 3 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, see <http://www.gnu.org/licenses/>.
 */

#include <stdio.h>
#include <getopt.h>
#include <glib.h>
#include "project.hpp"
#include "settings.h"
#include "compiler.hpp"
#include "interface.h"
#include "errorlinktofile.h"

//The functions declared in interface.h:

bool askAQuestion (const char * head, const char * msg)
{
	return true;
}

bool errorBox (const char * head, const char * msg)
{
	fprintf(stderr, "%s\n%s\n", head, msg);

	return false;
}

const char * getTempDir ()
{
	return g_get_user_cache_dir();
}

bool fileExists(char * file) {
	FILE * tester;
	bool retval = false;
	tester = fopen (file, "rb");
	if (tester) {
		retval = true;
		fclose (tester);
	}
	return retval;
}

void receiveCompilerInfo(compilerInfo *info)
{
	if (info->newComments) {
		if (! errorList) return;
		fprintf(stderr, "%s\n", errorList->fullText);
	}
}

void printCmdlineUsage() {
	fprintf(stdout, "SLUDGE compiler, usage: sludge-compiler [<options>] <project file>\n\n");
	fprintf(stdout, "Options:\n");
	fprintf(stdout, "-k,	--keep-slx		Keep compressed image files that are generated during compilation.\n");
	fprintf(stdout, "-t,	--string-file		Write a text file of the strings contained in the game.\n");
	fprintf(stdout, "-s,	--strip-debug-info	Strip debug information from the game file.\n");
	fprintf(stdout, "-h,	--help			Print this help message\n\n");
}

bool parseCmdlineParameters(int argc, char *argv[]) {
	int retval = true;
	programSettings.compilerKillImages = 1;
	programSettings.compilerWriteStrings = 0;
	programSettings.compilerVerbose = 1;
	programSettings.searchSensitive = 0;
	while (1)
	{
		static struct option long_options[] =
		{
			{"keep-slx",	no_argument,	   0, 'k' },
			{"string-file",	no_argument,	   0, 't' },
			{"silent",		no_argument,	   0, 's' },
			{"help",		no_argument,	   0, 'h' },
			{0,0,0,0} /* This is a filler for -1 */
		};
		int option_index = 0;
		int c = getopt_long (argc, argv, "ktsh", long_options, &option_index);
		if (c == -1) break;
			switch (c) {
		case 'k':
			programSettings.compilerKillImages = 0;
			break;
		case 't':
			programSettings.compilerWriteStrings = 1;
			break;
		case 's':
			programSettings.compilerVerbose = 0;
			break;
		case 'h':
		default:
			retval = false;
			break;
		}
	}
	return retval;
}

int main (int argc, char *argv[])
{
	char *fileList[1000];
	int fileListNum;

	if (! parseCmdlineParameters(argc, argv) ) {
		printCmdlineUsage();
		return 0;
	}

	if (argc < 2 || ! fileExists(argv[argc - 1]) ) {
		fprintf(stderr, "Project file not found.\n");
		printCmdlineUsage();
		return -1;
	}


	if (!loadProject (argv[argc - 1], fileList, &fileListNum))
	{
		fprintf(stderr, "Error loading project.\n");
		return -1;
	}
	fprintf(stderr, "Start compiling...\n");
	if (!compileEverything(argv[argc - 1], fileList, &fileListNum, &receiveCompilerInfo))
	{
		fprintf(stderr, "Error compiling project.\n");
		return -1;
	}

	return 0;
}