gitkinit.c

Go to the documentation of this file.
00001 
00027 #define GITK_LIB_C
00028 #define GITK_INIT_C
00029 
00030 #include "gitkincludes.h"
00031 
00032 
00049 void gitk_init(guint * const argc, gchar *** const argv, gchar * const _client_package_name, gchar * const _client_locale_dir) /*@globals undef killed gitk_renderer_name@*/ {
00050   gboolean info_only;
00051 
00052   (void)g_log_set_handler(G_LOG_DOMAIN,G_LOG_LEVEL_INFO|G_LOG_LEVEL_DEBUG|G_LOG_LEVEL_MESSAGE|G_LOG_LEVEL_WARNING|G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_ERROR, gitk_log_handler, NULL);
00053   (void)g_log_set_handler("GLib",G_LOG_LEVEL_DEBUG|G_LOG_LEVEL_MESSAGE|G_LOG_LEVEL_WARNING|G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_ERROR, gitk_log_handler, NULL);
00054   (void)g_log_set_handler("GLib-GObject",G_LOG_LEVEL_DEBUG|G_LOG_LEVEL_MESSAGE|G_LOG_LEVEL_WARNING|G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_ERROR, gitk_log_handler, NULL);
00055   (void)g_set_printerr_handler(gitk_print_handler);
00056 
00057   g_assert(argc!=NULL);
00058   g_assert(argv!=NULL);
00059   
00060   if(gitk_initialized) { 
00061     gitk_err("gitk_init() called again");
00062     return;
00063   }
00064   gitk_log_intro();
00065 
00066   client_name=(*argv)[0];
00067   client_package_name=_client_package_name;
00068   client_locale_dir=_client_locale_dir;
00069   
00070   //-- this needs to be done very easrly !
00071   if(!gitk_profile_init()) {
00072     gitk_log("gitk_profile construction failed");
00073     exit(EXIT_FAILURE);
00074   }
00075   
00076   //-- run sensors
00077   gitk_sensor_locale();
00078 
00079 #ifdef ENABLE_NLS
00080   {
00081     //-- the catalog paths
00082     (void)bindtextdomain(PACKAGE, LOCALEDIR);
00083     (void)bindtextdomain(client_package_name, client_locale_dir);
00084     //-- choose the encoding, we want to get messages in
00085     (void)bind_textdomain_codeset(PACKAGE,"UTF-8");
00086     (void)bind_textdomain_codeset(client_package_name,"UTF-8");
00087     //-- use the libaries catalog as default for _() and the clients for __()
00088     (void)textdomain(PACKAGE);
00089     gitk_log3("\"%s\" NLS enabled for \"%s\" in \"%s\"",gitk_profile_get_property("locale"),PACKAGE,LOCALEDIR);
00090     gitk_log3("\"%s\" NLS enabled for \"%s\" in \"%s\"",gitk_profile_get_property("locale"),client_package_name,client_locale_dir);
00091   }
00092 #endif
00093 
00094   //-- check if there have been passed some parameters for libgitk and process them
00095   //-- only proceed if '--help' is not among the options
00096   info_only=gitk_init_process_commandline(argc,argv);
00097   gitk_log1("info_only ? %d",info_only);
00098 
00099   if(!g_module_supported())  {
00100     gitk_log("glib module support is not working");
00101     exit(EXIT_FAILURE);
00102   }
00103 
00104   //-- try to initialse a renderer ?
00105   if(!gitk_renderer_init(argc,argv,info_only)) {
00106     gitk_log("no (valid) renderer specified");
00107     exit(EXIT_FAILURE);
00108   }
00109   gitk_log("renderer okay");
00110 
00111   if(!info_only) {
00112 
00113 #if defined(USE_LIBHTTPD) && defined(G_THREADS_ENABLED)
00114     if(gitk_server_port) {
00115       GError *error;
00116       
00117       if(!g_thread_supported()) g_thread_init(NULL);
00118       //-- start server thread
00119       if(!(server_thread=g_thread_create(&gitk_server_thread, NULL, FALSE, &error))) {
00120         gitk_log1("error creating http thread : \"%s\"", error->message);
00121         g_error_free(error);
00122       }
00123       gitk_log1("http server is listening on port %d",gitk_server_port);
00124     }
00125 #endif
00126 
00127     //-- initialise libxml
00128     if(!gitk_init_xml()) {
00129       gitk_err("failed to initialise lib-xml");
00130       exit(EXIT_FAILURE);
00131     }
00132     gitk_log("xml okay");
00133 
00134     if(!gitk_init_common_xpath_expressions()) {
00135       gitk_err("failed to prepare common xpath expressions");
00136       exit(EXIT_FAILURE);
00137     }
00138     gitk_log("xml-xpath okay");
00139     //-- initialise libxslt
00140     if(!gitk_init_xsl()) {
00141       gitk_err("failed to initialise xsl files");
00142       exit(EXIT_FAILURE);
00143     }
00144     gitk_log("xslt okay");
00145   
00146     //-- everything initialized fine
00147     gitk_initialized=TRUE;
00148   }
00149   gitk_log_outro();
00150 }
00151 
00160 static gboolean gitk_init_process_commandline(guint * const argc, gchar *** const argv) {
00161   guint i;
00162   gchar *arg;
00163   gboolean info_only=FALSE; 
00164   gboolean info_help=FALSE, info_version=FALSE;
00165 
00166   gitk_log("gitk_init_process_commandline() beg");
00167 
00168   //-- check if there have been passed some parameters for libgitk
00169   for(i=1;i<*argc;) {
00170     if(!strcmp("--help", (*argv)[i]) || !strcmp("-h", (*argv)[i])) {
00171       info_only=info_help=TRUE;
00172     }
00173     else if((*argv)[i] && (!strcmp("--version", (*argv)[i]))) {
00174       info_only=info_version=TRUE;
00175     } 
00176     else if((*argv)[i] && (arg=parse_commandline_arg(argc,argv,&i,"--gitk-renderer"))) {
00177       gitk_renderer_name=strdup(arg);
00178       gitk_log1("selected renderer (par) : \"%s\"",gitk_renderer_name);
00179     }
00180     else if((*argv)[i] && (arg=parse_commandline_arg(argc,argv,&i,"--gitk-style"))) {
00181       gitk_style_name=strdup(arg);
00182       gitk_log1("selected style (par) : \"%s\"",gitk_style_name);
00183     }
00184 #ifdef USE_LIBHTTPD
00185     else if((*argv)[i] && (arg=parse_commandline_arg(argc,argv,&i,"--gitk-server-port"))) {
00186       gitk_server_port=atoi(arg);
00187       gitk_log1("server enabled at port (par) : %d",gitk_server_port);
00188     }
00189 #endif
00190     i++;
00191   }
00192   if(info_help) {
00194     gitk_puts(_("GITK options"));
00195     gitk_puts(_("      --gitk-renderer\t\twhich rendering module to use"));
00196     gitk_puts(_("      --gitk-style\t\twhich style to use"));
00197 #ifdef USE_LIBHTTPD
00198     gitk_puts(_("      --gitk-server-port\twhich port number to use for internal http server"));
00199     gitk_puts(_("                        \t(off when unspecified)"));
00200 #endif
00201     //puts("Report GITK bugs to "PACKAGE_BUGREPORT);
00202     putchar('\n');
00203   }
00204   if(info_version) puts(PACKAGE_NAME": version "PACKAGE_VERSION" by "PACKAGE_BUGREPORT);
00205   //-- remove found parameters
00206   cleanup_commandline_args(argc,argv);
00207   gitk_log1("gitk_init_process_commandline()=%1d end",info_only);
00208   return(info_only);
00209 }
00210 
00211 
00216 static gboolean gitk_init_xml(void) {
00217   gboolean result=TRUE;
00218 
00219   //-- set own error handler
00220   xmlSetGenericErrorFunc("libxml-error: ",&gitk_libxmlxslt_error_func);
00221   //-- initialise the xml parser
00222   xmlInitParser();
00223   //-- InitParser does that for us
00224   //xmlXPathInit();
00225   xmlSubstituteEntitiesDefault(1);
00226   xmlLoadExtDtdDefaultValue=TRUE;           // always load DTD default values (even when not validating)
00227   xmlDoValidityCheckingDefaultValue=FALSE;  // do not validate files (we load xsl files as well
00228   
00229   return(result);
00230 }
00231 
00237 static gboolean gitk_init_common_xpath_expressions(void) {
00238   gboolean result=TRUE;
00239 
00240   if(!(xpath_get_dialog_name=xmlXPathCompile("/"GITK_NS_PREFIX":giml/"GITK_NS_PREFIX":dialog/"GITK_NS_PREFIX":meta/dc:title"))) {
00241     gitk_err("failed to compile xpath expression (dialog_name)");
00242     result=FALSE;
00243   }
00244   if(!(xpath_get_dialog_modality=xmlXPathCompile("/"GITK_NS_PREFIX":giml/"GITK_NS_PREFIX":dialog/"GITK_NS_PREFIX":modal"))) {
00245     gitk_err("failed to compile xpath expression (dialog_modality)");
00246     result=FALSE;
00247   }
00248   if(!(xpath_get_label=xmlXPathCompile("./"GITK_NS_PREFIX":label"))) {
00249     gitk_err("failed to compile xpath expression (label)");
00250     result=FALSE;
00251   }
00252   return(result);
00253 }
00254 
00259 static gboolean gitk_init_xsl(void) {
00260   gboolean result=TRUE;
00261 
00262   g_assert(gitk_renderer_name!=NULL);
00263   
00264   //-- set own error handler
00265   xsltSetGenericErrorFunc("libxslt-error: ",&gitk_libxmlxslt_error_func);
00266 
00267   /* we can do
00268    *  xsltParseStylesheetFile(char *fname);
00269    * here to load a stylesheet from filesystem
00270    * or
00271    * generate the stylesheet as a xmlDoc and call
00272    *   xsltParseStylesheetDoc(xmlDocPtr doc);
00273    */
00274 
00275   //-- register own xslt function (we may pass NULL instead of xsltExtShutdown_i18n)
00276   if(xsltRegisterExtModule(I18N_NS_URL,xsltExtInit_i18n,xsltExtShutdown_i18n)) {
00277     gitk_err("failed to register extension modules (i18n)");
00278     result=FALSE;
00279   }
00280    
00281   //-- load the stylesheet for node expansion from filesystem
00282   if(!(xsl_expand=xsltParseStylesheetFile(XSL_PATH"expand.xsl"))) {
00283     gitk_err("failed to load stylesheet (expand.xsl)");
00284     result=FALSE;
00285   }
00286 
00328   if(!(xsl_i18n=xsltParseStylesheetFile(XSL_PATH"i18n.xsl"))) {
00329     gitk_err("failed to load stylesheet (i18n.xsl)");
00330     result=FALSE;
00331   }
00332 
00333   //-- load the stylesheet for domain transformation from filesystem
00334   if(!gitk_init_xsl_domain()) {
00335     result=FALSE;
00336   }
00337 
00338   //-- load the stylesheet for renderer specific style application from filesystem
00339   if(!gitk_init_xsl_style()) {
00340     result=FALSE;
00341   }
00342 
00343   return(result);
00344 }
00345 
00350 gboolean gitk_init_xsl_domain(void) {
00351   gboolean result=TRUE;
00352   gchar stylesheet_name[FILENAME_MAX];
00353 
00354   //-- free stylesheet, if already loaded
00355   if(xsl_domain) { xsltFreeStylesheet(xsl_domain);xsl_domain=NULL; }
00356   
00357   if(snprintf(stylesheet_name,FILENAME_MAX,XSL_ROOT_PATH"gitk-renderer-%s/domain.xsl",gitk_renderer_name)>=0) {
00358     gitk_log1("  stylesheet name1 : \"%s\"",stylesheet_name);
00359     if(!(xsl_domain=xsltParseStylesheetFile(stylesheet_name))) {
00360       gitk_err1("failed to load stylesheet : \"%s\"",stylesheet_name);
00361       result=FALSE;
00362     }
00363   }
00364   else {
00365     gitk_err("failed format stylesheet_name : \"domain\"");
00366     result=FALSE;
00367   }
00368   return(result); 
00369 }
00370 
00375 gboolean gitk_init_xsl_style(void) {
00376   gboolean result=TRUE;
00377   gchar stylesheet_name[FILENAME_MAX];
00378   gchar *envvar;
00379 
00380   //-- free stylesheet, if already loaded
00381   if(xsl_style) { xsltFreeStylesheet(xsl_style);xsl_style=NULL; }
00382 
00383   if(!gitk_style_name && (envvar=getenv("GITK_STYLE"))!=NULL) { //-- use that style
00384     gitk_style_name=strdup(envvar);
00385     gitk_log1("selected style (env) : \"%s\"",gitk_style_name);
00386   }
00387   if(!gitk_style_name) {
00388     gitk_style_name=strdup("default");
00389     gitk_log1("selected style (def) : \"%s\"",gitk_style_name);
00390   }
00391   if(snprintf(stylesheet_name,FILENAME_MAX,XSL_ROOT_PATH"gitk-renderer-%s/style/%s.xsl",gitk_renderer_name,gitk_style_name)>=0) {
00392     gitk_log1("  stylesheet name1 : \"%s\"",stylesheet_name);
00393     if(!(xsl_style=xsltParseStylesheetFile(stylesheet_name))) {
00394       gitk_err1("failed to load stylesheet (%s)",stylesheet_name);
00395       result=FALSE;
00396     }
00397   }
00398   else {
00399     gitk_err("failed format stylesheet_name : \"style\"");
00400     result=FALSE;
00401   }
00402   return(result);
00403 }
00404 

Generated on Thu Oct 28 10:59:08 2004 for gitk by doxygen 1.3.6