Subversion Repositories SvarDOS

Rev

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

Rev 219 Rev 245
Line 30... Line 30...
30
  }
30
  }
31
}
31
}
32
 
32
 
33
 
33
 
34
/* Loads metadata from an LSM file. Returns 0 on success, non-zero on error. */
34
/* Loads metadata from an LSM file. Returns 0 on success, non-zero on error. */
35
int readlsm(char *filename, char *version, int version_maxlen) {
35
int readlsm(const char *filename, char *version, int version_maxlen) {
36
  char linebuff[128];
36
  char linebuff[128];
37
  char *valuestr;
37
  char *valuestr;
38
  int x;
38
  int x;
39
  FILE *fd;
39
  FILE *fd;
40
  /* reset fields to be read to empty values */
40
  /* reset fields to be read to empty values */
41
  version[0] = 0;
41
  version[0] = 0;
42
  /* open the file */
42
  /* open the file */
43
  fd = fopen(filename, "rb");
43
  fd = fopen(filename, "rb");
44
  if (fd == NULL) return(-1);
44
  if (fd == NULL) return(-1);
45
  /* check the file's header */
-
 
46
  if (readline_fromfile(fd, linebuff, 64) < 0) {
-
 
47
    fclose(fd);
-
 
48
    return(-1);
-
 
49
  }
-
 
50
  if (strcasecmp(linebuff, "begin3") != 0) {
-
 
51
    fclose(fd);
-
 
52
    return(-1);
-
 
53
  }
-
 
54
  /* read the LSM file line by line */
45
  /* read the LSM file line by line */
55
  while (readline_fromfile(fd, linebuff, 127) >= 0) {
46
  while (readline_fromfile(fd, linebuff, sizeof(linebuff) - 1) >= 0) {
56
    for (x = 0;; x++) {
47
    for (x = 0;; x++) {
57
      if (linebuff[x] == 0) {
48
      if (linebuff[x] == 0) {
58
        x = -1;
49
        x = -1;
59
        break;
50
        break;
60
      } else if (linebuff[x] == ':') {
51
      } else if (linebuff[x] == ':') {
Line 64... Line 55...
64
    if (x > 0) {
55
    if (x > 0) {
65
      linebuff[x] = 0;
56
      linebuff[x] = 0;
66
      valuestr = linebuff + x + 1;
57
      valuestr = linebuff + x + 1;
67
      trim(linebuff);
58
      trim(linebuff);
68
      trim(valuestr);
59
      trim(valuestr);
69
      if (strcasecmp(linebuff, "version") == 0) {
-
 
70
        snprintf(version, version_maxlen, "%s", valuestr);
60
      if (strcasecmp(linebuff, "version") == 0) snprintf(version, version_maxlen, "%s", valuestr);
71
        version[version_maxlen] = 0; /* snprintf is supposed to terminate string itself, but the DJGPP doesn't */
-
 
72
      }
-
 
73
    }
61
    }
74
  }
62
  }
75
  fclose(fd);
63
  fclose(fd);
76
  return(0);
64
  return(0);
77
}
65
}