Updated Spanish translation
[anjuta-git-plugin.git] / plugins / build / build_file.c
blobf6cd09a9d6146e3dfcf5ef880acbbd09f0af2eef
1 /*
2 build_file.c
3 Copyright (C) 2000 Kh. Naba Kumar Singh
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
23 #include <sys/stat.h>
24 #include <unistd.h>
25 #include <sys/types.h>
26 #include <sys/wait.h>
27 #include <signal.h>
28 #include <string.h>
30 #include <gnome.h>
31 #include "anjuta.h"
32 #include "launcher.h"
33 #include "message-manager.h"
34 #include "compile.h"
35 #include "build_file.h"
37 void
38 build_file ()
40 gchar *dirname, *cmd, *buff;
41 TextEditor *te;
43 te = anjuta_get_current_text_editor ();
44 if (!te)
45 return;
46 if (te->full_filename == NULL)
48 anjuta_warning (_("This file has not been saved. Save it first and then build."));
49 return;
51 if (text_editor_is_saved (te) == FALSE)
53 if (text_editor_save_file (te, TRUE) == FALSE)
54 return;
57 #if 0 /* Skipping dependency check for file */
58 if (TRUE)
60 gchar *ext, *filename;
61 struct stat st1, st2;
62 gint flg;
64 filename = g_strdup (te->full_filename);
65 ext = get_file_extension (filename);
66 if (ext)
67 *(--ext) = '\0';
68 stat (te->full_filename, &st1);
69 flg = stat (filename, &st2);
70 if ((flg == 0) && (st2.st_mtime > st1.st_mtime))
72 anjuta_warning (_
73 ("The executable is up-to-date, there is no need to build it again."));
74 g_free (filename);
75 return;
77 g_free (filename);
79 #endif
81 anjuta_set_file_properties (te->full_filename);
82 cmd =
83 command_editor_get_command_file (app->command_editor,
84 COMMAND_BUILD_FILE,
85 te->filename);
86 if (cmd == NULL) {
87 anjuta_warning (_
88 ("No build command has been specified for this type of file."));
89 return;
92 dirname = extract_directory (te->full_filename);
93 chdir (dirname);
94 anjuta_set_execution_dir(dirname);
95 g_free (dirname);
97 if (build_execute_command (cmd) == FALSE)
99 g_free (cmd);
100 return;
102 anjuta_update_app_status (TRUE, _("Build"));
103 an_message_manager_clear (app->messages, MESSAGE_BUILD);
104 buff = g_strdup_printf (_("Building file: %s...\n"), te->filename);
105 an_message_manager_append (app->messages, buff, MESSAGE_BUILD);
106 an_message_manager_append (app->messages, cmd, MESSAGE_BUILD);
107 an_message_manager_append (app->messages, "\n", MESSAGE_BUILD);
108 an_message_manager_show (app->messages, MESSAGE_BUILD);
109 g_free (cmd);
110 g_free (buff);
113 /* Launching the command */
114 static void
115 on_build_mesg_arrived (AnjutaLauncher *launcher,
116 AnjutaLauncherOutputType output_type,
117 const gchar * mesg, gpointer data)
119 an_message_manager_append (app->messages, mesg, MESSAGE_BUILD);
122 static void
123 on_build_terminated (AnjutaLauncher *launcher,
124 gint child_pid, gint status, gulong time_taken,
125 gpointer data)
127 gchar *buff1;
129 g_signal_handlers_disconnect_by_func (launcher,
130 G_CALLBACK (on_build_terminated),
131 data);
132 buff1 = g_strdup_printf (_("Total time taken: %lu secs\n"), time_taken);
133 if (status)
135 an_message_manager_append (app->messages,
136 _("Completed... unsuccessful\n"),
137 MESSAGE_BUILD);
138 if (anjuta_preferences_get_int (ANJUTA_PREFERENCES (app->preferences),
139 DIALOG_ON_BUILD_COMPLETE))
140 anjuta_warning (_("Completed... unsuccessful"));
142 else
144 an_message_manager_append (app->messages,
145 _("Completed... successful\n"),
146 MESSAGE_BUILD);
147 if (anjuta_preferences_get_int (ANJUTA_PREFERENCES (app->preferences),
148 DIALOG_ON_BUILD_COMPLETE))
149 anjuta_status (_("Completed... successful"));
151 an_message_manager_append (app->messages, buff1, MESSAGE_BUILD);
152 if (anjuta_preferences_get_int (ANJUTA_PREFERENCES (app->preferences),
153 BEEP_ON_BUILD_COMPLETE))
154 gdk_beep ();
155 g_free (buff1);
156 anjuta_update_app_status (TRUE, NULL);
159 gboolean
160 build_execute_command (const gchar *command)
162 g_signal_connect (G_OBJECT (app->launcher), "child-exited",
163 G_CALLBACK (on_build_terminated), NULL);
164 return anjuta_launcher_execute (app->launcher, command,
165 on_build_mesg_arrived, NULL);