1 /* replch.f -- translated by f2c (version 19980913).
2    You must link the resulting object file with the libraries:
3 	-lf2c -lm   (in that order)
4 */
5 
6 #include "f2c.h"
7 
8 /* $Procedure      REPLCH ( Replace characters in a string ) */
replch_(char * instr,char * old,char * new__,char * outstr,ftnlen instr_len,ftnlen old_len,ftnlen new_len,ftnlen outstr_len)9 /* Subroutine */ int replch_(char *instr, char *old, char *new__, char *
10 	outstr, ftnlen instr_len, ftnlen old_len, ftnlen new_len, ftnlen
11 	outstr_len)
12 {
13     /* System generated locals */
14     integer i__1;
15 
16     /* Builtin functions */
17     /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen);
18     integer i_len(char *, ftnlen);
19 
20     /* Local variables */
21     integer i__;
22 
23 /* $ Abstract */
24 
25 /*      Replace all occurrences of a single character with a second */
26 /*      character. */
27 
28 /* $ Disclaimer */
29 
30 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
31 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
32 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
33 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
34 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
35 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
36 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
37 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
38 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
39 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
40 
41 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
42 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
43 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
44 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
45 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
46 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
47 
48 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
49 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
50 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
51 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
52 
53 /* $ Required_Reading */
54 
55 /*     None. */
56 
57 /* $ Keywords */
58 
59 /*      ASCII,  CHARACTER */
60 
61 /* $ Declarations */
62 /* $ Brief_I/O */
63 
64 /*      VARIABLE  I/O  DESCRIPTION */
65 /*      --------  ---  -------------------------------------------------- */
66 /*      INSTR      I   Input string. */
67 /*      OLD        I   Character to be replaced. */
68 /*      NEW        I   Replacement character. */
69 /*      OUTSTR     O   Output string. */
70 
71 /* $ Detailed_Input */
72 
73 /*      INSTR       is the input character string, possibly containing */
74 /*                  one or more occurrences of the character OLD. */
75 
76 /*      OLD         is the character to be replaced wherever it occurs in */
77 /*                  the input string. */
78 
79 /*      NEW         is the character which is to replace each occurrence */
80 /*                  of the character OLD in the output string. */
81 
82 /* $ Detailed_Output */
83 
84 /*      OUTSTR      is the output string. This is the input string */
85 /*                  with every occurrence of the character OLD replaced */
86 /*                  by the character NEW. */
87 
88 /*                  OUTSTR may overwrite INSTR. */
89 
90 /* $ Parameters */
91 
92 /*     None. */
93 
94 /* $ Particulars */
95 
96 /*      Copy the contents of the input string to the output string */
97 /*      a character at a time, replacing each occurrence of OLD with NEW. */
98 /*      If the output string is not long enough to contain the input */
99 /*      string, it is truncated on the right. */
100 
101 /* $ Exceptions */
102 
103 /*      Error free. */
104 
105 /* $ Files */
106 
107 /*      None. */
108 
109 /* $ Examples */
110 
111 /*      Let */
112 /*            INSTR  = 'Woodsy is the Anti-Pollution Owl.' */
113 /*            OLD    = 'O' */
114 /*            NEW    = 'E' */
115 /*      then */
116 /*            OUTSTR = 'Woodsy is the Anti-Pollution Ewl.' */
117 
118 /*      Note the case-sensitivity of REPLCH. The lowercase o's are */
119 /*      not affected. */
120 
121 /*      REPLCH may similarly be used to replace control characters */
122 /*      (such as tab stops, line feeds, and nulls) with regular ASCII */
123 /*      characters (such as blanks). */
124 
125 /* $ Restrictions */
126 
127 /*      REPLCH is sensitive to case, as shown in the examples above. */
128 
129 /* $ Author_and_Institution */
130 
131 /*      W.L. Taber      (JPL) */
132 /*      I.M. Underwood  (JPL) */
133 
134 /* $ Literature_References */
135 
136 /*      None. */
137 
138 /* $ Version */
139 
140 /* -     SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
141 
142 /*         Comment section for permuted index source lines was added */
143 /*         following the header. */
144 
145 /* -     SPICELIB Version 1.0.0, 31-JAN-1990 (WLT) (IMU) */
146 
147 /* -& */
148 /* $ Index_Entries */
149 
150 /*     replace characters in a string */
151 
152 /* -& */
153 
154 /*   Local Variables */
155 
156 
157 /*     Move the input string to the output string. If it's too long, */
158 /*     this will truncate it. */
159 
160     s_copy(outstr, instr, outstr_len, instr_len);
161 
162 /*     Check each character of OUTSTR and replace as necessary. */
163 
164     i__1 = i_len(outstr, outstr_len);
165     for (i__ = 1; i__ <= i__1; ++i__) {
166 	if (*(unsigned char *)&outstr[i__ - 1] == *(unsigned char *)old) {
167 	    *(unsigned char *)&outstr[i__ - 1] = *(unsigned char *)new__;
168 	}
169     }
170     return 0;
171 } /* replch_ */
172 
173