Link with C++ linker
[oweals/cde.git] / cde / programs / dtprintegrate / dtlp.src
1 XCOMM!/usr/dt/bin/dtksh
2 XCOMM $TOG: dtlp.src /main/17 1998/07/31 17:03:31 mgreess $
3 XCOMM 
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.
11
12 #define HASH #
13
14 XCOMM ###################################################################
15 XCOMM
16 XCOMM  File:              dtlp
17 XCOMM
18 XCOMM  Default Location:  /usr/dt/bin/dtlp
19 XCOMM
20 XCOMM  Purpose:           Set up print spooler options and print.
21 XCOMM
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".
26 XCOMM
27 XCOMM  Invoked by:        The default Print action or custom print actions.
28 XCOMM
29 XCOMM  Product:           @(#)Common Desktop Environment 1.0          
30 XCOMM
31 XCOMM  Note:              Please do not modify this file.
32 XCOMM                     Later product updates will overwrite this file.
33 XCOMM
34 XCOMM ###################################################################
35 set -u
36
37 XCOMM #################################################################
38 XCOMM
39 XCOMM  Following are the environmental options we support
40 XCOMM
41 XCOMM #################################################################
42
43 XCOMM LPDEST
44 XCOMM DTPRINTCWD
45 XCOMM DTPRINTFILEREMOVE
46 XCOMM DTPRINTSILENT
47 XCOMM DTPRINTTESTOUTPUT
48 XCOMM DTPRINTUSERFILENAME
49
50 XCOMM #################################################################
51 XCOMM ##  Internal Globals
52 XCOMM ##
53 XCOMM ##  Actually, most variables in this script are global.
54 XCOMM ##
55 XCOMM ##  Most are defined in the Initialize() routine.
56 XCOMM ##
57 XCOMM #################################################################
58 COMMAND_NAME=dtlp
59
60 PATH=/bin:/usr/bin:/usr/ucb
61 export PATH
62
63 XCOMM
64 XCOMM Exit/Return codes
65 XCOMM
66 CANCEL_EXIT=-1
67 SUCCESS=0
68 NO_PRINT_MESSAGE=1
69 USAGE_EXIT=2
70 NO_FILE_ERR=3
71 NO_INIT_FILE_ERR=4
72 NO_REGULAR_FILE_ERR=5
73 NO_READABLE_FILE_ERR=6
74 NO_DEFAULT_PRINTER=7
75 PRINTER_DOES_NOT_EXIST=8
76 PRINTER_NOT_ENABLED=9
77 NO_PRINTER_AVAILABLE=10
78 PRINTER_NOT_ACCEPT_REQ=11
79 NOT_POS_INTEGER=12
80
81 XCOMM
82 XCOMM For string processing
83 XCOMM
84 DOUBLE_QUOTE=\"
85 SINGLE_QUOTE=\'
86 MINUS_T="-t"
87
88 XCOMM #################################################################
89 XCOMM ##  Initialize()
90 XCOMM ##
91 XCOMM ##         Set a number of key variables to their defaults.
92 XCOMM ##
93 XCOMM ##         Examples
94 XCOMM ##         ----------------------
95 XCOMM ##            File to print:                     Stdin
96 XCOMM ##            Number of copies:                  1
97 XCOMM ##            Print Command:                     lp
98 XCOMM ##
99 XCOMM #################################################################
100 Initialize()
101 {
102     typeset -u Uppercase_string
103
104     Uppercase_string=""
105
106     banner_title_flag=0
107     banner_title=""
108
109     copy_count_flag=0
110     copy_count=1
111
112     failure_flag=$SUCCESS
113
114     format_flag=0
115
116     other_options_flag=0
117     other_options=""
118
119     print_command_flag=0
120     print_command=lp
121
122     print_cwd_flag=0
123     print_cwd=""
124
125     HASH
126     HASH Assume print file is stdin, unless told otherwise...
127     HASH
128     print_file_flag=1
129     print_file="-"
130
131     print_page_allowed=1
132
133     print_man_flag=0
134     print_man=""
135
136     printer_name_flag=0
137     printer_name=""
138
139     print_raw_flag=0
140
141     remove_flag=0
142
143     send_mail_flag=false
144
145     silent_flag=0
146
147     test_flag=0
148     test_output_file=""
149
150     verbose_flag=0
151
152     user_filename_flag=0
153     user_filename=""
154
155     CAT_MESG_STRING=""
156
157     HASH
158     HASH directory for temporary files used by dtlp
159     HASH
160     DTLPDIR="$HOME/.dt/tmp"
161
162     if [ ! -d "$DTLPDIR" ]
163     then
164         mkdir -p "$DTLPDIR"
165     fi
166
167     LPOPTIONS=""
168
169     catopen CAT_ID $COMMAND_NAME
170
171     SetPreEnvironment
172
173 }
174
175 XCOMM #################################################################
176 XCOMM ##  SetPreEnvironment()
177 XCOMM ##
178 XCOMM ##         Check the ENVIRONMENT values we care about, and
179 XCOMM ##         set the corresponding internal variable values.
180 XCOMM ##
181 XCOMM #################################################################
182 SetPreEnvironment()
183 {
184     if (( ${#LPDEST} ))
185     then
186         printer_name=$LPDEST
187         printer_name_flag=1
188     fi
189
190     if (( ${#DTPRINTCWD} ))
191     then
192         print_cwd=$DTPRINTCWD
193         print_cwd_flag=1
194     fi
195
196     if (( ${#DTPRINTFILEREMOVE} ))
197     then
198         HASH check for True
199         Uppercase_string=$DTPRINTFILEREMOVE
200         if [[ "$Uppercase_string" = "TRUE" ]]
201         then
202             remove_flag=1
203         fi
204         Uppercase_string=""
205     fi
206
207     if (( ${#DTPRINTSILENT} ))
208     then
209         HASH check for True
210         Uppercase_string=$DTPRINTSILENT
211         if [[ "$Uppercase_string" = "TRUE" ]]
212         then
213             silent_flag=1
214         fi
215         Uppercase_string=""
216     fi
217
218     if (( ${#DTPRINTUSERFILENAME} ))
219     then
220         user_filename=$DTPRINTUSERFILENAME
221         user_filename_flag=1
222     fi
223
224     if (( ${#DTPRINTTESTOUTPUT} ))
225     then
226         test_output_file=$DTPRINTTESTOUTPUT
227         test_flag=1
228     fi
229
230 }
231
232 XCOMM #################################################################
233 XCOMM ##  ReconcileOptions()
234 XCOMM ##
235 XCOMM ##       Arbitrate when there are two or more conflicting 
236 XCOMM ##       print options.
237 XCOMM ##
238 XCOMM ##       The order of precedence is: -w > -a > -r.
239 XCOMM ##
240 XCOMM #################################################################
241 ReconcileOptions()
242 {
243     HASH
244     HASH The RAW option takes precedence over all others.
245     HASH
246     if (( $print_raw_flag ))
247     then
248         format_flag=0
249         print_man_flag=0
250         print_page_allowed=0
251
252     HASH
253     HASH Next, this MAN option comes into play
254     HASH
255     elif (( $print_man_flag ))
256     then
257         format_flag=0
258         print_page_allowed=0
259     fi
260
261 }
262
263 XCOMM #################################################################
264 XCOMM ##  DoParameterCollectionSilent()
265 XCOMM ##
266 XCOMM ##       Collect the silent lp options, mimicking the GUI
267 XCOMM ##       collection process.
268 XCOMM ##
269 XCOMM #################################################################
270 DoParameterCollectionSilent()
271 {
272     HASH printer_name has to be set at this point so no need to check
273     LPOPTIONS=-d${printer_name}
274
275     if (( $banner_title_flag ))
276     then
277         LPOPTIONS=${LPOPTIONS}" "${MINUS_T}${SINGLE_QUOTE}${banner_title}${SINGLE_QUOTE}
278     fi
279
280     if (( $copy_count_flag ))
281     then
282         LPOPTIONS=${LPOPTIONS}" -n${copy_count}"
283     fi
284
285     if (( $other_options_flag ))
286     then
287         LPOPTIONS=${LPOPTIONS}" ${other_options}"
288     fi
289
290     if [[ "$send_mail_flag" == "true" ]]
291     then
292         LPOPTIONS=${LPOPTIONS}" -m"
293     fi
294
295     if (( $verbose_flag ))
296     then
297         echo Print Command is $print_command and Options are $LPOPTIONS
298     fi
299
300 }
301
302 XCOMM #################################################################
303 XCOMM ##  EchoDtlpSetupOptions()
304 XCOMM ##
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.
309 XCOMM ##
310 XCOMM #################################################################
311 EchoDtlpSetupOptions()
312 {
313     if (( $remove_flag ))
314     then
315         echo Remove file flag is SET.
316     fi
317     if (( $print_man_flag ))
318     then
319         echo Manpage flag is SET.
320     fi
321     if (( $print_raw_flag ))
322     then
323         echo Raw print flag is SET.
324     fi
325     if (( $print_cwd_flag ))
326     then
327         echo Print working directory is $print_cwd.
328     fi
329     if (( $print_page_allowed ))
330     then
331         echo Page printing is allowed.
332     else
333         echo Page printing is NOT allowed.
334     fi
335     if (( $format_flag ))
336     then
337         echo Format flag is SET.
338     fi
339     if (( $silent_flag ))
340     then
341         echo Silent flag is SET.
342     fi
343     if (( $user_filename_flag ))
344     then
345         echo User-visible filename is \"$user_filename\".
346     fi
347     if (( $verbose_flag ))
348     then
349         echo Verbose flag is SET.
350     fi
351     if (( $other_options_flag ))
352     then
353         echo Other options include \"$other_options\".
354     fi
355     if [[ "$send_mail_flag" == "true" ]]
356     then
357         echo Send Mail flag is SET.
358     fi
359     echo Copies is set to $copy_count.
360 }
361
362 XCOMM #################################################################
363 XCOMM ##  PrintIt()
364 XCOMM ##
365 XCOMM ##         Do the actual spooling, based on the value of LPOPTIONS.
366 XCOMM ##
367 XCOMM ##         If possible, log the results.
368 XCOMM #################################################################
369 PrintIt()
370 {
371     if (( $print_cwd_flag )) && [[ (-d "$print_cwd") && (-x "$print_cwd") ]]
372     then
373         cd $print_cwd
374     fi
375
376     if (( $test_flag ))
377     then
378         HASH then don't do any printing--instead log the results
379         EchoDtlpSetupOptions
380         echo ""
381         echo "Command that will be invoked is..."
382         INVOKER='echo'
383     else
384         INVOKER='eval'
385     fi
386
387     if (( $print_raw_flag ))
388     then
389         HASH Nothing special is required for raw mode on this platform.
390         LPOPTIONS="${LPOPTIONS}"
391     fi
392
393     if (( $format_flag ))
394     then
395         HASH set page header
396         if (( $banner_title_flag ))
397         then
398             PAGEHEADER="$banner_title"
399         elif (( $user_filename_flag ))
400         then
401             PAGEHEADER="$user_filename"
402         else
403             PAGEHEADER="$print_file"
404         fi
405
406         $INVOKER "cat $print_file | pr -f -h '${PAGEHEADER}' | ${print_command} ${LPOPTIONS}"
407     elif (( $print_man_flag ))
408     then
409         $INVOKER "cat $print_file | tbl | nroff -man | col | ${print_command} ${LPOPTIONS}"
410
411     else
412         if [ "$print_file" = "-" ]
413         then
414             $INVOKER "cat $print_file | ${print_command} ${LPOPTIONS}"
415         else
416             $INVOKER "${print_command} -c ${LPOPTIONS} $print_file"
417        fi
418     fi
419 }
420
421 XCOMM #################################################################
422 XCOMM ##  CleanUp()
423 XCOMM ##
424 XCOMM ##         End the show
425 XCOMM #################################################################
426 CleanUp()
427 {
428     if (( $remove_flag )) && [[ "$print_file" != "-" ]]
429     then
430         rm -f $print_file >/dev/null 2>&1
431     fi
432
433     if (( $verbose_flag ))
434     then
435         PrintEndLog
436     fi
437 }
438
439 XCOMM #################################################################
440 XCOMM ##
441 XCOMM ##         Ensure that the supplied file name references a
442 XCOMM ##         valid file. 
443 XCOMM ##
444 XCOMM ##         Returns true or false.
445 XCOMM #################################################################
446 CheckValidFile()
447 {
448     if [[ "$1" == "-" ]]
449     then
450         return $SUCCESS
451     fi
452
453     HASH check whether file exists and is a regular file
454     if [[ ! -f "$1" ]] 
455     then
456         return $NO_REGULAR_FILE_ERR
457     fi
458
459     HASH check whether file is readable by the user  
460     if [[ ! -r "$1" ]]
461     then
462         return $NO_READABLE_FILE_ERR
463     fi
464     return $SUCCESS
465 }
466
467 XCOMM #################################################################
468 XCOMM ##  CheckValidPrinter()
469 XCOMM ##
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.
473 XCOMM ##
474 XCOMM ##         Returns true or false.
475 XCOMM #################################################################
476 CheckValidPrinter()
477 {
478     catgets CAT_MESG_STRING $CAT_ID 1 10 "Default"
479
480     if [[ "$printer_name" = "" ]]
481     then
482         printer_name=$CAT_MESG_STRING
483     fi
484
485     if [[ "$printer_name" = "$CAT_MESG_STRING" ]]
486     then
487         GetDefaultPrinter
488         if (( $failure_flag == $SUCCESS ))
489         then
490             printer_name=$default_printer
491         else
492             return $failure_flag
493         fi
494     fi
495
496     tmpfile=$DTLPDIR/$printer_name$$
497     LANG=C lpstat -p$printer_name > $tmpfile 2>&1
498     if [[ $? != $SUCCESS ]]
499     then
500         HASH printer does not exist
501         failure_flag=$PRINTER_DOES_NOT_EXIST
502         rm -f $tmpfile
503         return $failure_flag
504     else
505         grep disabled $tmpfile > /dev/null 2>&1
506         if [ $? -eq 0 ]
507         then
508             failure_flag=$PRINTER_NOT_ENABLED
509             rm -f $tmpfile
510             return $failure_flag
511         else
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
516             if [ $? -eq 0 ]
517             then
518                 failure_flag=$PRINTER_NOT_ACCEPT_REQ
519                 rm -f $status
520                 return $failure_flag
521             fi
522             rm -f $status
523         fi
524     fi
525     rm -f $tmpfile
526
527     failure_flag=$SUCCESS
528     return $failure_flag
529 }
530
531 XCOMM #################################################################
532 XCOMM ##  GetDefaultPrinter()
533 XCOMM ##
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.
537 XCOMM ##
538 XCOMM #################################################################
539 GetDefaultPrinter()
540 {
541 #if defined(_AIX)
542     prfld=1
543     flddelim=' '
544 #elif defined(__uxp__)
545     prfld=5
546     flddelim=':'
547 #else
548     prfld=2
549     flddelim=':'
550 #endif
551
552     default_printer=""
553     if (( ${#LPDEST} ))
554     then
555         default_printer=$LPDEST
556     else
557 #if defined(_AIX)
558         t1="`LANG=C lpstat -d | head -3 | tail -1`"
559 #else
560         t1="`LANG=C lpstat -d`"
561 #endif
562         t2="`echo $t1 | cut -d' ' -f1`"
563         HASH
564         HASH "no system default destination" is expected if no default is defined;
565         HASH otherwise, "system default destination: <printer_name>" is expected.
566         HASH
567         if [[ "$t2" != "no" ]]
568         then
569             default_printer="`echo $t1 | cut -f$prfld -d"$flddelim"`"
570             HASH remove leading space
571             default_printer=${default_printer##+( )}
572         fi
573
574         if [[ "$default_printer" = "" ]]
575         then
576             failure_flag=$NO_DEFAULT_PRINTER
577             return $failure_flag
578         fi
579     fi
580     failure_flag=$SUCCESS
581     return $failure_flag
582 }
583
584
585 XCOMM #################################################################
586 XCOMM ##  PrintStartLog()
587 XCOMM ##
588 XCOMM ##         Print the start of the log
589 XCOMM ##
590 XCOMM #################################################################
591 PrintStartLog() {
592     print "$COMMAND_NAME..."
593     print ""
594 }
595
596 XCOMM #################################################################
597 XCOMM ##  CheckIsPosInteger()
598 XCOMM ##
599 XCOMM ##  Checks whether a given value is a positive integer.
600 XCOMM ##
601 XCOMM #################################################################
602 CheckIsPosInteger()
603 {
604     val=$1
605     HASH Strip any leading or trailing spaces
606     val=${val##+( )}
607     val=${val%%+( )}
608
609     if [[ ${#val} && "$val" = +([0-9]) ]]
610     then
611         failure_flag=$SUCCESS
612     else
613         failure_flag=$NOT_POS_INTEGER
614     fi
615     return $failure_flag
616 }
617
618 XCOMM #################################################################
619 XCOMM ##  GetErrorMessageString()
620 XCOMM ##
621 XCOMM ##  Looks up the appropriate error message based on the value of
622 XCOMM ##  failure_flag.
623 XCOMM ##
624 XCOMM #################################################################
625 GetErrorMessageString()
626 {
627     catgets CAT_MESG_STRING $CAT_ID 1 130 "Sorry--Unable to print:"
628
629     if (( $user_filename_flag ))
630     then
631         CAT_MESG_STRING=${CAT_MESG_STRING}"  \"$user_filename\"."
632     else
633         CAT_MESG_STRING=${CAT_MESG_STRING}"  \"$print_file\"."
634     fi
635
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."
639         ;;
640       $NO_READABLE_FILE_ERR)
641         catgets TEMP_MESG_STRING $CAT_ID 1 134 "You don't have permission to read that file."
642         ;;
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."
645         ;;
646       $PRINTER_DOES_NOT_EXIST)
647         catgets TEMP_MESG_STRING $CAT_ID 1 230 "The printer does not exist."
648         ;;
649       $PRINTER_NOT_ENABLED)
650         catgets TEMP_MESG_STRING $CAT_ID 1 240 "The printer is not enabled."
651         ;;
652       $NO_DEFAULT_PRINTER)
653         catgets TEMP_MESG_STRING $CAT_ID 1 250 "There is no default printer destination."
654         ;;
655       $PRINTER_NOT_ACCEPT_REQ)
656         catgets TEMP_MESG_STRING $CAT_ID 1 260 "The printer is currently not accepting requests."
657         ;;
658       $NOT_POS_INTEGER)
659         catgets TEMP_MESG_STRING $CAT_ID 1 270 "Number of copies must be a positive number."
660         ;;
661       *)
662         echo ""
663         ;;
664     esac
665
666     if (( $failure_flag == $NO_PRINTER_AVAILABLE ))
667     then
668     CAT_MESG_STRING="${TEMP_MESG_STRING}"
669     else
670     CAT_MESG_STRING="${CAT_MESG_STRING}""
671     ${TEMP_MESG_STRING}"
672     fi
673
674 }
675
676 XCOMM #################################################################
677 XCOMM ##  DisplayErrorMessage()
678 XCOMM ##
679 XCOMM ##         We have detected an error. Write out a message to
680 XCOMM ##         that effect.
681 XCOMM ##
682 XCOMM #################################################################
683 DisplayErrorMessage()
684 {
685     catgets CAT_MESG_STRING $CAT_ID 1 130 "Sorry--Unable to print:"
686
687     GetErrorMessageString
688
689     print ""
690     print `date`
691     print "${CAT_MESG_STRING}"
692     print ""
693 }
694
695
696 XCOMM #################################################################
697 XCOMM ##  PrintEndLog()
698 XCOMM ##
699 XCOMM ##         Print the end of the log.
700 XCOMM ##
701 XCOMM #################################################################
702 PrintEndLog() {
703     print ""
704     if (( $failure_flag == $SUCCESS ))
705     then
706         print "...successfully completed."
707     else
708         print "...completed unsuccessfully."
709     fi
710     print ""
711 }
712
713 XCOMM #################################################################
714 XCOMM ##  PrintUsage()
715 XCOMM ##
716 XCOMM ##        Print a usage message.
717 XCOMM ##
718 XCOMM #################################################################
719 PrintUsage() {
720     print ""
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>"
726     print "  where:"
727     print ""
728     print "  <banner_title>"
729     print "      Specifies the title to put on the banner page."
730     print ""
731     print "  <printer_name>"
732     print "      Specifies the printer name as known to the lp spooler."
733     print ""
734     print "  <print_command>"
735     print "      Specifies the command with which to invoke the printer."
736     print ""
737     print "  <copy_count>"
738     print "      Specifies the number of copies to print."
739     print ""
740     print "  <other_options>"
741     print "      Specifies the other print options."
742     print ""
743     print "  <user_filename>"
744     print "      Specifies the title of the file to display to the user."
745     print ""
746     print "  -a"
747     print "      Formats the file with "man" before printing."
748     print ""
749     print "  -e"
750     print "      Removes the file after printing."
751     print ""
752     print "  -h"
753     print "      Displays this help message."
754     print ""
755     print "  -i"
756     print "      Requests the spooler to sent mail to the user when the print job is completed."
757     print ""
758     print "  -r"
759     print "      Formats the file with "pr -f" before printing."
760     print ""
761     print "  -s"
762     print "      Prints silently (no dialog box)."
763     print ""
764     print "  -v"
765     print "      Directs verbose messages to standard output."
766     print ""
767     print "  -w"
768     print "      Prints the data raw (uninterpreted)."
769     print ""
770     print "  <print_file>"
771     print "      Specifies the name of file(s) to print."
772      
773 }
774
775 XCOMM #################################################################
776 XCOMM ##  Exit()
777 XCOMM ##
778 XCOMM ##        All exits should go through this routine.
779 XCOMM ##
780 XCOMM #################################################################
781 Exit()
782 {
783     exit $1
784 }
785
786 XCOMM #################   GUI Callbacks  ####################
787
788 XCOMM #################################################################
789 XCOMM ##  PrintHelpCB()
790 XCOMM ##
791 XCOMM ## This is the callback for the Help button in the Print dialog;
792 XCOMM ## it will post a help dialog.
793 XCOMM ##
794 XCOMM #################################################################
795 PrintHelpCB()
796 {
797     DtkshDisplayQuickHelpDialog "dtlp_help" HELP_TYPE_TOPIC \
798         "Printmgr" "dtlpPrintDialog"
799 }
800
801 XCOMM #################################################################
802 XCOMM ##  DoParameterCollection()
803 XCOMM ##
804 XCOMM ##  Gathers and validates print options set using the command line
805 XCOMM ##  and the Print dialog.
806 XCOMM ##
807 XCOMM #################################################################
808 DoParameterCollection()
809 {
810     catgets CAT_MESG_STRING $CAT_ID 1 10 "Default"
811
812     GetCurrentPrinterName
813     CheckValidPrinter
814     if (( $failure_flag != $SUCCESS ))
815     then
816         DisplayErrorMessageDialog
817         return $failure_flag
818     fi
819
820     if [[ ("$printer_name" != "") && "$printer_name" != "$CAT_MESG_STRING" ]] 
821     then
822         LPOPTIONS="-d"$printer_name
823     fi
824
825     HASH
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.
829     HASH
830     HASH We must make sure the value is a positive integer in this case.
831     HASH
832     XtGetValues $COPIES_SB textField:COPIES_TF 
833     XmTextFieldGetString copy_val $COPIES_TF
834
835     CheckIsPosInteger $copy_val
836     if (( $failure_flag == $NOT_POS_INTEGER ))
837     then
838         DisplayErrorMessageDialog
839         return $failure_flag
840     else
841         copy_count=$copy_val
842     fi
843
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
849         copy_count_flag=1
850         LPOPTIONS=${LPOPTIONS}" -n$copy_count"
851     fi
852
853     XmTextGetString banner_title $BANNER_TF
854
855     HASH Strip any leading or trailing spaces
856     banner_title=${banner_title##+( )}
857     banner_title=${banner_title%%+( )}
858     if [ "$banner_title" != "" ] ; then
859         banner_title_flag=1
860         LPOPTIONS=${LPOPTIONS}" "${MINUS_T}${SINGLE_QUOTE}${banner_title}${SINGLE_QUOTE}
861     fi
862
863     XmTextGetString other_options $OPTIONS_TF 
864
865     HASH Strip any leading or trailing spaces
866     other_options=${other_options##+( )}
867     other_options=${other_options%%+( )}
868     if  [ "$other_options" != "" ]
869     then
870         LPOPTIONS=${LPOPTIONS}" $other_options"
871     fi
872
873     XtGetValues $SEND_MAIL_BTN set:send_mail_flag
874
875     if [[ "$send_mail_flag" == "true" ]]
876     then
877         LPOPTIONS=${LPOPTIONS}" -m"
878     fi
879
880     if (( $verbose_flag ))
881     then
882         echo The LP options are \"${LPOPTIONS}\".
883     fi
884
885     return $SUCCESS
886 }
887
888 XCOMM #################################################################
889 XCOMM ##  DestroyDialogs()
890 XCOMM ##
891 XCOMM ##  Destroys the Select Printer dialog, if it exists, and the
892 XCOMM ##  Print dialog.
893 XCOMM ##
894 XCOMM #################################################################
895 DestroyDialogs()
896 {
897     if [[ "$SELECT_PRINTER_FORM" != "" ]]
898     then
899         XtDestroyWidget $(XtParent "-" $SELECT_PRINTER_FORM)
900     fi
901     XtDestroyWidget $(XtParent "-" $PDIALOG)
902 }
903
904 XCOMM #################################################################
905 XCOMM ##  PrintCB()
906 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.
909 XCOMM ##
910 XCOMM #################################################################
911 PrintCB()
912 {
913     XSync $DISPLAY True
914
915     DoParameterCollection
916     if [ $? != $SUCCESS ]
917     then
918         return
919     fi
920     PrintIt
921     CleanUp
922     DestroyDialogs
923     Exit $failure_flag
924 }
925
926 XCOMM #################################################################
927 XCOMM ##  PrintCancelCB()
928 XCOMM ##
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.
932 XCOMM ##
933 XCOMM #################################################################
934 PrintCancelCB()
935 {
936     echo ""
937     DestroyDialogs
938     Exit $CANCEL_EXIT
939 }
940
941 XCOMM #################################################################
942 XCOMM ##  UpdatePrinterDescription()
943 XCOMM ##
944 XCOMM ##  Updates Printer Description in the Print dialog.
945 XCOMM ##
946 XCOMM #################################################################
947 UpdatePrinterDescription()
948 {
949     CheckValidPrinter
950     if (( $failure_flag != $SUCCESS ))
951     then
952         XtSetValues $PRINTER_DESC_LABEL labelString:""
953         return
954     fi
955
956     GetPrinterInfo $printer_name
957     XtSetValues $PRINTER_DESC_LABEL labelString:"$printer_info"
958 }
959
960 XCOMM #################################################################
961 XCOMM ##  SelectPrinterCB()
962 XCOMM ##
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.
966 XCOMM ##
967 XCOMM #################################################################
968 SelectPrinterCB()
969 {
970     XtSetValues $PRINTER_TF value:$selected_printer
971     printer_name=$selected_printer
972     UpdatePrinterDescription
973     XtUnmanageChild $SELECT_PRINTER_FORM
974 }
975
976 XCOMM #################################################################
977 XCOMM ##  SelectPrinterHelpCB()
978 XCOMM ##
979 XCOMM ## This is the callback for the Help button in the Select Printer
980 XCOMM ## dialog; it will post a help dialog.
981 XCOMM ##
982 XCOMM #################################################################
983 SelectPrinterHelpCB()
984 {
985     DtkshDisplayQuickHelpDialog "dtlp_help" HELP_TYPE_TOPIC \
986         "Printmgr" "dtlpSelectPrinterDialog"
987 }
988
989 XCOMM #################################################################
990 XCOMM ##  ListSelectCB()
991 XCOMM ##
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.
994 XCOMM ##
995 XCOMM #################################################################
996 ListSelectCB()
997 {
998     GetPrinterInfo ${CB_CALL_DATA.ITEM}
999     XtSetValues $INFO_TEXT value:"$printer_info"
1000     selected_printer=${CB_CALL_DATA.ITEM}
1001 }
1002
1003 XCOMM #################################################################
1004 XCOMM ##  ListDblSelectCB()
1005 XCOMM ##
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.
1009 XCOMM ##
1010 XCOMM #################################################################
1011 ListDblSelectCB()
1012 {
1013     if [ ${CB_CALL_DATA.EVENT.TYPE} != KeyPress ]
1014     then
1015         XtCallCallbacks $SELECT_PRINTER_BTN activateCallback
1016     fi
1017 }
1018
1019 XCOMM #################################################################
1020 XCOMM ##  GetCurrentPrinterName()
1021 XCOMM ##
1022 XCOMM ##  Reads value of Printer Name textfield and strips off any
1023 XCOMM ##  leading and trailing spaces.
1024 XCOMM ##
1025 XCOMM #################################################################
1026 GetCurrentPrinterName()
1027 {
1028     XmTextFieldGetString printer_name $PRINTER_TF 
1029
1030     HASH Strip any leading or trailing spaces
1031     printer_name=${printer_name##+( )}
1032     printer_name=${printer_name%%+( )}
1033 }
1034
1035 XCOMM #################################################################
1036 XCOMM ##  GetAvailPrinters()
1037 XCOMM ##
1038 XCOMM ##  Gets the list of enabled printers.
1039 XCOMM ##
1040 XCOMM #################################################################
1041 GetAvailPrinters()
1042 {
1043     typeset -i num_printers=0
1044     printer_items=''
1045     comma=''
1046     HASH
1047     HASH get a sorted list of all enabled printers
1048     HASH
1049     tmpfile=$DTLPDIR/printers$$
1050
1051 #if defined(__osf__)
1052     LANG=C lpstat -p | \
1053            awk -F":" \
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
1058 #elif defined(_AIX)
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
1066 #else
1067     LANG=C lpstat -p | \
1068            grep enabled | cut -f2 -d" " | \
1069            sort | uniq > $tmpfile 2>&1
1070 #endif
1071
1072     if [ -s "$tmpfile" ]
1073     then
1074     for i in `cat $tmpfile`
1075     do
1076         printer_items=`echo $printer_items$comma$i`
1077         comma=','
1078         ((num_printers=num_printers+1))
1079     done
1080     fi
1081     rm -f $tmpfile
1082 }
1083
1084 XCOMM #################################################################
1085 XCOMM ##  GetPrinterInfo()
1086 XCOMM ##
1087 XCOMM ##  Gets the printer description.
1088 XCOMM ##
1089 XCOMM #################################################################
1090 GetPrinterInfo()
1091 {
1092 #if defined(sun)
1093     t1="$DTLPDIR/d1$$"
1094     t2="$DTLPDIR/d2$$"
1095
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/\(.*\)://'`"
1099     rm -f $t1 $t2
1100 #else
1101     printer_info=$1
1102 #endif
1103 }
1104
1105 XCOMM #################################################################
1106 XCOMM ##  SelectPrinterProc()
1107 XCOMM ##
1108 XCOMM ##  This is called when the Select Printer... button in the Print
1109 XCOMM ##  dialog is selected.  It posts the Select Printer dialog.
1110 XCOMM ##
1111 XCOMM #################################################################
1112 SelectPrinterProc()
1113 {
1114     if [[ "$SELECT_PRINTER_FORM" != "" ]]
1115     then
1116         HASH
1117         HASH dialog already exists, update printer info. if necessary
1118         HASH
1119         GetCurrentPrinterName
1120
1121         HASH get index of printer in the list
1122         XmListItemPos index $PRINTER_LIST $printer_name
1123
1124         HASH
1125         HASH If printer is in the list, select it and display info. on it;
1126         HASH otherwise, just re-manage the dialog.
1127         HASH
1128         if [[ $index > 0 ]]
1129         then
1130             GetPrinterInfo $printer_name
1131             HASH
1132             HASH display printer information and select the printer specified in
1133             HASH the Printer Name textfield
1134             HASH
1135             XmTextSetString $INFO_TEXT "$printer_info"
1136             XmListSelectItem $PRINTER_LIST $printer_name true
1137             XmListSetPos $PRINTER_LIST $index
1138         fi
1139
1140         XtManageChild $SELECT_PRINTER_FORM
1141         return
1142     fi
1143
1144     GetAvailPrinters
1145
1146     XmCreateFormDialog SELECT_PRINTER_FORM $TOPLEVEL form
1147
1148     catgets CAT_MESG_STRING $CAT_ID 1 180 "Select Printer"
1149
1150     XmInternAtom DEL_ATOM $DISPLAY WM_DELETE_WINDOW false
1151     XmAddWMProtocolCallback $(XtParent "-" $SELECT_PRINTER_FORM) \
1152         $DEL_ATOM SelectPrinterCancelCB
1153
1154     XtSetValues $(XtParent "-" $SELECT_PRINTER_FORM) \
1155         title:"$CAT_MESG_STRING" \
1156         allowShellResize:False \
1157         deleteResponse:DO_NOTHING
1158
1159     XtSetValues $SELECT_PRINTER_FORM \
1160         noResize:True \
1161         autoUnmanage:False \
1162         helpCallback:SelectPrinterHelpCB
1163
1164     XmCreateWorkArea WORK_AREA $SELECT_PRINTER_FORM work_area \
1165         orientation:XmVERTICAL
1166
1167     XmCreateWorkArea LIST_RC $WORK_AREA list_rc orientation:XmHORIZONTAL
1168
1169     catgets CAT_MESG_STRING $CAT_ID 1 190 "Available Printers:"
1170
1171     XmCreateLabelGadget LIST_LABEL $LIST_RC list_label \
1172         labelString:"$CAT_MESG_STRING"
1173     XtManageChild $LIST_LABEL
1174
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 \
1181         visibleItemCount:5
1182     XtManageChild $PRINTER_LIST
1183
1184     XmCreateWorkArea INFO_RC $WORK_AREA info_rc orientation:XmVERTICAL
1185
1186     catgets CAT_MESG_STRING $CAT_ID 1 200 "Printer Information:"
1187
1188     XmCreateLabelGadget INFO_LABEL $INFO_RC info_label \
1189         labelString:"$CAT_MESG_STRING"
1190     XtManageChild $INFO_LABEL
1191
1192     printer_info=""
1193     XmCreateScrolledText INFO_TEXT $INFO_RC info_text \
1194         editMode:XmMULTI_LINE_EDIT \
1195         value:"$printer_info" \
1196         rows:5 \
1197         columns:80 \
1198         wordWrap:True \
1199         editable:False
1200
1201     XmCreateSeparator BTN_SEP $SELECT_PRINTER_FORM sep \
1202         separatorType:XmSHADOW_ETCHED_IN \
1203         $(DtkshUnder $WORK_AREA 4) \
1204         $(DtkshSpanWidth)
1205
1206     catgets CAT_MESG_STRING $CAT_ID 1 180 "Select Printer"
1207
1208     XmCreatePushButtonGadget SELECT_PRINTER_BTN $SELECT_PRINTER_FORM \
1209         ok_button \
1210         labelString:"$CAT_MESG_STRING" \
1211         $(DtkshUnder $BTN_SEP 5) \
1212         $(DtkshFloatLeft 10) \
1213         $(DtkshFloatRight 30) \
1214         $(DtkshAnchorBottom 5) 
1215
1216     XtAddCallback $SELECT_PRINTER_BTN activateCallback "SelectPrinterCB"
1217
1218     catgets CAT_MESG_STRING $CAT_ID 1 110 "Cancel"
1219
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) 
1226
1227     XtAddCallback $CANCEL_BTN activateCallback "SelectPrinterCancelCB"
1228
1229     catgets CAT_MESG_STRING $CAT_ID 1 120 "Help"
1230
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) 
1237
1238     XtAddCallback $HELP_BTN activateCallback "SelectPrinterHelpCB"
1239
1240     XtSetValues $SELECT_PRINTER_FORM \
1241         initialFocus:$SELECT_PRINTER_BTN \
1242         defaultButton:$SELECT_PRINTER_BTN \
1243         cancelButton:$CANCEL_BTN \
1244         navigationType:EXCLUSIVE_TAB_GROUP
1245
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
1255
1256     if (( $num_printers ))
1257     then
1258         GetCurrentPrinterName
1259         CheckValidPrinter
1260         if  (( $failure_flag == $SUCCESS ))
1261         then
1262             GetPrinterInfo $printer_name
1263             HASH
1264             HASH display printer information and select the printer specified in
1265             HASH the Printer Name textfield
1266             HASH
1267             XmTextSetString $INFO_TEXT "$printer_info"
1268             XmListSelectItem $PRINTER_LIST $printer_name true
1269             XmListSetItem $PRINTER_LIST $printer_name
1270         fi
1271     else
1272         HASH
1273         HASH no available printer, desensitize Select Printer button in
1274         HASH the Select Printer dialog
1275         HASH
1276         XtSetSensitive $SELECT_PRINTER_BTN false
1277         failure_flag=$NO_PRINTER_AVAILABLE
1278         DisplayErrorMessageDialog
1279     fi
1280 }
1281
1282 XCOMM #################################################################
1283 XCOMM ##  SelectPrinterCancelCB()
1284 XCOMM ##
1285 XCOMM ##  Callback for the Cancel button in Select Printer dialog.
1286 XCOMM ##  It simply unmanages the dialog.
1287 XCOMM ##
1288 XCOMM #################################################################
1289 SelectPrinterCancelCB()
1290 {
1291     XtUnmanageChild $SELECT_PRINTER_FORM
1292 }
1293
1294 XCOMM #################################################################
1295 XCOMM ##  PrinterNameFocusCB()
1296 XCOMM ##
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.
1300 XCOMM ##
1301 XCOMM #################################################################
1302 PrinterNameFocusCB()
1303 {
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
1307     HASH description.
1308     if [ ${CB_CALL_DATA.REASON} = CR_FOCUS ]
1309     then
1310         GetCurrentPrinterName
1311         old_printer=$printer_name 
1312     else
1313         if [ ${CB_CALL_DATA.REASON} = CR_LOSING_FOCUS ]
1314         then
1315             GetCurrentPrinterName
1316             if [ "$old_printer" != "$printer_name" ]
1317             then
1318                 UpdatePrinterDescription
1319             fi
1320         fi
1321     fi
1322 }
1323
1324 XCOMM #################################################################
1325 XCOMM ##  UseGui()
1326 XCOMM ##
1327 XCOMM ##  Creates the Print dialog and sets up the callbacks.
1328 XCOMM ##
1329 XCOMM #################################################################
1330 UseGui()
1331 {
1332     catgets CAT_MESG_STRING $CAT_ID 1 10 "Default"
1333
1334     if (( $printer_name_flag ))
1335     then
1336         printer=$printer_name
1337     else
1338         GetDefaultPrinter
1339         if (( $failure_flag == $SUCCESS ))
1340         then
1341             printer=$default_printer
1342             printer_name=$default_printer
1343         else
1344             printer=$CAT_MESG_STRING
1345         fi
1346     fi
1347
1348     if [[ "$printer_name" != "" ]]
1349     then
1350         GetPrinterInfo $printer_name
1351     else
1352         printer_info=""
1353     fi
1354
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"
1365
1366     catgets CAT_MESG_STRING $CAT_ID 1 20 "Print"
1367
1368     XmInternAtom DEL_ATOM $DISPLAY WM_DELETE_WINDOW false
1369     XmAddWMProtocolCallback $(XtParent "-" $PDIALOG) $DEL_ATOM PrintCancelCB
1370
1371     XtSetValues $(XtParent "-" $PDIALOG) \
1372        title:"$CAT_MESG_STRING" \
1373        allowShellResize:False \
1374        deleteResponse:DO_NOTHING
1375
1376     XtSetValues $PDIALOG autoUnmanage:False
1377
1378     XmCreateWorkArea FILE_NAME_RC $PDIALOG file_name_rc \
1379         marginWidth:0 \
1380         marginHeight:0 \
1381         orientation:XmHORIZONTAL
1382
1383     catgets CAT_MESG_STRING $CAT_ID 1 170 "File Name(s): "
1384
1385     XmCreateLabel FILE_NAME_LABEL $FILE_NAME_RC file_name_label \
1386         labelString:"$CAT_MESG_STRING"
1387
1388     if (( $user_filename_flag ))
1389     then
1390         LABEL_STRING="${user_filename}"
1391     else
1392         LABEL_STRING="${print_file}"
1393     fi
1394     XmCreateLabel FILE_NAME $FILE_NAME_RC file_name \
1395         labelString:"$LABEL_STRING"
1396
1397     XtManageChild $FILE_NAME_RC
1398     XtManageChild $FILE_NAME_LABEL
1399     XtManageChild $FILE_NAME
1400
1401
1402     HASH
1403     HASH Unmanage unneeded widgets
1404     HASH
1405     XtNameToWidget TOP_SEP $PDIALOG "TopWorkAreaSeparator"
1406     XtUnmanageChild $TOP_SEP
1407
1408     XtNameToWidget INFO_BTN $PDIALOG "Info"
1409     XtUnmanageChild $INFO_BTN
1410
1411     XtNameToWidget SELECT_FILE_BTN $PDIALOG "SelectFile"
1412     XtUnmanageChild $SELECT_FILE_BTN
1413
1414     XtNameToWidget SETUP_BTN $PDIALOG "Setup"
1415     XtUnmanageChild $SETUP_BTN
1416
1417     DtCreatePDMJobSetup JOB $PDIALOG
1418
1419     HASH
1420     HASH Get widget handles
1421     HASH
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"
1432
1433     HASH
1434     HASH move cursor to end of printer name
1435     HASH
1436     XtSetValues $PRINTER_TF cursorPosition:${#PRINTER}
1437
1438     HASH
1439     HASH set focus callbacks to track printer name changes
1440     HASH
1441     XtAddCallback $PRINTER_TF focusCallback "PrinterNameFocusCB"
1442     XtAddCallback $PRINTER_TF losingFocusCallback "PrinterNameFocusCB"
1443
1444     HASH
1445     HASH initialize SELECT_PRINTER_FORM to be used in SelectPrinterProc
1446     HASH to determine if the Select Printer dialog already exists.
1447     HASH
1448     SELECT_PRINTER_FORM=""
1449
1450     if (( $banner_title_flag ))
1451     then
1452         XtSetValues $BANNER_TF value:"$banner_title"
1453     fi
1454     if (( $other_options_flag ))
1455     then
1456         XtSetValues $OPTIONS_TF value:"$other_options"
1457     fi
1458
1459     XtManageChild $PDIALOG
1460
1461     if (( $copy_count_flag ))
1462     then
1463         XtSetValues $COPIES_SB position:$copy_count 
1464     fi
1465
1466     if [[ "$send_mail_flag" == "true" ]]
1467     then
1468         XtSetValues $SEND_MAIL_BTN set:true
1469     fi
1470
1471     XtGetValues $COPIES_SB textField:COPIES_TF 
1472
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
1476
1477     XtMainLoop
1478
1479 }
1480
1481 XCOMM #################################################################
1482 XCOMM ##  BadFileCB()
1483 XCOMM ##
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. 
1487 XCOMM ##
1488 XCOMM #################################################################
1489 BadFileCB()
1490 {
1491     Exit $bad_file_flag
1492 }
1493
1494 XCOMM #################################################################
1495 XCOMM ##  ErrorDialogCB()
1496 XCOMM ##
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.
1500 XCOMM ##
1501 XCOMM #################################################################
1502 ErrorDialogCB()
1503 {
1504     XtDestroyWidget $INFORMATION
1505 }
1506
1507 XCOMM #################################################################
1508 XCOMM ##  DisplayErrorMessageDialog()
1509 XCOMM ##
1510 XCOMM ##  We have detected an error.  Post a dialog to that effect.
1511 XCOMM ##
1512 XCOMM ##  Upon entry, check the failure_flag value for the proper
1513 XCOMM ##  message to print.
1514 XCOMM ##
1515 XCOMM #################################################################
1516 DisplayErrorMessageDialog()
1517 {
1518     XmCreateErrorDialog INFORMATION $TOPLEVEL information
1519
1520     catgets CAT_MESG_STRING $CAT_ID 1 160 "Print Information"
1521
1522     XtSetValues $(XtParent "-" $INFORMATION) title:"$CAT_MESG_STRING"
1523
1524     GetErrorMessageString
1525
1526     if (($failure_flag == $NO_FILE_ERR )) ||
1527       (( $failure_flag == $NO_REGULAR_FILE_ERR )) ||
1528       (( $failure_flag == $NO_READABLE_FILE_ERR ))
1529     then
1530         bad_file_flag=$failure_flag
1531         cb="BadFileCB"
1532     else
1533         cb="ErrorDialogCB"
1534     fi
1535
1536     XtSetValues $INFORMATION \
1537         okCallback:$cb \
1538         messageString:"${CAT_MESG_STRING}" \
1539         noResize:True \
1540         defaultButtonType:DIALOG_OK_BUTTON \
1541         dialogStyle:DIALOG_FULL_APPLICATION_MODAL \
1542         messageAlignment:ALIGNMENT_CENTER 
1543
1544      XtUnmanageChild $(XmMessageBoxGetChild "-" $INFORMATION \
1545         DIALOG_CANCEL_BUTTON)
1546
1547      XtUnmanageChild $(XmMessageBoxGetChild "-" $INFORMATION \
1548         DIALOG_HELP_BUTTON)
1549
1550      XtManageChild $INFORMATION
1551
1552      XtMainLoop
1553 }
1554
1555
1556 XCOMM #################################################################
1557 XCOMM ##  Main()
1558 XCOMM ##
1559 XCOMM ##  Set up and call either the silent or the GUI routines.
1560 XCOMM ##
1561 XCOMM ##
1562 XCOMM #################################################################
1563
1564 Initialize
1565
1566 while getopts b:d:m:n:o:u:aehirsvw argument
1567 do
1568     case $argument in
1569     a) print_man_flag=1
1570        ;;
1571     b) banner_title=$OPTARG
1572        banner_title_flag=1
1573        ;;
1574     d) printer_name=$OPTARG
1575        printer_name_flag=1
1576        ;;
1577     e) remove_flag=1
1578        ;;
1579     h) PrintUsage
1580        Exit $SUCCESS
1581        ;;
1582     i) send_mail_flag=true
1583        ;;
1584     m) print_command=$OPTARG
1585        print_command_flag=1
1586        ;;
1587     n) copy_count=$OPTARG
1588        copy_count_flag=1
1589        ;;
1590     o) other_options=$OPTARG
1591        other_options_flag=1
1592        ;;
1593     r) format_flag=1
1594        ;;
1595     s) silent_flag=1
1596        ;;
1597     u) user_filename=$OPTARG
1598        user_filename_flag=1
1599        ;;
1600     v) verbose_flag=1
1601        ;;
1602     w) print_raw_flag=1
1603        ;;
1604    \?) PrintUsage
1605        Exit $USAGE_EXIT
1606        ;;
1607     esac
1608 done
1609
1610 ((shift_positions = OPTIND - 1))
1611
1612 let npf=0
1613
1614 if (( $shift_positions < $# ))
1615 then
1616 XCOMM
1617 XCOMM We have at least one remaining non-switch command line argument
1618 XCOMM
1619     shift $shift_positions
1620     HASH
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.
1623     HASH
1624     print_file=""
1625     print_file_flag=1
1626
1627     while (($# > 0))
1628     do
1629         nw=`echo $1 | wc -w`
1630         if ((nw > 1))
1631         then
1632             file="\"$1\""
1633         else
1634             file="$1"
1635         fi
1636
1637         if [ "" = "$print_file" ]
1638         then
1639           print_file="$file"
1640         else
1641           print_file="$print_file $file"
1642         fi
1643         files[$npf]=$1
1644         let npf=$npf+1
1645         shift
1646     done
1647 fi
1648
1649 XCOMM
1650 XCOMM make sure copy_count is a positive integer
1651 XCOMM
1652 if (( $copy_count_flag ))
1653 then
1654     CheckIsPosInteger $copy_count
1655     if (( $failure_flag != $SUCCESS ))
1656     then
1657         DisplayErrorMessage
1658         Exit $USAGE_EXIT
1659     fi
1660 fi
1661
1662 XCOMM
1663 XCOMM Make sure all these settings line up consistently.
1664 XCOMM
1665 ReconcileOptions
1666
1667 if (( $verbose_flag ))
1668 then
1669     PrintStartLog
1670 fi
1671
1672 XCOMM
1673 XCOMM  Do we have enough information to do our job?
1674 XCOMM  This step may cause us to exit.
1675 XCOMM
1676
1677 XCOMM
1678 XCOMM  Have we been given a valid file(s)?
1679 XCOMM
1680 let i=0
1681 while ((i < npf))
1682 do
1683     CheckValidFile "${files[$i]}"
1684     failure_flag=$?
1685     if (( $failure_flag != $SUCCESS ))
1686     then
1687         print_file="\"${files[$i]}\""
1688         break
1689     fi
1690     let i=i+1
1691 done
1692
1693 if (( $silent_flag ))
1694 then
1695     if (( $failure_flag == $SUCCESS ))
1696     then
1697         CheckValidPrinter
1698         failure_flag=$?
1699         if (( $failure_flag != $SUCCESS ))
1700         then
1701             DisplayErrorMessage
1702             Exit $failure_flag
1703         fi
1704
1705         DoParameterCollectionSilent
1706         PrintIt
1707         CleanUp
1708         Exit $failure_flag
1709     else
1710         DisplayErrorMessage
1711         Exit $failure_flag
1712     fi
1713 else
1714     if [[ -r "/usr/dt/lib/dtksh/DtFuncs.dtsh" ]]
1715     then
1716         . /usr/dt/lib/dtksh/DtFuncs.dtsh
1717     else
1718         failure_flag=1
1719         echo Sorry--cannot find initialization file.
1720         Exit $NO_INIT_FILE_ERR
1721     fi
1722
1723     XtInitialize TOPLEVEL printerConfig Dtlp "${@:-}"
1724     XtDisplay DISPLAY $TOPLEVEL
1725
1726     if (( $failure_flag == $SUCCESS ))
1727     then
1728         UseGui
1729     else
1730         DisplayErrorMessageDialog
1731     fi
1732 fi
1733
1734 XCOMM
1735 XCOMM  Never reached.
1736 XCOMM
1737 XCOMM ####################         eof       ##############################