1*9f988b79SJean-Baptiste Boric /* $NetBSD: cd9660_strings.c,v 1.5 2011/03/23 13:11:51 christos Exp $ */
2*9f988b79SJean-Baptiste Boric
3*9f988b79SJean-Baptiste Boric /*
4*9f988b79SJean-Baptiste Boric * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
5*9f988b79SJean-Baptiste Boric * Perez-Rathke and Ram Vedam. All rights reserved.
6*9f988b79SJean-Baptiste Boric *
7*9f988b79SJean-Baptiste Boric * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
8*9f988b79SJean-Baptiste Boric * Alan Perez-Rathke and Ram Vedam.
9*9f988b79SJean-Baptiste Boric *
10*9f988b79SJean-Baptiste Boric * Redistribution and use in source and binary forms, with or
11*9f988b79SJean-Baptiste Boric * without modification, are permitted provided that the following
12*9f988b79SJean-Baptiste Boric * conditions are met:
13*9f988b79SJean-Baptiste Boric * 1. Redistributions of source code must retain the above copyright
14*9f988b79SJean-Baptiste Boric * notice, this list of conditions and the following disclaimer.
15*9f988b79SJean-Baptiste Boric * 2. Redistributions in binary form must reproduce the above
16*9f988b79SJean-Baptiste Boric * copyright notice, this list of conditions and the following
17*9f988b79SJean-Baptiste Boric * disclaimer in the documentation and/or other materials provided
18*9f988b79SJean-Baptiste Boric * with the distribution.
19*9f988b79SJean-Baptiste Boric *
20*9f988b79SJean-Baptiste Boric * THIS SOFTWARE IS PROVIDED BY DANIEL WATT, WALTER DEIGNAN, RYAN
21*9f988b79SJean-Baptiste Boric * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
22*9f988b79SJean-Baptiste Boric * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23*9f988b79SJean-Baptiste Boric * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24*9f988b79SJean-Baptiste Boric * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
25*9f988b79SJean-Baptiste Boric * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
26*9f988b79SJean-Baptiste Boric * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27*9f988b79SJean-Baptiste Boric * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28*9f988b79SJean-Baptiste Boric * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29*9f988b79SJean-Baptiste Boric * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30*9f988b79SJean-Baptiste Boric * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31*9f988b79SJean-Baptiste Boric * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32*9f988b79SJean-Baptiste Boric * OF SUCH DAMAGE.
33*9f988b79SJean-Baptiste Boric */
34*9f988b79SJean-Baptiste Boric
35*9f988b79SJean-Baptiste Boric #if HAVE_NBTOOL_CONFIG_H
36*9f988b79SJean-Baptiste Boric #include "nbtool_config.h"
37*9f988b79SJean-Baptiste Boric #else
38*9f988b79SJean-Baptiste Boric #include <sys/mount.h>
39*9f988b79SJean-Baptiste Boric #endif
40*9f988b79SJean-Baptiste Boric
41*9f988b79SJean-Baptiste Boric #include <sys/cdefs.h>
42*9f988b79SJean-Baptiste Boric #include <sys/param.h>
43*9f988b79SJean-Baptiste Boric #include <ctype.h>
44*9f988b79SJean-Baptiste Boric
45*9f988b79SJean-Baptiste Boric #include "makefs.h"
46*9f988b79SJean-Baptiste Boric #include "cd9660.h"
47*9f988b79SJean-Baptiste Boric
48*9f988b79SJean-Baptiste Boric #if defined(__RCSID) && !defined(__lint)
49*9f988b79SJean-Baptiste Boric __RCSID("$NetBSD: cd9660_strings.c,v 1.5 2011/03/23 13:11:51 christos Exp $");
50*9f988b79SJean-Baptiste Boric #endif /* !__lint */
51*9f988b79SJean-Baptiste Boric
52*9f988b79SJean-Baptiste Boric
53*9f988b79SJean-Baptiste Boric void
cd9660_uppercase_characters(char * str,int len)54*9f988b79SJean-Baptiste Boric cd9660_uppercase_characters(char *str, int len)
55*9f988b79SJean-Baptiste Boric {
56*9f988b79SJean-Baptiste Boric int p;
57*9f988b79SJean-Baptiste Boric
58*9f988b79SJean-Baptiste Boric for (p = 0; p < len; p++) {
59*9f988b79SJean-Baptiste Boric if (islower((unsigned char)str[p]) )
60*9f988b79SJean-Baptiste Boric str[p] -= 32;
61*9f988b79SJean-Baptiste Boric }
62*9f988b79SJean-Baptiste Boric }
63*9f988b79SJean-Baptiste Boric
64*9f988b79SJean-Baptiste Boric static inline int
cd9660_is_d_char(char c)65*9f988b79SJean-Baptiste Boric cd9660_is_d_char(char c)
66*9f988b79SJean-Baptiste Boric {
67*9f988b79SJean-Baptiste Boric return (isupper((unsigned char)c)
68*9f988b79SJean-Baptiste Boric || c == '_'
69*9f988b79SJean-Baptiste Boric || (c >= '0' && c <= '9'));
70*9f988b79SJean-Baptiste Boric }
71*9f988b79SJean-Baptiste Boric
72*9f988b79SJean-Baptiste Boric static inline int
cd9660_is_a_char(char c)73*9f988b79SJean-Baptiste Boric cd9660_is_a_char(char c)
74*9f988b79SJean-Baptiste Boric {
75*9f988b79SJean-Baptiste Boric return (isupper((unsigned char)c)
76*9f988b79SJean-Baptiste Boric || c == '_'
77*9f988b79SJean-Baptiste Boric || (c >= '%' && c <= '?')
78*9f988b79SJean-Baptiste Boric || (c >= ' ' && c <= '\"'));
79*9f988b79SJean-Baptiste Boric }
80*9f988b79SJean-Baptiste Boric
81*9f988b79SJean-Baptiste Boric /*
82*9f988b79SJean-Baptiste Boric * Test a string to see if it is composed of valid a characters
83*9f988b79SJean-Baptiste Boric * @param const char* The string to test
84*9f988b79SJean-Baptiste Boric * @returns int 1 if valid, 2 if valid if characters are converted to
85*9f988b79SJean-Baptiste Boric * upper case, 0 otherwise
86*9f988b79SJean-Baptiste Boric */
87*9f988b79SJean-Baptiste Boric int
cd9660_valid_a_chars(const char * str)88*9f988b79SJean-Baptiste Boric cd9660_valid_a_chars(const char *str)
89*9f988b79SJean-Baptiste Boric {
90*9f988b79SJean-Baptiste Boric const char *c = str;
91*9f988b79SJean-Baptiste Boric int upperFound = 0;
92*9f988b79SJean-Baptiste Boric
93*9f988b79SJean-Baptiste Boric while ((*c) != '\0') {
94*9f988b79SJean-Baptiste Boric if (!(cd9660_is_a_char(*c))) {
95*9f988b79SJean-Baptiste Boric if (islower((unsigned char)*c) )
96*9f988b79SJean-Baptiste Boric upperFound = 1;
97*9f988b79SJean-Baptiste Boric else
98*9f988b79SJean-Baptiste Boric return 0;
99*9f988b79SJean-Baptiste Boric }
100*9f988b79SJean-Baptiste Boric c++;
101*9f988b79SJean-Baptiste Boric }
102*9f988b79SJean-Baptiste Boric return upperFound + 1;
103*9f988b79SJean-Baptiste Boric }
104*9f988b79SJean-Baptiste Boric
105*9f988b79SJean-Baptiste Boric /*
106*9f988b79SJean-Baptiste Boric * Test a string to see if it is composed of valid d characters
107*9f988b79SJean-Baptiste Boric * @param const char* The string to test
108*9f988b79SJean-Baptiste Boric * @returns int 1 if valid, 2 if valid if characters are converted to
109*9f988b79SJean-Baptiste Boric * upper case, 0 otherwise
110*9f988b79SJean-Baptiste Boric */
111*9f988b79SJean-Baptiste Boric int
cd9660_valid_d_chars(const char * str)112*9f988b79SJean-Baptiste Boric cd9660_valid_d_chars(const char *str)
113*9f988b79SJean-Baptiste Boric {
114*9f988b79SJean-Baptiste Boric const char *c=str;
115*9f988b79SJean-Baptiste Boric int upperFound = 0;
116*9f988b79SJean-Baptiste Boric
117*9f988b79SJean-Baptiste Boric while ((*c) != '\0') {
118*9f988b79SJean-Baptiste Boric if (!(cd9660_is_d_char(*c))) {
119*9f988b79SJean-Baptiste Boric if (islower((unsigned char)*c) )
120*9f988b79SJean-Baptiste Boric upperFound = 1;
121*9f988b79SJean-Baptiste Boric else
122*9f988b79SJean-Baptiste Boric return 0;
123*9f988b79SJean-Baptiste Boric }
124*9f988b79SJean-Baptiste Boric c++;
125*9f988b79SJean-Baptiste Boric }
126*9f988b79SJean-Baptiste Boric return upperFound + 1;
127*9f988b79SJean-Baptiste Boric }
128