X-Git-Url: http://git.jankratochvil.net/?p=udpgate.git;a=blobdiff_plain;f=src%2Fmain.c;h=f649a3e8ede600d7912258053d4cac1de5ec98d4;hp=0f6b384d8a99312cecfe93167cc30c109fd00cd4;hb=211f9c64a1c533d99c3c05c4d7b1bcaffdb7dbff;hpb=3d744d1c39879ffe66a02e74172e861a6fe1d81c diff --git a/src/main.c b/src/main.c index 0f6b384..f649a3e 100644 --- a/src/main.c +++ b/src/main.c @@ -30,11 +30,24 @@ #include #include +#include "main.h" /* self */ #include "ui-gnome.h" +#include "ui-line.h" +#include "network.h" + + +/* Config: */ +#define LOCAL_PORT_DEFAULT 9201 -int optarg_verbose; static int optarg_text; +int optarg_verbose; +int optarg_port=LOCAL_PORT_DEFAULT; +static int optarg_start; +static int optarg_stop; +int optarg_no_fork; + +void (*ui_interactive)(void); static const struct poptOption popt_table[]={ @@ -49,9 +62,18 @@ static const struct poptOption popt_table[]={ argDescrip: (argDescripP), \ } - UDPGATE_POPT(0 ,"text" ,POPT_ARG_NONE ,&optarg_text ,0, + UDPGATE_POPT(0 ,"text" ,POPT_ARG_NONE ,&optarg_text ,0, N_("Disable Gnome UI; --text must be first argument"),NULL), - UDPGATE_POPT('v',"verbose" ,POPT_ARG_NONE ,&optarg_verbose,0,N_("Display additional debug information"),NULL), + UDPGATE_POPT('v',"verbose",POPT_ARG_NONE ,&optarg_verbose,0, + N_("Display additional debug information"),NULL), + UDPGATE_POPT('p',"port" ,POPT_ARG_INT |POPT_ARGFLAG_SHOW_DEFAULT,&optarg_port ,0, + N_("Listen on this UDP port"),NULL), + UDPGATE_POPT('s',"start" ,POPT_ARG_NONE ,&optarg_start ,0, + N_("Start the daemon"),NULL), + UDPGATE_POPT('S',"stop" ,POPT_ARG_NONE ,&optarg_stop ,0, + N_("Stop the daemon"),NULL), + UDPGATE_POPT('1',"no-fork",POPT_ARG_NONE ,&optarg_no_fork,0, + N_("Do not detach from the current process"),NULL), #undef UDPGATE_POPT POPT_TABLEEND @@ -167,21 +189,24 @@ guint handler_id; } is_interactive=(1 -/* && ! optarg_scan_path_list - && ! optarg_scan_disks_quick - && ! optarg_scan_disks - && ! optarg_microsoft_com */ ); + && !optarg_start + && !optarg_stop); /* Initialize UI here to catch all GLog errors below. */ if (is_interactive && (no_gnome || !ui_gnome_init()) -/* && !ui_line_init()*/) + && !ui_line_init()) g_error(_("No UI interface could be initialized")); - if (!is_interactive) - /*scan_batch()*/; + if (!is_interactive) { + if (optarg_stop) + network_stop(); + if (optarg_start) + network_start(optarg_port); + network_detach(); + } else - ui_gnome_interactive(); + (*ui_interactive)(); return EXIT_SUCCESS; }