Enca should probably exit 1 each time it prints 'unknown'
JelF opened this issue · comments
I have some string, which encoding i want to detect (attached)
When i'm calling enca -m
, result is "unknown\n", but exit code is zero (same as enca
's, where response is
Macintosh Cyrillic
LF line terminators
)
I somehow can not reproduce this:
$ enca -m /tmp/123.txt
unknown
$ echo $?
1
What enca version are you using?
$ enca -v
enca 1.14
Features: +librecode-interface +iconv-interface +external-converter +language-detection +locale-alias +target-charset-auto +ENCAOPT
As far as i see, it is not latest. I'll build it from master and try to reproduce bug sometime later
➜ bin git:(master) ✗ ./enca --version
enca 1.19-dev
Features: +librecode-interface +iconv-interface +external-converter +language-detection +locale-alias +target-charset-auto +ENCAOPT
Copyright (C) 2000-2005 David Necas (Yeti) (<yeti@physics.muni.cz>),
2005 Zuxy Meng (<zuxy.meng@gmail.com>).
Enca is free software; it can be copied and/or modified under the terms of
version 2 of GNU General Public License, run `enca --license' to see the full
license text. There is NO WARRANTY; not even for MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.
➜ bin git:(master) ✗ ./enca -m /tmp/123.txt
unknown
➜ bin git:(master) ✗ echo $?
0
Hmm, that's strange. On what platform is that? I've fixed some minor issues in the return codes handling, but I don't think these will fix it for you.
sorry, no idea how to fix :(
Can you use gdb to see process_file return value?
@nijel no, i am completly not familar with gdb and other c-related stuff :(
I've reproduced this. The issue appears to be, as @JelF hinted at above, that enca -m
exits with the same exit value enca
would, even when enca -m
is outputting "unknown".
It's easiest to illustrate with an example. I'm in an en_US locale, so normally enca
doesn't support my local language settings:
$ enca -m ~/Desktop/123.txt
enca: Cannot determine (or understand) your language preferences. [...etc...]
$ echo $?
1
$ echo `# When enca can't recognize the encoding at all`
$ enca -L none ~/Desktop/123.txt
Unrecognized encoding
$ echo $?
1
$ enca -L none -m ~/Desktop/123.txt
unknown
$ echo $?
1
$ echo `# When enca CAN identify the file encoding, but not the corresponding MIME type`
$ enca -L russian ~/Desktop/123.txt
Macintosh Cyrillic
LF line terminators
$ echo $?
0
$ enca -L russian -m ~/Desktop/123.txt
unknown
$ echo $?
0