The script's window allows you to specify a search directory and a file name. Other options allow you to place restrictions on the type of file system to search and the file type on which to match. Figure 4-1 shows the script's window.
Figure 4-1 Window for script_find
Enter the search directory and file name you're looking for in the text fields at the top of the window. In addition, select any applicable choice (or choices) from the five toggle buttons. You can further restrict the search with the option menus. When you have made all the necessary selections, click OK. If all is well, a window appears shortly thereafter and displays the results of the find operation. An error dialog appears if you don't specify a search directory or file name, or if the specified search directory is invalid. For example, suppose you want to find a file called two_letter_calls, and you think it resides somewhere in the directory /users/dlm. When you enter the directory in the Search Directory text field, you inadvertently type /users/dln instead of /users/dlm. When you click OK or Apply, script_find can't find the directory /users/dln, so it creates the error dialog to notify you of this.
Figure 4-2 script_find error dialog
When you correct the mistake, script_find then executes properly and creates a dtterm window within which it displays the complete path of the file you requested, providing that the file is found.
Figure 4-3 Window showing complete path
If script_find cannot find the file in the specified directory, nothing appears in the dtterm window.
The first two lines of the script are important, and should be included in every dtksh script you write:
#! /usr/dt/bin/dtksh
. /usr/dt/lib/dtksh/DtFunc.dtsh
The first line executes the dtksh system and the second loads the dtksh convenience functions. The second line wasn't used in the scripts described in Chapter 2 because those scripts did not use any dtksh convenience functions.
dialogPostErrorDialog()
{
DtDisplayErrorDialog "Find Error" "$1" \
DIALOG_PRIMARY_APPLICATION_MODAL
}
The last parameter, DIALOG_PRIMARY_APPLICATION_MODAL
, tells dtksh to create a dialog that must be responded to before any other interaction can occur.
XmTextSetString $SD "/users/dlm"
XmTextFieldSetInsertionPosition $SD 10
XmTextSetString $FNP "two_letter_calls"
XmTextFieldSetInsertionPosition $FNP 16
XtSetValues $FSTYPE menuHistory:$NODIR
XtSetValues $FILETYPE menuHistory:$NOTYPE
XmToggleButtonSetState $T2 true false
XmToggleButtonSetState $T4 true false
The script_find window (see Figure 4-4) consists of a Form widget with four areas. The areas are marked by Separator widgets, and each area has several widgets, all of which are children of the Form.
Figure 4-4 Widgets in script_find window
The widgets are created in sequence by area, from top to bottom.
XtInitialize TOPLEVEL find Dtksh $0 "${@:-}"
This creates a top-level shell that serves as the parent of a Form widget, which is created next.Figure 4-5 First area of script_find Window
The following code segment creates and positions the first Label widget and positions it within the Form using the DtkshAnchorTop and DtkshAnchorLeft convenience functions:
XtCreateManagedWidget SDLABEL sdlabel XmLabel $FORM \
labelString:"Search Directory:" \
$(DtkshAnchorTop 12) \
$(DtkshAnchorLeft 10)
The following code segment creates and positions the first TextField widget. Note that it is positioned in relation to both the Form and the Label widget.
XtCreateManagedWidget SD sd XmText $FORM \
columns:30 \
value:"." \
$(DtkshAnchorTop 6) \
$(DtkshRightOf $SDLABEL 10) \
$(DtkshAnchorRight 10) \
navigationType:EXCLUSIVE_TAB_GROUP
XmTextFieldSetInsertionPosition $SD 1
The remaining Label widget and TextField widget are created in the same manner.The Separator widget is created as a child of the Form widget and positioned under the second TextField widget.
XtCreateManagedWidget SEP sep XmSeparator $FORM \
separatorType:SINGLE_DASHED_LINE \
$(DtkshUnder $FNP 10) \
$(DtkshSpanWidth)
Figure 4-6 Second Area of script_find Window
A gadget is a widget that relies on its parent for many of its attributes, thus saving memory resources.
The RowColumn widget is created as a child of the Form widget, and positioned directly under the Separator widget created in the first area.
The five ToggleButton gadgets are created as children of the RowColumn using the convenience function DtkshAddButtons: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" ""
Another Separator is then created to separate the second and third areas. Note that this Separator widget ID is called SEP2.
XtCreateManagedWidget SEP2 sep XmSeparator $FORM \
separatorType:SINGLE_DASHED_LINE \
$(DtkshUnder $RC 10) \
$(DtkshSpanWidth)
Figure 4-7 Third area of script_find Window
The Option Menus are pull-down menus. When the user clicks the option menu button, a menu pane with a number of choices appears. The user drags the pointer to the appropriate choice and releases the mouse button. The menu pane disappears and the option menu button label displays the new choice.
The first option menu menu pane consists of a number of push button gadgets, representing various restrictions that can be imposed upon the find command:
XmCreatePulldownMenu PANE $FORM pane
DtkshAddButtons -w $PANE XmPushButtonGadget \
NODIR "no restrictions" ""\
NFS "nfs" ""\
CDFS "cdfs" ""\
HFS "hfs" ""
Next, the Option Menu button itself is created and managed, with the menu pane just created ($PANE) identified as a subMenuId:
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
The second option menu button is created in the same manner. It provides further restrictions on the find command.The third separator is created in the same manner as the other separators.
The four push buttons are used as follows:
XtCreateManagedWidget OK ok XmPushButton $FORM \
labelString:"Ok" \
$(DtkshUnder $SEP3 10) \
$(DtkshFloatLeft 4) \
$(DtkshFloatRight 24) \
$(DtkshAnchorBottom 10)
XtAddCallback $OK activateCallback "OkCallback"
XtSetValues $FORM \
initialFocus:$SD \
defaultButton:$OK \
cancelButton:$CLOSE \
navigationType:EXCLUSIVE_TAB_GROUP
EXCLUSIVE_TAB_GROUP.
EXCLUSIVE_TAB_GROUP
in Appendix B for more information on its use.
DtkshSetReturnKeyControls $SD $FNP $FORM $OK
LoadStickyValues
XtRealizeWidget $TOPLEVEL
XtMainLoop