3 #######################################################################
7 # The shell-script which implements dtcreate (a.k.a. CreateAction).
9 # Hewlett-Packard Visual User Environment
11 # Copyright (c) 1990 Hewlett-Packard Company
13 # @(#) $XConsortium: dtcreate.sh /main/3 1995/11/01 16:13:20 rswiston $
15 ######################################################################
17 #####################################################################
19 # determine_system - determines the system name and then sets
20 # the global variables _SIGUSR1 and _SIGUSR2 accordingly.
42 #####################################################################
44 # getvalue accepts two arguments, the name of the resource whose
45 # value is desired and the name of the file where it is contained.
46 # The value of the resource is returned in $VALUE.
50 VALUE=`grep $1 $2 | sed -e "s/[^:]*: *//"`
55 # Sending SIGUSR1 to the dtdialog process tells it to reenable
60 toggleinvaliddialog ()
62 # Sending SIGIUSR2 to the dtdialog process tells it to either
63 # go to the invalid state (put up the invalid cursor) or go
64 # back to its previous state (either active or busy).
70 # Sending SIGINT to the dtdialog process tells it to remove the
75 ##############################################################
77 # checkprocess accepts a single argument with is a process-id.
78 # If the specified process is running (as reported by ps -ef),
79 # checkprocess returns 1. If it isn't running, checkprocess
84 RUNNING=`ps -ef | cut -c 9-14 | grep -c $1`
86 if [ "$RUNNING" = "0" ] ; then
93 # This is the main callback that is called whenever the user presses
94 # one of the buttons on the CreateAction dialog.
97 # Check which button on the dialog was invoked. The Help button
98 # is automatically handled by dtdialog, so it is only the apply
99 # and close buttons that we care about.
100 getvalue selectedButton $DIALOG_OUTPUT
102 if [ "$VALUE" = "apply" ] ; then
111 # Read all the values in from the dialog.
112 getvalue windowId $DIALOG_OUTPUT
113 CREATEACTION_WID=$VALUE
115 getvalue name.text $DIALOG_OUTPUT
118 getvalue largeIcon.text $DIALOG_OUTPUT
121 getvalue smallIcon.text $DIALOG_OUTPUT
124 getvalue description.text $DIALOG_OUTPUT
125 DESCRIPTION=`echo $VALUE | tr -s "\012" " "`
127 getvalue commandLine.text $DIALOG_OUTPUT
130 getvalue prompt.text $DIALOG_OUTPUT
133 getvalue commandType.active $DIALOG_OUTPUT
134 if [ "$VALUE" = "xWin" -o "$VALUE" = "noOut" ] ; then
135 WINDOWTYPE="NO_STDIO"
136 elif [ "$VALUE" = "term" ] ; then
137 WINDOWTYPE="PERM_TERMINAL"
139 WINDOWTYPE="TERMINAL"
143 # Make sure that an action name and an exec-string were provided.
144 if [ ! "$BAIL_OUT" -a ! "$ACTION" -a ! "$EXECSTRING" ] ; then
145 dtdialog -descFile dtcreate.ddf -dialogName noNameOrExec \
146 -transientFor $CREATEACTION_WID &
147 SECONDARY_DIALOG_PIDS[${NUM_SECONDARY_DIALOGS}]=$!
148 let NUM_SECONDARY_DIALOGS=${NUM_SECONDARY_DIALOGS}+1
149 enabledialog $CREATEACTION_PID
153 if [ ! "$BAIL_OUT" -a ! "$ACTION" ] ; then
154 dtdialog -descFile dtcreate.ddf -dialogName noName \
155 -transientFor $CREATEACTION_WID &
156 SECONDARY_DIALOG_PIDS[${NUM_SECONDARY_DIALOGS}]=$!
157 let NUM_SECONDARY_DIALOGS=${NUM_SECONDARY_DIALOGS}+1
158 enabledialog $CREATEACTION_PID
162 if [ ! "$BAIL_OUT" -a ! "$EXECSTRING" ] ; then
163 dtdialog -descFile dtcreate.ddf -dialogName noExecString \
164 -transientFor $CREATEACTION_WID &
165 SECONDARY_DIALOG_PIDS[${NUM_SECONDARY_DIALOGS}]=$!
166 let NUM_SECONDARY_DIALOGS=${NUM_SECONDARY_DIALOGS}+1
167 enabledialog $CREATEACTION_PID
171 # Make sure the action name does not contain any blanks.
172 if [ ! "$BAIL_OUT" -a `echo $ACTION | grep -c ' '` -eq 1 ] ; then
173 dtdialog -descFile dtcreate.ddf -dialogName foundBlank \
174 -transientFor $CREATEACTION_WID &
175 SECONDARY_DIALOG_PIDS[${NUM_SECONDARY_DIALOGS}]=$!
176 let NUM_SECONDARY_DIALOGS=${NUM_SECONDARY_DIALOGS}+1
177 enabledialog $CREATEACTION_PID
181 if [ ! "$BAIL_OUT" ] ; then
182 # Check the vf file we want to write to. If it exists and
183 # isn't writable, complain.
184 VF_DIR=$HOME/.dt/types
185 # Hack warning! Do temporary dt stuff.
186 if [[ $doDT = 1 ]] then
187 VF_FILE=$VF_DIR/$ACTION.dt
189 VF_FILE=$VF_DIR/$ACTION.vf
191 if [ -f $VF_FILE -a ! -w $VF_FILE ] ; then
192 dtdialog -descFile dtcreate.ddf \
193 -dialogName notWritable \
194 -transientFor $CREATEACTION_WID \
196 SECONDARY_DIALOG_PIDS[${NUM_SECONDARY_DIALOGS}]=$!
197 let NUM_SECONDARY_DIALOGS=${NUM_SECONDARY_DIALOGS}+1
198 enabledialog $CREATEACTION_PID
203 # Check if the action name is longer than 11 characters.
204 # If so, warn about the problems with short filename
205 # systems and give the user a chance to change it. This is a
206 # modal dialog (not run in background) because the user has to
208 if [ ! "$BAIL_OUT" -a `echo $ACTION | wc -c` -gt 11 ] ; then
209 toggleinvaliddialog $CREATEACTION_PID
210 dtdialog -descFile dtcreate.ddf \
211 -dialogName longName \
212 -transientFor $CREATEACTION_WID $ACTION
214 if [ $? -eq 2 ] ; then
215 enabledialog $CREATEACTION_PID
218 toggleinvaliddialog $CREATEACTION_PID
222 # Check that if the exec-string uses any shell features (e.g. pipes),
223 # that a shell is explicitly specified.
224 if [ ! "$BAIL_OUT" -a `echo $EXECSTRING | grep -c '[|&;<>]'` -eq 1 -a\
225 ! `echo $EXECSTRING | grep -c 'sh '` -eq 1 ] ; \
227 dtdialog -descFile dtcreate.ddf -dialogName needShell \
228 -transientFor $CREATEACTION_WID &
229 SECONDARY_DIALOG_PIDS[${NUM_SECONDARY_DIALOGS}]=$!
230 let NUM_SECONDARY_DIALOGS=${NUM_SECONDARY_DIALOGS}+1
231 enabledialog $CREATEACTION_PID
235 # Check that the prompt string does not contain quotes. I
236 # think there is a bug here that a single backquote (`) is not
237 # detected. I need to figure out the correct grep expression
239 QUOTES=`echo \'$PROMPT\' | tr '!$%&(-\\\/"' '%%%%%%%%%' | fgrep -c %`
240 if [ ! "$BAIL_OUT" -a $QUOTES -eq 1 ] ; then
241 dtdialog -descFile dtcreate.ddf \
242 -transientFor $CREATEACTION_WID \
243 -dialogName promptQuote &
244 SECONDARY_DIALOG_PIDS[${NUM_SECONDARY_DIALOGS}]=$!
245 let NUM_SECONDARY_DIALOGS=${NUM_SECONDARY_DIALOGS}+1
246 enabledialog $CREATEACTION_PID
250 # Check that if a prompt is supplied, that the action calls for
252 if [ ! "$BAIL_OUT" ] ; then
254 `echo $EXECSTRING | grep -c "\$[*0-9]"` -eq 0 ] ; then
255 dtdialog -descFile dtcreate.ddf \
256 -transientFor $CREATEACTION_WID \
257 -dialogName unusedPrompt &
258 SECONDARY_DIALOG_PIDS[${NUM_SECONDARY_DIALOGS}]=$!
259 let NUM_SECONDARY_DIALOGS=${NUM_SECONDARY_DIALOGS}+1
260 enabledialog $CREATEACTION_PID
265 # If no errors were caught, create the action and reenable the
267 if [ ! "$BAIL_OUT" ] ; then
269 enabledialog $CREATEACTION_PID
275 # If the vf file already exists, we are going to copy it to a temp
276 # file and comment out the definition for the current action.
277 # Make sure that this temp file doesn't already exist so that an old
278 # one doesn't get used by mistake.
279 OLD_FILE=/tmp/`basename $0`2_$$
281 if [ -w $VF_FILE ] ; then
282 sed -e "/^ACTION ${ACTION}[ ]*$/,/^[END|}]/s/^/\# /" \
283 ${VF_FILE} > ${OLD_FILE}
286 # Write out the new action definition.
287 echo "\n#\n# Action created by dtcreate\n#" > $VF_FILE
288 echo "ACTION $ACTION" > $VF_FILE
291 if [ "${LICON}" ] ; then
292 echo "\tLARGE_ICON\t\t$LICON" >> $VF_FILE
295 if [ "${SICON}" ] ; then
296 echo "\tSMALL_ICON\t\t$SICON" >> $VF_FILE
299 if [ "${DESCRIPTION}" ] ; then
300 echo "\tDESCRIPTION\t$DESCRIPTION" >> $VF_FILE
303 echo "\tTYPE\t\tCOMMAND" >>$VF_FILE
305 if [ "${EXECSTRING}" ] ; then
306 # Process the exec-string and look for $*, $1, $2, etc.
307 # These must be translated into DT's syntax of
308 # %(File)Arg_n%. Also insert the prompt string if one
310 echo "\tEXEC_STRING\t\c" >>$VF_FILE
311 if [ "$PROMPT" ] ; then
312 echo $EXECSTRING | sed \
313 -e "s/\$\*/%(File)Arg_1\"$PROMPT\"% %(File)Args%/" \
314 -e "s/\$\([1-9]\)/%(File)Arg_\1\"$PROMPT\"%/" \
315 -e "s/\$\([1-9]\)/%(File)Arg_\1%/g" \
318 echo $EXECSTRING | sed \
319 -e "s/\$\*/%(File)Args%/g" \
320 -e "s/\$\([1-9]\)/%(File)Arg_\1%/g" >> $VF_FILE
324 if [ "${WINDOWTYPE}" ] ; then
325 echo "\tWINDOW_TYPE\t$WINDOWTYPE" >> $VF_FILE
330 # If the temp file with the old contents of the vf file exists,
331 # stick it on the end of the file we just created.
332 if [ -r ${OLD_FILE} ] ; then
333 echo "\n#\n# Commented out by dtcreate\n#" >> $VF_FILE
334 cat ${OLD_FILE} >> ${VF_FILE}
339 # Invoke ReloadActions so that the new action
341 dtaction -timeout 1 ReloadActions
344 # Create the action copy file in the home directory.
345 if [ -w ${TOOLBOX} -a ! -f ${TOOLBOX}/${ACTION} ] ; then
346 touch ${TOOLBOX}/${ACTION}
347 chmod 755 ${TOOLBOX}/${ACTION}
350 # Check whether the action exists in the Home directory. (Either we
351 # just created it or it may have already existed.)
352 if [ -x ${TOOLBOX}/${ACTION} ] ; then
353 dtdialog -descFile dtcreate.ddf -dialogName actionExists \
354 -transientFor $CREATEACTION_WID \
356 SECONDARY_DIALOG_PIDS[${NUM_SECONDARY_DIALOGS}]=$!
357 let NUM_SECONDARY_DIALOGS=${NUM_SECONDARY_DIALOGS}+1
359 dtdialog -descFile dtcreate.ddf \
360 -dialogName actionDoesntExist \
361 -transientFor $CREATEACTION_WID \
363 SECONDARY_DIALOG_PIDS[${NUM_SECONDARY_DIALOGS}]=$!
364 let NUM_SECONDARY_DIALOGS=${NUM_SECONDARY_DIALOGS}+1
370 # Dismiss any secondary dialogs (e.g. Help, warnings, errors)
371 # that have been created.
372 if [ NUM_SECONDARY_DIALOGS -gt 0 ]; then
373 for PID in ${SECONDARY_DIALOG_PIDS[*]}
376 if [ $? -eq 1 ] ; then
382 dismissdialog $CREATEACTION_PID
384 rm -f ${DIALOG_OUTPUT}
388 #####################################################################
392 DIALOG_OUTPUT=/tmp/`basename $0`$$
393 #TOOLBOX=$HOME/.dt/types/tools
395 NUM_SECONDARY_DIALOGS=0
399 # Hack warning: This is to determine if should create .dt file or .vf file.
400 if [[ -f /opt/dt/types/useFT ]] then
406 # Set up the callback function that is invoked when the user
407 # presses any of the dialog buttons.
408 trap "actioncallback" ${_SIGUSR1}
410 # Invoke dtdialog and pass in the process-ID of this script.
411 # When the user presses any of the dialog buttons, dtdialog
412 # will send us a signal which will cause the callback function
415 dtdialog -descFile dtcreate.ddf -dialogName createAction -returnWinId \
416 -signal SIGUSR1 -ppid $PARENT_PID -outFile $DIALOG_OUTPUT &
418 # Keep track of the process-ID of the dtdialog process that is
419 # managing the main CreateAction dialog. We need this process-ID so
420 # that we can send it signals to do things such as reenable it.
423 # Sit in a loop as long as the main CreateAction dialog is up. The
424 # signals cause the 'wait' call to exit and I don't know of any way to
425 # determine whether the wait existed due to a signal or because the
426 # process died. Therefore we have to explicitly check if the process
429 while [ $EXIT -eq 0 ] ; do
430 wait $CREATEACTION_PID
431 checkprocess $CREATEACTION_PID
432 if [ $? -eq 0 ] ; then