2 XCOMM $TOG: dtlp.src /main/17 1998/07/31 17:03:31 mgreess $
4 XCOMM (c) Copyright 1996 Digital Equipment Corporation.
5 XCOMM (c) Copyright 1993-1996 Hewlett-Packard Company.
6 XCOMM (c) Copyright 1993-1996 International Business Machines Corp.
7 XCOMM (c) Copyright 1993-1996 Sun Microsystems, Inc.
8 XCOMM (c) Copyright 1993-1996 Novell, Inc.
9 XCOMM (c) Copyright 1996 FUJITSU LIMITED.
10 XCOMM (c) Copyright 1996 Hitachi.
14 XCOMM ###################################################################
18 XCOMM Default Location: /usr/dt/bin/dtlp
20 XCOMM Purpose: Set up print spooler options and print.
22 XCOMM Description: This shell script provides a graphical interface
23 XCOMM for a print spooler dialog by default. If
24 XCOMM DTPRINTSILENT is "true", however, then it processes
25 XCOMM the file and directly invokes "lp".
27 XCOMM Invoked by: The default Print action or custom print actions.
29 XCOMM Product: @(#)Common Desktop Environment 1.0
31 XCOMM Note: Please do not modify this file.
32 XCOMM Later product updates will overwrite this file.
34 XCOMM ###################################################################
37 XCOMM #################################################################
39 XCOMM Following are the environmental options we support
41 XCOMM #################################################################
45 XCOMM DTPRINTFILEREMOVE
47 XCOMM DTPRINTTESTOUTPUT
48 XCOMM DTPRINTUSERFILENAME
50 XCOMM #################################################################
51 XCOMM ## Internal Globals
53 XCOMM ## Actually, most variables in this script are global.
55 XCOMM ## Most are defined in the Initialize() routine.
57 XCOMM #################################################################
60 PATH=/bin:/usr/bin:/usr/ucb
64 XCOMM Exit/Return codes
73 NO_READABLE_FILE_ERR=6
75 PRINTER_DOES_NOT_EXIST=8
77 NO_PRINTER_AVAILABLE=10
78 PRINTER_NOT_ACCEPT_REQ=11
82 XCOMM For string processing
88 XCOMM #################################################################
91 XCOMM ## Set a number of key variables to their defaults.
94 XCOMM ## ----------------------
95 XCOMM ## File to print: Stdin
96 XCOMM ## Number of copies: 1
97 XCOMM ## Print Command: lp
99 XCOMM #################################################################
102 typeset -u Uppercase_string
112 failure_flag=$SUCCESS
126 HASH Assume print file is stdin, unless told otherwise...
158 HASH directory for temporary files used by dtlp
160 DTLPDIR="$HOME/.dt/tmp"
162 if [ ! -d "$DTLPDIR" ]
169 catopen CAT_ID $COMMAND_NAME
175 XCOMM #################################################################
176 XCOMM ## SetPreEnvironment()
178 XCOMM ## Check the ENVIRONMENT values we care about, and
179 XCOMM ## set the corresponding internal variable values.
181 XCOMM #################################################################
190 if (( ${#DTPRINTCWD} ))
192 print_cwd=$DTPRINTCWD
196 if (( ${#DTPRINTFILEREMOVE} ))
199 Uppercase_string=$DTPRINTFILEREMOVE
200 if [[ "$Uppercase_string" = "TRUE" ]]
207 if (( ${#DTPRINTSILENT} ))
210 Uppercase_string=$DTPRINTSILENT
211 if [[ "$Uppercase_string" = "TRUE" ]]
218 if (( ${#DTPRINTUSERFILENAME} ))
220 user_filename=$DTPRINTUSERFILENAME
224 if (( ${#DTPRINTTESTOUTPUT} ))
226 test_output_file=$DTPRINTTESTOUTPUT
232 XCOMM #################################################################
233 XCOMM ## ReconcileOptions()
235 XCOMM ## Arbitrate when there are two or more conflicting
236 XCOMM ## print options.
238 XCOMM ## The order of precedence is: -w > -a > -r.
240 XCOMM #################################################################
244 HASH The RAW option takes precedence over all others.
246 if (( $print_raw_flag ))
253 HASH Next, this MAN option comes into play
255 elif (( $print_man_flag ))
263 XCOMM #################################################################
264 XCOMM ## DoParameterCollectionSilent()
266 XCOMM ## Collect the silent lp options, mimicking the GUI
267 XCOMM ## collection process.
269 XCOMM #################################################################
270 DoParameterCollectionSilent()
272 HASH printer_name has to be set at this point so no need to check
273 LPOPTIONS=-d${printer_name}
275 if (( $banner_title_flag ))
277 LPOPTIONS=${LPOPTIONS}" "${MINUS_T}${SINGLE_QUOTE}${banner_title}${SINGLE_QUOTE}
280 if (( $copy_count_flag ))
282 LPOPTIONS=${LPOPTIONS}" -n${copy_count}"
285 if (( $other_options_flag ))
287 LPOPTIONS=${LPOPTIONS}" ${other_options}"
290 if [[ "$send_mail_flag" == "true" ]]
292 LPOPTIONS=${LPOPTIONS}" -m"
295 if (( $verbose_flag ))
297 echo Print Command is $print_command and Options are $LPOPTIONS
302 XCOMM #################################################################
303 XCOMM ## EchoDtlpSetupOptions()
305 XCOMM ## Echo all the command settings.
306 XCOMM ## If dtlp is run stand-alone, the invoker may redirect
307 XCOMM ## the test output to a log file. Under the test harness
308 XCOMM ## this is done automatically by the "record" function.
310 XCOMM #################################################################
311 EchoDtlpSetupOptions()
313 if (( $remove_flag ))
315 echo Remove file flag is SET.
317 if (( $print_man_flag ))
319 echo Manpage flag is SET.
321 if (( $print_raw_flag ))
323 echo Raw print flag is SET.
325 if (( $print_cwd_flag ))
327 echo Print working directory is $print_cwd.
329 if (( $print_page_allowed ))
331 echo Page printing is allowed.
333 echo Page printing is NOT allowed.
335 if (( $format_flag ))
337 echo Format flag is SET.
339 if (( $silent_flag ))
341 echo Silent flag is SET.
343 if (( $user_filename_flag ))
345 echo User-visible filename is \"$user_filename\".
347 if (( $verbose_flag ))
349 echo Verbose flag is SET.
351 if (( $other_options_flag ))
353 echo Other options include \"$other_options\".
355 if [[ "$send_mail_flag" == "true" ]]
357 echo Send Mail flag is SET.
359 echo Copies is set to $copy_count.
362 XCOMM #################################################################
365 XCOMM ## Do the actual spooling, based on the value of LPOPTIONS.
367 XCOMM ## If possible, log the results.
368 XCOMM #################################################################
371 if (( $print_cwd_flag )) && [[ (-d "$print_cwd") && (-x "$print_cwd") ]]
378 HASH then don't do any printing--instead log the results
381 echo "Command that will be invoked is..."
387 if (( $print_raw_flag ))
389 HASH Nothing special is required for raw mode on this platform.
390 LPOPTIONS="${LPOPTIONS}"
393 if (( $format_flag ))
396 if (( $banner_title_flag ))
398 PAGEHEADER="$banner_title"
399 elif (( $user_filename_flag ))
401 PAGEHEADER="$user_filename"
403 PAGEHEADER="$print_file"
406 $INVOKER "cat $print_file | pr -f -h '${PAGEHEADER}' | ${print_command} ${LPOPTIONS}"
407 elif (( $print_man_flag ))
409 $INVOKER "cat $print_file | tbl | nroff -man | col | ${print_command} ${LPOPTIONS}"
412 if [ "$print_file" = "-" ]
414 $INVOKER "cat $print_file | ${print_command} ${LPOPTIONS}"
416 $INVOKER "${print_command} -c ${LPOPTIONS} $print_file"
421 XCOMM #################################################################
424 XCOMM ## End the show
425 XCOMM #################################################################
428 if (( $remove_flag )) && [[ "$print_file" != "-" ]]
430 rm -f $print_file >/dev/null 2>&1
433 if (( $verbose_flag ))
439 XCOMM #################################################################
441 XCOMM ## Ensure that the supplied file name references a
444 XCOMM ## Returns true or false.
445 XCOMM #################################################################
453 HASH check whether file exists and is a regular file
456 return $NO_REGULAR_FILE_ERR
459 HASH check whether file is readable by the user
462 return $NO_READABLE_FILE_ERR
467 XCOMM #################################################################
468 XCOMM ## CheckValidPrinter()
470 XCOMM ## Ensure that the supplied printer name references a printer
471 XCOMM ## that exists and is enabled or a default printer exists,
472 XCOMM ## if no printer is specified.
474 XCOMM ## Returns true or false.
475 XCOMM #################################################################
478 catgets CAT_MESG_STRING $CAT_ID 1 10 "Default"
480 if [[ "$printer_name" = "" ]]
482 printer_name=$CAT_MESG_STRING
485 if [[ "$printer_name" = "$CAT_MESG_STRING" ]]
488 if (( $failure_flag == $SUCCESS ))
490 printer_name=$default_printer
496 tmpfile=$DTLPDIR/$printer_name$$
497 LANG=C lpstat -p$printer_name > $tmpfile 2>&1
498 if [[ $? != $SUCCESS ]]
500 HASH printer does not exist
501 failure_flag=$PRINTER_DOES_NOT_EXIST
505 grep disabled $tmpfile > /dev/null 2>&1
508 failure_flag=$PRINTER_NOT_ENABLED
512 status=$DTLPDIR/status$$
513 LANG=C lpstat -a > $tmpfile 2>&1
514 grep $printer_name $tmpfile > $status 2>&1
515 grep "not accepting" $status > /dev/null 2>&1
518 failure_flag=$PRINTER_NOT_ACCEPT_REQ
527 failure_flag=$SUCCESS
531 XCOMM #################################################################
532 XCOMM ## GetDefaultPrinter()
534 XCOMM ## Looks up the default printer destination. Returns value of
535 XCOMM ## LPDEST if set; otherwise, checks if there is a system default
536 XCOMM ## printer destination.
538 XCOMM #################################################################
552 default_printer=$LPDEST
555 t1="`LANG=C lpstat -d | head -3 | tail -1`"
557 t1="`LANG=C lpstat -d`"
559 t2="`echo $t1 | cut -d' ' -f1`"
561 HASH "no system default destination" is expected if no default is defined;
562 HASH otherwise, "system default destination: <printer_name>" is expected.
564 if [[ "$t2" != "no" ]]
566 default_printer="`echo $t1 | cut -f$prfld -d"$flddelim"`"
567 HASH remove leading space
568 default_printer=${default_printer##+( )}
571 if [[ "$default_printer" = "" ]]
573 failure_flag=$NO_DEFAULT_PRINTER
577 failure_flag=$SUCCESS
582 XCOMM #################################################################
583 XCOMM ## PrintStartLog()
585 XCOMM ## Print the start of the log
587 XCOMM #################################################################
589 print "$COMMAND_NAME..."
593 XCOMM #################################################################
594 XCOMM ## CheckIsPosInteger()
596 XCOMM ## Checks whether a given value is a positive integer.
598 XCOMM #################################################################
602 HASH Strip any leading or trailing spaces
606 if [[ ${#val} && "$val" = +([0-9]) ]]
608 failure_flag=$SUCCESS
610 failure_flag=$NOT_POS_INTEGER
615 XCOMM #################################################################
616 XCOMM ## GetErrorMessageString()
618 XCOMM ## Looks up the appropriate error message based on the value of
619 XCOMM ## failure_flag.
621 XCOMM #################################################################
622 GetErrorMessageString()
624 catgets CAT_MESG_STRING $CAT_ID 1 130 "Sorry--Unable to print:"
626 if (( $user_filename_flag ))
628 CAT_MESG_STRING=${CAT_MESG_STRING}" \"$user_filename\"."
630 CAT_MESG_STRING=${CAT_MESG_STRING}" \"$print_file\"."
633 case $failure_flag in
634 $NO_REGULAR_FILE_ERR)
635 catgets TEMP_MESG_STRING $CAT_ID 1 210 "That file is either not printable or it does not exist."
637 $NO_READABLE_FILE_ERR)
638 catgets TEMP_MESG_STRING $CAT_ID 1 134 "You don't have permission to read that file."
640 $NO_PRINTER_AVAILABLE)
641 catgets TEMP_MESG_STRING $CAT_ID 1 220 "There is either no printer defined for this system or no printer is enabled."
643 $PRINTER_DOES_NOT_EXIST)
644 catgets TEMP_MESG_STRING $CAT_ID 1 230 "The printer does not exist."
646 $PRINTER_NOT_ENABLED)
647 catgets TEMP_MESG_STRING $CAT_ID 1 240 "The printer is not enabled."
650 catgets TEMP_MESG_STRING $CAT_ID 1 250 "There is no default printer destination."
652 $PRINTER_NOT_ACCEPT_REQ)
653 catgets TEMP_MESG_STRING $CAT_ID 1 260 "The printer is currently not accepting requests."
656 catgets TEMP_MESG_STRING $CAT_ID 1 270 "Number of copies must be a positive number."
663 if (( $failure_flag == $NO_PRINTER_AVAILABLE ))
665 CAT_MESG_STRING="${TEMP_MESG_STRING}"
667 CAT_MESG_STRING="${CAT_MESG_STRING}""
673 XCOMM #################################################################
674 XCOMM ## DisplayErrorMessage()
676 XCOMM ## We have detected an error. Write out a message to
677 XCOMM ## that effect.
679 XCOMM #################################################################
680 DisplayErrorMessage()
682 catgets CAT_MESG_STRING $CAT_ID 1 130 "Sorry--Unable to print:"
684 GetErrorMessageString
688 print "${CAT_MESG_STRING}"
693 XCOMM #################################################################
694 XCOMM ## PrintEndLog()
696 XCOMM ## Print the end of the log.
698 XCOMM #################################################################
701 if (( $failure_flag == $SUCCESS ))
703 print "...successfully completed."
705 print "...completed unsuccessfully."
710 XCOMM #################################################################
711 XCOMM ## PrintUsage()
713 XCOMM ## Print a usage message.
715 XCOMM #################################################################
718 print "Usage: $COMMAND_NAME [-b <banner_title>] [-d <printer_name>]"
719 print " [-m <print_command>] [-n <copy_count>]"
720 print " [-o <other_options>] [-u <user_filename>]"
721 print " [-a] [-e] [-h] [-i] [-r] [-s] [-v] [-w]"
722 print " <print_file>"
725 print " <banner_title>"
726 print " Specifies the title to put on the banner page."
728 print " <printer_name>"
729 print " Specifies the printer name as known to the lp spooler."
731 print " <print_command>"
732 print " Specifies the command with which to invoke the printer."
734 print " <copy_count>"
735 print " Specifies the number of copies to print."
737 print " <other_options>"
738 print " Specifies the other print options."
740 print " <user_filename>"
741 print " Specifies the title of the file to display to the user."
744 print " Formats the file with "man" before printing."
747 print " Removes the file after printing."
750 print " Displays this help message."
753 print " Requests the spooler to sent mail to the user when the print job is completed."
756 print " Formats the file with "pr -f" before printing."
759 print " Prints silently (no dialog box)."
762 print " Directs verbose messages to standard output."
765 print " Prints the data raw (uninterpreted)."
767 print " <print_file>"
768 print " Specifies the name of file(s) to print."
772 XCOMM #################################################################
775 XCOMM ## All exits should go through this routine.
777 XCOMM #################################################################
783 XCOMM ################# GUI Callbacks ####################
785 XCOMM #################################################################
786 XCOMM ## PrintHelpCB()
788 XCOMM ## This is the callback for the Help button in the Print dialog;
789 XCOMM ## it will post a help dialog.
791 XCOMM #################################################################
794 DtkshDisplayQuickHelpDialog "dtlp_help" HELP_TYPE_TOPIC \
795 "Printmgr" "dtlpPrintDialog"
798 XCOMM #################################################################
799 XCOMM ## DoParameterCollection()
801 XCOMM ## Gathers and validates print options set using the command line
802 XCOMM ## and the Print dialog.
804 XCOMM #################################################################
805 DoParameterCollection()
807 catgets CAT_MESG_STRING $CAT_ID 1 10 "Default"
809 GetCurrentPrinterName
811 if (( $failure_flag != $SUCCESS ))
813 DisplayErrorMessageDialog
817 if [[ ("$printer_name" != "") && "$printer_name" != "$CAT_MESG_STRING" ]]
819 LPOPTIONS="-d"$printer_name
823 HASH Get current value from textfield resource rather than from position
824 HASH resource because the user may have changed the value using the former
825 HASH instead of the up/down arrow.
827 HASH We must make sure the value is a positive integer in this case.
829 XtGetValues $COPIES_SB textField:COPIES_TF
830 XmTextFieldGetString copy_val $COPIES_TF
832 CheckIsPosInteger $copy_val
833 if (( $failure_flag == $NOT_POS_INTEGER ))
835 DisplayErrorMessageDialog
841 HASH Strip any leading or trailing spaces
842 HASH This should be validated, to make sure it is a valid integer.
843 copy_count=${copy_count##+( )}
844 copy_count=${copy_count%%+( )}
845 if [ "$copy_count" != "" ] ; then
847 LPOPTIONS=${LPOPTIONS}" -n$copy_count"
850 XmTextGetString banner_title $BANNER_TF
852 HASH Strip any leading or trailing spaces
853 banner_title=${banner_title##+( )}
854 banner_title=${banner_title%%+( )}
855 if [ "$banner_title" != "" ] ; then
857 LPOPTIONS=${LPOPTIONS}" "${MINUS_T}${SINGLE_QUOTE}${banner_title}${SINGLE_QUOTE}
860 XmTextGetString other_options $OPTIONS_TF
862 HASH Strip any leading or trailing spaces
863 other_options=${other_options##+( )}
864 other_options=${other_options%%+( )}
865 if [ "$other_options" != "" ]
867 LPOPTIONS=${LPOPTIONS}" $other_options"
870 XtGetValues $SEND_MAIL_BTN set:send_mail_flag
872 if [[ "$send_mail_flag" == "true" ]]
874 LPOPTIONS=${LPOPTIONS}" -m"
877 if (( $verbose_flag ))
879 echo The LP options are \"${LPOPTIONS}\".
885 XCOMM #################################################################
886 XCOMM ## DestroyDialogs()
888 XCOMM ## Destroys the Select Printer dialog, if it exists, and the
889 XCOMM ## Print dialog.
891 XCOMM #################################################################
894 if [[ "$SELECT_PRINTER_FORM" != "" ]]
896 XtDestroyWidget $(XtParent "-" $SELECT_PRINTER_FORM)
898 XtDestroyWidget $(XtParent "-" $PDIALOG)
901 XCOMM #################################################################
904 XCOMM ## Callback for the Print button in the Print dialog. Submits
905 XCOMM ## print request to lp if all is well; otherwise, simply returns.
907 XCOMM #################################################################
912 DoParameterCollection
913 if [ $? != $SUCCESS ]
923 XCOMM #################################################################
924 XCOMM ## PrintCancelCB()
926 XCOMM ## This is the callback for the Cancel button in the Print dialog.
927 XCOMM ## It will send an empty string to stdout, and will then exit with
928 XCOMM ## a value of -1.
930 XCOMM #################################################################
938 XCOMM #################################################################
939 XCOMM ## UpdatePrinterDescription()
941 XCOMM ## Updates Printer Description in the Print dialog.
943 XCOMM #################################################################
944 UpdatePrinterDescription()
947 if (( $failure_flag != $SUCCESS ))
949 XtSetValues $PRINTER_DESC_LABEL labelString:""
953 GetPrinterInfo $printer_name
954 XtSetValues $PRINTER_DESC_LABEL labelString:"$printer_info"
957 XCOMM #################################################################
958 XCOMM ## SelectPrinterCB()
960 XCOMM ## Callback for the Select Printer button in the Select Printer
961 XCOMM ## dialog. Updates Printer Name and Description in the Print
962 XCOMM ## dialog and unmanages the Select Printer dialog.
964 XCOMM #################################################################
967 XtSetValues $PRINTER_TF value:$selected_printer
968 printer_name=$selected_printer
969 UpdatePrinterDescription
970 XtUnmanageChild $SELECT_PRINTER_FORM
973 XCOMM #################################################################
974 XCOMM ## SelectPrinterHelpCB()
976 XCOMM ## This is the callback for the Help button in the Select Printer
977 XCOMM ## dialog; it will post a help dialog.
979 XCOMM #################################################################
980 SelectPrinterHelpCB()
982 DtkshDisplayQuickHelpDialog "dtlp_help" HELP_TYPE_TOPIC \
983 "Printmgr" "dtlpSelectPrinterDialog"
986 XCOMM #################################################################
987 XCOMM ## ListSelectCB()
989 XCOMM ## Callback for the items in the printer list in the Select Printer
990 XCOMM ## dialog. Updates Printer Information when a printer is selected.
992 XCOMM #################################################################
995 GetPrinterInfo ${CB_CALL_DATA.ITEM}
996 XtSetValues $INFO_TEXT value:"$printer_info"
997 selected_printer=${CB_CALL_DATA.ITEM}
1000 XCOMM #################################################################
1001 XCOMM ## ListDblSelectCB()
1003 XCOMM ## Callback for the double-clicks on the printer list items in the
1004 XCOMM ## Select Printer dialog. Simulates selection of the Select Printer
1005 XCOMM ## button when a printer item is double-clicked on.
1007 XCOMM #################################################################
1010 if [ ${CB_CALL_DATA.EVENT.TYPE} != KeyPress ]
1012 XtCallCallbacks $SELECT_PRINTER_BTN activateCallback
1016 XCOMM #################################################################
1017 XCOMM ## GetCurrentPrinterName()
1019 XCOMM ## Reads value of Printer Name textfield and strips off any
1020 XCOMM ## leading and trailing spaces.
1022 XCOMM #################################################################
1023 GetCurrentPrinterName()
1025 XmTextFieldGetString printer_name $PRINTER_TF
1027 HASH Strip any leading or trailing spaces
1028 printer_name=${printer_name##+( )}
1029 printer_name=${printer_name%%+( )}
1032 XCOMM #################################################################
1033 XCOMM ## GetAvailPrinters()
1035 XCOMM ## Gets the list of enabled printers.
1037 XCOMM #################################################################
1040 typeset -i num_printers=0
1044 HASH get a sorted list of all enabled printers
1046 tmpfile=$DTLPDIR/printers$$
1049 LANG=C lpstat -p | \
1050 grep READY | cut -f1 -d" " | \
1051 sort | uniq > $tmpfile 2>&1
1053 LANG=C lpstat -p | \
1054 grep enabled | cut -f2 -d" " | \
1055 sort | uniq > $tmpfile 2>&1
1058 if [ -s "$tmpfile" ]
1060 for i in `cat $tmpfile`
1062 printer_items=`echo $printer_items$comma$i`
1064 ((num_printers=num_printers+1))
1070 XCOMM #################################################################
1071 XCOMM ## GetPrinterInfo()
1073 XCOMM ## Gets the printer description.
1075 XCOMM #################################################################
1082 lpstat -p$1 > $t1 2>/dev/null
1083 lpstat -p$1 -D > $t2 2>/dev/null
1084 printer_info="`diff $t1 $t2 | sed -e '1d' -e 's/\(.*\)://'`"
1091 XCOMM #################################################################
1092 XCOMM ## SelectPrinterProc()
1094 XCOMM ## This is called when the Select Printer... button in the Print
1095 XCOMM ## dialog is selected. It posts the Select Printer dialog.
1097 XCOMM #################################################################
1100 if [[ "$SELECT_PRINTER_FORM" != "" ]]
1103 HASH dialog already exists, update printer info. if necessary
1105 GetCurrentPrinterName
1107 HASH get index of printer in the list
1108 XmListItemPos index $PRINTER_LIST $printer_name
1111 HASH If printer is in the list, select it and display info. on it;
1112 HASH otherwise, just re-manage the dialog.
1116 GetPrinterInfo $printer_name
1118 HASH display printer information and select the printer specified in
1119 HASH the Printer Name textfield
1121 XmTextSetString $INFO_TEXT "$printer_info"
1122 XmListSelectItem $PRINTER_LIST $printer_name true
1123 XmListSetPos $PRINTER_LIST $index
1126 XtManageChild $SELECT_PRINTER_FORM
1132 XmCreateFormDialog SELECT_PRINTER_FORM $TOPLEVEL form
1134 catgets CAT_MESG_STRING $CAT_ID 1 180 "Select Printer"
1136 XmInternAtom DEL_ATOM $DISPLAY WM_DELETE_WINDOW false
1137 XmAddWMProtocolCallback $(XtParent "-" $SELECT_PRINTER_FORM) \
1138 $DEL_ATOM SelectPrinterCancelCB
1140 XtSetValues $(XtParent "-" $SELECT_PRINTER_FORM) \
1141 title:"$CAT_MESG_STRING" \
1142 allowShellResize:False \
1143 deleteResponse:DO_NOTHING
1145 XtSetValues $SELECT_PRINTER_FORM \
1147 autoUnmanage:False \
1148 helpCallback:SelectPrinterHelpCB
1150 XmCreateWorkArea WORK_AREA $SELECT_PRINTER_FORM work_area \
1151 orientation:XmVERTICAL
1153 XmCreateWorkArea LIST_RC $WORK_AREA list_rc orientation:XmHORIZONTAL
1155 catgets CAT_MESG_STRING $CAT_ID 1 190 "Available Printers:"
1157 XmCreateLabelGadget LIST_LABEL $LIST_RC list_label \
1158 labelString:"$CAT_MESG_STRING"
1159 XtManageChild $LIST_LABEL
1161 XmCreateScrolledList PRINTER_LIST $LIST_RC printer_list \
1162 selectionPolicy:XmSINGLE_SELECT \
1163 singleSelectionCallback:ListSelectCB \
1164 defaultActionCallback:ListDblSelectCB \
1165 itemCount:$num_printers \
1166 items:$printer_items \
1168 XtManageChild $PRINTER_LIST
1170 XmCreateWorkArea INFO_RC $WORK_AREA info_rc orientation:XmVERTICAL
1172 catgets CAT_MESG_STRING $CAT_ID 1 200 "Printer Information:"
1174 XmCreateLabelGadget INFO_LABEL $INFO_RC info_label \
1175 labelString:"$CAT_MESG_STRING"
1176 XtManageChild $INFO_LABEL
1179 XmCreateScrolledText INFO_TEXT $INFO_RC info_text \
1180 editMode:XmMULTI_LINE_EDIT \
1181 value:"$printer_info" \
1187 XmCreateSeparator BTN_SEP $SELECT_PRINTER_FORM sep \
1188 separatorType:XmSHADOW_ETCHED_IN \
1189 $(DtkshUnder $WORK_AREA 4) \
1192 catgets CAT_MESG_STRING $CAT_ID 1 180 "Select Printer"
1194 XmCreatePushButtonGadget SELECT_PRINTER_BTN $SELECT_PRINTER_FORM \
1196 labelString:"$CAT_MESG_STRING" \
1197 $(DtkshUnder $BTN_SEP 5) \
1198 $(DtkshFloatLeft 10) \
1199 $(DtkshFloatRight 30) \
1200 $(DtkshAnchorBottom 5)
1202 XtAddCallback $SELECT_PRINTER_BTN activateCallback "SelectPrinterCB"
1204 catgets CAT_MESG_STRING $CAT_ID 1 110 "Cancel"
1206 XmCreatePushButtonGadget CANCEL_BTN $SELECT_PRINTER_FORM cancel_button \
1207 labelString:"$CAT_MESG_STRING" \
1208 $(DtkshUnder $BTN_SEP 5) \
1209 $(DtkshFloatLeft 40) \
1210 $(DtkshFloatRight 60) \
1211 $(DtkshAnchorBottom 5)
1213 XtAddCallback $CANCEL_BTN activateCallback "SelectPrinterCancelCB"
1215 catgets CAT_MESG_STRING $CAT_ID 1 120 "Help"
1217 XmCreatePushButtonGadget HELP_BTN $SELECT_PRINTER_FORM help_button \
1218 labelString:"$CAT_MESG_STRING" \
1219 $(DtkshUnder $BTN_SEP 5) \
1220 $(DtkshFloatLeft 70) \
1221 $(DtkshFloatRight 90) \
1222 $(DtkshAnchorBottom 5)
1224 XtAddCallback $HELP_BTN activateCallback "SelectPrinterHelpCB"
1226 XtSetValues $SELECT_PRINTER_FORM \
1227 initialFocus:$SELECT_PRINTER_BTN \
1228 defaultButton:$SELECT_PRINTER_BTN \
1229 cancelButton:$CANCEL_BTN \
1230 navigationType:EXCLUSIVE_TAB_GROUP
1232 XtManageChild $BTN_SEP
1233 XtManageChild $SELECT_PRINTER_BTN
1234 XtManageChild $CANCEL_BTN
1235 XtManageChild $HELP_BTN
1236 XtManageChild $INFO_TEXT
1237 XtManageChild $LIST_RC
1238 XtManageChild $INFO_RC
1239 XtManageChild $WORK_AREA
1240 XtManageChild $SELECT_PRINTER_FORM
1242 if (( $num_printers ))
1244 GetCurrentPrinterName
1246 if (( $failure_flag == $SUCCESS ))
1248 GetPrinterInfo $printer_name
1250 HASH display printer information and select the printer specified in
1251 HASH the Printer Name textfield
1253 XmTextSetString $INFO_TEXT "$printer_info"
1254 XmListSelectItem $PRINTER_LIST $printer_name true
1255 XmListSetItem $PRINTER_LIST $printer_name
1259 HASH no available printer, desensitize Select Printer button in
1260 HASH the Select Printer dialog
1262 XtSetSensitive $SELECT_PRINTER_BTN false
1263 failure_flag=$NO_PRINTER_AVAILABLE
1264 DisplayErrorMessageDialog
1268 XCOMM #################################################################
1269 XCOMM ## SelectPrinterCancelCB()
1271 XCOMM ## Callback for the Cancel button in Select Printer dialog.
1272 XCOMM ## It simply unmanages the dialog.
1274 XCOMM #################################################################
1275 SelectPrinterCancelCB()
1277 XtUnmanageChild $SELECT_PRINTER_FORM
1280 XCOMM #################################################################
1281 XCOMM ## PrinterNameFocusCB()
1283 XCOMM ## Focus callback for the Printer Name textfield to determine when
1284 XCOMM ## a printer name is changed so that printer description is updated
1285 XCOMM ## when the user changes the printer name in the Print dialog.
1287 XCOMM #################################################################
1288 PrinterNameFocusCB()
1290 HASH If Printer Name textfield gained focus, save the current printer name.
1291 HASH When it loses focus, compare the saved printer name with the new one
1292 HASH to determine if the user has changed it. If so, update the printer
1294 if [ ${CB_CALL_DATA.REASON} = CR_FOCUS ]
1296 GetCurrentPrinterName
1297 old_printer=$printer_name
1299 if [ ${CB_CALL_DATA.REASON} = CR_LOSING_FOCUS ]
1301 GetCurrentPrinterName
1302 if [ "$old_printer" != "$printer_name" ]
1304 UpdatePrinterDescription
1310 XCOMM #################################################################
1313 XCOMM ## Creates the Print dialog and sets up the callbacks.
1315 XCOMM #################################################################
1318 catgets CAT_MESG_STRING $CAT_ID 1 10 "Default"
1320 if (( $printer_name_flag ))
1322 printer=$printer_name
1325 if (( $failure_flag == $SUCCESS ))
1327 printer=$default_printer
1328 printer_name=$default_printer
1330 printer=$CAT_MESG_STRING
1334 if [[ "$printer_name" != "" ]]
1336 GetPrinterInfo $printer_name
1341 DtCreatePrintSetupDialog PDIALOG $TOPLEVEL pdialog \
1342 printCallback:PrintCB \
1343 cancelCallback:PrintCancelCB \
1344 helpCallback:PrintHelpCB \
1345 selectPrinterProc:SelectPrinterProc \
1346 workAreaLocation:DtWORK_AREA_TOP_AND_BOTTOM \
1347 printSetupMode:DtPRINT_SETUP_PLAIN \
1348 printDestination:DtPRINT_TO_PRINTER \
1349 printerName:"$printer" \
1350 description:"$printer_info"
1352 catgets CAT_MESG_STRING $CAT_ID 1 20 "Print"
1354 XmInternAtom DEL_ATOM $DISPLAY WM_DELETE_WINDOW false
1355 XmAddWMProtocolCallback $(XtParent "-" $PDIALOG) $DEL_ATOM PrintCancelCB
1357 XtSetValues $(XtParent "-" $PDIALOG) \
1358 title:"$CAT_MESG_STRING" \
1359 allowShellResize:False \
1360 deleteResponse:DO_NOTHING
1362 XtSetValues $PDIALOG autoUnmanage:False
1364 XmCreateWorkArea FILE_NAME_RC $PDIALOG file_name_rc \
1367 orientation:XmHORIZONTAL
1369 catgets CAT_MESG_STRING $CAT_ID 1 170 "File Name(s): "
1371 XmCreateLabel FILE_NAME_LABEL $FILE_NAME_RC file_name_label \
1372 labelString:"$CAT_MESG_STRING"
1374 if (( $user_filename_flag ))
1376 LABEL_STRING="${user_filename}"
1378 LABEL_STRING="${print_file}"
1380 XmCreateLabel FILE_NAME $FILE_NAME_RC file_name \
1381 labelString:"$LABEL_STRING"
1383 XtManageChild $FILE_NAME_RC
1384 XtManageChild $FILE_NAME_LABEL
1385 XtManageChild $FILE_NAME
1389 HASH Unmanage unneeded widgets
1391 XtNameToWidget TOP_SEP $PDIALOG "TopWorkAreaSeparator"
1392 XtUnmanageChild $TOP_SEP
1394 XtNameToWidget INFO_BTN $PDIALOG "Info"
1395 XtUnmanageChild $INFO_BTN
1397 XtNameToWidget SELECT_FILE_BTN $PDIALOG "SelectFile"
1398 XtUnmanageChild $SELECT_FILE_BTN
1400 XtNameToWidget SETUP_BTN $PDIALOG "Setup"
1401 XtUnmanageChild $SETUP_BTN
1403 DtCreatePDMJobSetup JOB $PDIALOG
1406 HASH Get widget handles
1408 XtNameToWidget PRINTER_COMBO $PDIALOG "Name"
1409 XtNameToWidget PRINTER_TF $PRINTER_COMBO "Text"
1410 XtNameToWidget PRINTER_DESC_LABEL $PDIALOG "Description"
1411 XtNameToWidget COPIES_SB $PDIALOG "*Copies"
1412 XtNameToWidget SEND_MAIL_CB $JOB "*SendMail"
1413 XtNameToWidget BANNER_TF $JOB "*Banner"
1414 XtNameToWidget OPTIONS_TF $JOB "*Options"
1415 XtNameToWidget SEND_MAIL_BTN $SEND_MAIL_CB "button_0"
1416 XtNameToWidget PRINT_BTN $PDIALOG "Print"
1417 XtNameToWidget PRINT_CANCEL_BTN $PDIALOG "Cancel"
1420 HASH move cursor to end of printer name
1422 XtSetValues $PRINTER_TF cursorPosition:${#PRINTER}
1425 HASH set focus callbacks to track printer name changes
1427 XtAddCallback $PRINTER_TF focusCallback "PrinterNameFocusCB"
1428 XtAddCallback $PRINTER_TF losingFocusCallback "PrinterNameFocusCB"
1431 HASH initialize SELECT_PRINTER_FORM to be used in SelectPrinterProc
1432 HASH to determine if the Select Printer dialog already exists.
1434 SELECT_PRINTER_FORM=""
1436 if (( $banner_title_flag ))
1438 XtSetValues $BANNER_TF value:"$banner_title"
1440 if (( $other_options_flag ))
1442 XtSetValues $OPTIONS_TF value:"$other_options"
1445 XtManageChild $PDIALOG
1447 if (( $copy_count_flag ))
1449 XtSetValues $COPIES_SB position:$copy_count
1452 if [[ "$send_mail_flag" == "true" ]]
1454 XtSetValues $SEND_MAIL_BTN set:true
1457 XtGetValues $COPIES_SB textField:COPIES_TF
1459 DtkshSetReturnKeyControls $PRINTER_TF $COPIES_TF $PDIALOG $PRINT_BTN
1460 DtkshSetReturnKeyControls $COPIES_TF $BANNER_TF $PDIALOG $PRINT_BTN
1461 DtkshSetReturnKeyControls $BANNER_TF $OPTIONS_TF $PDIALOG $PRINT_BTN
1467 XCOMM #################################################################
1468 XCOMM ## BadFileCB()
1470 XCOMM ## This is the callback for the OK button in the error message
1471 XCOMM ## dialog and is used when the file to print is invalid. It will
1472 XCOMM ## exit the program.
1474 XCOMM #################################################################
1480 XCOMM #################################################################
1481 XCOMM ## ErrorDialogCB()
1483 XCOMM ## This is the callback for the OK button in the error message
1484 XCOMM ## dialog and is used for non-fatal error messages. It simply
1485 XCOMM ## destroys the message dialog.
1487 XCOMM #################################################################
1490 XtDestroyWidget $INFORMATION
1493 XCOMM #################################################################
1494 XCOMM ## DisplayErrorMessageDialog()
1496 XCOMM ## We have detected an error. Post a dialog to that effect.
1498 XCOMM ## Upon entry, check the failure_flag value for the proper
1499 XCOMM ## message to print.
1501 XCOMM #################################################################
1502 DisplayErrorMessageDialog()
1504 XmCreateErrorDialog INFORMATION $TOPLEVEL information
1506 catgets CAT_MESG_STRING $CAT_ID 1 160 "Print Information"
1508 XtSetValues $(XtParent "-" $INFORMATION) title:"$CAT_MESG_STRING"
1510 GetErrorMessageString
1512 if (($failure_flag == $NO_FILE_ERR )) ||
1513 (( $failure_flag == $NO_REGULAR_FILE_ERR )) ||
1514 (( $failure_flag == $NO_READABLE_FILE_ERR ))
1516 bad_file_flag=$failure_flag
1522 XtSetValues $INFORMATION \
1524 messageString:"${CAT_MESG_STRING}" \
1526 defaultButtonType:DIALOG_OK_BUTTON \
1527 dialogStyle:DIALOG_FULL_APPLICATION_MODAL \
1528 messageAlignment:ALIGNMENT_CENTER
1530 XtUnmanageChild $(XmMessageBoxGetChild "-" $INFORMATION \
1531 DIALOG_CANCEL_BUTTON)
1533 XtUnmanageChild $(XmMessageBoxGetChild "-" $INFORMATION \
1536 XtManageChild $INFORMATION
1542 XCOMM #################################################################
1545 XCOMM ## Set up and call either the silent or the GUI routines.
1548 XCOMM #################################################################
1552 while getopts b:d:m:n:o:u:aehirsvw argument
1557 b) banner_title=$OPTARG
1560 d) printer_name=$OPTARG
1568 i) send_mail_flag=true
1570 m) print_command=$OPTARG
1571 print_command_flag=1
1573 n) copy_count=$OPTARG
1576 o) other_options=$OPTARG
1577 other_options_flag=1
1583 u) user_filename=$OPTARG
1584 user_filename_flag=1
1596 ((shift_positions = OPTIND - 1))
1600 if (( $shift_positions < $# ))
1603 XCOMM We have at least one remaining non-switch command line argument
1605 shift $shift_positions
1607 HASH We assume that any remaining arguments constitute the filename.
1608 HASH At some later point, may want to parse a list of filenames.
1615 nw=`echo $1 | wc -w`
1623 if [ "" = "$print_file" ]
1627 print_file="$print_file $file"
1636 XCOMM make sure copy_count is a positive integer
1638 if (( $copy_count_flag ))
1640 CheckIsPosInteger $copy_count
1641 if (( $failure_flag != $SUCCESS ))
1649 XCOMM Make sure all these settings line up consistently.
1653 if (( $verbose_flag ))
1659 XCOMM Do we have enough information to do our job?
1660 XCOMM This step may cause us to exit.
1664 XCOMM Have we been given a valid file(s)?
1669 CheckValidFile "${files[$i]}"
1671 if (( $failure_flag != $SUCCESS ))
1673 print_file="\"${files[$i]}\""
1679 if (( $silent_flag ))
1681 if (( $failure_flag == $SUCCESS ))
1685 if (( $failure_flag != $SUCCESS ))
1691 DoParameterCollectionSilent
1700 if [[ -r CDE_INSTALLATION_TOP/lib/dtksh/DtFuncs.dtsh ]]
1702 . CDE_INSTALLATION_TOP/lib/dtksh/DtFuncs.dtsh
1705 echo Sorry--cannot find initialization file.
1706 Exit $NO_INIT_FILE_ERR
1709 XtInitialize TOPLEVEL printerConfig Dtlp "${@:-}"
1710 XtDisplay DISPLAY $TOPLEVEL
1712 if (( $failure_flag == $SUCCESS ))
1716 DisplayErrorMessageDialog
1721 XCOMM Never reached.
1723 XCOMM #################### eof ##############################