# Copyright 2003 by Sun Microsystems, Inc.
# All rights reserved.

# File
# ----
# awk script
# 
# Description
# -----------
# Service_svc.c parsing

#pragma ident  "@(#)Service_svc_c.awk 1.1     04/05/12 SMI"

{
	main = match($0,"main")
	if (main != 0 )  {
	        print("#include <pthread.h>")
		print("extern int portNumber;")
		print("extern int portNumberCreated;")
		
		print("extern pthread_mutex_t mutexPortNumber;");
		print("extern pthread_cond_t condPortNumber;");
		print("")
      		print("void *connectorserverthread(void *arg)")
	}
	else {
     		svc_run = match ($0,"svc_run")
		svc_run_returned = match ($0,"svc_run returned")
   		if ((svc_run != 0 )  && (svc_run_returned == 0)) {
      			print"\tportNumber=getrpcport(\"localhost\",Service_program, Service_version,IPPROTO_TCP);"
			print("\tpthread_mutex_lock(&mutexPortNumber);")
			print("\tportNumberCreated = 1 ;")
			print("\pthread_cond_signal(&condPortNumber);");
			print("\tpthread_mutex_unlock(&mutexPortNumber);")
   		}

   		svc_create = match($0,"svc_create")
   		if (svc_create != 0 )  {
      			print("#endif /* corresponds to #if 0 */")
   		}
   
   		sigset = match($0,"sigset")
   		if (sigset != 0 )  {
      			print("#if 0")
   		}

		print $0
	}
}
