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