Scanimage Batch Prompt: Discard Extraneous Input Properly
This merge adjusts the handling of character input from the prompt provided by:
scanimage --batch --batch-prompt
Which reads:
Press <RETURN> to continue.
Press Ctrl + D to terminate.
The following scenarios were tested with before and after behavior:
Return with no other input:
- Before: Scan one page, prompt again
- After: Scan one page, prompt again
Return with character input preceding:
- Before: Scan one page per entered character (including newline), prompt again
- After: Scan one page, prompt again
EOF with no other input:
- Before: Complete job
- After: Complete job
EOF with other input:
- Before: Scan one page per entered character (excluding EOF), prompt again
- After: Do nothing, await a second EOF to complete job, otherwise resume batch. I've found this behavior in many, many applications reading stdin, the first EOF of a pair does not trigger a flush of characters from stdin, but the second does. The first EOF is discarded as it is not emitted by getchar before the newline after the first time pressing Ctrl + D. I presume this is terminal driver behavior far beyond the scope of this fix. In any case, if you press return after several characters and a single EOF, you will get the "Return with character input preceding" behavior above.
This merge additionally clarifies the prompt text to indicate Ctrl + D as calling for EOF, just in the very off chance a platform calls for a different combination. The previous code was not explicitly checking for the actual EOF value from stdin, but now does, so this clarification may be necessary.