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/>.
24 #include <sys/types.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>
50 const char* showformat
= "${Package}\t${Version}\n";
53 printversion(const struct cmdinfo
*cip
, const char *value
)
55 printf(_("Debian `%s' package archive backend version %s.\n"),
56 BACKEND
, DPKG_VERSION_ARCH
);
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>"));
68 usage(const struct cmdinfo
*cip
, const char *value
)
71 "Usage: %s [<option> ...] <command>\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"
88 " -h|--help Show this help message.\n"
89 " --version Show the version.\n"
90 " --license|--licence Show the copyright licensing terms.\n"
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"
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"
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"
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"));
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>"));
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
);
146 set_compress_level(const struct cmdinfo
*cip
, const char *value
)
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
[]= {
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
},
196 { "licence", 0, 0, NULL
, NULL
, showcopyright
},
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
) {
204 badusage(_("conflicting actions -%c (--%s) and -%c (--%s)"),
205 cip
->oshort
, cip
->olong
, cipaction
->oshort
, cipaction
->olong
);
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
) {
220 setlocale(LC_NUMERIC
, "POSIX");
221 setlocale(LC_ALL
, "");
222 bindtextdomain(PACKAGE
, LOCALEDIR
);
225 standard_startup(&ejbuf
);
226 myopt(&argv
, cmdinfos
);
228 if (!cipaction
) badusage(_("need an action option"));