1 /* 2 3 -Procedure repmot_c ( Replace marker with ordinal text ) 4 5 -Abstract 6 7 Replace a marker with the text representation of an ordinal number. 8 9 -Disclaimer 10 11 THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE 12 CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. 13 GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE 14 ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE 15 PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" 16 TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY 17 WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A 18 PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC 19 SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE 20 SOFTWARE AND RELATED MATERIALS, HOWEVER USED. 21 22 IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA 23 BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT 24 LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, 25 INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, 26 REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE 27 REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. 28 29 RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF 30 THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY 31 CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE 32 ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. 33 34 -Required_Reading 35 36 None. 37 38 -Keywords 39 40 CHARACTER 41 CONVERSION 42 STRING 43 44 */ 45 46 #include "SpiceUsr.h" 47 #include "SpiceZfc.h" 48 #include "SpiceZst.h" 49 #include "SpiceZmc.h" 50 51 repmot_c(ConstSpiceChar * in,ConstSpiceChar * marker,SpiceInt value,SpiceChar repcase,SpiceInt lenout,SpiceChar * out)52 void repmot_c ( ConstSpiceChar * in, 53 ConstSpiceChar * marker, 54 SpiceInt value, 55 SpiceChar repcase, 56 SpiceInt lenout, 57 SpiceChar * out ) 58 59 /* 60 61 -Brief_I/O 62 63 VARIABLE I/O DESCRIPTION 64 -------- --- -------------------------------------------------- 65 in I Input string. 66 marker I Marker to be replaced. 67 value I Replacement value. 68 repcase I Case of replacement text. 69 lenout I Available space in output string. 70 out O Output string. 71 MAXLON P Maximum length of an ordinal number. 72 73 -Detailed_Input 74 75 in is an arbitrary character string. 76 77 marker is an arbitrary character string. The first 78 occurrence of marker in the input string is 79 to be replaced by the text representation of 80 the ordinal number value. 81 82 Leading and trailing blanks in marker are not 83 significant. In particular, no substitution is 84 performed if marker is blank or empty. 85 86 value is an arbitrary integer. 87 88 repcase indicates the case of the replacement text. 89 repcase may be any of the following: 90 91 repcase Meaning Example 92 ------- ----------- ----------------------- 93 U, u Uppercase ONE HUNDRED FIFTY-THREE 94 95 L, l Lowercase one hundred fifty-three 96 97 C, c Capitalized One hundred fifty-three 98 99 lenout is the allowed length of the output string. This 100 length must large enough to hold the output string 101 plus the terminator. If the output string is 102 expected to have x characters, lenout should be at 103 least x + 1. 104 -Detailed_Output 105 106 out is the string obtained by substituting the text 107 representation of the ordinal number value for 108 the first occurrence of marker in the input string. 109 110 out and in must be identical or disjoint. 111 112 -Parameters 113 114 MAXLON is the maximum expected length of any ordinal 115 text. 147 characters are sufficient to hold the 116 text representing any ordinal value whose 117 corresponding ordinal value is in the range 118 119 ( -10**12, 10**12 ) 120 121 An example of a number whose ordinal text 122 representation is of maximum length is 123 124 - 777 777 777 777 125 -Files 126 127 None. 128 129 -Exceptions 130 131 1) The error SPICE(NULLPOINTER) is signaled if any of 132 the input or output string pointers is null. 133 134 2) If the marker string is blank or empty, this routine leaves 135 the input string unchanged, except that trailing blanks 136 will be trimmed. This case is not considered an error. 137 138 3) If the output string is too short to accommodate a terminating 139 null character, the error SPICE(STRINGTOOSHORT) is signaled. 140 141 4) If out does not have sufficient length to accommodate the 142 result of the substitution, the result will be truncated on 143 the right. 144 145 5) If the value of repcase is not recognized, the error 146 will be diagnosed by routines in the call tree of this 147 routine. out is not changed. 148 149 -Particulars 150 151 This is one of a family of related routines for inserting values 152 into strings. They are typically to construct messages that 153 are partly fixed, and partly determined at run time. For example, 154 a message like 155 156 "The fifty-first picture was found in directory [USER.DATA]." 157 158 might be constructed from the variable string 159 160 "The #1 picture was found in directory #2." 161 162 by the calls 163 164 repmot_c ( string, "#1", 51, 'L', LENOUT, string ); 165 repmc_c ( string, "#2", "[USER.DATA]", LENOUT, string ); 166 167 which substitute the ordinal text "fifty-first" and the character 168 string "[USER.DATA]" for the markers "#1" and "#2" respectively. 169 170 The complete list of routines is shown below. 171 172 repmc_c ( Replace marker with character string value ) 173 repmd_c ( Replace marker with double precision value ) 174 repmf_c ( Replace marker with formatted d.p. value ) 175 repmi_c ( Replace marker with integer value ) 176 repmct_c ( Replace marker with cardinal text ) 177 repmot_c ( Replace marker with ordinal text ) 178 179 -Examples 180 181 The following examples illustrate the use of repmot_c to 182 replace a marker within a string with the ordinal text 183 corresponding to an integer. 184 185 Uppercase 186 --------- 187 188 Let 189 190 marker = "#" 191 in = "Invalid command. The # word was not recognized." 192 193 Then following the call, 194 . 195 . 196 . 197 #define LENOUT 201 198 . 199 . 200 . 201 repmot_c ( in, "#", 5, 'U', LENOUT, in ); 202 203 in is 204 205 "Invalid command. The FIFTH word was not recognized." 206 207 Lowercase 208 --------- 209 210 Let 211 212 marker = " XX " 213 in = "The XX word of the XX sentence was misspelled." 214 215 Then following the call, 216 217 repmot_c ( in, " XX ", 5, 'L', LENOUT, out ); 218 219 OUT is 220 221 "The fifth word of the XX sentence was misspelled." 222 223 224 Capitalized 225 ----------- 226 227 Let 228 229 marker == " XX " 230 in == "Name: YY. Rank: XX." 231 232 Then following the calls, 233 234 #include "SpiceUsr.h" 235 . 236 . 237 . 238 #define LENOUT 201 239 . 240 . 241 . 242 repmc_c ( in, "YY", "Moriarty", LENOUT, out ); 243 repmct_c ( out, "XX", 1, 'C', LENOUT, out ); 244 245 out is 246 247 "Name: Moriarty. Rank: First." 248 249 -Restrictions 250 251 1) value must be in the range accepted by subroutine intord_. 252 This range is currently 253 254 ( -10**12, 10**12 ) 255 256 Note that the endpoints of the interval are excluded. 257 258 -Literature_References 259 260 None. 261 262 -Author_and_Institution 263 264 N.J. Bachman (JPL) 265 I.M. Underwood (JPL) 266 267 -Version 268 269 -CSPICE Version 1.0.0, 14-AUG-2002 (NJB) (IMU) 270 271 -Index_Entries 272 273 replace marker with ordinal text 274 275 -& 276 */ 277 278 { /* Begin repmot_c */ 279 280 /* 281 Local variables 282 */ 283 ConstSpiceChar * markPtr; 284 285 286 /* 287 Use discovery check-in. 288 289 Make sure no string argument pointers are null. 290 */ 291 CHKPTR( CHK_DISCOVER, "repmot_c", in ); 292 CHKPTR( CHK_DISCOVER, "repmot_c", marker ); 293 CHKPTR( CHK_DISCOVER, "repmot_c", out ); 294 295 296 /* 297 If the output string can't hold a terminating null character, 298 we can't proceed. 299 */ 300 if ( lenout < 1 ) 301 { 302 chkin_c ( "repmot_c" ); 303 setmsg_c ( "String length lenout must be >= 1; actual " 304 "value = #." ); 305 errint_c ( "#", lenout ); 306 sigerr_c ( "SPICE(STRINGTOOSHORT)" ); 307 chkout_c ( "repmot_c" ); 308 return; 309 } 310 311 312 /* 313 If the output string has no room for data characters, we simply 314 terminate the string. 315 */ 316 if ( lenout == 1 ) 317 { 318 out[0] = NULLCHAR; 319 return; 320 } 321 322 323 /* 324 If the input string has zero length, the output is empty as well. 325 */ 326 if ( in[0] == NULLCHAR ) 327 { 328 out[0] = NULLCHAR; 329 330 return; 331 } 332 333 334 /* 335 If the marker is empty, pass a blank marker to the f2c'd routine. 336 Otherwise, pass in the marker. 337 */ 338 if ( marker[0] == NULLCHAR ) 339 { 340 markPtr = " "; 341 } 342 else 343 { 344 markPtr = marker; 345 } 346 347 /* 348 Simply call the f2c'd routine. 349 */ 350 repmot_ ( ( char * ) in, 351 ( char * ) markPtr, 352 ( integer * ) &value, 353 ( char * ) &repcase, 354 ( char * ) out, 355 ( ftnlen ) strlen(in), 356 ( ftnlen ) strlen(markPtr), 357 ( ftnlen ) 1, 358 ( ftnlen ) lenout-1 ); 359 360 /* 361 Convert the output string from Fortran to C style. 362 */ 363 F2C_ConvertStr ( lenout, out ); 364 365 366 } /* End repmot_c */ 367