home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / XAP / XFILEMAN / XFILEMAN.TAR / xfilemanager / action_exec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-22  |  4.2 KB  |  176 lines

  1. /*
  2.  * Copyright 1993 by Ove Kalkan, Cremlingen, Germany
  3.  *
  4.  * Permission to use, copy, modify, distribute and sell this software and it's
  5.  * documentation for any purpose is hereby granted without fee, rpovided that
  6.  * the above copyright notice and this permission appear in supporting
  7.  * documentation, and that the name of Ove Kalkan not to be used in
  8.  * advertising or publicity pertaining to distributiopn of the software without
  9.  * specific, written prior permission. Ove Kalkan makes no representations
  10.  * about the suitability of this software for any purpose. It is provided
  11.  * as is without express or implied warranty.
  12.  *
  13.  * OVE KALKAN DISPLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  14.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABLILITY AND FITNESS, IN NO
  15.  * EVENT SHALL OVE KALKAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  16.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  17.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18.  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19.  * PERFORMANCE OF THIS SOFTWARE.
  20.  *
  21.  * $Header: filename,v 1.0 yyyy/mm/dd hh:mm:ss loginname Exp $
  22.  */
  23.  
  24. #include "global.h"
  25.  
  26. /*
  27.  * Global variables
  28.  */
  29.  
  30.  
  31.  
  32. /*********************************************************
  33.  * name:    init_exec
  34.  * description:    erzeugt ein Fenster mit 2 texten zum Ausfuehren
  35.  *        von Programmen
  36.  * input:    char *file
  37.  * output:    none
  38.  * date:    10.5.93
  39.  *********************************************************/
  40. void    init_exec (char *prog, char *file)
  41. {
  42.     Widget    but;
  43.     char    cmd[2000];
  44.  
  45.     /*
  46.      * Das Dialogfenster erzeugen
  47.      */
  48.     NO_MULTI = TRUE;
  49.     sprintf(cmd,"%s %s",(prog ? prog : ""),(file ? file : ""));
  50.     but = makeDialog(1,"Command :",NULL,cmd,NULL,
  51.              "Program executer",TRUE,FALSE,Icon_Exec_PM);
  52.  
  53.     XtAddCallback(but,XtNcallback,(XtCallbackProc) exec_exec_cb,NULL);
  54.  
  55.     /*
  56.      * Zum Schluss die Dialogshell managen
  57.      */
  58.     XtManageChild (dialog);
  59.  
  60.     /*
  61.      * Max und Minsize setzen
  62.      */
  63.     setSize();
  64. }
  65.  
  66.  
  67.  
  68. /*********************************************************
  69.  * name:    exec_exec
  70.  * description:    Ausfuehren von Programmen starten
  71.  * input:    none
  72.  * output:    none
  73.  * date:    
  74.  *********************************************************/
  75. void    exec_exec_cb (void)
  76. {
  77.     char    *prog;
  78.     Arg    args[1];
  79.     char    buf[1024];
  80.  
  81.     /*
  82.      * Die Texte der beiden Textfelder holen
  83.      */
  84.     XtSetArg(args[0],XtNstring,&prog);
  85.     XtGetValues(text_1,args,1);
  86.  
  87.     /*
  88.      * Ueberpruefen ob in beiden ein Text steht, sonst
  89.      * Warnung ausgeben
  90.      */
  91.     if (!strlen(prog)) {
  92.         WARNING ("Insuffisant Arguments.\nOperation aborted.");
  93.         return;
  94.     }
  95.  
  96.     /*
  97.      * Befehl generieren und ausfuehren
  98.      */
  99.     exec_exec(prog,NULL);
  100. }
  101.  
  102.  
  103. /*********************************************************
  104.  * name:    exec_exec
  105.  * description:    Ausfuehren von Programmen starten
  106.  * input:    none
  107.  * output:    none
  108.  * date:    
  109.  *********************************************************/
  110. void    exec_exec (char    *prog, char *file)
  111. {
  112.     char    buf[1024];
  113.  
  114.     /*
  115.      * Befehl generieren und ausfuehren
  116.      */
  117.     sprintf(buf,"%s &",prog);
  118.     if (SYSTEM(buf)) {
  119.         WARNING("Execution aborted.");
  120.         return;
  121.     }
  122.     else {
  123.         /*
  124.          * Dialogfenster loeschen
  125.          */
  126.         if (dialog)
  127.             XtDestroyWidget(dialog);
  128.         dialog = NULL;
  129.  
  130.         /*
  131.          * Hier muss ein Update der veranderten Felder kommen
  132.          * Bisher unvollstaendig. Problem: Feststellen was
  133.          * veraendert wurde oder ob ueberhaupt etwas veraendert
  134.          * wurde.
  135.          */
  136.     }
  137. }
  138.  
  139.  
  140.  
  141. /*********************************************************
  142.  * name:    SYSTEM
  143.  * description:    Ausfuehren von Programmen. Extraroutine notwendig,
  144.  *        da unter Linux z.B. Zombies erzeugt werden.
  145.  * input:    char    *cmd;
  146.  * output:    0 wenn alles gut ging, sonst 1
  147.  * author:    Ove Kalkan
  148.  * date:    5.8.1993
  149.  *********************************************************/
  150. int    SYSTEM (char *cmd)
  151. {
  152. /*
  153.  * Note: If this routine causes trouble while compiling, you are free to
  154.  * exhange it with  return(system(cmd));
  155.  * I had to use such a routine, because Linux creates many zombies when I
  156.  * am using the system(3) call.
  157.  */
  158.  
  159.  
  160. #define    SHELL    "/bin/sh"
  161.     int    pid,status;
  162.  
  163.     switch ((pid = fork())) {
  164.     case -1:
  165.         return(-1);
  166.     case 0:
  167.         for (status = 3; status < 100; status++)
  168.             close(status);
  169.         execl(SHELL,"sh","-c",cmd,(char *) 0);
  170.         WARNING("System Error: Execl failed!");
  171.         _exit(127);
  172.     default:
  173.         return(0);
  174.     }
  175. }
  176.