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