cleanups, add manual page
[unix-history] / usr / src / usr.bin / more / command.c
index 8e3efc1..0463329 100644 (file)
@@ -3,15 +3,13 @@
  * Copyright (c) 1988 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1988 Regents of the University of California.
  * All rights reserved.
  *
- * This code is derived from software contributed to Berkeley by
- * Mark Nudleman.
- * 
  * Redistribution and use in source and binary forms are permitted
  * provided that the above copyright notice and this paragraph are
  * duplicated in all such forms and that any documentation,
  * advertising materials, and other materials related to such
  * distribution and use acknowledge that the software was developed
  * Redistribution and use in source and binary forms are permitted
  * provided that the above copyright notice and this paragraph are
  * duplicated in all such forms and that any documentation,
  * advertising materials, and other materials related to such
  * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
+ * by Mark Nudleman and the University of California, Berkeley.  The
+ * name of Mark Nudleman or the
  * University may not be used to endorse or promote products derived
  * from this software without specific prior written permission.
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  * University may not be used to endorse or promote products derived
  * from this software without specific prior written permission.
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
@@ -20,7 +18,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)command.c  5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)command.c  5.9 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -49,17 +47,10 @@ extern int quitting;
 extern int scroll;
 extern char *first_cmd;
 extern char *every_first_cmd;
 extern int scroll;
 extern char *first_cmd;
 extern char *every_first_cmd;
-extern char version[];
 extern char *current_file;
 extern char *current_file;
-#if EDITOR
-extern char *editor;
-#endif
 extern int screen_trashed;     /* The screen has been overwritten */
 
 static char cmdbuf[120];       /* Buffer for holding a multi-char command */
 extern int screen_trashed;     /* The screen has been overwritten */
 
 static char cmdbuf[120];       /* Buffer for holding a multi-char command */
-#if SHELL_ESCAPE
-static char *shellcmd = NULL;  /* For holding last shell command for "!!" */
-#endif
 static char *cp;               /* Pointer into cmdbuf */
 static int cmd_col;            /* Current column of the multi-char command */
 static int mca;                        /* The multicharacter command (action) */
 static char *cp;               /* Pointer into cmdbuf */
 static int cmd_col;            /* Current column of the multi-char command */
 static int mca;                        /* The multicharacter command (action) */
@@ -279,7 +270,6 @@ getcc()
 exec_mca()
 {
        register char *p;
 exec_mca()
 {
        register char *p;
-       register int n;
 
        *cp = '\0';
        cmd_exec();
 
        *cp = '\0';
        cmd_exec();
@@ -315,62 +305,6 @@ exec_mca()
                        ;
                edit(glob(p));
                break;
                        ;
                edit(glob(p));
                break;
-#if SHELL_ESCAPE
-       case A_SHELL:
-               /*
-                * !! just uses whatever is in shellcmd.
-                * Otherwise, copy cmdbuf to shellcmd,
-                * replacing any '%' with the current
-                * file name.
-                */
-               if (*cmdbuf != '!')
-               {
-                       register char *fr, *to;
-
-                       /*
-                        * Make one pass to see how big a buffer we 
-                        * need to allocate for the expanded shell cmd.
-                        */
-                       for (fr = cmdbuf;  *fr != '\0';  fr++)
-                               if (*fr == '%')
-                                       n += strlen(current_file);
-                               else
-                                       n++;
-
-                       if (shellcmd != NULL)
-                               free(shellcmd);
-                       shellcmd = calloc(n+1, sizeof(char));
-                       if (shellcmd == NULL)
-                       {
-                               error("cannot allocate memory");
-                               break;
-                       }
-
-                       /*
-                        * Now copy the shell cmd, expanding any "%"
-                        * into the current filename.
-                        */
-                       to = shellcmd;
-                       for (fr = cmdbuf;  *fr != '\0';  fr++)
-                       {
-                               if (*fr != '%')
-                                       *to++ = *fr;
-                               else
-                               {
-                                       strcpy(to, current_file);
-                                       to += strlen(to);
-                               }
-                       }
-                       *to = '\0';
-               }
-
-               if (shellcmd == NULL)
-                       lsystem("");
-               else
-                       lsystem(shellcmd);
-               error("!done");
-               break;
-#endif
        }
 }
 
        }
 }
 
@@ -484,7 +418,6 @@ commands()
                        if (quitting)
                                quit();
                }
                        if (quitting)
                                quit();
                }
-                       
                /*
                 * Display prompt and accept a character.
                 */
                /*
                 * Display prompt and accept a character.
                 */
@@ -493,8 +426,7 @@ commands()
                noprefix();
                c = getcc();
 
                noprefix();
                c = getcc();
 
-       again:
-               if (sigs)
+again:         if (sigs)
                        continue;
 
                /*
                        continue;
 
                /*
@@ -660,17 +592,12 @@ commands()
                         * Print file name, etc.
                         */
                        cmd_exec();
                         * Print file name, etc.
                         */
                        cmd_exec();
-                       error(eq_message());
-                       break;
-                       
-               case A_VERSION:
-                       /*
-                        * Print version number, without the "@(#)".
-                        */
-                       cmd_exec();
-                       error(version+4);
-                       break;
-
+                       lower_left();
+                       clear_eol();
+                       putstr(eq_message());
+                       lower_left();
+                       c = getcc();
+                       goto again;
                case A_QUIT:
                        /*
                         * Exit.
                case A_QUIT:
                        /*
                         * Exit.
@@ -743,31 +670,16 @@ commands()
                        /*
                         * Invoke an editor on the input file.
                         */
                        /*
                         * Invoke an editor on the input file.
                         */
-#if EDITOR
                        if (ispipe)
                        {
                                error("Cannot edit standard input");
                                break;
                        }
                        if (ispipe)
                        {
                                error("Cannot edit standard input");
                                break;
                        }
-                       /*
-                        * Try to pass the line number to the editor.
-                        */
                        cmd_exec();
                        cmd_exec();
-                       c = currline(MIDDLE);
-                       if (c == 0)
-                               sprintf(cmdbuf, "%s %s",
-                                       editor, current_file);
-                       else
-                               sprintf(cmdbuf, "%s +%d %s",
-                                       editor, c, current_file);
-                       lsystem(cmdbuf);
+                       editfile();
                        ch_init(0, 0);
                        clr_linenum();
                        break;
                        ch_init(0, 0);
                        clr_linenum();
                        break;
-#else
-                       error("Command not available");
-                       break;
-#endif
 
                case A_NEXT_FILE:
                        /*
 
                case A_NEXT_FILE:
                        /*
@@ -819,20 +731,6 @@ commands()
                        c = getcc();
                        goto again;
 
                        c = getcc();
                        goto again;
 
-               case A_SHELL:
-                       /*
-                        * Shell escape.
-                        */
-#if SHELL_ESCAPE
-                       cmd_reset();
-                       start_mca(A_SHELL, "!");
-                       c = getcc();
-                       goto again;
-#else
-                       error("Command not available");
-                       break;
-#endif
-
                case A_SETMARK:
                        /*
                         * Set a mark.
                case A_SETMARK:
                        /*
                         * Set a mark.
@@ -882,3 +780,28 @@ commands()
                }
        }
 }
                }
        }
 }
+
+static
+editfile()
+{
+       static int dolinenumber;
+       static char *editor;
+       int c;
+       char buf[MAXPATHLEN], *getenv();
+
+       if (editor == NULL) {
+               editor = getenv("EDITOR");
+               /* pass the line number to vi */
+               if (editor == NULL || *editor == '\0') {
+                       editor = "/usr/ucb/vi";
+                       dolinenumber = 1;
+               }
+               else
+                       dolinenumber = 0;
+       }
+       if (dolinenumber && (c = currline(MIDDLE)))
+               (void)sprintf(buf, "%s +%d %s", editor, c, current_file);
+       else
+               (void)sprintf(buf, "%s %s", editor, current_file);
+       lsystem(buf);
+}