$!	
$!	File:		SMC.COM
$!
$!	Purpose:	Used to call SHOW MERGED CLASSES utility.
$!
$!	Usage:		SMC <pending> <spr,opr,... | @file > <CMS_library | @file > <output_report> [<"ALL_PENDING">] [<"ALL_SPR">]
$!
$!	Revision History:
$!		Date		Who		Description
$!		-----------------------------------------------------------------
$!		3/88		Bauer		Initial implementation.
$!		5/10/88		Bauer		Converted parameters to upper case and
$!						added usage error statement.
$!
$!
$ RUNSMC  :== $devtools:show_merged_classes						! Set up symbols for running C tools
$ USE_CMS :== $devtools:use_cms								! use_cms, weed_classes and 
$ WEED    :== $devtools:weed_classes							! show_merged_classes
$!
$ set noon										! Turn off error checking
$!
$!
$ on control_y then goto C_Y_EXIT							! Trap ^Y and ^C
$ on control_c then goto C_Y_EXIT
$!    
$ if p1 .eqs. "" then goto Usage_err
$ if p2 .eqs. "" then goto Usage_err
$ if p3 .eqs. "" then goto Usage_err
$ if p4 .eqs. "" then goto Usage_err
$!
$ lib_filename = ""
$!
$!
$ library = p3
$ at = f$locate("@", p3)								! Handle @<file> for case when file of 
$ if at .eq. f$length(p3) then goto one_library 					! CMS library names 
$ lib_filename = f$extract(at+1, 100, p3)
$ open/read lib_fp: 'lib_filename'
$!
$!
$ lib_read_loop:					!
$	read/end=big_exit lib_fp: cms_lib_name 
$ 	CMS SET LIB 'cms_lib_name' 							! Map to CMS library from file 
$ 	if .not. $STATUS then goto lib_read_loop 
$	library = cms_lib_name								! For USE_CMS case
$	goto init_vars
$!
$!
$ one_library:						!
$ CMS SET LIB 'library'									! Map to CMS library in  P3
$ if .not. $STATUS then goto AB_EXIT
$!
$!
$ init_vars:						!
$ temp_pending 	= ""									! Initialize certain string variables
$ temp_spr     	= ""
$ sorted_file  	= ""
$ comma         = ","
$ pending_error = 0
$ spr_error     = 0
$!
$ IF P4 .EQS. "SYS$OUTPUT" THEN GOTO DEFAULT_FILES					! Check for sys$output as the report
$!											! file - if so use default temporary files
$!
$ temp_pending = f$parse (p4,,,"name")+".pending_show_class;"				! Otherwise use report file specific 
$ temp_spr = f$parse (p4,,,"name")+".spr_show_class;"					! temporary files.
$ goto skip_default
$!
$!
$ default_files:				!
$ temp_pending = "pending.show_cms_class;"
$ temp_spr =     "spr.show_cms_class;"
$!
$!
$ skip_default:					!
$ CMS SHOW CLASS/CONT/OUT='temp_pending' 'p1'						! Dump contents of pending class to file
$ if .not. $STATUS then pending_error = 1 						! Check for errors
$!
$ num = 0
$!
$ p2 = f$edit(p2, "TRIM, UPCASE")
$ if p2 .nes. "USE_CMS" then goto check_for_at
$ sorted_file = "use_cms.list;"
$ USE_CMS 'library' 'sorted_file' 'p1'
$ sort/noduplicates 'sorted_file' 'sorted_file'
$ del/nolog 'sorted_file'-1
$ goto start_spr_read_at
$!
$ check_for_at:					!
$ at = f$locate("@", p2)								! Handle @<file> for case when file of 
$ if at .eq. f$length(p2) then goto loop						! class names as P2
$ filename = f$extract(at+1, 100, p2)
$ sort_file =    f$parse(filename,,,"name")+".SMC_SORT;"				! Make sure @<file> is soreted so we can
$ sorted_file =  f$parse(filename,,,"name")+".SMC_LIST;"				! strip out unnecessary class names to
$ sort/nodup 'filename' 'sort_file'							! save processing time 
$ if lib_filename .nes. "" then goto next_shcl
$ weed 'p3' 'sorted_file' 'sort_file'
$ goto delete_sort
$!
$ next_shcl:						!
$ weed 'cms_lib_name' 'sorted_file' 'sort_file'
$!
$ delete_sort:						!
$ delete/nolog  'sort_file'
$ start_spr_read_at:					!
$ open/read fp: 'sorted_file'
$ read_loop:						!
$	read/end=exit_loop fp: class_name 
$ 	if num .eq. 0 then goto first_read
$	CMS SHOW CLASS/CONT/OUT='temp_spr'/APPEND 'class_name'				! Dump contents of SPR class to file
$	goto read_loop
$ first_read: 						!
$	have_read = 1
$	num = 1
$	CMS SHOW CLASS/CONT/OUT='temp_spr' 'class_name'					! Dump contents of SPR class to file
$	goto read_loop
$!
$ loop: 						!				! This loop handles case where P2 is a
$	x = f$element(num, comma, p2)							! list of SPR (OPR...) classes and not
$	if x .eqs. COMMA then goto exit_loop						! an @<file>
$ 	if num .eq. 0 then goto first_time
$	CMS SHOW CLASS/CONT/OUT='temp_spr'/APPEND 'x'					! Dump contents of SPR class to file
$	num = num + 1
$	goto loop
$ first_time: 						!
$	CMS SHOW CLASS/CONT/OUT='temp_spr' 'x'						! Dump contents of SPR class to file
$	num = num + 1
$ goto loop
$!
$ exit_loop: 						!
$!
$ spr_error = num
$!
$ if f$logical("fp:") .nes. "" then $ close fp:						! Close @<file> if necessary
$!
$!
$ p5 = f$edit(p5, "TRIM, UPCASE")
$ p6 = f$edit(p6, "TRIM, UPCASE")
$ p7 = f$edit(p7, "TRIM, UPCASE")
$!
$ if pending_error .and. .NOT. spr_error then goto ab_exit
$ if lib_filename .nes. "" then goto next_runsmc
$ RUNSMC 'temp_pending' 'temp_spr' 'p3' 'p4' 'p1' 'p5' 'p6' 'p7'			! Now execute the C tool that parses out
$ goto norm_exit									! the information in the two files to 
$!											! generate the report.
$!
$!
$ next_runsmc:						!
$ RUNSMC 'temp_pending' 'temp_spr' 'cms_lib_name' 'p4' 'p1' 'p5' 'p6' 'p7'		! Now execute the C tool that parses out
$ goto norm_exit									! the information in the two files to 
$!											! generate the report.
$!
$!
$ c_y_exit:
$ lib_filename = ""								
$!
$!
$ ab_exit:						!				! ABNORMAL exits jump to here
$ norm_exit:						!				! Clean up before exiting
$!
$!
$ set nocontrol=y
$ save_message = f$environment("MESSAGE")						! Turn off VMS error messages temporarily
$ set message/nofac/noiden/nosever/notext
$ if f$logical("fp:") .nes. "" then $ close fp:
$ if temp_pending .nes. "" then $ delete/nolog 'temp_pending'				! Delete temporary files if they exist
$ if temp_spr .nes. ""     then $ delete/nolog 'temp_spr'
$ if sorted_file .nes. ""  then $ delete/nolog 'sorted_file'
$ set message 'save_message'								! Turn back on VMS error messages
$!
$! 
$ set control=y
$!
$!
$ on control_y then goto C_Y_EXIT							! Trap ^Y and ^C
$ on control_c then goto C_Y_EXIT
$!    
$!
$ if lib_filename .nes. "" then goto lib_read_loop
$ set on										! Turn back on error checking
$!
$ big_exit:						!
$ if f$logical("lib_fp:") .nes. "" then $ close lib_fp:					! Close @<file> if necessary
$ exit
$ Usage_err:	write sys$output "%SHOW_MERG-E-USAGERR, Usage:  SMC <pending-class>"
$               write sys$output "                                  <spr class | @sprfile | USE_CMS>"
$               write sys$output "                                  <cms library | @cmsfile>"
$               write sys$output "                                  <output report file | SYS$OUTPUT>"
$               write sys$output "                                  [<ALL_PENDING>]"
$               write sys$output "                                  [<ALL_SPR>]"
$ exit
