aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archival/dpkg.c122
-rw-r--r--dpkg.c122
2 files changed, 102 insertions, 142 deletions
diff --git a/archival/dpkg.c b/archival/dpkg.c
index e8c5557fa..eab2ace92 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -8,6 +8,7 @@
8#include <utime.h> 8#include <utime.h>
9#include <sys/types.h> 9#include <sys/types.h>
10#include <sys/stat.h> 10#include <sys/stat.h>
11
11#include "busybox.h" 12#include "busybox.h"
12 13
13//#define PACKAGE "udpkg" 14//#define PACKAGE "udpkg"
@@ -24,19 +25,16 @@
24#define DODEBUG 0 25#define DODEBUG 0
25 26
26#ifdef DODEBUG 27#ifdef DODEBUG
27#include <assert.h>
28#define ASSERT(x) assert(x)
29#define SYSTEM(x) do_system(x) 28#define SYSTEM(x) do_system(x)
30#define DPRINTF(fmt,args...) fprintf(stderr, fmt, ##args) 29#define DPRINTF(fmt,args...) fprintf(stderr, fmt, ##args)
31#else 30#else
32#define ASSERT(x) /* nothing */
33#define SYSTEM(x) system(x) 31#define SYSTEM(x) system(x)
34#define DPRINTF(fmt,args...) /* nothing */ 32#define DPRINTF(fmt,args...) /* nothing */
35#endif 33#endif
36 34
37#define BUFSIZE 4096 35#define BUFSIZE 4096
38#define ADMINDIR "/var/lib/dpkg" 36#define ADMINDIR "/var/lib/dpkg"
39#define STATUSFILE ADMINDIR ## "/status" 37#define STATUSFILE ADMINDIR ## "/status.udeb"
40#define DPKGCIDIR ADMINDIR ## "/tmp.ci/" 38#define DPKGCIDIR ADMINDIR ## "/tmp.ci/"
41#define INFODIR ADMINDIR ## "/info/" 39#define INFODIR ADMINDIR ## "/info/"
42#define UDPKG_QUIET "UDPKG_QUIET" 40#define UDPKG_QUIET "UDPKG_QUIET"
@@ -81,7 +79,7 @@ const int color_grey = 1;
81const int color_black = 2; 79const int color_black = 2;
82 80
83/* data structures */ 81/* data structures */
84struct package_t { 82typedef struct package_s {
85 char *file; 83 char *file;
86 char *package; 84 char *package;
87 char *version; 85 char *version;
@@ -91,17 +89,16 @@ struct package_t {
91 int installer_menu_item; 89 int installer_menu_item;
92 unsigned long status; 90 unsigned long status;
93 char color; /* for topo-sort */ 91 char color; /* for topo-sort */
94 struct package_t *requiredfor[DEPENDSMAX]; 92 struct package_s *requiredfor[DEPENDSMAX];
95 unsigned short requiredcount; 93 unsigned short requiredcount;
96 struct package_t *next; 94 struct package_s *next;
97}; 95} package_t;
98 96
99/* function prototypes */ 97static int package_compare(const void *p1, const void *p2)
100void *status_read(void); 98{
101void control_read(FILE *f, struct package_t *p); 99 return strcmp(((package_t *)p1)->package,
102int status_merge(void *status, struct package_t *pkgs); 100 ((package_t *)p2)->package);
103int package_compare(const void *p1, const void *p2); 101}
104struct package_t *depends_resolve(struct package_t *pkgs, void *status);
105 102
106#ifdef DODEPENDS 103#ifdef DODEPENDS
107#include <ctype.h> 104#include <ctype.h>
@@ -139,8 +136,8 @@ static char **depends_split(const char *dependsstr)
139 return dependsvec; 136 return dependsvec;
140} 137}
141 138
142static void depends_sort_visit(struct package_t **ordered, 139static void depends_sort_visit(package_t **ordered, package_t *pkgs,
143 struct package_t *pkgs, struct package_t *pkg) 140 package_t *pkg)
144{ 141{
145 /* Topological sort algorithm: 142 /* Topological sort algorithm:
146 * ordered is the output list, pkgs is the dependency graph, pkg is 143 * ordered is the output list, pkgs is the dependency graph, pkg is
@@ -177,12 +174,12 @@ static void depends_sort_visit(struct package_t **ordered,
177 pkg->color = color_black; 174 pkg->color = color_black;
178} 175}
179 176
180static struct package_t *depends_sort(struct package_t *pkgs) 177static package_t *depends_sort(package_t *pkgs)
181{ 178{
182 /* TODO: it needs to break cycles in the to-be-installed package 179 /* TODO: it needs to break cycles in the to-be-installed package
183 * graph... */ 180 * graph... */
184 struct package_t *ordered = NULL; 181 package_t *ordered = NULL;
185 struct package_t *pkg; 182 package_t *pkg;
186 183
187 for (pkg = pkgs; pkg != 0; pkg = pkg->next) 184 for (pkg = pkgs; pkg != 0; pkg = pkg->next)
188 pkg->color = color_white; 185 pkg->color = color_white;
@@ -207,10 +204,10 @@ static struct package_t *depends_sort(struct package_t *pkgs)
207 * efficient algorithm, but given that at any one time you are unlikely 204 * efficient algorithm, but given that at any one time you are unlikely
208 * to install a very large number of packages it doesn't really matter 205 * to install a very large number of packages it doesn't really matter
209 */ 206 */
210struct package_t *depends_resolve(struct package_t *pkgs, void *status) 207static package_t *depends_resolve(package_t *pkgs, void *status)
211{ 208{
212 struct package_t *pkg, *chk; 209 package_t *pkg, *chk;
213 struct package_t dependpkg; 210 package_t dependpkg;
214 char **dependsvec; 211 char **dependsvec;
215 int i; 212 int i;
216 void *found; 213 void *found;
@@ -224,7 +221,7 @@ struct package_t *depends_resolve(struct package_t *pkgs, void *status)
224 /* Check for dependencies; first look for installed packages */ 221 /* Check for dependencies; first look for installed packages */
225 dependpkg.package = dependsvec[i]; 222 dependpkg.package = dependsvec[i];
226 if ((found = tfind(&dependpkg, &status, package_compare)) == 0 || 223 if ((found = tfind(&dependpkg, &status, package_compare)) == 0 ||
227 ((chk = *(struct package_t **)found) && 224 ((chk = *(package_t **)found) &&
228 (chk->status & (status_flagok | status_statusinstalled)) != 225 (chk->status & (status_flagok | status_statusinstalled)) !=
229 (status_flagok | status_statusinstalled))) 226 (status_flagok | status_statusinstalled)))
230 { 227 {
@@ -276,12 +273,6 @@ struct package_t *depends_resolve(struct package_t *pkgs, void *status)
276 * read using the status_read function is written back to the status file 273 * read using the status_read function is written back to the status file
277 */ 274 */
278 275
279int package_compare(const void *p1, const void *p2)
280{
281 return strcmp(((struct package_t *)p1)->package,
282 ((struct package_t *)p2)->package);
283}
284
285static unsigned long status_parse(const char *line) 276static unsigned long status_parse(const char *line)
286{ 277{
287 char *p; 278 char *p;
@@ -340,7 +331,7 @@ static const char *status_print(unsigned long flags)
340 * Read a control file (or a stanza of a status file) and parse it, 331 * Read a control file (or a stanza of a status file) and parse it,
341 * filling parsed fields into the package structure 332 * filling parsed fields into the package structure
342 */ 333 */
343void control_read(FILE *f, struct package_t *p) 334static void control_read(FILE *f, package_t *p)
344{ 335{
345 char buf[BUFSIZE]; 336 char buf[BUFSIZE];
346 while (fgets(buf, BUFSIZE, f) && !feof(f)) 337 while (fgets(buf, BUFSIZE, f) && !feof(f))
@@ -377,11 +368,11 @@ void control_read(FILE *f, struct package_t *p)
377 } 368 }
378} 369}
379 370
380void *status_read(void) 371static void *status_read(void)
381{ 372{
382 FILE *f; 373 FILE *f;
383 void *status = 0; 374 void *status = 0;
384 struct package_t *m = 0, *p = 0, *t = 0; 375 package_t *m = 0, *p = 0, *t = 0;
385 376
386 if ((f = fopen(STATUSFILE, "r")) == NULL) 377 if ((f = fopen(STATUSFILE, "r")) == NULL)
387 { 378 {
@@ -392,8 +383,8 @@ void *status_read(void)
392 printf("(Reading database...)\n"); 383 printf("(Reading database...)\n");
393 while (!feof(f)) 384 while (!feof(f))
394 { 385 {
395 m = (struct package_t *)malloc(sizeof(struct package_t)); 386 m = (package_t *)malloc(sizeof(package_t));
396 memset(m, 0, sizeof(struct package_t)); 387 memset(m, 0, sizeof(package_t));
397 control_read(f, m); 388 control_read(f, m);
398 if (m->package) 389 if (m->package)
399 { 390 {
@@ -411,11 +402,11 @@ void *status_read(void)
411 * of a pseudo package into the status 402 * of a pseudo package into the status
412 * binary-tree. 403 * binary-tree.
413 */ 404 */
414 p = (struct package_t *)malloc(sizeof(struct package_t)); 405 p = (package_t *)malloc(sizeof(package_t));
415 memset(p, 0, sizeof(struct package_t)); 406 memset(p, 0, sizeof(package_t));
416 p->package = strdup(m->provides); 407 p->package = strdup(m->provides);
417 408
418 t = *(struct package_t **)tsearch(p, &status, package_compare); 409 t = *(package_t **)tsearch(p, &status, package_compare);
419 if (!(t == p)) 410 if (!(t == p))
420 { 411 {
421 free(p->package); 412 free(p->package);
@@ -443,12 +434,12 @@ void *status_read(void)
443 return status; 434 return status;
444} 435}
445 436
446int status_merge(void *status, struct package_t *pkgs) 437static int status_merge(void *status, package_t *pkgs)
447{ 438{
448 FILE *fin, *fout; 439 FILE *fin, *fout;
449 char buf[BUFSIZE]; 440 char buf[BUFSIZE];
450 struct package_t *pkg = 0, *statpkg = 0; 441 package_t *pkg = 0, *statpkg = 0;
451 struct package_t locpkg; 442 package_t locpkg;
452 int r = 0; 443 int r = 0;
453 444
454 if ((fin = fopen(STATUSFILE, "r")) == NULL) 445 if ((fin = fopen(STATUSFILE, "r")) == NULL)
@@ -475,8 +466,8 @@ int status_merge(void *status, struct package_t *pkgs)
475 */ 466 */
476 if (strstr(buf, "Package: ") == buf) 467 if (strstr(buf, "Package: ") == buf)
477 { 468 {
478 for (pkg = pkgs; pkg != 0 && strncmp(buf+9, 469 for (pkg = pkgs; pkg != 0 && strncmp(buf + 9,
479 pkg->package, strlen(pkg->package))!=0; 470 pkg->package, strlen(buf) - 9)!=0;
480 pkg = pkg->next) ; 471 pkg = pkg->next) ;
481 472
482 locpkg.package = buf+9; 473 locpkg.package = buf+9;
@@ -486,7 +477,7 @@ int status_merge(void *status, struct package_t *pkgs)
486 * file was changed while we are processing (no locking 477 * file was changed while we are processing (no locking
487 * is currently done... 478 * is currently done...
488 */ 479 */
489 if (statpkg != 0) statpkg = *(struct package_t **)statpkg; 480 if (statpkg != 0) statpkg = *(package_t **)statpkg;
490 } 481 }
491 if (pkg != 0) continue; 482 if (pkg != 0) continue;
492 483
@@ -522,17 +513,6 @@ int status_merge(void *status, struct package_t *pkgs)
522 return 0; 513 return 0;
523} 514}
524 515
525#include <errno.h>
526#include <fcntl.h>
527#include <search.h>
528#include <stdio.h>
529#include <stdlib.h>
530#include <string.h>
531#include <unistd.h>
532#include <utime.h>
533#include <sys/types.h>
534#include <sys/stat.h>
535
536/* 516/*
537 * Main udpkg implementation routines 517 * Main udpkg implementation routines
538 */ 518 */
@@ -587,7 +567,7 @@ static int dpkg_copyfile(const char *src, const char *dest)
587 return 1; 567 return 1;
588} 568}
589 569
590static int dpkg_doconfigure(struct package_t *pkg) 570static int dpkg_doconfigure(package_t *pkg)
591{ 571{
592 int r; 572 int r;
593 char postinst[1024]; 573 char postinst[1024];
@@ -611,7 +591,7 @@ static int dpkg_doconfigure(struct package_t *pkg)
611 return 0; 591 return 0;
612} 592}
613 593
614static int dpkg_dounpack(struct package_t *pkg) 594static int dpkg_dounpack(package_t *pkg)
615{ 595{
616 int r = 0; 596 int r = 0;
617 char *cwd, *p; 597 char *cwd, *p;
@@ -701,13 +681,13 @@ static int dpkg_dounpack(struct package_t *pkg)
701 return r; 681 return r;
702} 682}
703 683
704static int dpkg_doinstall(struct package_t *pkg) 684static int dpkg_doinstall(package_t *pkg)
705{ 685{
706 DPRINTF("Installing %s\n", pkg->package); 686 DPRINTF("Installing %s\n", pkg->package);
707 return (dpkg_dounpack(pkg) || dpkg_doconfigure(pkg)); 687 return (dpkg_dounpack(pkg) || dpkg_doconfigure(pkg));
708} 688}
709 689
710static int dpkg_unpackcontrol(struct package_t *pkg) 690static int dpkg_unpackcontrol(package_t *pkg)
711{ 691{
712 int r = 1; 692 int r = 1;
713 char *cwd = 0; 693 char *cwd = 0;
@@ -742,10 +722,10 @@ static int dpkg_unpackcontrol(struct package_t *pkg)
742 return r; 722 return r;
743} 723}
744 724
745static int dpkg_unpack(struct package_t *pkgs) 725static int dpkg_unpack(package_t *pkgs)
746{ 726{
747 int r = 0; 727 int r = 0;
748 struct package_t *pkg; 728 package_t *pkg;
749 void *status = status_read(); 729 void *status = status_read();
750 730
751 if (SYSTEM("rm -rf -- " DPKGCIDIR) != 0 || 731 if (SYSTEM("rm -rf -- " DPKGCIDIR) != 0 ||
@@ -766,11 +746,11 @@ static int dpkg_unpack(struct package_t *pkgs)
766 return r; 746 return r;
767} 747}
768 748
769static int dpkg_configure(struct package_t *pkgs) 749static int dpkg_configure(package_t *pkgs)
770{ 750{
771 int r = 0; 751 int r = 0;
772 void *found; 752 void *found;
773 struct package_t *pkg; 753 package_t *pkg;
774 void *status = status_read(); 754 void *status = status_read();
775 for (pkg = pkgs; pkg != 0 && r == 0; pkg = pkg->next) 755 for (pkg = pkgs; pkg != 0 && r == 0; pkg = pkg->next)
776 { 756 {
@@ -784,16 +764,16 @@ static int dpkg_configure(struct package_t *pkgs)
784 { 764 {
785 /* configure the package listed in the status file; 765 /* configure the package listed in the status file;
786 * not pkg, as we have info only for the latter */ 766 * not pkg, as we have info only for the latter */
787 r = dpkg_doconfigure(*(struct package_t **)found); 767 r = dpkg_doconfigure(*(package_t **)found);
788 } 768 }
789 } 769 }
790 status_merge(status, 0); 770 status_merge(status, 0);
791 return r; 771 return r;
792} 772}
793 773
794static int dpkg_install(struct package_t *pkgs) 774static int dpkg_install(package_t *pkgs)
795{ 775{
796 struct package_t *p, *ordered = 0; 776 package_t *p, *ordered = 0;
797 void *status = status_read(); 777 void *status = status_read();
798 if (SYSTEM("rm -rf -- " DPKGCIDIR) != 0 || 778 if (SYSTEM("rm -rf -- " DPKGCIDIR) != 0 ||
799 mkdir(DPKGCIDIR, S_IRWXU) != 0) 779 mkdir(DPKGCIDIR, S_IRWXU) != 0)
@@ -842,9 +822,9 @@ static int dpkg_install(struct package_t *pkgs)
842 return 0; 822 return 0;
843} 823}
844 824
845static int dpkg_remove(struct package_t *pkgs) 825static int dpkg_remove(package_t *pkgs)
846{ 826{
847 struct package_t *p; 827 package_t *p;
848 void *status = status_read(); 828 void *status = status_read();
849 for (p = pkgs; p != 0; p = p->next) 829 for (p = pkgs; p != 0; p = p->next)
850 { 830 {
@@ -853,11 +833,11 @@ static int dpkg_remove(struct package_t *pkgs)
853 return 0; 833 return 0;
854} 834}
855 835
856int dpkg_main(int argc, char **argv) 836extern int dpkg_main(int argc, char **argv)
857{ 837{
858 char opt = 0; 838 char opt = 0;
859 char *s; 839 char *s;
860 struct package_t *p, *packages = NULL; 840 package_t *p, *packages = NULL;
861 char *cwd = getcwd(0, 0); 841 char *cwd = getcwd(0, 0);
862 while (*++argv) 842 while (*++argv)
863 { 843 {
@@ -870,8 +850,8 @@ int dpkg_main(int argc, char **argv)
870 } 850 }
871 else 851 else
872 { 852 {
873 p = (struct package_t *)malloc(sizeof(struct package_t)); 853 p = (package_t *)malloc(sizeof(package_t));
874 memset(p, 0, sizeof(struct package_t)); 854 memset(p, 0, sizeof(package_t));
875 if (**argv == '/') 855 if (**argv == '/')
876 p->file = *argv; 856 p->file = *argv;
877 else if (opt != 'c') 857 else if (opt != 'c')
diff --git a/dpkg.c b/dpkg.c
index e8c5557fa..eab2ace92 100644
--- a/dpkg.c
+++ b/dpkg.c
@@ -8,6 +8,7 @@
8#include <utime.h> 8#include <utime.h>
9#include <sys/types.h> 9#include <sys/types.h>
10#include <sys/stat.h> 10#include <sys/stat.h>
11
11#include "busybox.h" 12#include "busybox.h"
12 13
13//#define PACKAGE "udpkg" 14//#define PACKAGE "udpkg"
@@ -24,19 +25,16 @@
24#define DODEBUG 0 25#define DODEBUG 0
25 26
26#ifdef DODEBUG 27#ifdef DODEBUG
27#include <assert.h>
28#define ASSERT(x) assert(x)
29#define SYSTEM(x) do_system(x) 28#define SYSTEM(x) do_system(x)
30#define DPRINTF(fmt,args...) fprintf(stderr, fmt, ##args) 29#define DPRINTF(fmt,args...) fprintf(stderr, fmt, ##args)
31#else 30#else
32#define ASSERT(x) /* nothing */
33#define SYSTEM(x) system(x) 31#define SYSTEM(x) system(x)
34#define DPRINTF(fmt,args...) /* nothing */ 32#define DPRINTF(fmt,args...) /* nothing */
35#endif 33#endif
36 34
37#define BUFSIZE 4096 35#define BUFSIZE 4096
38#define ADMINDIR "/var/lib/dpkg" 36#define ADMINDIR "/var/lib/dpkg"
39#define STATUSFILE ADMINDIR ## "/status" 37#define STATUSFILE ADMINDIR ## "/status.udeb"
40#define DPKGCIDIR ADMINDIR ## "/tmp.ci/" 38#define DPKGCIDIR ADMINDIR ## "/tmp.ci/"
41#define INFODIR ADMINDIR ## "/info/" 39#define INFODIR ADMINDIR ## "/info/"
42#define UDPKG_QUIET "UDPKG_QUIET" 40#define UDPKG_QUIET "UDPKG_QUIET"
@@ -81,7 +79,7 @@ const int color_grey = 1;
81const int color_black = 2; 79const int color_black = 2;
82 80
83/* data structures */ 81/* data structures */
84struct package_t { 82typedef struct package_s {
85 char *file; 83 char *file;
86 char *package; 84 char *package;
87 char *version; 85 char *version;
@@ -91,17 +89,16 @@ struct package_t {
91 int installer_menu_item; 89 int installer_menu_item;
92 unsigned long status; 90 unsigned long status;
93 char color; /* for topo-sort */ 91 char color; /* for topo-sort */
94 struct package_t *requiredfor[DEPENDSMAX]; 92 struct package_s *requiredfor[DEPENDSMAX];
95 unsigned short requiredcount; 93 unsigned short requiredcount;
96 struct package_t *next; 94 struct package_s *next;
97}; 95} package_t;
98 96
99/* function prototypes */ 97static int package_compare(const void *p1, const void *p2)
100void *status_read(void); 98{
101void control_read(FILE *f, struct package_t *p); 99 return strcmp(((package_t *)p1)->package,
102int status_merge(void *status, struct package_t *pkgs); 100 ((package_t *)p2)->package);
103int package_compare(const void *p1, const void *p2); 101}
104struct package_t *depends_resolve(struct package_t *pkgs, void *status);
105 102
106#ifdef DODEPENDS 103#ifdef DODEPENDS
107#include <ctype.h> 104#include <ctype.h>
@@ -139,8 +136,8 @@ static char **depends_split(const char *dependsstr)
139 return dependsvec; 136 return dependsvec;
140} 137}
141 138
142static void depends_sort_visit(struct package_t **ordered, 139static void depends_sort_visit(package_t **ordered, package_t *pkgs,
143 struct package_t *pkgs, struct package_t *pkg) 140 package_t *pkg)
144{ 141{
145 /* Topological sort algorithm: 142 /* Topological sort algorithm:
146 * ordered is the output list, pkgs is the dependency graph, pkg is 143 * ordered is the output list, pkgs is the dependency graph, pkg is
@@ -177,12 +174,12 @@ static void depends_sort_visit(struct package_t **ordered,
177 pkg->color = color_black; 174 pkg->color = color_black;
178} 175}
179 176
180static struct package_t *depends_sort(struct package_t *pkgs) 177static package_t *depends_sort(package_t *pkgs)
181{ 178{
182 /* TODO: it needs to break cycles in the to-be-installed package 179 /* TODO: it needs to break cycles in the to-be-installed package
183 * graph... */ 180 * graph... */
184 struct package_t *ordered = NULL; 181 package_t *ordered = NULL;
185 struct package_t *pkg; 182 package_t *pkg;
186 183
187 for (pkg = pkgs; pkg != 0; pkg = pkg->next) 184 for (pkg = pkgs; pkg != 0; pkg = pkg->next)
188 pkg->color = color_white; 185 pkg->color = color_white;
@@ -207,10 +204,10 @@ static struct package_t *depends_sort(struct package_t *pkgs)
207 * efficient algorithm, but given that at any one time you are unlikely 204 * efficient algorithm, but given that at any one time you are unlikely
208 * to install a very large number of packages it doesn't really matter 205 * to install a very large number of packages it doesn't really matter
209 */ 206 */
210struct package_t *depends_resolve(struct package_t *pkgs, void *status) 207static package_t *depends_resolve(package_t *pkgs, void *status)
211{ 208{
212 struct package_t *pkg, *chk; 209 package_t *pkg, *chk;
213 struct package_t dependpkg; 210 package_t dependpkg;
214 char **dependsvec; 211 char **dependsvec;
215 int i; 212 int i;
216 void *found; 213 void *found;
@@ -224,7 +221,7 @@ struct package_t *depends_resolve(struct package_t *pkgs, void *status)
224 /* Check for dependencies; first look for installed packages */ 221 /* Check for dependencies; first look for installed packages */
225 dependpkg.package = dependsvec[i]; 222 dependpkg.package = dependsvec[i];
226 if ((found = tfind(&dependpkg, &status, package_compare)) == 0 || 223 if ((found = tfind(&dependpkg, &status, package_compare)) == 0 ||
227 ((chk = *(struct package_t **)found) && 224 ((chk = *(package_t **)found) &&
228 (chk->status & (status_flagok | status_statusinstalled)) != 225 (chk->status & (status_flagok | status_statusinstalled)) !=
229 (status_flagok | status_statusinstalled))) 226 (status_flagok | status_statusinstalled)))
230 { 227 {
@@ -276,12 +273,6 @@ struct package_t *depends_resolve(struct package_t *pkgs, void *status)
276 * read using the status_read function is written back to the status file 273 * read using the status_read function is written back to the status file
277 */ 274 */
278 275
279int package_compare(const void *p1, const void *p2)
280{
281 return strcmp(((struct package_t *)p1)->package,
282 ((struct package_t *)p2)->package);
283}
284
285static unsigned long status_parse(const char *line) 276static unsigned long status_parse(const char *line)
286{ 277{
287 char *p; 278 char *p;
@@ -340,7 +331,7 @@ static const char *status_print(unsigned long flags)
340 * Read a control file (or a stanza of a status file) and parse it, 331 * Read a control file (or a stanza of a status file) and parse it,
341 * filling parsed fields into the package structure 332 * filling parsed fields into the package structure
342 */ 333 */
343void control_read(FILE *f, struct package_t *p) 334static void control_read(FILE *f, package_t *p)
344{ 335{
345 char buf[BUFSIZE]; 336 char buf[BUFSIZE];
346 while (fgets(buf, BUFSIZE, f) && !feof(f)) 337 while (fgets(buf, BUFSIZE, f) && !feof(f))
@@ -377,11 +368,11 @@ void control_read(FILE *f, struct package_t *p)
377 } 368 }
378} 369}
379 370
380void *status_read(void) 371static void *status_read(void)
381{ 372{
382 FILE *f; 373 FILE *f;
383 void *status = 0; 374 void *status = 0;
384 struct package_t *m = 0, *p = 0, *t = 0; 375 package_t *m = 0, *p = 0, *t = 0;
385 376
386 if ((f = fopen(STATUSFILE, "r")) == NULL) 377 if ((f = fopen(STATUSFILE, "r")) == NULL)
387 { 378 {
@@ -392,8 +383,8 @@ void *status_read(void)
392 printf("(Reading database...)\n"); 383 printf("(Reading database...)\n");
393 while (!feof(f)) 384 while (!feof(f))
394 { 385 {
395 m = (struct package_t *)malloc(sizeof(struct package_t)); 386 m = (package_t *)malloc(sizeof(package_t));
396 memset(m, 0, sizeof(struct package_t)); 387 memset(m, 0, sizeof(package_t));
397 control_read(f, m); 388 control_read(f, m);
398 if (m->package) 389 if (m->package)
399 { 390 {
@@ -411,11 +402,11 @@ void *status_read(void)
411 * of a pseudo package into the status 402 * of a pseudo package into the status
412 * binary-tree. 403 * binary-tree.
413 */ 404 */
414 p = (struct package_t *)malloc(sizeof(struct package_t)); 405 p = (package_t *)malloc(sizeof(package_t));
415 memset(p, 0, sizeof(struct package_t)); 406 memset(p, 0, sizeof(package_t));
416 p->package = strdup(m->provides); 407 p->package = strdup(m->provides);
417 408
418 t = *(struct package_t **)tsearch(p, &status, package_compare); 409 t = *(package_t **)tsearch(p, &status, package_compare);
419 if (!(t == p)) 410 if (!(t == p))
420 { 411 {
421 free(p->package); 412 free(p->package);
@@ -443,12 +434,12 @@ void *status_read(void)
443 return status; 434 return status;
444} 435}
445 436
446int status_merge(void *status, struct package_t *pkgs) 437static int status_merge(void *status, package_t *pkgs)
447{ 438{
448 FILE *fin, *fout; 439 FILE *fin, *fout;
449 char buf[BUFSIZE]; 440 char buf[BUFSIZE];
450 struct package_t *pkg = 0, *statpkg = 0; 441 package_t *pkg = 0, *statpkg = 0;
451 struct package_t locpkg; 442 package_t locpkg;
452 int r = 0; 443 int r = 0;
453 444
454 if ((fin = fopen(STATUSFILE, "r")) == NULL) 445 if ((fin = fopen(STATUSFILE, "r")) == NULL)
@@ -475,8 +466,8 @@ int status_merge(void *status, struct package_t *pkgs)
475 */ 466 */
476 if (strstr(buf, "Package: ") == buf) 467 if (strstr(buf, "Package: ") == buf)
477 { 468 {
478 for (pkg = pkgs; pkg != 0 && strncmp(buf+9, 469 for (pkg = pkgs; pkg != 0 && strncmp(buf + 9,
479 pkg->package, strlen(pkg->package))!=0; 470 pkg->package, strlen(buf) - 9)!=0;
480 pkg = pkg->next) ; 471 pkg = pkg->next) ;
481 472
482 locpkg.package = buf+9; 473 locpkg.package = buf+9;
@@ -486,7 +477,7 @@ int status_merge(void *status, struct package_t *pkgs)
486 * file was changed while we are processing (no locking 477 * file was changed while we are processing (no locking
487 * is currently done... 478 * is currently done...
488 */ 479 */
489 if (statpkg != 0) statpkg = *(struct package_t **)statpkg; 480 if (statpkg != 0) statpkg = *(package_t **)statpkg;
490 } 481 }
491 if (pkg != 0) continue; 482 if (pkg != 0) continue;
492 483
@@ -522,17 +513,6 @@ int status_merge(void *status, struct package_t *pkgs)
522 return 0; 513 return 0;
523} 514}
524 515
525#include <errno.h>
526#include <fcntl.h>
527#include <search.h>
528#include <stdio.h>
529#include <stdlib.h>
530#include <string.h>
531#include <unistd.h>
532#include <utime.h>
533#include <sys/types.h>
534#include <sys/stat.h>
535
536/* 516/*
537 * Main udpkg implementation routines 517 * Main udpkg implementation routines
538 */ 518 */
@@ -587,7 +567,7 @@ static int dpkg_copyfile(const char *src, const char *dest)
587 return 1; 567 return 1;
588} 568}
589 569
590static int dpkg_doconfigure(struct package_t *pkg) 570static int dpkg_doconfigure(package_t *pkg)
591{ 571{
592 int r; 572 int r;
593 char postinst[1024]; 573 char postinst[1024];
@@ -611,7 +591,7 @@ static int dpkg_doconfigure(struct package_t *pkg)
611 return 0; 591 return 0;
612} 592}
613 593
614static int dpkg_dounpack(struct package_t *pkg) 594static int dpkg_dounpack(package_t *pkg)
615{ 595{
616 int r = 0; 596 int r = 0;
617 char *cwd, *p; 597 char *cwd, *p;
@@ -701,13 +681,13 @@ static int dpkg_dounpack(struct package_t *pkg)
701 return r; 681 return r;
702} 682}
703 683
704static int dpkg_doinstall(struct package_t *pkg) 684static int dpkg_doinstall(package_t *pkg)
705{ 685{
706 DPRINTF("Installing %s\n", pkg->package); 686 DPRINTF("Installing %s\n", pkg->package);
707 return (dpkg_dounpack(pkg) || dpkg_doconfigure(pkg)); 687 return (dpkg_dounpack(pkg) || dpkg_doconfigure(pkg));
708} 688}
709 689
710static int dpkg_unpackcontrol(struct package_t *pkg) 690static int dpkg_unpackcontrol(package_t *pkg)
711{ 691{
712 int r = 1; 692 int r = 1;
713 char *cwd = 0; 693 char *cwd = 0;
@@ -742,10 +722,10 @@ static int dpkg_unpackcontrol(struct package_t *pkg)
742 return r; 722 return r;
743} 723}
744 724
745static int dpkg_unpack(struct package_t *pkgs) 725static int dpkg_unpack(package_t *pkgs)
746{ 726{
747 int r = 0; 727 int r = 0;
748 struct package_t *pkg; 728 package_t *pkg;
749 void *status = status_read(); 729 void *status = status_read();
750 730
751 if (SYSTEM("rm -rf -- " DPKGCIDIR) != 0 || 731 if (SYSTEM("rm -rf -- " DPKGCIDIR) != 0 ||
@@ -766,11 +746,11 @@ static int dpkg_unpack(struct package_t *pkgs)
766 return r; 746 return r;
767} 747}
768 748
769static int dpkg_configure(struct package_t *pkgs) 749static int dpkg_configure(package_t *pkgs)
770{ 750{
771 int r = 0; 751 int r = 0;
772 void *found; 752 void *found;
773 struct package_t *pkg; 753 package_t *pkg;
774 void *status = status_read(); 754 void *status = status_read();
775 for (pkg = pkgs; pkg != 0 && r == 0; pkg = pkg->next) 755 for (pkg = pkgs; pkg != 0 && r == 0; pkg = pkg->next)
776 { 756 {
@@ -784,16 +764,16 @@ static int dpkg_configure(struct package_t *pkgs)
784 { 764 {
785 /* configure the package listed in the status file; 765 /* configure the package listed in the status file;
786 * not pkg, as we have info only for the latter */ 766 * not pkg, as we have info only for the latter */
787 r = dpkg_doconfigure(*(struct package_t **)found); 767 r = dpkg_doconfigure(*(package_t **)found);
788 } 768 }
789 } 769 }
790 status_merge(status, 0); 770 status_merge(status, 0);
791 return r; 771 return r;
792} 772}
793 773
794static int dpkg_install(struct package_t *pkgs) 774static int dpkg_install(package_t *pkgs)
795{ 775{
796 struct package_t *p, *ordered = 0; 776 package_t *p, *ordered = 0;
797 void *status = status_read(); 777 void *status = status_read();
798 if (SYSTEM("rm -rf -- " DPKGCIDIR) != 0 || 778 if (SYSTEM("rm -rf -- " DPKGCIDIR) != 0 ||
799 mkdir(DPKGCIDIR, S_IRWXU) != 0) 779 mkdir(DPKGCIDIR, S_IRWXU) != 0)
@@ -842,9 +822,9 @@ static int dpkg_install(struct package_t *pkgs)
842 return 0; 822 return 0;
843} 823}
844 824
845static int dpkg_remove(struct package_t *pkgs) 825static int dpkg_remove(package_t *pkgs)
846{ 826{
847 struct package_t *p; 827 package_t *p;
848 void *status = status_read(); 828 void *status = status_read();
849 for (p = pkgs; p != 0; p = p->next) 829 for (p = pkgs; p != 0; p = p->next)
850 { 830 {
@@ -853,11 +833,11 @@ static int dpkg_remove(struct package_t *pkgs)
853 return 0; 833 return 0;
854} 834}
855 835
856int dpkg_main(int argc, char **argv) 836extern int dpkg_main(int argc, char **argv)
857{ 837{
858 char opt = 0; 838 char opt = 0;
859 char *s; 839 char *s;
860 struct package_t *p, *packages = NULL; 840 package_t *p, *packages = NULL;
861 char *cwd = getcwd(0, 0); 841 char *cwd = getcwd(0, 0);
862 while (*++argv) 842 while (*++argv)
863 { 843 {
@@ -870,8 +850,8 @@ int dpkg_main(int argc, char **argv)
870 } 850 }
871 else 851 else
872 { 852 {
873 p = (struct package_t *)malloc(sizeof(struct package_t)); 853 p = (package_t *)malloc(sizeof(package_t));
874 memset(p, 0, sizeof(struct package_t)); 854 memset(p, 0, sizeof(package_t));
875 if (**argv == '/') 855 if (**argv == '/')
876 p->file = *argv; 856 p->file = *argv;
877 else if (opt != 'c') 857 else if (opt != 'c')