[docs] Replace cyrillic 'с' with latin 'c' in register names
[kolibrios.git] / contrib / other / kpm / kpm.c
blob80a8be1cef8ba7e5ec6e880d7d460e7085146ea1
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <kos32sys.h>
5 #include <sys/kos_io.h>
7 #include "getopt.h"
8 #include "package.h"
9 #include "http.h"
11 void process_task(list_t *task);
13 #define BUFFSIZE (64*1024)
15 #define OPTION_STD_BASE 150
17 enum option_values
19 OPTION_HELP = OPTION_STD_BASE,
20 OPTION_LIST_PACKAGES,
21 OPTION_LIST_INSTALLED,
22 OPTION_INSTALL_ALL
25 static const struct option longopts[] =
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}
33 static void show_usage ()
35 sprintf (conbuf, "Usage: kpm [option...]\n");
36 con_write_asciiz(conbuf);
38 sprintf (conbuf, ("\
39 Options:\n\
40 --list-packages\n\
41 show available packages\n"));
42 con_write_asciiz(conbuf);
44 sprintf (conbuf, ("\
45 --list-installed\n\
46 show available packages\n"));
47 con_write_asciiz(conbuf);
49 sprintf (conbuf, ("\
50 --install all\n\
51 install all packages\n"));
52 con_write_asciiz(conbuf);
55 int main(int argc, char *argv[])
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);
63 int count;
64 char *cache_path;
65 char *tmp_path;
66 int act = 1;
68 if(http_init())
69 goto err_init;
71 set_cwd("/tmp0/1");
73 con_init(80, 25, 80, 250, "Kolibri package manager");
75 tmp_path = make_tmp_path("packages.xml");
77 count = http_load_file(tmp_path, make_url("packages.xml"));
79 if(count)
80 build_server_list(&server_list, tmp_path);
82 while(act)
84 int val;
85 int index;
87 val = getopt_long_only(argc, argv,"",longopts, &index);
89 switch(val)
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;
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;
105 case OPTION_INSTALL_ALL:
106 copy_list(&task_list, &server_list);
107 process_task(&task_list);
108 act = 0;
109 break;
111 default:
112 show_usage();
113 act = 0;
117 con_exit(0);
119 return 0;
121 err_init:
122 printf("HTTP library initialization failed\n");
123 return -1;