mh_xstrdup arguments now const
[mmh] / sbr / seq_nameok.c
1 /*
2 ** seq_nameok.c -- check if a name is ok for a user-defined sequence
3 **
4 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
7 */
8
9 #include <h/mh.h>
10 #include <ctype.h>
11
12
13 /*
14 ** returns true if it is a valid name for a user-defined sequence
15 */
16 int
17 seq_nameok(unsigned char *s)
18 {
19         unsigned char *pp;
20
21         if (s == NULL || *s == '\0') {
22                 advise(NULL, "empty sequence name");
23                 return 0;
24         }
25
26         /*
27         ** Make sure sequence name doesn't clash with one
28         ** of the `reserved' sequence names.
29         ** Note: Accept `cur' here! But why is it treated special? --meillo
30         */
31         if (strcmp(s, seq_first)==0 || strcmp(s, seq_last)==0 ||
32                         strcmp(s, seq_prev)==0 || strcmp(s, seq_next)==0 ||
33                         strcmp(s, seq_all)==0 || strcmp(s, seq_beyond)==0) {
34                 advise(NULL, "collision with reserved sequence name: `%s'", s);
35                 return 0;
36         }
37
38         /*
39         ** First character in a sequence name must be
40         ** an alphabetic character ...
41         */
42         if (!isalpha(*s)) {
43                 advise(NULL, "sequence name must start with a letter: %s", s);
44                 return 0;
45         }
46
47         /*
48         ** and can be followed by zero or more alphanumeric characters
49         */
50         for (pp = s+1; *pp; pp++) {
51                 if (!isalnum(*pp)) {
52                         advise(NULL, "sequence name must only contain "
53                                         "letters and digits: %s", s);
54                         return 0;
55                 }
56         }
57
58         return 1;
59 }