Subversion Repositories SvarDOS

Rev

Rev 219 | Rev 223 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 219 Rev 221
1
/*
1
/*
2
 * This file is part of FDNPKG
2
 * This file is part of FDNPKG
3
 * Copyright (C) 2012-2021 Mateusz Viste
3
 * Copyright (C) 2012-2021 Mateusz Viste
4
 * Changes by TK Chia
4
 * Changes by TK Chia
5
 */
5
 */
6
 
6
 
7
#include <ctype.h>     /* toupper() */
7
#include <ctype.h>     /* toupper() */
8
#include <stdio.h>
8
#include <stdio.h>
9
#include <stdlib.h>    /* system() */
9
#include <stdlib.h>    /* system() */
10
#include <string.h>    /* strcpy() */
10
#include <string.h>    /* strcpy() */
11
#include <unistd.h>    /* read() */
11
#include <unistd.h>    /* read() */
12
#include <sys/types.h> /* struct utimbuf */
12
#include <sys/types.h> /* struct utimbuf */
13
 
13
 
14
#include "crc32.h"     /* all CRC32 related stuff */
14
#include "crc32.h"     /* all CRC32 related stuff */
15
#include "fdnpkg.h"    /* PKGINST_NOSOURCE, PKGINST_SKIPLINKS... */
15
#include "fdnpkg.h"    /* PKGINST_NOSOURCE, PKGINST_SKIPLINKS... */
16
#include "http.h"
-
 
17
#include "helpers.h"   /* slash2backslash(), strtolower() */
16
#include "helpers.h"   /* slash2backslash(), strtolower() */
18
#include "fileexst.h"
17
#include "fileexst.h"
19
#include "kprintf.h"
18
#include "kprintf.h"
20
#include "libunzip.h"  /* zip_listfiles()... */
19
#include "libunzip.h"  /* zip_listfiles()... */
21
#include "showinst.h"  /* pkg_loadflist() */
20
#include "showinst.h"  /* pkg_loadflist() */
22
#include "pkginst.h"   /* include self for control */
21
#include "pkginst.h"   /* include self for control */
23
#include "version.h"
22
#include "version.h"
24
 
23
 
25
 
24
 
26
/* return 1 if fname looks like a link filename, 0 otherwise */
25
/* return 1 if fname looks like a link filename, 0 otherwise */
27
static int islinkfile(char *fname) {
26
static int islinkfile(char *fname) {
28
  char *link1 = "LINKS\\";
27
  char *link1 = "LINKS\\";
29
  char *link2 = "links\\";
28
  char *link2 = "links\\";
30
  int x;
29
  int x;
31
  for (x = 0; ; x++) {
30
  for (x = 0; ; x++) {
32
    if (link1[x] == 0) return(1);
31
    if (link1[x] == 0) return(1);
33
    if ((fname[x] != link1[x]) && (fname[x] != link2[x])) return(0);
32
    if ((fname[x] != link1[x]) && (fname[x] != link2[x])) return(0);
34
  }
33
  }
35
}
34
}
36
 
35
 
37
 
36
 
38
/* validate a filename (8+3, no weird characters, etc). returns 0 on success,
37
/* validate a filename (8+3, no weird characters, etc). returns 0 on success,
39
 * nonzero otherwise. */
38
 * nonzero otherwise. */
40
static int validfilename(char *fname) {
39
static int validfilename(char *fname) {
41
  int i, i2;
40
  int i, i2;
42
  char *validchars = "!#$%&'()-@^_`{}~";
41
  char *validchars = "!#$%&'()-@^_`{}~";
43
  int elemlen = 0;
42
  int elemlen = 0;
44
  int elemmaxlen = 8; /* switches from 8 to 3 depending wheter I am analyzing
43
  int elemmaxlen = 8; /* switches from 8 to 3 depending wheter I am analyzing
45
                         a filename or an extension */
44
                         a filename or an extension */
46
  /* look for invalid chars in the entire string, and check the length of the
45
  /* look for invalid chars in the entire string, and check the length of the
47
   * element at the same time */
46
   * element at the same time */
48
  for (i = 0; fname[i] != 0; i++) {
47
  for (i = 0; fname[i] != 0; i++) {
49
    /* director separators are threated specially */
48
    /* director separators are threated specially */
50
    if (fname[i] == '\\') {
49
    if (fname[i] == '\\') {
51
      elemlen = 0;
50
      elemlen = 0;
52
      elemmaxlen = 8;
51
      elemmaxlen = 8;
53
      continue;
52
      continue;
54
    }
53
    }
55
    /* '.' switches the check into extension mode */
54
    /* '.' switches the check into extension mode */
56
    if (fname[i] == '.') {
55
    if (fname[i] == '.') {
57
      if (elemlen == 0) return(-1); /* a file must have a base name */
56
      if (elemlen == 0) return(-1); /* a file must have a base name */
58
      if (elemmaxlen == 3) return(-2); /* a file cannot have two extensions */
57
      if (elemmaxlen == 3) return(-2); /* a file cannot have two extensions */
59
      elemlen = 0;
58
      elemlen = 0;
60
      elemmaxlen = 3;
59
      elemmaxlen = 3;
61
      continue;
60
      continue;
62
    }
61
    }
63
    /* check that the element is not too long */
62
    /* check that the element is not too long */
64
    if (++elemlen > elemmaxlen) return(-3);
63
    if (++elemlen > elemmaxlen) return(-3);
65
    /* look for valid characters */
64
    /* look for valid characters */
66
    if ((fname[i] >= 'a') && (fname[i] <= 'z')) continue;
65
    if ((fname[i] >= 'a') && (fname[i] <= 'z')) continue;
67
    if ((fname[i] >= 'A') && (fname[i] <= 'Z')) continue;
66
    if ((fname[i] >= 'A') && (fname[i] <= 'Z')) continue;
68
    if ((fname[i] >= '0') && (fname[i] <= '9')) continue;
67
    if ((fname[i] >= '0') && (fname[i] <= '9')) continue;
69
    if ((fname[i] & 128) != 0) continue; /* high bytes are okay (NLS) */
68
    if ((fname[i] & 128) != 0) continue; /* high bytes are okay (NLS) */
70
    /* look for other valid characters */
69
    /* look for other valid characters */
71
    for (i2 = 0; validchars[i2] != 0; i2++) {
70
    for (i2 = 0; validchars[i2] != 0; i2++) {
72
      if (fname[i] == validchars[i2]) break;
71
      if (fname[i] == validchars[i2]) break;
73
    }
72
    }
74
    if (validchars[i2] != 0) continue;
73
    if (validchars[i2] != 0) continue;
75
    /* if we are here, then the character is invalid */
74
    /* if we are here, then the character is invalid */
76
    return(-4);
75
    return(-4);
77
  }
76
  }
78
  /* all checks passed */
77
  /* all checks passed */
79
  return(0);
78
  return(0);
80
}
79
}
81
 
80
 
82
 
81
 
83
/* processes a link file - that is, reads the target inside, and overwrite
82
/* processes a link file - that is, reads the target inside, and overwrite
84
 * the file with new content */
83
 * the file with new content */
85
static void processlinkfile(char *linkfile, char *dosdir, struct customdirs *dirlist, char *buff) {
84
static void processlinkfile(char *linkfile, char *dosdir, struct customdirs *dirlist, char *buff) {
86
  char origtarget[512];
85
  char origtarget[512];
87
  int x;
86
  int x;
88
  char *shortfile;
87
  char *shortfile;
89
  unsigned char comstub[] = { /* machine code of a COM stub launcher */
88
  unsigned char comstub[] = { /* machine code of a COM stub launcher */
90
    0xBC,0x00,0x00,0xBB,0x00,0x10,0xB4,0x4A,0xCD,0x21,0xBB,0x2A,0x01,0x8C,0x5F,0x04,
89
    0xBC,0x00,0x00,0xBB,0x00,0x10,0xB4,0x4A,0xCD,0x21,0xBB,0x2A,0x01,0x8C,0x5F,0x04,
91
    0x8C,0x5F,0x08,0x8C,0x5F,0x0C,0xB8,0x00,0x4B,0xBA,0x38,0x01,0xCD,0x21,0xB0,0x7F,
90
    0x8C,0x5F,0x08,0x8C,0x5F,0x0C,0xB8,0x00,0x4B,0xBA,0x38,0x01,0xCD,0x21,0xB0,0x7F,
92
    0x72,0x04,0xB4,0x4D,0xCD,0x21,0xB4,0x4C,0xCD,0x21,0x00,0x00,0x80,0x00,0x00,0x00,
91
    0x72,0x04,0xB4,0x4D,0xCD,0x21,0xB4,0x4C,0xCD,0x21,0x00,0x00,0x80,0x00,0x00,0x00,
93
    0x5C,0x00,0x00,0x00,0x6C,0x00,0x00,0x00}; /* read comlink.asm for details */
92
    0x5C,0x00,0x00,0x00,0x6C,0x00,0x00,0x00}; /* read comlink.asm for details */
94
  const unsigned stack_paras = 12;
93
  const unsigned stack_paras = 12;
95
  unsigned alloc_paras, alloc_bytes;
94
  unsigned alloc_paras, alloc_bytes;
96
  FILE *fd;
95
  FILE *fd;
97
  /* open the link file and read the original target */
96
  /* open the link file and read the original target */
98
  fd = fopen(linkfile, "r");
97
  fd = fopen(linkfile, "r");
99
  if (fd == NULL) {
98
  if (fd == NULL) {
100
    kitten_printf(3, 21, "Error: Failed to open link file '%s' for read access.", linkfile);
99
    kitten_printf(3, 21, "Error: Failed to open link file '%s' for read access.", linkfile);
101
    puts("");
100
    puts("");
102
    return;
101
    return;
103
  }
102
  }
104
  x = fread(origtarget, 1, sizeof(origtarget) - 1, fd);
103
  x = fread(origtarget, 1, sizeof(origtarget) - 1, fd);
105
  origtarget[x] = 0;
104
  origtarget[x] = 0;
106
  fclose(fd);
105
  fclose(fd);
107
  /* validate the original target (ltrim to first \r or \n) */
106
  /* validate the original target (ltrim to first \r or \n) */
108
  for (x = 0; origtarget[x] != 0; x++) {
107
  for (x = 0; origtarget[x] != 0; x++) {
109
    if ((origtarget[x] == '\r') || (origtarget[x] == '\n')) {
108
    if ((origtarget[x] == '\r') || (origtarget[x] == '\n')) {
110
      origtarget[x] = 0;
109
      origtarget[x] = 0;
111
      break;
110
      break;
112
    }
111
    }
113
  }
112
  }
114
  /* translate the original target to a local path */
113
  /* translate the original target to a local path */
115
  shortfile = computelocalpath(origtarget, buff, dosdir, dirlist);
114
  shortfile = computelocalpath(origtarget, buff, dosdir, dirlist);
116
  /* compute the amount of memory the stub should leave for itself:
115
  /* compute the amount of memory the stub should leave for itself:
117
	- 16 paragraphs needed for the PSP
116
	- 16 paragraphs needed for the PSP
118
	- sizeof(comstub) bytes needed for code and data
117
	- sizeof(comstub) bytes needed for code and data
119
	- strlen(shortfile) + 1 for the command line
118
	- strlen(shortfile) + 1 for the command line
120
	- stack_paras paragraphs for the stack */
119
	- stack_paras paragraphs for the stack */
121
  alloc_paras = 16 + (sizeof(comstub) + strlen(shortfile) + 16) / 16 + stack_paras;
120
  alloc_paras = 16 + (sizeof(comstub) + strlen(shortfile) + 16) / 16 + stack_paras;
122
  alloc_bytes = 16 * alloc_paras;
121
  alloc_bytes = 16 * alloc_paras;
123
  comstub[1] = alloc_bytes & 0xff;
122
  comstub[1] = alloc_bytes & 0xff;
124
  comstub[2] = alloc_bytes >> 8;
123
  comstub[2] = alloc_bytes >> 8;
125
  comstub[4] = alloc_paras & 0xff;
124
  comstub[4] = alloc_paras & 0xff;
126
  comstub[5] = alloc_paras >> 8;
125
  comstub[5] = alloc_paras >> 8;
127
  /* write new content into the link file */
126
  /* write new content into the link file */
128
  fd = fopen(linkfile, "wb");
127
  fd = fopen(linkfile, "wb");
129
  if (fd == NULL) {
128
  if (fd == NULL) {
130
    kitten_printf(3, 22, "Error: Failed to open link file '%s' for write access.", linkfile);
129
    kitten_printf(3, 22, "Error: Failed to open link file '%s' for write access.", linkfile);
131
    puts("");
130
    puts("");
132
    return;
131
    return;
133
  }
132
  }
134
  fwrite(comstub, 1, sizeof(comstub), fd);
133
  fwrite(comstub, 1, sizeof(comstub), fd);
135
  fprintf(fd, "%s%s%c", buff, shortfile, 0);
134
  fprintf(fd, "%s%s%c", buff, shortfile, 0);
136
  fclose(fd);
135
  fclose(fd);
137
}
136
}
138
 
137
 
139
 
138
 
140
/* returns 0 if pkgname is not installed, non-zero otherwise */
139
/* returns 0 if pkgname is not installed, non-zero otherwise */
141
int is_package_installed(char *pkgname, char *dosdir, char *mapdrv) {
140
int is_package_installed(char *pkgname, char *dosdir, char *mapdrv) {
142
  char fname[512];
141
  char fname[512];
143
  sprintf(fname, "%s\\packages\\%s.lst", dosdir, pkgname);
142
  sprintf(fname, "%s\\packages\\%s.lst", dosdir, pkgname);
144
  mapdrives(fname, mapdrv);
143
  mapdrives(fname, mapdrv);
145
  if (fileexists(fname) != 0) { /* file exists -> package is installed */
144
  if (fileexists(fname) != 0) { /* file exists -> package is installed */
146
    return(1);
145
    return(1);
147
  } else {
146
  } else {
148
    return(0);
147
    return(0);
149
  }
148
  }
150
}
149
}
151
 
150
 
152
 
151
 
153
/* checks that pkgname is NOT installed. return 0 on success, non-zero otherwise. */
152
/* checks that pkgname is NOT installed. return 0 on success, non-zero otherwise. */
154
int validate_package_not_installed(char *pkgname, char *dosdir, char *mapdrv) {
153
int validate_package_not_installed(char *pkgname, char *dosdir, char *mapdrv) {
155
  if (is_package_installed(pkgname, dosdir, mapdrv) != 0) {
154
  if (is_package_installed(pkgname, dosdir, mapdrv) != 0) {
156
    kitten_printf(3, 18, "Package %s is already installed! You might want to use the 'update' action.", pkgname);
155
    kitten_printf(3, 18, "Package %s is already installed! You might want to use the 'update' action.", pkgname);
157
    puts("");
156
    puts("");
158
    return(-1);
157
    return(-1);
159
  }
158
  }
160
  return(0);
159
  return(0);
161
}
160
}
162
 
161
 
163
 
162
 
164
/* find a filename in a flist linked list, and returns a pointer to it */
163
/* find a filename in a flist linked list, and returns a pointer to it */
165
static struct flist_t *findfileinlist(struct flist_t *flist, char *fname) {
164
static struct flist_t *findfileinlist(struct flist_t *flist, char *fname) {
166
  while (flist != NULL) {
165
  while (flist != NULL) {
167
    if (strcmp(flist->fname, fname) == 0) return(flist);
166
    if (strcmp(flist->fname, fname) == 0) return(flist);
168
    flist = flist->next;
167
    flist = flist->next;
169
  }
168
  }
170
  return(NULL);
169
  return(NULL);
171
}
170
}
172
 
171
 
173
 
172
 
174
/* prepare a package for installation. this is mandatory before actually installing it!
173
/* prepare a package for installation. this is mandatory before actually installing it!
175
 * returns a pointer to the zip file's index on success, NULL on failure. the *zipfile pointer is updated with a file descriptor to the open zip file to install. */
174
 * returns a pointer to the zip file's index on success, NULL on failure. the *zipfile pointer is updated with a file descriptor to the open zip file to install. */
176
struct ziplist *pkginstall_preparepackage(struct pkgdb *pkgdb, char *pkgname, char *tempdir, char *localfile, int flags, char **repolist, FILE **zipfd, char *proxy, int proxyport, char *downloadingstring, char *dosdir, struct customdirs *dirlist, char *buffmem1k, char *mapdrv) {
175
struct ziplist *pkginstall_preparepackage(struct pkgdb *pkgdb, char *pkgname, char *tempdir, char *localfile, int flags, char **repolist, FILE **zipfd, char *proxy, int proxyport, char *downloadingstring, char *dosdir, struct customdirs *dirlist, char *buffmem1k, char *mapdrv) {
177
  char *fname;
176
  char *fname;
178
  char *zipfile;
177
  char *zipfile;
179
  char *appinfofile;
178
  char *appinfofile;
180
  int appinfopresence;
179
  int appinfopresence;
181
  char *shortfile;
180
  char *shortfile;
182
  struct ziplist *ziplinkedlist, *curzipnode, *prevzipnode;
181
  struct ziplist *ziplinkedlist, *curzipnode, *prevzipnode;
183
  struct flist_t *flist;
182
  struct flist_t *flist;
184
 
183
 
185
  fname = buffmem1k;
184
  fname = buffmem1k;
186
  zipfile = buffmem1k + 256;
185
  zipfile = buffmem1k + 256;
187
  appinfofile = buffmem1k + 512;
186
  appinfofile = buffmem1k + 512;
188
 
187
 
189
  strtolower(pkgname); /* convert pkgname to lower case, because the http repo is probably case sensitive */
188
  strtolower(pkgname); /* convert pkgname to lower case, because the http repo is probably case sensitive */
190
  sprintf(appinfofile, "appinfo\\%s.lsm", pkgname); /* Prepare the appinfo/xxxx.lsm filename string for later use */
189
  sprintf(appinfofile, "appinfo\\%s.lsm", pkgname); /* Prepare the appinfo/xxxx.lsm filename string for later use */
191
 
190
 
192
  /* check if not already installed, if already here, print a message "you might want to use update instead"
191
  /* check if not already installed, if already here, print a message "you might want to use update instead"
193
   * of course this must not be done if we are in the process of upgrading said package */
192
   * of course this must not be done if we are in the process of upgrading said package */
194
  if (((flags & PKGINST_UPDATE) == 0) && (validate_package_not_installed(pkgname, dosdir, mapdrv) != 0)) {
193
  if (((flags & PKGINST_UPDATE) == 0) && (validate_package_not_installed(pkgname, dosdir, mapdrv) != 0)) {
195
    return(NULL);
194
    return(NULL);
196
  }
195
  }
197
 
196
 
198
  if (localfile != NULL) {  /* if it's a local file, then we will have to skip all the network stuff */
197
  if (localfile != NULL) {  /* if it's a local file, then we will have to skip all the network stuff */
199
    strcpy(zipfile, localfile);
198
    strcpy(zipfile, localfile);
200
  } else {
199
  } else {
201
    zipfile[0] = 0;
200
    zipfile[0] = 0;
202
  }
201
  }
203
 
202
 
204
#ifndef NOREPOS
203
#ifndef NOREPOS
205
  if (zipfile[0] == 0) { /* need to download the package from a repository */
204
  if (zipfile[0] == 0) { /* need to download the package from a repository */
206
    char *instrepo;
205
    char *instrepo;
207
    struct pkgdb *pkgnode, *lastnode;
206
    struct pkgdb *pkgnode, *lastnode;
208
    struct pkgrepo *pkgrepo;
207
    struct pkgrepo *pkgrepo;
209
    int repoid;
208
    int repoid;
210
    unsigned long zipfilecrc, remotecrc;
209
    unsigned long zipfilecrc, remotecrc;
211
    unsigned char *buff;
210
    unsigned char *buff;
212
    int buffreadres;
211
    int buffreadres;
213
    char *pkgext; /* zip or zib */
212
    char *pkgext; /* zip or zib */
214
 
213
 
215
    /* look into the db to find the package */
214
    /* look into the db to find the package */
216
    pkgnode = findpkg(pkgdb, pkgname, &lastnode);
215
    pkgnode = findpkg(pkgdb, pkgname, &lastnode);
217
    if (pkgnode == NULL) { /* no such package found in repositories */
216
    if (pkgnode == NULL) { /* no such package found in repositories */
218
      kitten_printf(3, 1, "No package '%s' found in online repositories.", pkgname);
217
      kitten_printf(3, 1, "No package '%s' found in online repositories.", pkgname);
219
      puts("");
218
      puts("");
220
      return(NULL);
219
      return(NULL);
221
    }
220
    }
222
 
221
 
223
    /* if found - check the list of repositories */
222
    /* if found - check the list of repositories */
224
    if (pkgnode->repolist == NULL) {
223
    if (pkgnode->repolist == NULL) {
225
      kitten_printf(3, 2, "Package '%s' is not available in repositories.", pkgname);
224
      kitten_printf(3, 2, "Package '%s' is not available in repositories.", pkgname);
226
      puts("");
225
      puts("");
227
      return(NULL);
226
      return(NULL);
228
    }
227
    }
229
 
228
 
230
    if (pkgnode->repolist->nextrepo != NULL) { /* available from more than 1 repo.. */
229
    if (pkgnode->repolist->nextrepo != NULL) { /* available from more than 1 repo.. */
231
      char userchoicestr[8];
230
      char userchoicestr[8];
232
      int userchoice, latestver_repoid = 1;
231
      int userchoice, latestver_repoid = 1;
233
      struct pkgrepo *xrepo, *latestver = pkgnode->repolist;
232
      struct pkgrepo *xrepo, *latestver = pkgnode->repolist;
234
      /* check out if we are able to find out the newest version */
233
      /* check out if we are able to find out the newest version */
235
      repoid = 2; /* setting to 2, because we start iterating at the second repo entry */
234
      repoid = 2; /* setting to 2, because we start iterating at the second repo entry */
236
      for (xrepo = pkgnode->repolist->nextrepo; xrepo != NULL; xrepo = xrepo->nextrepo) {
235
      for (xrepo = pkgnode->repolist->nextrepo; xrepo != NULL; xrepo = xrepo->nextrepo) {
237
        int versionnewerres = isversionnewer(latestver->version, xrepo->version);
236
        int versionnewerres = isversionnewer(latestver->version, xrepo->version);
238
        if (versionnewerres > 0) {
237
        if (versionnewerres > 0) {
239
          latestver = xrepo;
238
          latestver = xrepo;
240
          latestver_repoid = repoid;
239
          latestver_repoid = repoid;
241
        } else if (versionnewerres < 0) {  /* unable to tell which version is newer */
240
        } else if (versionnewerres < 0) {  /* unable to tell which version is newer */
242
          latestver_repoid = -1;
241
          latestver_repoid = -1;
243
          break;
242
          break;
244
        }
243
        }
245
        repoid += 1;
244
        repoid += 1;
246
      }
245
      }
247
      if (latestver_repoid > 0) {
246
      if (latestver_repoid > 0) {
248
        repoid = latestver_repoid;
247
        repoid = latestver_repoid;
249
      } else { /* newest version could not be figured out, so let's ask the user to choose */
248
      } else { /* newest version could not be figured out, so let's ask the user to choose */
250
        puts("");
249
        puts("");
251
        kitten_printf(3, 3, "%s is available from several repositories. Choose which one to use:", pkgname);
250
        kitten_printf(3, 3, "%s is available from several repositories. Choose which one to use:", pkgname);
252
        puts("");
251
        puts("");
253
        repoid = 1;
252
        repoid = 1;
254
        for (xrepo = pkgnode->repolist; xrepo != NULL; xrepo = xrepo->nextrepo) {
253
        for (xrepo = pkgnode->repolist; xrepo != NULL; xrepo = xrepo->nextrepo) {
255
          printf(" %d) %s %s (%s)\n", repoid, pkgnode->name, xrepo->version, repolist[xrepo->repo]);
254
          printf(" %d) %s %s (%s)\n", repoid, pkgnode->name, xrepo->version, repolist[xrepo->repo]);
256
          repoid += 1;
255
          repoid += 1;
257
        }
256
        }
258
        for (;;) {
257
        for (;;) {
259
          kitten_printf(3, 4, "Your choice:");
258
          kitten_printf(3, 4, "Your choice:");
260
          printf(" ");
259
          printf(" ");
261
          fgets(userchoicestr, 6, stdin);
260
          fgets(userchoicestr, 6, stdin);
262
          userchoice = atoi(userchoicestr);
261
          userchoice = atoi(userchoicestr);
263
          if ((userchoice < 1) || (userchoice >= repoid)) {
262
          if ((userchoice < 1) || (userchoice >= repoid)) {
264
            kitten_puts(3, 5, "Invalid choice!");
263
            kitten_puts(3, 5, "Invalid choice!");
265
          } else {
264
          } else {
266
            break;
265
            break;
267
          }
266
          }
268
        }
267
        }
269
        repoid = userchoice;
268
        repoid = userchoice;
270
      }
269
      }
271
    } else { /* available only from one repository - get it there */
270
    } else { /* available only from one repository - get it there */
272
      repoid = 1;
271
      repoid = 1;
273
    }
272
    }
274
    pkgrepo = pkgnode->repolist;
273
    pkgrepo = pkgnode->repolist;
275
    for (; repoid > 1; repoid--) pkgrepo = pkgrepo->nextrepo;
274
    for (; repoid > 1; repoid--) pkgrepo = pkgrepo->nextrepo;
276
    instrepo = repolist[pkgrepo->repo];
275
    instrepo = repolist[pkgrepo->repo];
277
 
276
 
278
    /* select the package extension: zip or zib */
277
    /* select the package extension: zip or zib */
279
    if ((flags & PKGINST_NOSOURCE) && (pkgrepo->crc32zib != 0)) { /* use zib if available and if no sources needed */
278
    if ((flags & PKGINST_NOSOURCE) && (pkgrepo->crc32zib != 0)) { /* use zib if available and if no sources needed */
280
      pkgext = "zib"; /* zib is the same thing as zip, but binary-only (no sources) */
279
      pkgext = "zib"; /* zib is the same thing as zip, but binary-only (no sources) */
281
      remotecrc = pkgrepo->crc32zib;
280
      remotecrc = pkgrepo->crc32zib;
282
    } else { /* otherwise use the full-blown zip package */
281
    } else { /* otherwise use the full-blown zip package */
283
      pkgext = "zip";
282
      pkgext = "zip";
284
      remotecrc = pkgrepo->crc32zip;
283
      remotecrc = pkgrepo->crc32zip;
285
    }
284
    }
286
 
285
 
287
    /* if it's a network repo, download the package from repoid into the temp directory */
286
    /* if it's a network repo, download the package from repoid into the temp directory */
288
    if (detect_localpath(instrepo) == 0) {
287
    if (detect_localpath(instrepo) == 0) {
289
      sprintf(fname, "%s%s.%s", instrepo, pkgname, pkgext);
288
      sprintf(fname, "%s%s.%s", instrepo, pkgname, pkgext);
290
      sprintf(zipfile, "%s\\fdnpkg.tmp", tempdir);
289
      sprintf(zipfile, "%s\\fdnpkg.tmp", tempdir);
291
      kitten_printf(3, 6, "Downloading package %s...", fname);
290
      kitten_printf(3, 6, "Downloading package %s...", fname);
292
      puts("");
291
      puts("");
293
      if (http_get(fname, zipfile, proxy, proxyport, downloadingstring) <= 0) {
292
      if (http_get(fname, zipfile, proxy, proxyport, downloadingstring) <= 0) {
294
        kitten_puts(3, 7, "Error downloading package. Aborted.");
293
        kitten_puts(3, 7, "Error downloading package. Aborted.");
295
        return(NULL);
294
        return(NULL);
296
      }
295
      }
297
    } else { /* else it's an on-disk repo, so we can use the package right from there */
296
    } else { /* else it's an on-disk repo, so we can use the package right from there */
298
      sprintf(zipfile, "%s%s.%s", instrepo, pkgname, pkgext);
297
      sprintf(zipfile, "%s%s.%s", instrepo, pkgname, pkgext);
299
    }
298
    }
300
    /* check the CRC of the downloaded file */
299
    /* check the CRC of the downloaded file */
301
    buff = malloc(4096);  /* use a 4K buffer to compute file's CRC */
300
    buff = malloc(4096);  /* use a 4K buffer to compute file's CRC */
302
    if (buff == NULL) {
301
    if (buff == NULL) {
303
      kitten_puts(3, 15, "Error: Out of memory while computing the CRC of the package!");
302
      kitten_puts(3, 15, "Error: Out of memory while computing the CRC of the package!");
304
      return(NULL);
303
      return(NULL);
305
    }
304
    }
306
    *zipfd = fopen(zipfile, "rb");
305
    *zipfd = fopen(zipfile, "rb");
307
    if (*zipfd == NULL) {
306
    if (*zipfd == NULL) {
308
      kitten_puts(3, 14, "Error: Failed to open the downloaded package. Installation aborted.");
307
      kitten_puts(3, 14, "Error: Failed to open the downloaded package. Installation aborted.");
309
      free(buff);
308
      free(buff);
310
      return(NULL);
309
      return(NULL);
311
    }
310
    }
312
    zipfilecrc = crc32_init();
311
    zipfilecrc = crc32_init();
313
    while ((buffreadres = read(fileno(*zipfd), buff, 4096)) > 0) {
312
    while ((buffreadres = read(fileno(*zipfd), buff, 4096)) > 0) {
314
      crc32_feed(&zipfilecrc, buff, buffreadres);
313
      crc32_feed(&zipfilecrc, buff, buffreadres);
315
    }
314
    }
316
    crc32_finish(&zipfilecrc);
315
    crc32_finish(&zipfilecrc);
317
    fclose(*zipfd);
316
    fclose(*zipfd);
318
    free(buff);
317
    free(buff);
319
    if (zipfilecrc != remotecrc) {
318
    if (zipfilecrc != remotecrc) {
320
      kitten_puts(3, 13, "Error: Downloaded package had wrong CRC. Installation aborted.");
319
      kitten_puts(3, 13, "Error: Downloaded package had wrong CRC. Installation aborted.");
321
      return(NULL);
320
      return(NULL);
322
    }
321
    }
323
  } /* if (zipfile[0] == 0) */
322
  } /* if (zipfile[0] == 0) */
324
#endif
323
#endif
325
 
324
 
326
  /* Now let's check the content of the zip file */
325
  /* Now let's check the content of the zip file */
327
 
326
 
328
  *zipfd = fopen(zipfile, "rb");
327
  *zipfd = fopen(zipfile, "rb");
329
  if (*zipfd == NULL) {
328
  if (*zipfd == NULL) {
330
    kitten_puts(3, 8, "Error: Invalid zip archive! Package not installed.");
329
    kitten_puts(3, 8, "Error: Invalid zip archive! Package not installed.");
331
    return(NULL);
330
    return(NULL);
332
  }
331
  }
333
  ziplinkedlist = zip_listfiles(*zipfd);
332
  ziplinkedlist = zip_listfiles(*zipfd);
334
  if (ziplinkedlist == NULL) {
333
  if (ziplinkedlist == NULL) {
335
    kitten_puts(3, 8, "Error: Invalid zip archive! Package not installed.");
334
    kitten_puts(3, 8, "Error: Invalid zip archive! Package not installed.");
336
    fclose(*zipfd);
335
    fclose(*zipfd);
337
    return(NULL);
336
    return(NULL);
338
  }
337
  }
339
  /* if updating, load the list of files belonging to the current package */
338
  /* if updating, load the list of files belonging to the current package */
340
  if ((flags & PKGINST_UPDATE) != 0) {
339
  if ((flags & PKGINST_UPDATE) != 0) {
341
    flist = pkg_loadflist(pkgname, dosdir);
340
    flist = pkg_loadflist(pkgname, dosdir);
342
  } else {
341
  } else {
343
    flist = NULL;
342
    flist = NULL;
344
  }
343
  }
345
  /* Verify that there's no collision with existing local files, look for the appinfo presence, get rid of sources if required, and rename BAT links into COM files */
344
  /* Verify that there's no collision with existing local files, look for the appinfo presence, get rid of sources if required, and rename BAT links into COM files */
346
  appinfopresence = 0;
345
  appinfopresence = 0;
347
  prevzipnode = NULL;
346
  prevzipnode = NULL;
348
  for (curzipnode = ziplinkedlist; curzipnode != NULL;) {
347
  for (curzipnode = ziplinkedlist; curzipnode != NULL;) {
349
    /* change all slashes to backslashes, and switch into all-lowercase */
348
    /* change all slashes to backslashes, and switch into all-lowercase */
350
    slash2backslash(curzipnode->filename);
349
    slash2backslash(curzipnode->filename);
351
    strtolower(curzipnode->filename);
350
    strtolower(curzipnode->filename);
352
    /* remove 'directory' ZIP entries to avoid false alerts about directory already existing */
351
    /* remove 'directory' ZIP entries to avoid false alerts about directory already existing */
353
    if ((curzipnode->flags & ZIP_FLAG_ISADIR) != 0) {
352
    if ((curzipnode->flags & ZIP_FLAG_ISADIR) != 0) {
354
      curzipnode->filename[0] = 0; /* mark it "empty", will be removed in a short moment */
353
      curzipnode->filename[0] = 0; /* mark it "empty", will be removed in a short moment */
355
    }
354
    }
356
    /* if --nosource specified, skip sources */
355
    /* if --nosource specified, skip sources */
357
    if ((flags & PKGINST_NOSOURCE) != 0) {
356
    if ((flags & PKGINST_NOSOURCE) != 0) {
358
      if (fdnpkg_strcasestr(curzipnode->filename, "source\\") == curzipnode->filename) { /* drop this file */
357
      if (fdnpkg_strcasestr(curzipnode->filename, "source\\") == curzipnode->filename) { /* drop this file */
359
        curzipnode->filename[0] = 0; /* in fact, we just mark the file as 'empty' on the filename.. see below */
358
        curzipnode->filename[0] = 0; /* in fact, we just mark the file as 'empty' on the filename.. see below */
360
      }
359
      }
361
    }
360
    }
362
    /* is it a "link file"? */
361
    /* is it a "link file"? */
363
    if (fdnpkg_strcasestr(curzipnode->filename, "links\\") == curzipnode->filename) {
362
    if (fdnpkg_strcasestr(curzipnode->filename, "links\\") == curzipnode->filename) {
364
      /* skip links, if that's what the user wants */
363
      /* skip links, if that's what the user wants */
365
      if ((flags & PKGINST_SKIPLINKS) != 0) {
364
      if ((flags & PKGINST_SKIPLINKS) != 0) {
366
        curzipnode->filename[0] = 0; /* in fact, we just mark the file as 'empty' on the filename.. see later below */
365
        curzipnode->filename[0] = 0; /* in fact, we just mark the file as 'empty' on the filename.. see later below */
367
      } else {
366
      } else {
368
        /* if it's a *.BAT link, then rename it to *.COM */
367
        /* if it's a *.BAT link, then rename it to *.COM */
369
        char *ext = getfext(curzipnode->filename);
368
        char *ext = getfext(curzipnode->filename);
370
        if (strcasecmp(ext, "bat") == 0) sprintf(ext, "com");
369
        if (strcasecmp(ext, "bat") == 0) sprintf(ext, "com");
371
      }
370
      }
372
    }
371
    }
373
 
372
 
374
    if (curzipnode->filename[0] == 0) { /* ignore empty filenames (maybe it was empty originally, or has been emptied because it's a dropped source or link) */
373
    if (curzipnode->filename[0] == 0) { /* ignore empty filenames (maybe it was empty originally, or has been emptied because it's a dropped source or link) */
375
      if (prevzipnode == NULL) {  /* take the item out of the list */
374
      if (prevzipnode == NULL) {  /* take the item out of the list */
376
        ziplinkedlist = curzipnode->nextfile;
375
        ziplinkedlist = curzipnode->nextfile;
377
        free(curzipnode); /* free the item */
376
        free(curzipnode); /* free the item */
378
        curzipnode = ziplinkedlist;
377
        curzipnode = ziplinkedlist;
379
      } else {
378
      } else {
380
        prevzipnode->nextfile = curzipnode->nextfile;
379
        prevzipnode->nextfile = curzipnode->nextfile;
381
        free(curzipnode); /* free the item */
380
        free(curzipnode); /* free the item */
382
        curzipnode = prevzipnode->nextfile;
381
        curzipnode = prevzipnode->nextfile;
383
      }
382
      }
384
      continue; /* go to the next item */
383
      continue; /* go to the next item */
385
    }
384
    }
386
    /* validate that the file has a valid filename (8+3, no shady chars...) */
385
    /* validate that the file has a valid filename (8+3, no shady chars...) */
387
    if (validfilename(curzipnode->filename) != 0) {
386
    if (validfilename(curzipnode->filename) != 0) {
388
      kitten_puts(3, 23, "Error: Package contains an invalid filename:");
387
      kitten_puts(3, 23, "Error: Package contains an invalid filename:");
389
      printf(" %s\n", curzipnode->filename);
388
      printf(" %s\n", curzipnode->filename);
390
      zip_freelist(&ziplinkedlist);
389
      zip_freelist(&ziplinkedlist);
391
      fclose(*zipfd);
390
      fclose(*zipfd);
392
      return(NULL);
391
      return(NULL);
393
    }
392
    }
394
    /* look out for collisions with already existing files (unless we are
393
    /* look out for collisions with already existing files (unless we are
395
     * updating the package and the local file belongs to it */
394
     * updating the package and the local file belongs to it */
396
    shortfile = computelocalpath(curzipnode->filename, fname, dosdir, dirlist);
395
    shortfile = computelocalpath(curzipnode->filename, fname, dosdir, dirlist);
397
    mapdrives(fname, mapdrv);
396
    mapdrives(fname, mapdrv);
398
    strcat(fname, shortfile);
397
    strcat(fname, shortfile);
399
    if ((findfileinlist(flist, fname) == NULL) && (fileexists(fname) != 0)) {
398
    if ((findfileinlist(flist, fname) == NULL) && (fileexists(fname) != 0)) {
400
      kitten_puts(3, 9, "Error: Package contains a file that already exists locally:");
399
      kitten_puts(3, 9, "Error: Package contains a file that already exists locally:");
401
      printf(" %s\n", fname);
400
      printf(" %s\n", fname);
402
      zip_freelist(&ziplinkedlist);
401
      zip_freelist(&ziplinkedlist);
403
      fclose(*zipfd);
402
      fclose(*zipfd);
404
      return(NULL);
403
      return(NULL);
405
    }
404
    }
406
    /* abort if any entry is encrypted */
405
    /* abort if any entry is encrypted */
407
    if ((curzipnode->flags & ZIP_FLAG_ENCRYPTED) != 0) {
406
    if ((curzipnode->flags & ZIP_FLAG_ENCRYPTED) != 0) {
408
      kitten_printf(3, 20, "Error: Package contains an encrypted file:");
407
      kitten_printf(3, 20, "Error: Package contains an encrypted file:");
409
      puts("");
408
      puts("");
410
      printf(" %s\n", curzipnode->filename);
409
      printf(" %s\n", curzipnode->filename);
411
      zip_freelist(&ziplinkedlist);
410
      zip_freelist(&ziplinkedlist);
412
      fclose(*zipfd);
411
      fclose(*zipfd);
413
      return(NULL);
412
      return(NULL);
414
    }
413
    }
415
    /* abort if any file is compressed with an unsupported method */
414
    /* abort if any file is compressed with an unsupported method */
416
    if ((curzipnode->compmethod != 0/*store*/) && (curzipnode->compmethod != 8/*deflate*/) && (curzipnode->compmethod != 14/*lzma*/)) { /* unsupported compression method */
415
    if ((curzipnode->compmethod != 0/*store*/) && (curzipnode->compmethod != 8/*deflate*/) && (curzipnode->compmethod != 14/*lzma*/)) { /* unsupported compression method */
417
      kitten_printf(8, 2, "Error: Package contains a file compressed with an unsupported method (%d):", curzipnode->compmethod);
416
      kitten_printf(8, 2, "Error: Package contains a file compressed with an unsupported method (%d):", curzipnode->compmethod);
418
      puts("");
417
      puts("");
419
      printf(" %s\n", curzipnode->filename);
418
      printf(" %s\n", curzipnode->filename);
420
      zip_freelist(&ziplinkedlist);
419
      zip_freelist(&ziplinkedlist);
421
      fclose(*zipfd);
420
      fclose(*zipfd);
422
      return(NULL);
421
      return(NULL);
423
    }
422
    }
424
    if (strcmp(curzipnode->filename, appinfofile) == 0) appinfopresence = 1;
423
    if (strcmp(curzipnode->filename, appinfofile) == 0) appinfopresence = 1;
425
    prevzipnode = curzipnode;
424
    prevzipnode = curzipnode;
426
    curzipnode = curzipnode->nextfile;
425
    curzipnode = curzipnode->nextfile;
427
  }
426
  }
428
  /* if appinfo file not found, this is not a real FreeDOS package */
427
  /* if appinfo file not found, this is not a real FreeDOS package */
429
  if (appinfopresence != 1) {
428
  if (appinfopresence != 1) {
430
    kitten_printf(3, 12, "Error: Package do not contain the %s file! Not a valid FreeDOS package.", appinfofile);
429
    kitten_printf(3, 12, "Error: Package do not contain the %s file! Not a valid FreeDOS package.", appinfofile);
431
    puts("");
430
    puts("");
432
    zip_freelist(&ziplinkedlist);
431
    zip_freelist(&ziplinkedlist);
433
    fclose(*zipfd);
432
    fclose(*zipfd);
434
    return(NULL);
433
    return(NULL);
435
  }
434
  }
436
 
435
 
437
  return(ziplinkedlist);
436
  return(ziplinkedlist);
438
}
437
}
439
 
438
 
440
 
439
 
441
/* install a package that has been prepared already. returns 0 on success,
440
/* install a package that has been prepared already. returns 0 on success,
442
 * or a negative value on error, or a positive value on warning */
441
 * or a negative value on error, or a positive value on warning */
443
int pkginstall_installpackage(char *pkgname, char *dosdir, struct customdirs *dirlist, struct ziplist *ziplinkedlist, FILE *zipfd, char *mapdrv) {
442
int pkginstall_installpackage(char *pkgname, char *dosdir, struct customdirs *dirlist, struct ziplist *ziplinkedlist, FILE *zipfd, char *mapdrv) {
444
  char *buff;
443
  char *buff;
445
  char *fulldestfilename;
444
  char *fulldestfilename;
446
  char packageslst[64];
445
  char packageslst[64];
447
  char *shortfile;
446
  char *shortfile;
448
  long filesextractedsuccess = 0, filesextractedfailure = 0;
447
  long filesextractedsuccess = 0, filesextractedfailure = 0;
449
  struct ziplist *curzipnode;
448
  struct ziplist *curzipnode;
450
  FILE *lstfd;
449
  FILE *lstfd;
451
 
450
 
452
  sprintf(packageslst, "packages\\%s.lst", pkgname); /* Prepare the packages/xxxx.lst filename string for later use */
451
  sprintf(packageslst, "packages\\%s.lst", pkgname); /* Prepare the packages/xxxx.lst filename string for later use */
453
 
452
 
454
  buff = malloc(512);
453
  buff = malloc(512);
455
  fulldestfilename = malloc(1024);
454
  fulldestfilename = malloc(1024);
456
  if ((buff == NULL) || (fulldestfilename == NULL)) {
455
  if ((buff == NULL) || (fulldestfilename == NULL)) {
457
    kitten_puts(8, 0, "Out of memory!");
456
    kitten_puts(8, 0, "Out of memory!");
458
    zip_freelist(&ziplinkedlist);
457
    zip_freelist(&ziplinkedlist);
459
    free(buff);
458
    free(buff);
460
    free(fulldestfilename);
459
    free(fulldestfilename);
461
    return(-1);
460
    return(-1);
462
  }
461
  }
463
 
462
 
464
  /* create the %DOSDIR%/packages directory, just in case it doesn't exist yet */
463
  /* create the %DOSDIR%/packages directory, just in case it doesn't exist yet */
465
  sprintf(buff, "%s\\packages\\", dosdir);
464
  sprintf(buff, "%s\\packages\\", dosdir);
466
  mkpath(buff);
465
  mkpath(buff);
467
 
466
 
468
  /* open the lst file */
467
  /* open the lst file */
469
  sprintf(buff, "%s\\%s", dosdir, packageslst);
468
  sprintf(buff, "%s\\%s", dosdir, packageslst);
470
  mapdrives(buff, mapdrv);
469
  mapdrives(buff, mapdrv);
471
  lstfd = fopen(buff, "wb"); /* opening it in binary mode, because I like to have control over line terminators (CR/LF) */
470
  lstfd = fopen(buff, "wb"); /* opening it in binary mode, because I like to have control over line terminators (CR/LF) */
472
  if (lstfd == NULL) {
471
  if (lstfd == NULL) {
473
    kitten_printf(3, 10, "Error: Could not create %s!", buff);
472
    kitten_printf(3, 10, "Error: Could not create %s!", buff);
474
    puts("");
473
    puts("");
475
    zip_freelist(&ziplinkedlist);
474
    zip_freelist(&ziplinkedlist);
476
    free(buff);
475
    free(buff);
477
    free(fulldestfilename);
476
    free(fulldestfilename);
478
    return(-2);
477
    return(-2);
479
  }
478
  }
480
 
479
 
481
  /* write list of files in zip into the lst, and create the directories structure */
480
  /* write list of files in zip into the lst, and create the directories structure */
482
  for (curzipnode = ziplinkedlist; curzipnode != NULL; curzipnode = curzipnode->nextfile) {
481
  for (curzipnode = ziplinkedlist; curzipnode != NULL; curzipnode = curzipnode->nextfile) {
483
    int unzip_result;
482
    int unzip_result;
484
    if ((curzipnode->flags & ZIP_FLAG_ISADIR) != 0) continue; /* skip directories */
483
    if ((curzipnode->flags & ZIP_FLAG_ISADIR) != 0) continue; /* skip directories */
485
    if (strcasecmp(curzipnode->filename, packageslst) == 0) continue; /* skip silently the package.lst file, if found */
484
    if (strcasecmp(curzipnode->filename, packageslst) == 0) continue; /* skip silently the package.lst file, if found */
486
    shortfile = computelocalpath(curzipnode->filename, buff, dosdir, dirlist); /* substitute paths to custom dirs */
485
    shortfile = computelocalpath(curzipnode->filename, buff, dosdir, dirlist); /* substitute paths to custom dirs */
487
    /* log the filename to packages\pkg.lst (with original, unmapped drive) */
486
    /* log the filename to packages\pkg.lst (with original, unmapped drive) */
488
    fprintf(lstfd, "%s%s\r\n", buff, shortfile);
487
    fprintf(lstfd, "%s%s\r\n", buff, shortfile);
489
    /* remap drive letter, if needed (AFTER writing to lstfd) */
488
    /* remap drive letter, if needed (AFTER writing to lstfd) */
490
    mapdrives(buff, mapdrv);
489
    mapdrives(buff, mapdrv);
491
    /* create the path, just in case it doesn't exist yet */
490
    /* create the path, just in case it doesn't exist yet */
492
    mkpath(buff);
491
    mkpath(buff);
493
    sprintf(fulldestfilename, "%s%s", buff, shortfile);
492
    sprintf(fulldestfilename, "%s%s", buff, shortfile);
494
    /* Now unzip the file */
493
    /* Now unzip the file */
495
    unzip_result = zip_unzip(zipfd, curzipnode, fulldestfilename);
494
    unzip_result = zip_unzip(zipfd, curzipnode, fulldestfilename);
496
    if (unzip_result != 0) {
495
    if (unzip_result != 0) {
497
      kitten_printf(8, 3, "Error while extracting '%s' to '%s'!", curzipnode->filename, fulldestfilename);
496
      kitten_printf(8, 3, "Error while extracting '%s' to '%s'!", curzipnode->filename, fulldestfilename);
498
      printf(" [%d]\n", unzip_result);
497
      printf(" [%d]\n", unzip_result);
499
      filesextractedfailure += 1;
498
      filesextractedfailure += 1;
500
    } else {
499
    } else {
501
      printf(" %s -> %s\n", curzipnode->filename, buff);
500
      printf(" %s -> %s\n", curzipnode->filename, buff);
502
      filesextractedsuccess += 1;
501
      filesextractedsuccess += 1;
503
    }
502
    }
504
    /* if it's a LINK file, recompute a new content */
503
    /* if it's a LINK file, recompute a new content */
505
    if (islinkfile(curzipnode->filename) != 0) {
504
    if (islinkfile(curzipnode->filename) != 0) {
506
      unmapdrives(buff, mapdrv);
505
      unmapdrives(buff, mapdrv);
507
      processlinkfile(fulldestfilename, dosdir, dirlist, buff);
506
      processlinkfile(fulldestfilename, dosdir, dirlist, buff);
508
    }
507
    }
509
  }
508
  }
510
  fclose(lstfd);
509
  fclose(lstfd);
511
 
510
 
512
  /* free the ziplist and close file descriptor */
511
  /* free the ziplist and close file descriptor */
513
  zip_freelist(&ziplinkedlist);
512
  zip_freelist(&ziplinkedlist);
514
  free(buff);
513
  free(buff);
515
  free(fulldestfilename);
514
  free(fulldestfilename);
516
 
515
 
517
  kitten_printf(3, 19, "Package %s installed: %ld files extracted, %ld errors.", pkgname, filesextractedsuccess, filesextractedfailure);
516
  kitten_printf(3, 19, "Package %s installed: %ld files extracted, %ld errors.", pkgname, filesextractedsuccess, filesextractedfailure);
518
  puts("");
517
  puts("");
519
  return(filesextractedfailure);
518
  return(filesextractedfailure);
520
}
519
}
521
 
520