Subversion Repositories SvarDOS

Rev

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

Rev 614 Rev 1678
Line 1... Line 1...
1
/*
1
/*
2
 * This file is part of PKG (SvarDOS)
2
 * This file is part of PKG (SvarDOS)
3
 * Copyright (C) 2013-2022 Mateusz Viste
3
 * Copyright (C) 2013-2024 Mateusz Viste
4
 */
4
 */
5
 
5
 
6
#include <stdio.h>
6
#include <stdio.h>
7
#include <ctype.h>    /* tolower() */
7
#include <ctype.h>    /* tolower() */
8
#include <stdlib.h>   /* atoi(), qsort() - not using it after all, redefining it manually later */
8
#include <stdlib.h>   /* atoi(), qsort() - not using it after all, redefining it manually later */
Line 24... Line 24...
24
  struct dirent *ep;
24
  struct dirent *ep;
25
  char buff[256];
25
  char buff[256];
26
  char ver[16];
26
  char ver[16];
27
  int matchfound = 0;
27
  int matchfound = 0;
28
 
28
 
29
  sprintf(buff, "%s\\packages", dosdir);
29
  sprintf(buff, "%s\\appinfo", dosdir);
30
  dp = opendir(buff);
30
  dp = opendir(buff);
31
  if (dp == NULL) {
31
  if (dp == NULL) {
32
    kitten_printf(9, 0, buff); /* "ERROR: Could not access directory %s" */
32
    kitten_printf(9, 0, buff); /* "ERROR: Could not access directory %s" */
33
    puts("");
33
    puts("");
34
    return(-1);
34
    return(-1);
Line 36... Line 36...
36
 
36
 
37
  while ((ep = readdir(dp)) != NULL) { /* readdir() result must never be freed (statically allocated) */
37
  while ((ep = readdir(dp)) != NULL) { /* readdir() result must never be freed (statically allocated) */
38
    int tlen = strlen(ep->d_name);
38
    int tlen = strlen(ep->d_name);
39
    if (ep->d_name[0] == '.') continue; /* ignore '.', '..', and hidden directories */
39
    if (ep->d_name[0] == '.') continue; /* ignore '.', '..', and hidden directories */
40
    if (tlen < 4) continue; /* files must be at least 5 bytes long ("x.lst") */
40
    if (tlen < 4) continue; /* files must be at least 5 bytes long ("x.lst") */
41
    if (strcasecmp(ep->d_name + tlen - 4, ".lst") != 0) continue;  /* if not an .lst file, skip it silently */
41
    if (strcasecmp(ep->d_name + tlen - 4, ".lsm") != 0) continue;  /* if not an .lsm file, skip it silently */
42
    ep->d_name[tlen - 4] = 0; /* trim out the ".lst" suffix */
42
    ep->d_name[tlen - 4] = 0; /* trim out the ".lsm" suffix */
43
 
43
 
44
    if (filterstr != NULL) {
44
    if (filterstr != NULL) {
45
      if (fdnpkg_strcasestr(ep->d_name, filterstr) == NULL) continue; /* if it's not matching the non-NULL filter, skip it */
45
      if (fdnpkg_strcasestr(ep->d_name, filterstr) == NULL) continue; /* skip if not matching the non-NULL filter */
46
    }
46
    }
47
 
47
 
48
    /* load the metadata from %DOSDIR\APPINFO\*.lsm */
48
    /* load the metadata from %DOSDIR\APPINFO\*.lsm */
49
    sprintf(buff, "%s\\appinfo\\%s.lsm", dosdir, ep->d_name);
49
    sprintf(buff, "%s\\appinfo\\%s.lsm", dosdir, ep->d_name);
50
    readlsm(buff, ver, sizeof(ver));
50
    readlsm(buff, ver, sizeof(ver));
Line 77... Line 77...
77
  char buff[256];
77
  char buff[256];
78
 
78
 
79
  sprintf(buff, "%s\\packages\\%s.lst", dosdir, pkgname);
79
  sprintf(buff, "%s\\packages\\%s.lst", dosdir, pkgname);
80
  fd = fopen(buff, "rb");
80
  fd = fopen(buff, "rb");
81
  if (fd == NULL) {
81
  if (fd == NULL) {
-
 
82
    sprintf(buff, "%s\\appinfo\\%s.lsm", dosdir, pkgname);
-
 
83
    fd = fopen(buff, "rb");
-
 
84
    if (fd == NULL) {
82
    kitten_printf(9, 1, pkgname); /* "ERROR: Local package '%s' not found." */
85
      kitten_printf(9, 1, pkgname); /* "ERROR: Local package '%s' not found." */
83
    puts("");
86
      puts("");
84
    return(NULL);
87
      return(NULL);
-
 
88
    }
85
  }
89
  }
-
 
90
 
86
  /* iterate through all lines of the file */
91
  /* iterate through all lines of the file */
87
  while (freadtokval(fd, buff, sizeof(buff), NULL, 0) == 0) {
92
  while (freadtokval(fd, buff, sizeof(buff), NULL, 0) == 0) {
-
 
93
    /* skip empty lines */
-
 
94
    if (buff[0] == 0) continue;
-
 
95
 
-
 
96
    /* normalize slashes to backslashes */
88
    slash2backslash(buff); /* change all / to \ */
97
    slash2backslash(buff);
-
 
98
 
-
 
99
    /* skip garbage */
89
    if (buff[0] == 0) continue; /* skip empty lines */
100
    if ((buff[1] != ':') || (buff[2] != '\\')) continue;
-
 
101
 
-
 
102
    /* skip directories */
90
    if (buff[strlen(buff) - 1] == '\\') continue; /* skip directories */
103
    if (buff[strlen(buff) - 1] == '\\') continue;
-
 
104
 
-
 
105
    /* trim ? trailer (may contain the file's CRC) */
-
 
106
    trimfnamecrc(buff);
-
 
107
 
91
    /* add the new node to the result */
108
    /* add the new node to the result */
92
    newnode = malloc(sizeof(struct flist_t) + strlen(buff));
109
    newnode = malloc(sizeof(struct flist_t) + strlen(buff));
93
    if (newnode == NULL) {
110
    if (newnode == NULL) {
94
      kitten_printf(2, 14, "malloc failure"); /* "Out of memory! (%s)" */
111
      kitten_printf(2, 14, "malloc failure"); /* "Out of memory! (%s)" */
95
      continue;
112
      continue;