66319b5ef4368ffcb8701416f1d1a13722192d59
[mmh] / sbr / seq_nameok.c
1
2 /*
3  * seq_nameok.c -- check if a sequence name is ok
4  *
5  * $Id$
6  */
7
8 #include <h/mh.h>
9
10
11 int
12 seq_nameok (char *s)
13 {
14     char *pp;
15
16     if (s == NULL || *s == '\0') {
17         advise (NULL, "empty sequence name");
18         return 0;
19     }
20
21     /*
22      * Make sure sequence name doesn't clash with one
23      * of the `reserved' sequence names.
24      */
25     if (!(strcmp (s, "new") &&
26           strcmp (s, "all") &&
27           strcmp (s, "first") &&
28           strcmp (s, "last") &&
29           strcmp (s, "prev") &&
30           strcmp (s, "next"))) {
31         advise (NULL, "illegal sequence name: %s", s);
32         return 0;
33     }
34
35     /*
36      * First character in a sequence name must be
37      * an alphabetic character ...
38      */
39     if (!isalpha (*s)) {
40         advise (NULL, "illegal sequence name: %s", s);
41         return 0;
42     }
43
44     /*
45      * and can be followed by zero or more alphanumeric characters
46      */
47     for (pp = s + 1; *pp; pp++)
48         if (!isalnum (*pp)) {
49             advise (NULL, "illegal sequence name: %s", s);
50             return 0;
51         }
52
53     return 1;
54 }