handle blank lines in spice3 ascii format - as produced by recent ngspice
[gwave-svn.git] / remote / gwave-exec.c
blob6809ac9f1577465b37dc8b9d826788a557fa5e1f
1 /* $Id: gwave-exec.c,v 1.1 2000-11-06 06:39:09 sgt Exp $
3 * this is a generalized version of scwmexec,
4 * Copyright (C) 1997-2000, Maciej Stachowiak and Greg J. Badros
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this software; see the file COPYING.GPL. If not, write to
18 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 * Boston, MA 02111-1307 USA
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
28 #include "xgexec.h"
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
33 Display *display;
34 char *dispName;
36 int
37 init_display()
39 if (!(dispName = getenv("DISPLAY")))
40 return 0;
41 if (!(display = XOpenDisplay(dispName)))
42 return 0;
43 return 1;
47 void die(char *str)
49 fputs(str,stderr);
50 exit(1);
53 int
54 main(int argc, char **argv)
56 Window w;
57 char *result, *output, *error;
59 if (argc != 2)
60 die("Usage: xgexec EXPRESSION\n");
61 if (!init_display())
62 die("Could not connect to server. Check your DISPLAY environment variable.\n");
64 w=xgexec_init(display);
66 if (w==None)
67 die("Unable to establish xgexec connection.\n");
69 result = xgexec_exec_full(display,w,argv[1],&output,&error);
71 fputs(output, stdout);
72 if (strlen(error)!=0) {
73 fputs(error, stderr);
74 } else {
75 fputs(result, stdout);
78 if (result) XFree(result);
79 if (error) XFree(error);
80 if (output) XFree(output);
82 XCloseDisplay (display);
84 return 0;