Subversion Repositories SvarDOS

Rev

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

Rev 272 Rev 613
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-2021 Mateusz Viste
3
 * Copyright (C) 2013-2022 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 12... Line 12...
12
 
12
 
13
#include "helpers.h"  /* fdnpkg_strcasestr(), slash2backslash()... */
13
#include "helpers.h"  /* fdnpkg_strcasestr(), slash2backslash()... */
14
#include "kprintf.h"
14
#include "kprintf.h"
15
#include "libunzip.h"  /* zip_freelist()... */
15
#include "libunzip.h"  /* zip_freelist()... */
16
#include "lsm.h"
16
#include "lsm.h"
-
 
17
#include "svarlang.lib\svarlang.h"
17
 
18
 
18
#include "showinst.h"  /* include self for control */
19
#include "showinst.h"  /* include self for control */
19
 
20
 
20
 
21
 
21
int showinstalledpkgs(const char *filterstr, const char *dosdir) {
22
int showinstalledpkgs(const char *filterstr, const char *dosdir) {
Line 26... Line 27...
26
  int matchfound = 0;
27
  int matchfound = 0;
27
 
28
 
28
  sprintf(buff, "%s\\packages", dosdir);
29
  sprintf(buff, "%s\\packages", dosdir);
29
  dp = opendir(buff);
30
  dp = opendir(buff);
30
  if (dp == NULL) {
31
  if (dp == NULL) {
31
    kitten_printf(9, 0, "ERROR: Could not access directory %s", buff);
32
    kitten_printf(9, 0, buff); /* "ERROR: Could not access directory %s" */
32
    puts("");
33
    puts("");
33
    return(-1);
34
    return(-1);
34
  }
35
  }
35
 
36
 
36
  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) */
Line 50... Line 51...
50
 
51
 
51
    printf("%s %s", ep->d_name, ver);
52
    printf("%s %s", ep->d_name, ver);
52
    puts("");
53
    puts("");
53
    matchfound = 1;
54
    matchfound = 1;
54
  }
55
  }
55
  if (matchfound == 0) kitten_puts(5, 0, "No package matched the search.");
56
  if (matchfound == 0) puts(svarlang_str(5, 0)); /* "No package matched the search." */
56
 
57
 
57
  closedir(dp);
58
  closedir(dp);
58
  return(0);
59
  return(0);
59
}
60
}
60
 
61
 
Line 76... Line 77...
76
  char buff[256];
77
  char buff[256];
77
 
78
 
78
  sprintf(buff, "%s\\packages\\%s.lst", dosdir, pkgname);
79
  sprintf(buff, "%s\\packages\\%s.lst", dosdir, pkgname);
79
  fd = fopen(buff, "rb");
80
  fd = fopen(buff, "rb");
80
  if (fd == NULL) {
81
  if (fd == NULL) {
81
    kitten_printf(9, 1, "ERROR: Local package '%s' not found.", pkgname);
82
    kitten_printf(9, 1, pkgname); /* "ERROR: Local package '%s' not found." */
82
    puts("");
83
    puts("");
83
    return(NULL);
84
    return(NULL);
84
  }
85
  }
85
  /* iterate through all lines of the file */
86
  /* iterate through all lines of the file */
86
  while (freadtokval(fd, buff, sizeof(buff), NULL, 0) == 0) {
87
  while (freadtokval(fd, buff, sizeof(buff), NULL, 0) == 0) {
Line 88... Line 89...
88
    if (buff[0] == 0) continue; /* skip empty lines */
89
    if (buff[0] == 0) continue; /* skip empty lines */
89
    if (buff[strlen(buff) - 1] == '\\') continue; /* skip directories */
90
    if (buff[strlen(buff) - 1] == '\\') continue; /* skip directories */
90
    /* add the new node to the result */
91
    /* add the new node to the result */
91
    newnode = malloc(sizeof(struct flist_t) + strlen(buff));
92
    newnode = malloc(sizeof(struct flist_t) + strlen(buff));
92
    if (newnode == NULL) {
93
    if (newnode == NULL) {
93
      kitten_printf(2, 14, "Out of memory! (%s)", "malloc failure");
94
      kitten_printf(2, 14, "malloc failure"); /* "Out of memory! (%s)" */
94
      continue;
95
      continue;
95
    }
96
    }
96
    newnode->next = res;
97
    newnode->next = res;
97
    strcpy(newnode->fname, buff);
98
    strcpy(newnode->fname, buff);
98
    res = newnode;
99
    res = newnode;