guess output file format

If no output file type is specified via the -O parameter, guess the
desired file type by looking at the file name extension.
If that provides no useful hints, assume "dtb" as long as the input
type is "dts". Any other input type will lead to "dts" being used as
the guessed output type.
Any explicit specification of the output type will skip this guessing.

Signed-off-by: Andre Przywara <osp@andrep.de>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
main
Andre Przywara 2015-07-01 00:31:28 +01:00 committed by David Gibson
parent 5e78dff424
commit f6dbc6ca96
1 changed files with 10 additions and 1 deletions

11
dtc.c
View File

@ -155,7 +155,7 @@ int main(int argc, char *argv[])
{
struct boot_info *bi;
const char *inform = NULL;
const char *outform = "dts";
const char *outform = NULL;
const char *outname = "-";
const char *depname = NULL;
bool force = false, sort = false;
@ -262,6 +262,15 @@ int main(int argc, char *argv[])

if (inform == NULL)
inform = guess_input_format(arg, "dts");
if (outform == NULL) {
outform = guess_type_by_name(outname, NULL);
if (outform == NULL) {
if (streq(inform, "dts"))
outform = "dtb";
else
outform = "dts";
}
}
if (streq(inform, "dts"))
bi = dt_from_source(arg);
else if (streq(inform, "fs"))