c930a09334d96e631dff1b8cb633a6d27f2b1bbe
[oweals/cde.git] / dtlp.src
1 XCOMM! DTKORNSHELL
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 #else
545     prfld=2
546     flddelim=':'
547 #endif
548
549     default_printer=""
550     if (( ${#LPDEST} ))
551     then
552         default_printer=$LPDEST
553     else
554 #if defined(_AIX)
555         t1="`LANG=C lpstat -d | head -3 | tail -1`"
556 #else
557         t1="`LANG=C lpstat -d`"
558 #endif
559         t2="`echo $t1 | cut -d' ' -f1`"
560         HASH
561         HASH "no system default destination" is expected if no default is defined;
562         HASH otherwise, "system default destination: <printer_name>" is expected.
563         HASH
564         if [[ "$t2" != "no" ]]
565         then
566             default_printer="`echo $t1 | cut -f$prfld -d"$flddelim"`"
567             HASH remove leading space
568             default_printer=${default_printer##+( )}
569         fi
570
571         if [[ "$default_printer" = "" ]]
572         then
573             failure_flag=$NO_DEFAULT_PRINTER
574             return $failure_flag
575         fi
576     fi
577     failure_flag=$SUCCESS
578     return $failure_flag
579 }
580
581
582 XCOMM #################################################################
583 XCOMM ##  PrintStartLog()
584 XCOMM ##
585 XCOMM ##         Print the start of the log
586 XCOMM ##
587 XCOMM #################################################################
588 PrintStartLog() {
589     print "$COMMAND_NAME..."
590     print ""
591 }
592
593 XCOMM #################################################################
594 XCOMM ##  CheckIsPosInteger()
595 XCOMM ##
596 XCOMM ##  Checks whether a given value is a positive integer.
597 XCOMM ##
598 XCOMM #################################################################
599 CheckIsPosInteger()
600 {
601     val=$1
602     HASH Strip any leading or trailing spaces
603     val=${val##+( )}
604     val=${val%%+( )}
605
606     if [[ ${#val} && "$val" = +([0-9]) ]]
607     then
608         failure_flag=$SUCCESS
609     else
610         failure_flag=$NOT_POS_INTEGER
611     fi
612     return $failure_flag
613 }
614
615 XCOMM #################################################################
616 XCOMM ##  GetErrorMessageString()
617 XCOMM ##
618 XCOMM ##  Looks up the appropriate error message based on the value of
619 XCOMM ##  failure_flag.
620 XCOMM ##
621 XCOMM #################################################################
622 GetErrorMessageString()
623 {
624     catgets CAT_MESG_STRING $CAT_ID 1 130 "Sorry--Unable to print:"
625
626     if (( $user_filename_flag ))
627     then
628         CAT_MESG_STRING=${CAT_MESG_STRING}"  \"$user_filename\"."
629     else
630         CAT_MESG_STRING=${CAT_MESG_STRING}"  \"$print_file\"."
631     fi
632
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."
636         ;;
637       $NO_READABLE_FILE_ERR)
638         catgets TEMP_MESG_STRING $CAT_ID 1 134 "You don't have permission to read that file."
639         ;;
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."
642         ;;
643       $PRINTER_DOES_NOT_EXIST)
644         catgets TEMP_MESG_STRING $CAT_ID 1 230 "The printer does not exist."
645         ;;
646       $PRINTER_NOT_ENABLED)
647         catgets TEMP_MESG_STRING $CAT_ID 1 240 "The printer is not enabled."
648         ;;
649       $NO_DEFAULT_PRINTER)
650         catgets TEMP_MESG_STRING $CAT_ID 1 250 "There is no default printer destination."
651         ;;
652       $PRINTER_NOT_ACCEPT_REQ)
653         catgets TEMP_MESG_STRING $CAT_ID 1 260 "The printer is currently not accepting requests."
654         ;;
655       $NOT_POS_INTEGER)
656         catgets TEMP_MESG_STRING $CAT_ID 1 270 "Number of copies must be a positive number."
657         ;;
658       *)
659         echo ""
660         ;;
661     esac
662
663     if (( $failure_flag == $NO_PRINTER_AVAILABLE ))
664     then
665     CAT_MESG_STRING="${TEMP_MESG_STRING}"
666     else
667     CAT_MESG_STRING="${CAT_MESG_STRING}""
668     ${TEMP_MESG_STRING}"
669     fi
670
671 }
672
673 XCOMM #################################################################
674 XCOMM ##  DisplayErrorMessage()
675 XCOMM ##
676 XCOMM ##         We have detected an error. Write out a message to
677 XCOMM ##         that effect.
678 XCOMM ##
679 XCOMM #################################################################
680 DisplayErrorMessage()
681 {
682     catgets CAT_MESG_STRING $CAT_ID 1 130 "Sorry--Unable to print:"
683
684     GetErrorMessageString
685
686     print ""
687     print `date`
688     print "${CAT_MESG_STRING}"
689     print ""
690 }
691
692
693 XCOMM #################################################################
694 XCOMM ##  PrintEndLog()
695 XCOMM ##
696 XCOMM ##         Print the end of the log.
697 XCOMM ##
698 XCOMM #################################################################
699 PrintEndLog() {
700     print ""
701     if (( $failure_flag == $SUCCESS ))
702     then
703         print "...successfully completed."
704     else
705         print "...completed unsuccessfully."
706     fi
707     print ""
708 }
709
710 XCOMM #################################################################
711 XCOMM ##  PrintUsage()
712 XCOMM ##
713 XCOMM ##        Print a usage message.
714 XCOMM ##
715 XCOMM #################################################################
716 PrintUsage() {
717     print ""
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>"
723     print "  where:"
724     print ""
725     print "  <banner_title>"
726     print "      Specifies the title to put on the banner page."
727     print ""
728     print "  <printer_name>"
729     print "      Specifies the printer name as known to the lp spooler."
730     print ""
731     print "  <print_command>"
732     print "      Specifies the command with which to invoke the printer."
733     print ""
734     print "  <copy_count>"
735     print "      Specifies the number of copies to print."
736     print ""
737     print "  <other_options>"
738     print "      Specifies the other print options."
739     print ""
740     print "  <user_filename>"
741     print "      Specifies the title of the file to display to the user."
742     print ""
743     print "  -a"
744     print "      Formats the file with "man" before printing."
745     print ""
746     print "  -e"
747     print "      Removes the file after printing."
748     print ""
749     print "  -h"
750     print "      Displays this help message."
751     print ""
752     print "  -i"
753     print "      Requests the spooler to sent mail to the user when the print job is completed."
754     print ""
755     print "  -r"
756     print "      Formats the file with "pr -f" before printing."
757     print ""
758     print "  -s"
759     print "      Prints silently (no dialog box)."
760     print ""
761     print "  -v"
762     print "      Directs verbose messages to standard output."
763     print ""
764     print "  -w"
765     print "      Prints the data raw (uninterpreted)."
766     print ""
767     print "  <print_file>"
768     print "      Specifies the name of file(s) to print."
769      
770 }
771
772 XCOMM #################################################################
773 XCOMM ##  Exit()
774 XCOMM ##
775 XCOMM ##        All exits should go through this routine.
776 XCOMM ##
777 XCOMM #################################################################
778 Exit()
779 {
780     exit $1
781 }
782
783 XCOMM #################   GUI Callbacks  ####################
784
785 XCOMM #################################################################
786 XCOMM ##  PrintHelpCB()
787 XCOMM ##
788 XCOMM ## This is the callback for the Help button in the Print dialog;
789 XCOMM ## it will post a help dialog.
790 XCOMM ##
791 XCOMM #################################################################
792 PrintHelpCB()
793 {
794     DtkshDisplayQuickHelpDialog "dtlp_help" HELP_TYPE_TOPIC \
795         "Printmgr" "dtlpPrintDialog"
796 }
797
798 XCOMM #################################################################
799 XCOMM ##  DoParameterCollection()
800 XCOMM ##
801 XCOMM ##  Gathers and validates print options set using the command line
802 XCOMM ##  and the Print dialog.
803 XCOMM ##
804 XCOMM #################################################################
805 DoParameterCollection()
806 {
807     catgets CAT_MESG_STRING $CAT_ID 1 10 "Default"
808
809     GetCurrentPrinterName
810     CheckValidPrinter
811     if (( $failure_flag != $SUCCESS ))
812     then
813         DisplayErrorMessageDialog
814         return $failure_flag
815     fi
816
817     if [[ ("$printer_name" != "") && "$printer_name" != "$CAT_MESG_STRING" ]] 
818     then
819         LPOPTIONS="-d"$printer_name
820     fi
821
822     HASH
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.
826     HASH
827     HASH We must make sure the value is a positive integer in this case.
828     HASH
829     XtGetValues $COPIES_SB textField:COPIES_TF 
830     XmTextFieldGetString copy_val $COPIES_TF
831
832     CheckIsPosInteger $copy_val
833     if (( $failure_flag == $NOT_POS_INTEGER ))
834     then
835         DisplayErrorMessageDialog
836         return $failure_flag
837     else
838         copy_count=$copy_val
839     fi
840
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
846         copy_count_flag=1
847         LPOPTIONS=${LPOPTIONS}" -n$copy_count"
848     fi
849
850     XmTextGetString banner_title $BANNER_TF
851
852     HASH Strip any leading or trailing spaces
853     banner_title=${banner_title##+( )}
854     banner_title=${banner_title%%+( )}
855     if [ "$banner_title" != "" ] ; then
856         banner_title_flag=1
857         LPOPTIONS=${LPOPTIONS}" "${MINUS_T}${SINGLE_QUOTE}${banner_title}${SINGLE_QUOTE}
858     fi
859
860     XmTextGetString other_options $OPTIONS_TF 
861
862     HASH Strip any leading or trailing spaces
863     other_options=${other_options##+( )}
864     other_options=${other_options%%+( )}
865     if  [ "$other_options" != "" ]
866     then
867         LPOPTIONS=${LPOPTIONS}" $other_options"
868     fi
869
870     XtGetValues $SEND_MAIL_BTN set:send_mail_flag
871
872     if [[ "$send_mail_flag" == "true" ]]
873     then
874         LPOPTIONS=${LPOPTIONS}" -m"
875     fi
876
877     if (( $verbose_flag ))
878     then
879         echo The LP options are \"${LPOPTIONS}\".
880     fi
881
882     return $SUCCESS
883 }
884
885 XCOMM #################################################################
886 XCOMM ##  DestroyDialogs()
887 XCOMM ##
888 XCOMM ##  Destroys the Select Printer dialog, if it exists, and the
889 XCOMM ##  Print dialog.
890 XCOMM ##
891 XCOMM #################################################################
892 DestroyDialogs()
893 {
894     if [[ "$SELECT_PRINTER_FORM" != "" ]]
895     then
896         XtDestroyWidget $(XtParent "-" $SELECT_PRINTER_FORM)
897     fi
898     XtDestroyWidget $(XtParent "-" $PDIALOG)
899 }
900
901 XCOMM #################################################################
902 XCOMM ##  PrintCB()
903 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.
906 XCOMM ##
907 XCOMM #################################################################
908 PrintCB()
909 {
910     XSync $DISPLAY True
911
912     DoParameterCollection
913     if [ $? != $SUCCESS ]
914     then
915         return
916     fi
917     PrintIt
918     CleanUp
919     DestroyDialogs
920     Exit $failure_flag
921 }
922
923 XCOMM #################################################################
924 XCOMM ##  PrintCancelCB()
925 XCOMM ##
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.
929 XCOMM ##
930 XCOMM #################################################################
931 PrintCancelCB()
932 {
933     echo ""
934     DestroyDialogs
935     Exit $CANCEL_EXIT
936 }
937
938 XCOMM #################################################################
939 XCOMM ##  UpdatePrinterDescription()
940 XCOMM ##
941 XCOMM ##  Updates Printer Description in the Print dialog.
942 XCOMM ##
943 XCOMM #################################################################
944 UpdatePrinterDescription()
945 {
946     CheckValidPrinter
947     if (( $failure_flag != $SUCCESS ))
948     then
949         XtSetValues $PRINTER_DESC_LABEL labelString:""
950         return
951     fi
952
953     GetPrinterInfo $printer_name
954     XtSetValues $PRINTER_DESC_LABEL labelString:"$printer_info"
955 }
956
957 XCOMM #################################################################
958 XCOMM ##  SelectPrinterCB()
959 XCOMM ##
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.
963 XCOMM ##
964 XCOMM #################################################################
965 SelectPrinterCB()
966 {
967     XtSetValues $PRINTER_TF value:$selected_printer
968     printer_name=$selected_printer
969     UpdatePrinterDescription
970     XtUnmanageChild $SELECT_PRINTER_FORM
971 }
972
973 XCOMM #################################################################
974 XCOMM ##  SelectPrinterHelpCB()
975 XCOMM ##
976 XCOMM ## This is the callback for the Help button in the Select Printer
977 XCOMM ## dialog; it will post a help dialog.
978 XCOMM ##
979 XCOMM #################################################################
980 SelectPrinterHelpCB()
981 {
982     DtkshDisplayQuickHelpDialog "dtlp_help" HELP_TYPE_TOPIC \
983         "Printmgr" "dtlpSelectPrinterDialog"
984 }
985
986 XCOMM #################################################################
987 XCOMM ##  ListSelectCB()
988 XCOMM ##
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.
991 XCOMM ##
992 XCOMM #################################################################
993 ListSelectCB()
994 {
995     GetPrinterInfo ${CB_CALL_DATA.ITEM}
996     XtSetValues $INFO_TEXT value:"$printer_info"
997     selected_printer=${CB_CALL_DATA.ITEM}
998 }
999
1000 XCOMM #################################################################
1001 XCOMM ##  ListDblSelectCB()
1002 XCOMM ##
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.
1006 XCOMM ##
1007 XCOMM #################################################################
1008 ListDblSelectCB()
1009 {
1010     if [ ${CB_CALL_DATA.EVENT.TYPE} != KeyPress ]
1011     then
1012         XtCallCallbacks $SELECT_PRINTER_BTN activateCallback
1013     fi
1014 }
1015
1016 XCOMM #################################################################
1017 XCOMM ##  GetCurrentPrinterName()
1018 XCOMM ##
1019 XCOMM ##  Reads value of Printer Name textfield and strips off any
1020 XCOMM ##  leading and trailing spaces.
1021 XCOMM ##
1022 XCOMM #################################################################
1023 GetCurrentPrinterName()
1024 {
1025     XmTextFieldGetString printer_name $PRINTER_TF 
1026
1027     HASH Strip any leading or trailing spaces
1028     printer_name=${printer_name##+( )}
1029     printer_name=${printer_name%%+( )}
1030 }
1031
1032 XCOMM #################################################################
1033 XCOMM ##  GetAvailPrinters()
1034 XCOMM ##
1035 XCOMM ##  Gets the list of enabled printers.
1036 XCOMM ##
1037 XCOMM #################################################################
1038 GetAvailPrinters()
1039 {
1040     typeset -i num_printers=0
1041     printer_items=''
1042     comma=''
1043     HASH
1044     HASH get a sorted list of all enabled printers
1045     HASH
1046     tmpfile=$DTLPDIR/printers$$
1047
1048 #if defined(_AIX)
1049     LANG=C lpstat -p | \
1050            grep READY   | cut -f1 -d" " | \
1051            sort | uniq > $tmpfile 2>&1
1052 #else
1053     LANG=C lpstat -p | \
1054            grep enabled | cut -f2 -d" " | \
1055            sort | uniq > $tmpfile 2>&1
1056 #endif
1057
1058     if [ -s "$tmpfile" ]
1059     then
1060     for i in `cat $tmpfile`
1061     do
1062         printer_items=`echo $printer_items$comma$i`
1063         comma=','
1064         ((num_printers=num_printers+1))
1065     done
1066     fi
1067     rm -f $tmpfile
1068 }
1069
1070 XCOMM #################################################################
1071 XCOMM ##  GetPrinterInfo()
1072 XCOMM ##
1073 XCOMM ##  Gets the printer description.
1074 XCOMM ##
1075 XCOMM #################################################################
1076 GetPrinterInfo()
1077 {
1078 #if defined(sun)
1079     t1="$DTLPDIR/d1$$"
1080     t2="$DTLPDIR/d2$$"
1081
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/\(.*\)://'`"
1085     rm -f $t1 $t2
1086 #else
1087     printer_info=$1
1088 #endif
1089 }
1090
1091 XCOMM #################################################################
1092 XCOMM ##  SelectPrinterProc()
1093 XCOMM ##
1094 XCOMM ##  This is called when the Select Printer... button in the Print
1095 XCOMM ##  dialog is selected.  It posts the Select Printer dialog.
1096 XCOMM ##
1097 XCOMM #################################################################
1098 SelectPrinterProc()
1099 {
1100     if [[ "$SELECT_PRINTER_FORM" != "" ]]
1101     then
1102         HASH
1103         HASH dialog already exists, update printer info. if necessary
1104         HASH
1105         GetCurrentPrinterName
1106
1107         HASH get index of printer in the list
1108         XmListItemPos index $PRINTER_LIST $printer_name
1109
1110         HASH
1111         HASH If printer is in the list, select it and display info. on it;
1112         HASH otherwise, just re-manage the dialog.
1113         HASH
1114         if [[ $index > 0 ]]
1115         then
1116             GetPrinterInfo $printer_name
1117             HASH
1118             HASH display printer information and select the printer specified in
1119             HASH the Printer Name textfield
1120             HASH
1121             XmTextSetString $INFO_TEXT "$printer_info"
1122             XmListSelectItem $PRINTER_LIST $printer_name true
1123             XmListSetPos $PRINTER_LIST $index
1124         fi
1125
1126         XtManageChild $SELECT_PRINTER_FORM
1127         return
1128     fi
1129
1130     GetAvailPrinters
1131
1132     XmCreateFormDialog SELECT_PRINTER_FORM $TOPLEVEL form
1133
1134     catgets CAT_MESG_STRING $CAT_ID 1 180 "Select Printer"
1135
1136     XmInternAtom DEL_ATOM $DISPLAY WM_DELETE_WINDOW false
1137     XmAddWMProtocolCallback $(XtParent "-" $SELECT_PRINTER_FORM) \
1138         $DEL_ATOM SelectPrinterCancelCB
1139
1140     XtSetValues $(XtParent "-" $SELECT_PRINTER_FORM) \
1141         title:"$CAT_MESG_STRING" \
1142         allowShellResize:False \
1143         deleteResponse:DO_NOTHING
1144
1145     XtSetValues $SELECT_PRINTER_FORM \
1146         noResize:True \
1147         autoUnmanage:False \
1148         helpCallback:SelectPrinterHelpCB
1149
1150     XmCreateWorkArea WORK_AREA $SELECT_PRINTER_FORM work_area \
1151         orientation:XmVERTICAL
1152
1153     XmCreateWorkArea LIST_RC $WORK_AREA list_rc orientation:XmHORIZONTAL
1154
1155     catgets CAT_MESG_STRING $CAT_ID 1 190 "Available Printers:"
1156
1157     XmCreateLabelGadget LIST_LABEL $LIST_RC list_label \
1158         labelString:"$CAT_MESG_STRING"
1159     XtManageChild $LIST_LABEL
1160
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 \
1167         visibleItemCount:5
1168     XtManageChild $PRINTER_LIST
1169
1170     XmCreateWorkArea INFO_RC $WORK_AREA info_rc orientation:XmVERTICAL
1171
1172     catgets CAT_MESG_STRING $CAT_ID 1 200 "Printer Information:"
1173
1174     XmCreateLabelGadget INFO_LABEL $INFO_RC info_label \
1175         labelString:"$CAT_MESG_STRING"
1176     XtManageChild $INFO_LABEL
1177
1178     printer_info=""
1179     XmCreateScrolledText INFO_TEXT $INFO_RC info_text \
1180         editMode:XmMULTI_LINE_EDIT \
1181         value:"$printer_info" \
1182         rows:5 \
1183         columns:80 \
1184         wordWrap:True \
1185         editable:False
1186
1187     XmCreateSeparator BTN_SEP $SELECT_PRINTER_FORM sep \
1188         separatorType:XmSHADOW_ETCHED_IN \
1189         $(DtkshUnder $WORK_AREA 4) \
1190         $(DtkshSpanWidth)
1191
1192     catgets CAT_MESG_STRING $CAT_ID 1 180 "Select Printer"
1193
1194     XmCreatePushButtonGadget SELECT_PRINTER_BTN $SELECT_PRINTER_FORM \
1195         ok_button \
1196         labelString:"$CAT_MESG_STRING" \
1197         $(DtkshUnder $BTN_SEP 5) \
1198         $(DtkshFloatLeft 10) \
1199         $(DtkshFloatRight 30) \
1200         $(DtkshAnchorBottom 5) 
1201
1202     XtAddCallback $SELECT_PRINTER_BTN activateCallback "SelectPrinterCB"
1203
1204     catgets CAT_MESG_STRING $CAT_ID 1 110 "Cancel"
1205
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) 
1212
1213     XtAddCallback $CANCEL_BTN activateCallback "SelectPrinterCancelCB"
1214
1215     catgets CAT_MESG_STRING $CAT_ID 1 120 "Help"
1216
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) 
1223
1224     XtAddCallback $HELP_BTN activateCallback "SelectPrinterHelpCB"
1225
1226     XtSetValues $SELECT_PRINTER_FORM \
1227         initialFocus:$SELECT_PRINTER_BTN \
1228         defaultButton:$SELECT_PRINTER_BTN \
1229         cancelButton:$CANCEL_BTN \
1230         navigationType:EXCLUSIVE_TAB_GROUP
1231
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
1241
1242     if (( $num_printers ))
1243     then
1244         GetCurrentPrinterName
1245         CheckValidPrinter
1246         if  (( $failure_flag == $SUCCESS ))
1247         then
1248             GetPrinterInfo $printer_name
1249             HASH
1250             HASH display printer information and select the printer specified in
1251             HASH the Printer Name textfield
1252             HASH
1253             XmTextSetString $INFO_TEXT "$printer_info"
1254             XmListSelectItem $PRINTER_LIST $printer_name true
1255             XmListSetItem $PRINTER_LIST $printer_name
1256         fi
1257     else
1258         HASH
1259         HASH no available printer, desensitize Select Printer button in
1260         HASH the Select Printer dialog
1261         HASH
1262         XtSetSensitive $SELECT_PRINTER_BTN false
1263         failure_flag=$NO_PRINTER_AVAILABLE
1264         DisplayErrorMessageDialog
1265     fi
1266 }
1267
1268 XCOMM #################################################################
1269 XCOMM ##  SelectPrinterCancelCB()
1270 XCOMM ##
1271 XCOMM ##  Callback for the Cancel button in Select Printer dialog.
1272 XCOMM ##  It simply unmanages the dialog.
1273 XCOMM ##
1274 XCOMM #################################################################
1275 SelectPrinterCancelCB()
1276 {
1277     XtUnmanageChild $SELECT_PRINTER_FORM
1278 }
1279
1280 XCOMM #################################################################
1281 XCOMM ##  PrinterNameFocusCB()
1282 XCOMM ##
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.
1286 XCOMM ##
1287 XCOMM #################################################################
1288 PrinterNameFocusCB()
1289 {
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
1293     HASH description.
1294     if [ ${CB_CALL_DATA.REASON} = CR_FOCUS ]
1295     then
1296         GetCurrentPrinterName
1297         old_printer=$printer_name 
1298     else
1299         if [ ${CB_CALL_DATA.REASON} = CR_LOSING_FOCUS ]
1300         then
1301             GetCurrentPrinterName
1302             if [ "$old_printer" != "$printer_name" ]
1303             then
1304                 UpdatePrinterDescription
1305             fi
1306         fi
1307     fi
1308 }
1309
1310 XCOMM #################################################################
1311 XCOMM ##  UseGui()
1312 XCOMM ##
1313 XCOMM ##  Creates the Print dialog and sets up the callbacks.
1314 XCOMM ##
1315 XCOMM #################################################################
1316 UseGui()
1317 {
1318     catgets CAT_MESG_STRING $CAT_ID 1 10 "Default"
1319
1320     if (( $printer_name_flag ))
1321     then
1322         printer=$printer_name
1323     else
1324         GetDefaultPrinter
1325         if (( $failure_flag == $SUCCESS ))
1326         then
1327             printer=$default_printer
1328             printer_name=$default_printer
1329         else
1330             printer=$CAT_MESG_STRING
1331         fi
1332     fi
1333
1334     if [[ "$printer_name" != "" ]]
1335     then
1336         GetPrinterInfo $printer_name
1337     else
1338         printer_info=""
1339     fi
1340
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"
1351
1352     catgets CAT_MESG_STRING $CAT_ID 1 20 "Print"
1353
1354     XmInternAtom DEL_ATOM $DISPLAY WM_DELETE_WINDOW false
1355     XmAddWMProtocolCallback $(XtParent "-" $PDIALOG) $DEL_ATOM PrintCancelCB
1356
1357     XtSetValues $(XtParent "-" $PDIALOG) \
1358        title:"$CAT_MESG_STRING" \
1359        allowShellResize:False \
1360        deleteResponse:DO_NOTHING
1361
1362     XtSetValues $PDIALOG autoUnmanage:False
1363
1364     XmCreateWorkArea FILE_NAME_RC $PDIALOG file_name_rc \
1365         marginWidth:0 \
1366         marginHeight:0 \
1367         orientation:XmHORIZONTAL
1368
1369     catgets CAT_MESG_STRING $CAT_ID 1 170 "File Name(s): "
1370
1371     XmCreateLabel FILE_NAME_LABEL $FILE_NAME_RC file_name_label \
1372         labelString:"$CAT_MESG_STRING"
1373
1374     if (( $user_filename_flag ))
1375     then
1376         LABEL_STRING="${user_filename}"
1377     else
1378         LABEL_STRING="${print_file}"
1379     fi
1380     XmCreateLabel FILE_NAME $FILE_NAME_RC file_name \
1381         labelString:"$LABEL_STRING"
1382
1383     XtManageChild $FILE_NAME_RC
1384     XtManageChild $FILE_NAME_LABEL
1385     XtManageChild $FILE_NAME
1386
1387
1388     HASH
1389     HASH Unmanage unneeded widgets
1390     HASH
1391     XtNameToWidget TOP_SEP $PDIALOG "TopWorkAreaSeparator"
1392     XtUnmanageChild $TOP_SEP
1393
1394     XtNameToWidget INFO_BTN $PDIALOG "Info"
1395     XtUnmanageChild $INFO_BTN
1396
1397     XtNameToWidget SELECT_FILE_BTN $PDIALOG "SelectFile"
1398     XtUnmanageChild $SELECT_FILE_BTN
1399
1400     XtNameToWidget SETUP_BTN $PDIALOG "Setup"
1401     XtUnmanageChild $SETUP_BTN
1402
1403     DtCreatePDMJobSetup JOB $PDIALOG
1404
1405     HASH
1406     HASH Get widget handles
1407     HASH
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"
1418
1419     HASH
1420     HASH move cursor to end of printer name
1421     HASH
1422     XtSetValues $PRINTER_TF cursorPosition:${#PRINTER}
1423
1424     HASH
1425     HASH set focus callbacks to track printer name changes
1426     HASH
1427     XtAddCallback $PRINTER_TF focusCallback "PrinterNameFocusCB"
1428     XtAddCallback $PRINTER_TF losingFocusCallback "PrinterNameFocusCB"
1429
1430     HASH
1431     HASH initialize SELECT_PRINTER_FORM to be used in SelectPrinterProc
1432     HASH to determine if the Select Printer dialog already exists.
1433     HASH
1434     SELECT_PRINTER_FORM=""
1435
1436     if (( $banner_title_flag ))
1437     then
1438         XtSetValues $BANNER_TF value:"$banner_title"
1439     fi
1440     if (( $other_options_flag ))
1441     then
1442         XtSetValues $OPTIONS_TF value:"$other_options"
1443     fi
1444
1445     XtManageChild $PDIALOG
1446
1447     if (( $copy_count_flag ))
1448     then
1449         XtSetValues $COPIES_SB position:$copy_count 
1450     fi
1451
1452     if [[ "$send_mail_flag" == "true" ]]
1453     then
1454         XtSetValues $SEND_MAIL_BTN set:true
1455     fi
1456
1457     XtGetValues $COPIES_SB textField:COPIES_TF 
1458
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
1462
1463     XtMainLoop
1464
1465 }
1466
1467 XCOMM #################################################################
1468 XCOMM ##  BadFileCB()
1469 XCOMM ##
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. 
1473 XCOMM ##
1474 XCOMM #################################################################
1475 BadFileCB()
1476 {
1477     Exit $bad_file_flag
1478 }
1479
1480 XCOMM #################################################################
1481 XCOMM ##  ErrorDialogCB()
1482 XCOMM ##
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.
1486 XCOMM ##
1487 XCOMM #################################################################
1488 ErrorDialogCB()
1489 {
1490     XtDestroyWidget $INFORMATION
1491 }
1492
1493 XCOMM #################################################################
1494 XCOMM ##  DisplayErrorMessageDialog()
1495 XCOMM ##
1496 XCOMM ##  We have detected an error.  Post a dialog to that effect.
1497 XCOMM ##
1498 XCOMM ##  Upon entry, check the failure_flag value for the proper
1499 XCOMM ##  message to print.
1500 XCOMM ##
1501 XCOMM #################################################################
1502 DisplayErrorMessageDialog()
1503 {
1504     XmCreateErrorDialog INFORMATION $TOPLEVEL information
1505
1506     catgets CAT_MESG_STRING $CAT_ID 1 160 "Print Information"
1507
1508     XtSetValues $(XtParent "-" $INFORMATION) title:"$CAT_MESG_STRING"
1509
1510     GetErrorMessageString
1511
1512     if (($failure_flag == $NO_FILE_ERR )) ||
1513       (( $failure_flag == $NO_REGULAR_FILE_ERR )) ||
1514       (( $failure_flag == $NO_READABLE_FILE_ERR ))
1515     then
1516         bad_file_flag=$failure_flag
1517         cb="BadFileCB"
1518     else
1519         cb="ErrorDialogCB"
1520     fi
1521
1522     XtSetValues $INFORMATION \
1523         okCallback:$cb \
1524         messageString:"${CAT_MESG_STRING}" \
1525         noResize:True \
1526         defaultButtonType:DIALOG_OK_BUTTON \
1527         dialogStyle:DIALOG_FULL_APPLICATION_MODAL \
1528         messageAlignment:ALIGNMENT_CENTER 
1529
1530      XtUnmanageChild $(XmMessageBoxGetChild "-" $INFORMATION \
1531         DIALOG_CANCEL_BUTTON)
1532
1533      XtUnmanageChild $(XmMessageBoxGetChild "-" $INFORMATION \
1534         DIALOG_HELP_BUTTON)
1535
1536      XtManageChild $INFORMATION
1537
1538      XtMainLoop
1539 }
1540
1541
1542 XCOMM #################################################################
1543 XCOMM ##  Main()
1544 XCOMM ##
1545 XCOMM ##  Set up and call either the silent or the GUI routines.
1546 XCOMM ##
1547 XCOMM ##
1548 XCOMM #################################################################
1549
1550 Initialize
1551
1552 while getopts b:d:m:n:o:u:aehirsvw argument
1553 do
1554     case $argument in
1555     a) print_man_flag=1
1556        ;;
1557     b) banner_title=$OPTARG
1558        banner_title_flag=1
1559        ;;
1560     d) printer_name=$OPTARG
1561        printer_name_flag=1
1562        ;;
1563     e) remove_flag=1
1564        ;;
1565     h) PrintUsage
1566        Exit $SUCCESS
1567        ;;
1568     i) send_mail_flag=true
1569        ;;
1570     m) print_command=$OPTARG
1571        print_command_flag=1
1572        ;;
1573     n) copy_count=$OPTARG
1574        copy_count_flag=1
1575        ;;
1576     o) other_options=$OPTARG
1577        other_options_flag=1
1578        ;;
1579     r) format_flag=1
1580        ;;
1581     s) silent_flag=1
1582        ;;
1583     u) user_filename=$OPTARG
1584        user_filename_flag=1
1585        ;;
1586     v) verbose_flag=1
1587        ;;
1588     w) print_raw_flag=1
1589        ;;
1590    \?) PrintUsage
1591        Exit $USAGE_EXIT
1592        ;;
1593     esac
1594 done
1595
1596 ((shift_positions = OPTIND - 1))
1597
1598 let npf=0
1599
1600 if (( $shift_positions < $# ))
1601 then
1602 XCOMM
1603 XCOMM We have at least one remaining non-switch command line argument
1604 XCOMM
1605     shift $shift_positions
1606     HASH
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.
1609     HASH
1610     print_file=""
1611     print_file_flag=1
1612
1613     while (($# > 0))
1614     do
1615         nw=`echo $1 | wc -w`
1616         if ((nw > 1))
1617         then
1618             file="\"$1\""
1619         else
1620             file="$1"
1621         fi
1622
1623         if [ "" = "$print_file" ]
1624         then
1625           print_file="$file"
1626         else
1627           print_file="$print_file $file"
1628         fi
1629         files[$npf]=$1
1630         let npf=$npf+1
1631         shift
1632     done
1633 fi
1634
1635 XCOMM
1636 XCOMM make sure copy_count is a positive integer
1637 XCOMM
1638 if (( $copy_count_flag ))
1639 then
1640     CheckIsPosInteger $copy_count
1641     if (( $failure_flag != $SUCCESS ))
1642     then
1643         DisplayErrorMessage
1644         Exit $USAGE_EXIT
1645     fi
1646 fi
1647
1648 XCOMM
1649 XCOMM Make sure all these settings line up consistently.
1650 XCOMM
1651 ReconcileOptions
1652
1653 if (( $verbose_flag ))
1654 then
1655     PrintStartLog
1656 fi
1657
1658 XCOMM
1659 XCOMM  Do we have enough information to do our job?
1660 XCOMM  This step may cause us to exit.
1661 XCOMM
1662
1663 XCOMM
1664 XCOMM  Have we been given a valid file(s)?
1665 XCOMM
1666 let i=0
1667 while ((i < npf))
1668 do
1669     CheckValidFile "${files[$i]}"
1670     failure_flag=$?
1671     if (( $failure_flag != $SUCCESS ))
1672     then
1673         print_file="\"${files[$i]}\""
1674         break
1675     fi
1676     let i=i+1
1677 done
1678
1679 if (( $silent_flag ))
1680 then
1681     if (( $failure_flag == $SUCCESS ))
1682     then
1683         CheckValidPrinter
1684         failure_flag=$?
1685         if (( $failure_flag != $SUCCESS ))
1686         then
1687             DisplayErrorMessage
1688             Exit $failure_flag
1689         fi
1690
1691         DoParameterCollectionSilent
1692         PrintIt
1693         CleanUp
1694         Exit $failure_flag
1695     else
1696         DisplayErrorMessage
1697         Exit $failure_flag
1698     fi
1699 else
1700     if [[ -r CDE_INSTALLATION_TOP/lib/dtksh/DtFuncs.dtsh ]]
1701     then
1702         . CDE_INSTALLATION_TOP/lib/dtksh/DtFuncs.dtsh
1703     else
1704         failure_flag=1
1705         echo Sorry--cannot find initialization file.
1706         Exit $NO_INIT_FILE_ERR
1707     fi
1708
1709     XtInitialize TOPLEVEL printerConfig Dtlp "${@:-}"
1710     XtDisplay DISPLAY $TOPLEVEL
1711
1712     if (( $failure_flag == $SUCCESS ))
1713     then
1714         UseGui
1715     else
1716         DisplayErrorMessageDialog
1717     fi
1718 fi
1719
1720 XCOMM
1721 XCOMM  Never reached.
1722 XCOMM
1723 XCOMM ####################         eof       ##############################