CMake checks for regular expression support.
[gromacs/qmmm-gamess-us.git] / src / ngmx / xstat.c
blobe860eef73fb111f717c6f1eabc7c7706fd4f4b73
1 /*
2 *
3 * This source code is part of
4 *
5 * G R O M A C S
6 *
7 * GROningen MAchine for Chemical Simulations
8 *
9 * VERSION 3.2.0
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
32 * And Hey:
33 * Gyas ROwers Mature At Cryogenic Speed
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
39 #include "sysstuff.h"
40 #include "smalloc.h"
41 #include "x11.h"
42 #include "string2.h"
43 #include "macros.h"
44 #include "fgrid.h"
45 #include "futil.h"
46 #include "xdlg.h"
47 #include "xdlghi.h"
49 typedef struct {
50 int nopt,nAppl;
51 char **name;
52 char **description;
53 char **dlgfile;
54 t_dlg *dlg;
55 t_dlg *appl;
56 } t_data;
58 static void ApplCallback(t_x11 *x11,int dlg_mess,int item_id,
59 char *set,void *dta)
61 t_data *data;
62 t_dlg *dlg;
63 t_dlgitem *item;
64 int i;
65 char doit[1024];
67 data=(t_data *)dta;
68 dlg=data->appl;
70 fprintf(stderr,"item_id: %d (%s)\n",item_id,set);
71 if (strcasecmp(set,"OK") == 0) {
72 /* Doit */
73 sprintf(doit,
74 "xterm -geometry +100+100 -n %s"
75 " -title \"GROMACS: %s\" -e nice %s ",
76 data->name[data->nAppl],
77 data->name[data->nAppl],
78 data->name[data->nAppl]);
79 for(i=0; (i<dlg->nitem); i++) {
80 item=dlg->dlgitem[i];
81 switch (item->type) {
82 case edlgRB:
83 strcat(doit,item->set);
84 strcat(doit," ");
85 break;
86 case edlgCB:
87 if (item->u.checkbox.bChecked)
88 strcat(doit,item->set);
89 strcat(doit," ");
90 break;
91 case edlgET:
92 if (strlen(item->u.edittext.buf) > 0) {
93 strcat(doit,item->set);
94 strcat(doit," ");
95 strcat(doit,item->u.edittext.buf);
96 strcat(doit," ");
98 break;
99 default:
100 fprintf(stderr,"Type: %d\n",item->type);
103 strcat(doit," &");
104 fprintf(stderr,"Going to exec: '%s'\n",doit);
106 #ifdef GMX_NO_SYSTEM
107 printf("Warning-- No calls to system(3) supported on this platform.");
108 printf("Warning-- Skipping execution of 'system(\"%s\")'.", buf);
109 #else
110 system(doit);
111 #endif
113 HideDlg(data->appl);
115 else if (strcasecmp(set,"Cancel") == 0) {
116 data->nAppl = -1;
117 HideDlg(data->appl);
121 static void Callback(t_x11 *x11,int dlg_mess,int item_id,
122 char *set,void *dta)
124 t_data *data=(t_data *)dta;
126 if (item_id == data->nopt) {
127 fprintf(stderr,"Doei...\n");
128 exit(0);
130 else {
131 fprintf(stderr,"%d: %s\n",item_id,data->description[item_id]);
132 if (data->nAppl != -1)
133 HideDlg(data->appl);
134 data->nAppl=item_id;
135 data->appl=ReadDlg(x11,0,data->name[item_id],
136 BLACK,LIGHTGREY,data->dlgfile[item_id],
137 50,50,FALSE,FALSE,ApplCallback,data);
138 ShowDlg(data->appl);
142 static void read_opts(t_data *data)
144 FILE *in;
145 char fn[STRLEN],buf[STRLEN];
146 int i,n;
148 sprintf(fn,"xstat.dat");
149 in=libopen(fn);
150 fscanf(in,"%d",&n);
151 data->nopt=n;
152 snew(data->name,data->nopt);
153 snew(data->description,data->nopt);
154 snew(data->dlgfile,data->nopt);
156 for(i=0; (i<data->nopt); i++) {
157 ReadQuoteString(fn,in,buf);
158 data->name[i] = strdup(buf);
159 ReadQuoteString(fn,in,buf);
160 data->description[i] = strdup(buf);
161 ReadQuoteString(fn,in,buf);
162 data->dlgfile[i] = strdup(buf);
164 fclose(in);
167 static void add_opts(t_x11 *x11,t_data *data)
169 t_dlgitem *but;
170 int i,y0,w;
172 y0=OFFS_Y;
173 for(i=0; (i<data->nopt); i++) {
174 but=CreateButton(x11,data->description[i],FALSE,
175 (t_id)i,(t_id)0,
176 OFFS_X,y0,0,0,1);
177 AddDlgItem(data->dlg,but);
178 y0+=but->win.height+OFFS_Y;
180 but=CreateButton(x11,"Quit",TRUE,(t_id)data->nopt,(t_id)0,
181 OFFS_X,y0,0,0,1);
182 AddDlgItem(data->dlg,but);
183 y0+=but->win.height+OFFS_Y;
185 w=0;
186 for(i=0; (i<=data->nopt); i++)
187 w=max(w,QueryDlgItemW(data->dlg,i));
188 w+=2*OFFS_X;
189 for(i=0; (i<=data->nopt); i++)
190 SetDlgItemSize(data->dlg,i,w,0);
191 SetDlgSize(data->dlg,w+2*OFFS_X,y0,TRUE);
195 main(int argc,char *argv[])
197 t_x11 *x11;
198 t_data data;
200 /* Initiate X and data */
201 if ((x11=GetX11(&argc,argv))==NULL) {
202 fprintf(stderr,"Can't open DISPLAY\n");
203 exit(1);
205 read_opts(&data);
206 data.dlg=CreateDlg(x11,0,argv[0],0,0,0,0,0,BLACK,LIGHTGREY,Callback,&data);
207 add_opts(x11,&data);
208 data.nAppl=-1;
210 ShowDlg(data.dlg);
211 x11->MainLoop(x11);
212 HideDlg(data.dlg);