1*c316d7b2Schristos /* $NetBSD: cd9660_strings.c,v 1.6 2015/12/24 15:52:37 christos Exp $ */
23550dc98Sfvdl
33550dc98Sfvdl /*
43550dc98Sfvdl * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
53550dc98Sfvdl * Perez-Rathke and Ram Vedam. All rights reserved.
63550dc98Sfvdl *
73550dc98Sfvdl * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
83550dc98Sfvdl * Alan Perez-Rathke and Ram Vedam.
93550dc98Sfvdl *
103550dc98Sfvdl * Redistribution and use in source and binary forms, with or
113550dc98Sfvdl * without modification, are permitted provided that the following
123550dc98Sfvdl * conditions are met:
133550dc98Sfvdl * 1. Redistributions of source code must retain the above copyright
143550dc98Sfvdl * notice, this list of conditions and the following disclaimer.
153550dc98Sfvdl * 2. Redistributions in binary form must reproduce the above
163550dc98Sfvdl * copyright notice, this list of conditions and the following
173550dc98Sfvdl * disclaimer in the documentation and/or other materials provided
183550dc98Sfvdl * with the distribution.
193550dc98Sfvdl *
203550dc98Sfvdl * THIS SOFTWARE IS PROVIDED BY DANIEL WATT, WALTER DEIGNAN, RYAN
213550dc98Sfvdl * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
223550dc98Sfvdl * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
233550dc98Sfvdl * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
243550dc98Sfvdl * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
253550dc98Sfvdl * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
263550dc98Sfvdl * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
273550dc98Sfvdl * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
283550dc98Sfvdl * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
293550dc98Sfvdl * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
303550dc98Sfvdl * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
313550dc98Sfvdl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
323550dc98Sfvdl * OF SUCH DAMAGE.
333550dc98Sfvdl */
343550dc98Sfvdl
353550dc98Sfvdl #if HAVE_NBTOOL_CONFIG_H
363550dc98Sfvdl #include "nbtool_config.h"
37889da177Shubertf #else
38889da177Shubertf #include <sys/mount.h>
393550dc98Sfvdl #endif
403550dc98Sfvdl
413550dc98Sfvdl #include <sys/cdefs.h>
423550dc98Sfvdl #include <sys/param.h>
433550dc98Sfvdl #include <ctype.h>
443550dc98Sfvdl
453550dc98Sfvdl #include "makefs.h"
463550dc98Sfvdl #include "cd9660.h"
473550dc98Sfvdl
483550dc98Sfvdl #if defined(__RCSID) && !defined(__lint)
49*c316d7b2Schristos __RCSID("$NetBSD: cd9660_strings.c,v 1.6 2015/12/24 15:52:37 christos Exp $");
503550dc98Sfvdl #endif /* !__lint */
513550dc98Sfvdl
523550dc98Sfvdl
533550dc98Sfvdl void
cd9660_uppercase_characters(char * str,size_t len)54*c316d7b2Schristos cd9660_uppercase_characters(char *str, size_t len)
553550dc98Sfvdl {
56*c316d7b2Schristos size_t p;
573550dc98Sfvdl
583550dc98Sfvdl for (p = 0; p < len; p++) {
593550dc98Sfvdl if (islower((unsigned char)str[p]) )
603550dc98Sfvdl str[p] -= 32;
613550dc98Sfvdl }
623550dc98Sfvdl }
633550dc98Sfvdl
64ae6ae2c3Sperry static inline int
cd9660_is_d_char(char c)653550dc98Sfvdl cd9660_is_d_char(char c)
663550dc98Sfvdl {
673550dc98Sfvdl return (isupper((unsigned char)c)
683550dc98Sfvdl || c == '_'
698bd84b04Schristos || (c >= '0' && c <= '9'));
708bd84b04Schristos }
718bd84b04Schristos
728bd84b04Schristos static inline int
cd9660_is_a_char(char c)738bd84b04Schristos cd9660_is_a_char(char c)
748bd84b04Schristos {
758bd84b04Schristos return (isupper((unsigned char)c)
768bd84b04Schristos || c == '_'
778bd84b04Schristos || (c >= '%' && c <= '?')
783550dc98Sfvdl || (c >= ' ' && c <= '\"'));
793550dc98Sfvdl }
803550dc98Sfvdl
813550dc98Sfvdl /*
823550dc98Sfvdl * Test a string to see if it is composed of valid a characters
833550dc98Sfvdl * @param const char* The string to test
843550dc98Sfvdl * @returns int 1 if valid, 2 if valid if characters are converted to
853550dc98Sfvdl * upper case, 0 otherwise
863550dc98Sfvdl */
873550dc98Sfvdl int
cd9660_valid_a_chars(const char * str)883550dc98Sfvdl cd9660_valid_a_chars(const char *str)
893550dc98Sfvdl {
903550dc98Sfvdl const char *c = str;
913550dc98Sfvdl int upperFound = 0;
923550dc98Sfvdl
933550dc98Sfvdl while ((*c) != '\0') {
943550dc98Sfvdl if (!(cd9660_is_a_char(*c))) {
953550dc98Sfvdl if (islower((unsigned char)*c) )
963550dc98Sfvdl upperFound = 1;
973550dc98Sfvdl else
983550dc98Sfvdl return 0;
993550dc98Sfvdl }
1003550dc98Sfvdl c++;
1013550dc98Sfvdl }
1023550dc98Sfvdl return upperFound + 1;
1033550dc98Sfvdl }
1043550dc98Sfvdl
1053550dc98Sfvdl /*
1063550dc98Sfvdl * Test a string to see if it is composed of valid d characters
1073550dc98Sfvdl * @param const char* The string to test
1083550dc98Sfvdl * @returns int 1 if valid, 2 if valid if characters are converted to
1093550dc98Sfvdl * upper case, 0 otherwise
1103550dc98Sfvdl */
1113550dc98Sfvdl int
cd9660_valid_d_chars(const char * str)1123550dc98Sfvdl cd9660_valid_d_chars(const char *str)
1133550dc98Sfvdl {
1143550dc98Sfvdl const char *c=str;
1153550dc98Sfvdl int upperFound = 0;
1163550dc98Sfvdl
1173550dc98Sfvdl while ((*c) != '\0') {
1183550dc98Sfvdl if (!(cd9660_is_d_char(*c))) {
1193550dc98Sfvdl if (islower((unsigned char)*c) )
1203550dc98Sfvdl upperFound = 1;
1213550dc98Sfvdl else
1223550dc98Sfvdl return 0;
1233550dc98Sfvdl }
1243550dc98Sfvdl c++;
1253550dc98Sfvdl }
1263550dc98Sfvdl return upperFound + 1;
1273550dc98Sfvdl }
128