~ubuntu-branches/ubuntu/wily/weechat/wily

« back to all changes in this revision

Viewing changes to src/core/weechat.c

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bouthenot
  • Date: 2014-09-28 17:41:10 UTC
  • mfrom: (29.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20140928174110-bwlsn7gqmqfftnmb
Tags: 1.0.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ##########################################################################
 
1
/*
 
2
 * ##########################################################################
2
3
 * ##          ___       __         ______________        _____            ##
3
4
 * ##          __ |     / /___________  ____/__  /_______ __  /_           ##
4
5
 * ##          __ | /| / /_  _ \  _ \  /    __  __ \  __ `/  __/           ##
10
11
 * ##                                                                      ##
11
12
 * ##             By Sébastien Helleu <flashcode@flashtux.org>             ##
12
13
 * ##                                                                      ##
13
 
 * ##                      http://www.weechat.org/                         ##
 
14
 * ##                        http://weechat.org/                           ##
14
15
 * ##                                                                      ##
15
16
 * ##########################################################################
16
17
 *
161
162
{
162
163
    int i;
163
164
 
164
 
    weechat_argv0 = strdup (argv[0]);
 
165
    weechat_argv0 = (argv && argv[0]) ? strdup (argv[0]) : NULL;
165
166
    weechat_upgrading = 0;
166
167
    weechat_home = NULL;
167
168
    weechat_server_cmd_line = 0;
385
386
}
386
387
 
387
388
/*
 
389
 * Displays warnings about $TERM if it is detected as wrong.
 
390
 *
 
391
 * If $TERM is different from "screen" or "screen-256color" and that $STY is
 
392
 * set (GNU screen) or $TMUX is set (tmux), then a warning is displayed.
 
393
 */
 
394
 
 
395
void
 
396
weechat_term_check ()
 
397
{
 
398
    char *term, *sty, *tmux;
 
399
    int is_term_ok, is_screen, is_tmux;
 
400
 
 
401
    term = getenv ("TERM");
 
402
    sty = getenv ("STY");
 
403
    tmux = getenv ("TMUX");
 
404
 
 
405
    is_term_ok = (term && (strncmp (term, "screen", 6) == 0));
 
406
    is_screen = (sty && sty[0]);
 
407
    is_tmux = (tmux && tmux[0]);
 
408
 
 
409
    if ((is_screen || is_tmux) && !is_term_ok)
 
410
    {
 
411
        gui_chat_printf (
 
412
            NULL,
 
413
            /* TRANSLATORS: the "under %s" can be "under screen" or "under tmux" */
 
414
            _("%sWarning: WeeChat is running under %s and $TERM is \"%s\", "
 
415
              "which can cause display bugs; $TERM should be set to "
 
416
              "\"screen-256color\" or \"screen\""),
 
417
            gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
 
418
            (is_screen) ? "screen" : "tmux",
 
419
            (term) ? term : "");
 
420
        gui_chat_printf (
 
421
            NULL,
 
422
            _("%sYou should add this line in the file %s:  %s"),
 
423
            gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
 
424
            (is_screen) ? "~/.screenrc" : "~/.tmux.conf",
 
425
            (is_screen) ?
 
426
            "term screen-256color" :
 
427
            "set -g default-terminal \"screen-256color\"");
 
428
    }
 
429
}
 
430
 
 
431
/*
 
432
 * Callback for system signal SIGHUP: quits WeeChat.
 
433
 */
 
434
 
 
435
void
 
436
weechat_sighup ()
 
437
{
 
438
    log_printf (_("Signal %s received, exiting WeeChat..."), "SIGHUP");
 
439
    (void) hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, NULL);
 
440
    weechat_quit = 1;
 
441
}
 
442
 
 
443
/*
 
444
 * Callback for system signal SIGQUIT: quits WeeChat.
 
445
 */
 
446
 
 
447
void
 
448
weechat_sigquit ()
 
449
{
 
450
    log_printf (_("Signal %s received, exiting WeeChat..."), "SIGQUIT");
 
451
    (void) hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, NULL);
 
452
    weechat_quit = 1;
 
453
}
 
454
 
 
455
/*
 
456
 * Callback for system signal SIGTERM: quits WeeChat.
 
457
 */
 
458
 
 
459
void
 
460
weechat_sigterm ()
 
461
{
 
462
    log_printf (_("Signal %s received, exiting WeeChat..."), "SIGTERM");
 
463
    (void) hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, NULL);
 
464
    weechat_quit = 1;
 
465
}
 
466
 
 
467
/*
388
468
 * Shutdowns WeeChat.
389
469
 */
390
470
 
405
485
 
406
486
    if (crash)
407
487
        abort();
408
 
    else
 
488
    else if (return_code >= 0)
409
489
        exit (return_code);
410
490
}
411
491
 
412
492
/*
413
 
 * Entry point for WeeChat.
 
493
 * Initializes WeeChat.
414
494
 */
415
495
 
416
 
int
417
 
main (int argc, char *argv[])
 
496
void
 
497
weechat_init (int argc, char *argv[], void (*gui_init_cb)())
418
498
{
419
499
    weechat_first_start_time = time (NULL); /* initialize start time        */
420
500
    gettimeofday (&weechat_current_start_timeval, NULL);
433
513
#endif
434
514
    utf8_init ();
435
515
 
436
 
    util_catch_signal (SIGINT, SIG_IGN);  /* ignore SIGINT signal           */
437
 
    util_catch_signal (SIGQUIT, SIG_IGN); /* ignore SIGQUIT signal          */
438
 
    util_catch_signal (SIGPIPE, SIG_IGN); /* ignore SIGPIPE signal          */
439
 
    util_catch_signal (SIGSEGV,
440
 
                       &debug_sigsegv); /* crash dump for SIGSEGV signal    */
 
516
    /* catch signals */
 
517
    util_catch_signal (SIGINT, SIG_IGN);           /* signal ignored        */
 
518
    util_catch_signal (SIGQUIT, SIG_IGN);          /* signal ignored        */
 
519
    util_catch_signal (SIGPIPE, SIG_IGN);          /* signal ignored        */
 
520
    util_catch_signal (SIGSEGV, &debug_sigsegv);   /* crash dump            */
 
521
    util_catch_signal (SIGHUP, &weechat_sighup);   /* exit WeeChat          */
 
522
    util_catch_signal (SIGQUIT, &weechat_sigquit); /* exit WeeChat          */
 
523
    util_catch_signal (SIGTERM, &weechat_sigterm); /* exit WeeChat          */
 
524
 
441
525
    hdata_init ();                      /* initialize hdata                 */
442
526
    hook_init ();                       /* initialize hooks                 */
443
527
    debug_init ();                      /* hook signals for debug           */
444
 
    gui_main_pre_init (&argc, &argv);   /* pre-initialize interface         */
 
528
    gui_color_init ();                  /* initialize colors                */
 
529
    gui_chat_init ();                   /* initialize chat                  */
445
530
    command_init ();                    /* initialize WeeChat commands      */
446
531
    completion_init ();                 /* add core completion hooks        */
447
532
    gui_key_init ();                    /* init keys                        */
457
542
    secure_read ();                     /* read secured data options        */
458
543
    config_weechat_read ();             /* read WeeChat options             */
459
544
    network_init_gnutls ();             /* init GnuTLS                      */
460
 
    gui_main_init ();                   /* init WeeChat interface           */
 
545
 
 
546
    if (gui_init_cb)
 
547
        (*gui_init_cb) ();              /* init WeeChat interface           */
 
548
 
461
549
    if (weechat_upgrading)
462
550
    {
463
551
        upgrade_weechat_load ();        /* upgrade with session file        */
465
553
    }
466
554
    weechat_welcome_message ();         /* display WeeChat welcome message  */
467
555
    gui_chat_print_lines_waiting_buffer (NULL); /* display lines waiting    */
 
556
    weechat_term_check ();              /* warnings about $TERM (if wrong)  */
468
557
    command_startup (0);                /* command executed before plugins  */
469
558
    plugin_init (weechat_auto_load_plugins, /* init plugin interface(s)     */
470
559
                 argc, argv);
473
562
        gui_layout_window_apply (gui_layout_current, -1);
474
563
    if (weechat_upgrading)
475
564
        upgrade_weechat_end ();         /* remove .upgrade files + signal   */
476
 
 
477
 
    gui_main_loop ();                   /* WeeChat main loop                */
478
 
 
 
565
}
 
566
 
 
567
/*
 
568
 * Ends WeeChat.
 
569
 */
 
570
 
 
571
void
 
572
weechat_end (void (*gui_end_cb)(int clean_exit))
 
573
{
479
574
    gui_layout_store_on_exit ();        /* store layout                     */
480
575
    plugin_end ();                      /* end plugin interface(s)          */
481
576
    if (CONFIG_BOOLEAN(config_look_save_config_on_exit))
482
577
        (void) config_weechat_write (); /* save WeeChat config file         */
483
578
    (void) secure_write ();             /* save secured data                */
484
 
    gui_main_end (1);                   /* shut down WeeChat GUI            */
 
579
 
 
580
    if (gui_end_cb)
 
581
        (*gui_end_cb) (1);              /* shut down WeeChat GUI            */
 
582
 
485
583
    proxy_free_all ();                  /* free all proxies                 */
486
584
    config_weechat_free ();             /* free WeeChat options             */
487
585
    secure_free ();                     /* free secured data options        */
489
587
    gui_key_end ();                     /* remove all keys                  */
490
588
    unhook_all ();                      /* remove all hooks                 */
491
589
    hdata_end ();                       /* end hdata                        */
492
 
    eval_end ();                        /* end eval                         */
493
590
    secure_end ();                      /* end secured data                 */
494
591
    string_end ();                      /* end string                       */
495
 
    weechat_shutdown (EXIT_SUCCESS, 0); /* quit WeeChat (oh no, why?)       */
496
 
 
497
 
    return EXIT_SUCCESS;                /* make C compiler happy            */
 
592
    weechat_shutdown (-1, 0);           /* end other things                 */
498
593
}