예제 #1
0
파일: program.py 프로젝트: Yungzuck/pcbasic
def store_line(linebuf):
    """ Store the given line buffer. """
    if state.basic_state.protected:
        raise error.RunError(error.IFC)
    # get the new line number
    linebuf.seek(1)
    scanline = util.parse_line_number(linebuf)
    # check if linebuf is an empty line after the line number
    empty = (util.skip_white_read(linebuf) in tk.end_line)
    pos, afterpos, deleteable, beyond = find_pos_line_dict(scanline, scanline)
    if empty and not deleteable:
        raise error.RunError(error.UNDEFINED_LINE_NUMBER)
    # read the remainder of the program into a buffer to be pasted back after the write
    state.basic_state.bytecode.seek(afterpos)
    rest = state.basic_state.bytecode.read()
    # insert
    state.basic_state.bytecode.seek(pos)
    # write the line buffer to the program buffer
    length = 0
    if not empty:
        # set offsets
        linebuf.seek(3) # pass \x00\xC0\xDE
        length = len(linebuf.getvalue())
        state.basic_state.bytecode.write( '\0' + str(vartypes.integer_to_bytes(vartypes.int_to_integer_unsigned(program_memory_start + pos + length))) + linebuf.read())
    # write back the remainder of the program
    truncate_program(rest)
    # update all next offsets by shifting them by the length of the added line
    update_line_dict(pos, afterpos, length, deleteable, beyond)
    if not empty:
        state.basic_state.line_numbers[scanline] = pos
    # clear all program stacks
    flow.init_program()
    state.basic_state.last_stored = scanline
예제 #2
0
def check_number_start(linebuf):
    """ Check if the given line buffer starts with a line number. """
    # get the new line number
    linebuf.seek(1)
    scanline = util.parse_line_number(linebuf)
    c = util.skip_white_read(linebuf)
    # check if linebuf is an empty line after the line number
    empty = (c in tk.end_line)
    # check if we start with a number
    if c in tk.number:
        raise error.RunError(error.STX)
    return empty, scanline
예제 #3
0
파일: program.py 프로젝트: Yungzuck/pcbasic
def check_number_start(linebuf):
    """ Check if the given line buffer starts with a line number. """
    # get the new line number
    linebuf.seek(1)
    scanline = util.parse_line_number(linebuf)
    c = util.skip_white_read(linebuf)
    # check if linebuf is an empty line after the line number
    empty = (c in tk.end_line)
    # check if we start with a number
    if c in tk.number:
        raise error.RunError(error.STX)
    return empty, scanline
예제 #4
0
def store_line(linebuf):
    """ Store the given line buffer. """
    if state.basic_state.protected:
        raise error.RunError(error.IFC)
    # get the new line number
    linebuf.seek(1)
    scanline = util.parse_line_number(linebuf)
    # check if linebuf is an empty line after the line number
    empty = (util.skip_white_read(linebuf) in tk.end_line)
    pos, afterpos, deleteable, beyond = find_pos_line_dict(scanline, scanline)
    if empty and not deleteable:
        raise error.RunError(error.UNDEFINED_LINE_NUMBER)
    # read the remainder of the program into a buffer to be pasted back after the write
    state.basic_state.bytecode.seek(afterpos)
    rest = state.basic_state.bytecode.read()
    # insert
    state.basic_state.bytecode.seek(pos)
    # write the line buffer to the program buffer
    length = 0
    if not empty:
        # set offsets
        linebuf.seek(3)  # pass \x00\xC0\xDE
        length = len(linebuf.getvalue())
        state.basic_state.bytecode.write(
            '\0' +
            str(vartypes.value_to_uint(program_memory_start + pos + length)) +
            linebuf.read())
    # write back the remainder of the program
    truncate_program(rest)
    # update all next offsets by shifting them by the length of the added line
    update_line_dict(pos, afterpos, length, deleteable, beyond)
    if not empty:
        state.basic_state.line_numbers[scanline] = pos
    # clear all program stacks
    flow.init_program()
    state.basic_state.last_stored = scanline