Subversion Repositories Kolibri OS

Rev

Rev 5731 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <kos32sys.h>
  5. #include <sys/kos_io.h>
  6.  
  7. #include "getopt.h"
  8. #include "package.h"
  9. #include "http.h"
  10.  
  11. #define BUFFSIZE  (64*1024)
  12.  
  13. extern char conbuf[256];
  14.  
  15. #define OPTION_STD_BASE 150
  16.  
  17. enum option_values
  18. {
  19.       OPTION_HELP = OPTION_STD_BASE,
  20.       OPTION_LIST_PACKAGES,
  21.       OPTION_LIST_INSTALLED
  22. };
  23.  
  24. static const struct option longopts[] =
  25. {
  26.     {"list-packages", no_argument, NULL, OPTION_LIST_PACKAGES},
  27.     {"list-installed",no_argument, NULL, OPTION_LIST_INSTALLED},
  28.     {NULL,0,NULL,0}
  29. };
  30.  
  31. int main(int argc, char *argv[])
  32. {
  33.     LIST_HEAD(server_list);
  34.     LIST_HEAD(download_list);
  35.     LIST_HEAD(cache_list);
  36.     LIST_HEAD(local_list);
  37.     LIST_HEAD(task_list);
  38.  
  39.     int   count;
  40.     char *cache_path;
  41.     char *tmp_path;
  42.  
  43.     if(http_init())
  44.         goto err_init;
  45.  
  46.     set_cwd("/tmp0/1");
  47.  
  48.     con_init(80, 25, 80, 250, "Kolibri package manager");
  49.  
  50.     tmp_path = make_tmp_path("packages.xml");
  51.  
  52.     count = http_load_file(tmp_path, make_url("packages.xml"));
  53.  
  54.     if(count)
  55.         build_server_list(&server_list, tmp_path);
  56.  
  57.     while(1)
  58.     {
  59.         int val;
  60.         int index;
  61.  
  62.         val = getopt_long_only(argc, argv,"",longopts, &index);
  63.  
  64.         if(val == -1)
  65.             break;
  66.  
  67.         switch(val)
  68.         {
  69.             case OPTION_LIST_PACKAGES:
  70.                 sprintf(conbuf,"available packages:\n\n");
  71.                 con_write_asciiz(conbuf);
  72.                 print_pkg_list(&server_list);
  73.                 con_exit(0);
  74.                 return 0;
  75.  
  76.             case OPTION_LIST_INSTALLED:
  77.                 sprintf(conbuf,"installed packages:\n\n");
  78.                 con_write_asciiz(conbuf);
  79.                 print_pkg_list(&local_list);
  80.                 con_exit(0);
  81.                 return 0;
  82.  
  83.             default:
  84.                 break;
  85.         }
  86.     };
  87.  
  88. #if 0
  89.     {
  90.         package_t   *pkg;
  91.         LIST_HEAD(install_list);
  92.         LIST_HEAD(download_list);
  93.  
  94.         if(collection && build_install_list(&install_list, collection))
  95.         {
  96.             if(build_download_list(&download_list, &install_list))
  97.                 do_download(&download_list);
  98.  
  99.             if(!list_empty(&download_list))
  100.                 remove_missing_packages(&install_list, &download_list);
  101.  
  102.             list_for_each_entry(pkg, &install_list, list)
  103.             {
  104.                 sprintf(conbuf,"install package %s-%s\n", pkg->name, pkg->version);
  105.                 con_write_asciiz(conbuf);
  106.             };
  107.  
  108.             do_install(&install_list);
  109.         };
  110.     }
  111. #endif
  112.  
  113.     con_exit(0);
  114.  
  115.     return 0;
  116.  
  117. err_init:
  118.     printf("HTTP library initialization failed\n");
  119.     return -1;
  120. }
  121.  
  122.  
  123.  
  124.  
  125.