405 lines
14 KiB
Plaintext
405 lines
14 KiB
Plaintext
<!-- $XConsortium: appc.sgm /main/7 1996/09/08 19:45:21 rws $ -->
|
|
<!-- (c) Copyright 1995 Digital Equipment Corporation. -->
|
|
<!-- (c) Copyright 1995 Hewlett-Packard Company. -->
|
|
<!-- (c) Copyright 1995 International Business Machines Corp. -->
|
|
<!-- (c) Copyright 1995 Sun Microsystems, Inc. -->
|
|
<!-- (c) Copyright 1995 Novell, Inc. -->
|
|
<!-- (c) Copyright 1995 FUJITSU LIMITED. -->
|
|
<!-- (c) Copyright 1995 Hitachi. -->
|
|
<appendix id="DKSUG.finds.div.1">
|
|
<title>The script_findスクリプト</title>
|
|
<para>この付録には、第4章「複雑なスクリプト」で説明されている<filename>script_find</filename>の全リストが
|
|
掲載されています。このスクリプトは、<indexterm><primary>script_find</primary></indexterm><filename>script_find</filename>の後にリストされている<filename>Find.sticky</filename>と呼ばれるという従属的な
|
|
スクリプトを実行します。
|
|
メイン・スクリプト・ウィンドウの[ヘルプ]ボタンをクリックするとアクセスされる<filename>Find.help</filename>と呼ばれるテキスト・フィールドもあります。
|
|
このスクリプトのより詳細な情報は、第4章を参照してください。
|
|
</para>
|
|
<sect1 id="DKSUG.finds.div.2">
|
|
<title>script_findのリスト</title>
|
|
<programlisting>#! /usr/dt/bin/dtksh
|
|
set -u
|
|
|
|
. /usr/dt/lib/dtksh/DtFuncs.dtsh
|
|
|
|
#
|
|
# This sample shell script provides a graphical interface to the
|
|
# `find' command. Each time it is executed, it will attempt to
|
|
# restore the dialog to the last set of values entered by the user.
|
|
# When the `find' command is initiated, the output will be displayed
|
|
# in a dtterm window.
|
|
#
|
|
|
|
#
|
|
# Post an# error dialog. The main application window is disabled
|
|
# until the error dialog is unposted. The message to be displayed
|
|
# in the # error dialog is passed in as $1
|
|
#
|
|
PostErrorDialog()
|
|
{
|
|
DtDisplayErrorDialog “Find Error” “$1” \
|
|
DIALOG_PRIMARY_APPLICATION_MODAL
|
|
}
|
|
|
|
#
|
|
# This is both the `Ok' and the `Apply' callback; in the case of the
|
|
# `Ok' callback, it unposts the main application window, and then
|
|
# exits, if the dialog contains valid information. For both `Ok' and
|
|
# `Apply', the set of search directories is first validated; if any
|
|
# of the paths are not valid, then an error dialog is posted.
|
|
# Otherwise, the `find' process is started in a terminal window.
|
|
#
|
|
OkCallback()
|
|
{
|
|
RetrieveAndSaveCurrentValues
|
|
if [ “$SD_VAL” = ““ ]; then
|
|
PostErrorDialog “You must specify a directory to search”
|
|
else
|
|
for i in $SD_VAL; do
|
|
if [ ! -d $i ]; then
|
|
MSG=”The following search directory does not exist:
|
|
|
|
$i”
|
|
PostErrorDialog “$MSG”
|
|
return 1
|
|
fi
|
|
done
|
|
|
|
if [ $CB_WIDGET = $OK ]; then
|
|
XtPopdown $TOPLEVEL
|
|
fi
|
|
|
|
CMD=”/bin/find $SD_VAL”
|
|
if [ ! “$FNP_VAL” = ““ ]; then
|
|
CMD=$CMD” -name $FNP_VAL”
|
|
fi
|
|
|
|
if ! $(XmToggleButtonGetState $T1); then
|
|
CMD=$CMD” -xdev”
|
|
fi
|
|
|
|
if $(XmToggleButtonGetState $T3); then
|
|
CMD=$CMD” -hidden”
|
|
fi
|
|
|
|
if $(XmToggleButtonGetState $T4); then
|
|
CMD=$CMD” -follow”
|
|
fi
|
|
|
|
if $(XmToggleButtonGetState $T5); then
|
|
CMD=$CMD” -depth”
|
|
fi
|
|
|
|
case $FSTYPE_VAL in
|
|
$NFS) CMD=$CMD” -fsonly nfs” ;;
|
|
$CDFS) CMD=$CMD” -fsonly cdfs” ;;
|
|
$HFS) CMD=$CMD” -fsonly hfs” ;;
|
|
*) ;;
|
|
esac
|
|
|
|
case $FILETYPE_VAL in
|
|
$REGULAR) CMD=$CMD” -type f” ;;
|
|
$DIRECTORY) CMD=$CMD” -type d” ;;
|
|
$BLOCK) CMD=$CMD” -type b” ;;
|
|
$CHAR) CMD=$CMD” -type c” ;;
|
|
$FIFO) CMD=$CMD” -type p” ;;
|
|
$SYMLINK) CMD=$CMD” -type l” ;;
|
|
$SOCKET) CMD=$CMD” -type s” ;;
|
|
$NET) CMD=$CMD” -type n” ;;
|
|
$MOUNT) CMD=$CMD” -type M” ;;
|
|
$HIDDEN) CMD=$CMD” -type H” ;;
|
|
*) ;;
|
|
esac
|
|
|
|
if $(XmToggleButtonGetState $T2); then
|
|
CMD=$CMD” -print”
|
|
fi
|
|
|
|
/usr/dt/bin/dtterm -title “Find A File” -e /usr/dt/bin/dtexec
|
|
-open -1 $CMD &
|
|
|
|
if [ $CB_WIDGET = $OK ]; then
|
|
exit 0
|
|
fi
|
|
fi
|
|
}
|
|
|
|
#
|
|
# This function attempts to load in the previous dialog values.
|
|
# Each line read from the file is then interpreted as a ksh command.
|
|
#
|
|
LoadStickyValues()
|
|
{
|
|
if [ -r “./Find.sticky” ]; then
|
|
exec 6< “./Find.sticky”
|
|
XtAddInput FID 6 “EvalCmd”
|
|
fi
|
|
}
|
|
|
|
#
|
|
# This function is invoked for each line in the `sticky' values file.
|
|
# It will evalutate each line as a dtksh command.
|
|
#
|
|
EvalCmd()
|
|
{
|
|
if [ ${#INPUT_LINE} -gt 0 ]; then
|
|
eval “$INPUT_LINE”
|
|
fi
|
|
|
|
if [ “$INPUT_EOF” = `true' ]; then
|
|
XtRemoveInput $INPUT_ID
|
|
eval exec $INPUT_SOURCE'<&-'
|
|
fi
|
|
}
|
|
|
|
#
|
|
# This function retrieves the current values, and then saves them
|
|
# off into a file, so that they can be restored the next time the
|
|
# dialog is displayed. It is called anytime the user selects either
|
|
# the “Ok” or “Apply” buttons.
|
|
#
|
|
RetrieveAndSaveCurrentValues()
|
|
{
|
|
XmTextGetString SD_VAL $SD
|
|
XmTextGetString FNP_VAL $FNP
|
|
XtGetValues $FSTYPE menuHistory:FSTYPE_VAL
|
|
XtGetValues $FILETYPE menuHistory:FILETYPE_VAL
|
|
|
|
exec 3> “./Find.sticky”
|
|
if [ ! “$SD_VAL” = ““ ]; then
|
|
print -u 3 “XmTextSetString \$SD \”$SD_VAL\””
|
|
print -u 3 “XmTextFieldSetInsertionPosition \$SD ${#SD_VAL}”
|
|
fi
|
|
if [ ! “$FNP_VAL” = ““ ]; then
|
|
print -u 3 “XmTextSetString \$FNP \”$FNP_VAL\””
|
|
print -u 3 “XmTextFieldSetInsertionPosition \$FNP ${#FNP_VAL}”
|
|
fi
|
|
|
|
case $FSTYPE_VAL in
|
|
$NFS) FST=”\$NFS” ;;
|
|
$CDFS) FST=”\$CDFS” ;;
|
|
$HFS) FST=”\$HFS” ;;
|
|
*) FST=”\$NODIR” ;;
|
|
esac
|
|
print -u 3 “XtSetValues \$FSTYPE menuHistory:$FST”
|
|
|
|
case $FILETYPE_VAL in
|
|
$REGULAR) FT=”\$REGULAR” ;;
|
|
$DIRECTORY) FT=”\$DIRECTORY” ;;
|
|
$BLOCK) FT=”\$BLOCK” ;;
|
|
$CHAR) FT=”\$CHAR” ;;
|
|
$FIFO) FT=”\$FIFO” ;;
|
|
$SYMLINK) FT=”\$SYMLINK” ;;
|
|
$SOCKET) FT=”\$SOCKET” ;;
|
|
$NET) FT=”\$NET” ;;
|
|
$MOUNT) FT=”\$MOUNT” ;;
|
|
$HIDDEN) FT=”\$HIDDEN” ;;
|
|
*) FT=”\$NOTYPE” ;;
|
|
esac
|
|
print -u 3 “XtSetValues \$FILETYPE menuHistory:$FT”
|
|
|
|
if $(XmToggleButtonGetState $T1); then
|
|
print -u 3 “XmToggleButtonSetState \$T1 true false”
|
|
fi
|
|
|
|
if $(XmToggleButtonGetState $T2); then
|
|
print -u 3 “XmToggleButtonSetState \$T2 true false”
|
|
fi
|
|
|
|
if $(XmToggleButtonGetState $T3); then
|
|
print -u 3 “XmToggleButtonSetState \$T3 true false”
|
|
fi
|
|
|
|
if $(XmToggleButtonGetState $T4); then
|
|
print -u 3 “XmToggleButtonSetState \$T4 true false”
|
|
fi
|
|
|
|
if $(XmToggleButtonGetState $T5); then
|
|
print -u 3 “XmToggleButtonSetState \$T5 true false”
|
|
fi
|
|
|
|
exec 3<&-
|
|
}
|
|
|
|
|
|
################ Create the Main UI ####################
|
|
|
|
set -f
|
|
XtInitialize TOPLEVEL find Dtksh $0 “${@:-}”
|
|
XtSetValues $TOPLEVEL title:”Find Files”
|
|
|
|
XtCreateManagedWidget FORM form XmForm $TOPLEVEL
|
|
|
|
XtCreateManagedWidget SDLABEL sdlabel XmLabel $FORM \
|
|
labelString:”Search Directory:” \
|
|
$(DtkshAnchorTop 12) \
|
|
$(DtkshAnchorLeft 10)
|
|
|
|
XtCreateManagedWidget SD sd XmText $FORM \
|
|
columns:30 \
|
|
value:”.” \
|
|
$(DtkshAnchorTop 6) \
|
|
$(DtkshRightOf $SDLABEL 10) \
|
|
$(DtkshAnchorRight 10) \
|
|
navigationType:EXCLUSIVE_TAB_GROUP
|
|
XmTextFieldSetInsertionPosition $SD 1
|
|
|
|
XtCreateManagedWidget FNPLABEL fnpabel XmLabel $FORM \
|
|
labelString:”Filename Pattern:” \
|
|
$(DtkshUnder $SDLABEL 24) \
|
|
$(DtkshAnchorLeft 10)
|
|
|
|
XtCreateManagedWidget FNP fnp XmText $FORM \
|
|
columns:30 \
|
|
$(DtkshUnder $SD 8) \
|
|
$(DtkshRightOf $FNPLABEL 10) \
|
|
$(DtkshAnchorRight 10) \
|
|
navigationType:EXCLUSIVE_TAB_GROUP
|
|
|
|
XtCreateManagedWidget SEP sep XmSeparator $FORM \
|
|
separatorType:SINGLE_DASHED_LINE \
|
|
$(DtkshUnder $FNP 10) \
|
|
$(DtkshSpanWidth)
|
|
|
|
XtCreateManagedWidget RC rc XmRowColumn $FORM \
|
|
orientation:HORIZONTAL \
|
|
numColumns:3 \
|
|
packing:PACK_COLUMN \
|
|
$(DtkshUnder $SEP 10) \
|
|
$(DtkshSpanWidth 10 10) \
|
|
navigationType:EXCLUSIVE_TAB_GROUP
|
|
|
|
DtkshAddButtons -w $RC XmToggleButtonGadget \
|
|
T1 “Cross Mount Points” ““\
|
|
T2 “Print Matching Filenames” ““\
|
|
T3 “Search Hidden Subdirectories” ““\
|
|
T4 “Follow Symbolic Links” ““\
|
|
T5 “Descend Subdirectories First” ““
|
|
|
|
XtCreateManagedWidget SEP2 sep XmSeparator $FORM \
|
|
separatorType:SINGLE_DASHED_LINE \
|
|
$(DtkshUnder $RC 10) \
|
|
$(DtkshSpanWidth)
|
|
|
|
XmCreatePulldownMenu PANE $FORM pane
|
|
DtkshAddButtons -w $PANE XmPushButtonGadget \
|
|
NODIR “no restrictions” ““\
|
|
NFS “nfs” ““\
|
|
CDFS “cdfs” ““\
|
|
HFS “hfs” ““
|
|
|
|
XmCreateOptionMenu FSTYPE $FORM fstype \
|
|
labelString:”Restrict Search To File System Type:” \
|
|
menuHistory:$NODIR \
|
|
subMenuId:$PANE \
|
|
$(DtkshUnder $SEP2 20) \
|
|
$(DtkshSpanWidth 10 10) \
|
|
navigationType:EXCLUSIVE_TAB_GROUP
|
|
XtManageChild $FSTYPE
|
|
|
|
XmCreatePulldownMenu PANE2 $FORM pane2
|
|
DtkshAddButtons -w $PANE2 XmPushButtonGadget \
|
|
NOTYPE “no restrictions” ““\
|
|
REGULAR “regular” ““\
|
|
DIRECTORY “directory” ““\
|
|
BLOCK “block special” ““\
|
|
CHAR “character special” ““\
|
|
FIFO “fifo” ““\
|
|
SYMLINK “symbolic link” ““\
|
|
SOCKET “socket” ““\
|
|
NET “network special” ““\
|
|
MOUNT “mount point” ““\
|
|
HIDDEN “hidden directory” ““
|
|
|
|
XmCreateOptionMenu FILETYPE $FORM filetype \
|
|
labelString:”Match Only Files Of Type:” \
|
|
menuHistory:$NOTYPE \
|
|
subMenuId:$PANE2 \
|
|
$(DtkshUnder $FSTYPE 10) \
|
|
$(DtkshSpanWidth 10 10) \
|
|
navigationType:EXCLUSIVE_TAB_GROUP
|
|
XtManageChild $FILETYPE
|
|
XtSetValues $FILETYPE spacing:90
|
|
|
|
XtCreateManagedWidget SEP3 sep3 XmSeparator $FORM \
|
|
$(DtkshUnder $FILETYPE 10) \
|
|
$(DtkshSpanWidth)
|
|
|
|
XtCreateManagedWidget OK ok XmPushButton $FORM \
|
|
labelString:”Ok” \
|
|
$(DtkshUnder $SEP3 10) \
|
|
$(DtkshFloatLeft 4) \
|
|
$(DtkshFloatRight 24) \
|
|
$(DtkshAnchorBottom 10)
|
|
XtAddCallback $OK activateCallback “OkCallback”
|
|
|
|
XtCreateManagedWidget APPLY apply XmPushButton $FORM \
|
|
labelString:”Apply” \
|
|
$(DtkshUnder $SEP3 10) \
|
|
$(DtkshFloatLeft 28) \
|
|
$(DtkshFloatRight 48) \
|
|
$(DtkshAnchorBottom 10)
|
|
XtAddCallback $APPLY activateCallback “OkCallback”
|
|
|
|
XtCreateManagedWidget CLOSE close XmPushButton $FORM \
|
|
labelString:”Close” \
|
|
$(DtkshUnder $SEP3 10) \
|
|
$(DtkshFloatLeft 52) \
|
|
$(DtkshFloatRight 72) \
|
|
$(DtkshAnchorBottom 10)
|
|
XtAddCallback $CLOSE activateCallback “exit 1”
|
|
|
|
XtCreateManagedWidget HELP help XmPushButton $FORM \
|
|
labelString:”Help” \
|
|
$(DtkshUnder $SEP3 10) \
|
|
$(DtFloatLeft 76) \
|
|
$(DtkshFloatRight 96) \
|
|
$(DtkshAnchorBottom 10)
|
|
XtAddCallback $HELP activateCallback \
|
|
“DtkshDisplayQuickHelpDialog `Using The Find Command'
|
|
HELP_TYPE_FILE \
|
|
`./Find.help' “
|
|
|
|
XtSetValues $FORM \
|
|
initialFocus:$SD \
|
|
defaultButton:$OK \
|
|
cancelButton:$CLOSE \
|
|
navigationType:EXCLUSIVE_TAB_GROUP
|
|
|
|
DtkshSetReturnKeyControls $SD $FNP $FORM $OK
|
|
LoadStickyValues
|
|
|
|
XtRealizeWidget $TOPLEVEL
|
|
XtMainLoop</programlisting>
|
|
</sect1>
|
|
<sect1 id="DKSUG.finds.div.3">
|
|
<title>Find.sticky</title>
|
|
<para>次のスクリプト<indexterm><primary>Find.sticky</primary></indexterm><filename>Find.sticky</filename>は、<filename>script_find</filename>によって実行されます。
|
|
<filename>Find.sticky</filename>は、最も最近に<filename>script_find</filename>を実行した時に
|
|
使用したファイルとディレクトリ名を記録します。</para>
|
|
<programlisting>XmTextSetString $SD “/users/dlm”
|
|
XmTextFieldSetInsertionPosition $SD 10
|
|
XmTextSetString $FNP “elmbug”
|
|
XmTextFieldSetInsertionPosition $FNP 6
|
|
XtSetValues $FSTYPE menuHistory:$NODIR
|
|
XtSetValues $FILETYPE menuHistory:$DIRECTORY
|
|
XmToggleButtonSetState $T1 true false
|
|
XmToggleButtonSetState $T2 true false</programlisting>
|
|
</sect1>
|
|
<sect1 id="DKSUG.finds.div.4">
|
|
<title>Find.help</title>
|
|
<para><filename>Find.help</filename>は、メインの<filename>script_find</filename>ウィンドウの[ヘルプ]ボタンを
|
|
クリックすると画面に表示されるテキスト・ファイルです。</para>
|
|
<programlisting>This dialog presents a graphical interface to the
|
|
UNIX `find' command. The only required field is
|
|
the name of the directory to be searched;
|
|
all other fields are optional. Once the fields have
|
|
been set to the desired values, you can use the
|
|
`Ok' or `Apply' button to initiate the find operation.
|
|
The results of the find operation are displayed
|
|
in a dtterm terminal window.</programlisting>
|
|
</sect1>
|
|
</appendix>
|
|
<!--fickle 1.14 mif-to-docbook 1.7 01/02/96 10:26:11-->
|
|
<?Pub Caret>
|
|
<?Pub *0000015484>
|