cat > input <<'+-+-+-+-+-END-OF-FILE-+-+-+-+-+'
n
Wladislaw

p
Mosca

c
Kilroy

r

l

q

+-+-+-+-+-END-OF-FILE-+-+-+-+-+
chmod 644 input
cat > script.c <<'+-+-+-+-+-END-OF-FILE-+-+-+-+-+'
# include  <mscc.h>
# include  <stdio.h>
#include	<string.h>

# define  NAMELENGTH	32	/* max length of attr and rel names +1 */
# define  BUFSIZE	200

# define  streq(x,y)	(strcmp (x, y) == 0)
# define  NUMBER	"n"
# define  PHONE		"p"
# define  CREDIT	"c"
# define  RECORD	"r"
# define  LOANS		"l"
# define  QUIT		"q"
# define  NOTHING	""

int	printmenu();
int	briefmenu();
int	findname();

char	name[BUFSIZE];
char	clause[BUFSIZE];

int	msmain (argc, argv)
		int	argc;
		char	**argv;
{
	char	command[BUFSIZE], query[BUFSIZE],
		relation[NAMELENGTH], attribute[NAMELENGTH];
	int	showmenu;

	printmenu();

	for (;;)
	{
		strcpy(attribute,NOTHING);
		strcpy(clause,NOTHING);
		strcpy(relation,"personnel");
		showmenu = false;

		printf("\nCommand: ");
		fflush (stdout);
		fgets(command, sizeof (command) - 1, stdin);
		if (command[(int)strlen(command) - 1] == '\n')
			command[strlen(command) - 1] = 0;

		if (streq(command,NUMBER))
		{
			strcpy(attribute,"number");
			findname();
		}
		else if (streq(command,PHONE))
		{
			strcpy(attribute,"phone");
			findname();
		}
		else if (streq(command,CREDIT))
		{
			strcpy(attribute,"credit_limit");
			findname();
		}
		else if (streq(command,RECORD))
		{
			/* do nothing yet */
		}
		else if (streq(command,LOANS))
		{
			strcpy(relation,"loans");
		}
		else if (streq(command,QUIT))
		{
			return 0;
		}
		else 
		{
			showmenu = true;
			briefmenu();
		}

		if (! showmenu)	/* continue with query */
		{

			sprintf(query,"select %s from %s %s",
					attribute,relation,clause);
			mscall(argv[1],query);
		}
	}
	return 0;
}

int	printmenu()
{
	printf("\n\n	To Select:				Enter:\n\n");
	printf("An employee's personnel number			  %s\n",NUMBER);
	printf("An employee's phone number			  %s\n",PHONE);
	printf("An employee's credit limit			  %s\n",CREDIT);
	printf("All personnel records				  %s\n",RECORD);
	printf("All loans outstanding				  %s\n",LOANS);
	printf("To leave the program				  %s\n\n",QUIT);
	fflush (stdout);
	return (0);
}

int	briefmenu()
{
	printf("\nPersonnel number (%s), phone (%s), ",NUMBER,PHONE);
	printf("credit limit (%s), all records (%s),\n",CREDIT,RECORD);
	printf("all loans (%s), or quit (%s)\n",LOANS,QUIT);
	fflush (stdout);
	return (0);
}

int	findname()
{
	/* force non-null name and construct where_clause */

	strcpy(name,NOTHING);

	while (streq(name,NOTHING))  
	{
		printf("Enter employee name: ");
		fflush (stdout);
		fgets(name, sizeof (name) - 1, stdin);
		if (name[strlen(name) - 1] == '\n')
			name[strlen(name) - 1] = 0;
	}
	sprintf(clause,"where name = '%s'",name);
	return (0);
}
+-+-+-+-+-END-OF-FILE-+-+-+-+-+
chmod 644 script.c
cat > stdout <<'+-+-+-+-+-END-OF-FILE-+-+-+-+-+'


	To Select:				Enter:

An employee's personnel number			  n
An employee's phone number			  p
An employee's credit limit			  c
All personnel records				  r
All loans outstanding				  l
To leave the program				  q


Command: Enter employee name: number


Command: 
Personnel number (n), phone (p), credit limit (c), all records (r),
all loans (l), or quit (q)

Command: Enter employee name:       phone

    5442243

Command: 
Personnel number (n), phone (p), credit limit (c), all records (r),
all loans (l), or quit (q)

Command: Enter employee name: credit_limit

     $500.00

Command: 
Personnel number (n), phone (p), credit limit (c), all records (r),
all loans (l), or quit (q)

Command: name             char2                 char3                      sint  number        phone              date1               date2     date3     date4      date5       date6       date7       date8  credit_limit         dollar2

Kilroy             kilroy              Kilroy                        1      10      4269681   2 February  1981  February   2, 1981  02/02/81  02/02/81   2 Feb 81  Feb  2, 81  02/02/1981  02/02/1981       $500.00   $******500.00
Jones             Jones                  jone s                      3       3      6672951  22 January   1981  January   22, 1981  01/22/81  22/12/81  22 Jan 81  Jan 22, 81  01/22/1981  22/01/1981       $500.00   $******500.00
Mosca              Mosca               Mosca                         5       5      5442243  27 December  1980  December  27, 1980  12/27/80  27/12/80  27 Dec 80  Dec 27, 80  12/27/1980  27/12/1980       $750.00   $******750.00
Waldislaw        waldislaw             W a l d i s l a w             7      17      7236073  30 November  1980  November  30, 1980  11/30/80  30/11/80  30 Nov 80  Nov 30, 80  11/30/1980  30/11/1980       $200.00   $******200.00
Peterson            Peterson            p eterson                    9     888      9786060  20 May       1981  May       20, 1981  05/20/81  20/05/81  20 May 81  May 20, 81  05/20/1981  20/05/1981       $250.00   $******250.00
Scarlatti         Scarlatti              scar l atti                11     177      9617363   2 February  1982  February   2, 1982  02/02/82  02/02/82   2 Feb 82  Feb  2, 82  02/02/1982  02/02/1982       $100.00   $******100.00

Command: 
Personnel number (n), phone (p), credit limit (c), all records (r),
all loans (l), or quit (q)

Command: name                                    date        amount

Mosca                       2 February  1981       $150.00
Jones                       7 February  1981        $33.95
Kilroy                     16 February  1981       $250.00
Wladislaw                  27 February  1981        $55.00
Jones                       3 April     1981        $25.00
Mosca                       4 May       1981       $200.00
Wladislaw                  12 May       1981        $25.00
Peterson                    6 June      1981        $50.00
Wladislaw                  25 June      1981        $75.00
Jones                      12 August    1981       $300.00

Command: 
Personnel number (n), phone (p), credit limit (c), all records (r),
all loans (l), or quit (q)

Command: 
+-+-+-+-+-END-OF-FILE-+-+-+-+-+
chmod 644 stdout
cat > tag <<'+-+-+-+-+-END-OF-FILE-+-+-+-+-+'
Use a menu driven program to display part or all of the two tables.
+-+-+-+-+-END-OF-FILE-+-+-+-+-+
chmod 644 tag
