home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume20 / index-db / part01 / createdb.c next >
Encoding:
C/C++ Source or Header  |  1989-10-23  |  3.2 KB  |  152 lines

  1. #ifndef lint
  2. static char *RCSid = "$Header: /u5/davy/progs/index/RCS/createdb.c,v 1.1 89/08/09 11:06:21 davy Exp $";
  3. #endif
  4. /*
  5.  * createdb.c - handle creating a new database.
  6.  *
  7.  * David A. Curry
  8.  * Research Institute for Advanced Computer Science
  9.  * Mail Stop 230-5
  10.  * NASA Ames Research Center
  11.  * Moffett Field, CA 94035
  12.  * davy@riacs.edu
  13.  *
  14.  * $Log:    createdb.c,v $
  15.  * Revision 1.1  89/08/09  11:06:21  davy
  16.  * Initial revision
  17.  * 
  18.  */
  19. #include <sys/param.h>
  20. #include <curses.h>
  21. #include <stdio.h>
  22. #include "defs.h"
  23.  
  24. /*
  25.  * The message we'll print to explain what's happening.
  26.  */
  27. static struct message {
  28.     char    *m_line;
  29.     char    *m_arg;
  30. } message[] = {
  31.   { "You will now be placed into an editor so that you can create the\n",
  32.     0 },
  33.   { "database description file.  This file will be used by the program\n",
  34.     0 },
  35.   { "to prompt you for new items to be inserted into the database.\n",
  36.     0 },
  37.   { "\n",
  38.     0 },
  39.   { "Each line in this file is the name of a field.  It may be as long as\n",
  40.     0 },
  41.   { "you want, and may contain spaces.  The order of the lines in the file\n",
  42.     0 },
  43.   { "is the order you will be prompted for new information when inserting\n",
  44.     0 },
  45.   { "into the database.  You may leave blank lines in the file; this allows\n",
  46.     0 },
  47.   { "multiple-line entries for items such as addesses.  You may have a\n",
  48.     0 },
  49.   { "total of %d lines in the file.\n",
  50.     (char *) MAXDBLINES },
  51.   { "\n",
  52.     0 },
  53.   { "By default, all lines in an entry will be examined when searching for\n",
  54.     0 },
  55.   { "a pattern.  To make the program ignore a line, start that line with an\n",
  56.     0 },
  57.   { "exclamation point (!).\n",
  58.     0 },
  59.   { "\n",
  60.     0 },
  61.   { "The database is always sorted into ASCII collating sequence based on\n",
  62.     0 },
  63.   { "the contents of the first field.\n",
  64.     0 },
  65.   { "\n",
  66.     0 },
  67.   { "When you are finished, save the file and exit the editor.  You will\n",
  68.     0 },
  69.   { "then be placed in the main menu, where you can select other operations\n",
  70.     0 },
  71.   { "on the database.\n",
  72.     0 },
  73.   { NULL, 0 }
  74. };
  75.  
  76. /*
  77.  * create_db - execute an editor to allow the person to create the
  78.  *           index definition file.
  79.  */
  80. create_db(dbname)
  81. char *dbname;
  82. {
  83.     int pid;
  84.     char *editor;
  85.     char *getenv();
  86.     register int row;
  87.     char buf[BUFSIZ], fname[MAXPATHLEN];
  88.  
  89.     /*
  90.      * Clear the screen and move to the top.
  91.      */
  92.     clear();
  93.     move(0, 0);
  94.  
  95.     /*
  96.      * Print out the explanatory message.
  97.      */
  98.     for (row=0; message[row].m_line != NULL; row++)
  99.         printw(message[row].m_line, message[row].m_arg);
  100.  
  101.     /*
  102.      * Give the user a chance to read it.  Wait till they
  103.      * type a carriage return before proceeding.
  104.      */
  105.     prompt_char(++row, 0, "Type RETURN to continue: ", "\n");
  106.  
  107.     /*
  108.      * Use the editor the user prefers, or EDITOR if
  109.      * he doesn't have anything set.
  110.      */
  111.     if ((editor = getenv("EDITOR")) == NULL)
  112.         editor = EDITOR;
  113.  
  114.     /*
  115.      * Construct the file name.
  116.      */
  117.     sprintf(fname, "%s/%s%s", dbasedir, dbname, IDXFILE_SUFFIX);
  118.  
  119.     /*
  120.      * Go back to normal tty modes.
  121.      */
  122.     reset_modes();
  123.  
  124.     /*
  125.      * Spawn a child process.
  126.      */
  127.     if ((pid = fork()) < 0) {
  128.         error("%s: cannot fork.\n", pname, 0, 0);
  129.         exit(1);
  130.     }
  131.  
  132.     /*
  133.      * Execute the editor.
  134.      */
  135.     if (pid == 0) {
  136.         execl(editor, editor, fname, 0);
  137.         perror(editor);
  138.         exit(1);
  139.     }
  140.  
  141.     /*
  142.      * Wait for the editor to finish.
  143.      */
  144.     while (wait((int *) 0) != pid)
  145.         ;
  146.  
  147.     /*
  148.      * Set the tty modes up again.
  149.      */
  150.     set_modes();
  151. }
  152.