home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
m
/
master12.zip
/
mastering
/
command.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-18
|
3KB
|
91 lines
/**---------------------------------------------------------------------
***
*** file: command.c
***
*** project: Motif toolkit example programs
***
*** description: This program creates a Command widget.
***
***
***-------------------------------------------------------------------*/
#include <stdio.h>
#include <Xm/Command.h>
static XmString stringList[15];
static void EnterCB (w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
XmString name_string = NULL;
char *name = NULL;
XmCommandCallbackStruct *cb = (XmCommandCallbackStruct *) call_data;
/* Get the command compound string from the callback struct */
name_string = cb->value;
XmStringGetLtoR (name_string, XmFONTLIST_DEFAULT_TAG, &name);
/* Plug the command into a system call and execute it */
system (name);
}
/*-------------------------------------------------------------
** main - main logic for command program
*/
void main (argc,argv)
unsigned int argc;
char **argv;
{
Widget toplevel; /* MainShell widget */
Widget command; /* Command widget */
int i;
Arg args[10]; /* arg list */
register int ac; /* arg count */
XmString stringList[15];
XmString commandString;
XmString promptString;
XtAppContext app_context;
/* initialize toolkit */
toplevel = XtAppInitialize (&app_context, "Command", NULL, 0, &argc, argv,
NULL, args, 0);
/* set up XmStrings for the command history list */
stringList[0] = XmStringCreateLtoR ("ls", XmFONTLIST_DEFAULT_TAG);
stringList[1] = XmStringCreateLtoR ("ll", XmFONTLIST_DEFAULT_TAG);
stringList[2] = XmStringCreateLtoR ("ls -a", XmFONTLIST_DEFAULT_TAG);
stringList[3] = XmStringCreateLtoR ("df", XmFONTLIST_DEFAULT_TAG);
stringList[4] = NULL;
commandString = XmStringCreateLtoR ("du", XmFONTLIST_DEFAULT_TAG);
promptString = XmStringCreateLtoR ("Enter Command Below",
XmFONTLIST_DEFAULT_TAG);
/* Set up resource argument list */
ac = 0;
XtSetArg (args[ac], XmNcommand, commandString); ac++;
XtSetArg (args[ac], XmNpromptString, promptString); ac++;
XtSetArg (args[ac], XmNhistoryItems, stringList); ac++;
XtSetArg (args[ac], XmNhistoryItemCount, 4); ac++;
/* Create the command widget */
command = XmCreateCommand (toplevel, "command", args, ac);
XtAddCallback (command, XmNcommandEnteredCallback, EnterCB, NULL);
XtManageChild (command);
/* Free Compound String Memory */
for (i = 0; i < 4; i++)
XmStringFree (stringList[i]);
XmStringFree (promptString);
XmStringFree (commandString);
/* realize widgets */
XtRealizeWidget (toplevel);
/* process events */
XtAppMainLoop (app_context);
}