Changeset 521


Ignore:
Timestamp:
06/23/16 00:09:06 (8 years ago)
Author:
Maciej Komosinski
Message:

Extended error messages for invalid genotype format declaration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/geno.cpp

    r518 r521  
    3434                if (genstring.charAt(0) == '/')
    3535                {
    36                         int end;
     36                        int end, error_end=-1;
    3737                        switch (genstring.charAt(1))
    3838                        {
    3939                        case '/':
    4040                                genformat = genstring.charAt(2);
    41                                 if ((genformat=='\0')||(genformat=='\n'))
     41                                if ((genformat=='\0')||isspace(genformat))
    4242                                        genformat=INVALID_FORMAT;
    4343                                if ((end = genstring.indexOf('\n')) >= 0)
    4444                                {
     45                                        error_end=end;
    4546                                        if (end!=3) genformat=INVALID_FORMAT;
    4647                                        gencopy = genstring.substr(end + 1);
     
    5657                        case '*':
    5758                                genformat = genstring.charAt(2);
    58                                 if ((genformat=='\0')||(genformat=='\n'))
     59                                if ((genformat=='\0')||isspace(genformat))
    5960                                        genformat=INVALID_FORMAT;
    6061                                if ((end = genstring.indexOf("*/")) >= 0)
    6162                                {
     63                                        error_end=end+2;
    6264                                        if (end!=3) genformat=INVALID_FORMAT;
    6365                                        gencopy = genstring.substr(end + 2);
     
    7274                                break;
    7375                        }
     76                if (genformat==INVALID_FORMAT)
     77                        {
     78                        SString cut;
     79                        if (error_end<0) error_end=genstring.len();
     80                        static const int MAX_ERROR=20;
     81                        if (error_end>MAX_ERROR)
     82                                cut=genstring.substr(0,MAX_ERROR)+"...";
     83                        else
     84                                cut=genstring.substr(0,error_end);
     85                        int lf=cut.indexOf('\n');
     86                        if (lf>=0) cut=cut.substr(0,lf);
     87                        logPrintf("Geno","init",LOG_ERROR,"Invalid genotype format declaration: '%s'%s",cut.c_str(),genname.len()?SString::sprintf(" in '%s'",genname.c_str()).c_str():"");
     88                        }
     89
    7490                }
    7591        }
     
    274290                }
    275291        isvalid = 0;
    276         logPrintf("Geno", "validate", LOG_WARN, "Wrong configuration? No genotype validators defined for genetic format f%c.", format);
     292        logPrintf("Geno", "validate", LOG_WARN, "Wrong configuration? No genotype validators defined for genetic format 'f%c'.", format);
    277293}
    278294
Note: See TracChangeset for help on using the changeset viewer.