1214921Scognet/*	$NetBSD: cd9660_strings.c,v 1.4 2007/01/16 17:32:05 hubertf Exp $	*/
2214921Scognet
3214921Scognet/*
4214921Scognet * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
5214921Scognet * Perez-Rathke and Ram Vedam.  All rights reserved.
6214921Scognet *
7214921Scognet * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
8214921Scognet * Alan Perez-Rathke and Ram Vedam.
9214921Scognet *
10214921Scognet * Redistribution and use in source and binary forms, with or
11214921Scognet * without modification, are permitted provided that the following
12214921Scognet * conditions are met:
13214921Scognet * 1. Redistributions of source code must retain the above copyright
14214921Scognet *    notice, this list of conditions and the following disclaimer.
15214921Scognet * 2. Redistributions in binary form must reproduce the above
16214921Scognet *    copyright notice, this list of conditions and the following
17214921Scognet *    disclaimer in the documentation and/or other materials provided
18214921Scognet *    with the distribution.
19214921Scognet *
20214921Scognet * THIS SOFTWARE IS PROVIDED BY DANIEL WATT, WALTER DEIGNAN, RYAN
21214921Scognet * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
22214921Scognet * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23214921Scognet * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24214921Scognet * DISCLAIMED.  IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
25214921Scognet * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
26214921Scognet * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27214921Scognet * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28214921Scognet * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29214921Scognet * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30214921Scognet * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31214921Scognet * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32214921Scognet * OF SUCH DAMAGE.
33214921Scognet */
34214921Scognet
35214921Scognet#include <sys/mount.h>
36214921Scognet
37214921Scognet#include <sys/cdefs.h>
38214921Scognet__FBSDID("$FreeBSD$");
39214921Scognet#include <sys/param.h>
40214921Scognet#include <ctype.h>
41214921Scognet
42214921Scognet#include "makefs.h"
43214921Scognet#include "cd9660.h"
44214921Scognet
45214921Scognet
46214921Scognetvoid
47214921Scognetcd9660_uppercase_characters(char *str, int len)
48214921Scognet{
49214921Scognet	int p;
50214921Scognet
51214921Scognet	for (p = 0; p < len; p++) {
52214921Scognet		if (islower((unsigned char)str[p]) )
53214921Scognet			str[p] -= 32;
54214921Scognet	}
55214921Scognet}
56214921Scognet
57214921Scognetstatic inline int
58219956Sbaptcd9660_is_d_char(char c)
59214921Scognet{
60214921Scognet	return (isupper((unsigned char)c)
61214921Scognet		|| c == '_'
62219954Sbapt		|| (c >= '0' && c <= '9'));
63214921Scognet}
64214921Scognet
65214921Scognetstatic inline int
66219956Sbaptcd9660_is_a_char(char c)
67214921Scognet{
68214921Scognet	return (isupper((unsigned char)c)
69214921Scognet			|| c == '_'
70219954Sbapt			|| (c >= '%' && c <= '?')
71214921Scognet			|| (c >= ' ' && c <= '\"'));
72214921Scognet}
73214921Scognet
74214921Scognet/*
75214921Scognet * Test a string to see if it is composed of valid a characters
76214921Scognet * @param const char* The string to test
77214921Scognet * @returns int 1 if valid, 2 if valid if characters are converted to
78214921Scognet *              upper case, 0 otherwise
79214921Scognet */
80214921Scognetint
81214921Scognetcd9660_valid_a_chars(const char *str)
82214921Scognet{
83214921Scognet	const char *c = str;
84214921Scognet	int upperFound = 0;
85214921Scognet
86214921Scognet	while ((*c) != '\0') {
87214921Scognet		if (!(cd9660_is_a_char(*c))) {
88214921Scognet			if (islower((unsigned char)*c) )
89214921Scognet				upperFound = 1;
90214921Scognet			else
91214921Scognet				return 0;
92214921Scognet		}
93214921Scognet		c++;
94214921Scognet	}
95214921Scognet	return upperFound + 1;
96214921Scognet}
97214921Scognet
98214921Scognet/*
99214921Scognet * Test a string to see if it is composed of valid d characters
100214921Scognet * @param const char* The string to test
101214921Scognet * @returns int 1 if valid, 2 if valid if characters are converted to
102214921Scognet *                upper case, 0 otherwise
103214921Scognet */
104214921Scognetint
105214921Scognetcd9660_valid_d_chars(const char *str)
106214921Scognet{
107214921Scognet	const char *c=str;
108214921Scognet	int upperFound = 0;
109214921Scognet
110214921Scognet	while ((*c) != '\0') {
111214921Scognet		if (!(cd9660_is_d_char(*c))) {
112214921Scognet			if (islower((unsigned char)*c) )
113214921Scognet				upperFound = 1;
114214921Scognet			else
115214921Scognet				return 0;
116214921Scognet		}
117214921Scognet		c++;
118214921Scognet	}
119214921Scognet	return upperFound + 1;
120214921Scognet}
121