Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 249 → Rev 250

/pkginst/main.c
42,6 → 42,7
ACTION_INSTALL,
ACTION_REMOVE,
ACTION_LISTFILES,
ACTION_LISTLOCAL,
ACTION_HELP
};
 
54,6 → 55,7
"Usage: PKGINST install package.zip\n"
" PKGINST remove package\n"
" PKGINST listfiles package\n"
" PKGINST listlocal [filter]\n"
"\n"
"PKGINST is published under the MIT license. It uses a configuration file\n"
"located at %%DOSDIR%%\\CFG\\PKGINST.CFG\n"
62,17 → 64,16
}
 
 
static enum ACTIONTYPES parsearg(int argc, char **argv) {
/* I expect exactly 2 arguments (ie argc == 3) */
if (argc != 3) return(ACTION_HELP);
 
static enum ACTIONTYPES parsearg(int argc, char * const *argv) {
/* look for valid actions */
if (strcasecmp(argv[1], "install") == 0) {
if ((argc == 3) && (strcasecmp(argv[1], "install") == 0)) {
return(ACTION_INSTALL);
} else if (strcasecmp(argv[1], "remove") == 0) {
} else if ((argc == 3) && (strcasecmp(argv[1], "remove") == 0)) {
return(ACTION_REMOVE);
} else if (strcasecmp(argv[1], "listfiles") == 0) {
} else if ((argc == 3) && (strcasecmp(argv[1], "listfiles") == 0)) {
return(ACTION_LISTFILES);
} else if ((argc >= 2) && (argc <= 3) && (strcasecmp(argv[1], "listlocal") == 0)) {
return(ACTION_LISTLOCAL);
} else {
return(ACTION_HELP);
}
148,6 → 149,9
case ACTION_LISTFILES:
res = listfilesofpkg(argv[2], dosdir);
break;
case ACTION_LISTLOCAL:
res = showinstalledpkgs((argc == 3)?argv[2]:NULL, dosdir);
break;
default:
res = showhelp();
break;
/pkginst/showinst.c
11,91 → 11,54
#include <direct.h> /* opendir() and friends */
 
#include "fdnpkg.h"
#include "fileexst.h"
#include "getdelim.h"
#include "helpers.h" /* fdnpkg_strcasestr(), slash2backslash()... */
#include "kprintf.h"
#include "libunzip.h" /* zip_freelist()... */
#include "lsm.h"
#include "pkginst.h"
#include "pkgrem.h"
#include "rtrim.h"
 
#include "showinst.h" /* include self for control */
#include "version.h"
 
 
/* this is a wrapper around strcasecmp(), to be used by qsort() */
static int strcompare(const void *str1, const void *str2) {
char **s1 = (char **)str1;
char **s2 = (char **)str2;
return(strcasecmp(*s1, *s2));
}
 
 
static int loadinstpkglist(char **packagelist, char **packagelist_ver, int packagelist_maxlen, const char *filterstr, const char *dosdir) {
int showinstalledpkgs(const char *filterstr, const char *dosdir) {
DIR *dp;
int packagelist_len = 0, x;
struct dirent *ep;
#define verstr_maxlen 64
char pkgdir[512], lsmfilename[1024], verstr[verstr_maxlen];
sprintf(pkgdir, "%s\\packages", dosdir);
dp = opendir(pkgdir);
if (dp != NULL) {
while ((ep = readdir(dp)) != NULL) {
if (ep->d_name[0] != '.') { /* ignore '.', '..', and hidden directories */
if (strlen(ep->d_name) > 4) {
int tlen = strlen(ep->d_name);
if ((ep->d_name[tlen - 4] != '.') || (tolower(ep->d_name[tlen - 3]) != 'l') || (tolower(ep->d_name[tlen - 2]) != 's') || (tolower(ep->d_name[tlen - 1]) != 't')) continue; /* if it's not an .lst file, skip it silently */
char buff[256];
char ver[16];
int matchfound = 0;
 
if (filterstr != NULL) {
if (fdnpkg_strcasestr(ep->d_name, filterstr) == NULL) continue; /* if it's not matching the non-NULL filter, skip it */
}
if (packagelist_len >= packagelist_maxlen) {
closedir(dp);
return(-1); /* if not enough place in the list - return an error */
}
packagelist[packagelist_len] = strdup(ep->d_name);
packagelist[packagelist_len][strlen(packagelist[packagelist_len]) - 4] = 0; /* cut out the .lst extension */
packagelist_len += 1;
}
}
}
closedir(dp);
qsort(packagelist, packagelist_len, sizeof (char **), strcompare); /* sort the package list */
for (x = 0; x < packagelist_len; x++) {
/* for each package, load the metadata from %DOSDIR\APPINFO\*.lsm */
sprintf(lsmfilename, "%s\\appinfo\\%s.lsm", dosdir, packagelist[x]);
if (readlsm(lsmfilename, verstr, verstr_maxlen) != 0) sprintf(verstr, "(unknown version)");
packagelist_ver[x] = strdup(verstr);
}
return(packagelist_len);
} else {
kitten_printf(9, 0, "Error: Could not access the %s directory.", pkgdir);
sprintf(buff, "%s\\packages", dosdir);
dp = opendir(buff);
if (dp == NULL) {
kitten_printf(9, 0, "Error: Could not access directory %s", buff);
puts("");
return(-1);
}
}
 
#define packagelist_maxlen 1024
while ((ep = readdir(dp)) != NULL) { /* readdir() result must never be freed (statically allocated) */
int tlen = strlen(ep->d_name);
if (ep->d_name[0] == '.') continue; /* ignore '.', '..', and hidden directories */
if (tlen < 4) continue; /* files must be at least 5 bytes long ("x.lst") */
if (strcasecmp(ep->d_name + tlen - 4, ".lst") != 0) continue; /* if not an .lst file, skip it silently */
ep->d_name[tlen - 4] = 0; /* trim out the ".lst" suffix */
 
void showinstalledpkgs(const char *filterstr, const char *dosdir) {
char *packagelist[packagelist_maxlen];
char *packagelist_ver[packagelist_maxlen];
int packagelist_len, x;
if (filterstr != NULL) {
if (fdnpkg_strcasestr(ep->d_name, filterstr) == NULL) continue; /* if it's not matching the non-NULL filter, skip it */
}
 
/* load the list of packages */
packagelist_len = loadinstpkglist(packagelist, packagelist_ver, packagelist_maxlen, filterstr, dosdir); /* Populate the packages list */
if (packagelist_len < 0) return;
if (packagelist_len == 0) {
kitten_puts(5, 0, "No package matched the search.");
return;
/* load the metadata from %DOSDIR\APPINFO\*.lsm */
sprintf(buff, "%s\\appinfo\\%s.lsm", dosdir, ep->d_name);
readlsm(buff, ver, sizeof(ver));
 
printf("%s %s", ep->d_name, ver);
puts("");
matchfound = 1;
}
if (matchfound == 0) kitten_puts(5, 0, "No package matched the search.");
 
/* iterate through all packages */
for (x = 0; x < packagelist_len; x++) {
/* print the package/version couple on screen */
printf("%s %s\n", packagelist[x], packagelist_ver[x]);
}
closedir(dp);
return(0);
}
 
 
114,20 → 77,16
struct flist_t *res = NULL, *newnode;
FILE *fd;
char *lineptr;
char buff[512];
char buff[256];
int getdelimlen, fnamelen;
size_t getdelimcount = 0;
sprintf(buff, "%s\\packages\\%s.lst", dosdir, pkgname);
if (fileexists(buff) == 0) { /* file does not exist */
fd = fopen(buff, "rb");
if (fd == NULL) {
kitten_printf(9, 1, "Error: Local package %s not found.", pkgname);
puts("");
return(NULL);
}
fd = fopen(buff, "rb");
if (fd == NULL) {
kitten_puts(4, 1, "Error opening lst file!");
return(NULL);
}
/* iterate through all lines of the file */
for (;;) {
lineptr = NULL;
/pkginst/showinst.h
7,6 → 7,6
#define showinst_h_sentinel
void pkg_freeflist(struct flist_t *flist);
struct flist_t *pkg_loadflist(const char *pkgname, const char *dosdir);
void showinstalledpkgs(const char *filterstr, const char *dosdir);
int showinstalledpkgs(const char *filterstr, const char *dosdir);
int listfilesofpkg(const char *pkgname, const char *dosdir);
#endif