/* @(#)79    1.11  src/examples/type_mgr/client_args.c, examples.src, os2dce21.dss, 960602a.1 1/11/96 10:21:29 */
/*
 * COMPONENT_NAME:  examples.src
 *
 * FUNCTIONS:
 *
 * ORIGINS: 27
 *
 * (C) COPYRIGHT International Business Machines Corp. 1992, 1994
 * All Rights Reserved
 * Licensed Materials - Property of IBM
 *
 * US Government Users Restricted Rights - Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 *
 */

/*********************************************************************
 *  File      :  client_args.c                                       *
 *********************************************************************
 *                                                                   *
 *  Functions :  client_args()                                       *
 *                                                                   *
 *  Comments  :  Routines that read and interpret command line args. *
 *               Global variables can be set, based on the cmd line  *
 *               args, and then used by other client modules.        *
 *                                                                   *
 *********************************************************************/

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#ifdef IBMOS2
# include <os2def.h>
#endif
#include <dce/rpc.h>
#include "cust_if.h"
#include "type_mgr.h"
#include <util.h>
#include "client.h"

#define PRINT_USAGE \
    PRINT("\tUsage: %s   -n [client name]\n",argv[0]); \
    PRINT("\t\t\t-o [object entry]\n"); \
    PRINT("\t\t\t-z\n");


/*
 *  Global variables that are used throughout the program.  Any variables
 *  defined here should have extern definitions in client.h, so the
 *  global vars can be accessed anywhere in the client program.
 */

char       g_object_entry[ENTRY_LEN];
boolean32  g_trace;

extern int getopt(int argc, char *argv[], char *opstring);


/*********************************************************************
 *   Function    :  client_args()                                    *
 *********************************************************************
 *                                                                   *
 *   Description :  Parse the command line arguments, using the      *
 *                  getopt() function.  Sets the appropriate         *
 *                  variables where necessary.  Variables can then   *
 *                  be used in other parts of the program.           *
 *                                                                   *
 *   Returns     :  (0) success, or appropriate error code.          *
 *                                                                   *
 *********************************************************************/

unsigned32 client_args( unsigned32 argc,
                        char       *argv[] )
{
    extern char        *optarg;
    extern unsigned32  optind;
    unsigned32         c;
    unsigned32         error = 0;

    /*
     *  If no command line args, print the command usage.
     */
    if (argc < 2)
    {
        PRINT_USAGE;
        return(++error);
    }

    /*
     *  Set the default characteristics of the program.
     */

    g_trace = FALSE;

    while ((c = getopt( argc, argv, "n:o:z" )) != EOF )
    {
        switch (c)
        {
            case 'n': /* tag name */
                strncpy( g_prog_tag, optarg, PROG_TAG_LEN-1 );
                break;

            case 'o': /* object name */
                sprintf( g_object_entry, "%s%s", NAME_SERVICE_PATH, optarg);
                break;

            case 'z': /* tracing */
                g_trace = TRUE;
                break;

            case '?':
                error++;
                break;

            default:
                PRINT("Invalid command line arguments!\n");
                return(++error);

        } /* end switch */

        if ( error )
        {
            PRINT_USAGE;
            return(error);
        }

    } /* end while */

    return(error);

} /* end client_args() */

/* EOF client_args.c */

