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 #################################################################
544 #elif defined(__uxp__)
555 default_printer=$LPDEST
558 t1="`LANG=C lpstat -d | head -3 | tail -1`"
560 t1="`LANG=C lpstat -d`"
562 t2="`echo $t1 | cut -d' ' -f1`"
564 HASH "no system default destination" is expected if no default is defined;
565 HASH otherwise, "system default destination: <printer_name>" is expected.
567 if [[ "$t2" != "no" ]]
569 default_printer="`echo $t1 | cut -f$prfld -d"$flddelim"`"
570 HASH remove leading space
571 default_printer=${default_printer##+( )}
574 if [[ "$default_printer" = "" ]]
576 failure_flag=$NO_DEFAULT_PRINTER
580 failure_flag=$SUCCESS
585 XCOMM #################################################################
586 XCOMM ## PrintStartLog()
588 XCOMM ## Print the start of the log
590 XCOMM #################################################################
592 print "$COMMAND_NAME..."
596 XCOMM #################################################################
597 XCOMM ## CheckIsPosInteger()
599 XCOMM ## Checks whether a given value is a positive integer.
601 XCOMM #################################################################
605 HASH Strip any leading or trailing spaces
609 if [[ ${#val} && "$val" = +([0-9]) ]]
611 failure_flag=$SUCCESS
613 failure_flag=$NOT_POS_INTEGER
618 XCOMM #################################################################
619 XCOMM ## GetErrorMessageString()
621 XCOMM ## Looks up the appropriate error message based on the value of
622 XCOMM ## failure_flag.
624 XCOMM #################################################################
625 GetErrorMessageString()
627 catgets CAT_MESG_STRING $CAT_ID 1 130 "Sorry--Unable to print:"
629 if (( $user_filename_flag ))
631 CAT_MESG_STRING=${CAT_MESG_STRING}" \"$user_filename\"."
633 CAT_MESG_STRING=${CAT_MESG_STRING}" \"$print_file\"."
636 case $failure_flag in
637 $NO_REGULAR_FILE_ERR)
638 catgets TEMP_MESG_STRING $CAT_ID 1 210 "That file is either not printable or it does not exist."
640 $NO_READABLE_FILE_ERR)
641 catgets TEMP_MESG_STRING $CAT_ID 1 134 "You don't have permission to read that file."
643 $NO_PRINTER_AVAILABLE)
644 catgets TEMP_MESG_STRING $CAT_ID 1 220 "There is either no printer defined for this system or no printer is enabled."
646 $PRINTER_DOES_NOT_EXIST)
647 catgets TEMP_MESG_STRING $CAT_ID 1 230 "The printer does not exist."
649 $PRINTER_NOT_ENABLED)
650 catgets TEMP_MESG_STRING $CAT_ID 1 240 "The printer is not enabled."
653 catgets TEMP_MESG_STRING $CAT_ID 1 250 "There is no default printer destination."
655 $PRINTER_NOT_ACCEPT_REQ)
656 catgets TEMP_MESG_STRING $CAT_ID 1 260 "The printer is currently not accepting requests."
659 catgets TEMP_MESG_STRING $CAT_ID 1 270 "Number of copies must be a positive number."
666 if (( $failure_flag == $NO_PRINTER_AVAILABLE ))
668 CAT_MESG_STRING="${TEMP_MESG_STRING}"
670 CAT_MESG_STRING="${CAT_MESG_STRING}""
676 XCOMM #################################################################
677 XCOMM ## DisplayErrorMessage()
679 XCOMM ## We have detected an error. Write out a message to
680 XCOMM ## that effect.
682 XCOMM #################################################################
683 DisplayErrorMessage()
685 catgets CAT_MESG_STRING $CAT_ID 1 130 "Sorry--Unable to print:"
687 GetErrorMessageString
691 print "${CAT_MESG_STRING}"
696 XCOMM #################################################################
697 XCOMM ## PrintEndLog()
699 XCOMM ## Print the end of the log.
701 XCOMM #################################################################
704 if (( $failure_flag == $SUCCESS ))
706 print "...successfully completed."
708 print "...completed unsuccessfully."
713 XCOMM #################################################################
714 XCOMM ## PrintUsage()
716 XCOMM ## Print a usage message.
718 XCOMM #################################################################
721 print "Usage: $COMMAND_NAME [-b <banner_title>] [-d <printer_name>]"
722 print " [-m <print_command>] [-n <copy_count>]"
723 print " [-o <other_options>] [-u <user_filename>]"
724 print " [-a] [-e] [-h] [-i] [-r] [-s] [-v] [-w]"
725 print " <print_file>"
728 print " <banner_title>"
729 print " Specifies the title to put on the banner page."
731 print " <printer_name>"
732 print " Specifies the printer name as known to the lp spooler."
734 print " <print_command>"
735 print " Specifies the command with which to invoke the printer."
737 print " <copy_count>"
738 print " Specifies the number of copies to print."
740 print " <other_options>"
741 print " Specifies the other print options."
743 print " <user_filename>"
744 print " Specifies the title of the file to display to the user."
747 print " Formats the file with "man" before printing."
750 print " Removes the file after printing."
753 print " Displays this help message."
756 print " Requests the spooler to sent mail to the user when the print job is completed."
759 print " Formats the file with "pr -f" before printing."
762 print " Prints silently (no dialog box)."
765 print " Directs verbose messages to standard output."
768 print " Prints the data raw (uninterpreted)."
770 print " <print_file>"
771 print " Specifies the name of file(s) to print."
775 XCOMM #################################################################
778 XCOMM ## All exits should go through this routine.
780 XCOMM #################################################################
786 XCOMM ################# GUI Callbacks ####################
788 XCOMM #################################################################
789 XCOMM ## PrintHelpCB()
791 XCOMM ## This is the callback for the Help button in the Print dialog;
792 XCOMM ## it will post a help dialog.
794 XCOMM #################################################################
797 DtkshDisplayQuickHelpDialog "dtlp_help" HELP_TYPE_TOPIC \
798 "Printmgr" "dtlpPrintDialog"
801 XCOMM #################################################################
802 XCOMM ## DoParameterCollection()
804 XCOMM ## Gathers and validates print options set using the command line
805 XCOMM ## and the Print dialog.
807 XCOMM #################################################################
808 DoParameterCollection()
810 catgets CAT_MESG_STRING $CAT_ID 1 10 "Default"
812 GetCurrentPrinterName
814 if (( $failure_flag != $SUCCESS ))
816 DisplayErrorMessageDialog
820 if [[ ("$printer_name" != "") && "$printer_name" != "$CAT_MESG_STRING" ]]
822 LPOPTIONS="-d"$printer_name
826 HASH Get current value from textfield resource rather than from position
827 HASH resource because the user may have changed the value using the former
828 HASH instead of the up/down arrow.
830 HASH We must make sure the value is a positive integer in this case.
832 XtGetValues $COPIES_SB textField:COPIES_TF
833 XmTextFieldGetString copy_val $COPIES_TF
835 CheckIsPosInteger $copy_val
836 if (( $failure_flag == $NOT_POS_INTEGER ))
838 DisplayErrorMessageDialog
844 HASH Strip any leading or trailing spaces
845 HASH This should be validated, to make sure it is a valid integer.
846 copy_count=${copy_count##+( )}
847 copy_count=${copy_count%%+( )}
848 if [ "$copy_count" != "" ] ; then
850 LPOPTIONS=${LPOPTIONS}" -n$copy_count"
853 XmTextGetString banner_title $BANNER_TF
855 HASH Strip any leading or trailing spaces
856 banner_title=${banner_title##+( )}
857 banner_title=${banner_title%%+( )}
858 if [ "$banner_title" != "" ] ; then
860 LPOPTIONS=${LPOPTIONS}" "${MINUS_T}${SINGLE_QUOTE}${banner_title}${SINGLE_QUOTE}
863 XmTextGetString other_options $OPTIONS_TF
865 HASH Strip any leading or trailing spaces
866 other_options=${other_options##+( )}
867 other_options=${other_options%%+( )}
868 if [ "$other_options" != "" ]
870 LPOPTIONS=${LPOPTIONS}" $other_options"
873 XtGetValues $SEND_MAIL_BTN set:send_mail_flag
875 if [[ "$send_mail_flag" == "true" ]]
877 LPOPTIONS=${LPOPTIONS}" -m"
880 if (( $verbose_flag ))
882 echo The LP options are \"${LPOPTIONS}\".
888 XCOMM #################################################################
889 XCOMM ## DestroyDialogs()
891 XCOMM ## Destroys the Select Printer dialog, if it exists, and the
892 XCOMM ## Print dialog.
894 XCOMM #################################################################
897 if [[ "$SELECT_PRINTER_FORM" != "" ]]
899 XtDestroyWidget $(XtParent "-" $SELECT_PRINTER_FORM)
901 XtDestroyWidget $(XtParent "-" $PDIALOG)
904 XCOMM #################################################################
907 XCOMM ## Callback for the Print button in the Print dialog. Submits
908 XCOMM ## print request to lp if all is well; otherwise, simply returns.
910 XCOMM #################################################################
915 DoParameterCollection
916 if [ $? != $SUCCESS ]
926 XCOMM #################################################################
927 XCOMM ## PrintCancelCB()
929 XCOMM ## This is the callback for the Cancel button in the Print dialog.
930 XCOMM ## It will send an empty string to stdout, and will then exit with
931 XCOMM ## a value of -1.
933 XCOMM #################################################################
941 XCOMM #################################################################
942 XCOMM ## UpdatePrinterDescription()
944 XCOMM ## Updates Printer Description in the Print dialog.
946 XCOMM #################################################################
947 UpdatePrinterDescription()
950 if (( $failure_flag != $SUCCESS ))
952 XtSetValues $PRINTER_DESC_LABEL labelString:""
956 GetPrinterInfo $printer_name
957 XtSetValues $PRINTER_DESC_LABEL labelString:"$printer_info"
960 XCOMM #################################################################
961 XCOMM ## SelectPrinterCB()
963 XCOMM ## Callback for the Select Printer button in the Select Printer
964 XCOMM ## dialog. Updates Printer Name and Description in the Print
965 XCOMM ## dialog and unmanages the Select Printer dialog.
967 XCOMM #################################################################
970 XtSetValues $PRINTER_TF value:$selected_printer
971 printer_name=$selected_printer
972 UpdatePrinterDescription
973 XtUnmanageChild $SELECT_PRINTER_FORM
976 XCOMM #################################################################
977 XCOMM ## SelectPrinterHelpCB()
979 XCOMM ## This is the callback for the Help button in the Select Printer
980 XCOMM ## dialog; it will post a help dialog.
982 XCOMM #################################################################
983 SelectPrinterHelpCB()
985 DtkshDisplayQuickHelpDialog "dtlp_help" HELP_TYPE_TOPIC \
986 "Printmgr" "dtlpSelectPrinterDialog"
989 XCOMM #################################################################
990 XCOMM ## ListSelectCB()
992 XCOMM ## Callback for the items in the printer list in the Select Printer
993 XCOMM ## dialog. Updates Printer Information when a printer is selected.
995 XCOMM #################################################################
998 GetPrinterInfo ${CB_CALL_DATA.ITEM}
999 XtSetValues $INFO_TEXT value:"$printer_info"
1000 selected_printer=${CB_CALL_DATA.ITEM}
1003 XCOMM #################################################################
1004 XCOMM ## ListDblSelectCB()
1006 XCOMM ## Callback for the double-clicks on the printer list items in the
1007 XCOMM ## Select Printer dialog. Simulates selection of the Select Printer
1008 XCOMM ## button when a printer item is double-clicked on.
1010 XCOMM #################################################################
1013 if [ ${CB_CALL_DATA.EVENT.TYPE} != KeyPress ]
1015 XtCallCallbacks $SELECT_PRINTER_BTN activateCallback
1019 XCOMM #################################################################
1020 XCOMM ## GetCurrentPrinterName()
1022 XCOMM ## Reads value of Printer Name textfield and strips off any
1023 XCOMM ## leading and trailing spaces.
1025 XCOMM #################################################################
1026 GetCurrentPrinterName()
1028 XmTextFieldGetString printer_name $PRINTER_TF
1030 HASH Strip any leading or trailing spaces
1031 printer_name=${printer_name##+( )}
1032 printer_name=${printer_name%%+( )}
1035 XCOMM #################################################################
1036 XCOMM ## GetAvailPrinters()
1038 XCOMM ## Gets the list of enabled printers.
1040 XCOMM #################################################################
1043 typeset -i num_printers=0
1047 HASH get a sorted list of all enabled printers
1049 tmpfile=$DTLPDIR/printers$$
1051 #if defined(__osf__)
1052 LANG=C lpstat -p | \
1054 '/^.*:/ { PTRNAME = $1; QUEUING = 0 } \
1055 /^Queuing is enabled/ { QUEUING = 1 } \
1056 /^Printing is enabled/ {if (QUEUING == 1) print PTRNAME}' | \
1057 sort | uniq > $tmpfile 2>&1
1059 LANG=C lpstat -p | \
1060 grep READY | cut -f1 -d" " | \
1061 sort | uniq > $tmpfile 2>&1
1062 #elif defined(__uxp__)
1063 LANG=C lpstat -p | \
1064 grep enabled | cut -f4 -d" " | \
1065 sort | uniq > $tmpfile 2>&1
1067 LANG=C lpstat -p | \
1068 grep enabled | cut -f2 -d" " | \
1069 sort | uniq > $tmpfile 2>&1
1072 if [ -s "$tmpfile" ]
1074 for i in `cat $tmpfile`
1076 printer_items=`echo $printer_items$comma$i`
1078 ((num_printers=num_printers+1))
1084 XCOMM #################################################################
1085 XCOMM ## GetPrinterInfo()
1087 XCOMM ## Gets the printer description.
1089 XCOMM #################################################################
1096 lpstat -p$1 > $t1 2>/dev/null
1097 lpstat -p$1 -D > $t2 2>/dev/null
1098 printer_info="`diff $t1 $t2 | sed -e '1d' -e 's/\(.*\)://'`"
1105 XCOMM #################################################################
1106 XCOMM ## SelectPrinterProc()
1108 XCOMM ## This is called when the Select Printer... button in the Print
1109 XCOMM ## dialog is selected. It posts the Select Printer dialog.
1111 XCOMM #################################################################
1114 if [[ "$SELECT_PRINTER_FORM" != "" ]]
1117 HASH dialog already exists, update printer info. if necessary
1119 GetCurrentPrinterName
1121 HASH get index of printer in the list
1122 XmListItemPos index $PRINTER_LIST $printer_name
1125 HASH If printer is in the list, select it and display info. on it;
1126 HASH otherwise, just re-manage the dialog.
1130 GetPrinterInfo $printer_name
1132 HASH display printer information and select the printer specified in
1133 HASH the Printer Name textfield
1135 XmTextSetString $INFO_TEXT "$printer_info"
1136 XmListSelectItem $PRINTER_LIST $printer_name true
1137 XmListSetPos $PRINTER_LIST $index
1140 XtManageChild $SELECT_PRINTER_FORM
1146 XmCreateFormDialog SELECT_PRINTER_FORM $TOPLEVEL form
1148 catgets CAT_MESG_STRING $CAT_ID 1 180 "Select Printer"
1150 XmInternAtom DEL_ATOM $DISPLAY WM_DELETE_WINDOW false
1151 XmAddWMProtocolCallback $(XtParent "-" $SELECT_PRINTER_FORM) \
1152 $DEL_ATOM SelectPrinterCancelCB
1154 XtSetValues $(XtParent "-" $SELECT_PRINTER_FORM) \
1155 title:"$CAT_MESG_STRING" \
1156 allowShellResize:False \
1157 deleteResponse:DO_NOTHING
1159 XtSetValues $SELECT_PRINTER_FORM \
1161 autoUnmanage:False \
1162 helpCallback:SelectPrinterHelpCB
1164 XmCreateWorkArea WORK_AREA $SELECT_PRINTER_FORM work_area \
1165 orientation:XmVERTICAL
1167 XmCreateWorkArea LIST_RC $WORK_AREA list_rc orientation:XmHORIZONTAL
1169 catgets CAT_MESG_STRING $CAT_ID 1 190 "Available Printers:"
1171 XmCreateLabelGadget LIST_LABEL $LIST_RC list_label \
1172 labelString:"$CAT_MESG_STRING"
1173 XtManageChild $LIST_LABEL
1175 XmCreateScrolledList PRINTER_LIST $LIST_RC printer_list \
1176 selectionPolicy:XmSINGLE_SELECT \
1177 singleSelectionCallback:ListSelectCB \
1178 defaultActionCallback:ListDblSelectCB \
1179 itemCount:$num_printers \
1180 items:$printer_items \
1182 XtManageChild $PRINTER_LIST
1184 XmCreateWorkArea INFO_RC $WORK_AREA info_rc orientation:XmVERTICAL
1186 catgets CAT_MESG_STRING $CAT_ID 1 200 "Printer Information:"
1188 XmCreateLabelGadget INFO_LABEL $INFO_RC info_label \
1189 labelString:"$CAT_MESG_STRING"
1190 XtManageChild $INFO_LABEL
1193 XmCreateScrolledText INFO_TEXT $INFO_RC info_text \
1194 editMode:XmMULTI_LINE_EDIT \
1195 value:"$printer_info" \
1201 XmCreateSeparator BTN_SEP $SELECT_PRINTER_FORM sep \
1202 separatorType:XmSHADOW_ETCHED_IN \
1203 $(DtkshUnder $WORK_AREA 4) \
1206 catgets CAT_MESG_STRING $CAT_ID 1 180 "Select Printer"
1208 XmCreatePushButtonGadget SELECT_PRINTER_BTN $SELECT_PRINTER_FORM \
1210 labelString:"$CAT_MESG_STRING" \
1211 $(DtkshUnder $BTN_SEP 5) \
1212 $(DtkshFloatLeft 10) \
1213 $(DtkshFloatRight 30) \
1214 $(DtkshAnchorBottom 5)
1216 XtAddCallback $SELECT_PRINTER_BTN activateCallback "SelectPrinterCB"
1218 catgets CAT_MESG_STRING $CAT_ID 1 110 "Cancel"
1220 XmCreatePushButtonGadget CANCEL_BTN $SELECT_PRINTER_FORM cancel_button \
1221 labelString:"$CAT_MESG_STRING" \
1222 $(DtkshUnder $BTN_SEP 5) \
1223 $(DtkshFloatLeft 40) \
1224 $(DtkshFloatRight 60) \
1225 $(DtkshAnchorBottom 5)
1227 XtAddCallback $CANCEL_BTN activateCallback "SelectPrinterCancelCB"
1229 catgets CAT_MESG_STRING $CAT_ID 1 120 "Help"
1231 XmCreatePushButtonGadget HELP_BTN $SELECT_PRINTER_FORM help_button \
1232 labelString:"$CAT_MESG_STRING" \
1233 $(DtkshUnder $BTN_SEP 5) \
1234 $(DtkshFloatLeft 70) \
1235 $(DtkshFloatRight 90) \
1236 $(DtkshAnchorBottom 5)
1238 XtAddCallback $HELP_BTN activateCallback "SelectPrinterHelpCB"
1240 XtSetValues $SELECT_PRINTER_FORM \
1241 initialFocus:$SELECT_PRINTER_BTN \
1242 defaultButton:$SELECT_PRINTER_BTN \
1243 cancelButton:$CANCEL_BTN \
1244 navigationType:EXCLUSIVE_TAB_GROUP
1246 XtManageChild $BTN_SEP
1247 XtManageChild $SELECT_PRINTER_BTN
1248 XtManageChild $CANCEL_BTN
1249 XtManageChild $HELP_BTN
1250 XtManageChild $INFO_TEXT
1251 XtManageChild $LIST_RC
1252 XtManageChild $INFO_RC
1253 XtManageChild $WORK_AREA
1254 XtManageChild $SELECT_PRINTER_FORM
1256 if (( $num_printers ))
1258 GetCurrentPrinterName
1260 if (( $failure_flag == $SUCCESS ))
1262 GetPrinterInfo $printer_name
1264 HASH display printer information and select the printer specified in
1265 HASH the Printer Name textfield
1267 XmTextSetString $INFO_TEXT "$printer_info"
1268 XmListSelectItem $PRINTER_LIST $printer_name true
1269 XmListSetItem $PRINTER_LIST $printer_name
1273 HASH no available printer, desensitize Select Printer button in
1274 HASH the Select Printer dialog
1276 XtSetSensitive $SELECT_PRINTER_BTN false
1277 failure_flag=$NO_PRINTER_AVAILABLE
1278 DisplayErrorMessageDialog
1282 XCOMM #################################################################
1283 XCOMM ## SelectPrinterCancelCB()
1285 XCOMM ## Callback for the Cancel button in Select Printer dialog.
1286 XCOMM ## It simply unmanages the dialog.
1288 XCOMM #################################################################
1289 SelectPrinterCancelCB()
1291 XtUnmanageChild $SELECT_PRINTER_FORM
1294 XCOMM #################################################################
1295 XCOMM ## PrinterNameFocusCB()
1297 XCOMM ## Focus callback for the Printer Name textfield to determine when
1298 XCOMM ## a printer name is changed so that printer description is updated
1299 XCOMM ## when the user changes the printer name in the Print dialog.
1301 XCOMM #################################################################
1302 PrinterNameFocusCB()
1304 HASH If Printer Name textfield gained focus, save the current printer name.
1305 HASH When it loses focus, compare the saved printer name with the new one
1306 HASH to determine if the user has changed it. If so, update the printer
1308 if [ ${CB_CALL_DATA.REASON} = CR_FOCUS ]
1310 GetCurrentPrinterName
1311 old_printer=$printer_name
1313 if [ ${CB_CALL_DATA.REASON} = CR_LOSING_FOCUS ]
1315 GetCurrentPrinterName
1316 if [ "$old_printer" != "$printer_name" ]
1318 UpdatePrinterDescription
1324 XCOMM #################################################################
1327 XCOMM ## Creates the Print dialog and sets up the callbacks.
1329 XCOMM #################################################################
1332 catgets CAT_MESG_STRING $CAT_ID 1 10 "Default"
1334 if (( $printer_name_flag ))
1336 printer=$printer_name
1339 if (( $failure_flag == $SUCCESS ))
1341 printer=$default_printer
1342 printer_name=$default_printer
1344 printer=$CAT_MESG_STRING
1348 if [[ "$printer_name" != "" ]]
1350 GetPrinterInfo $printer_name
1355 DtCreatePrintSetupDialog PDIALOG $TOPLEVEL pdialog \
1356 printCallback:PrintCB \
1357 cancelCallback:PrintCancelCB \
1358 helpCallback:PrintHelpCB \
1359 selectPrinterProc:SelectPrinterProc \
1360 workAreaLocation:DtWORK_AREA_TOP_AND_BOTTOM \
1361 printSetupMode:DtPRINT_SETUP_PLAIN \
1362 printDestination:DtPRINT_TO_PRINTER \
1363 printerName:"$printer" \
1364 description:"$printer_info"
1366 catgets CAT_MESG_STRING $CAT_ID 1 20 "Print"
1368 XmInternAtom DEL_ATOM $DISPLAY WM_DELETE_WINDOW false
1369 XmAddWMProtocolCallback $(XtParent "-" $PDIALOG) $DEL_ATOM PrintCancelCB
1371 XtSetValues $(XtParent "-" $PDIALOG) \
1372 title:"$CAT_MESG_STRING" \
1373 allowShellResize:False \
1374 deleteResponse:DO_NOTHING
1376 XtSetValues $PDIALOG autoUnmanage:False
1378 XmCreateWorkArea FILE_NAME_RC $PDIALOG file_name_rc \
1381 orientation:XmHORIZONTAL
1383 catgets CAT_MESG_STRING $CAT_ID 1 170 "File Name(s): "
1385 XmCreateLabel FILE_NAME_LABEL $FILE_NAME_RC file_name_label \
1386 labelString:"$CAT_MESG_STRING"
1388 if (( $user_filename_flag ))
1390 LABEL_STRING="${user_filename}"
1392 LABEL_STRING="${print_file}"
1394 XmCreateLabel FILE_NAME $FILE_NAME_RC file_name \
1395 labelString:"$LABEL_STRING"
1397 XtManageChild $FILE_NAME_RC
1398 XtManageChild $FILE_NAME_LABEL
1399 XtManageChild $FILE_NAME
1403 HASH Unmanage unneeded widgets
1405 XtNameToWidget TOP_SEP $PDIALOG "TopWorkAreaSeparator"
1406 XtUnmanageChild $TOP_SEP
1408 XtNameToWidget INFO_BTN $PDIALOG "Info"
1409 XtUnmanageChild $INFO_BTN
1411 XtNameToWidget SELECT_FILE_BTN $PDIALOG "SelectFile"
1412 XtUnmanageChild $SELECT_FILE_BTN
1414 XtNameToWidget SETUP_BTN $PDIALOG "Setup"
1415 XtUnmanageChild $SETUP_BTN
1417 DtCreatePDMJobSetup JOB $PDIALOG
1420 HASH Get widget handles
1422 XtNameToWidget PRINTER_COMBO $PDIALOG "Name"
1423 XtNameToWidget PRINTER_TF $PRINTER_COMBO "Text"
1424 XtNameToWidget PRINTER_DESC_LABEL $PDIALOG "Description"
1425 XtNameToWidget COPIES_SB $PDIALOG "*Copies"
1426 XtNameToWidget SEND_MAIL_CB $JOB "*SendMail"
1427 XtNameToWidget BANNER_TF $JOB "*Banner"
1428 XtNameToWidget OPTIONS_TF $JOB "*Options"
1429 XtNameToWidget SEND_MAIL_BTN $SEND_MAIL_CB "button_0"
1430 XtNameToWidget PRINT_BTN $PDIALOG "Print"
1431 XtNameToWidget PRINT_CANCEL_BTN $PDIALOG "Cancel"
1434 HASH move cursor to end of printer name
1436 XtSetValues $PRINTER_TF cursorPosition:${#PRINTER}
1439 HASH set focus callbacks to track printer name changes
1441 XtAddCallback $PRINTER_TF focusCallback "PrinterNameFocusCB"
1442 XtAddCallback $PRINTER_TF losingFocusCallback "PrinterNameFocusCB"
1445 HASH initialize SELECT_PRINTER_FORM to be used in SelectPrinterProc
1446 HASH to determine if the Select Printer dialog already exists.
1448 SELECT_PRINTER_FORM=""
1450 if (( $banner_title_flag ))
1452 XtSetValues $BANNER_TF value:"$banner_title"
1454 if (( $other_options_flag ))
1456 XtSetValues $OPTIONS_TF value:"$other_options"
1459 XtManageChild $PDIALOG
1461 if (( $copy_count_flag ))
1463 XtSetValues $COPIES_SB position:$copy_count
1466 if [[ "$send_mail_flag" == "true" ]]
1468 XtSetValues $SEND_MAIL_BTN set:true
1471 XtGetValues $COPIES_SB textField:COPIES_TF
1473 DtkshSetReturnKeyControls $PRINTER_TF $COPIES_TF $PDIALOG $PRINT_BTN
1474 DtkshSetReturnKeyControls $COPIES_TF $BANNER_TF $PDIALOG $PRINT_BTN
1475 DtkshSetReturnKeyControls $BANNER_TF $OPTIONS_TF $PDIALOG $PRINT_BTN
1481 XCOMM #################################################################
1482 XCOMM ## BadFileCB()
1484 XCOMM ## This is the callback for the OK button in the error message
1485 XCOMM ## dialog and is used when the file to print is invalid. It will
1486 XCOMM ## exit the program.
1488 XCOMM #################################################################
1494 XCOMM #################################################################
1495 XCOMM ## ErrorDialogCB()
1497 XCOMM ## This is the callback for the OK button in the error message
1498 XCOMM ## dialog and is used for non-fatal error messages. It simply
1499 XCOMM ## destroys the message dialog.
1501 XCOMM #################################################################
1504 XtDestroyWidget $INFORMATION
1507 XCOMM #################################################################
1508 XCOMM ## DisplayErrorMessageDialog()
1510 XCOMM ## We have detected an error. Post a dialog to that effect.
1512 XCOMM ## Upon entry, check the failure_flag value for the proper
1513 XCOMM ## message to print.
1515 XCOMM #################################################################
1516 DisplayErrorMessageDialog()
1518 XmCreateErrorDialog INFORMATION $TOPLEVEL information
1520 catgets CAT_MESG_STRING $CAT_ID 1 160 "Print Information"
1522 XtSetValues $(XtParent "-" $INFORMATION) title:"$CAT_MESG_STRING"
1524 GetErrorMessageString
1526 if (($failure_flag == $NO_FILE_ERR )) ||
1527 (( $failure_flag == $NO_REGULAR_FILE_ERR )) ||
1528 (( $failure_flag == $NO_READABLE_FILE_ERR ))
1530 bad_file_flag=$failure_flag
1536 XtSetValues $INFORMATION \
1538 messageString:"${CAT_MESG_STRING}" \
1540 defaultButtonType:DIALOG_OK_BUTTON \
1541 dialogStyle:DIALOG_FULL_APPLICATION_MODAL \
1542 messageAlignment:ALIGNMENT_CENTER
1544 XtUnmanageChild $(XmMessageBoxGetChild "-" $INFORMATION \
1545 DIALOG_CANCEL_BUTTON)
1547 XtUnmanageChild $(XmMessageBoxGetChild "-" $INFORMATION \
1550 XtManageChild $INFORMATION
1556 XCOMM #################################################################
1559 XCOMM ## Set up and call either the silent or the GUI routines.
1562 XCOMM #################################################################
1566 while getopts b:d:m:n:o:u:aehirsvw argument
1571 b) banner_title=$OPTARG
1574 d) printer_name=$OPTARG
1582 i) send_mail_flag=true
1584 m) print_command=$OPTARG
1585 print_command_flag=1
1587 n) copy_count=$OPTARG
1590 o) other_options=$OPTARG
1591 other_options_flag=1
1597 u) user_filename=$OPTARG
1598 user_filename_flag=1
1610 ((shift_positions = OPTIND - 1))
1614 if (( $shift_positions < $# ))
1617 XCOMM We have at least one remaining non-switch command line argument
1619 shift $shift_positions
1621 HASH We assume that any remaining arguments constitute the filename.
1622 HASH At some later point, may want to parse a list of filenames.
1629 nw=`echo $1 | wc -w`
1637 if [ "" = "$print_file" ]
1641 print_file="$print_file $file"
1650 XCOMM make sure copy_count is a positive integer
1652 if (( $copy_count_flag ))
1654 CheckIsPosInteger $copy_count
1655 if (( $failure_flag != $SUCCESS ))
1663 XCOMM Make sure all these settings line up consistently.
1667 if (( $verbose_flag ))
1673 XCOMM Do we have enough information to do our job?
1674 XCOMM This step may cause us to exit.
1678 XCOMM Have we been given a valid file(s)?
1683 CheckValidFile "${files[$i]}"
1685 if (( $failure_flag != $SUCCESS ))
1687 print_file="\"${files[$i]}\""
1693 if (( $silent_flag ))
1695 if (( $failure_flag == $SUCCESS ))
1699 if (( $failure_flag != $SUCCESS ))
1705 DoParameterCollectionSilent
1714 if [[ -r CDE_INSTALLATION_TOP/lib/dtksh/DtFuncs.dtsh ]]
1716 . CDE_INSTALLATION_TOP/lib/dtksh/DtFuncs.dtsh
1719 echo Sorry--cannot find initialization file.
1720 Exit $NO_INIT_FILE_ERR
1723 XtInitialize TOPLEVEL printerConfig Dtlp "${@:-}"
1724 XtDisplay DISPLAY $TOPLEVEL
1726 if (( $failure_flag == $SUCCESS ))
1730 DisplayErrorMessageDialog
1735 XCOMM Never reached.
1737 XCOMM #################### eof ##############################