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