00001 #include "arraylist.h"
00002 #include "batchrender.h"
00003 #include "bcsignals.h"
00004 #include "builddate.h"
00005 #include "filexml.h"
00006 #include "filesystem.h"
00007 #include "language.h"
00008 #include "loadfile.inc"
00009 #include "mainmenu.h"
00010 #include "mwindow.h"
00011 #include "mwindowgui.h"
00012 #include "pluginserver.h"
00013 #include "preferences.h"
00014 #include "renderfarmclient.h"
00015
00016 #include <locale.h>
00017 #include <stdlib.h>
00018 #include <string.h>
00019
00020 #include <locale.h>
00021
00022 #define PACKAGE "cinelerra"
00023 #define LOCALEDIR "/usr/share/locale"
00024
00025
00026 enum
00027 {
00028 DO_GUI,
00029 DO_DEAMON,
00030 DO_DEAMON_FG,
00031 DO_BRENDER,
00032 DO_USAGE,
00033 DO_BATCHRENDER
00034 };
00035
00036 #include "thread.h"
00037
00038 int main(int argc, char *argv[])
00039 {
00040
00041 srand(time(0));
00042 ArrayList<char*> filenames;
00043 FileSystem fs;
00044
00045 int operation = DO_GUI;
00046 int deamon_port = DEAMON_PORT;
00047 char deamon_path[BCTEXTLEN];
00048 char config_path[BCTEXTLEN];
00049 char batch_path[BCTEXTLEN];
00050 int nice_value = 20;
00051 config_path[0] = 0;
00052 batch_path[0] = 0;
00053 deamon_path[0] = 0;
00054
00055
00056
00057
00058
00059
00060 char *s, *language;
00061
00062
00063 if ((s = getenv("LC_ALL")) ||
00064 (s = getenv("LC_MESSAGES")) ||
00065 (s = getenv("LC_CTYPE")) ||
00066 (s = getenv ("LANG")))
00067 {
00068
00069 if (strstr(s, ".UTF-8"))
00070 {
00071
00072 language = strtok (s, ".@");
00073
00074 setenv("LANG", language, 1);
00075 }
00076 }
00077
00078
00079
00080
00081
00082 bindtextdomain (PACKAGE, LOCALEDIR);
00083 textdomain (PACKAGE);
00084 setlocale (LC_MESSAGES, "");
00085 setlocale (LC_CTYPE, "");
00086
00087 for(int i = 1; i < argc; i++)
00088 {
00089 if(!strcmp(argv[i], "-h"))
00090 {
00091 operation = DO_USAGE;
00092 }
00093 else
00094 if(!strcmp(argv[i], "-r"))
00095 {
00096 operation = DO_BATCHRENDER;
00097 if(argc > i + 1)
00098 {
00099 if(argv[i + 1][0] != '-')
00100 {
00101 strcpy(batch_path, argv[i + 1]);
00102 i++;
00103 }
00104 }
00105 }
00106 else
00107 if(!strcmp(argv[i], "-c"))
00108 {
00109 if(argc > i + 1)
00110 {
00111 strcpy(config_path, argv[i + 1]);
00112 i++;
00113 }
00114 else
00115 {
00116 fprintf(stderr, "%s: -c needs a filename.\n", argv[0]);
00117 }
00118 }
00119 else
00120 if(!strcmp(argv[i], "-d") || !strcmp(argv[i], "-f"))
00121 {
00122 if(!strcmp(argv[i], "-d"))
00123 operation = DO_DEAMON;
00124 else
00125 operation = DO_DEAMON_FG;
00126
00127 if(argc > i + 1)
00128 {
00129 if(atol(argv[i + 1]) > 0)
00130 {
00131 deamon_port = atol(argv[i + 1]);
00132 i++;
00133 }
00134 }
00135 }
00136 else
00137 if(!strcmp(argv[i], "-b"))
00138 {
00139 operation = DO_BRENDER;
00140 if(i > argc - 2)
00141 {
00142 fprintf(stderr, "-b may not be used by the user.\n");
00143 exit(1);
00144 }
00145 else
00146 strcpy(deamon_path, argv[i + 1]);
00147 }
00148 else
00149 if(!strcmp(argv[i], "-n"))
00150 {
00151 if(argc > i + 1)
00152 {
00153 nice_value = atol(argv[i + 1]);
00154 i++;
00155 }
00156 }
00157 else
00158 {
00159 char *new_filename;
00160 new_filename = new char[1024];
00161 strcpy(new_filename, argv[i]);
00162 fs.complete_path(new_filename);
00163
00164 filenames.append(new_filename);
00165 }
00166 }
00167
00168
00169
00170
00171 if(operation == DO_GUI ||
00172 operation == DO_DEAMON ||
00173 operation == DO_DEAMON_FG ||
00174 operation == DO_USAGE ||
00175 operation == DO_BATCHRENDER)
00176 fprintf(stderr,
00177 PROGRAM_NAME " "
00178 CINELERRA_VERSION " "
00179 BUILDDATE
00180 " (C)2005 Heroine Virtual Ltd.\n\n"
00181
00182 PROGRAM_NAME " is free software, covered by the GNU General Public License,\n"
00183 "and you are welcome to change it and/or distribute copies of it under\n"
00184 "certain conditions. There is absolutely no warranty for " PROGRAM_NAME ".\n");
00185
00186
00187
00188
00189
00190 switch(operation)
00191 {
00192 case DO_USAGE:
00193 printf(_("\nUsage:\n"));
00194 printf(_("%s [-f] [-c configuration] [-d port] [-n nice] [-r batch file] [filenames]\n\n"), argv[0]);
00195 printf(_("-d = Run in the background as renderfarm client. The port (400) is optional.\n"));
00196 printf(_("-f = Run in the foreground as renderfarm client. Substitute for -d.\n"));
00197 printf(_("-n = Nice value if running as renderfarm client. (20)\n"));
00198 printf(_("-c = Configuration file to use instead of %s%s.\n"),
00199 BCASTDIR,
00200 CONFIG_FILE);
00201 printf(_("-r = batch render the contents of the batch file (%s%s) with no GUI. batch file is optional.\n"),
00202 BCASTDIR,
00203 BATCH_PATH);
00204 printf(_("filenames = files to load\n\n\n"));
00205 exit(0);
00206 break;
00207
00208 case DO_DEAMON:
00209 case DO_DEAMON_FG:
00210 {
00211 if(operation == DO_DEAMON)
00212 {
00213 int pid = fork();
00214
00215 if(pid)
00216 {
00217
00218 _exit(0);
00219 }
00220 }
00221
00222 RenderFarmClient client(deamon_port,
00223 0,
00224 nice_value,
00225 config_path);
00226 client.main_loop();
00227 break;
00228 }
00229
00230
00231 case DO_BRENDER:
00232 {
00233 RenderFarmClient client(0,
00234 deamon_path,
00235 20,
00236 config_path);
00237 client.main_loop();
00238 break;
00239 }
00240
00241 case DO_BATCHRENDER:
00242 {
00243 BatchRenderThread *thread = new BatchRenderThread;
00244 thread->start_rendering(config_path,
00245 batch_path);
00246 break;
00247 }
00248
00249 case DO_GUI:
00250 {
00251 MWindow mwindow;
00252 mwindow.create_objects(1,
00253 !filenames.total,
00254 config_path);
00255
00256
00257 if(filenames.total)
00258 {
00259 mwindow.gui->lock_window();
00260 mwindow.load_filenames(&filenames, LOAD_REPLACE);
00261 if(filenames.total == 1)
00262 mwindow.gui->mainmenu->add_load(filenames.values[0]);
00263 mwindow.gui->unlock_window();
00264 }
00265
00266
00267 mwindow.start();
00268 mwindow.save_defaults();
00269 DISABLE_BUFFER
00270 break;
00271 }
00272 }
00273
00274 filenames.remove_all_objects();
00275 return 0;
00276 }
00277