Rev 5737 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5737 | Rev 5809 | ||
---|---|---|---|
Line 6... | Line 6... | ||
6 | 6 | ||
7 | #include "getopt.h" |
7 | #include "getopt.h" |
8 | #include "package.h" |
8 | #include "package.h" |
Line 9... | Line 9... | ||
9 | #include "http.h" |
9 | #include "http.h" |
Line 10... | Line 10... | ||
10 | 10 | ||
Line 11... | Line 11... | ||
11 | #define BUFFSIZE (64*1024) |
11 | void process_task(list_t *task); |
Line 12... | Line 12... | ||
12 | 12 | ||
13 | extern char conbuf[256]; |
13 | #define BUFFSIZE (64*1024) |
14 | 14 | ||
15 | #define OPTION_STD_BASE 150 |
15 | #define OPTION_STD_BASE 150 |
16 | 16 | ||
- | 17 | enum option_values |
|
17 | enum option_values |
18 | { |
Line 18... | Line 19... | ||
18 | { |
19 | OPTION_HELP = OPTION_STD_BASE, |
19 | OPTION_HELP = OPTION_STD_BASE, |
20 | OPTION_LIST_PACKAGES, |
20 | OPTION_LIST_PACKAGES, |
21 | OPTION_LIST_INSTALLED, |
21 | OPTION_LIST_INSTALLED |
22 | OPTION_INSTALL_ALL |
- | 23 | }; |
|
22 | }; |
24 | |
23 | 25 | static const struct option longopts[] = |
|
Line -... | Line 26... | ||
- | 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); |
|
24 | static const struct option longopts[] = |
48 | |
25 | { |
49 | sprintf (conbuf, ("\ |
26 | {"list-packages", no_argument, NULL, OPTION_LIST_PACKAGES}, |
50 | --install all\n\ |
27 | {"list-installed",no_argument, NULL, OPTION_LIST_INSTALLED}, |
51 | install all packages\n")); |
28 | {NULL,0,NULL,0} |
52 | con_write_asciiz(conbuf); |
Line 37... | Line 61... | ||
37 | LIST_HEAD(task_list); |
61 | LIST_HEAD(task_list); |
Line 38... | Line 62... | ||
38 | 62 | ||
39 | int count; |
63 | int count; |
40 | char *cache_path; |
64 | char *cache_path; |
- | 65 | char *tmp_path; |
|
Line 41... | Line 66... | ||
41 | char *tmp_path; |
66 | int act = 1; |
42 | 67 | ||
Line 43... | Line 68... | ||
43 | if(http_init()) |
68 | if(http_init()) |
Line 52... | Line 77... | ||
52 | count = http_load_file(tmp_path, make_url("packages.xml")); |
77 | count = http_load_file(tmp_path, make_url("packages.xml")); |
Line 53... | Line 78... | ||
53 | 78 | ||
54 | if(count) |
79 | if(count) |
Line 55... | Line 80... | ||
55 | build_server_list(&server_list, tmp_path); |
80 | build_server_list(&server_list, tmp_path); |
56 | 81 | ||
57 | while(1) |
82 | while(act) |
58 | { |
83 | { |
Line 59... | Line 84... | ||
59 | int val; |
84 | int val; |
Line 60... | Line -... | ||
60 | int index; |
- | |
61 | - | ||
62 | val = getopt_long_only(argc, argv,"",longopts, &index); |
- | |
63 | 85 | int index; |
|
64 | if(val == -1) |
86 | |
65 | break; |
87 | val = getopt_long_only(argc, argv,"",longopts, &index); |
66 | 88 | ||
67 | switch(val) |
89 | switch(val) |
68 | { |
90 | { |
69 | case OPTION_LIST_PACKAGES: |
91 | case OPTION_LIST_PACKAGES: |
70 | sprintf(conbuf,"available packages:\n\n"); |
92 | sprintf(conbuf,"available packages:\n\n"); |
Line 71... | Line 93... | ||
71 | con_write_asciiz(conbuf); |
93 | con_write_asciiz(conbuf); |
72 | print_pkg_list(&server_list); |
94 | print_pkg_list(&server_list); |
73 | con_exit(0); |
95 | act = 0; |
74 | return 0; |
96 | break; |
75 | - | ||
76 | case OPTION_LIST_INSTALLED: |
97 | |
77 | sprintf(conbuf,"installed packages:\n\n"); |
- | |
78 | con_write_asciiz(conbuf); |
- | |
79 | print_pkg_list(&local_list); |
98 | case OPTION_LIST_INSTALLED: |
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); |
- | |
Line 93... | Line 99... | ||
93 | 99 | sprintf(conbuf,"installed packages:\n\n"); |
|
94 | if(collection && build_install_list(&install_list, collection)) |
100 | con_write_asciiz(conbuf); |
95 | { |
- | |
96 | if(build_download_list(&download_list, &install_list)) |
101 | print_pkg_list(&local_list); |
97 | do_download(&download_list); |
102 | act = 0; |
98 | - | ||
99 | if(!list_empty(&download_list)) |
- | |
100 | remove_missing_packages(&install_list, &download_list); |
103 | break; |
Line -... | Line 104... | ||
- | 104 | ||
101 | 105 | case OPTION_INSTALL_ALL: |
|
102 | list_for_each_entry(pkg, &install_list, list) |
106 | copy_list(&task_list, &server_list); |
103 | { |
107 | process_task(&task_list); |
104 | sprintf(conbuf,"install package %s-%s\n", pkg->name, pkg->version); |
108 | act = 0; |
Line 105... | Line 109... | ||
105 | con_write_asciiz(conbuf); |
109 | break; |
Line 106... | Line 110... | ||
106 | }; |
110 | |
Line 107... | Line 111... | ||
107 | 111 | default: |
|
108 | do_install(&install_list); |
112 | show_usage(); |
109 | }; |
113 | act = 0; |
110 | } |
114 | } |
Line 111... | Line -... | ||
111 | #endif |
- | |
112 | - | ||
113 | con_exit(0); |
- |