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: ");
60 fprintf(stderr, "Not enough values for %s", s);
63 fprintf(stderr, "'grid' expected instead of %s", s);
66 fprintf(stderr, "'{' expected instead of %s", s);
69 fprintf(stderr, "'}' expected instead of %s", s);
72 fprintf(stderr, "'group' expected instead of %s", s);
75 fprintf(stderr, "item expected instead of %s", s);
78 fprintf(stderr, "grid point for %s already in use", s);
81 fprintf(stderr, "grid too wide for %s", s);
84 fprintf(stderr, "grid too high for %s", s);
87 fprintf(stderr, "quote expected instead of %s", s);
90 fprintf(stderr, "????");
93 fprintf(stderr, " in file %s\n", infile);
94 fprintf(stderr, "C-File: %s, line: %d\n", file, line);
98 #define ReadDlgErr(in, er, es) ReadDlgError(in, er, es, __FILE__, __LINE__)
100 static void GetBuf(FILE *in, char *buf)
104 rc = fscanf(in, "%s", buf);
107 static void ReadAccOpen(const char *infile, FILE *in)
112 if (strcmp(buf, "{") != 0)
114 ReadDlgErr(infile, eACCOEXP, buf);
118 static void ReadAccClose(const char *infile, FILE *in)
123 if (strcmp(buf, "}") != 0)
125 ReadDlgErr(infile, eACCCEXP, buf);
129 void ReadQuoteString(const char *infile, FILE *in, char *buf)
134 /* Read until first quote */
135 while ((c[0] = fgetc(in)) != '"')
140 ReadDlgErr(infile, eQUOTE, c);
143 /* Read until second quote */
144 while ((c[0] = fgetc(in)) != '"')
151 static void ReadQuoteStringOrAccClose(FILE *in, char *buf)
156 /* Read until first quote */
169 /* Read until second quote */
170 while ((c = fgetc(in)) != '"')
177 static gmx_bool bNotAccClose(const char *buf)
179 return (strcmp(buf, "}") != 0);
182 static t_fitem *NewFItem(void)
197 static t_fsimple *NewFSimple(void)
206 static void AddFItemName(t_fitem *fitem, char *name)
208 srenew(fitem->name, ++fitem->nname);
209 fitem->name[fitem->nname-1] = strdup(name);
212 static t_fgroup *NewFGroup(void)
219 fgroup->fitem = NULL;
224 static void AddFGroupFItem(t_fgroup *fgroup, t_fitem *fitem)
226 srenew(fgroup->fitem, ++fgroup->nfitem);
227 fgroup->fitem[fgroup->nfitem-1] = fitem;
230 static t_fgroup *AddFGridFGroup(t_fgrid *fgrid)
232 srenew(fgrid->fgroup, ++fgrid->nfgroup);
233 fgrid->fgroup[fgrid->nfgroup-1] = NewFGroup();
234 return fgrid->fgroup[fgrid->nfgroup-1];
237 static t_fsimple *AddFGridFSimple(t_fgrid *fgrid)
239 srenew(fgrid->fsimple, ++fgrid->nfsimple);
240 fgrid->fsimple[fgrid->nfsimple-1] = NewFSimple();
241 return fgrid->fsimple[fgrid->nfsimple-1];
244 static t_fgrid *NewFGrid(void)
252 fgrid->fgroup = NULL;
254 fgrid->fsimple = NULL;
259 static void DoneFItem(t_fitem *fitem)
263 for (i = 0; (i < fitem->nname); i++)
265 sfree(fitem->name[i]);
274 static void DoneFGroup(t_fgroup *fgroup)
279 for (i = 0; (i < fgroup->nfitem); i++)
281 DoneFItem(fgroup->fitem[i]);
283 sfree(fgroup->fitem);
286 static void DoneFSimple(t_fsimple *fsimple)
288 DoneFItem(fsimple->fitem);
289 sfree(fsimple->fitem);
292 void DoneFGrid(t_fgrid *fgrid)
296 for (i = 0; (i < fgrid->nfgroup); i++)
298 DoneFGroup(fgrid->fgroup[i]);
300 sfree(fgrid->fgroup);
301 for (i = 0; (i < fgrid->nfsimple); i++)
303 DoneFSimple(fgrid->fsimple[i]);
305 sfree(fgrid->fsimple);
308 static t_fitem *ScanFItem(const char *infile, FILE *in, char *buf)
310 char set[STRLEN], get[STRLEN], help[STRLEN], def[STRLEN];
316 for (edlg = (edlgitem)0; (edlg < edlgNR+1); edlg = (edlgitem)(edlg + 1))
318 if (strcmp(buf, type[edlg]) == 0)
329 if (edlg == edlgNR+1)
331 ReadDlgErr(infile, eITEMEXP, buf);
340 ReadQuoteString(infile, in, buf);
341 AddFItemName(fitem, buf);
345 ReadAccOpen(infile, in);
346 ReadQuoteStringOrAccClose(in, buf);
347 while (bNotAccClose(buf))
349 AddFItemName(fitem, buf);
350 ReadQuoteStringOrAccClose(in, buf);
355 ReadDlgErr(infile, eITEMEXP, type[edlg]);
360 ReadQuoteString(infile, in, set);
361 ReadQuoteString(infile, in, get);
362 ReadQuoteString(infile, in, def);
363 ReadQuoteString(infile, in, help);
364 fitem->set = strdup(set);
365 fitem->get = strdup(get);
366 fitem->def = strdup(def);
367 fitem->help = strdup(help);
372 t_fgrid *FGridFromFile(const char *infile)
377 char newinfile[STRLEN];
384 in = libopen(infile);
386 if (strcmp(buf, "grid") != 0)
388 ReadDlgErr(infile, eGRIDEXP, buf);
391 if ((fscanf(in, "%d%d", &gridx, &gridy)) != 2)
393 ReadDlgErr(infile, eNOVALS, "grid w,h");
397 ReadAccOpen(infile, in);
399 while (bNotAccClose(buf))
401 if (strcmp(buf, "group") == 0)
403 fgroup = AddFGridFGroup(fgrid);
404 ReadQuoteString(infile, in, buf);
405 fgroup->name = strdup(buf);
406 if ((fscanf(in, "%d%d%d%d", &fgroup->x, &fgroup->y, &fgroup->w, &fgroup->h)) != 4)
408 ReadDlgErr(infile, eNOVALS, "group x,y,w,h");
410 if (fgroup->x+fgroup->w > gridx)
412 ReadDlgErr(infile, eTOOWIDE, buf);
414 if (fgroup->y+fgroup->h > gridy)
416 ReadDlgErr(infile, eTOOHIGH, buf);
418 ReadAccOpen(infile, in);
420 while (bNotAccClose(buf))
422 AddFGroupFItem(fgroup, ScanFItem(infile, in, buf));
426 else if (strcmp(buf, "simple") == 0)
428 fsimple = AddFGridFSimple(fgrid);
429 if ((fscanf(in, "%d%d%d%d", &fsimple->x, &fsimple->y, &fsimple->w, &fsimple->h)) != 4)
431 ReadDlgErr(infile, eNOVALS, "simple x,y,w,h");
433 if (fsimple->x+fsimple->w > gridx)
435 ReadDlgErr(infile, eTOOWIDE, "simple");
437 if (fsimple->y+fsimple->h > gridy)
439 ReadDlgErr(infile, eTOOHIGH, "simple");
441 ReadAccOpen(infile, in);
443 fsimple->fitem = ScanFItem(infile, in, buf);
444 ReadAccClose(infile, in);
453 static void DumpFItem(t_fitem *fitem)
457 printf(" type: %s, set: '%s', get: '%s', def: '%s', help: '%s'\n {",
458 type[fitem->edlg], fitem->set, fitem->get, fitem->def, fitem->help);
459 for (i = 0; (i < fitem->nname); i++)
461 printf(" '%s'", fitem->name[i]);
466 static void DumpFSimple(t_fsimple *fsimple)
468 printf("Simple %dx%d at %d,%d\n", fsimple->w, fsimple->h, fsimple->x, fsimple->y);
469 DumpFItem(fsimple->fitem);
472 static void DumpFGroup(t_fgroup *fgroup)
476 printf("Group %dx%d at %d,%d\n", fgroup->w, fgroup->h, fgroup->x, fgroup->y);
477 for (i = 0; (i < fgroup->nfitem); i++)
479 DumpFItem(fgroup->fitem[i]);
483 void DumpFGrid(t_fgrid *fgrid)
487 printf("Grid %dx%d\n", fgrid->w, fgrid->h);
488 for (i = 0; (i < fgrid->nfgroup); i++)
490 DumpFGroup(fgrid->fgroup[i]);
492 for (i = 0; (i < fgrid->nfsimple); i++)
494 DumpFSimple(fgrid->fsimple[i]);