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 >
C/C++ Source or Header  |  1992-08-18  |  3KB  |  91 lines

  1. /**---------------------------------------------------------------------
  2. ***    
  3. ***    file:        command.c
  4. ***
  5. ***    project:    Motif toolkit example programs
  6. ***
  7. ***    description:    This program creates a Command widget.
  8. ***    
  9. ***    
  10. ***-------------------------------------------------------------------*/
  11.  
  12. #include <stdio.h>
  13. #include <Xm/Command.h>
  14.  
  15. static XmString  stringList[15];
  16.  
  17. static void EnterCB (w, client_data, call_data)
  18. Widget      w;
  19. XtPointer   client_data;
  20. XtPointer   call_data;
  21. {
  22.   XmString name_string = NULL;
  23.   char *name = NULL;
  24.   XmCommandCallbackStruct *cb = (XmCommandCallbackStruct *) call_data;
  25.  
  26.   /* Get the command compound string from the callback struct */
  27.   name_string = cb->value;
  28.   XmStringGetLtoR (name_string, XmFONTLIST_DEFAULT_TAG, &name);
  29.  
  30.   /* Plug the command into a system call and execute it */
  31.   system (name);
  32. }
  33.  
  34. /*-------------------------------------------------------------
  35. **    main        - main logic for command program
  36. */
  37. void main (argc,argv)
  38.     unsigned int  argc;
  39.     char        **argv;
  40. {
  41.     Widget        toplevel;                /*  MainShell widget     */
  42.     Widget        command;                 /*  Command widget       */
  43.     int           i;
  44.     Arg           args[10];                /*  arg list             */
  45.     register int  ac;                      /*  arg count            */
  46.     XmString      stringList[15];
  47.     XmString      commandString;
  48.     XmString      promptString;
  49.     XtAppContext  app_context;
  50.  
  51.     /*  initialize toolkit  */
  52.     toplevel = XtAppInitialize (&app_context, "Command", NULL, 0, &argc, argv,
  53.    NULL, args, 0);
  54.  
  55.     /* set up XmStrings for the command history list */
  56.     stringList[0] = XmStringCreateLtoR ("ls", XmFONTLIST_DEFAULT_TAG);
  57.     stringList[1] = XmStringCreateLtoR ("ll", XmFONTLIST_DEFAULT_TAG);
  58.     stringList[2] = XmStringCreateLtoR ("ls -a", XmFONTLIST_DEFAULT_TAG);
  59.     stringList[3] = XmStringCreateLtoR ("df", XmFONTLIST_DEFAULT_TAG);
  60.     stringList[4] = NULL;
  61.  
  62.     commandString = XmStringCreateLtoR ("du", XmFONTLIST_DEFAULT_TAG);
  63.     promptString = XmStringCreateLtoR ("Enter Command Below",
  64.                                         XmFONTLIST_DEFAULT_TAG);
  65.  
  66.     /* Set up resource argument list */
  67.     ac = 0;
  68.     XtSetArg (args[ac], XmNcommand, commandString);  ac++;
  69.     XtSetArg (args[ac], XmNpromptString, promptString);  ac++;
  70.     XtSetArg (args[ac], XmNhistoryItems, stringList);  ac++;
  71.     XtSetArg (args[ac], XmNhistoryItemCount, 4);  ac++;
  72.  
  73.     /* Create the command widget */
  74.     command = XmCreateCommand (toplevel, "command", args, ac);
  75.     XtAddCallback (command, XmNcommandEnteredCallback, EnterCB, NULL);
  76.     XtManageChild (command);
  77.  
  78.     /* Free Compound String Memory */
  79.     for (i = 0; i < 4; i++)
  80.       XmStringFree (stringList[i]);
  81.  
  82.     XmStringFree (promptString);
  83.     XmStringFree (commandString);
  84.  
  85.     /*  realize widgets  */
  86.     XtRealizeWidget (toplevel);
  87.  
  88.     /*  process events  */
  89.     XtAppMainLoop (app_context);
  90. }
  91.