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