10	%TITLE "QUEUE_CONTROL.BAS"
	%SBTTL "Documentation Section"
	%IDENT "X02.70"
100	!++
	!**********************************************************************
	!  Program:	QUEUE_CONTROL.BAS
	!  Version:	2.7
	!  Purpose:	Allow users to control local queues from a priv'ed
        !               process.
	!
	!		MODIFICATION HISTORY
	!
	!   DATE     PROGRAMMER  VER #         MODIFICATION DESCRIPTION
	! ========= ============ ===== ========================================
	! 30-Feb-89 G.M. MORIN     1.0 initial release
	!           C.E. SALYERS
	! 13-JUL-89 C.E. SALYERS   1.1 Add size to SHOW QUEUE
        !                              Disable Broadcast trapping when exitting
	!			       Added more error trepping
	! 15-JUL-89 C.E. SALYERS   1.2 Add QC group 
	!                              Fixed SHOW QUEUE error
	! 19-JUL-89 C.E. SALYERS   1.3 Added help screen         
	! 20-JUL-89 C.E. SALYERS   1.4 Error Trapping in job entry number input
	! 20_JUL-89 C.E. SALYERS   1.5 Added LIST FORMS
	! 20-JUL-89 C.E. SALYERS   1.6 Added STOP/NEXT
	! 24-JUL-89 C.E. SALYERS   1.7 Added NO CHANGE as default for
        !                                 QUEUE and FORM Function
        !                              Fixed LIST FORMS bug 
	! 26-JUL-89 C.E. SALYERS   1.8 Added HELP KEY and F10 as exit
        ! 07-AUG-89 C.E. SALYERS   1.9 Changed group lookup to SYS$PRINT lookup
	! 30-AUG-89 C.E. SALYERS   2.0 Mutlipul pages during a JOBS/SHOW 
	! 15-SEP-89 C.E. SALYERS   2.1 Fixed bug - If no SYS$PRINT logical
        ! 06-OCT-89 C.E. SALYERS   2.2 scrolls jobs in queue to top
        ! 19-OCT-89 C.E. SALYERS   2.3 Update for VMS V5.1-1
	! 21-NOV-89 C.E. SALYERS   2.4 Make all choices menu driven
	! 28-DEC-89 C.E. SALYERS   2.5 Changed SHOW QUEUE to look better
	! 21-MAR-90 C.E. SALYERS   2.6 Added VMS help to menus
	! 09-APR-90 C.E. SALYERS   2.7 Added identifier lookup
	!
	!		COPYRIGHT © 1989,1990
	!               Aeroquip Corporation
	!	      Automotive Product Group
	!               Mt. Clemens, MI 48046
	! 
	! This software is furnished under a license and may be used and copied 
	! only in accordance with the terms of such license and with the 
	! inclusion of the above copyright notice.  THis software or any other
	! copies thereof may not be provided or otherwise made available to any
	! other person.  No title to any ownership of the software is hereby
	! transferred.
	!
	! The information in this software is sogject to change without notice
	! and should not be construed as a commitment by Aeroquip.
	!
	! Aeroquip assumes no reponsibility for the use or reliability of its 
	! software.
	!
	!**********************************************************************
	!--

	%SBTTL "Declarations"
	!==============================================================
	!                 SET UP GLOBAL PARAMETERS
	!==============================================================

	! ==> Equated Symbols <==

	! ==> External function definitions <==
	%nolist
	%include "$QUIDEF" %from %library "SYS$LIBRARY:BASIC$STARLET.TLB"
!	%include "$SJCDEf" %from %library "SYS$LIBRARY:BASIC$STARLET.TLB"
	%include "$SMGDEf" %from %library "SYS$LIBRARY:BASIC$STARLET.TLB"
        %include "$JBCMSGDEF" %from %library "SYS$LIBRARY:BASIC$STARLET.TLB"
 	%list

	external sub lib$stop(long by value)
	external sub lib$signal(long by value)

	!==> System Service return codes
	external long constant					&
			ss$_nosuchid

	!==> Screen Management functions
	external integer function				&
			smg$create_pasteboard,			&
			smg$delete_pasteboard,			&
			smg$set_cursor_mode,			&
			smg$create_virtual_display,		&
			smg$paste_virtual_display,		&
			smg$unpaste_virtual_display,		&
			smg$repaste_virtual_display,		&
			smg$get_display_attr,			&
			smg$change_rendition,			&
			smg$change_virtual_display,		&
			smg$label_border,			&
			smg$move_virtual_display,		&
			smg$delete_virtual_display,		&
			smg$create_virtual_keyboard,		&
			smg$delete_virtual_keyboard,		&
			smg$read_string,			&
			smg$read_composed_line,			&
			smg$read_keystroke,			&
			smg$cancel_input,			&
			smg$cursor_row,				&
			smg$cursor_column,			&
			smg$return_cursor_pos,			&
			smg$set_cursor_abs,			&
			smg$set_cursor_rel,			&
			smg$home_cursor,			&
			smg$delete_chars,			&
			smg$delete_line,			&
			smg$erase_chars,			&
			smg$erase_line,				&
			smg$erase_display,			&
			smg$insert_chars,			&
			smg$insert_line,			&
			smg$put_chars,				&
			smg$put_chars_wide,			&
			smg$put_chars_highwide,			&
			smg$put_line,				&
			smg$put_line_wide,			&
			smg$put_with_scroll,			&
			smg$draw_line,				&
			smg$draw_rectangle,			&
			smg$create_menu,			&
			smg$select_from_menu,			&
			smg$set_broadcast_trapping,		&
			smg$disable_broadcast_trapping,		&
			smg$scroll_viewport,			&
			smg$create_viewport,			&
			smg$change_viewport

	!==> SMG key constants
	!external word constant					&
	!		smg$k_trm_f10,				&
	!		smg$k_trm_help,                   	&
	!		smg$k_horizontal
			
	!==> SMG constants defined by smgdef macro
	!external integer constant				&
	!		smg$c_color_white,			&
	!		smg$m_bold,				&
	!		smg$m_border
			
        !==> QUI declarations
	%include "d3:[csalyers.library]quilib.bas"




	external long function sys$sndjbcw
	!==> SJC constants defined by sjcdef macro
	external long constant sjc$_file_specification,			&
		  	       sjc$_form_name,				&
		 	       sjc$_queue,				&
  			       sjc$_no_file_burst,			&
                               sjc$_no_file_flag,			&
			       sjc$_entry_number,			&
			       sjc$_destination_queue,			&
			       sjc$_hold,				&
			       sjc$_no_hold,				&
			       sjc$_notify

        external word constant sjc$_enter_file,	       			&
                               sjc$_reset_queue,			&
               		       sjc$_stop_queue,				&
                               sjc$_start_queue,			&
                               sjc$_alter_queue,			&
			       sjc$_alter_job,				&
			       sjc$_delete_job
        
        external long function sys$getjpiw
        !==> JPI constants
        external long constant jpi$_uic

	!==> I/O Status block return code
        external long constant jbc$_normal
	external long constant jbc$_nosuchque


	!==> SYS$GETMSG function declaration
	external long function sys$getmsg

        !==> SYS$TRNLNM function declaration
	external long function sys$trnlnm
	external long constant lnm$_string

        !==> SYS$GETJPI function declaration
	external long function sys$getjpiw
	external long constant jpi$_uic

        !==> SYS$FIND_HELD function declaration
	external long function sys$find_held

        !==> SYS$IDTOASC function declaration
	external long function sys$idtoasc

	!==> declarations for LBR functions
	external long function  lbr$ini_control,			&
				lbr$open,				&
				lbr$close,				&
				lbr$get_index
	external long constant  lbr$c_read,				&
				lbr$c_typ_hlp 

	!+
	! Declare the AST routines set up by this program
	!-
	external integer TRAP_MSG

	!+
	! Main program data structures
	!-
	record buf1        
		word buf_len1
		word item_code1
		long buf_addr1               
		long ret_len1                
		long list_terminator          
	end record buf1

	declare buf1 dvi_items
       	declare buf1 jpilist
 	declare buf1 stop_que_list
	declare buf1 lnmlist
        declare buf1 start_que_list
 
        record buf2
		word buf_len1
		word item_code1
		long buf_addr1               
		long ret_len1              
		word buf_len2
		word item_code2
		long buf_addr2              
		long ret_len2             
                long list_terminator
        end record buf2

        declare buf2 change_form_list
	declare buf2 del_job_list

	record buf3
		word buf_len1
		word item_code1     
		long buf_addr1                
		long ret_len1
		word buf_len2
		word item_code2
		long buf_addr2                
		long ret_len2
		word buf_len3
		word item_code3
		long buf_addr3                
		long ret_len3
		long list_terminator          
	end record buf3

	declare buf3 get_que_list
	declare buf3 alter_job_list

	record buf4
		word buf_len1
		word item_code1     
		long buf_addr1                
		long ret_len1
		word buf_len2
		word item_code2
		long buf_addr2                
		long ret_len2
		word buf_len3
		word item_code3
		long buf_addr3                
		long ret_len3
		word buf_len4    
		word item_code4
		long buf_addr4                
		long ret_len4
		long list_terminator          
	end record buf4

	declare buf4 quilist
	declare buf4 forms_list

	record buf5        
		word buf_len1
		word item_code1     
		long buf_addr1                
		long ret_len1
		word buf_len2
		word item_code2
		long buf_addr2                
		long ret_len2
		word buf_len3
		word item_code3
		long buf_addr3                
		long ret_len3
		word buf_len4    
		word item_code4
		long buf_addr4                
		long ret_len4
		word buf_len5
		word item_code5
		long buf_addr5                
		long ret_len5                 
		long list_terminator          
	end record buf5                     
                            
	declare buf5 jbc_items                     

	record buf6    
		word buf_len1
		word item_code1     
		long buf_addr1                
		long ret_len1
		word buf_len2
		word item_code2
		long buf_addr2                
		long ret_len2
		word buf_len3
		word item_code3
		long buf_addr3                
		long ret_len3
		word buf_len4    
		word item_code4
		long buf_addr4                
		long ret_len4
		word buf_len5
		word item_code5
		long buf_addr5                
		long ret_len5                 
		word buf_len6
		word item_code6
		long buf_addr6                
		long ret_len6 
		long list_terminator          
	end record buf6               
 
	declare buf6 get_job_list

	!==> MAP structure definition
	map (queue_buf) string filename = 25%,		    		&
	   		string queue_name = 31%,			&
			string form_name = 15%,                         &
			string job_name = 39%,				&
                        string user_name = 20%,				&
 			long job_size,					&
			long entry_number,				&
                        long job_status,				&
                        long queue_status

 	map (io_stat)   long iosb,					&
                        long iosb2
		
        map (uic_map)   long uic

        map (uic_map)   word acct, 					&
                        word grp 
						       


	!==> Declare Variables

	declare integer i,j,k,l

	declare long						&
			stat,					&
			pb_id,					&
			kb_id,					&
			head_vdid,				&
			menu_vdid,				&
			work_vdid,				&
			bcst_vdid,				&
			mess_vdid,				&
			help_vdid,				&
			list_vdid,				&
			term_code,			 	&
			id,					&
			current_row,				&
			current_column		

	declare integer 					&
			ascii_val,				&
			column,					&
			columns,				&
			row,					&
			rows,					&
			timer,					&
			vdid
			
	declare long						&
			queue_search_flags,			&
                        job_search_flags,			&
			form_search_flags,			&
			msgflags,				&
			form_number

	declare word    msglenm,				&
			selected_item	

	!==> Declare menu arrays

	map (menu1) string  main_menu(7),			&
                    string  Job_menu(5),			&
		    string  yes_no_menu(2),			&
		    string  stop_menu(3)

	!==> declare UIC map
	map (uic_map)	long user_uic,				&
			long user_uic2

	!==> Buffer area
	common string 						&
			text_buffer( 100% ) = 78%,		&
			input_buffer = 80%,                     & 
	                default_printer = 31%,			&
           		new_default_printer = 31%,		&
                        group_name = 3%,			&
                        queue_status_string = 30%,              &
                        new_form_name = 15%,			&
                        file_name = 252%,			&
                        print_form_name = 15%,			&
                        input_form_name = 15%,			&
 			entry_number_string = 12%,		&
			job_size_string = 10%,			&
			job_stat_string = 12,			&
			job_line_string = 78%,			&
			prompt_string = 25%,			&
 			new_que = 31%,				&
			error_message = 55%,			&
			list_form_name = 13%,			&
			search_name = 31%,			&
			lnm_string = 31%,			&
			id_name = 25%,				&
			libfile = 50%
        
        !+
	! Declare a MAP to be used by the main routine and the subroutines
	! for passing SMG information.
	!-
	map (smg_params) long disp_info(2), long keyboard_info(4)




	%SBTTL "Set-Up SMG Data Structures"

	!==> Create Pasteboard
	stat = smg$create_pasteboard( pb_id )
	call lib$signal(stat) if ( stat and 1%) = 0%

	!=> Save the value for the MAP to subroutine
	disp_info(0) = pb_id 

	!==> Create Virtual Keyboard
	stat = smg$create_virtual_keyboard( kb_id,,,, )
	call lib$signal(stat) if ( stat and 1%) = 0%

	!==> Create 14 Virtual Displays

	rows = 24%
	columns = 78%
	stat = smg$create_virtual_display(rows, columns, main_vdid, )
	call lib$signal(stat) if ( stat and 1%) = 0%

	rows = 1%
	columns = 78%
	stat = smg$create_virtual_display(rows, columns, head_vdid, smg$m_border)
	call lib$signal(stat) if ( stat and 1%) = 0%

	rows = 1%
	columns = 78%
	stat = smg$create_virtual_display(rows, columns, menu_vdid, smg$m_border)
	call lib$signal(stat) if ( stat and 1%) = 0%

	rows = 8%
	columns = 78%
	stat = smg$create_virtual_display(rows, columns, work_vdid, smg$m_border)
	call lib$signal(stat) if ( stat and 1%) = 0%

	rows = 18%
	columns = 78%
	stat = smg$create_virtual_display(rows, columns, show_que_vdid, smg$m_border)
	call lib$signal(stat) if ( stat and 1%) = 0%

	rows = 14%
	columns = 78%
	stat = smg$create_virtual_display(rows, columns, job_list_vdid)
	call lib$signal(stat) if ( stat and 1%) = 0%

 	rows = 4%
	colums = 78%
	stat= smg$create_virtual_display(rows,columns, que_heading_vdid,)
	call lib$signal(stat) if ( stat and 1%) = 0%

	rows = 10%
	columns = 50%
	stat = smg$create_virtual_display(rows, columns, help_vdid, smg$m_border)
	call lib$signal(stat) if ( stat and 1%) = 0%

	rows = 8%
	columns = 78%
	stat = smg$create_virtual_display(rows, columns, list_vdid, smg$m_border)
	call lib$signal(stat) if ( stat and 1%) = 0%

	rows = 4%
	columns = 78%
	stat = smg$create_virtual_display(rows, columns, bcst_vdid, smg$m_border)
	call lib$signal(stat) if ( stat and 1%) = 0%

	rows = 1%
	columns = 78%
	stat = smg$create_virtual_display(rows, columns, input_vdid, smg$m_border)
	call lib$signal(stat) if ( stat and 1%) = 0%

	rows = 7%
	columns = 20%
	stat = smg$create_virtual_display(rows, columns, pull_vdid, smg$m_border)
        stat = smg$label_border(pull_vdid,"||",smg$k_top,4%,,,)
 	call lib$signal(stat) if ( stat and 1%) = 0%

	rows = 5%
	columns = 12%
	stat = smg$create_virtual_display(rows, columns, job_menu_vdid,)
 	call lib$signal(stat) if ( stat and 1%) = 0%

	rows = 2%
	columns = 5%
	stat = smg$create_virtual_display(rows, columns, yes_no_vdid,)
 	call lib$signal(stat) if ( stat and 1%) = 0%

	rows = 3%
	columns = 10%
	stat = smg$create_virtual_display(rows, columns, stop_vdid,)
 	call lib$signal(stat) if ( stat and 1%) = 0%

	!==> Declare and create main menu
	main_menu(1) = "Queue"
	main_menu(2) = "Form"
	main_menu(3) = "Status"
	main_menu(4) = "Print"
	main_menu(5) = "Jobs"
	main_menu(6) = "Help"
	main_menu(7) = "Exit"
        stat = smg$create_menu(menu_vdid,main_menu(),smg$k_horizontal,,,,)
 	call lib$signal(stat) if ( stat and 1%) = 0%

	!==> Declare and create job menu
	job_menu(1) = "Requeue"
	job_menu(2) = "Delete"
	job_menu(3) = "Hold"
	job_menu(4) = "Release"
	job_menu(5) = "Show Queue"
        stat = smg$create_menu(job_menu_vdid,job_menu(),smg$k_vertical,,1%,,)
 	call lib$signal(stat) if ( stat and 1%) = 0%
      
	!==> Declare and create yes_no menu
	yes_no_menu(1) = "Yes" 
	yes_no_menu(2) = "No"
        stat = smg$create_menu(yes_no_vdid,yes_no_menu(),smg$k_vertical,,1%,,)
 	call lib$signal(stat) if ( stat and 1%) = 0%


	!==> Declare and create stop menu
	stop_menu(1) = "Reset"
	stop_menu(2) = "Next"
	stop_menu(3) = "No"
        stat = smg$create_menu(stop_vdid,stop_menu(),smg$k_vertical,,1%,,)
 	call lib$signal(stat) if ( stat and 1%) = 0%

	!=> MAP the vdid to the broadcast dispaly
	disp_info(1) = bcst_vdid 


	%SBTTL "Main Program"
	!================================================================
	!                M A I N   P R O G R A M
	!================================================================

	!+ 
	! Check for QUEUE_CONTROL Identifier
	!-
	!==> get UIC
	jpilist::buf_len1 = 4%
	jpilist::item_code1 = jpi$_uic
	jpilist::buf_addr1 = loc(user_uic)
	jpilist::ret_len1 = 0%
	jpilist::list_terminator = 0%
	user_uic2 = 0	
	stat = sys$getjpiw(,,,jpilist,iosb,,)
	call lib$signal(iosb) if ( iosb and 1%) = 0%
	call lib$signal(stat) if ( stat and 1%) = 0%
	!
	!==> get users identifiers
	cntxt = 0%
	found_id = 0%
	stat = sys$find_held(user_uic by ref,id by ref,,cntxt by ref) 
	call lib$signal(stat) if ( stat and 1%) = 0%
	while (stat <> ss$_nosuchid) and (found_id = 0%) 
		id_len = 25%
		stat = sys$idtoasc(id by value,id_len,id_name,id_val,,)
		call lib$signal(stat) if ( stat and 1%) = 0%
		if id_name = "QUEUE_CONTROL" then
			Found_id = 1%
		else 
			stat = sys$find_held(user_uic,id,,cntxt) 
		end if
	next
	!
	! IMPORTANT:
	!   If you want this program to be accessable to everyone
	!   (i.e. the QUEUE_CONTROL idenitifier is not needed), then
	!   comment the following If statement out.
	!
	if found_id = 0% then 
		Print "You do not have access to QUEUE_CONTROL"
		Print "You must have the QUEUE_CONTROL identifier to use this program"
		exit program 
	end if

	!+
	! Main loop data structures
	!-
	timer = 60%
	trace_key = 0%

        !+
        ! Read value of SYS$PRINT and set default printer
        !-
        lnmlist::buf_len1 = 255%
        lnmlist::item_code1 = lnm$_string
        lnmlist::buf_addr1 = loc(lnm_string)
        lnmlist::ret_len1 = 0%
        lnmlist::list_terminator = 0%
        stat = sys$trnlnm(,"LNM$PROCESS","SYS$PRINT",,lnmlist)

        if stat <> 1% then 
	    default_printer = "SYS$PRINT"
	    group_name = ""
        else	
	    default_printer = edit$(lnm_string,2%+4%+32%+128%)
	    pos_of_dollarsign = pos(lnm_string,"$",1)
	    Group_name = mid$(lnm_string,1,pos_of_dollarsign)  if pos_of_dollarsign <= 3
	end if 	    

	!+
	! Set the broadcast trapping on
	!-
	stat = smg$set_broadcast_trapping( pb_id, TRAP_MSG, 1 )
	call lib$signal(stat) if ( stat and 1%) = 0%

	! ==> paste main display and copyright
	row= 0%
	column = 0%
	stat = smg$paste_virtual_display( main_vdid, pb_id, row, column )
	row = 24%
	column = 2%
	text_buffer(1%) = "Copyright © Aeroquip 1989,1990"
	stat = smg$put_chars( main_vdid, text_buffer(1%), row, column)


	text_buffer(1%) = "QUEUE_CONTROL   V2.7"
	text_buffer(3%) = " "

	!==> Write test on the Virtual displays	
	stat = smg$home_cursor( head_vdid )		! Home the cursor
	call lib$signal(stat) if ( stat and 1%) = 0%
	stat = smg$put_line( head_vdid, text_buffer(1%),,,smg$m_bold )
	call lib$signal(stat) if ( stat and 1%) = 0%




	stat = smg$home_cursor( work_vdid )		! Home the cursor
	call lib$signal(stat) if ( stat and 1%) = 0%
	stat = smg$put_line( work_vdid, text_buffer(3%) )
	call lib$signal(stat) if ( stat and 1%) = 0%

	!==> Paste the virtual displays
	row = 2%
	column = 2%
	stat = smg$paste_virtual_display( head_vdid, pb_id, row, column )
	call lib$signal(stat) if ( stat and 1%) = 0%

	row = 4%
	column = 2%
	stat = smg$paste_virtual_display( menu_vdid, pb_id, row, column )
	call lib$signal(stat) if ( stat and 1%) = 0%

 
	!=> Put up the menu items
	text_buffer(11%) = ""
	text_buffer(12%) = "QUEUE:"
	text_buffer(13%) = ""
	text_buffer(14%) = "FORM:"
	text_buffer(15%) = ""
	text_buffer(16%) = "STATUS:"
	text_buffer(17%) = ""
	text_buffer(18%) = ""

	stat = smg$home_cursor( work_vdid )		! Home the cursor
	call lib$signal(stat) if ( stat and 1%) = 0%
	for i = 11% to 18%
		stat = smg$put_line( work_vdid, text_buffer(i) )
		call lib$signal(stat) if ( stat and 1%) = 0%
	next i

	!=> Paste the virtual display
	row = 6%
	column = 2%
	stat = smg$paste_virtual_display( work_vdid, pb_id, row, column )
	call lib$signal(stat) if ( stat and 1%) = 0%

	!==>Paste broadcast trapping display
	row = 18%
	column = 2%
	stat = smg$paste_virtual_display( bcst_vdid, pb_id, row, column )


	!=> Get info about default print queue
        gosub SUB_GET_QUE_INFO
        

	!+
	! Wait for a keystroke
	!-
200
 READ_KEYSTROKE:
		!==> make sure that current que is valid
		if TRM$(queue_status_string) = "NO SUCH QUEUE" then
		   gosub SUB_QUEUE
		   gosub SUB_GET_QUE_INFO
		   goto READ_KEYSTROKE
		end if

		!==> Activate menu and receive option
		stat = smg$set_cursor_mode(pb_id,smg$m_cursor_off)
		stat = smg$select_from_menu (kb_id,menu_vdid,selected_item,  &
                                            ,,"SYS$HELP:QUEUE_CONTROL_PRG.HLB",  &
                                            ,,,,)
		call lib$signal(stat) if (( stat and 1%) = 0%) 
		stat = smg$set_cursor_mode(pb_id,smd$m_cursor_on)

                
                if stat = ss$timeout then
                       term_code = 0
                       gosub SUB_GET_QUE_INFO
                end if
          
		!+
		! Identify the keystroke and execute
		!- 


 T_CODE: 
		select selected_item



			!==> Queue item selected from menu
			case 1% 
				gosub SUB_QUEUE
                                exit t_code

			!==> Form item selected from Menu Bar
			case 2%
				gosub SUB_FORM

			!==> Status item selected from Menu Bar
			case 3%
				gosub SUB_STATUS

			!==> Print item selected from Menu Bar
			case 4%
				gosub SUB_PRINT

			!==> Jobs item selected from Menu Bar
			case 5%
				gosub SUB_JOBS

			!==> Help item selected from Menu Bar
                       	case 6%
                             	gosub SUB_HELP
                       
   			!=> Exit itme selected from Menu Bar
                        case 7%
                               	goto EXIT_PROGRAM
		



			!==> Unknown item selected
			case else
				if trace_key then
					stat = smg$put_line( bcst_vdid, 	&
						"Undefined",,,,,, )
                            	end if
				exit T_code

		end select
        
       gosub SUB_GET_QUE_INFO

       goto READ_KEYSTROKE


EXIT_PROGRAM:
	!+
	! Clean up and go home
	!-
	text_buffer(21%) = ""	
	text_buffer(22%) = "   Do you really    "
	text_buffer(23%) = "   want to exit?"
	text_buffer(24%) = ""
	text_buffer(25%) = ""
	text_buffer(26%) = ""
	text_buffer(27%) = ""

	!
	stat = smg$home_cursor( pull_vdid )		! Home the cursor
	call lib$signal(stat) if ( stat and 1%) = 0%
	for i = 21% to 27%
		stat = smg$put_line( pull_vdid, text_buffer(i) )
		call lib$signal(stat) if ( stat and 1%) = 0%
	next i

	!=> Paste the virtual display
	row = 6%
	column = 53% 
	stat = smg$paste_virtual_display( pull_vdid, pb_id, row, column )
	call lib$signal(stat) if ( stat and 1%) = 0%

	!=> Paste the menu
	row = 10%
	column = 60% 
	stat = smg$paste_virtual_display( yes_no_vdid, pb_id, row, column )
	call lib$signal(stat) if ( stat and 1%) = 0%

	!=> Get Menu Item
	stat = smg$set_cursor_mode(pb_id,smg$m_cursor_off)
	stat = smg$select_from_menu (kb_id,yes_no_vdid,selected_item,  &
                                     ,,"SYS$HELP:QUEUE_CONTROL_PRG.HLB",,,,,)
	call lib$signal(stat) if (( stat and 1%) = 0%) 
	stat = smg$set_cursor_mode(pb_id,smd$m_cursor_on)

	
	!=> Really exit
	if selected_item = 1%   
            then goto FINISH
 	end if

	!=> Unpaste it when done
	stat = smg$unpaste_virtual_display( pull_vdid, pb_id ) 
	call lib$signal(stat) if ( stat and 1%) = 0%
	stat = smg$unpaste_virtual_display( yes_no_vdid, pb_id ) 
	call lib$signal(stat) if ( stat and 1%) = 0%

	!=> Repaste work area
	row = 6%
	column = 2%
	stat = smg$paste_virtual_display( work_vdid, pb_id, row, column )
	call lib$signal(stat) if ( stat and 1%) = 0%
       

    	goto READ_KEYSTROKE

 FINISH:
	!==> Disable broadcast Trapping
	stat = smg$disable_broadcast_trapping(pb_id)
 	stat = smg$delete_pasteboard(pb_id,1%)
	stat = smg$set_cursor_mode(pb_id,smd$m_cursor_on)
	exit program 1%

	!=============================================================
	!               E N D   M A I N   R O U T I N E
	!=============================================================


        %SBTTL "Internal Subroutine    <GET_QUE_INFO>"
SUB_GET_QUE_INFO:
        !+
        !
        !  FUNCTION DESCRIPTION:
        !
        !      This subroutine uses SYS$GETQUI to get the queue status
        !      and form number
        !
        !  IMPLICIT INPUTS:
        !
        !  IMPLICIT OUTPUTS:
        !
        !  SIDE EFFECTS:
        !
        !-

        queue_status = 0%
        queue_status_string = ""
        queue_search_flags = qui$m_search_symbiont

        quilist::buf_len1 = len(default_printer)
        quilist::item_code1 = qui$_search_name
        quilist::buf_addr1 = loc(default_printer)
        quilist::ret_len1 = 0%
        quilist::buf_len2 = 31%
        quilist::item_code2 = qui$_queue_name
        quilist::buf_addr2 = loc(queue_name)
        quilist::ret_len2 = 0%
        quilist::buf_len3 = 4%
        quilist::item_code3 = qui$_queue_status
        quilist::buf_addr3 = loc(queue_status)
        quilist::ret_len3 = 0%
        quilist::buf_len4 = 31%
        quilist::item_code4 = qui$_form_name
        quilist::buf_addr4 = loc(form_name)
        quilist::ret_len4= 0%
        quilist::list_terminator = 0%

	stat = sys$getquiw(,qui$_display_queue by value,,		&
                         quilist by ref ,iosb by ref,,)

        queue_status_string = "STARTED"


        if iosb = jbc$_nosuchque then 
           queue_status_string = "NO SUCH QUEUE"
           queue_name = default_printer
           form_name = ""          
        else


           queue_status_string = "PAUSING" 				&
                     if (queue_status and qui$m_queue_paused)

           queue_status_string = "PAUSED" 				&
                     if (queue_status and qui$m_queue_paused)
							
           queue_status_string = "RESETTING" 				&
                     if (queue_status and qui$m_queue_resetting)

           queue_status_string = "RESUMING" 				&
                     if (queue_status and qui$m_queue_resuming)

           queue_status_string = "STALLED" 				&
                     if (queue_status and qui$m_queue_stalled)

           queue_status_string = "STARTING" 				&
                     if (queue_status and qui$m_queue_starting)

           queue_status_string = "STOPPING" 				&
                     if (queue_status and qui$m_queue_stopping)

           queue_status_string = "STOPPED" 				&
                     if (queue_status and qui$m_queue_stopped)

           queue_status_string = "UNAVAILABLE" 				&
                     if (queue_status and qui$m_queue_unavailable)

           queue_status_string = "ALIGNING" 				&
                     if (queue_status and qui$m_queue_aligning)

        end if

        stat = smg$put_chars(work_vdid,"                            ",2%,9%)
        stat = smg$put_chars(work_vdid,"                            ",4%,9%)
        stat = smg$put_chars(work_vdid,"                            ",6%,9%)

        stat = smg$put_chars(work_vdid,queue_name,2%,9%)
        stat = smg$put_chars(work_vdid,form_name,4%,9%)
        stat = smg$put_chars(work_vdid,queue_status_string,6%,9%)

        return

	%SBTTL "Internal Subroutine:	<QUEUE>"
 SUB_QUEUE:
	!+
	!
	!  FUNCTIONAL DESCRIPTION:
	!
	!	This subroutine handles the modification of the queue
	!	referenced by this program.
	!
	!  IMPLICIT INPUTS:
	!
	!  IMPLICIT OUTPUTS:
	!
	!  SIDE EFFECTS:
	!
	!-
        text_buffer(19%) = "This function allows"        
        text_buffer(20%) = "you to change the   "
        text_buffer(21%) = "print que that this "
        text_buffer(22%) = "program refers to   "
        text_buffer(23%) = ""
        text_buffer(24%) = "Current queue is: "
        text_buffer(25%) = default_printer    
        
   	stat = smg$home_cursor(pull_vdid)   
        for i = 19% to 25%
       	   stat = smg$put_line(pull_vdid,text_buffer(i))
        next i

        row = 6%
        column =2%
 	stat = smg$paste_virtual_display( pull_vdid,pb_id,row,column)

        row = 15%
        column = 2%
	stat = smg$erase_display(input_vdid)
        stat = smg$paste_virtual_display(input_vdid,pb_id,row,column)
        stat = smg$read_string(kb_id,new_default_printer,		&
               "Enter new queue name =>" ,31%,,,,,,input_vdid,trm$(group_name),,)
        new_default_printer = edit$(new_default_printer,32%)

	! IMPORTANT:
	! 	If you do not want this program to work on queues with
	!  	the word "BATCH" in the name, then remove the comments 
	! 	from the following IF Statement
	!
!	if pos(new_default_printer,"BATCH",1) <> 0% then 
!      	   stat = smg$put_line(input_vdid,				&
!              "ERROR - Batch Queues Can not be modified        Press any key to continue")
!	    stat = smg$read_keystroke( kb_id, term_code,,timer,)
!          else if (len(edit$(new_default_printer,128%+2%)) >  3%) then
!             default_printer = new_default_printer
!	   end if
!	end if

 	stat = smg$unpaste_virtual_display(input_vdid, pb_id)   
 	stat = smg$unpaste_virtual_display(pull_vdid, pb_id)   


	return

	%SBTTL "Internal Subroutine:	<FORM>"
 SUB_FORM:
	!+
	!
	!  FUNCTIONAL DESCRIPTION: This function allows user to
        !      change the form mounted ont here default printer
	!
	!  IMPLICIT INPUTS:
	!
	!  IMPLICIT OUTPUTS:
	!
	!  SIDE EFFECTS:
	!
	!-                "                    "
        text_buffer(37) = "This function allows"
        text_buffer(38) = "you to change the   "
        text_buffer(39) = "form that is mounted"
        text_buffer(40) = "on " + default_printer
        text_buffer(41) = "Enter L to see list"
        text_buffer(42) = "The current form is:"
 	text_buffer(43) = form_name

   	stat = smg$home_cursor(pull_vdid)   
	for i = 37 to 43
       	   stat = smg$put_line(pull_vdid,text_buffer(i))
        next i

        !==> Paste virtual display
        row = 6%
        column = 11%
 	stat = smg$paste_virtual_display( pull_vdid,pb_id,row,column)

        !==> Get new form name
        row = 15%
        column = 2%
	stat = smg$erase_display(input_vdid)
        stat = smg$paste_virtual_display(input_vdid,pb_id,row,column)
        stat = smg$read_string(kb_id,input_form_name,			&
               "Enter new form name =>" ,31%,,,,,,input_vdid,,,)
	if trm$(input_form_name) = "L" or trm$(input_form_name) = "l"   
           then  gosub SUB_LIST_FORMS
        end if
	if trm$(input_form_name) = "" then goto EXIT_FORMS
	end if
        new_form_name = edit$(input_form_name,32%)

	!==> Define item list
        change_form_list::buf_len1 = len(default_printer)
        change_form_list::item_code1 = sjc$_queue
        change_form_list::buf_addr1 = loc(default_printer)
        change_form_list::ret_len1 = 0%
        change_form_list::buf_len2 = len(new_form_name)
        change_form_list::item_code2 = sjc$_form_name
        change_form_list::buf_addr2 = loc(new_form_name)
        change_form_list::ret_len2 = 0%
 	change_form_list::list_terminator = 0%

	!==> Make call to alter queue
        stat = sys$sndjbcw(,sjc$_alter_queue by value ,,           &
                           change_form_list by ref,iosb by ref,,)

	!==> Get return message and print message
        stat = sys$getmsg(stat by value, 55%, error_message,,)
	if stat <> jpc$_normal then
	      error_message = ""
              stat = sys$getmsg(iosb by value, 55%, error_message,,)
	end if
	stat = smg$erase_display(input_vdid)
	text_buffer(44) = error_message +"Press a key to continue"
     	stat = smg$put_line(input_vdid,text_buffer(44))
	stat = smg$read_keystroke( kb_id, term_code,,timer,)

   
   EXIT_FORMS:
	!==>unpaste displays
	stat = smg$erase_display(list_vdid)
	stat = smg$unpaste_virtual_display(list_vdid,pb_id)
 	stat = smg$unpaste_virtual_display(input_vdid, pb_id)   
 	stat = smg$unpaste_virtual_display(pull_vdid, pb_id)   

	return

	%SBTTL "Internal Subroutine:	<STATUS>"
 SUB_STATUS:
	!+
	!
	!  FUNCTIONAL DESCRIPTION: This Function allows a user to stop
        !     or start a queue
	!
	!  IMPLICIT INPUTS:
	!
	!  IMPLICIT OUTPUTS:
	!
	!  SIDE EFFECTS:
	!
	!-
        
        !=> Determine if que is already Started
        if mid$(queue_status_string,1,7) = "STARTED"     &
          or mid$(queue_status_string,1,7) = "STALLED" 
            then   ! Queue is started
                i = int((20 - len(trm$(default_printer)))/2)
        	text_buffer(30) = string$(i,32%) + default_printer
        	text_buffer(31) = "     is started"
        	text_buffer(32) = "   Do you want to"
	        text_buffer(33) = "      stop it?"
		text_buffer(34) = "                  "
		text_buffer(35) = "                  "
		text_buffer(36) = "                  "
                stat = smg$home_cursor(pull_vdid)
	        for i = 30 to 36
	       	   stat = smg$put_line(pull_vdid,text_buffer(i))
	        next i      

		!=> Paste the virtual display
		row = 6%
		column = 19% 
		stat = smg$paste_virtual_display( pull_vdid, pb_id, row, column )
		call lib$signal(stat) if ( stat and 1%) = 0%

		!=> Paste the menu 
		row = 10%
		column = 25% 
		stat = smg$paste_virtual_display( stop_vdid, pb_id, row, column )
		call lib$signal(stat) if ( stat and 1%) = 0%

		!=> Get Menu item
		stat = smg$set_cursor_mode(pb_id,smg$m_cursor_off)
		stat = smg$select_from_menu (kb_id,stop_vdid,selected_item,  &
                                            ,,"SYS$HELP:QUEUE_CONTROL_PRG.HLB",60% &
					    ,,,,)
		call lib$signal(stat) if (( stat and 1%) = 0%) 
		stat = smg$set_cursor_mode(pb_id,smd$m_cursor_on)


		!==> Unpaste Display as soon a key is pressed
                stat = smg$unpaste_virtual_display(pull_vdid,pb_id)
                stat = smg$unpaste_virtual_display(stop_vdid,pb_id)
		
		!=> Really stop?
	        if selected_item = 1%    !If Reset
	        then 
           	   !=> Stop and reset Queue
	           stop_que_list:: buf_len1 = len(default_printer)
	           stop_que_list:: item_code1 = sjc$_queue
	           stop_que_list:: buf_addr1 = loc(default_printer)
	           stop_que_list:: ret_len1 = 0%
	           stop_que_list:: list_terminator = 0%
	           stat = sys$sndjbcw(,sjc$_reset_queue by value ,,           &
                                       stop_que_list by ref,iosb by ref,,)
                end if


	        if selected_item = 2%   !If Next
	        then 
           	   !=> Stop and reset Queue
	           stop_que_list:: buf_len1 = len(default_printer)
	           stop_que_list:: item_code1 = sjc$_queue
	           stop_que_list:: buf_addr1 = loc(default_printer)
	           stop_que_list:: ret_len1 = 0%
	           stop_que_list:: list_terminator = 0%
	           stat = sys$sndjbcw(,sjc$_stop_queue by value ,,           &
                                       stop_que_list by ref,iosb by ref,,)
                end if
		
 	else  !Que is stopped:
                i = int((20 - len(trm$(default_printer)))/2)
        	text_buffer(30) = string$(i,32%) + default_printer
        	text_buffer(31) = "     is stopped"
        	text_buffer(32) = "   Do you want to"
	        text_buffer(33) = "     start it?"
	        text_buffer(34) = "                            "
	        text_buffer(35) = "                            "
	        text_buffer(36) = "                            "
                stat = smg$home_cursor(pull_vdid)
	        for i = 30 to 36
	       	   stat = smg$put_line(pull_vdid,text_buffer(i))
	        next i      

		!=> Paste the virtual display
		row = 6%
		column = 19% 
		stat = smg$paste_virtual_display( pull_vdid, pb_id, row, column )
		call lib$signal(stat) if ( stat and 1%) = 0%

		!=> Paste the menu
		row = 11%
		column = 26% 
		stat = smg$paste_virtual_display( yes_no_vdid, pb_id, row, column )
		call lib$signal(stat) if ( stat and 1%) = 0%

		!=> Get menu item
		stat = smg$set_cursor_mode(pb_id,smg$m_cursor_off)
		stat = smg$select_from_menu (kb_id,yes_no_vdid,selected_item,  &
                                            ,,"SYS$HELP:QUEUE_CONTROL_PRG.HLB",60% &
					    ,,,,)
		call lib$signal(stat) if (( stat and 1%) = 0%) 
		stat = smg$set_cursor_mode(pb_id,smd$m_cursor_on)


		!==> Unpaste Display as soon a key is pressed
                stat = smg$unpaste_virtual_display(pull_vdid,pb_id)
                stat = smg$unpaste_virtual_display(yes_no_vdid,pb_id)
				

		!=> Really start?
	        if (selected_item = 1%)   !If yes
	        then 
           	   !=> start Queue
	           start_que_list:: buf_len1 = len(default_printer)
	           start_que_list:: item_code1 = sjc$_queue
	           start_que_list:: buf_addr1 = loc(default_printer)
	           start_que_list:: ret_len1 = 0%
	           start_que_list:: list_terminator = 0%
	           stat = sys$sndjbcw(,sjc$_start_queue by value ,,           &
                                       start_que_list by ref,iosb by ref,,)
                end if
 	


        end if

	return

	%SBTTL "Print Subroutine	<PRINT>"
 SUB_PRINT:
	!+
	!
	!  FUNCTIONAL DESCRIPTION: This function allow user to send
        !     a file to there default printer
	!
	!  IMPLICIT INPUTS:
	!
	!  IMPLICIT OUTPUTS:
	!
	!  SIDE EFFECTS:
	!
	!-                "                    "

	text_buffer(44) = "This function allows"
	text_buffer(45) = "you to print a file "
	text_buffer(46) = "on " + default_printer
	text_buffer(47) = "                    "
	text_buffer(48) = "                    "
 	text_buffer(49) = "                    "
	text_buffer(50) = "                    "

   	stat = smg$home_cursor(pull_vdid)   
	for i = 44 to 50
       	   stat = smg$put_line(pull_vdid,text_buffer(i))
        next i

        !==> Paste virtual display
        row = 6%
        column = 30%
 	stat = smg$paste_virtual_display( pull_vdid,pb_id,row,column)

        !==> Get file name
        row = 15%
        column = 2%
	stat = smg$erase_display(input_vdid)
        stat = smg$paste_virtual_display(input_vdid,pb_id,row,column)
        stat = smg$read_string(kb_id,file_name,			&
               "Enter file name =>" ,31%,,,,,,input_vdid,,,)
        file_name = edit$(file_name,32%)     !  Lower case to Upper case

        !==> Get Form name
	text_buffer(44) = "Enter the form name"
	text_buffer(45) = "for the file."
	text_buffer(46) = "                    "
	text_buffer(47) = "Enter L to see List"
	text_buffer(48) = "of Valid forms"
 	text_buffer(49) = "                    "
	text_buffer(50) = "                    "

   	stat = smg$home_cursor(pull_vdid)   
	for i = 44 to 50
       	   stat = smg$put_line(pull_vdid,text_buffer(i))
        next i

        stat = smg$erase_display(input_vdid)
        stat = smg$read_string(kb_id,input_form_name,			&
               "Enter form name =>" ,31%,,,,,,input_vdid,"DEFAULT",,)
	if trm$(input_form_name) = "L" or trm$(input_form_name) = "l"
           then  gosub SUB_LIST_FORMS
 	end if
        print_form_name = edit$(input_form_name,32%)     ! Lower to Upper case

	!==> Initialize the item lists 
	jbc_items::buf_len1 = len(trm$(default_printer))
	jbc_items::item_code1 = sjc$_queue
	jbc_items::buf_addr1 =  loc(default_printer)     
	jbc_items::ret_len1 = 0%        
	jbc_items::buf_len2 = len(trm$(file_name))
	jbc_items::item_code2 = sjc$_file_specification
	jbc_items::buf_addr2 =  loc(file_name)     
	jbc_items::ret_len2 = 0%              
	jbc_items::buf_len3 = len(trm$(print_form_name))
	jbc_items::item_code3 = sjc$_form_name
	jbc_items::buf_addr3 =  loc(print_form_name)     
	jbc_items::ret_len3 = 0% 
	jbc_items::buf_len4 = 0%
	jbc_items::item_code4 = sjc$_notify
	jbc_items::buf_addr4 = 0%     
	jbc_items::ret_len4 = 0% 
	jbc_items::buf_len5 = 0%	
	jbc_items::item_code5 = sjc$_file_flag
	jbc_items::buf_addr5 =  0%    
	jbc_items::ret_len5 = 0% 
        jbc_items::list_terminator = 0%

      	stat =  sys$sndjbcw(,sjc$_enter_file by value,,jbc_items by ref,      &
		iosb by ref,,)

	!==> Get return message and print message
        stat = sys$getmsg(stat by value, 55%, error_message,,)
	if stat <> jpc$_normal then
	      error_message = ""
              stat = sys$getmsg(iosb by value, 55%, error_message,,)
	end if
	stat = smg$erase_display(input_vdid)
	text_buffer(44) = error_message +"Press a key to continue"
     	stat = smg$put_line(input_vdid,text_buffer(44))
	stat = smg$read_keystroke( kb_id, term_code,,timer,)

	!==>unpaste displays
	stat = smg$erase_display(list_vdid)
	stat = smg$unpaste_virtual_display(list_vdid,pb_id)
 	stat = smg$unpaste_virtual_display(input_vdid, pb_id)   
 	stat = smg$unpaste_virtual_display(pull_vdid, pb_id)   


	return

	%SBTTL "Internal Subroutine:	<JOBS>"
 SUB_JOBS:
	!+
	!
	!  FUNCTIONAL DESCRIPTION: Allows user to requeue, delete, hold
	!       and release jobs
	!
	!  IMPLICIT INPUTS:
	!
	!  IMPLICIT OUTPUTS:
	!
	!  SIDE EFFECTS:
	!
	!-              "                    "

        text_buffer(51) = "   Make Selection   "
        text_buffer(53) = "                    "
        text_buffer(54) = "                    "
        text_buffer(55) = "                    "
        text_buffer(56) = "                    "
        text_buffer(57) = "                    "
                    

	stat = smg$home_cursor( pull_vdid )		! Home the cursor
	call lib$signal(stat) if ( stat and 1%) = 0%
	for i = 51% to 57%
		stat = smg$put_line( pull_vdid, text_buffer(i) )
		call lib$signal(stat) if ( stat and 1%) = 0%
	next i

	stat = smg$home_cursor( job_menu_vdid )		! Home the cursor

	!=> Paste the virtual display
	row = 6%
	column = 37%
	stat = smg$paste_virtual_display(pull_vdid, pb_id, row, column )
	call lib$signal(stat) if ( stat and 1%) = 0%

	!=> Paste the menu
	row = 8%
	column = 42%
	stat = smg$paste_virtual_display(job_menu_vdid, pb_id, row, column )
	call lib$signal(stat) if ( stat and 1%) = 0%

	!=> Select form menu
	stat = smg$set_cursor_mode(pb_id,smg$m_cursor_off)
	stat = smg$select_from_menu (kb_id,job_menu_vdid,selected_item,  &
                                      ,,"SYS$HELP:QUEUE_CONTROL_PRG.HLB",,,,,)
	stat = smg$set_cursor_mode(pb_id,smg$m_cursor_on)

 	stat = smg$unpaste_virtual_display(pull_vdid, pb_id)   
 	stat = smg$unpaste_virtual_display(work_vdid, pb_id)   
 	stat = smg$unpaste_virtual_display(job_menu_vdid, pb_id)   
	stat = smg$unpaste_virtual_display(menu_vdid, pb_id)   
 

        row = 4%
        column = 2%
        stat = smg$erase_display(show_que_vdid)
	stat = smg$paste_virtual_display( show_que_vdid, pb_id, row, column )
        stat = smg$erase_display(que_heading_vdid)
	stat = smg$paste_virtual_display( que_heading_vdid, pb_id, row, column)
	row = 8%
	column = 2%
        stat = smg$erase_display(job_list_vdid)
	stat = smg$paste_virtual_display( job_list_vdid, pb_id, row, column )

        select selected_item
   	   case 1   ! Q
              text_buffer(58) = "Requeue: Sends file to a different print queue"
           case 2   ! D
              text_buffer(58) = "Delete: Deletes job from the print queue"
           case 3   ! H
      	      text_buffer(58) = "Hold: Puts job on 'HOLD' until it is released"
           case 4   ! R
              text_buffer(58) = "Release: Prints jobs that is on 'HOLD'"
           case else
              text_buffer(58) = ""
        end select 
        text_buffer(59) = "QUEUE: " + trm$(default_printer) + "     " +   &
                          "STATUS: " + trm$( queue_status_string) + "     " +  &
                          "FORM: " + form_name
        text_buffer(60) = ""
        text_buffer(61) = "   Name                        Owner       Number      Size       Status"


        for i = 58 to 60
           stat = smg$put_line( que_heading_vdid, text_buffer(i) )
        next i
        stat = smg$put_line( que_heading_vdid, text_buffer(61),,smg$m_underline )

        queue_search_flags = qui$m_search_wildcard

        get_que_list::buf_len1 = len(default_printer)
        get_que_list::item_code1 = qui$_search_name
        get_que_list::buf_addr1 = loc(default_printer)
        get_que_list::ret_len1 = 0%
        get_que_list::buf_len2 = 4%
        get_que_list::item_code2 = qui$_search_flags
        get_que_list::buf_addr2 = loc(queue_search_flags)
        get_que_list::ret_len2 = 0%
        get_que_list::buf_len3 = 31%
        get_que_list::item_code3 = qui$_queue_name
        get_que_list::buf_addr3 = loc(queue_name)
        get_que_list::ret_len3 = 0%
        get_que_list::list_terminator = 0%


 	!==> Initailize queue content
	stat = sys$getquiw(,qui$_display_queue by value,,		&
                         get_que_list by ref ,iosb by ref,,)


	!==> Initailize item list
 	job_search_flags = qui$m_search_all_jobs
 
        get_job_list::buf_len1 = 4%
        get_job_list::item_code1 = qui$_search_flags
        get_job_list::buf_addr1 = loc(job_search_flags)
        get_job_list::ret_len1 = 0%
        get_job_list::buf_len2 =39%
        get_job_list::item_code2 = qui$_job_name
        get_job_list::buf_addr2 = loc(job_name)
        get_job_list::ret_len2 = 0%
        get_job_list::buf_len3 = 12%
        get_job_list::item_code3 = qui$_username
        get_job_list::buf_addr3 = loc(user_name)
        get_job_list::ret_len3 = 0%
        get_job_list::buf_len4 = 4%
        get_job_list::item_code4 = qui$_entry_number
        get_job_list::buf_addr4 = loc(entry_number)
        get_job_list::ret_len4 = 0%
        get_job_list::buf_len5 = 4%
        get_job_list::item_code5 = qui$_job_status
        get_job_list::buf_addr5 = loc(job_status)
        get_job_list::ret_len5 = 0%
        get_job_list::buf_len6 = 4%
        get_job_list::item_code6 = qui$_job_size
        get_job_list::buf_addr6 = loc(job_size)
        get_job_list::ret_len6 = 0%
        get_job_list::list_terminator = 0%

        stat = sys$getquiw(,qui$_display_job by value,,   		&
                            get_job_list by ref, 			&
                            iosb by ref,,)

	job_counter = 0
	
        while iosb = jbc$_normal 
	    job_counter = job_counter + 1
            entry_number_string = str$(entry_number)
	    job_size_string = str$(job_size)
	

            select job_status

                 case = qui$m_job_aborting
            	      job_stat_string = "ABORTING"

                 case = qui$m_job_executing
            	      job_stat_string = "EXECUTING"

                 case = qui$m_job_holding
            	      job_stat_string = "HOLDING"

                 case = qui$m_job_inaccessible
            	      job_stat_string = "INACCESSIBLE"

                 case = qui$m_job_pending
            	      job_stat_string = "PENDING"

                 case = qui$m_job_refused
            	      job_stat_string = "REFUSED"

                 case = qui$m_job_retained
            	      job_stat_string = "RETAINED"

                 case = qui$m_job_starting
            	      job_stat_string = "STARTING"

                 case = qui$m_job_suspended
            	      job_stat_string = "SUSPENDED"

                 case = qui$m_job_time_release
            	      job_stat_string = "TIMED"

	    end select

	    job_name = edit$(job_name,4)
  	    user_name = edit$(user_name,4)

	    job_line_string = 	mid$(job_name,1%,29%) +			&
				mid$(user_name,1%,14%) +		&
				mid$(entry_number_string,1%,12%) +	&
				mid$(job_size_string,1%,10%) +		&
				mid$(job_stat_string,1%,12%)

            stat = smg$put_line(job_list_vdid,job_line_string)

            stat = sys$getquiw(,qui$_display_job by value,,   		&
                                get_job_list by ref, 			&
                                iosb by ref,,)
	    
	    gosub NEXT_PAGE   if job_counter > 13

  	next

	
	!==> Get Entry Number form user
	no_function = 0%
	select selected_item
		case 1 ! Q
                    prompt_string = "Number to be Requeued =>"
		case 2 ! D
                    prompt_string = "Number to be Deleted =>"
		case 3 ! H
                    prompt_string = "Number to be held =>"
		case 4 ! R
                    prompt_string = "Number to be Released =>"
                case else 
                    prompt_string = "Press RETURN to Continue"
                    no_function = 1%
	end select

	!==> Paste input display
	row = 23%
	column = 2%
	stat = smg$erase_display(input_vdid)
        stat = smg$paste_virtual_display(input_vdid,pb_id,row,column)

	!==> Read String
	stat = smg$read_string(kb_id,Entry_number_string,trm$(prompt_string),	       &
		5%,,,,,,input_vdid,,,)

        if no_function = 1% then 
		goto EXIT_SUB_JOBS 
	end if

	when error in
 	    entry_number = integer(entry_number_string,long)
        use
	    entry_number = -1
	end when

	if selected_item = 1% then
           row = 23%
	   column = 2%
	   prompt_string = "New Queue name =>" 
	   stat = smg$read_string(kb_id,new_que,trm$(prompt_string),	       &
		31%,,,,,,input_vdid,,,)
 	end if	

	!==>Initailize item list
        if selected_item <> 2  then   ! Requeue, hold, Release file from queue

           alter_job_list::buf_len1 = len(default_printer)
           alter_job_list::item_code1 = sjc$_queue
           alter_job_list::buf_addr1 = loc(default_printer)
  	   alter_job_list::ret_len1 = 0%
           alter_job_list::buf_len2 = 4%
           alter_job_list::item_code2 = sjc$_entry_number
           alter_job_list::buf_addr2 = loc(entry_number)
	   alter_job_list::ret_len2 = 0%
	   select selected_item
		case 1 ! Q
                   alter_job_list::buf_len3 = len(new_que)
                   alter_job_list::item_code3 = sjc$_destination_queue
                   alter_job_list::buf_addr3 = loc(new_que)
	           alter_job_list::ret_len3 = 0%


		case 3 ! H
                   alter_job_list::buf_len3 = 0%
                   alter_job_list::item_code3 = sjc$_hold
                   alter_job_list::buf_addr3 = 0%
	           alter_job_list::ret_len3 = 0%

		case 4 ! R
                   alter_job_list::buf_len3 = 0%
                   alter_job_list::item_code3 = sjc$_no_hold
                   alter_job_list::buf_addr3 = 0%
	           alter_job_list::ret_len3 = 0%

	   end select
	   alter_job_list::list_terminator = 0%
 
 	   stat = sys$sndjbcw(,sjc$_alter_job by value,, 		&
                              alter_job_list by ref,  			&
			      iosb by ref,,)

	   !==> Get return message and print message
           stat = sys$getmsg(stat by value, 55%, error_message,,)
	   if stat <> jpc$_normal then
		 error_message = ""
                 stat = sys$getmsg(iosb by value, 55%, error_message,,)
	   end if
	   stat = smg$erase_display(input_vdid)
	   text_buffer(44) = error_message +"Press a key to continue"
     	   stat = smg$put_line(input_vdid,text_buffer(44))
	   stat = smg$read_keystroke( kb_id, term_code,,timer,)



	else  ! To delete job from queue
           del_job_list::buf_len1 = len(default_printer)
           del_job_list::item_code1 = sjc$_queue
           del_job_list::buf_addr1 = loc(default_printer)
  	   del_job_list::ret_len1 = 0%
           del_job_list::buf_len2 = 4%
           del_job_list::item_code2 = sjc$_entry_number
           del_job_list::buf_addr2 = loc(entry_number)
	   del_job_list::ret_len2 = 0%
   	   del_job_list::list_terminator = 0%
       
 	   stat = sys$sndjbcw(,sjc$_delete_job by value,, 		&
                              del_job_list by ref,  			&
			      iosb by ref,,)
   	   !==> Get return message and print message
           stat = sys$getmsg(stat by value, 55%, error_message,,)
	   if stat <> jpc$_normal then
		 error_message = ""
                 stat = sys$getmsg(iosb by value, 55%, error_message,,)
	    end if
	    stat = smg$erase_display(input_vdid)
	    text_buffer(44) = error_message +"Press a key to continue"
     	    stat = smg$put_line(input_vdid,text_buffer(44))
	    stat = smg$read_keystroke( kb_id, term_code,,timer,)

	end if

EXIT_SUB_JOBS:
	!==> Erase  displays
	stat = smg$unpaste_virtual_display(input_vdid,pb_id)
	stat = smg$unpaste_virtual_display(show_que_vdid,pb_id)
	stat = smg$unpaste_virtual_display(job_list_vdid,pb_id)


 	!==> repaste work and menu displays
	row = 4%
	column = 2%
	stat = smg$paste_virtual_display( menu_vdid, pb_id, row, column )

	row = 6%
	column = 2%
	stat = smg$paste_virtual_display( work_vdid, pb_id, row, column )

 	!==> Cancel WildCard Operation
	stat = sys$getquiw(,qui$_cancel_operation by value,,,,,)

	return

NEXT_PAGE:
        prompt_string = "More jobs... Press Return"
	row = 23%
	column = 2%
	stat = smg$erase_display(input_vdid)
        stat = smg$paste_virtual_display(input_vdid,pb_id,row,column)

	!==> Read String
	stat = smg$read_string(kb_id,Entry_number_string,trm$(prompt_string),	       &
		5%,,,,,,input_vdid,,,)
	stat = smg$erase_display(job_list_vdid)
	stat = smg$home_cursor(job_list_vdid)
	call lib$signal(stat) if ( stat and 1%) = 0%
	job_counter = job_counter - 13

return	


	%SBTTL "Internal Subroutine:	<LIST_FORM>"
 SUB_LIST_FORM:
	!+
	!
	!  FUNCTIONAL DESCRIPTION: This function allows user to
	!      view a list of valid form names
	!
	!  IMPLICIT INPUTS:
	!
	!  IMPLICIT OUTPUTS:
	!
	!  SIDE EFFECTS:
	!
	!-                "                    "

SUB_LIST_FORMS:
	search_name = "*"
	Forms_list::buf_len1 = len(search_name)
        forms_list::item_code1 = qui$_search_name
	forms_list::buf_addr1 = loc(search_name)
	forms_list::ret_len1 = 0%
 	forms_list::buf_len2 = 4%
	forms_list::item_code2 = qui$_search_flags
	forms_list::buf_addr2 = loc(form_search_flags)
	forms_list::ret_len2 = 0%
 	forms_list::buf_len3 = 31%
	forms_list::item_code3 = qui$_form_name
	forms_list::buf_addr3 = loc(list_form_name)
	forms_list::ret_len3 = 0%
	forms_list::buf_len4 = 4%
	forms_list::item_code4 = qui$_form_number
	forms_list::buf_addr4 = loc(form_number)
	forms_list::ret_len4 = 0%
	forms_list::list_terminator = 0%

	!==> paste Display
	row = 6%
	column = 2%
	stat = smg$erase_display(list_vdid)
        stat = smg$paste_virtual_display(list_vdid,pb_id,row,column)
	stat = smg$home_cursor(list_vdid)

        !==> make initial call
	current_row = 1%
	current_column = 1%
	stat = sys$getquiw(,qui$_display_form by value,,	&
                            forms_list by ref,        		&
			    iosb by ref,,)

	!==> loop until no more forms
	while iosb <> jbc$_nomoreform 
	       	stat = smg$put_chars(list_vdid,list_form_name, 		&
				     current_row, current_column,,,,)
         	search_name = "*"
 		stat = sys$getquiw(,qui$_display_form by value,,	&
                                    forms_list by ref,        		&
				    iosb by ref,,)
		if current_column = 66 then
			current_row = current_row + 1
			current_column = 1
		else
			current_column = current_column + 13
		end if
	next

 	!==> Cancel WildCard Operation
	stat = sys$getquiw(,qui$_cancel_operation by value,,,,,)

        stat = smg$read_string(kb_id,input_form_name,			&
               "Enter form name =>" ,31%,,,,,,input_vdid,,,)


	return



	%SBTTL "Internal Subroutine:	<HELP>"
 SUB_HELP:
	!+
	!
	!  FUNCTIONAL DESCRIPTION:
	!
	!	Provides help displays
	!
	!  IMPLICIT INPUTS:
	!
	!  IMPLICIT OUTPUTS:
	!
	!  SIDE EFFECTS:
	!
	!-
        !   
 	!

	text_buffer(60%) = "This program allows you to view and alter "
	text_buffer(61%) = "characteristics of a print queue.  To select an "
	text_buffer(62%) = "option from a menu. Press the high-lighted"
	text_buffer(63%) = "key from the matching word. To see the list of "
	text_buffer(64%) = "functions and what they do, continue with HELP"
	text_buffer(65%) = ""

	text_buffer(66%) = "Queue:    Changes the current print queue"
	text_buffer(67%) = ""
	text_buffer(68%) = "Form:     Changes the queues mouted form"
	text_buffer(69%) = ""
	text_buffer(70%) = "Status:   Stops or starts the queue"
	text_buffer(71%) = ""

	text_buffer(72%) = "Print:    Send a file to the queue"
	text_buffer(73%) = ""
	text_buffer(74%) = "Jobs:     Allows for requeuing, deleting,"
	text_buffer(75%) = "          holding and release of jobs"
	text_buffer(76%) = ""
	text_buffer(77%) = ""

	text_buffer(78%) = "Requeue job:   Move job to different queue"
	text_buffer(79%) = ""
	text_buffer(80%) = "Delete job:    Remove job from queue"
	text_buffer(81%) = ""
	text_buffer(82%) = "Hold job:      Puts job on hold"
	text_buffer(83%) = ""

	text_buffer(84%) = "Release Job:   Prints job that is on hold"
	text_buffer(85%) = ""
	text_buffer(86%) = "Help:     Displays this window"
	text_buffer(87%) = ""
	text_buffer(88%) = "Exit:     Leave QUEUE_CONTROL program"
	text_buffer(89%) = ""

	text_buffer(90%) = ""
	text_buffer(91%) = ""
	text_buffer(92%) = "                  End of HELP"
	text_buffer(93%) = ""
	text_buffer(94%) = ""
	text_buffer(95%) = ""


	!
	stat = smg$home_cursor( help_vdid )		! Home the cursor
	call lib$signal(stat) if ( stat and 1%) = 0%

	!=> Paste the virtual display
	row = 12%
	column = 20%
	stat = smg$paste_virtual_display( help_vdid, pb_id, row, column )
	call lib$signal(stat) if ( stat and 1%) = 0%

	j = 1
        page_num = 1
	text_buffer(59%) = "QUEUE_CONTROL Help Window             Page:" + str$(page_num)
	stat = smg$put_line( help_vdid, text_buffer(59) )
	stat = smg$put_line( help_vdid, " " )
	for i = 60% to 95%
		call lib$signal(stat) if ( stat and 1%) = 0%
		stat = smg$put_line( help_vdid, text_buffer(i) )
		call lib$signal(stat) if ( stat and 1%) = 0%
		if j = 6 then 
		    j = 1 
		    page_num = page_num + 1
 	            stat = smg$put_line( help_vdid, " " )
		    text_buffer(99) = "Press F10 to exit help - Any other key to continue"
    		    stat = smg$put_line( help_vdid, text_buffer(99) )
          	    stat = smg$read_keystroke( kb_id, term_code,,timer,)
		    goto EXIT_HELP if term_code = smg$k_trm_f10
		    goto EXIT_HELP if term_code = smg$k_trm_f20
 		    stat = smg$home_cursor( help_vdid )	! Home the cursor
		    text_buffer(59%) = "QUEUE_CONTROL Help Window             Page:" + str$(page_num)
	            stat = smg$put_line( help_vdid, text_buffer(59) )
 	            stat = smg$put_line( help_vdid, " " )
                else	
		    j = j + 1
		end if
		    	
	next i


   EXIT_HELP:
	!=> Unpaste it when done
	stat = smg$unpaste_virtual_display( help_vdid, pb_id ) 
	call lib$signal(stat) if ( stat and 1%) = 0%

	!=> Repaste work area
	row = 6%
	column = 2%
	stat = smg$paste_virtual_display( work_vdid, pb_id, row, column )
	call lib$signal(stat) if ( stat and 1%) = 0%

	return



	%SBTTL "Error Block"
       
8000	handler error_block
	     select err
		     case = 155%
			   ! err = 155 is the basic error for record 
			   !	   not found
			   create_record = true
		     case = 11%
			   ! err = 11 is the basic error for end of file
			   create_record = true
			   continue
		     case = 52%
			   ! err = 52 is the basic error for illegal number
			   print  "Invalid quote number"
			   illegal_number = true
			   continue
                     case else
			   exit handler
     		end select
	end handler
                                                                       

	!================================================================
	!			END PROGRAM
	!================================================================

9999	end program


	%sbttl	"External Subroutine TRAP_MSG" 
	!++
	! AST routine called when a broadcast message is sent
	!
	!--

10000	sub TRAP_MSG (paste_id, nl_1, nl_2, nl_3, nl_4)

	declare long 						&
		stat1, 						&
		pasteboard, 					&
		message_vdid

	declare word msg_len

	declare string msg

	declare long constant forward = 1
	declare long constant wrp_flag = 1

	!+
	! MAP to the MAIN programs SMG data structure values
	!-
	map (smg_params) long disp_info(2), long keyboard_info(4)

	external long function					&
				smg$paste_virtual_display,	&
			 	smg$put_line,			&
				smg$get_broadcast_message,	&
				smg$label_border,		&
				smg$ring_bell

	external sub lib$stop(long by value)
	external sub lib$signal(long by value)

	external long constant 					&
			smg$_no_mormsg,				&
			smg$k_top

	!+
	! Assign values to the local variables according to the 
	! values stored in the MAP area
	!-

	pasteboard = disp_info(0)
	message_vdid = disp_info(1)

	!+
	! Print the trapped messages in the MESS display. If there are no
	! more messages, go back to the infinite loop in the main program.
	!-
	stat1 = smg$label_border(message_vdid, "Message from System",	&
		 smg$k_top,3%,,,)
	call lib$signal(stat1) if ( stat1 and 1%) = 0%


 WRITE_BROADCAST:
	while 1%

		stat1 = smg$get_broadcast_message(pasteboard, msg, msglen)
		if (stat1 = smg$_no_mormsg) then
		  goto EXIT_LOOP
		  !exit WRITE_BROADCAST
		end if
	        if ( stat1 and 1%) = 0% then
		  call lib$signal(stat1)
		end if

		stat1 = smg$ring_bell(message_vdid)
		stat1 = smg$put_line( message_vdid, msg, forward,,, wrp_flag)
		call lib$signal(stat1) if ( stat1 and 1%) = 0%

	next

 EXIT_LOOP:

	end sub
