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-2013, 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
46 #include "gromacs/fileio/futil.h"
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, "source file: %s, line: %d\n", file, line);
98 #define ReadDlgErr(in, er, es) ReadDlgError(in, er, es, __FILE__, __LINE__)
100 static void ReadAccOpen(const char *infile, FILE *in)
104 fscanf(in, "%4s", buf);
105 if (strcmp(buf, "{") != 0)
107 ReadDlgErr(infile, eACCOEXP, buf);
111 static void ReadAccClose(const char *infile, FILE *in)
115 fscanf(in, "%4s", buf);
116 if (strcmp(buf, "}") != 0)
118 ReadDlgErr(infile, eACCCEXP, buf);
122 void ReadQuoteString(const char *infile, FILE *in, char *buf)
127 /* Read until first quote */
128 while ((c[0] = fgetc(in)) != '"')
133 ReadDlgErr(infile, eQUOTE, c);
136 /* Read until second quote */
137 while ((c[0] = fgetc(in)) != '"')
144 static void ReadQuoteStringOrAccClose(FILE *in, char *buf)
149 /* Read until first quote */
162 /* Read until second quote */
163 while ((c = fgetc(in)) != '"')
170 static bool bNotAccClose(const char *buf)
172 return (strcmp(buf, "}") != 0);
175 static t_fitem *NewFItem(void)
190 static t_fsimple *NewFSimple(void)
199 static void AddFItemName(t_fitem *fitem, char *name)
201 srenew(fitem->name, ++fitem->nname);
202 fitem->name[fitem->nname-1] = strdup(name);
205 static t_fgroup *NewFGroup(void)
212 fgroup->fitem = NULL;
217 static void AddFGroupFItem(t_fgroup *fgroup, t_fitem *fitem)
219 srenew(fgroup->fitem, ++fgroup->nfitem);
220 fgroup->fitem[fgroup->nfitem-1] = fitem;
223 static t_fgroup *AddFGridFGroup(t_fgrid *fgrid)
225 srenew(fgrid->fgroup, ++fgrid->nfgroup);
226 fgrid->fgroup[fgrid->nfgroup-1] = NewFGroup();
227 return fgrid->fgroup[fgrid->nfgroup-1];
230 static t_fsimple *AddFGridFSimple(t_fgrid *fgrid)
232 srenew(fgrid->fsimple, ++fgrid->nfsimple);
233 fgrid->fsimple[fgrid->nfsimple-1] = NewFSimple();
234 return fgrid->fsimple[fgrid->nfsimple-1];
237 static t_fgrid *NewFGrid(void)
245 fgrid->fgroup = NULL;
247 fgrid->fsimple = NULL;
252 static void DoneFItem(t_fitem *fitem)
256 for (i = 0; (i < fitem->nname); i++)
258 sfree(fitem->name[i]);
267 static void DoneFGroup(t_fgroup *fgroup)
272 for (i = 0; (i < fgroup->nfitem); i++)
274 DoneFItem(fgroup->fitem[i]);
276 sfree(fgroup->fitem);
279 static void DoneFSimple(t_fsimple *fsimple)
281 DoneFItem(fsimple->fitem);
282 sfree(fsimple->fitem);
285 void DoneFGrid(t_fgrid *fgrid)
289 for (i = 0; (i < fgrid->nfgroup); i++)
291 DoneFGroup(fgrid->fgroup[i]);
293 sfree(fgrid->fgroup);
294 for (i = 0; (i < fgrid->nfsimple); i++)
296 DoneFSimple(fgrid->fsimple[i]);
298 sfree(fgrid->fsimple);
301 static t_fitem *ScanFItem(const char *infile, FILE *in, char *buf)
303 char set[STRLEN], get[STRLEN], help[STRLEN], def[STRLEN];
309 for (edlg = (edlgitem)0; (edlg < edlgNR+1); edlg = (edlgitem)(edlg + 1))
311 if (strcmp(buf, type[edlg]) == 0)
322 if (edlg == edlgNR+1)
324 ReadDlgErr(infile, eITEMEXP, buf);
333 ReadQuoteString(infile, in, buf);
334 AddFItemName(fitem, buf);
338 ReadAccOpen(infile, in);
339 ReadQuoteStringOrAccClose(in, buf);
340 while (bNotAccClose(buf))
342 AddFItemName(fitem, buf);
343 ReadQuoteStringOrAccClose(in, buf);
348 ReadDlgErr(infile, eITEMEXP, type[edlg]);
353 ReadQuoteString(infile, in, set);
354 ReadQuoteString(infile, in, get);
355 ReadQuoteString(infile, in, def);
356 ReadQuoteString(infile, in, help);
357 fitem->set = strdup(set);
358 fitem->get = strdup(get);
359 fitem->def = strdup(def);
360 fitem->help = strdup(help);
365 t_fgrid *FGridFromFile(const char *infile)
375 in = libopen(infile);
376 fscanf(in, "%6s", buf);
377 if (strcmp(buf, "grid") != 0)
379 ReadDlgErr(infile, eGRIDEXP, buf);
382 if ((fscanf(in, "%5d%5d", &gridx, &gridy)) != 2)
384 ReadDlgErr(infile, eNOVALS, "grid w,h");
388 ReadAccOpen(infile, in);
389 fscanf(in, "%15s", buf);
390 while (bNotAccClose(buf))
392 if (strcmp(buf, "group") == 0)
394 fgroup = AddFGridFGroup(fgrid);
395 ReadQuoteString(infile, in, buf);
396 fgroup->name = strdup(buf);
397 if ((fscanf(in, "%5d%5d%5d%5d", &fgroup->x, &fgroup->y, &fgroup->w, &fgroup->h)) != 4)
399 ReadDlgErr(infile, eNOVALS, "group x,y,w,h");
401 if (fgroup->x+fgroup->w > gridx)
403 ReadDlgErr(infile, eTOOWIDE, buf);
405 if (fgroup->y+fgroup->h > gridy)
407 ReadDlgErr(infile, eTOOHIGH, buf);
409 ReadAccOpen(infile, in);
410 fscanf(in, "%15s", buf);
411 while (bNotAccClose(buf))
413 AddFGroupFItem(fgroup, ScanFItem(infile, in, buf));
414 fscanf(in, "%15s", buf);
417 else if (strcmp(buf, "simple") == 0)
419 fsimple = AddFGridFSimple(fgrid);
420 if ((fscanf(in, "%5d%5d%5d%5d", &fsimple->x, &fsimple->y, &fsimple->w, &fsimple->h)) != 4)
422 ReadDlgErr(infile, eNOVALS, "simple x,y,w,h");
424 if (fsimple->x+fsimple->w > gridx)
426 ReadDlgErr(infile, eTOOWIDE, "simple");
428 if (fsimple->y+fsimple->h > gridy)
430 ReadDlgErr(infile, eTOOHIGH, "simple");
432 ReadAccOpen(infile, in);
433 fscanf(in, "%15s", buf);
434 fsimple->fitem = ScanFItem(infile, in, buf);
435 ReadAccClose(infile, in);
437 fscanf(in, "%15s", buf);
444 static void DumpFItem(t_fitem *fitem)
448 printf(" type: %s, set: '%s', get: '%s', def: '%s', help: '%s'\n {",
449 type[fitem->edlg], fitem->set, fitem->get, fitem->def, fitem->help);
450 for (i = 0; (i < fitem->nname); i++)
452 printf(" '%s'", fitem->name[i]);
457 static void DumpFSimple(t_fsimple *fsimple)
459 printf("Simple %dx%d at %d,%d\n", fsimple->w, fsimple->h, fsimple->x, fsimple->y);
460 DumpFItem(fsimple->fitem);
463 static void DumpFGroup(t_fgroup *fgroup)
467 printf("Group %dx%d at %d,%d\n", fgroup->w, fgroup->h, fgroup->x, fgroup->y);
468 for (i = 0; (i < fgroup->nfitem); i++)
470 DumpFItem(fgroup->fitem[i]);
474 void DumpFGrid(t_fgrid *fgrid)
478 printf("Grid %dx%d\n", fgrid->w, fgrid->h);
479 for (i = 0; (i < fgrid->nfgroup); i++)
481 DumpFGroup(fgrid->fgroup[i]);
483 for (i = 0; (i < fgrid->nfsimple); i++)
485 DumpFSimple(fgrid->fsimple[i]);