PROCEDURE lsi_find_buffer ! ! Prompt for a wild-card buffer name and position into the first buffer that ! matches. If no matching buffer is found, then create one. LOCAL buffer_name, buff_index, letter, after_len, before_len, curr_buff, curr_name, name_len, yn; ! ! Prompt the user for the buffer name. buffer_name := READ_LINE ('_Find buffer: '); IF buffer_name = '' THEN RETURN ENDIF; CHANGE_CASE (buffer_name, UPPER); ! ! Look for a '*' in the buffer name. buff_index := 1; buff_len := LENGTH (buffer_name); LOOP EXITIF buff_index > buff_len + 1; EXITIF SUBSTR (buffer_name + '*', buff_index, 1) = '*'; buff_index := buff_index + 1; ENDLOOP; ! ! Find the length of the substrings before and after the '*'. after_len := buff_len - buff_index; before_len := buff_index - 1; ! ! Look through the buffer list for a match. curr_buff := GET_INFO (BUFFERS, "first"); LOOP ! ! Exit if no more buffers. EXITIF curr_buff = 0; ! ! Get name of buffer as upper-case string. curr_name := GET_INFO (curr_buff, "name"); CHANGE_CASE (curr_name, UPPER); name_len := LENGTH (curr_name); ! ! Check the buffer name for a match if the '*' occurred at the start of ! the pattern. EXITIF (before_len = 0) AND (SUBSTR (curr_name, name_len - after_len + 1, after_len) = SUBSTR (buffer_name, buff_len - after_len + 1, after_len)); ! ! Check the buffer name for a match if the '*' occurred at the end of the ! pattern (or if no '*' occurred in the pattern). EXITIF (after_len = 0) AND (before_len <> 0) AND (SUBSTR (curr_name, 1, before_len) = SUBSTR (buffer_name, 1, before_len)); ! ! Check the buffer name for a match before and after the '*'. EXITIF (before_len <> 0) AND (SUBSTR (curr_name, 1, before_len) = SUBSTR (buffer_name, 1, before_len)) AND (SUBSTR (curr_name, name_len - after_len + 1, after_len) = SUBSTR (buffer_name, buff_len - after_len + 1, after_len)); ! ! No match - get the next buffer. curr_buff := GET_INFO (BUFFERS, "next"); ENDLOOP; ! ! If a match was found, then position to that buffer. IF curr_buff = 0 THEN yn := READ_LINE ('No buffer ' + buffer_name + ' found. Create? (Y/N) '); CHANGE_CASE (yn, UPPER); IF yn = 'Y' THEN curr_buff := (CREATE_BUFFER (buffer_name)) ENDIF ENDIF; IF curr_buff <> 0 THEN POSITION (curr_buff); MAP (CURRENT_WINDOW, CURRENT_BUFFER); LSE$SET_STATUS_LINE (CURRENT_WINDOW) ENDIF ENDPROCEDURE;