1 /* 2 3 -Procedure iswhsp_c ( Determine whether a string is white space ) 4 5 -Abstract 6 7 Return a boolean value indicating whether a string contains 8 only white space characters. 9 10 -Disclaimer 11 12 THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE 13 CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. 14 GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE 15 ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE 16 PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" 17 TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY 18 WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A 19 PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC 20 SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE 21 SOFTWARE AND RELATED MATERIALS, HOWEVER USED. 22 23 IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA 24 BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT 25 LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, 26 INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, 27 REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE 28 REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. 29 30 RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF 31 THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY 32 CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE 33 ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. 34 35 -Required_Reading 36 37 None. 38 39 -Keywords 40 41 FILES, TEXT 42 43 */ 44 45 #include <ctype.h> 46 #include "SpiceUsr.h" 47 #include "SpiceZmc.h" 48 49 iswhsp_c(ConstSpiceChar * string)50 SpiceBoolean iswhsp_c ( ConstSpiceChar * string ) 51 52 /* 53 54 -Brief_I/O 55 56 Variable I/O Description 57 -------- --- -------------------------------------------------- 58 string I String to be tested. 59 60 The function returns the boolean value SPICETRUE if the string is 61 empty or contains only white space characters; otherwise it returns 62 the value SPICEFALSE. 63 64 -Detailed_Input 65 66 string is a character pointer designating a string to be 67 searched for non-white-space characters. 68 69 -Detailed_Output 70 71 The function returns the boolean value SPICETRUE if the string 72 contains only white space characters; otherwise it returns the 73 value SPICEFALSE. 74 75 White space characters are those in the set 76 77 { ' ', '\f', '\n', '\r', '\t', '\v' } 78 79 80 -Parameters 81 82 None. 83 84 -Exceptions 85 86 1) If the input string pointer is null, the error SPICE(NULLPOINTER) 87 is signaled. 88 89 2) An empty string, that is a string with a null character 90 at index 0, is considered to be blank. 91 92 -Files 93 94 None. 95 96 -Particulars 97 98 This routine provides a short cut for testing lines for the presence 99 of non-blank characters; this is a test which is performed frequently 100 in CSPICE. 101 102 -Examples 103 104 1) Read a text file; print the non-blank lines. 105 106 #include <stdio.h> 107 #include "SpiceUsr.h" 108 109 void main() 110 { 111 #define MAXLEN 82 112 113 FILE *fptr; 114 SpiceBoolean eof; 115 SpiceChar line [MAXLEN]; 116 117 118 txtopr_c ( "myfile", &fptr ); 119 120 readln_c ( fptr, MAXLEN, line, &eof ); 121 122 while ( !eof ) 123 { 124 if ( !iswhsp_c(line) ) 125 { 126 printf ( "%s\n", line ); 127 } 128 129 readln_c ( fptr, MAXLEN, line, &eof ); 130 } 131 } 132 133 -Restrictions 134 135 None. 136 137 -Literature_References 138 139 1) "American National Standard for Programming Languages -- C," 140 Published by the American National Standards Institute, 1990. 141 Section 7.3.1.9., p. 104. 142 143 -Author_and_Institution 144 145 N.J. Bachman (JPL) 146 147 -Version 148 149 -CSPICE Version 1.1.0, 27-AUG-1999 (NJB) 150 151 Now checks for null input string. 152 153 -CSPICE Version 1.0.0, 24-FEB-1999 (NJB) 154 155 Arguments passed to isspace are now cast to unsigned char to 156 suppress compilation warnings on some systems. 157 158 -CSPICE Version 1.0.0, 08-FEB-1998 (NJB) 159 160 -Index_Entries 161 162 read a non-blank line from a text file 163 164 -& 165 */ 166 167 { /* Begin iswhsp_c */ 168 169 170 /* 171 Local variables 172 */ 173 SpiceBoolean blank; 174 ConstSpiceChar * sptr; 175 176 177 /* 178 Check the input string pointer to make sure it's non-null. 179 */ 180 CHKPTR_VAL ( CHK_DISCOVER, "iswhsp_c", string, SPICEFALSE ); 181 182 183 /* 184 Start out assuming the string is blank. If the string is empty, 185 we've got the right return value already. 186 */ 187 188 blank = SPICETRUE; 189 sptr = string; 190 191 while ( blank && ( (SpiceBoolean) *sptr ) ) 192 { 193 if ( !isspace( (unsigned char) *sptr ) ) 194 { 195 blank = SPICEFALSE; 196 } 197 198 sptr++; 199 } 200 201 202 return ( blank ); 203 204 205 } /* End iswhsp_c */ 206