home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Collection - Online Library - January 1996 / CKITOS2196.ISO / diskette / gg244090.dsk / unc.dsk / CHAPTER.07 / MATHO_C.C < prev    next >
C/C++ Source or Header  |  1993-08-04  |  4KB  |  101 lines

  1. /******************************************************************************/
  2. /* Module  : matho_c.c                                                        */
  3. /* Purpose : Client module for server matho_s. This program determines if the */
  4. /*           user wants to use integer, floating point math with 3 decimal    */
  5. /*           places of precision or floating point math with 6 decimal places */
  6. /*           of precision. Based on the choice, selects the appropriate       */
  7. /*           server using explicit binding and object UUIDs. The type of math */
  8. /*           and the values to be added come from the command line. The       */
  9. /*           number string values are sent to the remote add procedure        */
  10. /*           together with the number of values passed and a pointer to the   */
  11. /*           variable that will contain the result.                           */
  12. /******************************************************************************/
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <dce/rpc.h>
  18. #include "errchk.h"
  19. #include "matho.h"
  20.  
  21. #define ENTRY_NAME "/.:/Servers/MathO"  /* Server entry name.                 */
  22.  
  23. int main ( int argc, char *argv[] )
  24. {
  25.    uuid_t obj_uuid;
  26.    long int i, numv;
  27.    value_s_t va[ MAX_VALUES ], sum;
  28.    rpc_binding_handle_t bh;
  29.    unsigned32 status;
  30.    rpc_ns_handle_t imp_ctxt;
  31.    char *str_bind_p, obj_uuid_str[ 37 ];
  32.  
  33.    /* Check if the user passed the minimum number of parameters.              */
  34.    if ( argc < 4 ) {
  35.       printf ( "Usage : %s <math_type : i, f or d> <values to be added>\n",
  36.                argv[ 0 ] );
  37.       exit ( 1 );
  38.    }
  39.  
  40.    /* Check if the user passed the math flag.                                 */
  41.    switch ( argv[ 1 ][ 0 ] ) {
  42.       case 'i' :
  43.          /* Create object UUID for integer math from string.                  */
  44.          uuid_from_string ( OBJ_UUID_INT, &obj_uuid, &status );
  45.          ERRCHK ( status );
  46.  
  47.          /* Print the object UUID that will be used.                          */
  48.          printf ( "Object UUID that will be used : %s\n", OBJ_UUID_INT );
  49.          break;
  50.  
  51.       case 'f' :
  52.          /* Create object UUID for float math from string.                    */
  53.          uuid_from_string ( OBJ_UUID_FLOAT, &obj_uuid, &status );
  54.          ERRCHK ( status );
  55.  
  56.          /* Print the object UUID that will be used.                          */
  57.          printf ( "Object UUID that will be used : %s\n", OBJ_UUID_FLOAT );
  58.          break;
  59.  
  60.       case 'd' :
  61.          /* Create object UUID for double float math from string.             */
  62.          uuid_from_string ( OBJ_UUID_DOUBLE, &obj_uuid, &status );
  63.          ERRCHK ( status );
  64.  
  65.          /* Print the object UUID that will be used.                          */
  66.          printf ( "Object UUID that will be used : %s\n", OBJ_UUID_DOUBLE );
  67.          break;
  68.  
  69.       default :
  70.          printf ( "Usage : %s <math_type : i, f or d> <values to be added>\n",
  71.                   argv[ 0 ] );
  72.          exit ( 1 );
  73.          break;
  74.    }
  75.  
  76.    /* Set up the context to import the bindings.                              */
  77.    rpc_ns_binding_import_begin ( rpc_c_ns_syntax_dce, ENTRY_NAME,
  78.                                  matho_v1_0_c_ifspec, &obj_uuid, &imp_ctxt,
  79.                                  &status );
  80.    ERRCHK ( status );
  81.  
  82.    /* Get the first binding handle.                                           */
  83.    rpc_ns_binding_import_next ( imp_ctxt, &bh, &status );
  84.    ERRCHK ( status );
  85.  
  86.    /* Get values from the command line and load them in array va.             */
  87.    for ( i = 0; i < MAX_VALUES && i < argc - 2; i++ ) {
  88.       strncpy ( va[ i ], argv[ i + 2 ], MAX_PRECISION );
  89.       va[ i ][ MAX_PRECISION ] = '\0';
  90.    }
  91.    numv = i;
  92.  
  93.    /* Call add passing values, number of values and pointer to result.        */
  94.    add ( bh, va, ( long )numv, sum );
  95.    printf ( "The sum is %s\n", sum );
  96.  
  97.    /* Release the context.                                                    */
  98.    rpc_ns_binding_import_done ( &imp_ctxt, &status );
  99.    ERRCHK ( status );
  100. }
  101.