]> diplodocus.org Git - nmh/blob - sbr/seq_nameok.c
mhlsbr.c: Don't strchr(3) non-string NUL-less buffer.
[nmh] / sbr / seq_nameok.c
1 /* seq_nameok.c -- check if a sequence name is ok
2 *
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
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 inform("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 inform("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 ((unsigned char) *s)) {
40 inform("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 ((unsigned char) *pp)) {
49 inform("illegal sequence name: %s", s);
50 return 0;
51 }
52
53 return 1;
54 }