2
0

dthelpprint.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #!/bin/sh
  2. #######################################################
  3. ### File: dthelpprint.sh
  4. ###
  5. ### Default Location: /usr/dt/bin/dthelpprint.sh
  6. ###
  7. ### (c) Copyright 1993, 1994 Hewlett-Packard Company
  8. ### (c) Copyright 1993, 1994 International Business Machines Corp.
  9. ### (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  10. ### (c) Copyright 1993, 1994 Novell, Inc.
  11. ###
  12. ### Purpose:
  13. ###
  14. ### The dthelpprint executable generates a fully formatted
  15. ### temporary file and then calls the dthelpprint.sh script
  16. ### with options to actually print the file.
  17. ###
  18. ### Through the use of a shell script, dthelpprint
  19. ### does not need to link against libDtSvc and also
  20. ### supports better customization of help printing.
  21. ###
  22. ### Description:
  23. ###
  24. ### This script determines whether the Cde1 environment
  25. ### is installed and whether there is a Print action.
  26. ### If there is an action, use it to print the file.
  27. ### If there isn't and Cde1 is installed, try to use dtlp directly.
  28. ### If no Cde1 components are available, lp is used.
  29. ###
  30. ### Product: @(#)Cde1
  31. ###
  32. ### Invoked by: dthelpprint (only!)
  33. ###
  34. ### Revision: $XConsortium: dthelpprint.sh /main/3 1995/11/07 13:18:44 rswiston $
  35. ###
  36. #########################################################
  37. # set -x # trace on
  38. #########################################################
  39. ### Function: usage()
  40. ### Prints the usage message and exits
  41. #########################################################
  42. usage()
  43. {
  44. echo "usage: dthelpprint.sh options";
  45. echo "options:";
  46. echo "\t -d <lpdest> : printer to use";
  47. echo "\t -f <print file> : file to print";
  48. echo "\t -m <print command> : print command to use";
  49. echo "\t -n <num copies> : number copies to print";
  50. echo "\t -u <user file name> : filename to show user";
  51. echo "\t -w : print raw";
  52. echo "\t -s : print silent";
  53. echo "\t -e : remove file";
  54. exit 0;
  55. }
  56. #########################################################
  57. ### Main()
  58. ### set the env vars based on the arg list options
  59. ### These env vars conform to the dtlp interface
  60. #########################################################
  61. # define which executables to use
  62. ProgDtKsh=/usr/dt/bin/dtksh
  63. ProgDtAction=/usr/dt/bin/dtaction
  64. ProgDtLp=/usr/dt/bin/dtlp # only executed directly if Print action not avail
  65. ProgLp=/usr/bin/lp
  66. ActionPrint=Print
  67. # init vars and consts
  68. FlagActionOk=0;
  69. True="True"
  70. False="False"
  71. # get the options
  72. if [ $# -lt 2 ]; then usage; fi;
  73. for argument in $*
  74. do
  75. case $argument in
  76. -d) LPDEST=$2; shift 2; export LPDEST; ## Cde1 Print API
  77. ;;
  78. -e) DTPRINTFILEREMOVE=$True; shift; export DTPRINTFILEREMOVE; ## Cde1 Print API
  79. ;;
  80. -s) DTPRINTSILENT=$True; shift; export DTPRINTSILENT; ## Cde1 Print API
  81. ;;
  82. -u) DTPRINTUSERFILENAME=$2; shift 2; export DTPRINTUSERFILENAME; ## Cde1 Print API
  83. ;;
  84. -f) OptFile=$2; shift 2; export OptFile; ## local variables
  85. ;;
  86. -m) OptLpCommand=$2; shift 2; export OptLpCommand; ## local variables
  87. ;;
  88. -n) OptCopyCnt=$2; shift 2; export OptCopyCnt; ## local variables
  89. ;;
  90. -w) OptRaw=$True; shift; export OptRaw; ## local variables
  91. ;;
  92. --) shift; break;
  93. ;;
  94. -\?) usage;
  95. ;;
  96. esac
  97. done
  98. # can't print if no file is spec'd
  99. if [ -z "$OptFile" -o ! -r "$OptFile" ];
  100. then exit 1;
  101. fi;
  102. # is Cde1 installed and OptLpCommand not specified ?
  103. if [ -x $ProgDtAction -a -x $ProgDtKsh -a -z "$OptLpCommand" ];
  104. then
  105. # exec a dtksh script to determine whether the print action exists
  106. $ProgDtKsh -c "XtInitialize TOPLEVEL chkPntr Dtksh;\
  107. DtDbLoad;\
  108. if DtActionExists $ActionPrint;\
  109. then exit 1;\
  110. else exit 0;\
  111. fi;";
  112. # if action exists, use it; action removes the print file
  113. FlagActionOk=$?;
  114. if [ $FlagActionOk = 1 ];
  115. then
  116. # don't iterate wildly
  117. if [ -z "$OptCopyCnt" -o "$OptCopyCnt" -lt 0 -o "$OptCopyCnt" -gt "100" ]
  118. then OptCopyCnt=1;
  119. fi;
  120. # honor copycount by looping
  121. # only set the DTPRINTFILEREMOVE for the last iteration
  122. VarOldFileRemove=$DTPRINTFILEREMOVE # save orig value
  123. DTPRINTFILEREMOVE=$False # deactivate the remove request
  124. while [ "$OptCopyCnt" -gt "1" ]
  125. do
  126. $ProgDtAction $ActionPrint $OptFile; # take other options from env vars
  127. OptCopyCnt=`expr "$OptCopyCnt" - 1`;
  128. done;
  129. DTPRINTFILEREMOVE=$VarOldFileRemove; # restore orig value
  130. $ProgDtAction $ActionPrint $OptFile; # take other options from env vars
  131. exit 0;
  132. # else if dtlp is installed, use it directly; it removes the print file
  133. elif [ -x $ProgDtLp ]
  134. then
  135. $ProgDtLp ${LPDEST:+-d} ${LPDEST:+$LPDEST} \
  136. ${DTPRINTFILEREMOVE:+-e} \
  137. ${DTPRINTSILENT:+-s} \
  138. -u "${DTPRINTUSERFILENAME:-Help Information}" \
  139. -b "Help" \
  140. ${OptLpCommand:+-m} ${OptLpCommand:+$OptLpCommand} \
  141. -n ${OptCopyCnt:-1} \
  142. ${OptRaw:+-w} \
  143. "$OptFile";
  144. exit 0;
  145. fi; # use Print actio or ProgDtLp
  146. fi; # if Cde1 installed
  147. # if Cde1 not installed or print action & dtlp not avail or OptLpCommand set
  148. if [ -n "$FlagActionOk" -a "$FlagActionOk" = 0 -a -r "$OptFile" ];
  149. then
  150. ${OptLpCommand:-$ProgLp} -s -t "Help" \
  151. ${LPDEST:+-d} ${LPDEST:+$LPDEST} \
  152. ${OptRaw:+"-oraw"} \
  153. -n ${OptCopyCnt:-1} \
  154. $OptFile;
  155. if [ "$DTPRINTFILEREMOVE" = $True ]; then rm -f $OptFile; fi;
  156. fi;
  157. exit 0;