am-project: Add a new test and fix issue when changing several target properties...
[anjuta.git] / launcher / anjuta-launcher.c
blob64e4b2f45580b70d838792f31bc8496ecab64ba0
1 /*
2 anjuta-launcher.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
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
24 #include <sys/types.h>
25 #include <sys/unistd.h>
26 #include <sys/wait.h>
27 #include <stdio.h>
28 #include <glib.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <stdlib.h>
33 /* #define DEBUG */
35 int
36 main (int argc, char **argv)
38 pid_t pid;
39 int status, i;
40 char **arg_v;
42 if (argc < 2)
44 printf ("\nUsage:\n");
45 printf
46 ("anjuta-launcher program_name [program_parameter ... ]\n\n");
47 exit (-1);
50 if (strcmp (argv[1], "--version") == 0)
52 printf ("anjuta-launcher version 0.1.2\n");
53 exit (0);
55 if (strcmp (argv[1], "--__debug_terminal") == 0)
57 FILE *fp;
59 if (argc != 3)
61 printf ("\nUsage:\n");
62 printf ("anjuta-launcher program_name [program_parameter ... ]\n\n");
63 exit (-1);
65 fp = fopen (argv[2], "w");
66 if (fp == NULL)
68 g_warning ("Fatal Error: Cannot write to redirection file\n");
70 else
72 char* tty_name;
73 tty_name = ttyname(0);
74 if (tty_name)
76 fprintf (fp, "%s\n", tty_name);
77 fclose (fp);
78 printf ("Debug Terminal for the process:\n");
79 printf ("-------------------------------\n");
80 while (1) pause ();
81 exit (0);
83 else
85 fprintf (fp, "__ERROR__\n");
86 fclose (fp);
87 g_warning ("Fatal Error: Unexpected error -- Unknowm tty\n");
90 getchar ();
91 exit (-1);
94 arg_v = g_malloc ((argc) * sizeof (char *));
95 printf ("EXECUTING:\n");
96 for (i = 1; i < argc; i++)
98 printf ("%s ", argv[i]);
99 arg_v[i - 1] = g_strdup (argv[i]);
101 printf ("\n----------------------------------------------\n");
102 arg_v[i - 1] = NULL;
104 if ((pid = fork ()) == 0)
106 execvp (argv[1], arg_v);
107 g_error ("Unable to execute the command (not found)\n");
109 if (pid < 0)
111 printf ("\n----------------------------------------------\n");
112 printf ("There was an error in launching the program\n");
113 status = -1;
115 else
117 waitpid (pid, &status, 0);
118 printf ("\n----------------------------------------------\n");
120 waitpid (pid, &status, 0);
122 if (WIFSIGNALED (status)) {
123 int signal = WTERMSIG (status);
125 printf ("Program has been terminated receiving signal %d (%s)\n", signal, g_strsignal (signal));
126 } else if (WIFEXITED (status))
127 printf ("Program exited successfully with errcode (%d)\n", WEXITSTATUS (status));
129 printf ("Press the Enter key to close this terminal ... \n");
130 getchar ();
131 return WEXITSTATUS (status);