appc.sgm 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <!-- $XConsortium: appc.sgm /main/7 1996/09/08 19:45:21 rws $ -->
  2. <!-- (c) Copyright 1995 Digital Equipment Corporation. -->
  3. <!-- (c) Copyright 1995 Hewlett-Packard Company. -->
  4. <!-- (c) Copyright 1995 International Business Machines Corp. -->
  5. <!-- (c) Copyright 1995 Sun Microsystems, Inc. -->
  6. <!-- (c) Copyright 1995 Novell, Inc. -->
  7. <!-- (c) Copyright 1995 FUJITSU LIMITED. -->
  8. <!-- (c) Copyright 1995 Hitachi. -->
  9. <appendix id="DKSUG.finds.div.1">
  10. <title>The script_findスクリプト</title>
  11. <para>この付録には、第4章「複雑なスクリプト」で説明されている<filename>script_find</filename>の全リストが
  12. 掲載されています。このスクリプトは、<indexterm><primary>script_find</primary></indexterm><filename>script_find</filename>の後にリストされている<filename>Find.sticky</filename>と呼ばれるという従属的な
  13. スクリプトを実行します。
  14. メイン・スクリプト・ウィンドウの[ヘルプ]ボタンをクリックするとアクセスされる<filename>Find.help</filename>と呼ばれるテキスト・フィールドもあります。
  15. このスクリプトのより詳細な情報は、第4章を参照してください。
  16. </para>
  17. <sect1 id="DKSUG.finds.div.2">
  18. <title>script_findのリスト</title>
  19. <programlisting>#! /usr/dt/bin/dtksh
  20. set -u
  21. . /usr/dt/lib/dtksh/DtFuncs.dtsh
  22. #
  23. # This sample shell script provides a graphical interface to the
  24. # `find' command. Each time it is executed, it will attempt to
  25. # restore the dialog to the last set of values entered by the user.
  26. # When the `find' command is initiated, the output will be displayed
  27. # in a dtterm window.
  28. #
  29. #
  30. # Post an# error dialog. The main application window is disabled
  31. # until the error dialog is unposted. The message to be displayed
  32. # in the # error dialog is passed in as $1
  33. #
  34. PostErrorDialog()
  35. {
  36. DtDisplayErrorDialog &ldquo;Find Error&rdquo; &ldquo;$1&rdquo; \
  37. DIALOG_PRIMARY_APPLICATION_MODAL
  38. }
  39. #
  40. # This is both the `Ok' and the `Apply' callback; in the case of the
  41. # `Ok' callback, it unposts the main application window, and then
  42. # exits, if the dialog contains valid information. For both `Ok' and
  43. # `Apply', the set of search directories is first validated; if any
  44. # of the paths are not valid, then an error dialog is posted.
  45. # Otherwise, the `find' process is started in a terminal window.
  46. #
  47. OkCallback()
  48. {
  49. RetrieveAndSaveCurrentValues
  50. if [ &ldquo;$SD_VAL&rdquo; = &ldquo;&ldquo; ]; then
  51. PostErrorDialog &ldquo;You must specify a directory to search&rdquo;
  52. else
  53. for i in $SD_VAL; do
  54. if [ ! -d $i ]; then
  55. MSG=&rdquo;The following search directory does not exist:
  56. $i&rdquo;
  57. PostErrorDialog &ldquo;$MSG&rdquo;
  58. return 1
  59. fi
  60. done
  61. if [ $CB_WIDGET = $OK ]; then
  62. XtPopdown $TOPLEVEL
  63. fi
  64. CMD=&rdquo;/bin/find $SD_VAL&rdquo;
  65. if [ ! &ldquo;$FNP_VAL&rdquo; = &ldquo;&ldquo; ]; then
  66. CMD=$CMD&rdquo; -name $FNP_VAL&rdquo;
  67. fi
  68. if ! $(XmToggleButtonGetState $T1); then
  69. CMD=$CMD&rdquo; -xdev&rdquo;
  70. fi
  71. if $(XmToggleButtonGetState $T3); then
  72. CMD=$CMD&rdquo; -hidden&rdquo;
  73. fi
  74. if $(XmToggleButtonGetState $T4); then
  75. CMD=$CMD&rdquo; -follow&rdquo;
  76. fi
  77. if $(XmToggleButtonGetState $T5); then
  78. CMD=$CMD&rdquo; -depth&rdquo;
  79. fi
  80. case $FSTYPE_VAL in
  81. $NFS) CMD=$CMD&rdquo; -fsonly nfs&rdquo; ;;
  82. $CDFS) CMD=$CMD&rdquo; -fsonly cdfs&rdquo; ;;
  83. $HFS) CMD=$CMD&rdquo; -fsonly hfs&rdquo; ;;
  84. *) ;;
  85. esac
  86. case $FILETYPE_VAL in
  87. $REGULAR) CMD=$CMD&rdquo; -type f&rdquo; ;;
  88. $DIRECTORY) CMD=$CMD&rdquo; -type d&rdquo; ;;
  89. $BLOCK) CMD=$CMD&rdquo; -type b&rdquo; ;;
  90. $CHAR) CMD=$CMD&rdquo; -type c&rdquo; ;;
  91. $FIFO) CMD=$CMD&rdquo; -type p&rdquo; ;;
  92. $SYMLINK) CMD=$CMD&rdquo; -type l&rdquo; ;;
  93. $SOCKET) CMD=$CMD&rdquo; -type s&rdquo; ;;
  94. $NET) CMD=$CMD&rdquo; -type n&rdquo; ;;
  95. $MOUNT) CMD=$CMD&rdquo; -type M&rdquo; ;;
  96. $HIDDEN) CMD=$CMD&rdquo; -type H&rdquo; ;;
  97. *) ;;
  98. esac
  99. if $(XmToggleButtonGetState $T2); then
  100. CMD=$CMD&rdquo; -print&rdquo;
  101. fi
  102. /usr/dt/bin/dtterm -title &ldquo;Find A File&rdquo; -e /usr/dt/bin/dtexec
  103. -open -1 $CMD &amp;
  104. if [ $CB_WIDGET = $OK ]; then
  105. exit 0
  106. fi
  107. fi
  108. }
  109. #
  110. # This function attempts to load in the previous dialog values.
  111. # Each line read from the file is then interpreted as a ksh command.
  112. #
  113. LoadStickyValues()
  114. {
  115. if [ -r &ldquo;./Find.sticky&rdquo; ]; then
  116. exec 6&lt; &ldquo;./Find.sticky&rdquo;
  117. XtAddInput FID 6 &ldquo;EvalCmd&rdquo;
  118. fi
  119. }
  120. #
  121. # This function is invoked for each line in the `sticky' values file.
  122. # It will evalutate each line as a dtksh command.
  123. #
  124. EvalCmd()
  125. {
  126. if [ ${#INPUT_LINE} -gt 0 ]; then
  127. eval &ldquo;$INPUT_LINE&rdquo;
  128. fi
  129. if [ &ldquo;$INPUT_EOF&rdquo; = `true' ]; then
  130. XtRemoveInput $INPUT_ID
  131. eval exec $INPUT_SOURCE'&lt;&amp;-'
  132. fi
  133. }
  134. #
  135. # This function retrieves the current values, and then saves them
  136. # off into a file, so that they can be restored the next time the
  137. # dialog is displayed. It is called anytime the user selects either
  138. # the &ldquo;Ok&rdquo; or &ldquo;Apply&rdquo; buttons.
  139. #
  140. RetrieveAndSaveCurrentValues()
  141. {
  142. XmTextGetString SD_VAL $SD
  143. XmTextGetString FNP_VAL $FNP
  144. XtGetValues $FSTYPE menuHistory:FSTYPE_VAL
  145. XtGetValues $FILETYPE menuHistory:FILETYPE_VAL
  146. exec 3> &ldquo;./Find.sticky&rdquo;
  147. if [ ! &ldquo;$SD_VAL&rdquo; = &ldquo;&ldquo; ]; then
  148. print -u 3 &ldquo;XmTextSetString \$SD \&rdquo;$SD_VAL\&rdquo;&rdquo;
  149. print -u 3 &ldquo;XmTextFieldSetInsertionPosition \$SD ${#SD_VAL}&rdquo;
  150. fi
  151. if [ ! &ldquo;$FNP_VAL&rdquo; = &ldquo;&ldquo; ]; then
  152. print -u 3 &ldquo;XmTextSetString \$FNP \&rdquo;$FNP_VAL\&rdquo;&rdquo;
  153. print -u 3 &ldquo;XmTextFieldSetInsertionPosition \$FNP ${#FNP_VAL}&rdquo;
  154. fi
  155. case $FSTYPE_VAL in
  156. $NFS) FST=&rdquo;\$NFS&rdquo; ;;
  157. $CDFS) FST=&rdquo;\$CDFS&rdquo; ;;
  158. $HFS) FST=&rdquo;\$HFS&rdquo; ;;
  159. *) FST=&rdquo;\$NODIR&rdquo; ;;
  160. esac
  161. print -u 3 &ldquo;XtSetValues \$FSTYPE menuHistory:$FST&rdquo;
  162. case $FILETYPE_VAL in
  163. $REGULAR) FT=&rdquo;\$REGULAR&rdquo; ;;
  164. $DIRECTORY) FT=&rdquo;\$DIRECTORY&rdquo; ;;
  165. $BLOCK) FT=&rdquo;\$BLOCK&rdquo; ;;
  166. $CHAR) FT=&rdquo;\$CHAR&rdquo; ;;
  167. $FIFO) FT=&rdquo;\$FIFO&rdquo; ;;
  168. $SYMLINK) FT=&rdquo;\$SYMLINK&rdquo; ;;
  169. $SOCKET) FT=&rdquo;\$SOCKET&rdquo; ;;
  170. $NET) FT=&rdquo;\$NET&rdquo; ;;
  171. $MOUNT) FT=&rdquo;\$MOUNT&rdquo; ;;
  172. $HIDDEN) FT=&rdquo;\$HIDDEN&rdquo; ;;
  173. *) FT=&rdquo;\$NOTYPE&rdquo; ;;
  174. esac
  175. print -u 3 &ldquo;XtSetValues \$FILETYPE menuHistory:$FT&rdquo;
  176. if $(XmToggleButtonGetState $T1); then
  177. print -u 3 &ldquo;XmToggleButtonSetState \$T1 true false&rdquo;
  178. fi
  179. if $(XmToggleButtonGetState $T2); then
  180. print -u 3 &ldquo;XmToggleButtonSetState \$T2 true false&rdquo;
  181. fi
  182. if $(XmToggleButtonGetState $T3); then
  183. print -u 3 &ldquo;XmToggleButtonSetState \$T3 true false&rdquo;
  184. fi
  185. if $(XmToggleButtonGetState $T4); then
  186. print -u 3 &ldquo;XmToggleButtonSetState \$T4 true false&rdquo;
  187. fi
  188. if $(XmToggleButtonGetState $T5); then
  189. print -u 3 &ldquo;XmToggleButtonSetState \$T5 true false&rdquo;
  190. fi
  191. exec 3&lt;&amp;-
  192. }
  193. ################ Create the Main UI ####################
  194. set -f
  195. XtInitialize TOPLEVEL find Dtksh $0 &ldquo;${@:-}&rdquo;
  196. XtSetValues $TOPLEVEL title:&rdquo;Find Files&rdquo;
  197. XtCreateManagedWidget FORM form XmForm $TOPLEVEL
  198. XtCreateManagedWidget SDLABEL sdlabel XmLabel $FORM \
  199. labelString:&rdquo;Search Directory:&rdquo; \
  200. $(DtkshAnchorTop 12) \
  201. $(DtkshAnchorLeft 10)
  202. XtCreateManagedWidget SD sd XmText $FORM \
  203. columns:30 \
  204. value:&rdquo;.&rdquo; \
  205. $(DtkshAnchorTop 6) \
  206. $(DtkshRightOf $SDLABEL 10) \
  207. $(DtkshAnchorRight 10) \
  208. navigationType:EXCLUSIVE_TAB_GROUP
  209. XmTextFieldSetInsertionPosition $SD 1
  210. XtCreateManagedWidget FNPLABEL fnpabel XmLabel $FORM \
  211. labelString:&rdquo;Filename Pattern:&rdquo; \
  212. $(DtkshUnder $SDLABEL 24) \
  213. $(DtkshAnchorLeft 10)
  214. XtCreateManagedWidget FNP fnp XmText $FORM \
  215. columns:30 \
  216. $(DtkshUnder $SD 8) \
  217. $(DtkshRightOf $FNPLABEL 10) \
  218. $(DtkshAnchorRight 10) \
  219. navigationType:EXCLUSIVE_TAB_GROUP
  220. XtCreateManagedWidget SEP sep XmSeparator $FORM \
  221. separatorType:SINGLE_DASHED_LINE \
  222. $(DtkshUnder $FNP 10) \
  223. $(DtkshSpanWidth)
  224. XtCreateManagedWidget RC rc XmRowColumn $FORM \
  225. orientation:HORIZONTAL \
  226. numColumns:3 \
  227. packing:PACK_COLUMN \
  228. $(DtkshUnder $SEP 10) \
  229. $(DtkshSpanWidth 10 10) \
  230. navigationType:EXCLUSIVE_TAB_GROUP
  231. DtkshAddButtons -w $RC XmToggleButtonGadget \
  232. T1 &ldquo;Cross Mount Points&rdquo; &ldquo;&ldquo;\
  233. T2 &ldquo;Print Matching Filenames&rdquo; &ldquo;&ldquo;\
  234. T3 &ldquo;Search Hidden Subdirectories&rdquo; &ldquo;&ldquo;\
  235. T4 &ldquo;Follow Symbolic Links&rdquo; &ldquo;&ldquo;\
  236. T5 &ldquo;Descend Subdirectories First&rdquo; &ldquo;&ldquo;
  237. XtCreateManagedWidget SEP2 sep XmSeparator $FORM \
  238. separatorType:SINGLE_DASHED_LINE \
  239. $(DtkshUnder $RC 10) \
  240. $(DtkshSpanWidth)
  241. XmCreatePulldownMenu PANE $FORM pane
  242. DtkshAddButtons -w $PANE XmPushButtonGadget \
  243. NODIR &ldquo;no restrictions&rdquo; &ldquo;&ldquo;\
  244. NFS &ldquo;nfs&rdquo; &ldquo;&ldquo;\
  245. CDFS &ldquo;cdfs&rdquo; &ldquo;&ldquo;\
  246. HFS &ldquo;hfs&rdquo; &ldquo;&ldquo;
  247. XmCreateOptionMenu FSTYPE $FORM fstype \
  248. labelString:&rdquo;Restrict Search To File System Type:&rdquo; \
  249. menuHistory:$NODIR \
  250. subMenuId:$PANE \
  251. $(DtkshUnder $SEP2 20) \
  252. $(DtkshSpanWidth 10 10) \
  253. navigationType:EXCLUSIVE_TAB_GROUP
  254. XtManageChild $FSTYPE
  255. XmCreatePulldownMenu PANE2 $FORM pane2
  256. DtkshAddButtons -w $PANE2 XmPushButtonGadget \
  257. NOTYPE &ldquo;no restrictions&rdquo; &ldquo;&ldquo;\
  258. REGULAR &ldquo;regular&rdquo; &ldquo;&ldquo;\
  259. DIRECTORY &ldquo;directory&rdquo; &ldquo;&ldquo;\
  260. BLOCK &ldquo;block special&rdquo; &ldquo;&ldquo;\
  261. CHAR &ldquo;character special&rdquo; &ldquo;&ldquo;\
  262. FIFO &ldquo;fifo&rdquo; &ldquo;&ldquo;\
  263. SYMLINK &ldquo;symbolic link&rdquo; &ldquo;&ldquo;\
  264. SOCKET &ldquo;socket&rdquo; &ldquo;&ldquo;\
  265. NET &ldquo;network special&rdquo; &ldquo;&ldquo;\
  266. MOUNT &ldquo;mount point&rdquo; &ldquo;&ldquo;\
  267. HIDDEN &ldquo;hidden directory&rdquo; &ldquo;&ldquo;
  268. XmCreateOptionMenu FILETYPE $FORM filetype \
  269. labelString:&rdquo;Match Only Files Of Type:&rdquo; \
  270. menuHistory:$NOTYPE \
  271. subMenuId:$PANE2 \
  272. $(DtkshUnder $FSTYPE 10) \
  273. $(DtkshSpanWidth 10 10) \
  274. navigationType:EXCLUSIVE_TAB_GROUP
  275. XtManageChild $FILETYPE
  276. XtSetValues $FILETYPE spacing:90
  277. XtCreateManagedWidget SEP3 sep3 XmSeparator $FORM \
  278. $(DtkshUnder $FILETYPE 10) \
  279. $(DtkshSpanWidth)
  280. XtCreateManagedWidget OK ok XmPushButton $FORM \
  281. labelString:&rdquo;Ok&rdquo; \
  282. $(DtkshUnder $SEP3 10) \
  283. $(DtkshFloatLeft 4) \
  284. $(DtkshFloatRight 24) \
  285. $(DtkshAnchorBottom 10)
  286. XtAddCallback $OK activateCallback &ldquo;OkCallback&rdquo;
  287. XtCreateManagedWidget APPLY apply XmPushButton $FORM \
  288. labelString:&rdquo;Apply&rdquo; \
  289. $(DtkshUnder $SEP3 10) \
  290. $(DtkshFloatLeft 28) \
  291. $(DtkshFloatRight 48) \
  292. $(DtkshAnchorBottom 10)
  293. XtAddCallback $APPLY activateCallback &ldquo;OkCallback&rdquo;
  294. XtCreateManagedWidget CLOSE close XmPushButton $FORM \
  295. labelString:&rdquo;Close&rdquo; \
  296. $(DtkshUnder $SEP3 10) \
  297. $(DtkshFloatLeft 52) \
  298. $(DtkshFloatRight 72) \
  299. $(DtkshAnchorBottom 10)
  300. XtAddCallback $CLOSE activateCallback &ldquo;exit 1&rdquo;
  301. XtCreateManagedWidget HELP help XmPushButton $FORM \
  302. labelString:&rdquo;Help&rdquo; \
  303. $(DtkshUnder $SEP3 10) \
  304. $(DtFloatLeft 76) \
  305. $(DtkshFloatRight 96) \
  306. $(DtkshAnchorBottom 10)
  307. XtAddCallback $HELP activateCallback \
  308. &ldquo;DtkshDisplayQuickHelpDialog `Using The Find Command'
  309. HELP_TYPE_FILE \
  310. `./Find.help' &ldquo;
  311. XtSetValues $FORM \
  312. initialFocus:$SD \
  313. defaultButton:$OK \
  314. cancelButton:$CLOSE \
  315. navigationType:EXCLUSIVE_TAB_GROUP
  316. DtkshSetReturnKeyControls $SD $FNP $FORM $OK
  317. LoadStickyValues
  318. XtRealizeWidget $TOPLEVEL
  319. XtMainLoop</programlisting>
  320. </sect1>
  321. <sect1 id="DKSUG.finds.div.3">
  322. <title>Find.sticky</title>
  323. <para>次のスクリプト<indexterm><primary>Find.sticky</primary></indexterm><filename>Find.sticky</filename>は、<filename>script_find</filename>によって実行されます。
  324. <filename>Find.sticky</filename>は、最も最近に<filename>script_find</filename>を実行した時に
  325. 使用したファイルとディレクトリ名を記録します。</para>
  326. <programlisting>XmTextSetString $SD &ldquo;/users/dlm&rdquo;
  327. XmTextFieldSetInsertionPosition $SD 10
  328. XmTextSetString $FNP &ldquo;elmbug&rdquo;
  329. XmTextFieldSetInsertionPosition $FNP 6
  330. XtSetValues $FSTYPE menuHistory:$NODIR
  331. XtSetValues $FILETYPE menuHistory:$DIRECTORY
  332. XmToggleButtonSetState $T1 true false
  333. XmToggleButtonSetState $T2 true false</programlisting>
  334. </sect1>
  335. <sect1 id="DKSUG.finds.div.4">
  336. <title>Find.help</title>
  337. <para><filename>Find.help</filename>は、メインの<filename>script_find</filename>ウィンドウの[ヘルプ]ボタンを
  338. クリックすると画面に表示されるテキスト・ファイルです。</para>
  339. <programlisting>This dialog presents a graphical interface to the
  340. UNIX `find' command. The only required field is
  341. the name of the directory to be searched;
  342. all other fields are optional. Once the fields have
  343. been set to the desired values, you can use the
  344. `Ok' or `Apply' button to initiate the find operation.
  345. The results of the find operation are displayed
  346. in a dtterm terminal window.</programlisting>
  347. </sect1>
  348. </appendix>
  349. <!--fickle 1.14 mif-to-docbook 1.7 01/02/96 10:26:11-->
  350. <?Pub Caret>
  351. <?Pub *0000015484>