1*9a86cdb6Snatano /* $OpenBSD: cd9660_strings.c,v 1.3 2016/10/16 20:26:56 natano Exp $ */
26163fc9cSnatano /* $NetBSD: cd9660_strings.c,v 1.6 2015/12/24 15:52:37 christos Exp $ */
36163fc9cSnatano
46163fc9cSnatano /*
56163fc9cSnatano * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
66163fc9cSnatano * Perez-Rathke and Ram Vedam. All rights reserved.
76163fc9cSnatano *
86163fc9cSnatano * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
96163fc9cSnatano * Alan Perez-Rathke and Ram Vedam.
106163fc9cSnatano *
116163fc9cSnatano * Redistribution and use in source and binary forms, with or
126163fc9cSnatano * without modification, are permitted provided that the following
136163fc9cSnatano * conditions are met:
146163fc9cSnatano * 1. Redistributions of source code must retain the above copyright
156163fc9cSnatano * notice, this list of conditions and the following disclaimer.
166163fc9cSnatano * 2. Redistributions in binary form must reproduce the above
176163fc9cSnatano * copyright notice, this list of conditions and the following
186163fc9cSnatano * disclaimer in the documentation and/or other materials provided
196163fc9cSnatano * with the distribution.
206163fc9cSnatano *
216163fc9cSnatano * THIS SOFTWARE IS PROVIDED BY DANIEL WATT, WALTER DEIGNAN, RYAN
226163fc9cSnatano * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
236163fc9cSnatano * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
246163fc9cSnatano * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
256163fc9cSnatano * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
266163fc9cSnatano * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
276163fc9cSnatano * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
286163fc9cSnatano * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
296163fc9cSnatano * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
306163fc9cSnatano * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
316163fc9cSnatano * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
326163fc9cSnatano * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
336163fc9cSnatano * OF SUCH DAMAGE.
346163fc9cSnatano */
356163fc9cSnatano
366163fc9cSnatano #include <ctype.h>
376163fc9cSnatano
386163fc9cSnatano #include "makefs.h"
396163fc9cSnatano
406163fc9cSnatano
416163fc9cSnatano void
cd9660_uppercase_characters(char * str,size_t len)426163fc9cSnatano cd9660_uppercase_characters(char *str, size_t len)
436163fc9cSnatano {
446163fc9cSnatano size_t p;
456163fc9cSnatano
466163fc9cSnatano for (p = 0; p < len; p++) {
476163fc9cSnatano if (islower((unsigned char)str[p]) )
486163fc9cSnatano str[p] -= 32;
496163fc9cSnatano }
506163fc9cSnatano }
516163fc9cSnatano
526163fc9cSnatano static inline int
cd9660_is_d_char(char c)536163fc9cSnatano cd9660_is_d_char(char c)
546163fc9cSnatano {
556163fc9cSnatano return (isupper((unsigned char)c)
566163fc9cSnatano || c == '_'
576163fc9cSnatano || (c >= '0' && c <= '9'));
586163fc9cSnatano }
596163fc9cSnatano
606163fc9cSnatano static inline int
cd9660_is_a_char(char c)616163fc9cSnatano cd9660_is_a_char(char c)
626163fc9cSnatano {
636163fc9cSnatano return (isupper((unsigned char)c)
646163fc9cSnatano || c == '_'
656163fc9cSnatano || (c >= '%' && c <= '?')
666163fc9cSnatano || (c >= ' ' && c <= '\"'));
676163fc9cSnatano }
686163fc9cSnatano
696163fc9cSnatano /*
706163fc9cSnatano * Test a string to see if it is composed of valid a characters
716163fc9cSnatano * @param const char* The string to test
726163fc9cSnatano * @returns int 1 if valid, 2 if valid if characters are converted to
736163fc9cSnatano * upper case, 0 otherwise
746163fc9cSnatano */
756163fc9cSnatano int
cd9660_valid_a_chars(const char * str)766163fc9cSnatano cd9660_valid_a_chars(const char *str)
776163fc9cSnatano {
786163fc9cSnatano const char *c = str;
796163fc9cSnatano int upperFound = 0;
806163fc9cSnatano
816163fc9cSnatano while ((*c) != '\0') {
826163fc9cSnatano if (!(cd9660_is_a_char(*c))) {
836163fc9cSnatano if (islower((unsigned char)*c) )
846163fc9cSnatano upperFound = 1;
856163fc9cSnatano else
866163fc9cSnatano return 0;
876163fc9cSnatano }
886163fc9cSnatano c++;
896163fc9cSnatano }
906163fc9cSnatano return upperFound + 1;
916163fc9cSnatano }
926163fc9cSnatano
936163fc9cSnatano /*
946163fc9cSnatano * Test a string to see if it is composed of valid d characters
956163fc9cSnatano * @param const char* The string to test
966163fc9cSnatano * @returns int 1 if valid, 2 if valid if characters are converted to
976163fc9cSnatano * upper case, 0 otherwise
986163fc9cSnatano */
996163fc9cSnatano int
cd9660_valid_d_chars(const char * str)1006163fc9cSnatano cd9660_valid_d_chars(const char *str)
1016163fc9cSnatano {
1026163fc9cSnatano const char *c=str;
1036163fc9cSnatano int upperFound = 0;
1046163fc9cSnatano
1056163fc9cSnatano while ((*c) != '\0') {
1066163fc9cSnatano if (!(cd9660_is_d_char(*c))) {
1076163fc9cSnatano if (islower((unsigned char)*c) )
1086163fc9cSnatano upperFound = 1;
1096163fc9cSnatano else
1106163fc9cSnatano return 0;
1116163fc9cSnatano }
1126163fc9cSnatano c++;
1136163fc9cSnatano }
1146163fc9cSnatano return upperFound + 1;
1156163fc9cSnatano }
116