History

formats: clarify setting of reverse_bytes

Factor out repeated conditions and merge the resulting if statement with the following one. This makes the intent clearer and silences a flurry of warnings from clang.

Mans Rullgard committed 6 years ago

Commit 6e278ee1 parent 021c7881 file · +17 −13Browse files

Unified · Split

src/formats.c+17−13
@@ -302,23 +302,27 @@ char const * sox_find_comment(sox_comments_t comments, char const * id) · 301 unmodified lines
302302
303303 static void set_endiannesses(sox_format_t * ft)
304304 {
305− if (ft->encoding.opposite_endian)
306− ft->encoding.reverse_bytes = (ft->handler.flags & SOX_FILE_ENDIAN)?
307− !(ft->handler.flags & SOX_FILE_ENDBIG) != MACHINE_IS_BIGENDIAN : sox_true;
308− else if (ft->encoding.reverse_bytes == sox_option_default)
309− ft->encoding.reverse_bytes = (ft->handler.flags & SOX_FILE_ENDIAN)?
310− !(ft->handler.flags & SOX_FILE_ENDBIG) == MACHINE_IS_BIGENDIAN : sox_false;
305+ if (ft->handler.flags & SOX_FILE_ENDIAN) {
306+ sox_bool file_is_bigendian = !(ft->handler.flags & SOX_FILE_ENDBIG);
307+
308+ if (ft->encoding.opposite_endian) {
309+ ft->encoding.reverse_bytes = file_is_bigendian != MACHINE_IS_BIGENDIAN;
310+ lsx_report("`%s': overriding file-type byte-order", ft->filename);
311+ } else if (ft->encoding.reverse_bytes == sox_option_default) {
312+ ft->encoding.reverse_bytes = file_is_bigendian == MACHINE_IS_BIGENDIAN;
313+ }
314+ } else {
315+ if (ft->encoding.opposite_endian) {
316+ ft->encoding.reverse_bytes = sox_option_yes;
317+ lsx_report("`%s': overriding machine byte-order", ft->filename);
318+ } else if (ft->encoding.reverse_bytes == sox_option_default) {
319+ ft->encoding.reverse_bytes = sox_option_no;
320+ }
321+ }
311322
312323 /* FIXME: Change reports to suitable warnings if trying
313324 * to override something that can't be overridden. */
314325
315− if (ft->handler.flags & SOX_FILE_ENDIAN) {
316− if (ft->encoding.reverse_bytes == (sox_option_t)
317− (!(ft->handler.flags & SOX_FILE_ENDBIG) != MACHINE_IS_BIGENDIAN))
318− lsx_report("`%s': overriding file-type byte-order", ft->filename);
319− } else if (ft->encoding.reverse_bytes == sox_option_yes)
320− lsx_report("`%s': overriding machine byte-order", ft->filename);
321−
322326 if (ft->encoding.reverse_bits == sox_option_default)
323327 ft->encoding.reverse_bits = !!(ft->handler.flags & SOX_FILE_BIT_REV);
324328 else if (ft->encoding.reverse_bits == !(ft->handler.flags & SOX_FILE_BIT_REV))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t