home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 11 / 11.iso / n / n001 / 2.ddi / EXAMPLES / TUTORIAL / SERVER / RPROC.C next >
Encoding:
C/C++ Source or Header  |  1989-12-11  |  3.5 KB  |  121 lines

  1. /*                                                                            *
  2.  *                                                                            *
  3.  *                  Copyright 1987, 1988, 1989 Netwise, Inc.                  *
  4.  *                              All Rights Reserved                           *
  5.  *   This software contains information which is proprietary to and a trade   *
  6.  *   secret of Netwise, Inc. It is not to be used, reproduced, or disclosed   *
  7.  *   except as authorized in your license agreement.                          *
  8.  *                                                                            *
  9.  *                          Restricted Rights Legend                          *
  10.  *   Use, duplication,  or  disclosure  by the  Government  is  subject  to   *
  11.  *   restrictions as set forth in subparagraph (c)(1)(ii) of the Rights  in   *
  12.  *   Technical Data and  Computer Software clause  at 252.227-7013, or  the   *
  13.  *   equivalent Government clause for other agencies.                         *
  14.  *   Contractor: Netwise, Inc., Boulder, CO 80301 USA                         *
  15.  *                                                                            *
  16.  */ 
  17. /*
  18.  * File: tutorial\server\rproc.c
  19.  *
  20.  * This example runs in the following environment:
  21.  *    NetWare RPC 1.0, NetWare 2.1 or higher, DOS 3.3
  22.  *
  23.  * This file contains the remote procedures for the tutorial example.
  24.  *
  25.  */ 
  26.  
  27. #include <stdio.h>
  28. #include "database.h"    /* server header file,
  29.                created by RPC compiler */
  30.  
  31. int recerr;    /* external variable used by append_record */
  32.  
  33. static struct employee_record database_record[MAXREC+1];
  34.  
  35. void
  36. init()
  37. {
  38. /* Database initialization procedure; executes as a local
  39.  * procedure of the server program
  40.  */
  41.     database_record[0].employee_name[0] = '\0';
  42. }
  43.  
  44. int
  45. shut_down_server()
  46. {
  47. /* Procedure added to allow client program to 
  48.  * terminate server program when user exits
  49.  */
  50.     extern int shut_down;
  51.  
  52.     /* shut_down set to TRUE tells server control program
  53.      * that server program is to terminate 
  54.      */
  55.     shut_down = TRUE;
  56.     return(SUCCESS);
  57. }
  58.  
  59. int
  60. get_record (name, record_ptr)
  61. char name[NAMESIZE];            /* employee name */
  62. struct employee_record **record_ptr;    /* upon return, set to ptr
  63.                      * to employee record */
  64. {
  65. /* retrieve an employee record from the database */
  66.  
  67.     struct employee_record *ptr;
  68.  
  69.     ptr = database_record;
  70.     while (ptr->employee_name[0] != '\0') {
  71.         if (strcmp(ptr->employee_name, name))
  72.             ptr++;
  73.         else {
  74.             *record_ptr = ptr;
  75.             return (SUCCESS);
  76.         }    
  77.     }
  78.     /* set value of record pointer to NULL to indicate that
  79.      * no structure is being returned
  80.      */
  81.     *record_ptr = NULL;
  82.     return (ERROR);
  83. }
  84.  
  85. int
  86. append_record (record_ptr)
  87. struct employee_record *record_ptr;    /* ptr to record to add */
  88. {
  89. /* add an employee record to the database */
  90.  
  91.     struct employee_record *ptr;
  92.  
  93.     /* look through database for duplicate employee names
  94.      * or numbers, and find room for a new record
  95.      */
  96.     ptr = database_record;
  97.     while (ptr->employee_name[0] != '\0') {
  98.         if (strcmp(ptr->employee_name,
  99.                 record_ptr->employee_name) == 0) {
  100.             recerr = OLDNAME;
  101.             return (ERROR);
  102.         }
  103.         if (record_ptr->employee_type == PERMANENT) { 
  104.             if (ptr->employee_info.employee_id == 
  105.                 record_ptr->employee_info.employee_id) {
  106.             recerr = OLDNUM;
  107.             return (ERROR);
  108.             }
  109.         }
  110.         if (++ptr > &database_record[MAXREC]) {
  111.             recerr = DBFULL;
  112.             return (ERROR);
  113.         }
  114.     }
  115.  
  116.     /* add employee record to database */
  117.     *ptr = *record_ptr;
  118.     (++ptr)->employee_name[0] = '\0';
  119.     return (SUCCESS);
  120. }
  121.