1N/A/*********************************************************************** 1N/A* This software is part of the ast package * 1N/A* Copyright (c) 1982-2011 AT&T Intellectual Property * 1N/A* and is licensed under the * 1N/A* Common Public License, Version 1.0 * 1N/A* by AT&T Intellectual Property * 1N/A* A copy of the License is available at * 1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 1N/A* Information and Software Systems Research * 1N/A* David Korn <dgk@research.att.com> * 1N/A***********************************************************************/ 1N/A * History file manipulation routines 1N/A * Each command in the history file starts on an even byte is null terminated. 1N/A * The first byte must contain the special character HIST_UNDO and the second 1N/A * byte is the version number. The sequence HIST_UNDO 0, following a command, 1N/A * nullifies the previous command. A six byte sequence starting with 1N/A * HIST_CMDNO is used to store the command number so that it is not necessary 1N/A * to read the file from beginning to end to get to the last block of 1N/A * commands. This format of this sequence is different in version 1 1N/A * then in version 0. Version 1 allows commands to use the full 8 bit 1N/A * character set. It can understand version 0 format files. 1N/A#
define HIST_BIG (0
100000-
1024)
/* 1K less than maximum short */ 1N/A#
endif /* __STDC__ */ 1N/A#
endif /* O_BINARY */ 1N/A#
endif /* SHOPT_ACCTFILE */ 1N/A#
endif /*SHOPT_AUDIT*/ 1N/A * open the history file 1N/A * if HISTNAME is not given and userid==0 then no history file. 1N/A * if login_sh and HISTFILE is longer than HIST_MAX bytes then it is 1N/A * hist_open() returns 1, if history file is open 1N/A /* reuse history file if same name */ 1N/A /* make sure that file has history file format */ 1N/A /* don't allow root a history_file in /tmp */ 1N/A /* set the file to close-on-exec */ 1N/A /* put special characters at front of file */ 1N/A /* initialize history list */ 1N/A#
endif /* SHOPT_ACCTFILE */ 1N/A * close the history file and free the space 1N/A#
endif /* SHOPT_AUDIT */ 1N/A#
endif /* SHOPT_ACCTFILE */ 1N/A * check history file format to see if it begins with special byte 1N/A * clean out history file OK if not modified in HIST_RECENT seconds 1N/A * Copy the last <n> commands to a new file and make this the history file 1N/A /* The unlink can fail on windows 95 */ 1N/A /* use the old history file */ 1N/A /* copy to null byte */ 1N/A * position history file at size and find next command number 1N/A /* skip to marker command and return the number */ 1N/A /* numbering commands occur after a null and begin with HIST_CMDNO */ 1N/A /* check for marker */ 1N/A * This routine reads the history file from the present position 1N/A * to the end-of-file and puts the information in the in-core 1N/A * Note that HIST_CMDNO is only recognized at the beginning of a command 1N/A * and that HIST_UNDO as the first character of a command is skipped 1N/A * unless it is followed by 0. If followed by 0 then it cancels 1N/A * the previous command. 1N/A switch(*((
unsigned char*)(
cp++)))
1N/A * This routine will cause the previous command to be cancelled 1N/A * flush the current history command 1N/A * This is the write discipline for the history file 1N/A * When called from hist_flush(), trailing newlines are deleted and 1N/A * a zero byte. Line sequencing is added as required 1N/A /* remove whitespace from end of commands */ 1N/A /* don't count empty lines */ 1N/A#
endif /* SHOPT_AUDIT */ 1N/A#
endif /* SHOPT_ACCTFILE */ 1N/A * Put history sequence number <n> into buffer <buff> 1N/A * The buffer must be large enough to hold HIST_MARKSZ chars 1N/A * return byte offset in history file for command <n> 1N/A * seek to the position of command <n> 1N/A * write the command starting at offset <offset> onto file <outfile>. 1N/A * if character <last> appears before newline it is deleted 1N/A * each new-line character is replaced with string <nl>. 1N/A * find index for last line with given string 1N/A * If flag==0 then line must begin with string 1N/A * direction < 1 for backwards search 1N/A /* leading ^ means beginning of line unless escaped */ 1N/A /* allow a search to be aborted */ 1N/A * search for <string> in history file starting at location <offset> 1N/A * If coffset==0 then line must begin with string 1N/A * returns the line number of the match if successful, otherwise -1 1N/A#
endif /* SHOPT_MULTIBYTE */ 1N/A#
endif /* SHOPT_MULTIBYTE */ 1N/A * copy command <command> from history file to s1 1N/A * at most <size> characters copied 1N/A * if s1==0 the number of lines for the command is returned 1N/A * line=linenumber for emacs copy and only this line of command will be copied 1N/A * line < 0 for full command copy 1N/A * -1 returned if there is no history file 1N/A * return word number <word> from command number <command> 1N/A register unsigned char *
cp = (
unsigned char*)
s1;
1N/A#
endif /* SHOPT_ESH */ 1N/A * given the current command and line number, 1N/A * and number of lines back or foward, 1N/A * compute the new command and line number. 1N/A#
endif /* SHOPT_ESH */ 1N/A * Handle history file exceptions 1N/A /* write failure could be NFS problem, try to re-open */