home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
NDXHELP.PEL
< prev
next >
Wrap
Text File
|
1995-03-31
|
17KB
|
636 lines
# $Header: P:\source\wmacros\ndxhelp.pev 1.19 31 Mar 1995 15:34:46 NOBLE $
# $Tabs:4 7$
##############################################################################
#
# Compuware Corporation
# 31440 Northwestern Highway
# Farmington Hills, Michigan 48334-2564
#
# This source code listing contains information that is
# proprietary to Compuware Corporation and may not be copied
# duplicated, translated, transmitted, stored, retrieved
# or in any manner or by any method conveyed or disclosed
# to a third party or parties without express written
# permission from Compuware Corporation.
#
#
##############################################################################
#### $Workfile: ndxhelp.pel $: help stuff
global fast_help = 0 # If this is not set to 0, the topic is not searched
# for until after the user selects a help file from all
# of the possible help files for that extension.
# if it is 0, then the topic is searched for in each
# ndx file to see if it is actually contained in the
# help file before it is added to the list for the
# user to choose from.
global first_help = 0 # If this is not set to 0 and fast_help is set to 0,
# then the first ndx file that has an entry that
# matches the desired topic is used and no other
# ndx files are searched.
global function gui_help_index()
{
if(isWindows())
display_help("Table Of Contents")
else
display_help("HelpIndex")
}
global function gui_general_help()
{
if(isWindows())
display_help("Table Of Contents");
else
display_help("introduction")
}
global function gui_using()
{
if(isWindows())
display_help("Help On Help");
else
display_help("HelpOnHelp")
}
global function gui_tutorial()
{
gui_nyi()
}
global function gui_cobolhelp()
{
display_help("verbs")
}
#
# display help on word that cursor is in or parameter
#
global function display_help_item(item)
{
local symbol
if ( !helpndx )
load_ndx_help()
if (item)
symbol = item
else
{
symbol = left_symbol_under_cursor();
if(!symbol)
{
warning("No symbol under cursor.")
return
}
}
if (!ndx_help(symbol))
display_help(symbol)
}
local helpndx = 0
local helporder
# this function will load all the .ndx files specified in the
# HELPNDX environment variable. The DPATH, BOOKSHELF, HELP, PATH
# and CPE environment variables are searched to locate the .ndx files
global function load_ndx_help(ndx, bookshelf, clear)
{
local str, fn, i
local old_buf, buf
local locate_help_file
local index = 0
local sf = SEARCH_FORWARD+SEARCH_REGEX
if (argcount() >= 3 && clear)
delete helpndx
else
{
clear = 0
for (i in helporder)
index = max(index, i)
}
if (argcount() >= 2 && length(ndx))
{
if (!clear && length(ENV ["HELPNDX"]))
ENV ["HELPNDX"] = ENV ["HELPNDX"] "+" ndx
else
ENV ["HELPNDX"] = ndx
}
if (argcount() >= 1 && length(bookshelf))
{
if (!clear && length(ENV ["BOOKSHELF"]))
ENV ["BOOKSHELF"] = ENV ["BOOKSHELF"] ";" bookshelf
else
ENV ["BOOKSHELF"] = bookshelf
}
if ( "HELPNDX" in ENV )
{
old_buf = current_buffer
for (fn = strtok(ENV["HELPNDX"], /[ \t+,;]+/); fn != 0; fn = strtok())
{
if (!length(path_ext(fn)))
fn = fn ".ndx"
locate_help_file = fn
if ((fn = find_help_file(fn)))
{
helporder[index] = fn
helpndx[fn].filename = fn
index++
if (tolower(path_ext(fn)) == ".ndx")
{
if ( message_level == 0 )
message("Processing %s...", fn)
# load it into a system buffer
buf = create_buffer( "", fn, BUFFER_NO_UNDO+BUFFER_SYSTEM )
current_buffer = buf
goto_buffer_top()
# load the extensions
if (search("^[ \\t]*EXTENSIONS:\\c", sf))
{
helpndx[fn].extensions = ltrim( trim(read_buffer()) )
helpndx[fn].extensions = "<" tolower(helpndx[fn].extensions) ">"
gsub(" ", ">|<", helpndx[fn].extensions)
}
else
helpndx[fn].extensions = "*"
# load the description
if (search("^[ \\t]*DESCRIPTION:\\c", sf))
helpndx[fn].description = ltrim(trim(read_buffer()))
else
helpndx[fn].description = fn
# load the help files (if any)
# (Note: This is a preditor extension to the OS/2 NDX
# file definition and therefore can be placed
# inside a comment to allow the NDX file to
# be used with KwikINF)
if (search("^[ \\t]*FILES:\\c", sf) || \
search("^[ \\t]*/\\*[ \\t]*FILES:\\c", sf))
{
str = read_buffer()
gsub(/\*\//, "", str)
helpndx[fn].files = ltrim(trim(str))
}
# see if there are any entries in this ndx file
helpndx[fn].has_entries = search( "^\\(", sf)
current_buffer = old_buf
delete_buffer(buf)
}
else
{
helpndx[fn].extensions = "*"
helpndx[fn].description = fn
helpndx[fn].has_entries = 0
}
}
else
warning("Unable to locate " locate_help_file ". The file must exist in your DPATH.")
}
if ( message_level == 0 )
message("Processing complete.")
}
else
notify("No HELPNDX environment variable defined")
}
#
# ndx_help()
# will search for symbol in the currently loaded ndx files.
#
global function ndx_help(symbol, ndx_file)
{
local cmd, pos, file, topic, show_it
if ( symbol == "" )
symbol = symbol_under_cursor()
if ( length(ndx_file) )
cmd = find_topic(ndx_file, symbol)
else
cmd = find_help(symbol)
if (length(cmd))
{
if (!(show_it = match(cmd, /hlp/) && match(cmd, /view/)))
show_it = match(cmd, /winhelp/)
if (show_it)
{
file = ltrim(substr(cmd, RSTART+RLENGTH))
pos = cindex(file, " ")
topic = ltrim(substr(file, pos + 1))
file = prefix(file, pos - 1)
if ( message_level == 0 )
message("Looking Up %s in %s...", topic, file)
show_help(file, topic)
}
else
{
if ( message_level == 0 )
message("Executing %s...", cmd)
system("@" cmd)
}
if ( message_level == 0 )
message("")
return 1
}
return 0
}
local function find_help(symbol)
{
local i
local fn
local ext
local cmd
local dlgid
local bufext
local ndx_file
local hlp_file
local cmd_list[]
local found_list[]
local found = 0
for ( i in helporder )
{
fn = helporder[i]
ext = helpndx[fn].extensions
bufext = ltrim( path_ext(buffer_filename), "." )
if ( ext == "*" || ext == "<*>" || match(bufext, ext) )
{
if (!fast_help)
cmd = find_topic(fn, symbol)
if (fast_help || length(cmd))
{
found++
found_list[found] = fn
if (!fast_help)
{
cmd_list[found] = cmd
if (first_help)
break
}
}
}
}
if ( found == 1 )
{
ndx_file = helpndx[found_list[found]].filename
if (fast_help)
cmd = find_cmd(found, symbol)
else
cmd = cmd_list[found]
}
else if (found > 1)
{
dlgid = create_selection_dialog("Select a help file", 40)
for ( i in found_list )
{
set_dialog_item( dlgid, IDL_LIST, DAC_ADD_ITEM,
helpndx[found_list[i]].description )
}
new_response = ""
begin_dialog(dlgid)
if (length(new_response))
{
for ( i in found_list )
{
if ( helpndx[found_list[i]].description == new_response )
{
ndx_file = find_help_file(helpndx[found_list[i]].filename)
if (fast_help)
cmd = find_cmd(ndx_file, symbol)
else
cmd = cmd_list[i]
}
}
}
delete_dialog(dlgid)
}
return cmd
}
local function find_cmd(ndx_file, symbol)
{
local hlp_file
local cmd = find_topic(ndx_file, symbol)
if (!length(cmd))
{
if (!isWindows())
hlp_file = find_help_file(path_fname(ndx_file) ".inf")
if (!length(hlp_file))
hlp_file = find_help_file(path_fname(ndx_file) ".hlp")
if (length(hlp_file))
{
if(isWindows())
cmd = "winhelp " hlp_file " " symbol
else
cmd = "view " hlp_file " " symbol
}
}
return cmd
}
local function find_topic(ndx_file, symbol)
{
local hlp_file
local cmd = ""
local oldbuf = current_buffer
local buf = create_buffer( "", ndx_file, BUFFER_NO_UNDO+BUFFER_SYSTEM )
local sf = SEARCH_FORWARD+SEARCH_REGEX
local excluded = 0
current_buffer = buf
goto_buffer_top()
if ( message_level == 0 )
message("Searching %s...", ndx_file)
if (tolower(path_ext(ndx_file)) == ".ndx")
{
if (helpndx[ndx_file].has_entries)
{
if (search("^[ \\t]*\\([ \\t]*" quote_regex(symbol), sf))
{
goto_bol()
cmd = get_help_cmd(symbol)
excluded = !length(cmd)
}
else if (!(excluded = is_topic_excluded(symbol)))
{
# Only dig through the ndx file while there be wildcards there.
goto_buffer_top()
while (search("^[ \\t]*\\(.*\\*", sf))
{
goto_bol()
cmd = get_help_cmd(symbol)
if (length(cmd))
break
else
sf = or(sf, SEARCH_ADVANCE)
}
}
}
else
excluded = is_topic_excluded(symbol)
if (!length(cmd) && !excluded)
{
if (length(helpndx[ndx_file].files))
cmd = search_help_files(helpndx[ndx_file].files, symbol)
else if (!helpndx[ndx_file].has_entries)
{
if (!isWindows())
hlp_file = find_help_file(path_fname(ndx_file) ".inf")
if (!length(hlp_file))
hlp_file = find_help_file(path_fname(ndx_file) ".hlp")
if (length(hlp_file))
cmd = search_help_files(hlp_file, symbol)
}
if (!and(buffer_flags, BUFFER_READ_ONLY))
{
if (!helpndx[ndx_file].has_entries &&
!length(helpndx[ndx_file].files))
{
helpndx[ndx_file].files = ndx_file
goto_buffer_bottom()
if (current_column != 1)
insert_newline()
insert_string("/* FILES: " ndx_file " */")
insert_newline()
}
if (length(helpndx[ndx_file].files))
{
if (length(cmd))
{
goto_buffer_bottom()
if (current_column != 1)
insert_newline()
insert_string("(" symbol ", " cmd ")")
insert_newline()
write_buffer()
}
else
{
goto_buffer_bottom()
if (current_column != 1)
insert_newline()
insert_string("/* EXCLUDE: " symbol " */")
insert_newline()
write_buffer()
}
}
}
}
}
else
{
if (search(symbol, SEARCH_FORWARD))
{
if(isWindows())
cmd = "winhelp " ndx_file " " symbol
else
cmd = "view " ndx_file " " symbol
}
}
current_buffer = oldbuf
delete_buffer(buf)
if ( message_level == 0 )
message("")
return cmd
}
# Search through Excluded key-words.
# (Note: This is a preditor extension to the OS/2 NDX
# file definition and therefore can be placed
# inside a comment to allow the NDX file to
# be used with KwikINF)
#
local function is_topic_excluded(symbol)
{
local str
local sf = SEARCH_FORWARD+SEARCH_REGEX
goto_buffer_top()
while (search("^[ \\t]*EXCLUDE:\\c", sf) || \
search("^[ \\t]*/\\*[ \\t]*EXCLUDE:\\c", sf))
{
str = read_buffer()
gsub(/\*\//, "", str)
if (match(str, "[ \\t,+]*" quote_regex(symbol) "[ \\t,+]*"))
return TRUE
}
return FALSE
}
local function get_help_cmd(symbol)
{
local arr[]
local i, item, file, path, show_it
local found = 0
local cmd = ""
local ln = read_buffer()
split(ln, arr, "\\(")
for ( i in arr )
{
ln = ltrim(arr[i])
if ( match(ln, ".+,") )
{
item = substr(ln, RSTART, RLENGTH-1)
ln = ltrim(substr(ln, RSTART+RLENGTH))
match(ln, ".+\\)")
cmd = substr(ln, RSTART, RLENGTH-1)
# adjust for any regular expression characters contained in
# the item name (except for * which has special meaning
gsub("\\\\", "\\\\", item)
gsub("\\^", "\\^", item)
gsub("\\$", "\\$", item)
gsub("\\.", "\\.", item)
gsub("\\[", "\\[", item)
gsub("\\]", "\\]", item)
gsub("\\|", "\\|", item)
gsub("\\(", "\\(", item)
gsub("\\)", "\\)", item)
gsub("\\{", "\\{", item)
gsub("\\}", "\\}", item)
gsub("\\+", "\\+", item)
gsub("\\?", "\\?", item)
gsub("\\<", "\\<", item)
gsub("\\>", "\\>", item)
gsub("\\*", ".*", item)
item = "<" item ">"
if ( match(symbol, item) )
{
if(isWindows())
{
gsub(/\.inf/, ".hlp", cmd)
if (!(show_it = match(cmd, /view/)))
show_it = match(cmd, /winhelp/)
if (show_it)
{
file = ltrim(substr(cmd, RSTART+RLENGTH))
file = prefix(file, cindex(file, " ") - 1)
path = find_help_file(file)
if (length(path))
gsub(file, path, cmd)
}
}
gsub("~", symbol, cmd)
found = 1
break
}
}
}
return found ? cmd : ""
}
local function search_help_files(files, symbol)
{
local fn, buf, old_buf
local found = 0
local cmd = ""
old_buf = current_buffer
for (fn = strtok(files, /[ \t+,;]+/); (fn = strtok()); )
{
fn = find_help_file(fn)
if ( message_level == 0 )
message("Checking %s...", fn)
buf = create_buffer( "", fn, BUFFER_NO_UNDO+BUFFER_SYSTEM )
current_buffer = buf
goto_buffer_top()
found = search(symbol, SEARCH_FORWARD)
delete_buffer(buf)
if (found)
{
if(isWindows())
cmd = "winhelp " fn " " symbol
else
cmd = "view " fn " " symbol
break
}
}
current_buffer = old_buf
return cmd
}
local function find_help_file(file)
{
local path
if (length(file))
{
if (length(findfirst(file)))
path = file
else
{
if (!(path = search_path(file, "DPATH;BOOKSHELF;HELP;PATH;CPE")))
{
path = editor_path() file
if (!length(findfirst(path)))
{
path = editor_path() "help\\" file
if (!length(findfirst(path)))
path = ""
}
}
}
}
return path
}