101a0f853SOlivier Houchard /* $NetBSD: cd9660_strings.c,v 1.4 2007/01/16 17:32:05 hubertf Exp $ */
201a0f853SOlivier Houchard
31de7b4b8SPedro F. Giffuni /*-
4b61a5730SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
51de7b4b8SPedro F. Giffuni *
601a0f853SOlivier Houchard * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
701a0f853SOlivier Houchard * Perez-Rathke and Ram Vedam. All rights reserved.
801a0f853SOlivier Houchard *
901a0f853SOlivier Houchard * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
1001a0f853SOlivier Houchard * Alan Perez-Rathke and Ram Vedam.
1101a0f853SOlivier Houchard *
1201a0f853SOlivier Houchard * Redistribution and use in source and binary forms, with or
1301a0f853SOlivier Houchard * without modification, are permitted provided that the following
1401a0f853SOlivier Houchard * conditions are met:
1501a0f853SOlivier Houchard * 1. Redistributions of source code must retain the above copyright
1601a0f853SOlivier Houchard * notice, this list of conditions and the following disclaimer.
1701a0f853SOlivier Houchard * 2. Redistributions in binary form must reproduce the above
1801a0f853SOlivier Houchard * copyright notice, this list of conditions and the following
1901a0f853SOlivier Houchard * disclaimer in the documentation and/or other materials provided
2001a0f853SOlivier Houchard * with the distribution.
2101a0f853SOlivier Houchard *
2201a0f853SOlivier Houchard * THIS SOFTWARE IS PROVIDED BY DANIEL WATT, WALTER DEIGNAN, RYAN
2301a0f853SOlivier Houchard * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
2401a0f853SOlivier Houchard * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2501a0f853SOlivier Houchard * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2601a0f853SOlivier Houchard * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
2701a0f853SOlivier Houchard * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
2801a0f853SOlivier Houchard * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2901a0f853SOlivier Houchard * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
3001a0f853SOlivier Houchard * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
3101a0f853SOlivier Houchard * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3201a0f853SOlivier Houchard * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3301a0f853SOlivier Houchard * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
3401a0f853SOlivier Houchard * OF SUCH DAMAGE.
3501a0f853SOlivier Houchard */
3601a0f853SOlivier Houchard
3701a0f853SOlivier Houchard #include <sys/mount.h>
3801a0f853SOlivier Houchard
3901a0f853SOlivier Houchard #include <sys/param.h>
4001a0f853SOlivier Houchard #include <ctype.h>
4101a0f853SOlivier Houchard
4201a0f853SOlivier Houchard #include "makefs.h"
4301a0f853SOlivier Houchard #include "cd9660.h"
4401a0f853SOlivier Houchard
4501a0f853SOlivier Houchard
4601a0f853SOlivier Houchard void
cd9660_uppercase_characters(char * str,size_t len)471d1ffa2eSEd Maste cd9660_uppercase_characters(char *str, size_t len)
4801a0f853SOlivier Houchard {
491d1ffa2eSEd Maste size_t p;
5001a0f853SOlivier Houchard
5101a0f853SOlivier Houchard for (p = 0; p < len; p++) {
5201a0f853SOlivier Houchard if (islower((unsigned char)str[p]) )
5301a0f853SOlivier Houchard str[p] -= 32;
5401a0f853SOlivier Houchard }
5501a0f853SOlivier Houchard }
5601a0f853SOlivier Houchard
5701a0f853SOlivier Houchard static inline int
cd9660_is_d_char(char c)58395b253fSBaptiste Daroussin cd9660_is_d_char(char c)
5901a0f853SOlivier Houchard {
6001a0f853SOlivier Houchard return (isupper((unsigned char)c)
6101a0f853SOlivier Houchard || c == '_'
62b880379bSBaptiste Daroussin || (c >= '0' && c <= '9'));
6301a0f853SOlivier Houchard }
6401a0f853SOlivier Houchard
6501a0f853SOlivier Houchard static inline int
cd9660_is_a_char(char c)66395b253fSBaptiste Daroussin cd9660_is_a_char(char c)
6701a0f853SOlivier Houchard {
6801a0f853SOlivier Houchard return (isupper((unsigned char)c)
6901a0f853SOlivier Houchard || c == '_'
70b880379bSBaptiste Daroussin || (c >= '%' && c <= '?')
7101a0f853SOlivier Houchard || (c >= ' ' && c <= '\"'));
7201a0f853SOlivier Houchard }
7301a0f853SOlivier Houchard
7401a0f853SOlivier Houchard /*
7501a0f853SOlivier Houchard * Test a string to see if it is composed of valid a characters
7601a0f853SOlivier Houchard * @param const char* The string to test
7701a0f853SOlivier Houchard * @returns int 1 if valid, 2 if valid if characters are converted to
7801a0f853SOlivier Houchard * upper case, 0 otherwise
7901a0f853SOlivier Houchard */
8001a0f853SOlivier Houchard int
cd9660_valid_a_chars(const char * str)8101a0f853SOlivier Houchard cd9660_valid_a_chars(const char *str)
8201a0f853SOlivier Houchard {
8301a0f853SOlivier Houchard const char *c = str;
8401a0f853SOlivier Houchard int upperFound = 0;
8501a0f853SOlivier Houchard
8601a0f853SOlivier Houchard while ((*c) != '\0') {
8701a0f853SOlivier Houchard if (!(cd9660_is_a_char(*c))) {
8801a0f853SOlivier Houchard if (islower((unsigned char)*c) )
8901a0f853SOlivier Houchard upperFound = 1;
9001a0f853SOlivier Houchard else
9101a0f853SOlivier Houchard return 0;
9201a0f853SOlivier Houchard }
9301a0f853SOlivier Houchard c++;
9401a0f853SOlivier Houchard }
9501a0f853SOlivier Houchard return upperFound + 1;
9601a0f853SOlivier Houchard }
9701a0f853SOlivier Houchard
9801a0f853SOlivier Houchard /*
9901a0f853SOlivier Houchard * Test a string to see if it is composed of valid d characters
10001a0f853SOlivier Houchard * @param const char* The string to test
10101a0f853SOlivier Houchard * @returns int 1 if valid, 2 if valid if characters are converted to
10201a0f853SOlivier Houchard * upper case, 0 otherwise
10301a0f853SOlivier Houchard */
10401a0f853SOlivier Houchard int
cd9660_valid_d_chars(const char * str)10501a0f853SOlivier Houchard cd9660_valid_d_chars(const char *str)
10601a0f853SOlivier Houchard {
10701a0f853SOlivier Houchard const char *c=str;
10801a0f853SOlivier Houchard int upperFound = 0;
10901a0f853SOlivier Houchard
11001a0f853SOlivier Houchard while ((*c) != '\0') {
11101a0f853SOlivier Houchard if (!(cd9660_is_d_char(*c))) {
11201a0f853SOlivier Houchard if (islower((unsigned char)*c) )
11301a0f853SOlivier Houchard upperFound = 1;
11401a0f853SOlivier Houchard else
11501a0f853SOlivier Houchard return 0;
11601a0f853SOlivier Houchard }
11701a0f853SOlivier Houchard c++;
11801a0f853SOlivier Houchard }
11901a0f853SOlivier Houchard return upperFound + 1;
12001a0f853SOlivier Houchard }
121