Skip to content

Conversation

@olebole
Copy link
Member

@olebole olebole commented Jan 9, 2026

This is only a partial fix, because it doesn't work with integers that start with 0x or 0o. So, the following will not work correctly:

scanf("%2d%d", "0x1234")

because the first conversion will eat up all (not only the first two digits). This seems however a quite strange case because it is f.e. unclear whether the 0x is valid also for the second part.

I am not even sure whether we shall support 0x or 0o prefixes at all; they seem to be artefacts of the old parser. IRAF scanf does not support them.

Closes #194

This is only a partial fix, because it doesn't work with integers that
start with 0x or 0o.
@jehturner
Copy link
Collaborator

That's an odd one. It seems not to work with the previous parser either and, from the help page, IRAF uses %x & %o for scanning hex & octal values, respectively, rather than %d, which is for decimals. So I don't think we need to worry about that case? I have to admit to a little bit of confusion as to where in the code IRAF vs Python conventions are being used.

@jehturner
Copy link
Collaborator

jehturner commented Jan 12, 2026

Could we therefore get rid of the 0x/0o in the regex and just keep it more like it was before? There do already seem to be some separate expressions for those, at the end of scanf_translate?

@olebole
Copy link
Member Author

olebole commented Jan 12, 2026

Yes, this was also my thought: the iraf scanf code does not handle 0x/0o in %d format. 0x/0o was implemented only in the original PyRAF scanf module - I thing on accident, because the source code that was chosen as the base supported that. And when I replaced this by a Python code, I tried to resemble the original (PyRAF) behaviour and added the octal/hexadecimal handling.
The best is really to get rid of this and have unconditional decimal (%d), octal (%o) and hexadecimal (%h) formats, just like IRAF itself.

While this was implemented in the original PyRAF scanf module, its
Python implementation didn't work well. Also it was not implemented in
the original IRAF scanf function.

Parsing of octal/hexadecimal strings is still possible by using the %o
ond %h formats, just like in IRAFs scanf.
@jehturner
Copy link
Collaborator

Yeah, this seems right to me (subject to more testing). It's also getting simpler! Thanks.

@olebole
Copy link
Member Author

olebole commented Jan 13, 2026

I'll take the opportunity and remove also a number of other format options that are not part of IRAF scanf:

  • %i, %l as integer synonyms (IRAF cl only allows %d; in C scanf %i should allow 0x prefixes)
  • %u unsigned integers
  • %X as synonym to %x
  • %E as synonym for %f
  • optional 0x prefix when using %x (has the same problem as described above)

@jehturner
Copy link
Collaborator

Sounds good (without double checking that list).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Error from fscanf on main branch when parsing integers

3 participants