Changeset 4418
- Timestamp:
- 05/09/08 12:52:43 (5 years ago)
- Location:
- trunk/src/target/opkg
- Files:
-
- 4 edited
-
configure.ac (modified) (1 diff)
-
libopkg/opkg.c (modified) (9 diffs)
-
libopkg/opkg.h (modified) (2 diffs)
-
tests/libopkg_test.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/target/opkg/configure.ac
r4416 r4418 1 1 # Process this file with autoconf to produce a configure script 2 2 AC_INIT(libopkg/libopkg.c) 3 AM_INIT_AUTOMAKE([opkg], [0.1. 2])3 AM_INIT_AUTOMAKE([opkg], [0.1.3]) 4 4 AM_CONFIG_HEADER(libopkg/config.h) 5 5 -
trunk/src/target/opkg/libopkg/opkg.c
r4416 r4418 46 46 47 47 #define progress(d, p) d.percentage = p; if (progress_callback) progress_callback (opkg, &d, user_data); 48 #define OLD_PKG_TO_NEW(pkg) opkg_package_new_with_values (pkg->name, pkg->version, pkg->architecture, pkg->description, pkg->tags, pkg->url, (pkg->size ? atoi (pkg->size) : 0), (pkg->state_status == SS_INSTALLED));48 #define SSTRCMP(x,y) (x && y) ? strcmp (x, y) : 0 49 49 50 50 /** Private Functions ***/ 51 51 52 static opkg_package_t* 53 old_pkg_to_new (pkg_t *old) 54 { 55 opkg_package_t *new; 56 57 new = opkg_package_new (); 58 59 #define sstrdup(x) (x) ? strdup (x) : NULL; 60 61 new->name = sstrdup (old->name); 62 new->version = pkg_version_str_alloc (old); 63 new->architecture = sstrdup (old->architecture); 64 new->repository = sstrdup (old->src->name); 65 new->description = sstrdup (old->description); 66 new->tags = sstrdup (old->tags); 67 new->url = sstrdup (old->url); 68 69 new->size = (old->size) ? atoi (old->size) : 0; 70 new->installed = (old->state_status == SS_INSTALLED); 71 72 return new; 73 } 52 74 53 75 static int … … 142 164 143 165 return p; 144 }145 146 opkg_package_t *147 opkg_package_new_with_values (const char *name, const char *version,148 const char *arch, const char *desc, const char *tags, const char *url, int size, int installed)149 {150 opkg_package_t *package;151 package = opkg_package_new ();152 153 #define sstrdup(x) (x) ? strdup (x) : NULL;154 155 package->name = sstrdup (name);156 package->version = sstrdup (version);157 package->architecture = sstrdup (arch);158 package->description = sstrdup (desc);159 package->tags = sstrdup (tags);160 package->url = sstrdup (url);161 162 package->size = size;163 package->installed = (installed != 0);164 165 return package;166 166 } 167 167 … … 377 377 } 378 378 pdata.action = OPKG_INSTALL; 379 pdata.package = OLD_PKG_TO_NEW(new);379 pdata.package = old_pkg_to_new (new); 380 380 381 381 progress (pdata, 0); … … 442 442 443 443 pdata.action = OPKG_REMOVE; 444 pdata.package = OLD_PKG_TO_NEW(pkg);444 pdata.package = old_pkg_to_new (pkg); 445 445 progress (pdata, 0); 446 446 … … 516 516 517 517 pdata.action = OPKG_INSTALL; 518 pdata.package = OLD_PKG_TO_NEW(pkg);518 pdata.package = old_pkg_to_new (pkg); 519 519 progress (pdata, 0); 520 520 … … 551 551 pkg = installed->pkgs[i]; 552 552 553 pdata.package = OLD_PKG_TO_NEW(pkg);553 pdata.package = old_pkg_to_new (pkg); 554 554 progress (pdata, 99 * i / installed->len); 555 555 opkg_package_free (pdata.package); … … 760 760 pkg = all->pkgs[i]; 761 761 762 package = OLD_PKG_TO_NEW(pkg);762 package = old_pkg_to_new (pkg); 763 763 callback (opkg, package, user_data); 764 764 } … … 801 801 if (cmp < 0) 802 802 { 803 package = OLD_PKG_TO_NEW(new);803 package = old_pkg_to_new (new); 804 804 callback (opkg, package, user_data); 805 805 } … … 811 811 } 812 812 813 opkg_package_t* 814 opkg_find_package (opkg_t *opkg, const char *name, const char *ver, const char *arch, const char *repo) 815 { 816 pkg_vec_t *all; 817 opkg_package_t *package = NULL; 818 int i; 819 #define sstrcmp(x,y) (x && y) ? strcmp (x, y) : 0 820 821 opkg_assert (opkg); 822 823 all = pkg_vec_alloc (); 824 pkg_hash_fetch_available (&opkg->conf->pkg_hash, all); 825 for (i = 0; i < all->len; i++) 826 { 827 pkg_t *pkg; 828 char *pkgv; 829 830 pkg = all->pkgs[i]; 831 832 /* check name */ 833 if (sstrcmp (pkg->name, name)) 834 continue; 835 836 /* check version */ 837 pkgv = pkg_version_str_alloc (pkg); 838 if (sstrcmp (pkgv, ver)) 839 { 840 free (pkgv); 841 continue; 842 } 843 free (pkgv); 844 845 /* check architecture */ 846 if (arch) 847 { 848 if (sstrcmp (pkg->architecture, arch)) 849 continue; 850 } 851 852 /* check repository */ 853 if (repo) 854 { 855 if (sstrcmp (pkg->src->name, repo)) 856 continue; 857 } 858 859 /* match found */ 860 package = old_pkg_to_new (pkg); 861 break; 862 } 863 864 pkg_vec_free (all); 865 866 return package; 867 } -
trunk/src/target/opkg/libopkg/opkg.h
r4416 r4418 51 51 52 52 opkg_package_t* opkg_package_new (); 53 opkg_package_t* opkg_package_new_with_values (const char *name, const char *version, const char *arch, const char *desc, const char *tags, const char *url, int size, int installed);54 53 void opkg_package_free (opkg_package_t *package); 55 54 … … 68 67 int opkg_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data); 69 68 int opkg_list_upgradable_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data); 69 opkg_package_t* opkg_find_package (opkg_t *opkg, const char *name, const char *version, const char *architecture, const char *repository); -
trunk/src/target/opkg/tests/libopkg_test.c
r4415 r4418 2 2 #include <stdlib.h> 3 3 #include <stdio.h> 4 5 opkg_package_t *find_pkg = NULL; 4 6 5 7 void … … 24 26 fflush (stdout); 25 27 26 opkg_package_free (pkg); 28 if (!find_pkg) 29 { 30 /* store the first package to print out later */ 31 find_pkg = pkg; 32 } 33 else 34 opkg_package_free (pkg); 27 35 } 28 36 … … 33 41 } 34 42 43 void 44 print_package (opkg_package_t *pkg) 45 { 46 printf ( 47 "Name: %s\n" 48 "Version: %s\n" 49 "Repository: %s\n" 50 "Architecture: %s\n" 51 "Description: %s\n" 52 "Tags: %s\n" 53 "URL: %s\n" 54 "Size: %d\n" 55 "Installed: %s\n", 56 pkg->name, 57 pkg->version, 58 pkg->repository, 59 pkg->architecture, 60 pkg->description, 61 pkg->tags, 62 pkg->url, 63 pkg->size, 64 (pkg->installed ? "True" : "False") 65 ); 66 } 67 35 68 int 36 69 main (int argc, char **argv) 37 70 { 38 71 opkg_t *opkg; 72 opkg_package_t *pkg; 39 73 int err; 40 74 … … 47 81 err = opkg_update_package_lists (opkg, progress_callback, "Updating..."); 48 82 printf ("\nopkg_update_package_lists returned %d\n", err); 83 84 opkg_list_packages (opkg, package_list_callback, NULL); 85 printf ("\n"); 86 87 if (find_pkg) 88 { 89 printf ("Finding package \"%s\"\n", find_pkg->name); 90 pkg = opkg_find_package (opkg, find_pkg->name, find_pkg->version, find_pkg->architecture, find_pkg->repository); 91 if (pkg) 92 { 93 print_package (pkg); 94 opkg_package_free (find_pkg); 95 opkg_package_free (pkg); 96 } 97 else 98 printf ("Package \"%s\" not found!\n", find_pkg->name); 99 } 100 else 101 printf ("No package available to test find_package.\n"); 49 102 50 103 err = opkg_install_package (opkg, "aspell", progress_callback, "Installing..."); … … 63 116 printf ("\nopkg_upgrade_all returned %d\n", err); 64 117 65 opkg_list_packages (opkg, package_list_callback, NULL); 66 printf ("\n"); 118 opkg_free (opkg); 67 119 68 opkg_free (opkg);120 return 0; 69 121 }
Note: See TracChangeset
for help on using the changeset viewer.
