Update Swedish translation.
[dpkg.git] / dpkg-deb / main.c
blob37e42a138238ef126dd73ec54e6f2ed7b5db7777
1 /*
2 * dpkg-deb - construction and deconstruction of *.deb archives
3 * main.c - main program
5 * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
7 * This is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <config.h>
22 #include <compat.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <sys/wait.h>
28 #include <assert.h>
29 #include <errno.h>
30 #include <limits.h>
31 #if HAVE_LOCALE_H
32 #include <locale.h>
33 #endif
34 #include <ctype.h>
35 #include <string.h>
36 #include <dirent.h>
37 #include <unistd.h>
38 #include <stdlib.h>
39 #include <stdio.h>
41 #include <dpkg/macros.h>
42 #include <dpkg/i18n.h>
43 #include <dpkg/dpkg.h>
44 #include <dpkg/dpkg-db.h>
45 #include <dpkg/compress.h>
46 #include <dpkg/myopt.h>
48 #include "dpkg-deb.h"
50 const char* showformat = "${Package}\t${Version}\n";
52 static void
53 printversion(const struct cmdinfo *cip, const char *value)
55 printf(_("Debian `%s' package archive backend version %s.\n"),
56 BACKEND, DPKG_VERSION_ARCH);
57 printf(_(
58 "This is free software; see the GNU General Public License version 2 or\n"
59 "later for copying conditions. There is NO warranty.\n"
60 "See %s --license for copyright and license details.\n"), BACKEND);
62 m_output(stdout, _("<standard output>"));
64 exit(0);
67 static void
68 usage(const struct cmdinfo *cip, const char *value)
70 printf(_(
71 "Usage: %s [<option> ...] <command>\n"
72 "\n"), BACKEND);
74 printf(_(
75 "Commands:\n"
76 " -b|--build <directory> [<deb>] Build an archive.\n"
77 " -c|--contents <deb> List contents.\n"
78 " -I|--info <deb> [<cfile> ...] Show info to stdout.\n"
79 " -W|--show <deb> Show information on package(s)\n"
80 " -f|--field <deb> [<cfield> ...] Show field(s) to stdout.\n"
81 " -e|--control <deb> [<directory>] Extract control info.\n"
82 " -x|--extract <deb> <directory> Extract files.\n"
83 " -X|--vextract <deb> <directory> Extract & list files.\n"
84 " --fsys-tarfile <deb> Output filesystem tarfile.\n"
85 "\n"));
87 printf(_(
88 " -h|--help Show this help message.\n"
89 " --version Show the version.\n"
90 " --license|--licence Show the copyright licensing terms.\n"
91 "\n"));
93 printf(_(
94 "<deb> is the filename of a Debian format archive.\n"
95 "<cfile> is the name of an administrative file component.\n"
96 "<cfield> is the name of a field in the main `control' file.\n"
97 "\n"));
99 printf(_(
100 "Options:\n"
101 " --showformat=<format> Use alternative format for --show.\n"
102 " -D Enable debugging output.\n"
103 " --old, --new Select archive format.\n"
104 " --nocheck Suppress control file check (build bad\n"
105 " packages).\n"
106 " -z# Set the compression level when building.\n"
107 " -Z<type> Set the compression type used when building.\n"
108 " Allowed values: gzip, bzip2, lzma, none.\n"
109 "\n"));
111 printf(_(
112 "Format syntax:\n"
113 " A format is a string that will be output for each package. The format\n"
114 " can include the standard escape sequences \\n (newline), \\r (carriage\n"
115 " return) or \\\\ (plain backslash). Package information can be included\n"
116 " by inserting variable references to package fields using the ${var[;width]}\n"
117 " syntax. Fields will be right-aligned unless the width is negative in which\n"
118 " case left alignment will be used.\n"));
120 printf(_(
121 "\n"
122 "Use `dpkg' to install and remove packages from your system, or\n"
123 "`dselect' or `aptitude' for user-friendly package management. Packages\n"
124 "unpacked using `dpkg-deb --extract' will be incorrectly installed !\n"));
126 m_output(stdout, _("<standard output>"));
128 exit(0);
131 const char thisname[]= BACKEND;
132 const char printforhelp[]=
133 N_("Type dpkg-deb --help for help about manipulating *.deb files;\n"
134 "Type dpkg --help for help about installing and deinstalling packages.");
136 int debugflag=0, nocheckflag=0, oldformatflag=BUILDOLDPKGFORMAT;
137 struct compressor *compressor = &compressor_gzip;
138 int compress_level = -1;
139 const struct cmdinfo *cipaction = NULL;
140 dofunction *action = NULL;
142 static void setaction(const struct cmdinfo *cip, const char *value);
143 static void setcompresstype(const struct cmdinfo *cip, const char *value);
145 static void
146 set_compress_level(const struct cmdinfo *cip, const char *value)
148 long level;
149 char *end;
151 level = strtol(value, &end, 0);
152 if (value == end || *end || level > INT_MAX)
153 badusage(_("invalid integer for -%c: '%.250s'"), cip->oshort, value);
155 if (level < 0 || level > 9)
156 badusage(_("invalid compression level for -%c: %ld'"), cip->oshort, level);
158 compress_level = level;
161 static dofunction *const dofunctions[]= {
162 do_build,
163 do_contents,
164 do_control,
165 do_info,
166 do_field,
167 do_extract,
168 do_vextract,
169 do_fsystarfile,
170 do_showinfo
173 /* NB: the entries using setaction must appear first and be in the
174 * same order as dofunctions:
176 static const struct cmdinfo cmdinfos[]= {
177 { "build", 'b', 0, NULL, NULL, setaction },
178 { "contents", 'c', 0, NULL, NULL, setaction },
179 { "control", 'e', 0, NULL, NULL, setaction },
180 { "info", 'I', 0, NULL, NULL, setaction },
181 { "field", 'f', 0, NULL, NULL, setaction },
182 { "extract", 'x', 0, NULL, NULL, setaction },
183 { "vextract", 'X', 0, NULL, NULL, setaction },
184 { "fsys-tarfile", 0, 0, NULL, NULL, setaction },
185 { "show", 'W', 0, NULL, NULL, setaction },
186 { "new", 0, 0, &oldformatflag, NULL, NULL, 0 },
187 { "old", 0, 0, &oldformatflag, NULL, NULL, 1 },
188 { "debug", 'D', 0, &debugflag, NULL, NULL, 1 },
189 { "nocheck", 0, 0, &nocheckflag, NULL, NULL, 1 },
190 { "compression", 'z', 1, NULL, NULL, set_compress_level },
191 { "compress_type", 'Z', 1, NULL, NULL, setcompresstype },
192 { "showformat", 0, 1, NULL, &showformat, NULL },
193 { "help", 'h', 0, NULL, NULL, usage },
194 { "version", 0, 0, NULL, NULL, printversion },
195 /* UK spelling. */
196 { "licence", 0, 0, NULL, NULL, showcopyright },
197 /* US spelling. */
198 { "license", 0, 0, NULL, NULL, showcopyright },
199 { NULL, 0, 0, NULL, NULL, NULL }
202 static void setaction(const struct cmdinfo *cip, const char *value) {
203 if (cipaction)
204 badusage(_("conflicting actions -%c (--%s) and -%c (--%s)"),
205 cip->oshort, cip->olong, cipaction->oshort, cipaction->olong);
206 cipaction= cip;
207 assert((int)(cip - cmdinfos) < (int)(array_count(dofunctions)));
208 action= dofunctions[cip-cmdinfos];
211 static void setcompresstype(const struct cmdinfo *cip, const char *value) {
212 compressor = compressor_find_by_name(value);
213 if (compressor == NULL)
214 ohshit(_("unknown compression type `%s'!"), value);
217 int main(int argc, const char *const *argv) {
218 jmp_buf ejbuf;
220 setlocale(LC_NUMERIC, "POSIX");
221 setlocale(LC_ALL, "");
222 bindtextdomain(PACKAGE, LOCALEDIR);
223 textdomain(PACKAGE);
225 standard_startup(&ejbuf);
226 myopt(&argv, cmdinfos);
228 if (!cipaction) badusage(_("need an action option"));
230 unsetenv("GZIP");
231 action(argv);
232 standard_shutdown();
233 exit(0);
236 /* vi: sw=2