File: compile.cc

package info (click to toggle)
exult 1.2-4
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 9,040 kB
  • ctags: 10,543
  • sloc: cpp: 99,373; sh: 8,333; ansic: 4,659; makefile: 988; yacc: 769; lex: 313; xml: 19
file content (146 lines) | stat: -rw-r--r-- 3,037 bytes parent folder | download | duplicates (8)
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
/**
 **	Compile.cc - Run usecode compiler and show results.
 **
 **	Written: 10/08/02 - JSF
 **/

/*
Copyright (C) 2002 The Exult Team

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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <string>
#include "studio.h"
#include "exult_constants.h"
#include "utils.h"
#include "execbox.h"

using std::cout;
using std::endl;
using std::string;

/*
 *	"Compile" button
 */
C_EXPORT void on_compile_btn_clicked
	(
	GtkButton *btn,
	gpointer user_data
	)
	{
	ExultStudio::get_instance()->compile();
	}

/*
 *	"Halt" button.
 */
C_EXPORT void on_halt_compile_btn_clicked
	(
	GtkButton *btn,
	gpointer user_data
	)
	{
	ExultStudio::get_instance()->halt_compile();
	}

/*
 *	Called when UCC is done.
 */

void Ucc_done
	(
	int exit_code,
	Exec_box *box,			// Box that called this.
	gpointer user_data		// Not used.
	)
	{
	if (exit_code == 0)		// Success?
		{
		ExultStudio::get_instance()->reload_usecode();
		box->add_message("Reloaded usecode\n");
		}
	}

/*
 *	Open the compile window.
 */

void ExultStudio::open_compile_window
	(
	)
	{
	if (!compilewin)		// First time?
		{
		compilewin = glade_xml_get_widget( app_xml, "compile_win" );
		compile_box = new Exec_box(
			GTK_TEXT_VIEW(
			    glade_xml_get_widget(app_xml, "compile_msgs")),
			GTK_STATUSBAR(
			    glade_xml_get_widget(app_xml, "compile_status")),
			Ucc_done, 0);
		}
	gtk_widget_show(compilewin);
	}

/*
 *	Compile.
 */

void ExultStudio::compile
	(
	bool if_needed			// Means check timestamps.
	)
	{
					// Get source (fixed, for now).
	string source("<PATCH>/usecode.uc");
	source = get_system_path(source);
	string obj("<PATCH>/usecode");
	obj = get_system_path(obj);
	if (!U7exists(source))
		{
		if (!if_needed)
			EStudio::Alert("Source '%s' doesn't exist",
							source.c_str());
		return;			// No source.
		}
					// ++++++Check timestamps.
	open_compile_window();		// Make sure it's open.
	const char *argv[8];		// Set up args.
	argv[0] = "ucc";		// Program to run.
	argv[1] = "-o";			// Specify output.
	argv[2] = obj.c_str();
	argv[3] = source.c_str();	// What to compile.
					// ++++++Which game type (SI/BG)?
	argv[4] = 0;			// NULL.
	if (!compile_box->exec("ucc", (char **) argv))
		EStudio::Alert("Error executing usecode compiler ('ucc')");
	}

/*
 *	Halt compilation.
 */

void ExultStudio::halt_compile
	(
	)
	{
	if (compile_box)
		compile_box->kill_child();
	}