Deleted Added
full compact
cmdbuf.c (161475) cmdbuf.c (170256)
1/*
1/*
2 * Copyright (C) 1984-2005 Mark Nudelman
2 * Copyright (C) 1984-2007 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

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

63 * A mlist structure represents a command history.
64 */
65struct mlist
66{
67 struct mlist *next;
68 struct mlist *prev;
69 struct mlist *curr_mp;
70 char *string;
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

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

63 * A mlist structure represents a command history.
64 */
65struct mlist
66{
67 struct mlist *next;
68 struct mlist *prev;
69 struct mlist *curr_mp;
70 char *string;
71 int modified;
71};
72
73/*
74 * These are the various command histories that exist.
75 */
76struct mlist mlist_search =
72};
73
74/*
75 * These are the various command histories that exist.
76 */
77struct mlist mlist_search =
77 { &mlist_search, &mlist_search, &mlist_search, NULL };
78 { &mlist_search, &mlist_search, &mlist_search, NULL, 0 };
78public void * constant ml_search = (void *) &mlist_search;
79
80struct mlist mlist_examine =
79public void * constant ml_search = (void *) &mlist_search;
80
81struct mlist mlist_examine =
81 { &mlist_examine, &mlist_examine, &mlist_examine, NULL };
82 { &mlist_examine, &mlist_examine, &mlist_examine, NULL, 0 };
82public void * constant ml_examine = (void *) &mlist_examine;
83
84#if SHELL_ESCAPE || PIPEC
85struct mlist mlist_shell =
83public void * constant ml_examine = (void *) &mlist_examine;
84
85#if SHELL_ESCAPE || PIPEC
86struct mlist mlist_shell =
86 { &mlist_shell, &mlist_shell, &mlist_shell, NULL };
87 { &mlist_shell, &mlist_shell, &mlist_shell, NULL, 0 };
87public void * constant ml_shell = (void *) &mlist_shell;
88#endif
89
90#else /* CMD_HISTORY */
91
92/* If CMD_HISTORY is off, these are just flags. */
93public void * constant ml_search = (void *)1;
94public void * constant ml_examine = (void *)2;

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

119 *cp = '\0';
120 cmd_col = 0;
121 cmd_offset = 0;
122 literal = 0;
123 cmd_mbc_buf_len = 0;
124}
125
126/*
88public void * constant ml_shell = (void *) &mlist_shell;
89#endif
90
91#else /* CMD_HISTORY */
92
93/* If CMD_HISTORY is off, these are just flags. */
94public void * constant ml_search = (void *)1;
95public void * constant ml_examine = (void *)2;

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

120 *cp = '\0';
121 cmd_col = 0;
122 cmd_offset = 0;
123 literal = 0;
124 cmd_mbc_buf_len = 0;
125}
126
127/*
127 * Clear command line on display.
128 * Clear command line.
128 */
129 public void
130clear_cmd()
131{
129 */
130 public void
131clear_cmd()
132{
132 clear_bot();
133 cmd_col = prompt_col = 0;
134 cmd_mbc_buf_len = 0;
135}
136
137/*
138 * Display a string, usually as a prompt for input into the command buffer.
139 */
140 public void

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

762{
763#if CMD_HISTORY
764 /*
765 * Nothing to do if there is no currently selected history list.
766 */
767 if (curr_mlist == NULL)
768 return;
769 cmd_addhist(curr_mlist, cmdbuf);
133 cmd_col = prompt_col = 0;
134 cmd_mbc_buf_len = 0;
135}
136
137/*
138 * Display a string, usually as a prompt for input into the command buffer.
139 */
140 public void

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

762{
763#if CMD_HISTORY
764 /*
765 * Nothing to do if there is no currently selected history list.
766 */
767 if (curr_mlist == NULL)
768 return;
769 cmd_addhist(curr_mlist, cmdbuf);
770 curr_mlist->modified = 1;
770#endif
771}
772
773/*
774 * Try to perform a line-edit function on the command buffer,
775 * using a specified char as a line-editing command.
776 * Returns:
777 * CC_PASS The char does not invoke a line edit function.

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

1270 */
1271 return (cmd_ichar(cmd_mbc_buf, len));
1272}
1273
1274/*
1275 * Return the number currently in the command buffer.
1276 */
1277 public LINENUM
771#endif
772}
773
774/*
775 * Try to perform a line-edit function on the command buffer,
776 * using a specified char as a line-editing command.
777 * Returns:
778 * CC_PASS The char does not invoke a line edit function.

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

1271 */
1272 return (cmd_ichar(cmd_mbc_buf, len));
1273}
1274
1275/*
1276 * Return the number currently in the command buffer.
1277 */
1278 public LINENUM
1278cmd_int()
1279cmd_int(frac)
1280 long *frac;
1279{
1281{
1280 register char *p;
1282 char *p;
1281 LINENUM n = 0;
1283 LINENUM n = 0;
1284 int err;
1282
1285
1283 for (p = cmdbuf; *p != '\0'; p++)
1284 n = (10 * n) + (*p - '0');
1286 for (p = cmdbuf; *p >= '0' && *p <= '9'; p++)
1287 n = (n * 10) + (*p - '0');
1288 *frac = 0;
1289 if (*p++ == '.')
1290 {
1291 *frac = getfraction(&p, NULL, &err);
1292 /* {{ do something if err is set? }} */
1293 }
1285 return (n);
1286}
1287
1288/*
1289 * Return a pointer to the command buffer.
1290 */
1291 public char *
1292get_cmdbuf()
1293{
1294 return (cmdbuf);
1295}
1296
1294 return (n);
1295}
1296
1297/*
1298 * Return a pointer to the command buffer.
1299 */
1300 public char *
1301get_cmdbuf()
1302{
1303 return (cmdbuf);
1304}
1305
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}
1316
1297#if CMD_HISTORY
1298/*
1299 * Get the name of the history file.
1300 */
1301 static char *
1302histfile_name()
1303{
1304 char *home;
1305 char *name;
1306 int len;
1307
1308 /* See if filename is explicitly specified by $LESSHISTFILE. */
1309 name = lgetenv("LESSHISTFILE");
1310 if (name != NULL && *name != '\0')
1311 {
1317#if CMD_HISTORY
1318/*
1319 * Get the name of the history file.
1320 */
1321 static char *
1322histfile_name()
1323{
1324 char *home;
1325 char *name;
1326 int len;
1327
1328 /* See if filename is explicitly specified by $LESSHISTFILE. */
1329 name = lgetenv("LESSHISTFILE");
1330 if (name != NULL && *name != '\0')
1331 {
1312 if (strcmp(name, "-") == 0)
1332 if (strcmp(name, "-") == 0 || strcmp(name, "/dev/null") == 0)
1313 /* $LESSHISTFILE == "-" means don't use a history file. */
1314 return (NULL);
1315 return (save(name));
1316 }
1317
1318 /* Otherwise, file is in $HOME. */
1319 home = lgetenv("HOME");
1320 if (home == NULL || *home == '\0')

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

1423{
1424#if CMD_HISTORY
1425 char *filename;
1426 FILE *f;
1427
1428 filename = histfile_name();
1429 if (filename == NULL)
1430 return;
1333 /* $LESSHISTFILE == "-" means don't use a history file. */
1334 return (NULL);
1335 return (save(name));
1336 }
1337
1338 /* Otherwise, file is in $HOME. */
1339 home = lgetenv("HOME");
1340 if (home == NULL || *home == '\0')

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

1443{
1444#if CMD_HISTORY
1445 char *filename;
1446 FILE *f;
1447
1448 filename = histfile_name();
1449 if (filename == NULL)
1450 return;
1451 if (!mlist_search.modified && !mlist_shell.modified)
1452 return;
1431 f = fopen(filename, "w");
1432 free(filename);
1433 if (f == NULL)
1434 return;
1435#if HAVE_FCHMOD
1436 /* Make history file readable only by owner. */
1437 fchmod(fileno(f), 0600);
1438#endif

--- 14 unchanged lines hidden ---
1453 f = fopen(filename, "w");
1454 free(filename);
1455 if (f == NULL)
1456 return;
1457#if HAVE_FCHMOD
1458 /* Make history file readable only by owner. */
1459 fchmod(fileno(f), 0600);
1460#endif

--- 14 unchanged lines hidden ---