4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * Great Red Oystrich Makes All Chemists Sane
29 static char *SRCID_fgrid_c
= "$Id$";
39 static char *type
[] = {
40 "button", "radiobuttons", "groupbox", "checkbox",
41 "pixmap", "statictext", "edittext", "defbutton"
44 void ReadDlgError(char *infile
,eDLGERR err
,char *s
,char *file
,int line
)
46 fprintf(stderr
,"Error: ");
49 fprintf(stderr
,"Not enough values for %s",s
);
52 fprintf(stderr
,"'grid' expected instead of %s",s
);
55 fprintf(stderr
,"'{' expected instead of %s",s
);
58 fprintf(stderr
,"'}' expected instead of %s",s
);
61 fprintf(stderr
,"'group' expected instead of %s",s
);
64 fprintf(stderr
,"item expected instead of %s",s
);
67 fprintf(stderr
,"grid point for %s already in use",s
);
70 fprintf(stderr
,"grid too wide for %s",s
);
73 fprintf(stderr
,"grid too high for %s",s
);
76 fprintf(stderr
,"quote expected instead of %s",s
);
79 fprintf(stderr
,"????");
82 fprintf(stderr
," in file %s\n",infile
);
83 fprintf(stderr
,"C-File: %s, line: %d\n",file
,line
);
87 #define ReadDlgErr(in,er,es) ReadDlgError(in,er,es,__FILE__,__LINE__)
89 static void GetBuf(FILE *in
, char *buf
)
94 static void ReadAccOpen(char *infile
, FILE *in
)
99 if (strcmp(buf
,"{")!=0)
100 ReadDlgErr(infile
,eACCOEXP
,buf
);
103 static void ReadAccClose(char *infile
, FILE *in
)
108 if (strcmp(buf
,"}")!=0)
109 ReadDlgErr(infile
,eACCCEXP
,buf
);
112 void ReadQuoteString(char *infile
, FILE *in
, char *buf
)
117 /* Read until first quote */
118 while ((c
[0]=fgetc(in
))!='"')
119 if (!isspace(c
[0])) {
121 ReadDlgErr(infile
,eQUOTE
,c
);
123 /* Read until second quote */
124 while ((c
[0]=fgetc(in
))!='"')
129 static void ReadQuoteStringOrAccClose(FILE *in
, char *buf
)
134 /* Read until first quote */
144 /* Read until second quote */
145 while ((c
=fgetc(in
))!='"')
150 static bool bNotAccClose(char *buf
)
152 return (strcmp(buf
,"}")!=0);
155 static t_fitem
*NewFItem(void)
170 static t_fsimple
*NewFSimple(void)
179 static void AddFItemName(t_fitem
*fitem
, char *name
)
181 srenew(fitem
->name
,++fitem
->nname
);
182 fitem
->name
[fitem
->nname
-1]=strdup(name
);
185 static t_fgroup
*NewFGroup(void)
197 static void AddFGroupFItem(t_fgroup
*fgroup
, t_fitem
*fitem
)
199 srenew(fgroup
->fitem
,++fgroup
->nfitem
);
200 fgroup
->fitem
[fgroup
->nfitem
-1]=fitem
;
203 static t_fgroup
*AddFGridFGroup(t_fgrid
*fgrid
)
205 srenew(fgrid
->fgroup
,++fgrid
->nfgroup
);
206 fgrid
->fgroup
[fgrid
->nfgroup
-1]=NewFGroup();
207 return fgrid
->fgroup
[fgrid
->nfgroup
-1];
210 static t_fsimple
*AddFGridFSimple(t_fgrid
*fgrid
)
212 srenew(fgrid
->fsimple
,++fgrid
->nfsimple
);
213 fgrid
->fsimple
[fgrid
->nfsimple
-1]=NewFSimple();
214 return fgrid
->fsimple
[fgrid
->nfsimple
-1];
217 static t_fgrid
*NewFGrid(void)
232 static void DoneFItem(t_fitem
*fitem
)
236 for(i
=0; (i
<fitem
->nname
); i
++)
237 sfree(fitem
->name
[i
]);
245 static void DoneFGroup(t_fgroup
*fgroup
)
250 for(i
=0; (i
<fgroup
->nfitem
); i
++)
251 DoneFItem(fgroup
->fitem
[i
]);
252 sfree(fgroup
->fitem
);
255 static void DoneFSimple(t_fsimple
*fsimple
)
257 DoneFItem(fsimple
->fitem
);
258 sfree(fsimple
->fitem
);
261 void DoneFGrid(t_fgrid
*fgrid
)
265 for(i
=0; (i
<fgrid
->nfgroup
); i
++)
266 DoneFGroup(fgrid
->fgroup
[i
]);
267 sfree(fgrid
->fgroup
);
268 for(i
=0; (i
<fgrid
->nfsimple
); i
++)
269 DoneFSimple(fgrid
->fsimple
[i
]);
270 sfree(fgrid
->fsimple
);
273 static t_fitem
*ScanFItem(char *infile
, FILE *in
, char *buf
)
275 char set
[STRLEN
],get
[STRLEN
],help
[STRLEN
],def
[STRLEN
];
281 for(edlg
=(edlgitem
)0; (edlg
<edlgNR
+1); edlg
++)
282 if (strcmp(buf
,type
[edlg
])==0)
289 if (edlg
==edlgNR
+1) {
290 ReadDlgErr(infile
,eITEMEXP
,buf
);
298 ReadQuoteString(infile
,in
,buf
);
299 AddFItemName(fitem
,buf
);
303 ReadAccOpen(infile
,in
);
304 ReadQuoteStringOrAccClose(in
,buf
);
305 while (bNotAccClose(buf
)) {
306 AddFItemName(fitem
,buf
);
307 ReadQuoteStringOrAccClose(in
,buf
);
312 ReadDlgErr(infile
,eITEMEXP
,type
[edlg
]);
317 ReadQuoteString(infile
,in
,set
);
318 ReadQuoteString(infile
,in
,get
);
319 ReadQuoteString(infile
,in
,def
);
320 ReadQuoteString(infile
,in
,help
);
321 fitem
->set
=strdup(set
);
322 fitem
->get
=strdup(get
);
323 fitem
->def
=strdup(def
);
324 fitem
->help
=strdup(help
);
329 t_fgrid
*FGridFromFile(char *infile
)
334 char newinfile
[STRLEN
];
341 if ((in
=fopen(infile
,"r"))==NULL
) {
342 /* Try in the GMXLIB directory */
343 if ((gmxlib
=getenv("GMXLIB"))==NULL
) {
344 fprintf(stderr
,"No GMXLIB environment variable and no %s dlg-script"
345 "in current directory\n",infile
);
348 sprintf(newinfile
,"%s/%s",gmxlib
,infile
);
349 if ((in
=fopen(newinfile
,"r"))==NULL
) {
355 if (strcmp(buf
,"grid")!=0)
356 ReadDlgErr(infile
,eGRIDEXP
,buf
);
358 if ((fscanf(in
,"%d%d",&gridx
,&gridy
))!=2)
359 ReadDlgErr(infile
,eNOVALS
,"grid w,h");
362 ReadAccOpen(infile
,in
);
364 while (bNotAccClose(buf
)) {
365 if (strcmp(buf
,"group")==0) {
366 fgroup
=AddFGridFGroup(fgrid
);
367 ReadQuoteString(infile
,in
,buf
);
368 fgroup
->name
=strdup(buf
);
369 if ((fscanf(in
,"%d%d%d%d",&fgroup
->x
,&fgroup
->y
,&fgroup
->w
,&fgroup
->h
))!=4)
370 ReadDlgErr(infile
,eNOVALS
,"group x,y,w,h");
371 if (fgroup
->x
+fgroup
->w
> gridx
)
372 ReadDlgErr(infile
,eTOOWIDE
,buf
);
373 if (fgroup
->y
+fgroup
->h
> gridy
)
374 ReadDlgErr(infile
,eTOOHIGH
,buf
);
375 ReadAccOpen(infile
,in
);
377 while (bNotAccClose(buf
)) {
378 AddFGroupFItem(fgroup
,ScanFItem(infile
,in
,buf
));
382 else if (strcmp(buf
,"simple")==0) {
383 fsimple
=AddFGridFSimple(fgrid
);
384 if ((fscanf(in
,"%d%d%d%d",&fsimple
->x
,&fsimple
->y
,&fsimple
->w
,&fsimple
->h
))!=4)
385 ReadDlgErr(infile
,eNOVALS
,"simple x,y,w,h");
386 if (fsimple
->x
+fsimple
->w
> gridx
)
387 ReadDlgErr(infile
,eTOOWIDE
,"simple");
388 if (fsimple
->y
+fsimple
->h
> gridy
)
389 ReadDlgErr(infile
,eTOOHIGH
,"simple");
390 ReadAccOpen(infile
,in
);
392 fsimple
->fitem
=ScanFItem(infile
,in
,buf
);
393 ReadAccClose(infile
,in
);
402 static void DumpFItem(t_fitem
*fitem
)
406 printf(" type: %s, set: '%s', get: '%s', def: '%s', help: '%s'\n {",
407 type
[fitem
->edlg
],fitem
->set
,fitem
->get
,fitem
->def
,fitem
->help
);
408 for(i
=0; (i
<fitem
->nname
); i
++)
409 printf(" '%s'",fitem
->name
[i
]);
413 static void DumpFSimple(t_fsimple
*fsimple
)
415 printf("Simple %dx%d at %d,%d\n",fsimple
->w
,fsimple
->h
,fsimple
->x
,fsimple
->y
);
416 DumpFItem(fsimple
->fitem
);
419 static void DumpFGroup(t_fgroup
*fgroup
)
423 printf("Group %dx%d at %d,%d\n",fgroup
->w
,fgroup
->h
,fgroup
->x
,fgroup
->y
);
424 for(i
=0; (i
<fgroup
->nfitem
); i
++)
425 DumpFItem(fgroup
->fitem
[i
]);
428 void DumpFGrid(t_fgrid
*fgrid
)
432 printf("Grid %dx%d\n",fgrid
->w
,fgrid
->h
);
433 for(i
=0; (i
<fgrid
->nfgroup
); i
++)
434 DumpFGroup(fgrid
->fgroup
[i
]);
435 for(i
=0; (i
<fgrid
->nfsimple
); i
++)
436 DumpFSimple(fgrid
->fsimple
[i
]);