extsay-ng/extsayng.c
changeset 24 81cbb47f1aa6
parent 23 cf95a475825c
child 25 a98004eb58cd
equal deleted inserted replaced
23:cf95a475825c 24:81cbb47f1aa6
    42         .init           = extsayng_init,
    42         .init           = extsayng_init,
    43         .uninit         = extsayng_uninit,
    43         .uninit         = extsayng_uninit,
    44         .next           = NULL,
    44         .next           = NULL,
    45 };
    45 };
    46 
    46 
    47 // Forks and run the external helper script
    47 
       
    48 // Run the external helper script with parameters
    48 static void screen_run_script(const gchar *args)
    49 static void screen_run_script(const gchar *args)
    49 {
    50 {
    50   GError *err = NULL;
    51   GError *err = NULL;
    51   gchar *argv[] = { "screen", "-r", "-X", "screen", NULL, NULL, NULL };
    52   gchar *argv[] = { "screen", "-r", "-X", "screen", NULL,
       
    53                     NULL, NULL, NULL, NULL };
    52   gboolean ret;
    54   gboolean ret;
       
    55   gchar strwinheight[32];
       
    56   gboolean winsplit = settings_opt_get_int("extsay_split_win");
    53 
    57 
    54   // screen -r -X screen $path/extsay.sh
    58   // screen -r -X screen $path/extsay.sh [jid [winsplit [height]]]
    55   argv[4] = (gchar*)settings_opt_get("extsay_script_path");
    59   argv[4] = (gchar*)settings_opt_get("extsay_script_path");
    56 
    60 
       
    61   // Helper script path
    57   if (!argv[4] || !argv[4][0]) {
    62   if (!argv[4] || !argv[4][0]) {
    58     scr_log_print(LPRINT_NORMAL, "Please set option 'extsay_script_path'.");
    63     scr_log_print(LPRINT_NORMAL, "Please set option 'extsay_script_path'.");
    59     return;
    64     return;
    60   }
    65   }
    61 
    66 
       
    67   // Helper script parameter #1
    62   if (args && *args)
    68   if (args && *args)
    63     argv[5] = (gchar*)args;
    69     argv[5] = (gchar*)args;
    64   else
    70   else
    65     argv[5] = ".";
    71     argv[5] = ".";
       
    72 
       
    73   // Update environment variables for the helper script
       
    74   if (winsplit) {
       
    75     gint winheight = settings_opt_get_int("extsay_win_height");
       
    76     argv[6] = "winsplit";       // Helper script parameter #2
       
    77     if (winheight > 0 && winheight < 256) {
       
    78       snprintf(strwinheight, sizeof strwinheight, "%d", winheight);
       
    79       argv[7] = strwinheight;   // Helper script parameter #3
       
    80     }
       
    81   }
    66 
    82 
    67   ret = g_spawn_async(NULL, argv, NULL,
    83   ret = g_spawn_async(NULL, argv, NULL,
    68                       G_SPAWN_SEARCH_PATH |
    84                       G_SPAWN_SEARCH_PATH |
    69                         G_SPAWN_STDOUT_TO_DEV_NULL|G_SPAWN_STDERR_TO_DEV_NULL,
    85                         G_SPAWN_STDOUT_TO_DEV_NULL|G_SPAWN_STDERR_TO_DEV_NULL,
    70                       NULL, NULL, NULL, &err);
    86                       NULL, NULL, NULL, &err);