atexit() isn't really appropriate for a library.
[project/opkg-lede.git] / libopkg / libopkg.c
1 /* opkglib.c - the opkg package management system
2
3 Florina Boor
4
5 Copyright (C) 2003 kernel concepts
6
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.
11
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.
16 */
17
18 #include "includes.h"
19 #include "libopkg.h"
20
21 #include "args.h"
22 #include "opkg_conf.h"
23 #include "opkg_cmd.h"
24 #include "file_util.h"
25
26 #include "opkg_message.h"
27 #include "opkg_error.h"
28
29 /* This is used for backward compatibility */
30 int
31 opkg_op (int argc, char *argv[])
32 {
33 int err, optind;
34 args_t args;
35 char *cmd_name;
36 opkg_cmd_t *cmd;
37 opkg_conf_t opkg_conf;
38
39 args_init (&args);
40
41 optind = args_parse (&args, argc, argv);
42 if (optind == argc || optind < 0)
43 {
44 args_usage ("opkg must have one sub-command argument");
45 }
46
47 cmd_name = argv[optind++];
48 /* Pigi: added a flag to disable the checking of structures if the command does not need to
49 read anything from there.
50 */
51 if ( !strcmp(cmd_name,"print-architecture") ||
52 !strcmp(cmd_name,"print_architecture") ||
53 !strcmp(cmd_name,"print-installation-architecture") ||
54 !strcmp(cmd_name,"print_installation_architecture") )
55 args.nocheckfordirorfile = 1;
56
57 /* Pigi: added a flag to disable the reading of feed files if the command does not need to
58 read anything from there.
59 */
60 if ( !strcmp(cmd_name,"flag") ||
61 !strcmp(cmd_name,"configure") ||
62 !strcmp(cmd_name,"remove") ||
63 !strcmp(cmd_name,"files") ||
64 !strcmp(cmd_name,"search") ||
65 !strcmp(cmd_name,"compare_versions") ||
66 !strcmp(cmd_name,"compare-versions") ||
67 !strcmp(cmd_name,"list_installed") ||
68 !strcmp(cmd_name,"status") )
69 args.noreadfeedsfile = 1;
70
71
72 err = opkg_conf_init (&opkg_conf, &args);
73 args_deinit (&args);
74 if (err)
75 {
76 print_error_list();
77 free_error_list();
78 return err;
79 }
80
81 cmd = opkg_cmd_find (cmd_name);
82 if (cmd == NULL)
83 {
84 fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
85 cmd_name);
86 args_usage (NULL);
87 }
88
89 if (cmd->requires_args && optind == argc)
90 {
91 fprintf (stderr,
92 "%s: the ``%s'' command requires at least one argument\n",
93 __FUNCTION__, cmd_name);
94 args_usage (NULL);
95 }
96
97 err = opkg_cmd_exec (cmd, &opkg_conf, argc - optind, (const char **) (argv + optind), NULL);
98
99 #ifdef HAVE_CURL
100 opkg_curl_cleanup();
101 #endif
102 opkg_conf_deinit (&opkg_conf);
103
104 return err;
105 }