1 /* opkglib.c - the opkg package management system
5 Copyright (C) 2003 kernel concepts
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2, or (at
10 your option) any later version.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
22 #include "opkg_conf.h"
24 #include "file_util.h"
26 #include "opkg_message.h"
27 #include "opkg_error.h"
29 opkg_status_callback opkg_cb_status
= NULL
;
30 opkg_list_callback opkg_cb_list
= NULL
;
32 int default_opkg_message_callback(opkg_conf_t
*conf
, message_level_t level
,
35 if (conf
&& (conf
->verbosity
< level
)) {
38 if ( level
== OPKG_ERROR
){
39 push_error_list(&error_list
, msg
);
46 int default_opkg_list_callback(char *name
, char *desc
, char *version
,
47 pkg_state_status_t status
, void *userdata
)
50 printf("%s - %s - %s\n", name
, version
, desc
);
52 printf("%s - %s\n", name
, version
);
56 int default_opkg_files_callback(char *name
, char *desc
, char *version
,
57 pkg_state_status_t status
, void *userdata
)
64 int default_opkg_status_callback(char *name
, int istatus
, char *desc
,
71 char* default_opkg_response_callback(char *question
)
73 char *response
= NULL
;
74 printf("%s",question
);
77 response
= (char *)file_read_line_alloc(stdin
);
78 } while (response
== NULL
);
82 /* This is used for backward compatibility */
84 opkg_op (int argc
, char *argv
[])
90 opkg_conf_t opkg_conf
;
94 optind
= args_parse (&args
, argc
, argv
);
95 if (optind
== argc
|| optind
< 0)
97 args_usage ("opkg must have one sub-command argument");
100 cmd_name
= argv
[optind
++];
101 /* Pigi: added a flag to disable the checking of structures if the command does not need to
102 read anything from there.
104 if ( !strcmp(cmd_name
,"print-architecture") ||
105 !strcmp(cmd_name
,"print_architecture") ||
106 !strcmp(cmd_name
,"print-installation-architecture") ||
107 !strcmp(cmd_name
,"print_installation_architecture") )
108 args
.nocheckfordirorfile
= 1;
110 /* Pigi: added a flag to disable the reading of feed files if the command does not need to
111 read anything from there.
113 if ( !strcmp(cmd_name
,"flag") ||
114 !strcmp(cmd_name
,"configure") ||
115 !strcmp(cmd_name
,"remove") ||
116 !strcmp(cmd_name
,"files") ||
117 !strcmp(cmd_name
,"search") ||
118 !strcmp(cmd_name
,"compare_versions") ||
119 !strcmp(cmd_name
,"compare-versions") ||
120 !strcmp(cmd_name
,"list_installed") ||
121 !strcmp(cmd_name
,"list-installed") ||
122 !strcmp(cmd_name
,"status") )
123 args
.noreadfeedsfile
= 1;
125 opkg_cb_message
= default_opkg_message_callback
;
126 opkg_cb_response
= default_opkg_response_callback
;
127 opkg_cb_status
= default_opkg_status_callback
;
130 err
= opkg_conf_init (&opkg_conf
, &args
);
133 opkg_print_error_list (&opkg_conf
);
139 if ( strcmp(cmd_name
, "files")==0)
140 opkg_cb_list
= default_opkg_files_callback
;
142 opkg_cb_list
= default_opkg_list_callback
;
144 cmd
= opkg_cmd_find (cmd_name
);
147 fprintf (stderr
, "%s: unknown sub-command %s\n", argv
[0],
152 if (cmd
->requires_args
&& optind
== argc
)
155 "%s: the ``%s'' command requires at least one argument\n",
156 __FUNCTION__
, cmd_name
);
160 err
= opkg_cmd_exec (cmd
, &opkg_conf
, argc
- optind
, (const char **) (argv
+ optind
), NULL
);
162 opkg_conf_deinit (&opkg_conf
);