2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
51 static const char *type
[] = {
52 "button", "radiobuttons", "groupbox", "checkbox",
53 "pixmap", "statictext", "edittext", "defbutton"
56 void ReadDlgError(const char *infile
,eDLGERR err
,const char *s
,
57 const char *file
,int line
)
59 fprintf(stderr
,"Error: ");
62 fprintf(stderr
,"Not enough values for %s",s
);
65 fprintf(stderr
,"'grid' expected instead of %s",s
);
68 fprintf(stderr
,"'{' expected instead of %s",s
);
71 fprintf(stderr
,"'}' expected instead of %s",s
);
74 fprintf(stderr
,"'group' expected instead of %s",s
);
77 fprintf(stderr
,"item expected instead of %s",s
);
80 fprintf(stderr
,"grid point for %s already in use",s
);
83 fprintf(stderr
,"grid too wide for %s",s
);
86 fprintf(stderr
,"grid too high for %s",s
);
89 fprintf(stderr
,"quote expected instead of %s",s
);
92 fprintf(stderr
,"????");
95 fprintf(stderr
," in file %s\n",infile
);
96 fprintf(stderr
,"C-File: %s, line: %d\n",file
,line
);
100 #define ReadDlgErr(in,er,es) ReadDlgError(in,er,es,__FILE__,__LINE__)
102 static void GetBuf(FILE *in
, char *buf
)
106 rc
=fscanf(in
,"%s",buf
);
109 static void ReadAccOpen(const char *infile
, FILE *in
)
114 if (strcmp(buf
,"{")!=0)
115 ReadDlgErr(infile
,eACCOEXP
,buf
);
118 static void ReadAccClose(const char *infile
, FILE *in
)
123 if (strcmp(buf
,"}")!=0)
124 ReadDlgErr(infile
,eACCCEXP
,buf
);
127 void ReadQuoteString(const char *infile
, FILE *in
, char *buf
)
132 /* Read until first quote */
133 while ((c
[0]=fgetc(in
))!='"')
134 if (!isspace(c
[0])) {
136 ReadDlgErr(infile
,eQUOTE
,c
);
138 /* Read until second quote */
139 while ((c
[0]=fgetc(in
))!='"')
144 static void ReadQuoteStringOrAccClose(FILE *in
, char *buf
)
149 /* Read until first quote */
159 /* Read until second quote */
160 while ((c
=fgetc(in
))!='"')
165 static gmx_bool
bNotAccClose(const char *buf
)
167 return (strcmp(buf
,"}")!=0);
170 static t_fitem
*NewFItem(void)
185 static t_fsimple
*NewFSimple(void)
194 static void AddFItemName(t_fitem
*fitem
, char *name
)
196 srenew(fitem
->name
,++fitem
->nname
);
197 fitem
->name
[fitem
->nname
-1]=strdup(name
);
200 static t_fgroup
*NewFGroup(void)
212 static void AddFGroupFItem(t_fgroup
*fgroup
, t_fitem
*fitem
)
214 srenew(fgroup
->fitem
,++fgroup
->nfitem
);
215 fgroup
->fitem
[fgroup
->nfitem
-1]=fitem
;
218 static t_fgroup
*AddFGridFGroup(t_fgrid
*fgrid
)
220 srenew(fgrid
->fgroup
,++fgrid
->nfgroup
);
221 fgrid
->fgroup
[fgrid
->nfgroup
-1]=NewFGroup();
222 return fgrid
->fgroup
[fgrid
->nfgroup
-1];
225 static t_fsimple
*AddFGridFSimple(t_fgrid
*fgrid
)
227 srenew(fgrid
->fsimple
,++fgrid
->nfsimple
);
228 fgrid
->fsimple
[fgrid
->nfsimple
-1]=NewFSimple();
229 return fgrid
->fsimple
[fgrid
->nfsimple
-1];
232 static t_fgrid
*NewFGrid(void)
247 static void DoneFItem(t_fitem
*fitem
)
251 for(i
=0; (i
<fitem
->nname
); i
++)
252 sfree(fitem
->name
[i
]);
260 static void DoneFGroup(t_fgroup
*fgroup
)
265 for(i
=0; (i
<fgroup
->nfitem
); i
++)
266 DoneFItem(fgroup
->fitem
[i
]);
267 sfree(fgroup
->fitem
);
270 static void DoneFSimple(t_fsimple
*fsimple
)
272 DoneFItem(fsimple
->fitem
);
273 sfree(fsimple
->fitem
);
276 void DoneFGrid(t_fgrid
*fgrid
)
280 for(i
=0; (i
<fgrid
->nfgroup
); i
++)
281 DoneFGroup(fgrid
->fgroup
[i
]);
282 sfree(fgrid
->fgroup
);
283 for(i
=0; (i
<fgrid
->nfsimple
); i
++)
284 DoneFSimple(fgrid
->fsimple
[i
]);
285 sfree(fgrid
->fsimple
);
288 static t_fitem
*ScanFItem(const char *infile
, FILE *in
, char *buf
)
290 char set
[STRLEN
],get
[STRLEN
],help
[STRLEN
],def
[STRLEN
];
296 for(edlg
=(edlgitem
)0; (edlg
<edlgNR
+1); edlg
= (edlgitem
)(edlg
+ 1))
297 if (strcmp(buf
,type
[edlg
])==0)
304 if (edlg
==edlgNR
+1) {
305 ReadDlgErr(infile
,eITEMEXP
,buf
);
313 ReadQuoteString(infile
,in
,buf
);
314 AddFItemName(fitem
,buf
);
318 ReadAccOpen(infile
,in
);
319 ReadQuoteStringOrAccClose(in
,buf
);
320 while (bNotAccClose(buf
)) {
321 AddFItemName(fitem
,buf
);
322 ReadQuoteStringOrAccClose(in
,buf
);
327 ReadDlgErr(infile
,eITEMEXP
,type
[edlg
]);
332 ReadQuoteString(infile
,in
,set
);
333 ReadQuoteString(infile
,in
,get
);
334 ReadQuoteString(infile
,in
,def
);
335 ReadQuoteString(infile
,in
,help
);
336 fitem
->set
=strdup(set
);
337 fitem
->get
=strdup(get
);
338 fitem
->def
=strdup(def
);
339 fitem
->help
=strdup(help
);
344 t_fgrid
*FGridFromFile(const char *infile
)
349 char newinfile
[STRLEN
];
356 in
= libopen(infile
);
358 if (strcmp(buf
,"grid")!=0)
359 ReadDlgErr(infile
,eGRIDEXP
,buf
);
361 if ((fscanf(in
,"%d%d",&gridx
,&gridy
))!=2)
362 ReadDlgErr(infile
,eNOVALS
,"grid w,h");
365 ReadAccOpen(infile
,in
);
367 while (bNotAccClose(buf
)) {
368 if (strcmp(buf
,"group")==0) {
369 fgroup
=AddFGridFGroup(fgrid
);
370 ReadQuoteString(infile
,in
,buf
);
371 fgroup
->name
=strdup(buf
);
372 if ((fscanf(in
,"%d%d%d%d",&fgroup
->x
,&fgroup
->y
,&fgroup
->w
,&fgroup
->h
))!=4)
373 ReadDlgErr(infile
,eNOVALS
,"group x,y,w,h");
374 if (fgroup
->x
+fgroup
->w
> gridx
)
375 ReadDlgErr(infile
,eTOOWIDE
,buf
);
376 if (fgroup
->y
+fgroup
->h
> gridy
)
377 ReadDlgErr(infile
,eTOOHIGH
,buf
);
378 ReadAccOpen(infile
,in
);
380 while (bNotAccClose(buf
)) {
381 AddFGroupFItem(fgroup
,ScanFItem(infile
,in
,buf
));
385 else if (strcmp(buf
,"simple")==0) {
386 fsimple
=AddFGridFSimple(fgrid
);
387 if ((fscanf(in
,"%d%d%d%d",&fsimple
->x
,&fsimple
->y
,&fsimple
->w
,&fsimple
->h
))!=4)
388 ReadDlgErr(infile
,eNOVALS
,"simple x,y,w,h");
389 if (fsimple
->x
+fsimple
->w
> gridx
)
390 ReadDlgErr(infile
,eTOOWIDE
,"simple");
391 if (fsimple
->y
+fsimple
->h
> gridy
)
392 ReadDlgErr(infile
,eTOOHIGH
,"simple");
393 ReadAccOpen(infile
,in
);
395 fsimple
->fitem
=ScanFItem(infile
,in
,buf
);
396 ReadAccClose(infile
,in
);
405 static void DumpFItem(t_fitem
*fitem
)
409 printf(" type: %s, set: '%s', get: '%s', def: '%s', help: '%s'\n {",
410 type
[fitem
->edlg
],fitem
->set
,fitem
->get
,fitem
->def
,fitem
->help
);
411 for(i
=0; (i
<fitem
->nname
); i
++)
412 printf(" '%s'",fitem
->name
[i
]);
416 static void DumpFSimple(t_fsimple
*fsimple
)
418 printf("Simple %dx%d at %d,%d\n",fsimple
->w
,fsimple
->h
,fsimple
->x
,fsimple
->y
);
419 DumpFItem(fsimple
->fitem
);
422 static void DumpFGroup(t_fgroup
*fgroup
)
426 printf("Group %dx%d at %d,%d\n",fgroup
->w
,fgroup
->h
,fgroup
->x
,fgroup
->y
);
427 for(i
=0; (i
<fgroup
->nfitem
); i
++)
428 DumpFItem(fgroup
->fitem
[i
]);
431 void DumpFGrid(t_fgrid
*fgrid
)
435 printf("Grid %dx%d\n",fgrid
->w
,fgrid
->h
);
436 for(i
=0; (i
<fgrid
->nfgroup
); i
++)
437 DumpFGroup(fgrid
->fgroup
[i
]);
438 for(i
=0; (i
<fgrid
->nfsimple
); i
++)
439 DumpFSimple(fgrid
->fsimple
[i
]);