Re: Universal Context Sensitive Help utility program for Geany and other editors

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

Edited - eudir() corrected. Now the HelpFile is opened correctly.

--  
-- EuHelp.e   edited February 1, 2013 to include two routines  
--            suggested by SDPRINGLE 
--  
  
-- usage: EuHelp(sequence word, integer online)  
--        if "word" is found in one of Euphoria's Standard Libraries,  
--        a specific article from a /EUDIR/doc/html/std*.hml file will  
--        be loaded into your browser. Multiple articles can be loaded,  
--        and the number to be loaded can be designated by the user for  
--        disambiguation.  
          
--        If you are using a 3rd party library for which you  
--        have a *.html help file you can configure EuHelp to load that  
--        help file into your browser, if your search word is not found  
--        in one of Euphoria's Standard Libraries. See comments below:  
 
 
  
include std/filesys.e  
include std/text.e  
include std/console.e  
include std/wildcard.e  
  
-- Linux users can specify a browser  
-- constant BROWSER = "google-chrome  "  
-- constant BROWSER = "firefox "  
-- constant BROWSER  = "netsurf "  
-- constant BROWSER = "midori --log-file=midori.log  "  
-- constant BROWSER = "dillo  "  
-- or use this routine provided by SDPRINGLE to select a browser from "PATH": 
object BROWSER = 0  
browsers = { "midori", "dillo", "google-chrome", "firefox", "opera", "netsurf" }  
for browser_i = length(browsers) to 1 by -1 do  
    sequence temp = locate_file(browsers[browser_i], getenv("PATH"))  
 
    if not equal(temp, browsers[browser_i]) then  
        BROWSER = temp & " "  
        exit  
    end if  
end for  
 
 
--  get EUDIR from path to "eui/eui.ex", thanks to SDPRINGLE: 
sequence eui                                                                                                   
ifdef WINDOWS then                                                                                             
    eui = "eui.exe"                                                                                            
elsedef                                                                                                        
    eui = "eui"                                                                                                
end ifdef                                                                                                      
 
function eudir()             
sequence eudirectory                                                                                                                                                                   
    eudirectory = locate_file( eui, getenv("PATH") )           
    eudirectory = eudirectory[1..length(eudirectory)-length(eui)-4]                                                  
return eudirectory                                                                                         
end function                                                                                                   
constant EUDIR = eudir()  
--------------------------------------------------------------------------- 
---------------------------------------------------------------------------  
-----------< install an alternate *.html file if desired >-----------------  
  
integer AltHelpFile = 0  -- set to one if you have installed/coclose(hfn) pied an   
			 -- alternate *.html help file in /EUDIR/docs/html/  
  
sequence  ALT_HELPFILE = "index.html" --< name your helpfile  
ALT_HELPFILE = EUDIR & SLASH     
			& "docs" & SLASH   
			    & "html" & SLASH   
				& ALT_HELPFILE  
ifdef LINUX then  
    ALT_HELPFILE = BROWSER & "file://" & ALT_HELPFILE  
end ifdef  
 
constant ONLINE_INDEX_MATCHES_LOCAL = 0 -- FALSE  
-- set to 1, if you have verified that your  
-- local *.html index numbers match those online  
  
                 
------------------------------------------------------------------------------------------  
------------------------------------------------------------------------------------------  
------------------------------------------------------------------------------------------  
-- integer online = 0  -- "0" for local std*.html files, "1" for openeuphoria.org files.  
public procedure EuHelp( sequence word, integer online)  
    sequence pattern   
    sequence HelpFile = EUDIR & SLASH   -- HelpFile starts as:  
	& "docs" & SLASH   
	    & "html" & SLASH   
		& "key_index.html"                  -- key_index.html  
     close(hfn)  
      
    object line  
    integer start_slice, end_slice, underscore, wcmatch, hfn  
    integer cont = 1, files = 0,   
    maxfiles = 4                        -- maximum number of *.html help pages to display.  
      
    hfn = open(HelpFile, "r")  
    while cont do  
	  
	line = gets(hfn)  
	if hfn = -1 then  
	    puts(1, "Couldn't open key_index.html\n")  
	    abort(1)  
	end if  
	if atom(line) then  
	    -- end of file close(hfn)  
	    exit  
	end if  
	  
	word = lower(word)  
	line = lower(line)  
	pattern = "*std*"  & word & "\">*"  
	pattern = lower(pattern)  
	wcmatch =  is_match(pattern, line)   
	if wcmatch then  
	    start_slice = match("std", line)  
	    pattern = "_" & word & "\">"  
	    underscore = match(pattern, line)  
	    if underscore then  
		pattern = "\">"  
		end_slice = match(pattern, line)  
		end_slice = end_slice -1  
		HelpFile = line[start_slice..end_slice] -- HelpFile now = help "article"         
		files += 1  
		if online then  
		    -- Openeuphoria.org online index's need to match local html file indexes.   
		    -- Maybe when 4.1 is officially released:  
		    if ONLINE_INDEX_MATCHES_LOCAL then  
			HelpFile = "http://openeuphoria.org/docs/" & HelpFile  
		    else  
			HelpFile = "openeuphoria.org/search/results.wc?manual=1\\&s="&word  
		    end if  
		      
		    ifdef LINUX  then  
			HelpFile = BROWSER & HelpFile  
		    end ifdef  
		else  
		    -- offline, using local std*.html files  
		    ifdef LINUX then  
			HelpFile = BROWSER & "file://" & EUDIR & SLASH   
				    & "docs" & SLASH   
					& "html" & SLASH & HelpFile  
		    elsifdef WINDOWS then                 
			HelpFile = EUDIR & SLASH   
				    & "docs" & SLASH   
					& "html"  & SLASH  & HelpFile  
		    end ifdef  
		end if  
 
                system(HelpFile, 0)  
 
	    end if  
	end if  
 
 
        if files = maxfiles then  
	    cont = 0  
	    close(hfn)  
	end if  
    end while  
     
    if files = 0 then  
	if AltHelpFile then  
	    system(ALT_HELPFILE, 0)  
	else  
	    printf(1, "\n\n\tNo match for <%s> in Euphoria's Standard Libraries\n\t", {word})  
	    puts(1, "Press any key to return...")  
	end if  
    end if  
 
close(hfn)                                                                        
abort(1)  
end procedure  
------------------------------------------------------------------------------------------  
------------------------------------------------------------------------------------------  
------------------------------------------------------------------------------------------  
 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu