Interactive Parsing

version 3 by Jon Ingold

  • Home page
  • Beginning
  • Previous
  • Next



  • Chapter 3 - Command Line Recall

    Section - Store the Command Line after the player hits Return

    Include (-

    Constant COMMAND_RECALL_DEPTH = 10;
    Constant COMMAND_LINE_AVERAGE_LENGTH = 16;
    Constant COMMAND_STORAGE = COMMAND_LINE_AVERAGE_LENGTH * COMMAND_RECALL_DEPTH;

    Array command_lines -> COMMAND_STORAGE + 10;
    Array command_line_pointers --> COMMAND_RECALL_DEPTH + 2;
    Global current_command_line = 0;
    ! 0 = player's typing. 1+ = going backwards in time

    [ StoreCommandLine input_buffer
        start_point
        i os ol
        ;
        ! store characters in command_lines array.
        ! store start point and length in command_line pointers (via snippety method 1,000 * length + start point)
        
        if (input_buffer-->0 == 0) rfalse;

    ! PrintCommandLineStorage("Before writing in new line.");

        ! start point = character after end of last line
        start_point = GetCommandLineStart(1) + GetCommandLineLength(1);

        if (start_point + input_buffer-->0 > COMMAND_STORAGE)
            ! We're out of storage so we start again from the beginning
            start_point = 0;
            
        ! find any commands in the stack which live in the part of the storage buffer we're using, and erase their pointers

        ! overlap between new and old command <=> either starts in the middle of the other
        for (i = COMMAND_RECALL_DEPTH : i >= 1 : i-- )
        {
            os = GetCommandLineStart(i) ; ol = GetCommandLineLength(i);
            if (ol ~= 0 && (WordInsideWord(os, start_point, input_buffer-->0) || WordInsideWord(start_point, os, ol)))
                command_line_pointers-->i = 0;
        }

        WriteBufferToCommandLine(input_buffer, start_point);

        ! shift all the pointers one along - note this means we don't need to edit the command line buffer. So nyah.
        for (i = COMMAND_RECALL_DEPTH: i > 1 : i-- )
        {
            command_line_pointers --> i = command_line_pointers --> (i - 1);
        }

        command_line_pointers --> 1 = ConstructCommandLinePoint(start_point, input_buffer-->0);

    ! PrintCommandLineStorage("After writing in new line.");


        
    ];

    [ WordInsideWord teststart interval_start interval_length;
        return (teststart >= interval_start && teststart < interval_start + interval_length);
    ];

    -) after "Parser.i6t".