Deleted Added
full compact
cmdbuf.c (170965) cmdbuf.c (191930)
1/*
1/*
2 * Copyright (C) 1984-2007 Mark Nudelman
2 * Copyright (C) 1984-2008 Mark Nudelman
3 *
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
6 *
7 * For more information about less, or for information on how to
8 * contact the author, see the README file.
9 */
10

--- 646 unchanged lines hidden (view full) ---

657/*
658 * Select an mlist structure to be the current command history.
659 */
660 public void
661set_mlist(mlist, cmdflags)
662 void *mlist;
663 int cmdflags;
664{
3 *
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
6 *
7 * For more information about less, or for information on how to
8 * contact the author, see the README file.
9 */
10

--- 646 unchanged lines hidden (view full) ---

657/*
658 * Select an mlist structure to be the current command history.
659 */
660 public void
661set_mlist(mlist, cmdflags)
662 void *mlist;
663 int cmdflags;
664{
665#if CMD_HISTORY
665 curr_mlist = (struct mlist *) mlist;
666 curr_cmdflags = cmdflags;
667
668 /* Make sure the next up-arrow moves to the last string in the mlist. */
669 if (curr_mlist != NULL)
670 curr_mlist->curr_mp = curr_mlist;
666 curr_mlist = (struct mlist *) mlist;
667 curr_cmdflags = cmdflags;
668
669 /* Make sure the next up-arrow moves to the last string in the mlist. */
670 if (curr_mlist != NULL)
671 curr_mlist->curr_mp = curr_mlist;
672#endif
671}
672
673#if CMD_HISTORY
674/*
675 * Move up or down in the currently selected command history list.
676 */
677 static int
678cmd_updown(action)

--- 619 unchanged lines hidden (view full) ---

1298 * Return a pointer to the command buffer.
1299 */
1300 public char *
1301get_cmdbuf()
1302{
1303 return (cmdbuf);
1304}
1305
673}
674
675#if CMD_HISTORY
676/*
677 * Move up or down in the currently selected command history list.
678 */
679 static int
680cmd_updown(action)

--- 619 unchanged lines hidden (view full) ---

1300 * Return a pointer to the command buffer.
1301 */
1302 public char *
1303get_cmdbuf()
1304{
1305 return (cmdbuf);
1306}
1307
1308#if CMD_HISTORY
1306/*
1307 * Return the last (most recent) string in the current command history.
1308 */
1309 public char *
1310cmd_lastpattern()
1311{
1312 if (curr_mlist == NULL)
1313 return (NULL);
1314 return (curr_mlist->curr_mp->prev->string);
1315}
1309/*
1310 * Return the last (most recent) string in the current command history.
1311 */
1312 public char *
1313cmd_lastpattern()
1314{
1315 if (curr_mlist == NULL)
1316 return (NULL);
1317 return (curr_mlist->curr_mp->prev->string);
1318}
1319#endif
1316
1317#if CMD_HISTORY
1318/*
1319 * Get the name of the history file.
1320 */
1321 static char *
1322histfile_name()
1323{

--- 136 unchanged lines hidden (view full) ---

1460#endif
1461 if (!modified)
1462 return;
1463 f = fopen(filename, "w");
1464 free(filename);
1465 if (f == NULL)
1466 return;
1467#if HAVE_FCHMOD
1320
1321#if CMD_HISTORY
1322/*
1323 * Get the name of the history file.
1324 */
1325 static char *
1326histfile_name()
1327{

--- 136 unchanged lines hidden (view full) ---

1464#endif
1465 if (!modified)
1466 return;
1467 f = fopen(filename, "w");
1468 free(filename);
1469 if (f == NULL)
1470 return;
1471#if HAVE_FCHMOD
1472{
1468 /* Make history file readable only by owner. */
1473 /* Make history file readable only by owner. */
1469 fchmod(fileno(f), 0600);
1474 int do_chmod = 1;
1475#if HAVE_STAT
1476 struct stat statbuf;
1477 int r = fstat(fileno(f), &statbuf);
1478 if (r < 0 || !S_ISREG(statbuf.st_mode))
1479 /* Don't chmod if not a regular file. */
1480 do_chmod = 0;
1470#endif
1481#endif
1482 if (do_chmod)
1483 fchmod(fileno(f), 0600);
1484}
1485#endif
1471
1472 fprintf(f, "%s\n", HISTFILE_FIRST_LINE);
1473
1474 fprintf(f, "%s\n", HISTFILE_SEARCH_SECTION);
1475 save_mlist(&mlist_search, f);
1476
1477#if SHELL_ESCAPE || PIPEC
1478 fprintf(f, "%s\n", HISTFILE_SHELL_SECTION);
1479 save_mlist(&mlist_shell, f);
1480#endif
1481
1482 fclose(f);
1483#endif /* CMD_HISTORY */
1484}
1486
1487 fprintf(f, "%s\n", HISTFILE_FIRST_LINE);
1488
1489 fprintf(f, "%s\n", HISTFILE_SEARCH_SECTION);
1490 save_mlist(&mlist_search, f);
1491
1492#if SHELL_ESCAPE || PIPEC
1493 fprintf(f, "%s\n", HISTFILE_SHELL_SECTION);
1494 save_mlist(&mlist_shell, f);
1495#endif
1496
1497 fclose(f);
1498#endif /* CMD_HISTORY */
1499}