- /* If the format is Auto, try to determine it from the file name */
- if (Format == ifAuto) {
- /* Search for the entry in the table */
- const FileId* F = GetFileId (Name, FormatTable,
- sizeof (FormatTable) / sizeof (FormatTable[0]));
+ const FileId* F;
+
+ /* Get the file format from the command line */
+ const char* Format = GetAttrVal (A, "format");
+ if (Format != 0) {
+ /* Format is given, search for it in the table. */
+ F = bsearch (Format,
+ FormatTable,
+ sizeof (FormatTable) / sizeof (FormatTable[0]),
+ sizeof (FormatTable[0]),
+ CompareFileId);
+ if (F == 0) {
+ Error ("Unknown input format `%s'", Format);
+ }
+ } else {
+ /* No format given, use file name extension */
+ const char* Name = NeedAttrVal (A, "name", "write");
+ F = GetFileId (Name, FormatTable,
+ sizeof (FormatTable) / sizeof (FormatTable[0]));