home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / libcs / editor.c < prev    next >
C/C++ Source or Header  |  1990-12-11  |  3KB  |  73 lines

  1. /*
  2.  * Copyright (c) 1990 Carnegie Mellon University
  3.  * All Rights Reserved.
  4.  * 
  5.  * Permission to use, copy, modify and distribute this software and its
  6.  * documentation is hereby granted, provided that both the copyright
  7.  * notice and this permission notice appear in all copies of the
  8.  * software, derivative works or modified versions, and any portions
  9.  * thereof, and that both notices appear in supporting documentation.
  10.  *
  11.  * THE SOFTWARE IS PROVIDED "AS IS" AND CARNEGIE MELLON UNIVERSITY
  12.  * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  13.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT
  14.  * SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE FOR ANY SPECIAL, DIRECT,
  15.  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  16.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  17.  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  18.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19.  *
  20.  * Users of this software agree to return to Carnegie Mellon any
  21.  * improvements or extensions that they make and grant Carnegie the
  22.  * rights to redistribute these changes.
  23.  *
  24.  * Export of this software is permitted only after complying with the
  25.  * regulations of the U.S. Deptartment of Commerce relating to the
  26.  * Export of Technical Data.
  27.  */
  28. /*
  29.  *  editor  --  fork editor to edit some text file
  30.  *
  31.  *  Usage:
  32.  *    i = editor(file, prompt);
  33.  *    char *file, *prompt;
  34.  *    int i;
  35.  *
  36.  *  The editor() routine is used to fork the user's favorite editor.
  37.  *  There is assumed to be an environment variable named "EDITOR" whose
  38.  *  value is the name of the favored editor.  If the EDITOR parameter is
  39.  *  missing, some default (see DEFAULTED below) is assumed.  The runp()
  40.  *  routine is then used to find this editor on the searchlist specified
  41.  *  by the PATH variable (or the default path).  "file" is the name of
  42.  *  the file to be edited and "prompt" is a string (of any length) which
  43.  *  will be printed in a such a way that the user can see it at least at
  44.  *  the start of the editing session.  editor() returns the value of the
  45.  *  runp() call.
  46.  *
  47.  **********************************************************************
  48.  * HISTORY
  49.  * $Log:    editor.c,v $
  50.  * Revision 1.2  90/12/11  17:51:56  mja
  51.  *     Add copyright/disclaimer for distribution.
  52.  * 
  53.  * 22-Nov-85  Glenn Marcy (gm0w) at Carnegie-Mellon University
  54.  *    Rewritten for 4.2 BSD UNIX.
  55.  *
  56.  **********************************************************************
  57.  */
  58.  
  59. #include <libc.h>
  60.  
  61. #define DEFAULTED "emacs"
  62.  
  63. int editor(file, prompt)
  64. register char *file, *prompt;
  65. {
  66.     register char *editor;
  67.  
  68.     if ((editor = getenv("EDITOR")) == NULL)
  69.         editor = DEFAULTED;
  70.     if (*prompt) printf("%s\n", prompt);
  71.     return(runp(editor, editor, file, 0));
  72. }
  73.