2 * Copyright (C) 1984-2017 Mark Nudelman
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.
7 * For more information, see the README file.
12 * Functions which manipulate the command buffer.
13 * Used only by command() and related functions.
26 static char cmdbuf[CMDBUF_SIZE]; /* Buffer for holding a multi-char command */
27 static int cmd_col; /* Current column of the cursor */
28 static int prompt_col; /* Column of cursor just after prompt */
29 static char *cp; /* Pointer into cmdbuf */
30 static int cmd_offset; /* Index into cmdbuf of first displayed char */
31 static int literal; /* Next input char should not be interpreted */
32 static int updown_match = -1; /* Prefix length in up/down movement */
34 #if TAB_COMPLETE_FILENAME
35 static int cmd_complete();
37 * These variables are statics used by cmd_complete.
39 static int in_completion = 0;
41 static char *tk_original;
42 static char *tk_ipoint;
43 static char *tk_trial;
44 static struct textlist tk_tlist;
47 static int cmd_left();
48 static int cmd_right();
50 #if SPACES_IN_FILENAMES
51 public char openquote = '"';
52 public char closequote = '"';
58 #define HISTFILE_FIRST_LINE ".less-history-file:"
59 #define HISTFILE_SEARCH_SECTION ".search"
60 #define HISTFILE_SHELL_SECTION ".shell"
63 * A mlist structure represents a command history.
69 struct mlist *curr_mp;
75 * These are the various command histories that exist.
77 struct mlist mlist_search =
78 { &mlist_search, &mlist_search, &mlist_search, NULL, 0 };
79 public void *ml_search = (void *) &mlist_search;
81 struct mlist mlist_examine =
82 { &mlist_examine, &mlist_examine, &mlist_examine, NULL, 0 };
83 public void *ml_examine = (void *) &mlist_examine;
85 #if SHELL_ESCAPE || PIPEC
86 struct mlist mlist_shell =
87 { &mlist_shell, &mlist_shell, &mlist_shell, NULL, 0 };
88 public void *ml_shell = (void *) &mlist_shell;
91 #else /* CMD_HISTORY */
93 /* If CMD_HISTORY is off, these are just flags. */
94 public void *ml_search = (void *)1;
95 public void *ml_examine = (void *)2;
96 #if SHELL_ESCAPE || PIPEC
97 public void *ml_shell = (void *)3;
100 #endif /* CMD_HISTORY */
103 * History for the current command.
105 static struct mlist *curr_mlist = NULL;
106 static int curr_cmdflags;
108 static char cmd_mbc_buf[MAX_UTF_CHAR_LEN];
109 static int cmd_mbc_buf_len;
110 static int cmd_mbc_buf_index;
114 * Reset command buffer (to empty).
129 * Clear command line.
134 cmd_col = prompt_col = 0;
140 * Display a string, usually as a prompt for input into the command buffer.
148 constant char *endline = s + strlen(s);
151 char *ns = (char *) s;
153 ch = step_char(&ns, +1, endline);
158 else if (is_composing_char(ch) || is_combining_char(prev_ch, ch))
161 width = is_wide_char(ch) ? 2 : 1;
169 * How many characters are in the command buffer?
175 char *endline = s + strlen(s);
180 step_char(&s, +1, endline);
187 * Common part of cmd_step_right() and cmd_step_left().
188 * {{ Returning pwidth and bswidth separately is a historical artifact
189 * since they're always the same. Maybe clean this up someday. }}
192 cmd_step_common(p, ch, len, pwidth, bswidth)
204 pr = prchar((int) ch);
205 width = (int) strlen(pr);
209 if (is_composing_char(ch))
211 else if (is_ubin_char(ch))
212 width = (int) strlen(pr);
215 LWCHAR prev_ch = step_char(&p, -1, cmdbuf);
216 if (is_combining_char(prev_ch, ch))
219 width = is_wide_char(ch) ? 2 : 1;
230 * Step a pointer one character right in the command buffer.
233 cmd_step_right(pp, pwidth, bswidth)
239 LWCHAR ch = step_char(pp, +1, p + strlen(p));
241 return cmd_step_common(p, ch, *pp - p, pwidth, bswidth);
245 * Step a pointer one character left in the command buffer.
248 cmd_step_left(pp, pwidth, bswidth)
254 LWCHAR ch = step_char(pp, -1, cmdbuf);
256 return cmd_step_common(*pp, ch, p - *pp, pwidth, bswidth);
260 * Repaint the line from cp onwards.
261 * Then position the cursor just after the char old_cp (a pointer into cmdbuf).
265 constant char *old_cp;
268 * Repaint the line from the current position.
275 char *pr = cmd_step_right(&np, &width, NULL);
276 if (cmd_col + width >= sc_width)
286 char *pr = cmd_step_right(&np, &width, NULL);
294 * Back up the cursor to the correct position.
301 * Put the cursor at "home" (just after the prompt),
302 * and set cp to the corresponding char in cmdbuf.
307 while (cmd_col > prompt_col)
311 cmd_step_left(&cp, &width, &bswidth);
312 while (bswidth-- > 0)
317 cp = &cmdbuf[cmd_offset];
321 * Shift the cmdbuf display left a half-screen.
331 * Start at the first displayed char, count how far to the
332 * right we'd have to move to reach the center of the screen.
334 s = cmdbuf + cmd_offset;
336 while (cols < (sc_width - prompt_col) / 2 && *s != '\0')
339 cmd_step_right(&s, &width, NULL);
346 cmd_step_right(&ns, &width, NULL);
352 cmd_offset = (int) (s - cmdbuf);
355 cmd_repaint(save_cp);
359 * Shift the cmdbuf display right a half-screen.
369 * Start at the first displayed char, count how far to the
370 * left we'd have to move to traverse a half-screen width
371 * of displayed characters.
373 s = cmdbuf + cmd_offset;
375 while (cols < (sc_width - prompt_col) / 2 && s > cmdbuf)
378 cmd_step_left(&s, &width, NULL);
382 cmd_offset = (int) (s - cmdbuf);
385 cmd_repaint(save_cp);
389 * Move cursor right one character.
400 /* Already at the end of the line. */
404 pr = cmd_step_right(&ncp, &width, NULL);
405 if (cmd_col + width >= sc_width)
407 else if (cmd_col + width == sc_width - 1 && cp[1] != '\0')
414 pr = cmd_step_right(&ncp, &width, NULL);
424 * Move cursor left one character.
434 /* Already at the beginning of the line */
440 cmd_step_left(&ncp, &width, &bswidth);
444 if (cmd_col < prompt_col + width)
448 while (bswidth-- > 0)
454 * Insert a char into the command buffer, at the current position.
463 if (strlen(cmdbuf) + clen >= sizeof(cmdbuf)-1)
465 /* No room in the command buffer for another char. */
471 * Make room for the new character (shift the tail of the buffer right).
473 for (s = &cmdbuf[strlen(cmdbuf)]; s >= cp; s--)
476 * Insert the character into the buffer.
478 for (s = cp; s < cp + clen; s++)
481 * Reprint the tail of the line from the inserted char.
490 * Backspace in the command buffer.
491 * Delete the char to the left of the cursor.
502 * Backspace past beginning of the buffer:
503 * this usually means abort the command.
508 * Move cursor left (to the char being erased).
512 clen = (int) (s - cp);
515 * Remove the char from the buffer (shift the buffer left).
525 * Repaint the buffer after the erased char.
531 * We say that erasing the entire command string causes us
532 * to abort the current command, if CF_QUIT_ON_ERASE is set.
534 if ((curr_cmdflags & CF_QUIT_ON_ERASE) && cp == cmdbuf && *cp == '\0')
540 * Delete the char under the cursor.
547 /* At end of string; there is no char under the cursor. */
551 * Move right, then use cmd_erase.
559 * Delete the "word" to the left of the cursor.
564 if (cp > cmdbuf && cp[-1] == ' ')
567 * If the char left of cursor is a space,
568 * erase all the spaces left of cursor (to the first non-space).
570 while (cp > cmdbuf && cp[-1] == ' ')
575 * If the char left of cursor is not a space,
576 * erase all the nonspaces left of cursor (the whole "word").
578 while (cp > cmdbuf && cp[-1] != ' ')
585 * Delete the "word" under the cursor.
593 * If the char under the cursor is a space,
594 * delete it and all the spaces right of cursor.
601 * If the char under the cursor is not a space,
602 * delete it and all nonspaces right of cursor (the whole word).
604 while (*cp != ' ' && *cp != '\0')
611 * Delete all chars in the command buffer.
616 if (cmdbuf[0] == '\0')
618 /* Buffer is already empty; abort the current command. */
628 * We say that erasing the entire command string causes us
629 * to abort the current command, if CF_QUIT_ON_ERASE is set.
631 if (curr_cmdflags & CF_QUIT_ON_ERASE)
637 * Select an mlist structure to be the current command history.
640 set_mlist(mlist, cmdflags)
645 curr_mlist = (struct mlist *) mlist;
646 curr_cmdflags = cmdflags;
648 /* Make sure the next up-arrow moves to the last string in the mlist. */
649 if (curr_mlist != NULL)
650 curr_mlist->curr_mp = curr_mlist;
656 * Move up or down in the currently selected command history list.
657 * Only consider entries whose first updown_match chars are equal to
658 * cmdbuf's corresponding chars.
667 if (curr_mlist == NULL)
670 * The current command has no history list.
676 if (updown_match < 0)
678 updown_match = (int) (cp - cmdbuf);
682 * Find the next history entry which matches.
684 for (ml = curr_mlist->curr_mp;;)
686 ml = (action == EC_UP) ? ml->prev : ml->next;
687 if (ml == curr_mlist)
690 * We reached the end (or beginning) of the list.
694 if (strncmp(cmdbuf, ml->string, updown_match) == 0)
697 * This entry matches; stop here.
698 * Copy the entry into cmdbuf and echo it on the screen.
700 curr_mlist->curr_mp = ml;
707 for (cp = cmdbuf; *cp != '\0'; )
713 * We didn't find a history entry that matches.
721 * Add a string to an mlist.
724 cmd_addhist(mlist, cmd, modified)
733 * Don't save a trivial command.
735 if (strlen(cmd) == 0)
739 * Save the command unless it's a duplicate of the
740 * last command in the history.
743 if (ml == mlist || strcmp(ml->string, cmd) != 0)
746 * Did not find command in history.
747 * Save the command and put it at the end of the history list.
749 ml = (struct mlist *) ecalloc(1, sizeof(struct mlist));
750 ml->string = save(cmd);
751 ml->modified = modified;
753 ml->prev = mlist->prev;
754 mlist->prev->next = ml;
758 * Point to the cmd just after the just-accepted command.
759 * Thus, an UPARROW will always retrieve the previous command.
761 mlist->curr_mp = ml->next;
766 * Accept the command in the command buffer.
767 * Add it to the currently selected history list.
774 * Nothing to do if there is no currently selected history list.
776 if (curr_mlist == NULL)
778 cmd_addhist(curr_mlist, cmdbuf, 1);
779 curr_mlist->modified = 1;
784 * Try to perform a line-edit function on the command buffer,
785 * using a specified char as a line-editing command.
787 * CC_PASS The char does not invoke a line edit function.
788 * CC_OK Line edit function done.
789 * CC_QUIT The char requests the current command to be aborted.
798 #if TAB_COMPLETE_FILENAME
799 #define not_in_completion() in_completion = 0
801 #define not_in_completion()
805 * See if the char is indeed a line-editing command.
809 if (curr_mlist == NULL)
811 * No current history; don't accept history manipulation cmds.
813 flags |= EC_NOHISTORY;
815 #if TAB_COMPLETE_FILENAME
816 if (curr_mlist == ml_search)
818 * In a search command; don't accept file-completion cmds.
820 flags |= EC_NOCOMPLETE;
823 action = editchar(c, flags);
829 return (cmd_right());
835 while (*cp != '\0' && *cp != ' ')
842 while (cp > cmdbuf && cp[-1] == ' ')
844 while (cp > cmdbuf && cp[-1] != ' ')
863 return (cmd_erase());
873 return (cmd_werase());
876 return (cmd_delete());
879 return (cmd_wdelete());
887 return (cmd_updown(action));
889 #if TAB_COMPLETE_FILENAME
893 return (cmd_complete(action));
903 #if TAB_COMPLETE_FILENAME
905 * Insert a string into the command buffer, at the current position.
913 char *endline = str + strlen(str);
915 for (s = str; *s != '\0'; )
918 step_char(&s, +1, endline);
919 action = cmd_ichar(os, s - os);
930 * Find the beginning and end of the "current" word.
931 * This is the word which the cursor (cp) is inside or at the end of.
932 * Return pointer to the beginning of the word and put the
933 * cursor at the end of the word.
939 #if SPACES_IN_FILENAMES
941 int delim_quoted = 0;
943 constant char *esc = get_meta_escape();
944 int esclen = (int) strlen(esc);
948 * Move cursor to end of word.
950 if (*cp != ' ' && *cp != '\0')
953 * Cursor is on a nonspace.
954 * Move cursor right to the next space.
956 while (*cp != ' ' && *cp != '\0')
958 } else if (cp > cmdbuf && cp[-1] != ' ')
961 * Cursor is on a space, and char to the left is a nonspace.
962 * We're already at the end of the word.
969 * Cursor is on a space and char to the left is a space.
970 * Huh? There's no word here.
976 * Find the beginning of the word which the cursor is in.
980 #if SPACES_IN_FILENAMES
982 * If we have an unbalanced quote (that is, an open quote
983 * without a corresponding close quote), we return everything
984 * from the open quote, including spaces.
986 for (word = cmdbuf; word < cp; word++)
991 for (p = cmdbuf; p < cp; p++)
996 } else if (esclen > 0 && p + esclen < cp &&
997 strncmp(p, esc, esclen) == 0)
1001 } else if (delim_quoted)
1003 if (*p == closequote)
1005 } else /* (!delim_quoted) */
1007 if (*p == openquote)
1018 * Set things up to enter completion mode.
1019 * Expand the word under the cursor into a list of filenames
1020 * which start with that word, and set tk_text to that list.
1029 * Get rid of any previous tk_text.
1031 if (tk_text != NULL)
1037 * Find the original (uncompleted) word in the command buffer.
1039 word = delimit_word();
1043 * Set the insertion point to the point in the command buffer
1044 * where the original (uncompleted) word now sits.
1048 * Save the original (uncompleted) word
1050 if (tk_original != NULL)
1052 tk_original = (char *) ecalloc(cp-word+1, sizeof(char));
1053 strncpy(tk_original, word, cp-word);
1055 * Get the expanded filename.
1056 * This may result in a single filename, or
1057 * a blank-separated list of filenames.
1061 if (*word != openquote)
1063 tk_text = fcomplete(word);
1069 char *qword = shell_quote(word+1);
1072 tk_text = fcomplete(word+1);
1075 tk_text = fcomplete(qword);
1083 * Return the next word in the current completion list.
1086 next_compl(action, prev)
1093 return (forw_textlist(&tk_tlist, prev));
1095 return (back_textlist(&tk_tlist, prev));
1102 * Complete the filename before (or under) the cursor.
1103 * cmd_complete may be called multiple times. The global in_completion
1104 * remembers whether this call is the first time (create the list),
1105 * or a subsequent time (step thru the list).
1108 cmd_complete(action)
1113 if (!in_completion || action == EC_EXPAND)
1116 * Expand the word under the cursor and
1117 * use the first word in the expansion
1118 * (or the entire expansion if we're doing EC_EXPAND).
1121 if (tk_text == NULL)
1126 if (action == EC_EXPAND)
1129 * Use the whole list.
1135 * Use the first filename in the list.
1138 init_textlist(&tk_tlist, tk_text);
1139 tk_trial = next_compl(action, (char*)NULL);
1144 * We already have a completion list.
1145 * Use the next/previous filename from the list.
1147 tk_trial = next_compl(action, tk_trial);
1151 * Remove the original word, or the previous trial completion.
1153 while (cp > tk_ipoint)
1156 if (tk_trial == NULL)
1159 * There are no more trial completions.
1160 * Insert the original (uncompleted) filename.
1163 if (cmd_istr(tk_original) != CC_OK)
1168 * Insert trial completion.
1170 if (cmd_istr(tk_trial) != CC_OK)
1173 * If it is a directory, append a slash.
1175 if (is_dir(tk_trial))
1177 if (cp > cmdbuf && cp[-1] == closequote)
1179 s = lgetenv("LESSSEPARATOR");
1182 if (cmd_istr(s) != CC_OK)
1195 #endif /* TAB_COMPLETE_FILENAME */
1198 * Process a single character of a multi-character command, such as
1199 * a number, or the pattern of a search command.
1201 * CC_OK The char was accepted.
1202 * CC_QUIT The char requests the command to be aborted.
1203 * CC_ERROR The char could not be accepted due to an error.
1218 /* Perform strict validation in all possible cases. */
1219 if (cmd_mbc_buf_len == 0)
1222 cmd_mbc_buf_index = 1;
1224 if (IS_ASCII_OCTET(c))
1225 cmd_mbc_buf_len = 1;
1226 else if (IS_UTF8_LEAD(c))
1228 cmd_mbc_buf_len = utf_len(c);
1232 /* UTF8_INVALID or stray UTF8_TRAIL */
1236 } else if (IS_UTF8_TRAIL(c))
1238 cmd_mbc_buf[cmd_mbc_buf_index++] = c;
1239 if (cmd_mbc_buf_index < cmd_mbc_buf_len)
1241 if (!is_utf8_well_formed(cmd_mbc_buf, cmd_mbc_buf_index))
1243 /* complete, but not well formed (non-shortest form), sequence */
1244 cmd_mbc_buf_len = 0;
1250 /* Flush incomplete (truncated) sequence. */
1251 cmd_mbc_buf_len = 0;
1253 /* Handle new char. */
1257 len = cmd_mbc_buf_len;
1258 cmd_mbc_buf_len = 0;
1264 * Insert the char, even if it is a line-editing char.
1267 return (cmd_ichar(cmd_mbc_buf, len));
1271 * See if it is a line-editing character.
1273 if (in_mca() && len == 1)
1275 action = cmd_edit(c);
1287 * Insert the char into the command buffer.
1289 return (cmd_ichar(cmd_mbc_buf, len));
1293 * Return the number currently in the command buffer.
1303 for (p = cmdbuf; *p >= '0' && *p <= '9'; p++)
1304 n = (n * 10) + (*p - '0');
1308 *frac = getfraction(&p, NULL, &err);
1309 /* {{ do something if err is set? }} */
1315 * Return a pointer to the command buffer.
1325 * Return the last (most recent) string in the current command history.
1330 if (curr_mlist == NULL)
1332 return (curr_mlist->curr_mp->prev->string);
1344 for (ml = ml->next; ml->string != NULL; ml = ml->next)
1350 * Get the name of the history file.
1359 /* See if filename is explicitly specified by $LESSHISTFILE. */
1360 name = lgetenv("LESSHISTFILE");
1361 if (name != NULL && *name != '\0')
1363 if (strcmp(name, "-") == 0 || strcmp(name, "/dev/null") == 0)
1364 /* $LESSHISTFILE == "-" means don't use a history file. */
1366 return (save(name));
1369 /* See if history file is disabled in the build. */
1370 if (strcmp(LESSHISTFILE, "") == 0 || strcmp(LESSHISTFILE, "-") == 0)
1373 /* Otherwise, file is in $HOME. */
1374 home = lgetenv("HOME");
1375 if (home == NULL || *home == '\0')
1378 home = lgetenv("INIT");
1379 if (home == NULL || *home == '\0')
1383 len = (int) (strlen(home) + strlen(LESSHISTFILE) + 2);
1384 name = (char *) ecalloc(len, sizeof(char));
1385 SNPRINTF2(name, len, "%s/%s", home, LESSHISTFILE);
1390 * Read a .lesshst file and call a callback for each line in the file.
1393 read_cmdhist2(action, uparam, skip_search, skip_shell)
1394 void (*action)(void*,struct mlist*,char*);
1399 struct mlist *ml = NULL;
1400 char line[CMDBUF_SIZE];
1406 filename = histfile_name();
1407 if (filename == NULL)
1409 f = fopen(filename, "r");
1413 if (fgets(line, sizeof(line), f) == NULL ||
1414 strncmp(line, HISTFILE_FIRST_LINE, strlen(HISTFILE_FIRST_LINE)) != 0)
1419 while (fgets(line, sizeof(line), f) != NULL)
1421 for (p = line; *p != '\0'; p++)
1423 if (*p == '\n' || *p == '\r')
1429 if (strcmp(line, HISTFILE_SEARCH_SECTION) == 0)
1432 skip = &skip_search;
1433 } else if (strcmp(line, HISTFILE_SHELL_SECTION) == 0)
1435 #if SHELL_ESCAPE || PIPEC
1442 } else if (*line == '"')
1446 if (skip != NULL && *skip > 0)
1449 (*action)(uparam, ml, line+1);
1457 read_cmdhist(action, uparam, skip_search, skip_shell)
1458 void (*action)(void*,struct mlist*,char*);
1463 read_cmdhist2(action, uparam, skip_search, skip_shell);
1464 (*action)(uparam, NULL, NULL); /* signal end of file */
1468 addhist_init(void *uparam, struct mlist *ml, char *string)
1470 if (ml == NULL || string == NULL)
1472 cmd_addhist(ml, string, 0);
1474 #endif /* CMD_HISTORY */
1477 * Initialize history from a .lesshist file.
1483 read_cmdhist(&addhist_init, NULL, 0, 0);
1484 #endif /* CMD_HISTORY */
1488 * Write the header for a section of the history file.
1492 write_mlist_header(ml, f)
1496 if (ml == &mlist_search)
1497 fprintf(f, "%s\n", HISTFILE_SEARCH_SECTION);
1498 #if SHELL_ESCAPE || PIPEC
1499 else if (ml == &mlist_shell)
1500 fprintf(f, "%s\n", HISTFILE_SHELL_SECTION);
1505 * Write all modified entries in an mlist to the history file.
1512 for (ml = ml->next; ml->string != NULL; ml = ml->next)
1516 fprintf(f, "\"%s\n", ml->string);
1519 ml->modified = 0; /* entire mlist is now unmodified */
1523 * Make a temp name in the same directory as filename.
1526 make_tempname(filename)
1530 char *tempname = ecalloc(1, strlen(filename)+1);
1531 strcpy(tempname, filename);
1532 lastch = tempname[strlen(tempname)-1];
1533 tempname[strlen(tempname)-1] = (lastch == 'Q') ? 'Z' : 'Q';
1539 struct mlist *mlist;
1544 * Copy entries from the saved history file to a new file.
1545 * At the end of each mlist, append any new entries
1546 * created during this session.
1549 copy_hist(void *uparam, struct mlist *ml, char *string)
1551 struct save_ctx *ctx = (struct save_ctx *) uparam;
1553 if (ml != ctx->mlist) {
1554 /* We're changing mlists. */
1556 /* Append any new entries to the end of the current mlist. */
1557 write_mlist(ctx->mlist, ctx->fout);
1558 /* Write the header for the new mlist. */
1560 write_mlist_header(ctx->mlist, ctx->fout);
1564 /* Copy the entry. */
1565 fprintf(ctx->fout, "\"%s\n", string);
1567 if (ml == NULL) /* End of file */
1569 /* Write any sections that were not in the original file. */
1570 if (mlist_search.modified)
1572 write_mlist_header(&mlist_search, ctx->fout);
1573 write_mlist(&mlist_search, ctx->fout);
1575 #if SHELL_ESCAPE || PIPEC
1576 if (mlist_shell.modified)
1578 write_mlist_header(&mlist_shell, ctx->fout);
1579 write_mlist(&mlist_shell, ctx->fout);
1584 #endif /* CMD_HISTORY */
1587 * Make a file readable only by its owner.
1590 make_file_private(f)
1596 struct stat statbuf;
1597 int r = fstat(fileno(f), &statbuf);
1598 if (r < 0 || !S_ISREG(statbuf.st_mode))
1599 /* Don't chmod if not a regular file. */
1603 fchmod(fileno(f), 0600);
1608 * Does the history file need to be updated?
1613 if (mlist_search.modified)
1615 #if SHELL_ESCAPE || PIPEC
1616 if (mlist_shell.modified)
1623 * Update the .lesshst file.
1633 struct save_ctx ctx;
1638 if (!histfile_modified())
1640 histname = histfile_name();
1641 if (histname == NULL)
1643 tempname = make_tempname(histname);
1644 fout = fopen(tempname, "w");
1647 make_file_private(fout);
1648 s = lgetenv("LESSHISTSIZE");
1653 skip_search = mlist_size(&mlist_search) - histsize;
1654 #if SHELL_ESCAPE || PIPEC
1655 skip_shell = mlist_size(&mlist_shell) - histsize;
1657 fprintf(fout, "%s\n", HISTFILE_FIRST_LINE);
1660 read_cmdhist(copy_hist, &ctx, skip_search, skip_shell);
1662 #if MSDOS_COMPILER==WIN32C
1664 * Windows rename doesn't remove an existing file,
1665 * making it useless for atomic operations. Sigh.
1669 rename(tempname, histname);
1673 #endif /* CMD_HISTORY */