testexecmgmt/ucc/BinInternal/rpcgen/rpc_main.c
author Johnson Ma <johnson.ma@nokia.com>
Mon, 08 Mar 2010 15:04:18 +0800
changeset 0 3da2a79470a7
permissions -rw-r--r--
Initial EPL Contribution
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     1
/*********************************************************************
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     2
 * RPC for the Windows NT Operating System
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     3
 * 1993 by Martin F. Gergeleit
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     4
 * Users may use, copy or modify Sun RPC for the Windows NT Operating 
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     5
 * System according to the Sun copyright below.
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     6
 *
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     7
 * RPC for the Windows NT Operating System COMES WITH ABSOLUTELY NO 
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     8
 * WARRANTY, NOR WILL I BE LIABLE FOR ANY DAMAGES INCURRED FROM THE 
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     9
 * USE OF. USE ENTIRELY AT YOUR OWN RISK!!!
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    10
 *********************************************************************/
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    11
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    12
/* @(#)rpc_main.c	2.2 88/08/01 4.0 RPCSRC */
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    13
/*
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    14
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    15
 * unrestricted use provided that this legend is included on all tape
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    16
 * media and as a part of the software program in whole or part.  Users
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    17
 * may copy or modify Sun RPC without charge, but are not authorized
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    18
 * to license or distribute it to anyone else except as part of a product or
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    19
 * program developed by the user.
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    20
 * 
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    21
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    22
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    23
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    24
 * 
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    25
 * Sun RPC is provided with no support and without any obligation on the
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    26
 * part of Sun Microsystems, Inc. to assist in its use, correction,
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    27
 * modification or enhancement.
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    28
 * 
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    29
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    30
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    31
 * OR ANY PART THEREOF.
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    32
 * 
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    33
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    34
 * or profits or other special, indirect and consequential damages, even if
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    35
 * Sun has been advised of the possibility of such damages.
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    36
 * 
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    37
 * Sun Microsystems, Inc.
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    38
 * 2550 Garcia Avenue
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    39
 * Mountain View, California  94043
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    40
 */
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    41
//#ifndef lint
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    42
//static char sccsid[] = "@(#)rpc_main.c 1.7 87/06/24 (C) 1987 SMI";
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    43
//#endif
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    44
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    45
/*
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    46
 * rpc_main.c, Top level of the RPC protocol compiler. 
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    47
 * Copyright (C) 1987, Sun Microsystems, Inc. 
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    48
 */
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    49
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    50
#include <stdio.h>
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    51
#include <assert.h>
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    52
#include <stdlib.h>
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    53
#include <string.h>
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    54
#include <ctype.h>
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    55
#include "rpc_util.h"
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    56
#include "rpc_pars.h"
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    57
#include "rpc_scan.h"
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    58
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    59
#ifdef WIN32
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    60
#include <direct.h>
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    61
#include <process.h>
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    62
#include <io.h>
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    63
#include <fcntl.h>
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    64
#else
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    65
#include <unistd.h>
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    66
#include <sys/file.h>
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    67
#endif
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    68
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    69
#include "ae_component_rpc.h"
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    70
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    71
#define EXTEND	1		/* alias for TRUE */
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    72
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    73
static char *cmdname;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    74
#ifdef WIN32
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    75
#ifdef __BORLANDC__
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    76
static char CPP[] = "cpp32";
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    77
static char CPPFLAGS[] = "-C -P- -oCON";
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    78
#else
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    79
static char CPP[] = "cl";
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    80
static char CPPFLAGS[] = "/C /EP /nologo";
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    81
#endif
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    82
#else
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    83
static char CPP[] = "/usr/bin/cpp";
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    84
static char CPPFLAGS[] = "-C";
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    85
#endif
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    86
static char *allv[] = {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    87
	"rpcgen", "-s", "udp", "-s", "tcp",
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    88
};
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    89
static int allc = sizeof(allv)/sizeof(allv[0]);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    90
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    91
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    92
/* prototypes */
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    93
extern void crash();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    94
static void do_registers( int argc, char *argv[] );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    95
struct commandline command_line;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    96
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    97
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    98
/*
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    99
 * add extension to filename 
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   100
 */
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   101
char *
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   102
extendfile(file, ext)
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   103
	char *file;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   104
	char *ext;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   105
{
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   106
#ifdef WIN32
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   107
	int i;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   108
#endif
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   109
	char *res;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   110
	char *p;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   111
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   112
	res = alloc(strlen(file) + strlen(ext) + 1);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   113
	if (res == NULL) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   114
		abort();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   115
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   116
#ifdef WIN32
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   117
	p = NULL;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   118
	for (i = 0; file[i] != '\0'; i++)
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   119
		if (file[i] == '.')
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   120
			p = &file[i];
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   121
#else
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   122
	p = rindex(file, '.');
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   123
#endif
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   124
	if (p == NULL) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   125
		p = file + strlen(file);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   126
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   127
	(void) strcpy(res, file);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   128
	(void) strcpy(res + (p - file), ext);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   129
	return (res);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   130
}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   131
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   132
/*
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   133
 * Open output file with given extension 
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   134
 */
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   135
void
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   136
open_output(infile, outfile)
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   137
	char *infile;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   138
	char *outfile;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   139
{
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   140
	char *ptr;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   141
	char buff[1024];
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   142
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   143
	// check that some file is specified
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   144
	if (outfile == NULL) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   145
		fout = stdout;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   146
		return;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   147
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   148
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   149
	// set the buffer with the specified output path
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   150
	strcpy( buff, command_line.outfile );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   151
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   152
	// only copy the filename itself
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   153
	ptr = strrchr( outfile, '\\' );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   154
	if( ptr == NULL ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   155
		ptr = strrchr( outfile, '/' );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   156
		if( ptr == NULL ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   157
			ptr = outfile - 1;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   158
		}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   159
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   160
	ptr++;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   161
	strcat( buff, ptr );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   162
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   163
	// check that we are not going to overwrite the input file
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   164
	if (infile != NULL && streq(buff, infile)) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   165
		f_print(stderr, "%s: output would overwrite %s\n", cmdname, infile);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   166
		crash();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   167
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   168
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   169
//	fprintf( stderr, "INFO: opening output file %s\n", buff );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   170
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   171
	// open the output file
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   172
	fout = fopen(buff, "w");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   173
	if (fout == NULL) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   174
		f_print(stderr, "%s: unable to open output file.", cmdname);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   175
		perror(buff);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   176
		crash();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   177
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   178
	record_open(buff);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   179
}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   180
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   181
/*
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   182
 * Open input file with given define for C-preprocessor 
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   183
 */
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   184
void
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   185
open_input(infile, define)
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   186
	char *infile;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   187
	char *define;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   188
{
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   189
#ifdef WIN32
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   190
#ifdef __BORLANDC__
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   191
#define _P_WAIT P_WAIT
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   192
#define _spawnlp spawnlp
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   193
#endif
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   194
	int old;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   195
	int pd[2];
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   196
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   197
	infilename = (infile == NULL) ? "<stdin>" : infile;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   198
	_pipe(pd, 0xffff, O_TEXT);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   199
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   200
		old = dup(1);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   201
		(void) dup2(pd[1], 1);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   202
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   203
		if (_spawnlp(_P_WAIT, CPP, CPP, CPPFLAGS, 
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   204
					define, infile, NULL) < 0) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   205
			f_print(stderr, "%s: unable to open ", cmdname);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   206
			perror(CPP);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   207
			crash();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   208
		}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   209
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   210
	(void) dup2(old, 1);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   211
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   212
	(void) close(pd[1]);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   213
	fin = fdopen(pd[0], "r");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   214
	if (fin == NULL) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   215
		f_print(stderr, "%s: ", cmdname);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   216
		perror(infilename);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   217
		crash();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   218
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   219
#else
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   220
	int pd[2];
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   221
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   222
	infilename = (infile == NULL) ? "<stdin>" : infile;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   223
	(void) pipe(pd);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   224
	switch (fork()) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   225
	case 0:
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   226
		(void) close(1);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   227
		(void) dup2(pd[1], 1);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   228
		(void) close(pd[0]);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   229
		execl(CPP, CPP, CPPFLAGS, define, infile, NULL);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   230
		perror("execl");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   231
		exit(1);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   232
	case -1:
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   233
		perror("fork");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   234
		exit(1);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   235
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   236
	(void) close(pd[1]);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   237
	fin = fdopen(pd[0], "r");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   238
	if (fin == NULL) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   239
		f_print(stderr, "%s: ", cmdname);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   240
		perror(infilename);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   241
		crash();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   242
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   243
#endif
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   244
}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   245
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   246
/*
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   247
 * Compile into an XDR routine output file
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   248
 */
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   249
static void
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   250
c_output(infile, define, extend, outfile)
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   251
	char *infile;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   252
	char *define;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   253
	int extend;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   254
	char *outfile;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   255
{
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   256
	definition *def;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   257
	char *include;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   258
	char *outfilename;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   259
	long tell;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   260
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   261
	open_input(infile, define);	
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   262
	outfilename = extend ? extendfile(infile, outfile) : outfile;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   263
	open_output(infile, outfilename);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   264
	f_print(fout, "#include <rpc/rpc.h>\n");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   265
	if (infile && (include = extendfile(infile, ".h"))) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   266
		f_print(fout, "#include \"%s\"\n", include);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   267
		free(include);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   268
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   269
	tell = ftell(fout);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   270
	while ((def = get_definition())) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   271
		emit(def);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   272
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   273
	if (extend && tell == ftell(fout)) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   274
		(void) unlink(outfilename);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   275
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   276
}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   277
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   278
/*
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   279
 * Compile into an XDR header file
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   280
 */
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   281
static void
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   282
h_output(infile, define, extend, outfile)
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   283
	char *infile;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   284
	char *define;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   285
	int extend;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   286
	char *outfile;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   287
{
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   288
	definition *def;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   289
	char *outfilename;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   290
	long tell;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   291
	char nbuff[256];
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   292
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   293
	open_input(infile, define);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   294
	outfilename =  extend ? extendfile(infile, outfile) : outfile;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   295
	open_output(infile, outfilename);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   296
	tell = ftell(fout);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   297
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   298
	// AE -- do proper #ifdef
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   299
	{
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   300
		char *ptr;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   301
		int slen;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   302
		int i;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   303
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   304
		// get a pointer to the filename
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   305
		ptr = strrchr( outfilename, '\\' );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   306
		ptr = ((ptr == NULL) ? outfilename : ptr+1);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   307
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   308
		// now copy the filename
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   309
		slen = strlen(ptr);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   310
		assert( slen < 256 );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   311
		memcpy( nbuff, ptr, slen );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   312
		nbuff[slen] = 0;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   313
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   314
		// make everything upper case
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   315
		for( i = 0; i < slen; i++ ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   316
			nbuff[i] = toupper( nbuff[i] );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   317
		}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   318
		assert( nbuff[slen-2] == '.' );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   319
		nbuff[slen-2] = '_';
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   320
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   321
		// now print the ifdef
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   322
		f_print( fout, "#ifndef __%s__\n", nbuff );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   323
		f_print( fout, "#define __%s__\n", nbuff );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   324
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   325
		
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   326
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   327
	/*** The following line was added,  ***/
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   328
	/*** 31.03.92, Detlef Schwellenbach ***/
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   329
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   330
	f_print(fout, "#include <rpc/types.h>\n");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   331
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   332
	// AE -- include this for the CLIENT type
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   333
	{
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   334
		f_print(fout, "#include <rpc/rpc.h>\n\n");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   335
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   336
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   337
	while ((def = get_definition())) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   338
		print_datadef(def);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   339
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   340
	if (extend && tell == ftell(fout)) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   341
		(void) unlink(outfilename);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   342
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   343
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   344
	// AE -- end the #def
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   345
	f_print(fout, "#endif /* __%s__ */\n", nbuff );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   346
}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   347
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   348
/*
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   349
 * Compile into an RPC service
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   350
 */
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   351
static void
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   352
s_output(argc, argv, infile, define, extend, outfile, nomain)
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   353
	int argc;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   354
	char *argv[];
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   355
	char *infile;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   356
	char *define;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   357
	int extend;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   358
	char *outfile;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   359
	int nomain;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   360
{
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   361
	char *include;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   362
	definition *def;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   363
	int foundprogram;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   364
	char *outfilename;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   365
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   366
	open_input(infile, define);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   367
	outfilename = extend ? extendfile(infile, outfile) : outfile;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   368
	open_output(infile, outfilename);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   369
	f_print(fout, "#include <stdio.h>\n");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   370
	f_print(fout, "#include <rpc/rpc.h>\n");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   371
	f_print(fout, "#ifdef WIN32\n");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   372
	f_print(fout, "#include <rpc/PMAP_CLN.H>\n");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   373
	f_print(fout, "#else\n");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   374
	f_print(fout, "#include <rpc/pmap_clnt.h>\n");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   375
	f_print(fout, "#endif\n");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   376
	if (infile && (include = extendfile(infile, ".h"))) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   377
		f_print(fout, "#include \"%s\"\n", include);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   378
		free(include);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   379
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   380
	foundprogram = 0;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   381
	while ((def = get_definition())) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   382
		foundprogram |= (def->def_kind == DEF_PROGRAM);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   383
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   384
	if (extend && !foundprogram) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   385
		(void) unlink(outfilename);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   386
		return;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   387
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   388
	if (nomain) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   389
		write_programs((char *)NULL);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   390
	} else {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   391
		write_most();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   392
		do_registers(argc, argv);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   393
		write_rest();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   394
		write_programs("static");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   395
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   396
}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   397
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   398
static void
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   399
l_output(infile, define, extend, outfile)
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   400
	char *infile;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   401
	char *define;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   402
	int extend;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   403
	char *outfile;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   404
{
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   405
	char *include;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   406
	definition *def;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   407
	int foundprogram;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   408
	char *outfilename;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   409
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   410
	open_input(infile, define);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   411
	outfilename = extend ? extendfile(infile, outfile) : outfile;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   412
	open_output(infile, outfilename);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   413
	f_print(fout, "#include <rpc/rpc.h>\n");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   414
	if (infile && (include = extendfile(infile, ".h"))) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   415
		f_print(fout, "#include \"%s\"\n", include);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   416
		free(include);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   417
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   418
	foundprogram = 0;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   419
	while ((def = get_definition())) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   420
		foundprogram |= (def->def_kind == DEF_PROGRAM);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   421
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   422
	if (extend && !foundprogram) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   423
		(void) unlink(outfilename);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   424
		return;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   425
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   426
	write_stubs();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   427
}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   428
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   429
/*
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   430
 * Perform registrations for service output 
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   431
 */
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   432
static void
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   433
do_registers(argc, argv)
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   434
	int argc;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   435
	char *argv[];
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   436
{
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   437
	int i;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   438
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   439
	for (i = 1; i < argc; i++) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   440
		if (streq(argv[i], "-s")) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   441
			write_register(argv[i + 1]);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   442
			i++;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   443
		}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   444
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   445
}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   446
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   447
/*
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   448
 * Parse command line arguments 
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   449
 */
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   450
static int parseargs( int argc, char *argv[], struct commandline *cmd )
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   451
{
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   452
	int i, err;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   453
	char *opt;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   454
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   455
	// check params
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   456
	assert( argv != NULL );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   457
	assert( cmd != NULL );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   458
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   459
	// clear the cmd struct
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   460
	memset( cmd, 0, sizeof(*cmd) );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   461
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   462
	// if we don't have at least one extra param (the filename) then exit
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   463
	if( argc < 2 ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   464
		return 0;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   465
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   466
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   467
	// now parse each token
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   468
	for( i = 1; i < argc; i++ ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   469
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   470
		// if the first char is not '-' then this is the filename and we should break
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   471
		if( argv[i][0] != '-' ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   472
			break;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   473
		}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   474
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   475
		// get a pointer to the option
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   476
		opt = &(argv[i][1]);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   477
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   478
		// now look for a match
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   479
		if( strcmp(opt,"client") == 0 ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   480
			cmd->client_flag = 1;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   481
		} else if( strcmp(opt,"server") == 0 ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   482
			cmd->server_flag = 1;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   483
		} else if( strcmp(opt,"component_base") == 0 ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   484
			cmd->component_base_flag = 1;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   485
		} else if( strcmp(opt,"component_mod_service_manager") == 0 ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   486
			cmd->component_mod_service_manager = 1;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   487
		} else if( strcmp(opt,"component_mod_component_impl") == 0 ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   488
			cmd->component_mod_component_impl = 1;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   489
		} else if( strcmp(opt,"wrapstring") == 0 ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   490
			cmd->wrapstring_flag = 1;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   491
		} else if( strcmp(opt,"header") == 0 ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   492
			cmd->header = 1;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   493
		} else if( opt[0] == 't' ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   494
			opt++;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   495
			ae_set_trace( atoi(opt) );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   496
		} else if( strncmp(opt,"o:",2) == 0 ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   497
			opt = &(argv[i][3]);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   498
			strcpy( cmd->outfile, opt );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   499
		} else if( strncmp(opt,"p:",2) == 0 ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   500
			opt = &(argv[i][3]);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   501
			err = chdir( opt );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   502
			if( err != 0 ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   503
				fprintf( stderr, "WARNING: couldn't change to the specified path.\n" );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   504
				return 0;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   505
			}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   506
//			fprintf( stderr, "INFO: changing directory to %s.\n", opt );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   507
		} else {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   508
			fprintf( stderr, "WARNING: unknown option '-%s'\n", opt );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   509
		}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   510
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   511
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   512
	// now read in the filename
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   513
	if( i == argc ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   514
		fprintf( stderr, "WARNING: no filename specified.\n" );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   515
		return 0;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   516
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   517
	cmd->infile = argv[i];
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   518
	
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   519
	// done 
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   520
	return 1;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   521
}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   522
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   523
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   524
int
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   525
main(argc, argv)
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   526
	int argc;
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   527
	char *argv[];
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   528
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   529
{
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   530
	// parse the command line
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   531
	if (!parseargs(argc, argv, &command_line)) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   532
		fprintf( stderr, "usage: %s [-header | -client | -server | -component_base | -component_mod_service_manager | -component_mod_component_impl | -w | -t#] interface_file\n", argv[0] );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   533
		fprintf( stderr, "\tt0 - Component stubs.\n" );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   534
		fprintf( stderr, "\tt2 - Service manager.\n" );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   535
		fprintf( stderr, "\tt4 - Component instance.\n" );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   536
		fprintf( stderr, "\tt6 - Client stub.\n" );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   537
		exit(1);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   538
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   539
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   540
	// print the header if appropriate
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   541
	if( command_line.client_flag || command_line.server_flag || command_line.header ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   542
		h_output(command_line.infile, "-DRPC_HDR", EXTEND, ".h");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   543
		reinitialize();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   544
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   545
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   546
	// output the xdr file if appropriate
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   547
	if( command_line.client_flag || command_line.server_flag ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   548
		c_output(command_line.infile, "-DRPC_XDR", EXTEND, "_xdr.c");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   549
		reinitialize();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   550
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   551
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   552
	// output the client files
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   553
	if( command_line.client_flag ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   554
		l_output(command_line.infile, "-DRPC_CLNT", EXTEND, "_clnt.c");
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   555
		reinitialize();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   556
		if( command_line.component_base_flag ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   557
			ae_output_rpc_file( command_line.infile, ".h", TYPE_CLIENT_H );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   558
			reinitialize();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   559
			ae_output_rpc_file( command_line.infile, ".cpp", TYPE_CLIENT_C );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   560
			reinitialize();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   561
		}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   562
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   563
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   564
	// output the server files
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   565
	if( command_line.server_flag ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   566
		s_output(allc, allv, command_line.infile, "-DRPC_SVC", EXTEND, "_svc.c", 0);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   567
		reinitialize();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   568
		if( command_line.component_base_flag ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   569
			ae_output_rpc_file( command_line.infile, "_svc_stub_impl.cpp", TYPE_SVC_STUB_IMPL );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   570
			reinitialize();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   571
		}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   572
		if( command_line.component_mod_service_manager ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   573
			ae_output_rpc_file( command_line.infile, ".cpp", TYPE_SVC_MGR_C );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   574
			reinitialize();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   575
			ae_output_rpc_file( command_line.infile, ".h", TYPE_SVC_MGR_H );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   576
			reinitialize();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   577
		}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   578
		if( command_line.component_mod_component_impl ) {
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   579
			ae_output_rpc_file( command_line.infile, ".h", TYPE_INST_H );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   580
			reinitialize();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   581
			ae_output_rpc_file( command_line.infile, ".cpp", TYPE_INST_C );
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   582
			reinitialize();
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   583
		}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   584
	}
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   585
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   586
	exit(0);
3da2a79470a7 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   587
}