aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2001-09-21 04:30:51 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2001-09-21 04:30:51 +0000
commite73866181f553067cae3411608f3cf1677d63a8b (patch)
tree10e6b46b81fcd28039f16c8b8ba2cf3956f56ad7
parent4c67c596d1aa3aafde0bc8182e9a5d54ee67a05f (diff)
downloadbusybox-w32-e73866181f553067cae3411608f3cf1677d63a8b.tar.gz
busybox-w32-e73866181f553067cae3411608f3cf1677d63a8b.tar.bz2
busybox-w32-e73866181f553067cae3411608f3cf1677d63a8b.zip
Implement dpkg -l option, from Stefan Soucek (slightly modified)
-rw-r--r--archival/dpkg.c57
-rw-r--r--dpkg.c57
2 files changed, 106 insertions, 8 deletions
diff --git a/archival/dpkg.c b/archival/dpkg.c
index d7279cfd0..e58052d8b 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -1127,6 +1127,48 @@ void all_control_list(char **remove_files, const char *package_name)
1127 remove_files[10] = NULL; 1127 remove_files[10] = NULL;
1128} 1128}
1129 1129
1130
1131/* This function lists information on the installed packages. It loops through
1132 * the status_hashtable to retrieve the info. This results in smaller code than
1133 * scanning the status file. The resulting list, however, is unsorted.
1134 */
1135void list_packages(void)
1136{
1137 int i;
1138
1139 printf(" Name Version\n");
1140 printf("+++-==============-==============\n");
1141
1142 /* go through status hash, dereference package hash and finally strings */
1143 for (i=0; i<STATUS_HASH_PRIME+1; i++) {
1144
1145 if (status_hashtable[i]) {
1146 const char *stat_str; /* status string */
1147 const char *name_str; /* package name */
1148 const char *vers_str; /* version */
1149 char s1, s2; /* status abbreviations */
1150 int spccnt; /* space count */
1151 int j;
1152
1153 stat_str = name_hashtable[status_hashtable[i]->status];
1154 name_str = name_hashtable[package_hashtable[status_hashtable[i]->package]->name];
1155 vers_str = name_hashtable[package_hashtable[status_hashtable[i]->package]->version];
1156
1157 /* get abbreviation for status field 1 */
1158 s1 = stat_str[0] == 'i' ? 'i' : 'r';
1159
1160 /* get abbreviation for status field 2 */
1161 for (j=0, spccnt=0; stat_str[j] && spccnt<2; j++) {
1162 if (stat_str[j] == ' ') spccnt++;
1163 }
1164 s2 = stat_str[j];
1165
1166 /* print out the line formatted like Debian dpkg */
1167 printf("%c%c %-14s %s\n", s1, s2, name_str, vers_str);
1168 }
1169 }
1170}
1171
1130void remove_package(const unsigned int package_num) 1172void remove_package(const unsigned int package_num)
1131{ 1173{
1132 const char *package_name = name_hashtable[package_hashtable[package_num]->name]; 1174 const char *package_name = name_hashtable[package_hashtable[package_num]->name];
@@ -1304,6 +1346,7 @@ extern int dpkg_main(int argc, char **argv)
1304 break; 1346 break;
1305 case 'l': 1347 case 'l':
1306 dpkg_opt |= dpkg_opt_list_installed; 1348 dpkg_opt |= dpkg_opt_list_installed;
1349 break;
1307 case 'P': 1350 case 'P':
1308 dpkg_opt |= dpkg_opt_purge; 1351 dpkg_opt |= dpkg_opt_purge;
1309 dpkg_opt |= dpkg_opt_package_name; 1352 dpkg_opt |= dpkg_opt_package_name;
@@ -1320,14 +1363,20 @@ extern int dpkg_main(int argc, char **argv)
1320 show_usage(); 1363 show_usage();
1321 } 1364 }
1322 } 1365 }
1323 1366 /* check for non-otion argument if expected */
1324 if ((argc == optind) || (dpkg_opt == 0)) { 1367 if ((dpkg_opt == 0) || ((argc == optind) && !(dpkg_opt && dpkg_opt_list_installed))) {
1325 show_usage(); 1368 show_usage();
1326 } 1369 }
1327 1370
1328 puts("(Reading database ... xxxxx files and directories installed.)"); 1371/* puts("(Reading database ... xxxxx files and directories installed.)"); */
1329 index_status_file("/var/lib/dpkg/status"); 1372 index_status_file("/var/lib/dpkg/status");
1330 1373
1374 /* if the list action was given print the installed packages and exit */
1375 if (dpkg_opt & dpkg_opt_list_installed) {
1376 list_packages();
1377 return(EXIT_SUCCESS);
1378 }
1379
1331 /* Read arguments and store relevant info in structs */ 1380 /* Read arguments and store relevant info in structs */
1332 deb_file = xmalloc(sizeof(deb_file_t)); 1381 deb_file = xmalloc(sizeof(deb_file_t));
1333 while (optind < argc) { 1382 while (optind < argc) {
diff --git a/dpkg.c b/dpkg.c
index d7279cfd0..e58052d8b 100644
--- a/dpkg.c
+++ b/dpkg.c
@@ -1127,6 +1127,48 @@ void all_control_list(char **remove_files, const char *package_name)
1127 remove_files[10] = NULL; 1127 remove_files[10] = NULL;
1128} 1128}
1129 1129
1130
1131/* This function lists information on the installed packages. It loops through
1132 * the status_hashtable to retrieve the info. This results in smaller code than
1133 * scanning the status file. The resulting list, however, is unsorted.
1134 */
1135void list_packages(void)
1136{
1137 int i;
1138
1139 printf(" Name Version\n");
1140 printf("+++-==============-==============\n");
1141
1142 /* go through status hash, dereference package hash and finally strings */
1143 for (i=0; i<STATUS_HASH_PRIME+1; i++) {
1144
1145 if (status_hashtable[i]) {
1146 const char *stat_str; /* status string */
1147 const char *name_str; /* package name */
1148 const char *vers_str; /* version */
1149 char s1, s2; /* status abbreviations */
1150 int spccnt; /* space count */
1151 int j;
1152
1153 stat_str = name_hashtable[status_hashtable[i]->status];
1154 name_str = name_hashtable[package_hashtable[status_hashtable[i]->package]->name];
1155 vers_str = name_hashtable[package_hashtable[status_hashtable[i]->package]->version];
1156
1157 /* get abbreviation for status field 1 */
1158 s1 = stat_str[0] == 'i' ? 'i' : 'r';
1159
1160 /* get abbreviation for status field 2 */
1161 for (j=0, spccnt=0; stat_str[j] && spccnt<2; j++) {
1162 if (stat_str[j] == ' ') spccnt++;
1163 }
1164 s2 = stat_str[j];
1165
1166 /* print out the line formatted like Debian dpkg */
1167 printf("%c%c %-14s %s\n", s1, s2, name_str, vers_str);
1168 }
1169 }
1170}
1171
1130void remove_package(const unsigned int package_num) 1172void remove_package(const unsigned int package_num)
1131{ 1173{
1132 const char *package_name = name_hashtable[package_hashtable[package_num]->name]; 1174 const char *package_name = name_hashtable[package_hashtable[package_num]->name];
@@ -1304,6 +1346,7 @@ extern int dpkg_main(int argc, char **argv)
1304 break; 1346 break;
1305 case 'l': 1347 case 'l':
1306 dpkg_opt |= dpkg_opt_list_installed; 1348 dpkg_opt |= dpkg_opt_list_installed;
1349 break;
1307 case 'P': 1350 case 'P':
1308 dpkg_opt |= dpkg_opt_purge; 1351 dpkg_opt |= dpkg_opt_purge;
1309 dpkg_opt |= dpkg_opt_package_name; 1352 dpkg_opt |= dpkg_opt_package_name;
@@ -1320,14 +1363,20 @@ extern int dpkg_main(int argc, char **argv)
1320 show_usage(); 1363 show_usage();
1321 } 1364 }
1322 } 1365 }
1323 1366 /* check for non-otion argument if expected */
1324 if ((argc == optind) || (dpkg_opt == 0)) { 1367 if ((dpkg_opt == 0) || ((argc == optind) && !(dpkg_opt && dpkg_opt_list_installed))) {
1325 show_usage(); 1368 show_usage();
1326 } 1369 }
1327 1370
1328 puts("(Reading database ... xxxxx files and directories installed.)"); 1371/* puts("(Reading database ... xxxxx files and directories installed.)"); */
1329 index_status_file("/var/lib/dpkg/status"); 1372 index_status_file("/var/lib/dpkg/status");
1330 1373
1374 /* if the list action was given print the installed packages and exit */
1375 if (dpkg_opt & dpkg_opt_list_installed) {
1376 list_packages();
1377 return(EXIT_SUCCESS);
1378 }
1379
1331 /* Read arguments and store relevant info in structs */ 1380 /* Read arguments and store relevant info in structs */
1332 deb_file = xmalloc(sizeof(deb_file_t)); 1381 deb_file = xmalloc(sizeof(deb_file_t));
1333 while (optind < argc) { 1382 while (optind < argc) {