Deleted Added
full compact
myndbm.c (32785) myndbm.c (34461)
1/*
2 * Copyright (c) 1992, Brian Berliner
3 *
4 * You may distribute under the terms of the GNU General Public License as
5 * specified in the README file that comes with the CVS source distribution.
6 *
7 * A simple ndbm-emulator for CVS. It parses a text file of the format:
8 *

--- 186 unchanged lines hidden (view full) ---

195}
196
197static void
198mydbm_load_file (fp, list)
199 FILE *fp;
200 List *list;
201{
202 char *line = NULL;
1/*
2 * Copyright (c) 1992, Brian Berliner
3 *
4 * You may distribute under the terms of the GNU General Public License as
5 * specified in the README file that comes with the CVS source distribution.
6 *
7 * A simple ndbm-emulator for CVS. It parses a text file of the format:
8 *

--- 186 unchanged lines hidden (view full) ---

195}
196
197static void
198mydbm_load_file (fp, list)
199 FILE *fp;
200 List *list;
201{
202 char *line = NULL;
203 size_t line_len;
203 size_t line_size;
204 char *value;
205 size_t value_allocated;
206 char *cp, *vp;
204 char *value;
205 size_t value_allocated;
206 char *cp, *vp;
207 int len, cont;
207 int cont;
208 int line_length;
209
210 value_allocated = 1;
211 value = xmalloc (value_allocated);
212
208 int line_length;
209
210 value_allocated = 1;
211 value = xmalloc (value_allocated);
212
213 for (cont = 0; (line_length = getline (&line, &line_len, fp)) >= 0;)
213 cont = 0;
214 while ((line_length = getstr (&line, &line_size, fp, '\012', 0)) >= 0)
214 {
215 {
215 if ((cp = strrchr (line, '\012')) != NULL)
216 *cp = '\0'; /* strip the newline */
217 cp = line + strlen (line);
218 if (cp > line && cp[-1] == '\015')
216 if (line_length > 0 && line[line_length - 1] == '\012')
217 {
218 /* Strip the newline. */
219 --line_length;
220 line[line_length] = '\0';
221 }
222 if (line_length > 0 && line[line_length - 1] == '\015')
223 {
219 /* If the file (e.g. modules) was written on an NT box, it will
220 contain CRLF at the ends of lines. Strip them (we can't do
221 this by opening the file in text mode because we might be
222 running on unix). */
224 /* If the file (e.g. modules) was written on an NT box, it will
225 contain CRLF at the ends of lines. Strip them (we can't do
226 this by opening the file in text mode because we might be
227 running on unix). */
223 cp[-1] = '\0';
228 --line_length;
229 line[line_length] = '\0';
230 }
224
225 /*
226 * Add the line to the value, at the end if this is a continuation
227 * line; otherwise at the beginning, but only after any trailing
228 * backslash is removed.
229 */
230 if (!cont)
231 value[0] = '\0';
232
233 /*
234 * See if the line we read is a continuation line, and strip the
235 * backslash if so.
236 */
231
232 /*
233 * Add the line to the value, at the end if this is a continuation
234 * line; otherwise at the beginning, but only after any trailing
235 * backslash is removed.
236 */
237 if (!cont)
238 value[0] = '\0';
239
240 /*
241 * See if the line we read is a continuation line, and strip the
242 * backslash if so.
243 */
237 len = strlen (line);
238 if (len > 0)
239 cp = &line[len - 1];
244 if (line_length > 0)
245 cp = &line[line_length - 1];
240 else
241 cp = line;
242 if (*cp == '\\')
243 {
244 cont = 1;
245 *cp = '\0';
246 else
247 cp = line;
248 if (*cp == '\\')
249 {
250 cont = 1;
251 *cp = '\0';
252 --line_length;
246 }
247 else
248 {
249 cont = 0;
250 }
251 expand_string (&value,
252 &value_allocated,
253 }
254 else
255 {
256 cont = 0;
257 }
258 expand_string (&value,
259 &value_allocated,
253 strlen (value) + strlen (line) + 5);
260 strlen (value) + line_length + 5);
254 strcat (value, line);
255
256 if (value[0] == '#')
257 continue; /* comment line */
258 vp = value;
259 while (*vp && isspace (*vp))
260 vp++;
261 if (*vp == '\0')

--- 41 unchanged lines hidden ---
261 strcat (value, line);
262
263 if (value[0] == '#')
264 continue; /* comment line */
265 vp = value;
266 while (*vp && isspace (*vp))
267 vp++;
268 if (*vp == '\0')

--- 41 unchanged lines hidden ---