commit 5290f5477832c5edc8cabf5b9709570acb7f772a
parent 8906db24cb3d0ce6042f1e40bc6fa89607860d0b
Author: tgoodwin <tgoodwin>
Date: Fri, 10 Jul 1998 12:32:14 +0000
include rc.h
Diffstat:
1 file changed, 12 insertions(+), 16 deletions(-)
diff --git 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 {