~ubuntu-branches/debian/stretch/nano/stretch

« back to all changes in this revision

Viewing changes to src/nano.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach
  • Date: 2015-07-06 14:05:33 UTC
  • mfrom: (1.3.5)
  • Revision ID: package-import@ubuntu.com-20150706140533-atf2ip59pqbspkjo
Tags: 2.4.2-1
* The "Acord del Botànic" release.
* New upstream release.
  - Includes many improvements to syntax hightlighting definitions
    (closes: #664456, #688892, #744005, #783763, #785508, #788318, #790017).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: nano.c 5166 2015-03-27 13:46:50Z bens $ */
 
1
/* $Id: nano.c 5265 2015-06-20 18:48:43Z bens $ */
2
2
/**************************************************************************
3
3
 *   nano.c                                                               *
4
4
 *                                                                        *
25
25
 
26
26
#include <stdio.h>
27
27
#include <stdarg.h>
28
 
#include <signal.h>
29
28
#include <unistd.h>
30
29
#include <string.h>
31
30
#include <fcntl.h>
124
123
{
125
124
    assert(fileptr != NULL && fileptr->data != NULL);
126
125
 
127
 
    if (fileptr->data != NULL)
128
 
        free(fileptr->data);
129
 
 
 
126
    free(fileptr->data);
130
127
#ifndef DISABLE_COLOR
131
 
    if (fileptr->multidata)
132
 
        free(fileptr->multidata);
 
128
    free(fileptr->multidata);
133
129
#endif
134
 
 
135
130
    free(fileptr);
136
131
}
137
132
 
556
551
/* Unlink a node from the rest of the openfilestruct, and delete it. */
557
552
void unlink_opennode(openfilestruct *fileptr)
558
553
{
559
 
    assert(fileptr != NULL && fileptr->prev != NULL && fileptr->next != NULL && fileptr != fileptr->prev && fileptr != fileptr->next);
 
554
    assert(fileptr != NULL && fileptr->prev != NULL && fileptr->next != NULL &&
 
555
                 fileptr != fileptr->prev && fileptr != fileptr->next);
560
556
 
561
557
    fileptr->prev->next = fileptr->next;
562
558
    fileptr->next->prev = fileptr->prev;
572
568
    free(fileptr->filename);
573
569
    free_filestruct(fileptr->fileage);
574
570
#ifndef NANO_TINY
575
 
    if (fileptr->current_stat != NULL)
576
 
        free(fileptr->current_stat);
 
571
    free(fileptr->current_stat);
577
572
#endif
578
 
 
579
573
    free(fileptr);
580
574
}
581
575
 
851
845
    print_opt(_("-C <dir>"), _("--backupdir=<dir>"),
852
846
        N_("Directory for saving unique backup files"));
853
847
#endif
854
 
    print_opt("-D", "--boldtext",
855
 
        N_("Use bold instead of reverse video text"));
 
848
    print_opt("-D", "--boldtext", N_("Use bold instead of reverse video text"));
856
849
#ifndef NANO_TINY
857
 
    print_opt("-E", "--tabstospaces",
858
 
        N_("Convert typed tabs to spaces"));
 
850
    print_opt("-E", "--tabstospaces", N_("Convert typed tabs to spaces"));
859
851
#endif
860
852
#ifndef DISABLE_MULTIBUFFER
861
 
    print_opt("-F", "--multibuffer", N_("Enable multiple file buffers"));
 
853
    print_opt("-F", "--multibuffer",
 
854
        N_("Read a file into a new buffer by default"));
862
855
#endif
863
856
#ifndef NANO_TINY
864
 
    print_opt("-G", "--locking",
865
 
        N_("Use (vim-style) lock files"));
 
857
    print_opt("-G", "--locking", N_("Use (vim-style) lock files"));
866
858
#endif
867
859
#ifndef DISABLE_HISTORIES
868
860
    print_opt("-H", "--historylog",
869
861
        N_("Log & read search/replace string history"));
870
862
#endif
871
863
#ifndef DISABLE_NANORC
872
 
    print_opt("-I", "--ignorercfiles",
873
 
        N_("Don't look at nanorc files"));
 
864
    print_opt("-I", "--ignorercfiles", N_("Don't look at nanorc files"));
874
865
#endif
875
866
    print_opt("-K", "--rebindkeypad",
876
867
        N_("Fix numeric keypad key confusion problem"));
882
873
#endif
883
874
    print_opt("-O", "--morespace", N_("Use one more line for editing"));
884
875
#ifndef DISABLE_HISTORIES
885
 
    print_opt("-P", "--poslog",
886
 
        N_("Log & read location of cursor position"));
 
876
    print_opt("-P", "--poslog", N_("Log & read location of cursor position"));
887
877
#endif
888
878
#ifndef DISABLE_JUSTIFY
889
 
    print_opt(_("-Q <str>"), _("--quotestr=<str>"),
890
 
        N_("Quoting string"));
 
879
    print_opt(_("-Q <str>"), _("--quotestr=<str>"), N_("Quoting string"));
891
880
#endif
892
881
    print_opt("-R", "--restricted", N_("Restricted mode"));
893
882
#ifndef NANO_TINY
894
 
    print_opt("-S", "--smooth",
895
 
        N_("Scroll by line instead of half-screen"));
 
883
    print_opt("-S", "--smooth", N_("Scroll by line instead of half-screen"));
896
884
#endif
897
885
    print_opt(_("-T <#cols>"), _("--tabsize=<#cols>"),
898
886
        N_("Set width of a tab to #cols columns"));
899
887
#ifndef NANO_TINY
900
888
    print_opt("-U", "--quickblank", N_("Do quick statusbar blanking"));
901
889
#endif
902
 
    print_opt("-V", "--version",
903
 
        N_("Print version information and exit"));
 
890
    print_opt("-V", "--version", N_("Print version information and exit"));
904
891
#ifndef NANO_TINY
905
892
    print_opt("-W", "--wordbounds",
906
893
        N_("Detect word boundaries more accurately"));
914
901
        N_("Fix Backspace/Delete confusion problem"));
915
902
    print_opt("-h", "--help", N_("Show this help text"));
916
903
#ifndef NANO_TINY
917
 
    print_opt("-i", "--autoindent",
918
 
        N_("Automatically indent new lines"));
 
904
    print_opt("-i", "--autoindent", N_("Automatically indent new lines"));
919
905
    print_opt("-k", "--cut", N_("Cut from cursor to end of line"));
920
906
#endif
921
 
    print_opt("-l", "--nofollow",
922
 
        N_("Don't follow symbolic links, overwrite"));
 
907
    print_opt("-l", "--nofollow", N_("Don't follow symbolic links, overwrite"));
923
908
#ifndef DISABLE_MOUSE
924
909
    print_opt("-m", "--mouse", N_("Enable the use of the mouse"));
925
910
#endif
928
913
    print_opt(_("-o <dir>"), _("--operatingdir=<dir>"),
929
914
        N_("Set operating directory"));
930
915
#endif
931
 
    print_opt("-p", "--preserve",
932
 
        N_("Preserve XON (^Q) and XOFF (^S) keys"));
 
916
    print_opt("-p", "--preserve", N_("Preserve XON (^Q) and XOFF (^S) keys"));
933
917
#ifndef DISABLE_NANORC
934
918
    print_opt("-q", "--quiet",
935
919
        N_("Silently ignore startup issues like rc file errors"));
942
926
    print_opt(_("-s <prog>"), _("--speller=<prog>"),
943
927
        N_("Enable alternate speller"));
944
928
#endif
945
 
    print_opt("-t", "--tempfile",
946
 
        N_("Auto save on exit, don't prompt"));
 
929
    print_opt("-t", "--tempfile", N_("Auto save on exit, don't prompt"));
947
930
    print_opt("-v", "--view", N_("View mode (read-only)"));
948
931
#ifndef DISABLE_WRAPPING
949
932
    print_opt("-w", "--nowrap", N_("Don't hard-wrap long lines"));
1167
1150
    ;
1168
1151
}
1169
1152
 
1170
 
static struct sigaction pager_oldaction, pager_newaction;  /* Original and temporary handlers for SIGINT. */
1171
 
static bool pager_sig_failed = FALSE; /* Did sigaction() fail without changing the signal handlers? */
1172
 
static bool pager_input_aborted = FALSE; /* Did someone invoke the pager and abort it via ^C? */
 
1153
static struct sigaction pager_oldaction, pager_newaction;
 
1154
        /* Original and temporary handlers for SIGINT. */
 
1155
static bool pager_sig_failed = FALSE;
 
1156
        /* Did sigaction() fail without changing the signal handlers? */
 
1157
static bool pager_input_aborted = FALSE;
 
1158
        /* Did someone invoke the pager and abort it via ^C? */
1173
1159
 
1174
1160
/* Things which need to be run regardless of whether
1175
1161
 * we finished the stdin pipe correctly or not. */
1237
1223
/* Initialize the signal handlers. */
1238
1224
void signal_init(void)
1239
1225
{
1240
 
    /* Trap SIGINT and SIGQUIT because we want them to do useful
1241
 
     * things. */
 
1226
    /* Trap SIGINT and SIGQUIT because we want them to do useful things. */
1242
1227
    memset(&act, 0, sizeof(struct sigaction));
1243
1228
    act.sa_handler = SIG_IGN;
1244
1229
    sigaction(SIGINT, &act, NULL);
1253
1238
    /* Trap SIGWINCH because we want to handle window resizes. */
1254
1239
    act.sa_handler = handle_sigwinch;
1255
1240
    sigaction(SIGWINCH, &act, NULL);
1256
 
    allow_pending_sigwinch(FALSE);
1257
1241
#endif
1258
1242
 
1259
1243
    /* Trap normal suspend (^Z) so we can handle it ourselves. */
1313
1297
    kill(0, SIGSTOP);
1314
1298
}
1315
1299
 
1316
 
/* the subnfunc version */
 
1300
/* The version of above function that is bound to a key. */
1317
1301
void do_suspend_void(void)
1318
1302
{
1319
1303
    if (ISSET(SUSPEND))
1352
1336
/* Handler for SIGWINCH (window size change). */
1353
1337
RETSIGTYPE handle_sigwinch(int signal)
1354
1338
{
 
1339
    /* Let the input routine know that a SIGWINCH has occurred. */
 
1340
    sigwinch_counter++;
 
1341
}
 
1342
 
 
1343
/* Reinitialize and redraw the screen completely. */
 
1344
void regenerate_screen(void)
 
1345
{
1355
1346
    const char *tty = ttyname(0);
1356
1347
    int fd, result = 0;
1357
1348
    struct winsize win;
1375
1366
    LINES = win.ws_row;
1376
1367
#endif
1377
1368
 
1378
 
    /* If we've partitioned the filestruct, unpartition it now. */
1379
 
    if (filepart != NULL)
1380
 
        unpartition_filestruct(&filepart);
1381
 
 
1382
1369
#ifdef USE_SLANG
1383
1370
    /* Slang curses emulation brain damage, part 1: If we just do what
1384
1371
     * curses does here, it'll only work properly if the resize made the
1405
1392
    window_init();
1406
1393
 
1407
1394
    /* Redraw the contents of the windows that need it. */
1408
 
    blank_statusbar();
1409
 
    wnoutrefresh(bottomwin);
1410
 
    currmenu = MMAIN;
1411
1395
    total_refresh();
1412
 
 
1413
 
    /* Jump back to either main() or the unjustify routine in
1414
 
     * do_justify(). */
1415
 
    siglongjmp(jump_buf, 1);
1416
1396
}
1417
1397
 
1418
1398
/* If allow is TRUE, block any SIGWINCH signals that we get, so that we
1607
1587
    /* Read in a character. */
1608
1588
    input = get_kbinput(edit);
1609
1589
 
 
1590
#ifndef NANO_TINY
 
1591
    if (input == KEY_WINCH)
 
1592
        return KEY_WINCH;
 
1593
#endif
 
1594
 
1610
1595
#ifndef DISABLE_MOUSE
1611
1596
    if (func_key && input == KEY_MOUSE) {
1612
1597
        /* We received a mouse click. */
2118
2103
#endif
2119
2104
#ifdef HAVE_GETOPT_LONG
2120
2105
    const struct option long_options[] = {
2121
 
        {"help", 0, NULL, 'h'},
2122
2106
        {"boldtext", 0, NULL, 'D'},
2123
2107
#ifndef DISABLE_MULTIBUFFER
2124
2108
        {"multibuffer", 0, NULL, 'F'},
2140
2124
#endif
2141
2125
        {"const", 0, NULL, 'c'},
2142
2126
        {"rebinddelete", 0, NULL, 'd'},
 
2127
        {"help", 0, NULL, 'h'},
2143
2128
        {"nofollow", 0, NULL, 'l'},
2144
2129
#ifndef DISABLE_MOUSE
2145
2130
        {"mouse", 0, NULL, 'm'},
2174
2159
        {"poslog", 0, NULL, 'P'},
2175
2160
        {"smooth", 0, NULL, 'S'},
2176
2161
        {"quickblank", 0, NULL, 'U'},
2177
 
        {"undo", 0, NULL, 'u'},
2178
2162
        {"wordbounds", 0, NULL, 'W'},
2179
2163
        {"autoindent", 0, NULL, 'i'},
2180
2164
        {"cut", 0, NULL, 'k'},
2647
2631
#endif /* !DISABLE_NANORC */
2648
2632
#endif /* !NANO_TINY */
2649
2633
 
 
2634
    /* Initialize the search and replace strings. */
 
2635
    last_search = mallocstrcpy(NULL, "");
 
2636
    last_replace = mallocstrcpy(NULL, "");
 
2637
 
2650
2638
    /* If tabsize wasn't specified, set its default value. */
2651
2639
    if (tabsize == -1)
2652
2640
        tabsize = WIDTH_OF_TAB;
2802
2790
        reset_cursor();
2803
2791
        wnoutrefresh(edit);
2804
2792
 
2805
 
#ifndef NANO_TINY
2806
 
        if (!jump_buf_main) {
2807
 
            /* If we haven't already, we're going to set jump_buf so
2808
 
             * that we return here after a SIGWINCH.  Indicate this. */
2809
 
            jump_buf_main = TRUE;
2810
 
 
2811
 
            /* Return here after a SIGWINCH. */
2812
 
            sigsetjmp(jump_buf, 1);
2813
 
        }
2814
 
#endif
2815
 
 
2816
2793
        /* Just in case we were at the statusbar prompt, make sure the
2817
2794
         * statusbar cursor position is reset. */
2818
2795
        do_prompt_abort();