Subversion Repositories SvarDOS

Rev

Rev 240 | Rev 251 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 240 Rev 248
Line 11... Line 11...
11
#include <string.h>   /* */
11
#include <string.h>   /* */
12
#include <stdio.h>    /* sprintf() */
12
#include <stdio.h>    /* sprintf() */
13
#include <stdlib.h>   /* atoi() */
13
#include <stdlib.h>   /* atoi() */
14
#include <sys/stat.h> /* mkdir() */
14
#include <sys/stat.h> /* mkdir() */
15
 
15
 
-
 
16
#include "rtrim.h"
16
#include "helpers.h"
17
#include "helpers.h"
17
 
18
 
18
 
19
 
19
/* translates a version string into a array of integer values. The array must be 8-position long.
20
/* translates a version string into a array of integer values. The array must be 8-position long.
20
   returns 0 if parsing was successful, non-zero otherwise.
21
   returns 0 if parsing was successful, non-zero otherwise.
Line 244... Line 245...
244
  }
245
  }
245
  /* if no dot found, then point to the string's null terminator */
246
  /* if no dot found, then point to the string's null terminator */
246
  if (res == NULL) return(fname);
247
  if (res == NULL) return(fname);
247
  return(res);
248
  return(res);
248
}
249
}
-
 
250
 
-
 
251
 
-
 
252
/* reads a line from a "token = value" file, returns 0 on success
-
 
253
 * val (if not NULL) is updated with a pointer to the "value" part
-
 
254
 * delim is the delimiter char (typically ':' or '=' but can be anything) */
-
 
255
int freadtokval(FILE *fd, char *line, size_t maxlen, char **val, char delim) {
-
 
256
  int bytebuff, linelen = 0;
-
 
257
  if (val != NULL) *val = NULL;
-
 
258
  for (;;) {
-
 
259
    bytebuff = fgetc(fd);
-
 
260
    if (bytebuff == EOF) {
-
 
261
      if (linelen == 0) return(-1);
-
 
262
      break;
-
 
263
    }
-
 
264
    if (bytebuff < 0) return(-1);
-
 
265
    if ((*val == NULL) && (bytebuff == delim)) {
-
 
266
      line[linelen++] = 0;
-
 
267
      *val = line + linelen;
-
 
268
      continue;
-
 
269
    }
-
 
270
    if (bytebuff == '\r') continue; /* ignore CR */
-
 
271
    if (bytebuff == '\n') break;
-
 
272
    if (linelen < maxlen - 1) line[linelen++] = bytebuff;
-
 
273
  }
-
 
274
  /* terminate line and trim token and value (if any) */
-
 
275
  line[linelen] = 0;
-
 
276
  trim(line);
-
 
277
  if ((val != NULL) && (*val != NULL)) trim(*val);
-
 
278
  return(0);
-
 
279
}