X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Fseq_nameok.c;h=54d63eed641bac4d874ced7360c3b8ca95214ff7;hp=6887ac6a309cce6a5e10792f1bfec0173c09418c;hb=18591f8e001ecedbee48a51c1d1f08ebaa1c15c8;hpb=5dd6771b28c257af405d7248639ed0e3bcdce38b diff --git a/sbr/seq_nameok.c b/sbr/seq_nameok.c index 6887ac6..54d63ee 100644 --- a/sbr/seq_nameok.c +++ b/sbr/seq_nameok.c @@ -1,56 +1,59 @@ - /* - * seq_nameok.c -- check if a sequence name is ok - * - * This code is Copyright (c) 2002, by the authors of nmh. See the - * COPYRIGHT file in the root directory of the nmh distribution for - * complete copyright information. - */ +** seq_nameok.c -- check if a name is ok for a user-defined sequence +** +** This code is Copyright (c) 2002, by the authors of nmh. See the +** COPYRIGHT file in the root directory of the nmh distribution for +** complete copyright information. +*/ #include +#include +/* +** returns true if it is a valid name for a user-defined sequence +*/ int -seq_nameok (unsigned char *s) +seq_nameok(unsigned char *s) { - unsigned char *pp; - - if (s == NULL || *s == '\0') { - advise (NULL, "empty sequence name"); - return 0; - } - - /* - * Make sure sequence name doesn't clash with one - * of the `reserved' sequence names. - */ - if (!(strcmp (s, "new") && - strcmp (s, "all") && - strcmp (s, "first") && - strcmp (s, "last") && - strcmp (s, "prev") && - strcmp (s, "next"))) { - advise (NULL, "illegal sequence name: %s", s); - return 0; - } - - /* - * First character in a sequence name must be - * an alphabetic character ... - */ - if (!isalpha (*s)) { - advise (NULL, "illegal sequence name: %s", s); - return 0; - } - - /* - * and can be followed by zero or more alphanumeric characters - */ - for (pp = s + 1; *pp; pp++) - if (!isalnum (*pp)) { - advise (NULL, "illegal sequence name: %s", s); - return 0; + unsigned char *pp; + + if (s == NULL || *s == '\0') { + advise(NULL, "empty sequence name"); + return 0; + } + + /* + ** Make sure sequence name doesn't clash with one + ** of the `reserved' sequence names. + ** Note: Accept `cur' here! But why is it treated special? --meillo + */ + if (strcmp(s, seq_first)==0 || strcmp(s, seq_last)==0 || + strcmp(s, seq_prev)==0 || strcmp(s, seq_next)==0 || + strcmp(s, seq_all)==0 || strcmp(s, seq_beyond)==0) { + advise(NULL, "collision with reserved sequence name: `%s'", s); + return 0; + } + + /* + ** First character in a sequence name must be + ** an alphabetic character ... + */ + if (!isalpha(*s)) { + advise(NULL, "sequence name must start with a letter: %s", s); + return 0; + } + + /* + ** and can be followed by zero or more alphanumeric characters + */ + for (pp = s+1; *pp; pp++) { + if (!isalnum(*pp)) { + advise(NULL, "sequence name must only contain " + "letters and digits: %s", s); + return 0; + } } - return 1; + return 1; }