3737
3838#include "script.h"
3939#include "script_functions.h"
40+ #include "logger.h"
4041
4142#include "error_strings.h"
4243
5354GMainLoop * loop = NULL ;
5455
5556static gboolean debug = FALSE;
57+ static gboolean logtofifo = FALSE;
5658static gboolean emulate = FALSE;
59+
60+ static gboolean show_fifo = FALSE;
61+
5762static gboolean show_version = FALSE;
5863
5964// libwnck Version Information is only availible if you have
@@ -215,7 +220,7 @@ static void signal_handler(int sig)
215220/**
216221 *
217222 */
218- void print_list (GSList * list )
223+ static void print_list (GSList * list )
219224{
220225 GSList * temp_list ;
221226 if (list != NULL ) {
@@ -226,7 +231,7 @@ void print_list(GSList *list)
226231
227232 if (file_name ) {
228233 if (g_str_has_suffix ((gchar * )file_name , ".lua" )) {
229- printf ("%s\n" , (gchar * )file_name );
234+ logger_printf ("%s\n" , (gchar * )file_name );
230235 }
231236 }
232237 temp_list = temp_list -> next ;
@@ -238,30 +243,26 @@ void print_list(GSList *list)
238243/**
239244 *
240245 */
241- void print_script_lists ()
246+ static void print_script_lists ()
242247{
243248 gboolean have_any_files = FALSE;
244249 win_event_type i ;
245250
246- if (debug )
247- printf ("------------\n" );
251+ logger_print ("------------\n" );
248252
249253 for (i = 0 ; i < W_NUM_EVENTS ; i ++ ) {
250254 if (event_lists [i ])
251255 have_any_files = TRUE;
252256 // If we are running debug mode - print the list of files:
253- if (debug ) {
254- printf (_ ("List of Lua files handling \"%s\" events in folder:" ),
255- event_names [i ]);
256- printf ("\n" );
257- if (event_lists [i ]) {
258- print_list (event_lists [i ]);
259- }
257+ logger_printf (_ ("List of Lua files handling \"%s\" events in folder:\n" ),
258+ event_names [i ]);
259+ if (event_lists [i ]) {
260+ print_list (event_lists [i ]);
260261 }
261262 }
262263
263264 if (!have_any_files ) {
264- printf ("%s\n\n" , _ ("No script files found in the script folder - exiting." ));
265+ logger_err_printf ("%s\n\n" , _ ("No script files found in the script folder - exiting." ));
265266 exit (EXIT_SUCCESS );
266267 }
267268}
@@ -275,19 +276,17 @@ void refresh_config_and_script()
275276 set_current_window (NULL );
276277
277278 if (load_config (config_filename ) != 0 ) {
278- printf ("Configuration file cannot be re-loaded. Processing will not continue until the error is corrected" );
279+ logger_print_always ("Configuration file cannot be re-loaded. Processing will not continue until the error is corrected.\n " );
279280 return ;
280281 }
281282
282283 global_lua_state = reinit_script (global_lua_state , script_folder );
283284
284- if (debug )
285- printf ("Files in folder updated!\n - new lists:\n\n" );
285+ logger_print ("Files in folder updated!\n - new lists:\n\n" );
286286
287287 print_script_lists ();
288288
289- if (debug )
290- printf ("-----------\n" );
289+ logger_print ("-----------\n" );
291290}
292291
293292/**
@@ -332,7 +331,6 @@ void folder_changed_callback(GFileMonitor *mon G_GNUC_UNUSED,
332331 }
333332}
334333
335-
336334/**
337335 * Program main entry
338336 */
@@ -342,6 +340,12 @@ int main(int argc, char *argv[])
342340 { "debug" , 'd' , 0 , G_OPTION_ARG_NONE , & debug ,
343341 N_ ("Print debug info to stdout" ), NULL
344342 },
343+ { "debug-fifo" , 'D' , 0 , G_OPTION_ARG_NONE , & logtofifo ,
344+ N_ ("Print debug info & copy stdout to a FIFO" ), NULL
345+ },
346+ { "print-fifo" , 'P' , 0 , G_OPTION_ARG_NONE , & show_fifo ,
347+ N_ ("Print the debug FIFO's file name then quit" ), NULL
348+ },
345349 { "emulate" , 'e' , 0 , G_OPTION_ARG_NONE , & emulate ,
346350 N_ ("Don't apply any rules, only emulate execution" ), NULL
347351 },
@@ -383,6 +387,12 @@ int main(int argc, char *argv[])
383387 printf ("\n" );
384388 exit (EXIT_FAILURE );
385389 }
390+
391+ if (show_fifo ) {
392+ puts (logger_get_fifo_name ());
393+ exit (EXIT_SUCCESS );
394+ }
395+
386396 gboolean shown = FALSE;
387397 if (show_version ) {
388398 printf ("Devilspie2 v%s\n" , DEVILSPIE2_VERSION );
@@ -503,9 +513,11 @@ int main(int argc, char *argv[])
503513 (gpointer )(config_filename ));
504514
505515 global_lua_state = init_script (script_folder );
516+ if (logtofifo )
517+ logger_create (global_lua_state );
506518 print_script_lists ();
507519
508- if ( debug ) printf ("------------\n" );
520+ logger_print ("------------\n" );
509521
510522 // remove stuff cleanly
511523 atexit (devilspie_exit );
0 commit comments