r802: Remove renderframfsclient and renderfarmfsserver .h and .C from Makefile.am...
[cinelerra_cv/mob.git] / cinelerra / main.C
blobd43927f92ac49affc282f678ac07579b085f7747
1 #include "arraylist.h"
2 #include "batchrender.h"
3 #include "bcsignals.h"
4 #include "builddate.h"
5 #include "filexml.h"
6 #include "filesystem.h"
7 #include "language.h"
8 #include "loadfile.inc"
9 #include "mainmenu.h"
10 #include "mwindow.h"
11 #include "mwindowgui.h"
12 #include "pluginserver.h"
13 #include "preferences.h"
14 #include "renderfarmclient.h"
16 #include <locale.h>
17 #include <stdlib.h>
18 #include <string.h>
20 #include <locale.h>
22 #define PACKAGE "cinelerra"
23 #define LOCALEDIR "/usr/share/locale"
26 enum
28         DO_GUI,
29         DO_DEAMON,
30         DO_DEAMON_FG,
31         DO_BRENDER,
32         DO_USAGE,
33         DO_BATCHRENDER
36 #include "thread.h"
38 int main(int argc, char *argv[])
40 // handle command line arguments first
41         srand(time(0));
42         ArrayList<char*> filenames;
43         FileSystem fs;
45         int operation = DO_GUI;
46         int deamon_port = DEAMON_PORT;
47         char deamon_path[BCTEXTLEN];
48         char config_path[BCTEXTLEN];
49         char batch_path[BCTEXTLEN];
50         int nice_value = 20;
51         config_path[0] = 0;
52         batch_path[0] = 0;
53         deamon_path[0] = 0;
57 // detect an UTF-8 locale and try to use a non-Unicode locale instead
58 // <---Beginning of dirty hack
59 // This hack will be removed as soon as Cinelerra is UTF-8 compliant
60     char *s, *language;
62 // Query user locale
63     if ((s = getenv("LC_ALL"))  || 
64                 (s = getenv("LC_MESSAGES")) || 
65                 (s = getenv("LC_CTYPE")) || 
66                 (s = getenv ("LANG")))
67     {
68 // Test if user locale is set to Unicode        
69         if (strstr(s, ".UTF-8"))
70         {
71 // extract language  from language-charset@variant
72           language = strtok (s, ".@");
73 // set language as the default locale
74           setenv("LANG", language, 1);
75         }
76     }
77 // End of dirty hack --->
82         bindtextdomain (PACKAGE, LOCALEDIR);
83         textdomain (PACKAGE);
84         setlocale (LC_MESSAGES, "");
85         setlocale (LC_CTYPE, "");
87         for(int i = 1; i < argc; i++)
88         {
89                 if(!strcmp(argv[i], "-h"))
90                 {
91                         operation = DO_USAGE;
92                 }
93                 else
94                 if(!strcmp(argv[i], "-r"))
95                 {
96                         operation = DO_BATCHRENDER;
97                         if(argc > i + 1)
98                         {
99                                 if(argv[i + 1][0] != '-')
100                                 {
101                                         strcpy(batch_path, argv[i + 1]);
102                                         i++;
103                                 }
104                         }
105                 }
106                 else
107                 if(!strcmp(argv[i], "-c"))
108                 {
109                         if(argc > i + 1)
110                         {
111                                 strcpy(config_path, argv[i + 1]);
112                                 i++;
113                         }
114                         else
115                         {
116                                 fprintf(stderr, "%s: -c needs a filename.\n", argv[0]);
117                         }
118                 }
119                 else
120                 if(!strcmp(argv[i], "-d") || !strcmp(argv[i], "-f"))
121                 {
122                         if(!strcmp(argv[i], "-d"))
123                                 operation = DO_DEAMON;
124                         else
125                                 operation = DO_DEAMON_FG;
127                         if(argc > i + 1)
128                         {
129                                 if(atol(argv[i + 1]) > 0)
130                                 {
131                                         deamon_port = atol(argv[i + 1]);
132                                         i++;
133                                 }
134                         }
135                 }
136                 else
137                 if(!strcmp(argv[i], "-b"))
138                 {
139                         operation = DO_BRENDER;
140                         if(i > argc - 2)
141                         {
142                                 fprintf(stderr, "-b may not be used by the user.\n");
143                                 exit(1);
144                         }
145                         else
146                                 strcpy(deamon_path, argv[i + 1]);
147                 }
148                 else
149                 if(!strcmp(argv[i], "-n"))
150                 {
151                         if(argc > i + 1)
152                         {
153                                 nice_value = atol(argv[i + 1]);
154                                 i++;
155                         }
156                 }
157                 else
158                 {
159                         char *new_filename;
160                         new_filename = new char[1024];
161                         strcpy(new_filename, argv[i]);
162             fs.complete_path(new_filename);
164                         filenames.append(new_filename);
165                 }
166         }
171         if(operation == DO_GUI || 
172                 operation == DO_DEAMON || 
173                 operation == DO_DEAMON_FG || 
174                 operation == DO_USAGE ||
175                 operation == DO_BATCHRENDER)
176         fprintf(stderr, 
177                 PROGRAM_NAME " " 
178                 CINELERRA_VERSION " " 
179                 BUILDDATE 
180                 " (C)2005 Heroine Virtual Ltd.\n\n"
182 PROGRAM_NAME " is free software, covered by the GNU General Public License,\n"
183 "and you are welcome to change it and/or distribute copies of it under\n"
184 "certain conditions. There is absolutely no warranty for " PROGRAM_NAME ".\n");
190         switch(operation)
191         {
192                 case DO_USAGE:
193                         printf(_("\nUsage:\n"));
194                         printf(_("%s [-f] [-c configuration] [-d port] [-n nice] [-r batch file] [filenames]\n\n"), argv[0]);
195                         printf(_("-d = Run in the background as renderfarm client.  The port (400) is optional.\n"));
196                         printf(_("-f = Run in the foreground as renderfarm client.  Substitute for -d.\n"));
197                         printf(_("-n = Nice value if running as renderfarm client. (20)\n"));
198                         printf(_("-c = Configuration file to use instead of %s%s.\n"), 
199                                 BCASTDIR, 
200                                 CONFIG_FILE);
201                         printf(_("-r = batch render the contents of the batch file (%s%s) with no GUI.  batch file is optional.\n"), 
202                                 BCASTDIR, 
203                                 BATCH_PATH);
204                         printf(_("filenames = files to load\n\n\n"));
205                         exit(0);
206                         break;
208                 case DO_DEAMON:
209                 case DO_DEAMON_FG:
210                 {
211                         if(operation == DO_DEAMON)
212                         {
213                                 int pid = fork();
215                                 if(pid)
216                                 {
217 // Redhat 9 requires _exit instead of exit here.
218                                         _exit(0);
219                                 }
220                         }
222                         RenderFarmClient client(deamon_port, 
223                                 0, 
224                                 nice_value, 
225                                 config_path);
226                         client.main_loop();
227                         break;
228                 }
230 // Same thing without detachment
231                 case DO_BRENDER:
232                 {
233                         RenderFarmClient client(0, 
234                                 deamon_path, 
235                                 20,
236                                 config_path);
237                         client.main_loop();
238                         break;
239                 }
241                 case DO_BATCHRENDER:
242                 {
243                         BatchRenderThread *thread = new BatchRenderThread;
244                         thread->start_rendering(config_path, 
245                                 batch_path);
246                         break;
247                 }
249                 case DO_GUI:
250                 {
251                         MWindow mwindow;
252                         mwindow.create_objects(1, 
253                                 !filenames.total,
254                                 config_path);
256 // load the initial files on seperate tracks
257                         if(filenames.total)
258                         {
259                                 mwindow.gui->lock_window();
260                                 mwindow.load_filenames(&filenames, LOAD_REPLACE);
261                                 if(filenames.total == 1)
262                                         mwindow.gui->mainmenu->add_load(filenames.values[0]);
263                                 mwindow.gui->unlock_window();
264                         }
266 // run the program
267                         mwindow.start();
268                         mwindow.save_defaults();
269 DISABLE_BUFFER
270                         break;
271                 }
272         }
274         filenames.remove_all_objects();
275         return 0;