X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fmolecule.c;h=02b8362461a5285bf26fd8661f602fb715da9085;hb=a94197e76a5dea5cb60542840809d6c20d0abbf3;hp=069d74752941308ebd95c56b6cd8a5cb96ef3320;hpb=a1d41b2aa6e18bf9a49b914a99dda8232c5d7762;p=xscreensaver diff --git a/hacks/glx/molecule.c b/hacks/glx/molecule.c index 069d7475..02b83624 100644 --- a/hacks/glx/molecule.c +++ b/hacks/glx/molecule.c @@ -112,6 +112,7 @@ #ifdef USE_GL /* whole file */ +#include #include #include @@ -229,7 +230,7 @@ static XrmOptionDescRec opts[] = { { "-molecule", ".molecule", XrmoptionSepArg, 0 }, { "-timeout",".timeout",XrmoptionSepArg, 0 }, { "-spin", ".spin", XrmoptionSepArg, 0 }, - { "+spin", ".spin", XrmoptionNoArg, "" }, + { "+spin", ".spin", XrmoptionNoArg, "False" }, { "-wander", ".wander", XrmoptionNoArg, "True" }, { "+wander", ".wander", XrmoptionNoArg, "False" }, { "-labels", ".labels", XrmoptionNoArg, "True" }, @@ -1034,13 +1035,34 @@ parse_pdb_file (molecule *m, const char *name) } +typedef struct { char *atom; int count; } atom_and_count; + +/* When listing the components of a molecule, the convention is to put the + carbon atoms first, the hydrogen atoms second, and the other atom types + sorted alphabetically after that (although for some molecules, the usual + order is different, like for NH(3), but we don't special-case those.) + */ +static int +cmp_atoms (const void *aa, const void *bb) +{ + const atom_and_count *a = (atom_and_count *) aa; + const atom_and_count *b = (atom_and_count *) bb; + if (!a->atom) return 1; + if (!b->atom) return -1; + if (!strcmp(a->atom, "C")) return -1; + if (!strcmp(b->atom, "C")) return 1; + if (!strcmp(a->atom, "H")) return -1; + if (!strcmp(b->atom, "H")) return 1; + return strcmp (a->atom, b->atom); +} + static void generate_molecule_formula (molecule *m) { char *buf = (char *) malloc (m->natoms * 10); char *s = buf; int i; - struct { char *atom; int count; } counts[200]; + atom_and_count counts[200]; memset (counts, 0, sizeof(counts)); *s = 0; for (i = 0; i < m->natoms; i++) @@ -1061,6 +1083,10 @@ generate_molecule_formula (molecule *m) counts[j].count++; } + i = 0; + while (counts[i].atom) i++; + qsort (counts, i, sizeof(*counts), cmp_atoms); + i = 0; while (counts[i].atom) {