summaryrefslogtreecommitdiff
path: root/history.c
diff options
context:
space:
mode:
Diffstat (limited to 'history.c')
-rw-r--r--history.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/history.c b/history.c
index e6aa29d..3a42a2e 100644
--- a/history.c
+++ b/history.c
@@ -16,15 +16,11 @@
more than 1k characters long.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "rc.h"
-static char *id = "@(#) history.c 8/91";
+#include <stdio.h>
-#undef FALSE
-#undef TRUE
-typedef enum { FALSE, TRUE } bool;
+static const char id[] = "$Release: @(#)" PACKAGE " " VERSION " " RELDATE " $";
#define CHUNKSIZE 65536
@@ -36,9 +32,9 @@ static char **search, *progname, *history;
static char me; /* typically ':' or '-' */
static bool editit = FALSE, printit = FALSE;
static int nreplace = 0, nsearch = 0;
-static FILE *fp;
+static FILE *histfile;
-static void *ealloc(size_t n) {
+void *ealloc(size_t n) {
void *p = (void *) malloc(n);
if (p == NULL) {
perror("malloc");
@@ -47,7 +43,7 @@ static void *ealloc(size_t n) {
return p;
}
-static void *erealloc(void *p, size_t n) {
+void *erealloc(void *p, size_t n) {
p = (void *) realloc(p, n);
if (p == NULL) {
perror("realloc");
@@ -202,8 +198,8 @@ static char *readhistoryfile(char **last) {
fprintf(stderr, "$history not set\n");
exit(1);
}
- fp = fopen(history, "r+");
- if (fp == NULL) {
+ histfile = fopen(history, "r+");
+ if (histfile == NULL) {
perror(history);
exit(1);
}
@@ -211,7 +207,7 @@ static char *readhistoryfile(char **last) {
size = 0;
count = 0;
buf = ealloc(size = CHUNKSIZE);
- while ((nread = fread(buf + count, sizeof (char), size - count, fp)) > 0) {
+ while ((nread = fread(buf + count, sizeof (char), size - count, histfile)) > 0) {
count += nread;
if (size - count == 0)
buf = erealloc(buf, size *= 4);
@@ -321,9 +317,9 @@ next: s = getcommand();
if (s == NULL)
goto next;
}
- fseek(fp, 0, 2); /* 2 == end of file. i.e., append command to $history */
- fprintf(fp, "%s\n", s);
- fclose(fp);
+ fseek(histfile, 0, 2); /* 2 == end of file. i.e., append command to $history */
+ fprintf(histfile, "%s\n", s);
+ fclose(histfile);
if (printit)
printf("%s\n", s);
else {