Subversion Repositories SvarDOS

Rev

Rev 250 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 250 Rev 254
Line 9... Line 9...
9
#include <string.h>   /* strlen() */
9
#include <string.h>   /* strlen() */
10
#include <sys/types.h>
10
#include <sys/types.h>
11
#include <direct.h> /* opendir() and friends */
11
#include <direct.h> /* opendir() and friends */
12
 
12
 
13
#include "fdnpkg.h"
13
#include "fdnpkg.h"
14
#include "getdelim.h"
-
 
15
#include "helpers.h"  /* fdnpkg_strcasestr(), slash2backslash()... */
14
#include "helpers.h"  /* fdnpkg_strcasestr(), slash2backslash()... */
16
#include "kprintf.h"
15
#include "kprintf.h"
17
#include "libunzip.h"  /* zip_freelist()... */
16
#include "libunzip.h"  /* zip_freelist()... */
18
#include "lsm.h"
17
#include "lsm.h"
19
#include "rtrim.h"
-
 
20
 
18
 
21
#include "showinst.h"  /* include self for control */
19
#include "showinst.h"  /* include self for control */
22
 
20
 
23
 
21
 
24
int showinstalledpkgs(const char *filterstr, const char *dosdir) {
22
int showinstalledpkgs(const char *filterstr, const char *dosdir) {
Line 74... Line 72...
74
 
72
 
75
/* returns a linked list of the files that belong to package pkgname */
73
/* returns a linked list of the files that belong to package pkgname */
76
struct flist_t *pkg_loadflist(const char *pkgname, const char *dosdir) {
74
struct flist_t *pkg_loadflist(const char *pkgname, const char *dosdir) {
77
  struct flist_t *res = NULL, *newnode;
75
  struct flist_t *res = NULL, *newnode;
78
  FILE *fd;
76
  FILE *fd;
79
  char *lineptr;
-
 
80
  char buff[256];
77
  char buff[256];
81
  int getdelimlen, fnamelen;
-
 
82
  size_t getdelimcount = 0;
-
 
-
 
78
 
83
  sprintf(buff, "%s\\packages\\%s.lst", dosdir, pkgname);
79
  sprintf(buff, "%s\\packages\\%s.lst", dosdir, pkgname);
84
  fd = fopen(buff, "rb");
80
  fd = fopen(buff, "rb");
85
  if (fd == NULL) {
81
  if (fd == NULL) {
86
    kitten_printf(9, 1, "Error: Local package %s not found.", pkgname);
82
    kitten_printf(9, 1, "Error: Local package %s not found.", pkgname);
87
    puts("");
83
    puts("");
88
    return(NULL);
84
    return(NULL);
89
  }
85
  }
90
  /* iterate through all lines of the file */
86
  /* iterate through all lines of the file */
91
  for (;;) {
-
 
92
    lineptr = NULL;
-
 
93
    getdelimlen = getdelim(&lineptr, &getdelimcount, '\n', fd);
87
  while (freadtokval(fd, buff, sizeof(buff), NULL, 0) == 0) {
94
    if (getdelimlen < 0) { /* EOF */
-
 
95
      free(lineptr);
-
 
96
      break;
-
 
97
    }
-
 
98
    rtrim(lineptr);  /* right-trim the filename */
-
 
99
    slash2backslash(lineptr); /* change all / to \ */
88
    slash2backslash(buff); /* change all / to \ */
100
    if ((lineptr[0] == 0) || (lineptr[0] == '\r') || (lineptr[0] == '\n')) continue; /* skip empty lines */
89
    if (buff[0] == 0) continue; /* skip empty lines */
101
    if (lineptr[strlen(lineptr) - 1] == '\\') continue; /* skip directories */
90
    if (buff[strlen(buff) - 1] == '\\') continue; /* skip directories */
102
    if ((lineptr[0] == '\\') || (lineptr[1] == ':')) { /* this is an absolute path */
-
 
103
      fnamelen = snprintf(buff, sizeof(buff), "%s", lineptr);
-
 
104
    } else { /* else it's a relative path starting at %dosdir% */
-
 
105
      fnamelen = snprintf(buff, sizeof(buff), "%s\\%s\n", dosdir, lineptr);
-
 
106
    }
-
 
107
    free(lineptr); /* free the memory occupied by the line */
-
 
108
    /* add the new node to the result */
91
    /* add the new node to the result */
109
    newnode = malloc(sizeof(struct flist_t) + fnamelen);
92
    newnode = malloc(sizeof(struct flist_t) + strlen(buff));
110
    if (newnode == NULL) {
93
    if (newnode == NULL) {
111
      kitten_printf(2, 14, "Out of memory! (%s)", "malloc failure");
94
      kitten_printf(2, 14, "Out of memory! (%s)", "malloc failure");
112
      continue;
95
      continue;
113
    }
96
    }
114
    newnode->next = res;
97
    newnode->next = res;