edx.ex :: function get_err_line() replacement

new topic     » topic index » view thread      » older message » newer message

The function trim_tail can replace the entire function "delete_trailing_white". The function to_number can replace the entire function "numeric"

-- this entire function: 
function delete_trailing_white(sequence name)                                                        
    -- get rid of blanks, tabs, newlines at end of string                                            
    while length(name) > 0 do                                                                        
        if find(name[length(name)], "\n\r\t ") then                                                  
            name = name[1..length(name)-1]                                                           
        else                                                                                         
            exit                                                                                     
        end if                                                                                       
    end while                                                                                        
    return name                                                                                      
end function 
-- can be replaced by using: 
trim_tail(sequence name, "\t\r\n ")  -- requires include std/text.e 
-- in each instance that delete_trailing_white(sequence name) is called 
 
 
-- likewise to_number(sequence text_in) can replace  
-- the entire routine: 
function numeric(sequence string)                                                                    
    -- convert digit string to an integer                                                            
    atom n                                                                                           
                                                                                                     
    n = 0                                                                                            
    for i = 1 to length(string) do                                                                   
        if string[i] >= '0' and string[i] <= '9' then                                                
            n = n * 10 + string[i] - '0'                                                             
            if not integer(n) then                                                                   
                return 0                                                                                        end if                                                                                   
        else                                                                                         
            exit                                                                                     
        end if                                                                                       
    end for                                                                                          
    return n                                                                                         
end function              
 
-- This function much more clear and concise than the original ed.ex/edx.ex code:                          
-- requires include std/convert.e for to_number(sequence text_in) 
function get_err_line() 
    ---------------------------------------- 
    --  derived from Irv Mulling's, gneui.ex 
    ----------------------------------------- 
    object file_lines 
    object file 
    object temp_line 
    object err_line 
    integer err_col = 0, i = 0 
     
    file_lines = read_lines("ex.err") 
    if atom(file_lines) then  
	--                  crash("Cannot find ex.err!\n")  
	error_message = "" 
	return "" 
	break    
    else 
	 
	error_message = trim_tail(file_lines[2]) 
	 
	for n = 1 to length(file_lines) do 
	    if match("^^^ call-back from external source",file_lines[n]) = 1 then 
		file_lines = file_lines[1..n-1] 
		exit 
	    end if 
	end for	 
	 
	-- trap & process euphoria error report; 
	for n = 1 to length(file_lines) do 
	    if find('^', file_lines[n]) then 
		i = find(':',file_lines[1]) 
		err_col = match("^", expand_tabs(STANDARD_TAB_WIDTH, file_lines[n]))-1 
		file = file_lines[1][1..i-1] 
		err_line = to_number(file_lines[1][i+1..$]) 
		start_col = err_col 
		start_line = err_line 
		return file 
	    end if  
	end for 
    end if 
end function  

Ken

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu