mask tweaks, focus follows centroid, gradient/colorpicker rework, no hard edges in...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / threadexec.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "mutex.h"
23 #include "threadexec.h"
24
25 #include <stdlib.h>
26 #include <string.h>
27 #include <sys/types.h>
28 #include <sys/wait.h>
29 #include <unistd.h>
30
31 #define MAX_ARGS 32
32
33
34
35
36
37 ThreadExec::ThreadExec()
38  : Thread(1, 0, 0)
39 {
40         Thread::set_synchronous(1);
41         arguments = new char*[MAX_ARGS];
42         total_arguments = 0;
43         start_lock = new Mutex;
44         stdin_fd = 0;
45         pipe_stdin = 0;
46         command_line = "";
47 }
48
49 ThreadExec::~ThreadExec()
50 {
51         if(pipe_stdin)
52         {
53                 fflush(stdin_fd);
54                 fclose(stdin_fd);
55                 close(filedes[0]);
56                 close(filedes[1]);
57         }
58
59         Thread::join();
60
61         for(int i = 0; i < total_arguments; i++)
62                 delete [] arguments[i];
63
64         delete start_lock;
65         delete [] arguments;
66 }
67
68
69
70 void ThreadExec::start_command(const char *command_line, int pipe_stdin)
71 {
72         this->command_line = command_line;
73         this->pipe_stdin = pipe_stdin;
74
75         Thread::start();
76
77         start_lock->lock();
78         start_lock->lock();
79         start_lock->unlock();
80 }
81
82
83 void ThreadExec::run()
84 {
85         char *path_ptr;
86         char *ptr;
87         char *argument_ptr;
88         char argument[BCTEXTLEN];
89         char command_line[BCTEXTLEN];
90
91         strcpy(command_line, this->command_line);
92
93
94
95 // Set up arguments for exec
96         ptr = command_line;
97         path_ptr = path;
98         while(*ptr != ' ' && *ptr != 0)
99         {
100                 *path_ptr++ = *ptr++;
101         }
102         *path_ptr = 0;
103
104         arguments[total_arguments] = new char[strlen(path) + 1];
105         strcpy(arguments[total_arguments], path);
106 //printf("%s\n", arguments[total_arguments]);
107         total_arguments++;
108         arguments[total_arguments] = 0;
109
110         while(*ptr != 0)
111         {
112                 ptr++;
113                 argument_ptr = argument;
114                 while(*ptr != ' ' && *ptr != 0)
115                 {
116                         *argument_ptr++ = *ptr++;
117                 }
118                 *argument_ptr = 0;
119 //printf("%s\n", argument);
120
121                 arguments[total_arguments] = new char[strlen(argument) + 1];
122                 strcpy(arguments[total_arguments], argument);
123                 total_arguments++;
124                 arguments[total_arguments] = 0;
125         }
126
127
128
129
130
131
132
133
134
135
136         if(pipe_stdin)
137         {
138                 (void)pipe(filedes);
139                 stdin_fd = fdopen(filedes[1], "w");
140         }
141
142         start_lock->unlock();
143
144 printf("ThreadExec::run 1\n");
145         run_program(total_arguments, arguments, filedes[0]);
146
147 printf("ThreadExec::run 2\n");
148
149
150 }
151
152
153 FILE* ThreadExec::get_stdin()
154 {
155         return stdin_fd;
156 }
157
158
159
160 void ThreadExec::run_program(int argc, char *argv[], int stdin_fd)
161 {
162 }