Subversion Repositories Kolibri OS

Rev

Rev 5737 | 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. void process_task(list_t *task);
  12.  
  13. #define BUFFSIZE  (64*1024)
  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.       OPTION_INSTALL_ALL
  23. };
  24.  
  25. static const struct option longopts[] =
  26. {
  27.     {"list-packages", no_argument, NULL, OPTION_LIST_PACKAGES},
  28.     {"list-installed",no_argument, NULL, OPTION_LIST_INSTALLED},
  29.     {"install-all",no_argument, NULL, OPTION_INSTALL_ALL},
  30.     {NULL,0,NULL,0}
  31. };
  32.  
  33. static void show_usage ()
  34. {
  35.     sprintf (conbuf, "Usage: kpm [option...]\n");
  36.     con_write_asciiz(conbuf);
  37.  
  38.     sprintf (conbuf, ("\
  39. Options:\n\
  40.  --list-packages\n\
  41.                          show available packages\n"));
  42.     con_write_asciiz(conbuf);
  43.  
  44.     sprintf (conbuf, ("\
  45.  --list-installed\n\
  46.                          show available packages\n"));
  47.     con_write_asciiz(conbuf);
  48.  
  49.     sprintf (conbuf, ("\
  50.  --install all\n\
  51.                          install all packages\n"));
  52.     con_write_asciiz(conbuf);
  53. };
  54.  
  55. int main(int argc, char *argv[])
  56. {
  57.     LIST_HEAD(server_list);
  58.     LIST_HEAD(download_list);
  59.     LIST_HEAD(cache_list);
  60.     LIST_HEAD(local_list);
  61.     LIST_HEAD(task_list);
  62.  
  63.     int   count;
  64.     char *cache_path;
  65.     char *tmp_path;
  66.     int   act = 1;
  67.  
  68.     if(http_init())
  69.         goto err_init;
  70.  
  71.     set_cwd("/tmp0/1");
  72.  
  73.     con_init(80, 25, 80, 250, "Kolibri package manager");
  74.  
  75.     tmp_path = make_tmp_path("packages.xml");
  76.  
  77.     count = http_load_file(tmp_path, make_url("packages.xml"));
  78.  
  79.     if(count)
  80.         build_server_list(&server_list, tmp_path);
  81.  
  82.     while(act)
  83.     {
  84.         int val;
  85.         int index;
  86.  
  87.         val = getopt_long_only(argc, argv,"",longopts, &index);
  88.  
  89.         switch(val)
  90.         {
  91.             case OPTION_LIST_PACKAGES:
  92.                 sprintf(conbuf,"available packages:\n\n");
  93.                 con_write_asciiz(conbuf);
  94.                 print_pkg_list(&server_list);
  95.                 act = 0;
  96.                 break;
  97.  
  98.             case OPTION_LIST_INSTALLED:
  99.                 sprintf(conbuf,"installed packages:\n\n");
  100.                 con_write_asciiz(conbuf);
  101.                 print_pkg_list(&local_list);
  102.                 act = 0;
  103.                 break;
  104.  
  105.             case OPTION_INSTALL_ALL:
  106.                 copy_list(&task_list, &server_list);
  107.                 process_task(&task_list);
  108.                 act = 0;
  109.                 break;
  110.  
  111.             default:
  112.                 show_usage();
  113.                 act = 0;
  114.         }
  115.     };
  116.  
  117.     con_exit(0);
  118.  
  119.     return 0;
  120.  
  121. err_init:
  122.     printf("HTTP library initialization failed\n");
  123.     return -1;
  124. }
  125.  
  126.