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