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-2013, The GROMACS development team.
6 * Copyright (c) 2013,2014, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
46 #include "gromacs/utility/smalloc.h"
48 #include "gromacs/fileio/futil.h"
50 static const char *type[] = {
51 "button", "radiobuttons", "groupbox", "checkbox",
52 "pixmap", "statictext", "edittext", "defbutton"
55 void ReadDlgError(const char *infile, eDLGERR err, const char *s,
56 const char *file, int line)
58 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, "source file: %s, line: %d\n", file, line);
100 #define ReadDlgErr(in, er, es) ReadDlgError(in, er, es, __FILE__, __LINE__)
102 static void ReadAccOpen(const char *infile, FILE *in)
106 fscanf(in, "%4s", buf);
107 if (strcmp(buf, "{") != 0)
109 ReadDlgErr(infile, eACCOEXP, buf);
113 static void ReadAccClose(const char *infile, FILE *in)
117 fscanf(in, "%4s", buf);
118 if (strcmp(buf, "}") != 0)
120 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)) != '"')
135 ReadDlgErr(infile, eQUOTE, c);
138 /* Read until second quote */
139 while ((c[0] = fgetc(in)) != '"')
146 static void ReadQuoteStringOrAccClose(FILE *in, char *buf)
151 /* Read until first quote */
164 /* Read until second quote */
165 while ((c = fgetc(in)) != '"')
172 static bool bNotAccClose(const char *buf)
174 return (strcmp(buf, "}") != 0);
177 static t_fitem *NewFItem(void)
192 static t_fsimple *NewFSimple(void)
201 static void AddFItemName(t_fitem *fitem, char *name)
203 srenew(fitem->name, ++fitem->nname);
204 fitem->name[fitem->nname-1] = strdup(name);
207 static t_fgroup *NewFGroup(void)
214 fgroup->fitem = NULL;
219 static void AddFGroupFItem(t_fgroup *fgroup, t_fitem *fitem)
221 srenew(fgroup->fitem, ++fgroup->nfitem);
222 fgroup->fitem[fgroup->nfitem-1] = fitem;
225 static t_fgroup *AddFGridFGroup(t_fgrid *fgrid)
227 srenew(fgrid->fgroup, ++fgrid->nfgroup);
228 fgrid->fgroup[fgrid->nfgroup-1] = NewFGroup();
229 return fgrid->fgroup[fgrid->nfgroup-1];
232 static t_fsimple *AddFGridFSimple(t_fgrid *fgrid)
234 srenew(fgrid->fsimple, ++fgrid->nfsimple);
235 fgrid->fsimple[fgrid->nfsimple-1] = NewFSimple();
236 return fgrid->fsimple[fgrid->nfsimple-1];
239 static t_fgrid *NewFGrid(void)
247 fgrid->fgroup = NULL;
249 fgrid->fsimple = NULL;
254 static void DoneFItem(t_fitem *fitem)
258 for (i = 0; (i < fitem->nname); i++)
260 sfree(fitem->name[i]);
269 static void DoneFGroup(t_fgroup *fgroup)
274 for (i = 0; (i < fgroup->nfitem); i++)
276 DoneFItem(fgroup->fitem[i]);
278 sfree(fgroup->fitem);
281 static void DoneFSimple(t_fsimple *fsimple)
283 DoneFItem(fsimple->fitem);
284 sfree(fsimple->fitem);
287 void DoneFGrid(t_fgrid *fgrid)
291 for (i = 0; (i < fgrid->nfgroup); i++)
293 DoneFGroup(fgrid->fgroup[i]);
295 sfree(fgrid->fgroup);
296 for (i = 0; (i < fgrid->nfsimple); i++)
298 DoneFSimple(fgrid->fsimple[i]);
300 sfree(fgrid->fsimple);
303 static t_fitem *ScanFItem(const char *infile, FILE *in, char *buf)
305 char set[STRLEN], get[STRLEN], help[STRLEN], def[STRLEN];
311 for (edlg = 0; (edlg < edlgNR+1); edlg++)
313 if (strcmp(buf, type[edlg]) == 0)
324 if (edlg == edlgNR+1)
326 ReadDlgErr(infile, eITEMEXP, buf);
329 fitem->edlg = (edlgitem)edlg;
335 ReadQuoteString(infile, in, buf);
336 AddFItemName(fitem, buf);
340 ReadAccOpen(infile, in);
341 ReadQuoteStringOrAccClose(in, buf);
342 while (bNotAccClose(buf))
344 AddFItemName(fitem, buf);
345 ReadQuoteStringOrAccClose(in, buf);
350 ReadDlgErr(infile, eITEMEXP, type[edlg]);
355 ReadQuoteString(infile, in, set);
356 ReadQuoteString(infile, in, get);
357 ReadQuoteString(infile, in, def);
358 ReadQuoteString(infile, in, help);
359 fitem->set = strdup(set);
360 fitem->get = strdup(get);
361 fitem->def = strdup(def);
362 fitem->help = strdup(help);
367 t_fgrid *FGridFromFile(const char *infile)
377 in = libopen(infile);
378 fscanf(in, "%6s", buf);
379 if (strcmp(buf, "grid") != 0)
381 ReadDlgErr(infile, eGRIDEXP, buf);
384 if ((fscanf(in, "%5d%5d", &gridx, &gridy)) != 2)
386 ReadDlgErr(infile, eNOVALS, "grid w,h");
390 ReadAccOpen(infile, in);
391 fscanf(in, "%15s", buf);
392 while (bNotAccClose(buf))
394 if (strcmp(buf, "group") == 0)
396 fgroup = AddFGridFGroup(fgrid);
397 ReadQuoteString(infile, in, buf);
398 fgroup->name = strdup(buf);
399 if ((fscanf(in, "%5d%5d%5d%5d", &fgroup->x, &fgroup->y, &fgroup->w, &fgroup->h)) != 4)
401 ReadDlgErr(infile, eNOVALS, "group x,y,w,h");
403 if (fgroup->x+fgroup->w > gridx)
405 ReadDlgErr(infile, eTOOWIDE, buf);
407 if (fgroup->y+fgroup->h > gridy)
409 ReadDlgErr(infile, eTOOHIGH, buf);
411 ReadAccOpen(infile, in);
412 fscanf(in, "%15s", buf);
413 while (bNotAccClose(buf))
415 AddFGroupFItem(fgroup, ScanFItem(infile, in, buf));
416 fscanf(in, "%15s", buf);
419 else if (strcmp(buf, "simple") == 0)
421 fsimple = AddFGridFSimple(fgrid);
422 if ((fscanf(in, "%5d%5d%5d%5d", &fsimple->x, &fsimple->y, &fsimple->w, &fsimple->h)) != 4)
424 ReadDlgErr(infile, eNOVALS, "simple x,y,w,h");
426 if (fsimple->x+fsimple->w > gridx)
428 ReadDlgErr(infile, eTOOWIDE, "simple");
430 if (fsimple->y+fsimple->h > gridy)
432 ReadDlgErr(infile, eTOOHIGH, "simple");
434 ReadAccOpen(infile, in);
435 fscanf(in, "%15s", buf);
436 fsimple->fitem = ScanFItem(infile, in, buf);
437 ReadAccClose(infile, in);
439 fscanf(in, "%15s", buf);
446 static void DumpFItem(t_fitem *fitem)
450 printf(" type: %s, set: '%s', get: '%s', def: '%s', help: '%s'\n {",
451 type[fitem->edlg], fitem->set, fitem->get, fitem->def, fitem->help);
452 for (i = 0; (i < fitem->nname); i++)
454 printf(" '%s'", fitem->name[i]);
459 static void DumpFSimple(t_fsimple *fsimple)
461 printf("Simple %dx%d at %d,%d\n", fsimple->w, fsimple->h, fsimple->x, fsimple->y);
462 DumpFItem(fsimple->fitem);
465 static void DumpFGroup(t_fgroup *fgroup)
469 printf("Group %dx%d at %d,%d\n", fgroup->w, fgroup->h, fgroup->x, fgroup->y);
470 for (i = 0; (i < fgroup->nfitem); i++)
472 DumpFItem(fgroup->fitem[i]);
476 void DumpFGrid(t_fgrid *fgrid)
480 printf("Grid %dx%d\n", fgrid->w, fgrid->h);
481 for (i = 0; (i < fgrid->nfgroup); i++)
483 DumpFGroup(fgrid->fgroup[i]);
485 for (i = 0; (i < fgrid->nfsimple); i++)
487 DumpFSimple(fgrid->fsimple[i]);