BSD 4_4_Lite2 release
[unix-history] / usr / src / bin / sh / histedit.c
index 0093c17..5601852 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)histedit.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)histedit.c 8.2 (Berkeley) 5/4/95";
 #endif /* not lint */
 
 #endif /* not lint */
 
-/*
- * Editline and history functions (and glue).
- */
 #include <sys/param.h>
 #include <paths.h>
 #include <stdio.h>
 #include <sys/param.h>
 #include <paths.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+/*
+ * Editline and history functions (and glue).
+ */
 #include "shell.h"
 #include "parser.h"
 #include "var.h"
 #include "options.h"
 #include "shell.h"
 #include "parser.h"
 #include "var.h"
 #include "options.h"
+#include "main.h"
+#include "output.h"
 #include "mystring.h"
 #include "mystring.h"
+#ifndef NO_HISTORY
+#include "myhistedit.h"
+#endif
 #include "error.h"
 #include "error.h"
-#include "histedit.h"
+#include "eval.h"
 #include "memalloc.h"
 
 #define MAXHISTLOOPS   4       /* max recursions through fc */
 #include "memalloc.h"
 
 #define MAXHISTLOOPS   4       /* max recursions through fc */
@@ -67,7 +74,9 @@ STATIC char *fc_replace __P((const char *, char *, char *));
  * Set history and editing status.  Called whenever the status may
  * have changed (figures out what to do).
  */
  * Set history and editing status.  Called whenever the status may
  * have changed (figures out what to do).
  */
-histedit() {
+void
+histedit() 
+{
 
 #define editing (Eflag || Vflag)
 
 
 #define editing (Eflag || Vflag)
 
@@ -132,7 +141,10 @@ bad:
        }
 }
 
        }
 }
 
-sethistsize() {
+
+void
+sethistsize()
+{
        char *cp;
        int histsize;
 
        char *cp;
        int histsize;
 
@@ -149,8 +161,10 @@ sethistsize() {
  *  This command is provided since POSIX decided to standardize
  *  the Korn shell fc command.  Oh well...
  */
  *  This command is provided since POSIX decided to standardize
  *  the Korn shell fc command.  Oh well...
  */
+int
 histcmd(argc, argv)
 histcmd(argc, argv)
-       char *argv[];
+       int argc;
+       char **argv;
 {
        extern char *optarg;
        extern int optind, optopt, optreset;
 {
        extern char *optarg;
        extern int optind, optopt, optreset;
@@ -167,6 +181,21 @@ histcmd(argc, argv)
        struct jmploc *volatile savehandler;
        char editfile[MAXPATHLEN + 1];
        FILE *efp;
        struct jmploc *volatile savehandler;
        char editfile[MAXPATHLEN + 1];
        FILE *efp;
+#ifdef __GNUC__
+       /* Avoid longjmp clobbering */
+       (void) &editor;
+       (void) &lflg;
+       (void) &nflg;
+       (void) &rflg;
+       (void) &sflg;
+       (void) &firststr;
+       (void) &laststr;
+       (void) &pat;
+       (void) &repl;
+       (void) &efp;
+       (void) &argc;
+       (void) &argv;
+#endif
 
        if (hist == NULL)
                error("history not active");
 
        if (hist == NULL)
                error("history not active");
@@ -358,6 +387,7 @@ histcmd(argc, argv)
                --active;
        if (displayhist)
                displayhist = 0;
                --active;
        if (displayhist)
                displayhist = 0;
+       return 0;
 }
 
 STATIC char *
 }
 
 STATIC char *
@@ -384,14 +414,18 @@ fc_replace(s, p, r)
        return (dest);
 }
 
        return (dest);
 }
 
+int
 not_fcnumber(s)
         char *s;
 {
 not_fcnumber(s)
         char *s;
 {
+       if (s == NULL)
+               return 0;
         if (*s == '-')
                 s++;
        return (!is_number(s));
 }
 
         if (*s == '-')
                 s++;
        return (!is_number(s));
 }
 
+int
 str_to_event(str, last)
        char *str;
        int last;
 str_to_event(str, last)
        char *str;
        int last;
@@ -399,7 +433,7 @@ str_to_event(str, last)
        const HistEvent *he;
        char *s = str;
        int relative = 0;
        const HistEvent *he;
        char *s = str;
        int relative = 0;
-       int i, j;
+       int i;
 
        he = history(hist, H_FIRST);
        switch (*s) {
 
        he = history(hist, H_FIRST);
        switch (*s) {