3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
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
33 * Gyas ROwers Mature At Cryogenic Speed
48 static const char *type
[] = {
49 "button", "radiobuttons", "groupbox", "checkbox",
50 "pixmap", "statictext", "edittext", "defbutton"
53 void ReadDlgError(const char *infile
,eDLGERR err
,const char *s
,
54 const char *file
,int line
)
56 fprintf(stderr
,"Error: ");
59 fprintf(stderr
,"Not enough values for %s",s
);
62 fprintf(stderr
,"'grid' expected instead of %s",s
);
65 fprintf(stderr
,"'{' expected instead of %s",s
);
68 fprintf(stderr
,"'}' expected instead of %s",s
);
71 fprintf(stderr
,"'group' expected instead of %s",s
);
74 fprintf(stderr
,"item expected instead of %s",s
);
77 fprintf(stderr
,"grid point for %s already in use",s
);
80 fprintf(stderr
,"grid too wide for %s",s
);
83 fprintf(stderr
,"grid too high for %s",s
);
86 fprintf(stderr
,"quote expected instead of %s",s
);
89 fprintf(stderr
,"????");
92 fprintf(stderr
," in file %s\n",infile
);
93 fprintf(stderr
,"C-File: %s, line: %d\n",file
,line
);
97 #define ReadDlgErr(in,er,es) ReadDlgError(in,er,es,__FILE__,__LINE__)
99 static void GetBuf(FILE *in
, char *buf
)
103 rc
=fscanf(in
,"%s",buf
);
106 static void ReadAccOpen(const char *infile
, FILE *in
)
111 if (strcmp(buf
,"{")!=0)
112 ReadDlgErr(infile
,eACCOEXP
,buf
);
115 static void ReadAccClose(const char *infile
, FILE *in
)
120 if (strcmp(buf
,"}")!=0)
121 ReadDlgErr(infile
,eACCCEXP
,buf
);
124 void ReadQuoteString(const char *infile
, FILE *in
, char *buf
)
129 /* Read until first quote */
130 while ((c
[0]=fgetc(in
))!='"')
131 if (!isspace(c
[0])) {
133 ReadDlgErr(infile
,eQUOTE
,c
);
135 /* Read until second quote */
136 while ((c
[0]=fgetc(in
))!='"')
141 static void ReadQuoteStringOrAccClose(FILE *in
, char *buf
)
146 /* Read until first quote */
156 /* Read until second quote */
157 while ((c
=fgetc(in
))!='"')
162 static bool bNotAccClose(const char *buf
)
164 return (strcmp(buf
,"}")!=0);
167 static t_fitem
*NewFItem(void)
182 static t_fsimple
*NewFSimple(void)
191 static void AddFItemName(t_fitem
*fitem
, char *name
)
193 srenew(fitem
->name
,++fitem
->nname
);
194 fitem
->name
[fitem
->nname
-1]=strdup(name
);
197 static t_fgroup
*NewFGroup(void)
209 static void AddFGroupFItem(t_fgroup
*fgroup
, t_fitem
*fitem
)
211 srenew(fgroup
->fitem
,++fgroup
->nfitem
);
212 fgroup
->fitem
[fgroup
->nfitem
-1]=fitem
;
215 static t_fgroup
*AddFGridFGroup(t_fgrid
*fgrid
)
217 srenew(fgrid
->fgroup
,++fgrid
->nfgroup
);
218 fgrid
->fgroup
[fgrid
->nfgroup
-1]=NewFGroup();
219 return fgrid
->fgroup
[fgrid
->nfgroup
-1];
222 static t_fsimple
*AddFGridFSimple(t_fgrid
*fgrid
)
224 srenew(fgrid
->fsimple
,++fgrid
->nfsimple
);
225 fgrid
->fsimple
[fgrid
->nfsimple
-1]=NewFSimple();
226 return fgrid
->fsimple
[fgrid
->nfsimple
-1];
229 static t_fgrid
*NewFGrid(void)
244 static void DoneFItem(t_fitem
*fitem
)
248 for(i
=0; (i
<fitem
->nname
); i
++)
249 sfree(fitem
->name
[i
]);
257 static void DoneFGroup(t_fgroup
*fgroup
)
262 for(i
=0; (i
<fgroup
->nfitem
); i
++)
263 DoneFItem(fgroup
->fitem
[i
]);
264 sfree(fgroup
->fitem
);
267 static void DoneFSimple(t_fsimple
*fsimple
)
269 DoneFItem(fsimple
->fitem
);
270 sfree(fsimple
->fitem
);
273 void DoneFGrid(t_fgrid
*fgrid
)
277 for(i
=0; (i
<fgrid
->nfgroup
); i
++)
278 DoneFGroup(fgrid
->fgroup
[i
]);
279 sfree(fgrid
->fgroup
);
280 for(i
=0; (i
<fgrid
->nfsimple
); i
++)
281 DoneFSimple(fgrid
->fsimple
[i
]);
282 sfree(fgrid
->fsimple
);
285 static t_fitem
*ScanFItem(const char *infile
, FILE *in
, char *buf
)
287 char set
[STRLEN
],get
[STRLEN
],help
[STRLEN
],def
[STRLEN
];
293 for(edlg
=(edlgitem
)0; (edlg
<edlgNR
+1); edlg
= (edlgitem
)(edlg
+ 1))
294 if (strcmp(buf
,type
[edlg
])==0)
301 if (edlg
==edlgNR
+1) {
302 ReadDlgErr(infile
,eITEMEXP
,buf
);
310 ReadQuoteString(infile
,in
,buf
);
311 AddFItemName(fitem
,buf
);
315 ReadAccOpen(infile
,in
);
316 ReadQuoteStringOrAccClose(in
,buf
);
317 while (bNotAccClose(buf
)) {
318 AddFItemName(fitem
,buf
);
319 ReadQuoteStringOrAccClose(in
,buf
);
324 ReadDlgErr(infile
,eITEMEXP
,type
[edlg
]);
329 ReadQuoteString(infile
,in
,set
);
330 ReadQuoteString(infile
,in
,get
);
331 ReadQuoteString(infile
,in
,def
);
332 ReadQuoteString(infile
,in
,help
);
333 fitem
->set
=strdup(set
);
334 fitem
->get
=strdup(get
);
335 fitem
->def
=strdup(def
);
336 fitem
->help
=strdup(help
);
341 t_fgrid
*FGridFromFile(const char *infile
)
346 char newinfile
[STRLEN
];
353 in
= libopen(infile
);
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
]);