home *** CD-ROM | disk | FTP | other *** search
- /* *
- * *
- * Copyright 1987, 1988, 1989 Netwise, Inc. *
- * All Rights Reserved *
- * This software contains information which is proprietary to and a trade *
- * secret of Netwise, Inc. It is not to be used, reproduced, or disclosed *
- * except as authorized in your license agreement. *
- * *
- * Restricted Rights Legend *
- * Use, duplication, or disclosure by the Government is subject to *
- * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in *
- * Technical Data and Computer Software clause at 252.227-7013, or the *
- * equivalent Government clause for other agencies. *
- * Contractor: Netwise, Inc., Boulder, CO 80301 USA *
- * *
- */
- /*
- * File: tutorial\client\client.c
- *
- * This example runs in the following environments:
- * NetWare RPC 1.0, NetWare 2.1 or higher, DOS 3.3
- *
- * Client code for the tutorial example. This program calls two remote
- * procedures, opening and closing the connection for each call using
- * the non-persistent style of process binding.
- *
- */
-
- #include <stdio.h>
- #include "database.h" /* client header file,
- created by RPC compiler */
-
- int recerr; /* external set by remote proc append_record */
- extern int _rpcerr_; /* declare RPC error code */
-
- void add_employee_info();
- void list_employee_info();
-
- /* Server_Name is used to set the process-binding variable.
- * It must be defined as the name the server registers under.
- */
- #define Server_Name "example"
-
- /* declare variable of type server_name for process binding */
- server_name sname;
-
- main()
- {
- char chr;
-
- /* To access the remote procedures, the process-binding
- * variable sname must be set to the server name.
- * The syntax for the server name is environment specific.
- * If this client were to be moved to another environment,
- * sname might have to be set differently.
- */
- sname = Server_Name;
-
- /* prompt user for function */
- while (TRUE) {
- printf("\nType 'a' to append a new employee record\n");
- printf(" 'l' to list an employee record\n");
- printf(" 'x' to exit from this program\n");
- scanf(" %c", &chr);
-
- switch (chr) {
- case 'a':
- add_employee_info();
- break;
- case 'l':
- list_employee_info();
- break;
- case 'x':
- /* call remote procedure to shut down
- * server when user exits
- */
- shut_down_server();
- exit(0);
- case EOF :
- case 0 :
- /* Watch out for problem with standard input */
- printf("\nunexpected end of file encountered\n");
- printf("execution aborted");
- shut_down_server();
- exit (1);
- default:
- printf("Enter only 'a', 'l', or 'x'\n");
- break;
- }
- }
- }
-
- void
- list_employee_info()
- {
- /* prompt for an employee name, call get_record
- * to get the employee information from the database, and then
- * display it
- */
- int status;
- char name1[FIRSTNAME], name2[LASTNAME];
- struct employee_record *record_ptr;
- char name[NAMESIZE];
-
- printf("\nEnter employee name, first name then last name: ");
- scanf("%s %s", name1, name2);
- strcpy(name, name1);
- strcat(name, " ");
- strcat(name, name2);
-
- /* get employee info from database */
- status = get_record(name, &record_ptr);
-
- /* check RPC error code after remote call */
- if (_rpcerr_) {
- printf("RPC error %d from get_record()\n", _rpcerr_);
- return;
- }
- if (status) {
- printf("Employee %s not found\n", name);
- return;
- }
-
- /* display employee info based on employee type */
- switch (record_ptr->employee_type) {
- case PERMANENT:
- printf("Employee %s, Permanent, No. %d\n",
- record_ptr->employee_name,
- record_ptr->employee_info.employee_id);
- break;
- case TEMPORARY:
- printf("Employee %s, Temporary, Agency %s\n",
- record_ptr->employee_name,
- record_ptr->employee_info.temp_agency);
- break;
- default:
- printf("Employee %s, Invalid employee_type\n",
- record_ptr->employee_name);
- break;
- }
- /* free memory allocated by client stub for returned
- * employee structure
- */
- free(record_ptr);
- return;
- }
-
-
- void
- add_employee_info()
- {
- /* prompt for employee information and then add
- * the employee to the database.
- */
- int loop, status;
- char name1[FIRSTNAME], name2[LASTNAME];
- struct employee_record record;
-
- loop = TRUE;
- printf("\nEnter employee name, first name then last name: ");
- scanf("%s %s", name1, name2);
- strcpy(record.employee_name, name1);
- strcat(record.employee_name, " ");
- strcat(record.employee_name, name2);
- printf("Enter employee type, %c=permanent, %c=temporary: ",
- PERMANENT, TEMPORARY);
- scanf(" %c", &record.employee_type);
-
- /* get additional employee info depending on employee type */
- while (loop) {
- switch (record.employee_type) {
- case PERMANENT:
- printf("Enter employee number: ");
- scanf("%d", &record.employee_info.employee_id);
- loop = FALSE;
- break;
- case TEMPORARY:
- printf("Enter agency name: ");
- scanf("%s", record.employee_info.temp_agency);
- loop = FALSE;
- break;
- default:
- printf("Enter %c=permanent, %c=temporary\n",
- PERMANENT, TEMPORARY);
- scanf(" %c", &record.employee_type);
- break;
- }
- }
-
- /* add record to database and check for errors */
- status = append_record(&record);
-
- /* check RPC error code after remote call */
- if (_rpcerr_) {
- printf("RPC error %d from append_record()\n",_rpcerr_);
- return;
- }
- if (status) {
- printf("Error appending new employee record\n");
- switch (recerr) {
- case OLDNAME:
- printf("Duplicate employee name\n");
- break;
- case OLDNUM:
- printf("Duplicate employee number\n");
- break;
- case DBFULL:
- printf("Data base is full\n");
- break;
- default:
- printf("Unrecognized error\n");
- }
- }
- return;
- }
-