robhagemans / pcbasic

PC-BASIC - A free, cross-platform emulator for the GW-BASIC family of interpreters
http://www.pc-basic.org
Other
393 stars 48 forks source link

Bug fix for when reading raw exernal text files with sequencial input mode "I" #218

Closed EmmanuelAsmFun closed 1 year ago

EmmanuelAsmFun commented 1 year ago

Bug report

Problem

Read reading raw exernal text files with sequencial input mode "I" does not work correctly when the array type is a string, it needs to use comma's, when the array is numeric, it needs to uses spaces.

Steps

  1. Run the program below

Program 65 OPEN "I",3,AL:O=1 66 IF EOF(3) THEN CLOSE 3:O=O-1:RETURN ELSE INPUT #3,O(O),O1(O),AO(O):O=O+1:GOTO 6510 File content 1 1990 MrTest,

Crash log

Notes Fix

Replace in use default string and not decimal The type needs to by found by the complete name basic/implementation.py line 785 def _input_file(self, finp, readvar): """INPUT: retrieve input from file.""" for v in readvar: name, indices = v typechar = self.memory.completename(name)[-1:] word, = finp.input_entry(typechar, allow_past_end=False) value = self.values.from_repr(word, allow_nonnum=True, typechar=typechar) self.memory.set_variable(name, indices, value)

Full method fix def _input_file(self, finp, readvar): """INPUT: retrieve input from file.""" for v in readvar: name, indices = v typechar = self.memory.complete_name(name)[-1:] word, _ = finp.input_entry(typechar, allow_past_end=False) value = self.values.from_repr(word, allow_nonnum=True, typechar=typechar) self.memory.set_variable(name, indices, value) PC-BASIC version:
Operating system version:

robhagemans commented 1 year ago

Hi, apologies for the late response. I'm not sure I understand the issue you're reporting correctly as the program pasted is incomplete and doesn't run (AL should be defined; there needs to be a DEFSTR A for the first line to be syntactically correct, which implies AO is also a string, is that intended? line 6510 is undefined). Could you please include a working test case, including the outcome you see and the outcome you would have expected to see instead?

robhagemans commented 1 year ago

OK, I think this is what is meant:

test program

10 DEFSTR A
20 AL="TEST_SEQ.DAT"
65 OPEN "I",3,AL:O=1
66 IF EOF(3) THEN CLOSE 3:O=O-1:RETURN ELSE INPUT #3,O(O),O1(O),AO(O):O=O+1:GOTO 6510
6510 REM

outcome in PC-BASIC Type Mismatch in 66

outcome in GW-BASIC no error

The issue is that the INPUT implementation ignores the DEFSTR and tries to read AO as Single instead of Integer. Thanks for the proposed code fix which resolves the issue, I'll include.