~ubuntu-branches/ubuntu/saucy/nano/saucy

« back to all changes in this revision

Viewing changes to src/rcfile.c

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach
  • Date: 2009-12-01 20:59:14 UTC
  • mfrom: (1.2.5 upstream) (17.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20091201205914-k0hydhsoysp7tahr
Tags: 2.2.0-1
* The "Televisió Sense Fronteres" release.
* New upstream stable release!
* Remove patch 10_tinybuildfix, applied upstream.
* Update 01_manpage_hyphens, as it's been applied only partially upstream.
* Remove French manpages from nano, until they are back in sync with the
  original versions (§12.1, Policy 3.8.3).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: rcfile.c 4416 2009-11-03 19:31:17Z astyanax $ */
 
1
/* $Id: rcfile.c 4445 2009-11-27 05:09:56Z astyanax $ */
2
2
/**************************************************************************
3
3
 *   rcfile.c                                                             *
4
4
 *                                                                        *
454
454
        return;
455
455
    }
456
456
 
457
 
 
458
457
    /* now let's have some fun.  Try and delete the other entries
459
458
       we found for the same menu, then make this new new
460
459
       beginning */
470
469
    sclist = newsc;
471
470
}
472
471
 
 
472
/* Let user unbind a sequence from a given (or all) menus */
 
473
void parse_unbinding(char *ptr)
 
474
{
 
475
    char *keyptr = NULL, *keycopy = NULL, *menuptr = NULL;
 
476
    sc *s;
 
477
    int i, menu;
 
478
 
 
479
    assert(ptr != NULL);
 
480
 
 
481
    if (*ptr == '\0') {
 
482
        rcfile_error(N_("Missing key name"));
 
483
        return;
 
484
    }
 
485
 
 
486
    keyptr = ptr;
 
487
    ptr = parse_next_word(ptr);
 
488
    keycopy = mallocstrcpy(NULL, keyptr);
 
489
    for (i = 0; i < strlen(keycopy); i++)
 
490
        keycopy[i] = toupper(keycopy[i]);
 
491
 
 
492
#ifdef DEBUG
 
493
    fprintf(stderr, "Starting unbinding code");
 
494
#endif
 
495
 
 
496
    if (keycopy[0] != 'M' && keycopy[0] != '^' && keycopy[0] != 'F' && keycopy[0] != 'K') {
 
497
        rcfile_error(
 
498
                N_("keybindings must begin with \"^\", \"M\", or \"F\""));
 
499
        return;
 
500
    }
 
501
 
 
502
    menuptr = ptr;
 
503
    ptr = parse_next_word(ptr);
 
504
 
 
505
    if (!strcmp(menuptr, "")) {
 
506
        rcfile_error(
 
507
                /* Note to translators, do not translate the word "all"
 
508
                   in the sentence below, everything else is fine */
 
509
                N_("Must specify menu to bind key to (or \"all\")"));
 
510
        return;
 
511
    }
 
512
 
 
513
    menu = strtomenu(menuptr);
 
514
    if (menu < 1) {
 
515
        rcfile_error(
 
516
                N_("Could not map name \"%s\" to a menu"), menuptr);
 
517
        return;
 
518
    }
 
519
 
 
520
 
 
521
#ifdef DEBUG
 
522
    fprintf(stderr, "unbinding \"%s\" from menu = %d\n", keycopy, menu);
 
523
#endif
 
524
 
 
525
    /* Now find the apropriate entries in the menu to delete */
 
526
    for (s = sclist; s != NULL; s = s->next) {
 
527
        if (((s->menu & menu)) && !strcmp(s->keystr,keycopy)) {
 
528
            s->menu &= ~menu;
 
529
#ifdef DEBUG
 
530
            fprintf(stderr, "deleted menu entry %d\n", s->menu);
 
531
#endif
 
532
        }
 
533
    }
 
534
}
 
535
 
473
536
 
474
537
/* Read and parse additional syntax files. */
475
538
void parse_include(char *ptr)
829
892
{
830
893
    char *buf = NULL;
831
894
    ssize_t len;
832
 
    size_t n;
 
895
    size_t n = 0;
833
896
 
834
897
    while ((len = getline(&buf, &n, rcstream)) > 0) {
835
898
        char *ptr, *keyword, *option;
895
958
            parse_colors(ptr, TRUE);
896
959
        else if (strcasecmp(keyword, "bind") == 0)
897
960
            parse_keybinding(ptr);
 
961
        else if (strcasecmp(keyword, "unbind") == 0)
 
962
            parse_unbinding(ptr);
898
963
#endif /* ENABLE_COLOR */
899
964
        else
900
965
            rcfile_error(N_("Command \"%s\" not understood"), keyword);