Ocrad opens files in text mode

View: New views
5 Messages — Rating Filter:   Alert me  

Ocrad opens files in text mode

by smontanaro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In the SpamBayes project (http://www.spambayes.org/) we're starting to use
ocrad as an OCR tool.  It works well on Unix-oid systems, but fails on
Windows.  We tracked it down to the fact that the input files are not opened
in binary mode:

    if( std::strcmp( infile_name, "-" ) == 0 ) infile = stdin;
    else infile = std::fopen( infile_name, "r" );

There should be a "b" in that mode string.  Alas, it's not clear how you can
place stdin in binary mode, so input redirection will probably always fail.

We've built ocrad for Windows using cygwin set up in such a way that the
cygwin runtime isn't needed (probably some static linkage flags - I didn't
perform that step).

--
Skip Montanaro - skip@... - http://www.mojam.com/
"The hippies and the hipsters did some great stuff in the sixties,
but the geeks pulled their weight too." -- Billy Bragg


_______________________________________________
Bug-ocrad mailing list
Bug-ocrad@...
http://lists.gnu.org/mailman/listinfo/bug-ocrad

Re: Ocrad opens files in text mode

by Bugzilla from ant_diaz@teleline.es :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

skip@... wrote:

> In the SpamBayes project (http://www.spambayes.org/) we're starting to use
> ocrad as an OCR tool.  It works well on Unix-oid systems, but fails on
> Windows.  We tracked it down to the fact that the input files are not opened
> in binary mode:
>
>     if( std::strcmp( infile_name, "-" ) == 0 ) infile = stdin;
>     else infile = std::fopen( infile_name, "r" );
>
> There should be a "b" in that mode string.  Alas, it's not clear how you can
> place stdin in binary mode, so input redirection will probably always fail.

I didn't add the "b" because there is no difference between text and
binary files in POSIX systems. But Microsoft is always ready to annoy me. :)

I'll add the "b" for the next version, but as you say input redirection
will probably always fail.

Regards,
Antonio.


_______________________________________________
Bug-ocrad mailing list
Bug-ocrad@...
http://lists.gnu.org/mailman/listinfo/bug-ocrad

Re: Ocrad opens files in text mode

by smontanaro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    Antonio> I'll add the "b" for the next version, but as you say input
    Antonio> redirection will probably always fail.

I am told that _setmode will work to change the mode on Win32, e.g.:

    http://msdn2.microsoft.com/en-us/library/tw4k6df8.aspx

Skip


_______________________________________________
Bug-ocrad mailing list
Bug-ocrad@...
http://lists.gnu.org/mailman/listinfo/bug-ocrad

Re: Ocrad opens files in text mode

by Bugzilla from ant_diaz@teleline.es :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It seems this message got lost, so I send it again.

skip@... wrote:
>     Antonio> I'll add the "b" for the next version, but as you say input
>     Antonio> redirection will probably always fail.
>
> I am told that _setmode will work to change the mode on Win32, e.g.:

_setmode is neither ISO nor POSIX. Sorry, but I won't use a non-standard
feature only to make ocrad work on M$ systems. Better try to convince
Bill of making M$-windows POSIX compatible.


Regards,
Antonio.


_______________________________________________
Bug-ocrad mailing list
Bug-ocrad@...
http://lists.gnu.org/mailman/listinfo/bug-ocrad

Re: Ocrad opens files in text mode

by smontanaro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    >> I am told that _setmode will work to change the mode on Win32, e.g.:

    Antonio> _setmode is neither ISO nor POSIX. Sorry, but I won't use a
    Antonio> non-standard feature only to make ocrad work on M$
    Antonio> systems. Better try to convince Bill of making M$-windows POSIX
    Antonio> compatible.

What's wrong with

#ifdef HAVE__SETMODE
    ... do the _setmode dance here ...
#else
    ... treat stdin as a binary stream here ...
#endif

?  After all, isn't that what configure is for?

Skip


_______________________________________________
Bug-ocrad mailing list
Bug-ocrad@...
http://lists.gnu.org/mailman/listinfo/bug-ocrad