From: Teemu Murtola Date: Thu, 5 Jun 2014 03:28:12 +0000 (+0300) Subject: Remove support for "old" index file format X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=2ec0af58e19928d4176de734e10b60f7c21001d2;p=alexxy%2Fgromacs.git Remove support for "old" index file format The format wasn't documented anywhere, was at least 10+ years old, and error handling in the reading code was non-existent. Change-Id: I5abf97bfaa938f819228cace1eba948b8e45f796 --- diff --git a/src/gromacs/topology/index.cpp b/src/gromacs/topology/index.cpp index 60bbef46d1..31b2e663cc 100644 --- a/src/gromacs/topology/index.cpp +++ b/src/gromacs/topology/index.cpp @@ -55,7 +55,6 @@ #include "gromacs/topology/atoms.h" #include "gromacs/topology/block.h" #include "gromacs/topology/invblock.h" -#include "gromacs/utility/common.h" #include "gromacs/utility/cstringutil.h" #include "gromacs/utility/fatalerror.h" #include "gromacs/utility/futil.h" @@ -999,81 +998,52 @@ t_blocka *init_index(const char *gfile, char ***grpname) { FILE *in; t_blocka *b; - int a, maxentries; - int i, j, ng; + int maxentries; + int i, j; char line[STRLEN], *pt, str[STRLEN]; in = gmx_fio_fopen(gfile, "r"); snew(b, 1); - get_a_line(in, line, STRLEN); - if (line[0] == '[') + b->nr = 0; + b->index = NULL; + b->nra = 0; + b->a = NULL; + *grpname = NULL; + maxentries = 0; + while (get_a_line(in, line, STRLEN)) { - /* new format */ - b->nr = 0; - b->index = NULL; - b->nra = 0; - b->a = NULL; - *grpname = NULL; - maxentries = 0; - do + if (get_header(line, str)) { - if (get_header(line, str)) - { - b->nr++; - srenew(b->index, b->nr+1); - srenew(*grpname, b->nr); - if (b->nr == 1) - { - b->index[0] = 0; - } - b->index[b->nr] = b->index[b->nr-1]; - (*grpname)[b->nr-1] = strdup(str); - } - else + b->nr++; + srenew(b->index, b->nr+1); + srenew(*grpname, b->nr); + if (b->nr == 1) { - if (b->nr == 0) - { - gmx_fatal(FARGS, "The first header of your indexfile is invalid"); - } - pt = line; - while (sscanf(pt, "%s", str) == 1) - { - i = b->index[b->nr]; - if (i >= maxentries) - { - maxentries += 1024; - srenew(b->a, maxentries); - } - b->a[i] = strtol(str, NULL, 10)-1; - b->index[b->nr]++; - (b->nra)++; - pt = strstr(pt, str)+strlen(str); - } + b->index[0] = 0; } + b->index[b->nr] = b->index[b->nr-1]; + (*grpname)[b->nr-1] = strdup(str); } - while (get_a_line(in, line, STRLEN)); - } - else - { - /* old format */ - sscanf(line, "%d%d", &b->nr, &b->nra); - snew(b->index, b->nr+1); - snew(*grpname, b->nr); - b->index[0] = 0; - snew(b->a, b->nra); - for (i = 0; (i < b->nr); i++) + else { - GMX_IGNORE_RETURN_VALUE(fscanf(in, "%s%d", str, &ng)); - (*grpname)[i] = strdup(str); - b->index[i+1] = b->index[i]+ng; - if (b->index[i+1] > b->nra) + if (b->nr == 0) { - gmx_fatal(FARGS, "Something wrong in your indexfile at group %s", str); + gmx_fatal(FARGS, "The first header of your indexfile is invalid"); } - for (j = 0; (j < ng); j++) + pt = line; + while (sscanf(pt, "%s", str) == 1) { - GMX_IGNORE_RETURN_VALUE(fscanf(in, "%d", &a)); - b->a[b->index[i]+j] = a; + i = b->index[b->nr]; + if (i >= maxentries) + { + maxentries += 1024; + srenew(b->a, maxentries); + } + assert(b->a != NULL); // for clang analyzer + b->a[i] = strtol(str, NULL, 10)-1; + b->index[b->nr]++; + (b->nra)++; + pt = strstr(pt, str)+strlen(str); } } } @@ -1081,6 +1051,7 @@ t_blocka *init_index(const char *gfile, char ***grpname) for (i = 0; (i < b->nr); i++) { + assert(b->a != NULL); // for clang analyzer for (j = b->index[i]; (j < b->index[i+1]); j++) { if (b->a[j] < 0)