home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
COMPILER.PEL
< prev
next >
Wrap
Text File
|
1995-04-10
|
56KB
|
1,996 lines
# $Header: P:\source\wmacros\compiler.pev 1.51.1.2 10 Apr 1995 14:18:08 WALKER $
## $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: compiler.pel $: dialog window interface
# Types
# -----
# ada
# basic
# c
# cobol
# makefile
# pascal
# pel
#
#
# typedef struct compiler
# {
# str command_line;
# str error_format;
# bool needs_input;
# str input_file;
# bool list_all;
# bool save_all;
# bool chdir;
# bool background;
# long flags;
# any dos_settings;
# } Compiler;
#
# typedef struct category
# {
# str name;
# long foreground;
# long background;
# } Category;
#
# typedef long Style; // 0xllffccss : ll - column; ff - flags; cc - category; ss - style index
#
# typedef struct type
# {
# bool modified;
# str compiler_name;
# str template;
# str tab_stops;
# str margins;
# str matching_pairs;
# str esc_character;
# int buff_flags;
# str auto_indent;
# int syntax;
# str stile_delimiters;
# bool sensitive; // case sensitive find for keywords;
# int expand; // word processing mode indicator;
# int make_default; // for "type" == CURRENT_BUFFER only
# int apply_to_all; // for "type" == CURRENT_BUFFER only
# Category category[]; // indexed by number; contains category name, fg, bg color;
# Style keyword[]; // indexed by item; contains style;
# Style block[]; // indexed by item; contains style;
# Style line[]; // indexed by item; contains style;
# } Type;
#
# str extensions[]; // Indexed by extension (set to name of type for that extension);
#
# Compiler compilers[]; // Indexed by compiler name;
#
# str templates[]; // Indexed by type; template name for the type;
#
# Type languages[]; // Indexed by type;
#
################################################################################
global extensions[];
global compilers[];
global templates[];
global KEYWORD = 1;
global LINE = 2;
global BLOCK = 4;
################################################################################
# The folllowing functions and variables were put here in order to facilitate the
# exclusion of some pel from the response file;
################################################################################
global language_compiled = FALSE;
global save_languages;
global global_type;
global CURRENT_BUFFER = "Current Buffer";
global DEFAULT = "Default";
global function init_types(handle, buffer_page)
{
local name;
set_dialog_item(handle, IDL_TYPE, DAC_DELETE_ITEM)
for (name in languages)
{
if((name != CURRENT_BUFFER) && (name != DEFAULT))
set_dialog_item(handle, IDL_TYPE, DAC_ADD_ITEM, name "");
}
}
################################################################################
# end of refugee section;
################################################################################
## expand_command()
# function to substitute the components of a filename for the replacable
# characters in the compiler or vcs (or any other) command line.
#
# $< = full file spec
# $r = file name without path or extension (aka, root)
# $e = extension without period
# $p = path with trailing \
# $a = full file spec of the editor's AE file.
#
global function expand_command(cmd, fname)
{
gsub( /\$\</, fname, cmd);
gsub( /\$r/, path_fname(fname), cmd);
gsub( /\$e/, substr( path_ext(fname), 2 ), cmd);
gsub( /\$p/, path_path(fname), cmd);
gsub( /\$a/, locate_cpe_file(CPE_FILE_AE), cmd);
return cmd
}
## add_compiler()
#
# adds information about a compiler to the compilers array.
#
global function add_compiler( name, cmd_line, error_ruleset, needs_input,
input_file, list_all, save_all, chdir,
background, flags )
{
# cvdebug("add_compiler >" name "< called from >" function_caller() "<");
# check required arguments
if ( !name )
warning( "missing compiler_name in call to add_compiler" )
else
{
# if ( !cmd_line )
# warning( "missing command_line in call to add_compiler" )
set_command_line(name, cmd_line);
set_error_format(name, error_ruleset);
set_compiler_input(name, (needs_input+0 > 0), input_file);
set_compiler_output(name, (list_all+0 > 0));
set_compiler_save_all(name, (save_all+0 > 0));
set_compiler_chdir(name, chdir)
set_compiler_background(name, background)
set_compiler_flags(name, flags)
}
}
## edit_compiler()
#
# edits a compiler command string in the compilers array
#
global function edit_compiler( name )
{
local ext
local cmd
if ( !name )
{
# default is filename extension of current buffer
ext = path_ext( buffer_filename )
name = CompilerName(ext);
}
# prompt for compiler command string
if(name)
cmd = CommandLine(name);
cmd = prompt_history("COMPILE", "Enter compiler command: ", cmd, 1, 1)
# update the compiler command array
if(cmd)
set_command_line(name, cmd);
return cmd
}
## delete_compiler()
#
# deletes information about a compiler from the compilers array.
#
global function delete_compiler(comp_name)
{
local type;
# TODO Delete references to the compiler in the languages array also;
# Should it be "" or "[None]"?
delete compilers[comp_name];
for(type in languages)
{
if(CompilerName(type) == comp_name)
set_compiler_name(type, "");
}
}
################################################################################
#
# Utility functions
#
################################################################################
local function getCompiler(index)
{
local compiler = 0;
if(prefix(index, 1) == ".")
{
if(index in extensions)
compiler = languages[extensions[index]].compiler_name;
else
compiler = -1
}
else if(index in languages)
compiler = languages[index].compiler_name;
else
compiler = index
if (!(compiler in compilers))
compiler = -2
return compiler
}
global function Type(ext)
{
local result = "";
if(ext in extensions)
result = extensions[ext];
return result;
}
global function SetType(ext, type)
{
if(type)
extensions[ext] = type;
else
delete extensions[ext];
}
global function CopyType(type, new_type)
{
local word;
languages[new_type].compiler_name = languages[type].compiler_name;
languages[new_type].template = languages[type].template;
languages[new_type].tab_stops = languages[type].tab_stops;
languages[new_type].margins = languages[type].margins;
languages[new_type].matching_pairs = languages[type].matching_pairs;
languages[new_type].buff_flags = languages[type].buff_flags;
languages[new_type].auto_indent = languages[type].auto_indent;
languages[new_type].syntax = languages[type].syntax;
languages[new_type].stile_delimiters = languages[type].stile_delimiters;
languages[new_type].esc_character = languages[type].esc_character;
languages[new_type].sensitive = languages[type].sensitive;
languages[new_type].expand = languages[type].expand;
for(word in languages[type].category)
{
languages[new_type].category[word].name = languages[type].category[word].name;
languages[new_type].category[word].foreground = languages[type].category[word].foreground;
languages[new_type].category[word].background = languages[type].category[word].background;
}
for(word in languages[type].keyword)
{
languages[new_type].keyword[word] = languages[type].keyword[word];
}
for(word in languages[type].line)
{
languages[new_type].line[word] = languages[type].line[word];
}
for(word in languages[type].block)
{
languages[new_type].block[word] = languages[type].block[word];
}
}
################################################################################
#
# Type Query functions
#
################################################################################
global function Modified(index)
{
local result = "";
if(validate_index(index))
index = local_index;
if(index in languages)
result = languages[index].modified;
return result;
}
global function CompilerName(index)
{
local result = "";
if(validate_index(index))
index = local_index;
if(index in languages)
result = languages[index].compiler_name;
return result;
}
#
# Return template of given type/ext. Default is "text"
#
global function Template(index)
{
local result = "text";
if(validate_index(index))
index = local_index;
if(index in languages)
result = languages[index].template;
return result;
}
global function Tabs(index)
{
local result = "";
if(validate_index(index))
index = local_index;
if(index in languages)
result = languages[index].tab_stops;
return result;
}
global function Margins(index)
{
local result = "";
if(validate_index(index))
index = local_index;
if(index in languages)
result = languages[index].margins;
return result;
}
global function LeftMargin(index)
{
local arr, result = "";
if(validate_index(index))
index = local_index;
if(index in languages)
{
split(languages[index].margins, arr);
result = arr[1];
}
return result;
}
global function RightMargin(index)
{
local arr, result = "";
if(validate_index(index))
index = local_index;
if(index in languages)
{
split(languages[index].margins, arr);
result = arr[2];
}
return result;
}
global function MatchingPairs(index)
{
local result = "";
if(validate_index(index))
index = local_index;
if(index in languages)
result = languages[index].matching_pairs;
return result;
}
global function BufferFlags(index)
{
local result = "";
if(validate_index(index))
index = local_index;
if(index in languages)
result = languages[index].buff_flags;
return result;
}
global function AutoIndent(index)
{
local result = "";
if(validate_index(index))
index = local_index;
if(index in languages)
result = languages[index].auto_indent;
return result;
}
global function get_category_name(index, item)
{
local result = "";
if(validate_index(index))
index = local_index;
if((index in languages) && item)
{
result = Block(index, item, CATEGORY_MASK);
if(result < 0)
{
result = Line(index, item, CATEGORY_MASK);
if(result < 0)
result = Keyword(index, item, CATEGORY_MASK);
}
if(result > -1)
result = Category(index, result);
else
result = "";
}
return result;
}
#
# 1 parameter - return category array
# 1 < parameters - if word is an index return name of "word"th category
# or foreground color of category[word]
# or background color of category[word]
# - if word is a category name, return index of category "word"
# or foreground color of category "word"
# or background color of category "word"
#
global function Category(index, word, isfg)
{
local result = "", ind, found = FALSE;
if(validate_index(index))
index = local_index;
if(index in languages)
{
if(argcount() > 1)
{
if(word in languages[index].category)
{
if(isfg == 1)
result = languages[index].category[word].foreground;
else if(isfg == 2)
result = languages[index].category[word].background;
else
result = languages[index].category[word].name;
}
else
{
# word not in category array;
# check to see if word is a category name and not a category index
for(ind in languages[index].category)
{
if(languages[index].category[ind].name == word)
{
found = TRUE;
if(isfg == 1)
result = languages[index].category[ind].foreground;
else if(isfg == 2)
result = languages[index].category[ind].background;
else
result = ind;
break;
}
}
if(!found)
result = -1;
}
}
else
result = languages[index].category;
}
return result;
}
global ITEM_MASK = 0xffffff00;
global CATEGORY_MASK = 0xffff00ff;
global FLAG_MASK = 0xff00ffff;
global COLUMN_MASK = 0x00ffffff;
global function Keyword(index, word, MASK)
{
local result = -1;
if(validate_index(index))
index = local_index;
if(index in languages)
{
if(argcount() >= 2)
{
if(word in languages[index].keyword)
{
if(MASK)
{
result = and(languages[index].keyword[word], not(MASK));
if(MASK == CATEGORY_MASK)
result = shiftr(result, 8);
else if(MASK == FLAG_MASK)
result = shiftr(result, 16);
else if(MASK == COLUMN_MASK)
result = shiftr(result, 24);
}
else
result = languages[index].keyword[word];
}
}
else
result = languages[index].keyword;
}
return result;
}
global function Line(index, word, MASK)
{
local result = -1;
if(validate_index(index))
index = local_index;
if(index in languages)
{
if(argcount() >= 2)
{
if(word in languages[index].line)
{
if(MASK)
{
result = and(languages[index].line[word], not(MASK));
if(MASK == CATEGORY_MASK)
result = shiftr(result, 8);
else if(MASK == FLAG_MASK)
result = shiftr(result, 16);
else if(MASK == COLUMN_MASK)
result = shiftr(result, 24);
}
else
result = languages[index].line[word];
}
}
else
result = languages[index].line;
}
return result;
}
global function Block(index, word, MASK)
{
local result = -1;
if(validate_index(index))
index = local_index;
if(index in languages)
{
if(argcount() >= 2)
{
if(word in languages[index].block)
{
if(MASK)
{
result = and(languages[index].block[word], not(MASK));
if(MASK == CATEGORY_MASK)
result = shiftr(result, 8);
else if(MASK == FLAG_MASK)
result = shiftr(result, 16);
else if(MASK == COLUMN_MASK)
result = shiftr(result, 24);
}
else
result = languages[index].block[word];
}
}
else
result = languages[index].block;
}
return result;
}
global function Syntax(index)
{
local result = "";
if(validate_index(index))
index = local_index;
if(index in languages)
result = languages[index].syntax;
return result;
}
global function StyleDelimiters(index)
{
local result = "";
if(validate_index(index))
index = local_index;
if(index in languages)
result = languages[index].stile_delimiters;
return result;
}
global function get_case_sensitive(index)
{
local result = 0;
if(validate_index(index))
index = local_index;
if(index in languages)
result = languages[index].sensitive;
return result;
}
global function get_expand_template(index)
{
local result = 0;
if(validate_index(index))
index = local_index;
if(index in languages)
result = languages[index].expand;
return result;
}
#
# wp_mode( flags )
#
local WRAP = 0x01
local AUTO_FLOW = 0x02
local CARRY_DOWN_COMMENTS = 0x04
global function wp_mode( flags )
{
local result = 0;
if ( argcount() < 1 )
flags = buffer_flags
if ( and(flags, BUFFER_WP_ENABLED) )
{
result = WRAP;
if ( and(flags, BUFFER_WP_WRAP_CONTINUOUS) )
result = or(result, AUTO_FLOW);
if ( and(flags, BUFFER_WP_CARRY_COMMENTS) )
result = or(result, CARRY_DOWN_COMMENTS);
}
return result;
}
global function get_word_mode(index)
{
local mode
local flags
if ( argcount() < 1 )
{
flags = buffer_flags
}
else
{
if(validate_index(index))
index = local_index;
flags = BufferFlags(index)
}
mode = wp_mode( flags )
return mode
}
global function set_word_mode( mode )
{
if ( argcount() )
{
if ( and(mode, WRAP) )
{
buffer_flags = or( buffer_flags, BUFFER_WP_ENABLED )
if ( and(mode, AUTO_FLOW) )
buffer_flags = or( buffer_flags, BUFFER_WP_WRAP_CONTINUOUS )
else
buffer_flags = and( buffer_flags, not(BUFFER_WP_WRAP_CONTINUOUS) )
if ( and(mode, CARRY_DOWN_COMMENTS) )
buffer_flags = or( buffer_flags, BUFFER_WP_CARRY_COMMENTS )
else
buffer_flags = and( buffer_flags, not(BUFFER_WP_CARRY_COMMENTS) )
}
else
{
buffer_flags = and( buffer_flags, not(BUFFER_WP_ENABLED) )
buffer_flags = and( buffer_flags, not(BUFFER_WP_WRAP_CONTINUOUS) )
buffer_flags = and( buffer_flags, not(BUFFER_WP_CARRY_COMMENTS) )
}
}
}
global function EscapeCharacter(index)
{
local result = "";
if(validate_index(index))
index = local_index;
if(index in languages)
result = languages[index].esc_character;
return result;
}
global function Style(index, item)
{
local result = 0;
if(validate_index(index))
index = local_index;
if(index in languages)
{
if(item in languages[index].block)
result = BLOCK;
else if(item in languages[index].line)
result = LINE;
else if(item in languages[index].keyword)
result = KEYWORD;
}
return result;
}
################################################################################
#
# Type Set functions
#
################################################################################
local local_index;
local function validate_index(index)
{
local ret_val = TRUE;
if(prefix(index, 1) == ".")
{
if(index in extensions)
local_index = extensions[index];
else
{
local_index = DEFAULT;
# warning("tried to use non-existent extension in %s", function_caller());
ret_val = FALSE;
}
}
else
local_index = index;
return ret_val;
}
global function set_modified(index, value)
{
validate_index(index);
languages[local_index].modified = value;
}
global function set_compiler_name(index, value)
{
validate_index(index);
languages[local_index].compiler_name = value;
}
global function set_template(index, value)
{
validate_index(index);
languages[local_index].template = value;
}
global function set_tabs(index, value)
{
validate_index(index);
languages[local_index].tab_stops = value;
}
global function set_pairs(index, value)
{
validate_index(index);
languages[local_index].matching_pairs = value;
}
global function set_margins(index, value)
{
validate_index(index);
languages[local_index].margins = value;
}
global function set_buffer_flags(index, value)
{
validate_index(index);
languages[local_index].buff_flags = value;
}
global function set_auto_indent(index, value)
{
validate_index(index);
languages[local_index].auto_indent = value;
}
global function set_category(index, value1, value2, isfg)
{
local word, i = 1, done = FALSE, count = argcount();
validate_index(index);
if(count >= 3)
{
if(isfg == 1)
languages[local_index].category[value1].foreground = value2;
else if(isfg == 2)
languages[local_index].category[value1].background = value2;
else
languages[local_index].category[value1].name = value2;
}
else if(count == 1)
delete languages[local_index].category;
else
{
do
{
if(i in languages[local_index].category)
i++;
else
{
languages[local_index].category[i].name = value1;
done = TRUE;
}
} while(!done);
}
return i;
}
global function set_keyword(index, value1, value2, MASK)
{
local word;
validate_index(index);
if(argcount() > 2)
{
if(MASK)
{
if(MASK == CATEGORY_MASK)
value2 = shiftl(value2, 8);
else if(MASK == FLAG_MASK)
value2 = shiftl(value2, 16);
else if(MASK == COLUMN_MASK)
value2 = shiftl(value2, 24);
languages[local_index].keyword[value1] = and(languages[local_index].keyword[value1], MASK);
languages[local_index].keyword[value1] = or(languages[local_index].keyword[value1], value2);
}
else
languages[local_index].keyword[value1] = value2;
}
else
{
if(value1)
{
for(word in value1)
languages[local_index].keyword[word] = value1[word];
}
else
delete languages[local_index].keyword;
}
}
global function set_line(index, value1, value2, MASK)
{
local word;
validate_index(index);
if(argcount() > 2)
{
if(MASK)
{
if(MASK == CATEGORY_MASK)
value2 = shiftl(value2, 8);
else if(MASK == FLAG_MASK)
value2 = shiftl(value2, 16);
else if(MASK == COLUMN_MASK)
value2 = shiftl(value2, 24);
languages[local_index].line[value1] = and(languages[local_index].line[value1], MASK);
languages[local_index].line[value1] = or(languages[local_index].line[value1], value2);
}
else
languages[local_index].line[value1] = value2;
}
else
{
if(value1)
{
for(word in value1)
languages[local_index].line[word] = value1[word];
}
else
delete languages[local_index].line;
}
}
global function set_block(index, value1, value2, MASK)
{
local word;
validate_index(index);
if(argcount() > 2)
{
if(MASK)
{
if(MASK == CATEGORY_MASK)
value2 = shiftl(value2, 8);
else if(MASK == FLAG_MASK)
value2 = shiftl(value2, 16);
else if(MASK == COLUMN_MASK)
value2 = shiftl(value2, 24);
languages[local_index].block[value1] = and(languages[local_index].block[value1], MASK);
languages[local_index].block[value1] = or(languages[local_index].block[value1], value2);
}
else
languages[local_index].block[value1] = value2;
}
else
{
if(value1)
{
for(word in value1)
languages[local_index].block[word] = value1[word];
}
else
delete languages[local_index].block;
}
}
global function set_left_margin(index, value)
{
local arr;
validate_index(index);
split(languages[local_index].margins, arr);
languages[local_index].margins = value " " arr[2];
}
global function set_right_margin(index, value)
{
local arr;
validate_index(index);
split(languages[local_index].margins, arr);
languages[local_index].margins = arr[1] " " value;
}
global function set_syntax(index, value)
{
validate_index(index);
languages[local_index].syntax = value;
}
global function set_style_delimiters(index, value)
{
validate_index(index);
languages[local_index].stile_delimiters = value;
}
global function set_case_sensitive(index, value)
{
validate_index(index);
languages[local_index].sensitive = value;
}
global function set_escape_character(index, value)
{
validate_index(index);
languages[local_index].esc_character = value;
}
global function set_expand_template(index, value)
{
validate_index(index);
languages[local_index].expand = value;
}
################################################################################
#
# Compiler Query Functions
#
################################################################################
global function CommandLine(index, expand, fname)
{
local result
local compiler = getCompiler(index)
if (compiler+0 < 0)
result = ""
else
{
result = compilers[compiler].command_line;
if(expand)
{
result = expand_command(result, fname)
# gsub( /\$\</, fname, result);
# gsub( /\$r/, path_fname(fname), result);
# gsub( /\$e/, substr( path_ext(fname), 2 ), result);
# gsub( /\$p/, path_path(fname), result);
# gsub( /\$a/, locate_cpe_file(CPE_FILE_AE), result);
}
}
return result
}
global function ErrorFormat(index)
{
local result
local compiler = getCompiler(index)
if (compiler+0 < 0)
result = compiler
else
result = compilers[compiler].error_format;
return result;
}
global function CompilerInput(index)
{
local file
local state
local compiler = getCompiler(index)
if (compiler+0 < 0)
state = compiler - 1
else if (compilers[compiler].needs_input)
{
state = 1
file = compilers[compiler].input_file;
}
else
state = -1
return (state > 0) && length(file) ? file : state;
}
global function CompilerSaveAll(index)
{
local result = FALSE, compiler = getCompiler(index)
if(compiler+0 < 0)
result = compiler - 1
else
result = compilers[compiler].save_all;
return result;
}
global function CompilerOutput(index)
{
local state
local compiler = getCompiler(index)
if (compiler+0 < 0)
state = compiler
else
state = compilers[compiler].list_all
return state;
}
global function CompilerChdir(index)
{
local state
local compiler = getCompiler(index)
if (compiler+0 < 0)
state = compiler
else
state = compilers[compiler].chdir
return state;
}
global function CompilerBackground(index)
{
local state
local compiler = getCompiler(index)
if (compiler+0 < 0)
state = compiler
else
state = compilers[compiler].background
return state;
}
global function CompilerFlags(index)
{
local state
local compiler = getCompiler(index)
if (compiler+0 < 0)
state = compiler
else
state = compilers[compiler].flags
return state;
}
global function CompilerDOSSettingsArray(index)
{
local result
local compiler = getCompiler(index)
if (compiler+0 < 0)
result = compiler
else
result = compilers[compiler].dos_settings
return result;
}
################################################################################
#
# Compiler Set Functions
#
################################################################################
global function set_command_line(compiler, value)
{
compilers[compiler].command_line = value;
}
global function set_error_format(compiler, value)
{
compilers[compiler].error_format = value;
}
global function set_compiler_input(compiler, state, file)
{
compilers[compiler].needs_input = state;
compilers[compiler].input_file = state ? file : "";;
}
global function set_compiler_save_all(compiler, save)
{
compilers[compiler].save_all = save;
}
global function set_compiler_output(compiler, state)
{
compilers[compiler].list_all = state;
}
global function set_compiler_chdir(compiler, state)
{
compilers[compiler].chdir = state;
}
global function set_compiler_background(compiler, state)
{
compilers[compiler].background = state;
}
global function set_compiler_flags(compiler, state)
{
compilers[compiler].flags = state;
}
global function set_compiler_dos_settings_array(compiler, table)
{
compilers[compiler].dos_settings = table;
}
global function set_compiler_dos_setting(compiler, setting, value)
{
compilers[compiler].dos_settings[setting] = value;
}
global function copy_compiler(old, new)
{
local setting;
compilers[new].command_line = compilers[old].command_line;
compilers[new].error_format = compilers[old].error_format;
compilers[new].needs_input = compilers[old].needs_input;
compilers[new].input_file = compilers[old].input_file;
compilers[new].save_all = compilers[old].save_all;
compilers[new].list_all = compilers[old].list_all;
compilers[new].chdir = compilers[old].chdir;
compilers[new].background = compilers[old].background;
compilers[new].flags = compilers[old].flags;
delete compilers[new].dos_settings;
for(setting in compilers[old].dos_settings)
compilers[new].dos_settings[setting] = compilers[old].dos_settings[setting];
}
################################################################################
global function add_extension(ext, type)
{
extensions[ext] = type;
}
global function add_syntax_item(type, style, word, value, MASK)
{
if((style != LINE) && (style != KEYWORD) && (style != BLOCK))
style = tolower(style);
if((style == LINE) || (style == "line"))
set_line(type, word, value+0, MASK);
else if((style == KEYWORD) || (style == "keyword"))
set_keyword(type, word, value+0, MASK);
else if((style == BLOCK) || (style == "block"))
set_block(type, word, value+0, MASK);
}
global function add_syntax_category(type, index, name, fg, bg)
{
if(index < 0)
{
# Check to see if name is already a category name;
index = Category(type, name) +0;
if(index < 0)
{
index = set_category(type, name); # Add it and get its index;
}
}
set_category(type, index, name);
set_category(type, index, fg, 1);
set_category(type, index, bg, 2);
}
global function add_type(index, comp_name, plate, stops, mrgns, matching,
esc_char, flags, indent, syntx, stile_delims, no_case, expand_temp)
{
if(argcount() > 1)
{
languages[index].compiler_name = comp_name;
languages[index].template = plate;
languages[index].tab_stops = stops;
languages[index].margins = mrgns;
languages[index].matching_pairs = matching;
languages[index].buff_flags = flags;
languages[index].auto_indent = indent;
languages[index].syntax = syntx;
languages[index].stile_delimiters = stile_delims;
languages[index].esc_character = esc_char;
languages[index].sensitive = no_case;
languages[index].expand = expand_temp;
}
else if(index == CURRENT_BUFFER)
{
languages[index].compiler_name = "";
languages[index].template = "";
languages[index].tab_stops = buffer_tabs;
languages[index].margins = wp_left_margin " " wp_right_margin;
languages[index].matching_pairs = matching_pairs;
languages[index].buff_flags = buffer_flags;
languages[index].auto_indent = auto_indent_mode;
languages[index].syntax = syntax_highlight;
languages[index].stile_delimiters = style_delimiter;
languages[index].esc_character = escape_character;
languages[index].sensitive = case_insensitive;
languages[index].expand = electric_mode;
}
else
{
languages[index].compiler_name = "";
languages[index].template = "";
languages[index].tab_stops = default_buffer_tabs;
languages[index].margins = default_wp_left_margin " " default_wp_right_margin;
languages[index].matching_pairs = default_matching_pairs;
languages[index].buff_flags = default_buffer_flags;
languages[index].auto_indent = auto_indent_mode;
languages[index].syntax = default_syntax_highlight;
languages[index].stile_delimiters = style_delimiter;
languages[index].esc_character = escape_character;
languages[index].sensitive = case_insensitive;
languages[index].expand = 0;
}
set_factory_categories(index);
# add_syntax_category(index, 0, "All", COLOR_RED, -1);
}
global function delete_type(type)
{
local ext;
reset_languages(0);
delete languages[type];
reset_languages(1);
for(ext in extensions)
if(Type(ext) == type)
SetType(ext, "");
}
global function delete_keyword(type, word)
{
local value;
validate_index(type);
value = languages[local_index].keyword[word];
delete languages[local_index].keyword[word]
return value;
}
################################################################################
#
# Load default functions
#
################################################################################
global function load_factory_default_extensions(add)
{
if(!add)
delete extensions;
extensions[".ada"] = "ada";
extensions[".asm"] = "assembler";
extensions[".awk"] = "awk";
extensions[".bas"] = "basic";
extensions[".bat"] = "batch";
extensions[".c"] = "c";
extensions[".h"] = "c";
extensions[".cpp"] = "c";
extensions[".hpp"] = "c";
extensions[".cxx"] = "c";
extensions[".hxx"] = "c";
extensions[".cbl"] = "cobol";
extensions[".cob"] = "cobol";
extensions[".f"] = "fortran";
extensions[".for"] = "fortran";
extensions[".ipf"] = "helpfile";
extensions[".mak"] = "makefile";
extensions[".pas"] = "pascal";
extensions[".pel"] = "pel";
extensions[".rc"] = "rc";
extensions[".dlg"] = "rc";
extensions[".cmd"] = "rexx";
extensions[".txt"] = "text";
}
global function load_factory_default_compilers(add)
{
if(!add)
delete compilers
add_compiler("Advantage ADA", "ada $<", "ada");
add_compiler("Borland C++", "bcc -c $<", "turboc");
add_compiler("COBOL Compiler", "cobol $<", "other");
add_compiler("Clipper 5.0", "clipper $< /s /w /m", "clipper5");
add_compiler("Clipper Summer '87", "clipper $< -m -s", "clipper87");
add_compiler("Clipper Summer '87 (preprocessor)", "pre $<", "clipper87");
add_compiler("DOS Command Interpeter", "command.com /c $<", "none", 1, "", 1, 0, 0, 0, 512);
add_compiler("FORCE dBase Compiler", "force $<", "force");
add_compiler("IBM CSet++", "icc $<", "generic");
add_compiler("INTERSOLV PVCS Builder", "build -f $<", "build");
add_compiler("INTERSOLV PolyMake", "make -f $<", "polymake");
add_compiler("Lahey FORTRAN 77", "f77l $<", "lahey");
add_compiler("Microsoft C", "cl -c $<", "c");
add_compiler("Microsoft Masm", "masm $<,nul,asm.err;", "asm");
add_compiler("Microsoft Quick BASIC", "qb $<", "bas");
add_compiler("NMake", "nmake -f $<", "nmake");
add_compiler("PEL Compiler", "pel -o $a -adis $<", "pel");
add_compiler("Resource Compiler", "rc -r $<", "generic", 0, "");
add_compiler("REXX Interpeter", "cmd.exe /c $<", "none", 1, "", 1);
add_compiler("Thompson Tools Awk Compiler", "awkc $<", "none");
add_compiler("Turbo C", "tcc -c -w $<", "turboc");
add_compiler("Turbo C++", "tcc -c $<", "turboc");
add_compiler("Turbo Pascal", "tpc $<", "pas");
add_compiler("Watcom C++", "wcc386 -c $<", "watcom");
add_compiler("Zortech C", "ztc -c -r $<", "zortech");
add_compiler("Zortech C++", "ztc -c -cpp -r $<", "zortech");
add_compiler("[None]", "$<", "none");
}
global function load_factory_default_types(add)
{
local tab_stops = default_buffer_tabs;
local margins = wp_left_margin " " wp_right_margin;
local matching = default_matching_pairs;
local escchar = "\\"
local flags = default_buffer_flags;
local indent = 0;
local syntax = 1;
local c_pairs = "{ } [ ] ( ) /* */ #if #endif #ifdef #endif";
local c_tabs = "4 7";
local delimiter = "()[];:,='"
local no_case = 1;
# ext = ".prg"
# extension_array[ext].tabs = "5 9"
# if(!add)
# {
# reset_languages(0);
# delete languages;
# }
# Cobol should have expand tabs on;
add_type("ada", "Advantage ADA", "c", "5 9", margins, "begin end (* *) { }", escchar, flags, indent, syntax, delimiter, no_case);
add_type("assembler", "Microsoft Masm", "asm", "5 9", margins, c_pairs, escchar, flags, indent, syntax, delimiter, no_case);
optional_function("add_awk_type");
add_type("batch", "DOS Command Interpeter", "[None]", "4 7", "1 77", "{ } [ ] ( ) /* */ %if %endif #if #endif #ifdef #endif", "", 8448, 0, 1, "", 0, 0);
add_type("basic", "IBM Basic", "basic", tab_stops, margins, "", escchar, flags, indent, syntax, delimiter, no_case);
add_type("c", "Borland C++", "c", c_tabs, margins, c_pairs, escchar, flags, indent, syntax, delimiter, no_case);
optional_function("add_cobol_type");
add_type("fortran", "Lahey FORTRAN 77", "text", tab_stops, margins, "", escchar, flags, indent, syntax, delimiter, no_case);
add_type("helpfile", "IPFC", "text", tab_stops, margins, "", escchar, flags, indent, syntax, delimiter, no_case);
add_type("makefile", "NMake", "text", tab_stops, margins, "( ) %if %endif", escchar, flags, indent, syntax, delimiter, no_case);
optional_function("add_pascal_type");
optional_function("add_pel_type");
optional_function("add_rexx_type");
add_type("rc", "Resource Compiler", "", "4 7", "1 77", "{ } [ ] ( ) /* */ %if %endif #if #endif #ifdef #endif begin end", "", 8448, 0, 1, "", 0, 0);
add_type("rexx", "REXX Interpeter", "rexx", "4 7", "1 77", "{ } [ ] ( ) /* */ %if %endif #if #endif #ifdef #endif", "\\", 8448, 0, 1, ".();,=':", 1, 0);
add_type("text", "", "text", tab_stops, margins, "", escchar, flags, indent, syntax, delimiter, no_case);
optional_function("add_vdiff_ref_type");
optional_function("add_vdiff_target_type");
add_type(DEFAULT);
# add_type("[None]", comp_name, template, tab_stops, margins, "", escchar, syntax, delimiter, no_case);
# if(!add)
# reset_languages(1);
}
################################################################################
#
# Copy array functions
#
################################################################################
global function copy_extensions_array(input)
{
local ext, result[];
for(ext in input)
result[ext] = input[ext];
return result;
}
global function copy_compilers_array(input)
{
local comp, result[], setting;
for(comp in input)
{
result[comp].error_format = input[comp].error_format;
result[comp].command_line = input[comp].command_line;
result[comp].needs_input = input[comp].needs_input;
result[comp].inpput_file = input[comp].input_file;
result[comp].list_all = input[comp].list_all;
result[comp].save_all = input[comp].save_all;
result[comp].chdir = input[comp].chdir;
result[comp].background = input[comp].background;
result[comp].flags = input[comp].flags;
for(setting in input[comp].dos_settings)
result[comp].dos_settings[setting] = input[comp].dos_settings[setting];
}
return result;
}
global function copy_languages_array(input)
{
local type, result[], word;
for(type in input)
{
result[type].compiler_name = input[type].compiler_name;
result[type].template = input[type].template;
result[type].tab_stops = input[type].tab_stops;
result[type].margins = input[type].margins;
result[type].matching_pairs = input[type].matching_pairs;
result[type].buff_flags = input[type].buff_flags;
result[type].auto_indent = input[type].auto_indent;
result[type].esc_character = input[type].esc_character;
result[type].stile_delimiters = input[type].stile_delimiters;
result[type].syntax = input[type].syntax;
result[type].sensitive = input[type].sensitive;
result[type].expand = input[type].expand;
for(word in input[type].category)
result[type].category[word] = input[type].category[word];
for(word in input[type].keyword)
result[type].keyword[word] = input[type].keyword[word];
for(word in input[type].line)
result[type].line[word] = input[type].line[word];
for(word in input[type].block)
result[type].block[word] = input[type].block[word];
}
return result;
}
#global function copy_languages_array(input, page)
#{
# local type, result;
#
# for(type in input)
# {
# if(page && (page == "compiler"))
# result[type].compiler_name = input[type].compiler_name;
# else if(page && (page == "template"))
# result[type].template = input[type].template;
# else if(page && (page == "syntax"))
# result[type].syntax = input[type].syntax;
# else if(page && (page == "buffer2"))
# {
# result[type].tab_stops = input[type].tab_stops;
# result[type].margins = input[type].margins;
# result[type].matching_pairs = input[type].matching_pairs;
# result[type].buff_flags = input[type].buff_flags;
# result[type].auto_indent = input[type].auto_indent;
# }
# }
#
# return result;
#}
################################################################################
#
# Write structure functions
#
################################################################################
global function write_language_data()
{
local fname, prevEol, old_buffer = current_buffer, out_fid, outfile, status, cmd;
local language_buffer, dlgid, response = "y", old_beep = beep_string;
local pel_comp
local array[]
fname = source_file_name(function_id("load_user_types"));
if(!fname)
{
warning("language.pel could not be found. All notebook changes will be lost.");
return 2;
}
prevEol = default_buffer_eol_string;
default_buffer_eol_string = "\r\n";
language_buffer = create_buffer( "Language File" , fname, BUFFER_SYSTEM +
BUFFER_NO_UNDO +
BUFFER_REAL_SPACE_ONLY);
current_buffer = language_buffer;
# restore the default end of line sequence
default_buffer_eol_string = prevEol;
# TODO: do a check here to see if the arrays are changed before writing them and compiling;
# should only really compile if we have to;
if(and(buffer_flags, BUFFER_READ_ONLY))
{
set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
response = confirm(fname " is read only. Do you want to save settings changes anyway? (yn)", "YyNn");
restore_status_bar();
if(tolower(response) == "y")
toggle_buffer_flags(BUFFER_READ_ONLY, FALSE);
}
if(response == "y")
{
beep_string = "";
write_extensions();
write_compilers();
write_types();
write_styles();
write_syntax();
write_colors();
write_buffer();
delete_buffer(language_buffer);
current_buffer = old_buffer;
cmd = CommandLine(".pel", 1, fname);
outfile = create_temp_name(0, "err", "pel_" );
if ( (out_fid = fopen( outfile, 2 )) != -1 )
{
message("compiling %s", fname)
status = system(cmd, 0, out_fid, out_fid, SYS_NOSESSION)
fclose( out_fid );
if (status > 0)
{
if(status == 65526)
{
# unlink(outfile);
warning("Invalid PEL compiler found. Please change compile line for the PEL type.");
}
else
display_errors(fname, outfile);
}
else if ( status == -2 )
{
warning("PEL Compiler not found. Check command line for the compiler mapped to the '.pel' extension.");
language_compiled = TRUE; # This is set so we don't end up here again;
}
else
{
# unlink(outfile);
if(status == -10)
warning("Invalid PEL compiler found. Please change compile line for the PEL type.");
else if (status < 0)
warning("Unable to compile %s, Error %s", fname, status)
else
message("")
}
unlink(outfile);
}
language_compiled = TRUE;
beep_string = old_beep;
}
else
{
warning("Changes made to the language structure in the notebook have not been saved.");
delete_buffer(language_buffer);
current_buffer = old_buffer;
}
}
local function my_quote(string)
{
local r = string;
gsub( "[\"\\\\]", "\\\\&", r);
return r
}
local function write_extensions()
{
local outline, ext;
create_header("extensions");
for(ext in extensions)
{
outline = sprintf(" add_extension(\"%s\", \"%s\");\n", my_quote(ext),
my_quote(Type(ext)) );
insert_string(outline);
}
end_section("extensions");
}
local function write_compilers()
{
local cname, outline, s;
create_header("compilers");
for(cname in compilers)
{
outline = sprintf(" add_compiler(\"%s\", \"%s\", \"%s\", %d, \"%s\", %d, %d, %d, %d, %d);\n",
my_quote(cname),
my_quote(compilers[cname].command_line),
my_quote(compilers[cname].error_format),
compilers[cname].needs_input > 0,
my_quote(compilers[cname].input_file),
compilers[cname].list_all > 0,
compilers[cname].save_all > 0,
compilers[cname].chdir > 0,
compilers[cname].background > 0,
compilers[cname].flags > 0 ? compilers[cname].flags : 0);
insert_string(outline);
if (compilers[cname].flags > 0 && and(compilers[cname].flags, SYS_DOSSHELL))
{
for (s in compilers[cname].dos_settings)
{
if (length(s) && length(compilers[cname].dos_settings[s]))
{
outline = sprintf(" set_compiler_dos_setting(\"%s\", \"%s\", \"%s\");\n",
my_quote(cname), my_quote(s),
my_quote(compilers[cname].dos_settings[s]));
insert_string(outline);
}
}
}
}
end_section("compilers");
}
local function write_types()
{
local type, outline;
create_header("types");
for(type in languages)
{
# if((type != DEFAULT) && (type != CURRENT_BUFFER))
if(type != CURRENT_BUFFER)
{
outline = sprintf(" add_type(\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", %d, %d, %d, \"%s\", %d, %d);\n",
my_quote(type), my_quote(CompilerName(type)),
my_quote(Template(type)), my_quote(Tabs(type)),
my_quote(Margins(type)), my_quote(MatchingPairs(type)),
quote_regex(EscapeCharacter(type)), BufferFlags(type),
AutoIndent(type), Syntax(type),
my_quote(StyleDelimiters(type)), get_case_sensitive(type),
get_expand_template(type) );
insert_string(outline);
}
}
end_section("types");
}
global function write_syntax()
{
local type, outline, array, item, line_count;
local suffix = "", MAX = 200;
for(type in languages)
{
if((type != CURRENT_BUFFER) && (type != DEFAULT) && Modified(type))
{
line_count = 0;
suffix = "";
create_header(type "_syntax" suffix);
insert_string(" local type = \"" my_quote(type) "\";\n\n");
line_count++;
array = Line(type);
for(item in array)
{
outline = sprintf(" add_syntax_item(type, LINE, \"%s\", 0x%x);\n",
my_quote(item), array[item]);
insert_string(outline);
if(line_count++ > MAX)
{
suffix = start_new_function(type, suffix);
line_count = 1;
}
}
array = Keyword(type);
for(item in array)
{
outline = sprintf(" add_syntax_item(type, KEYWORD, \"%s\", 0x%x);\n",
my_quote(item), array[item]);
insert_string(outline);
if(line_count++ > MAX)
{
suffix = start_new_function(type, suffix);
line_count = 1;
}
}
array = Block(type);
for(item in array)
{
outline = sprintf(" add_syntax_item(type, BLOCK, \"%s\", 0x%x);\n",
my_quote(item), array[item]);
insert_string(outline);
if(line_count++ > MAX)
{
suffix = start_new_function(type, suffix);
line_count = 1;
}
}
array = Category(type);
for(item in array)
{
outline = sprintf(" add_syntax_category(type, %d, \"%s\", %d, %d);\n",
item, my_quote(array[item].name),
array[item].foreground, array[item].background);
insert_string(outline);
if(line_count++ > MAX)
{
suffix = start_new_function(type, suffix);
line_count = 1;
}
}
end_section(type "_syntax" suffix);
}
}
}
local function start_new_function(type, suffix)
{
local old_name = type "_syntax" suffix;
local new_name = type "_syntax"
local new_suffix;
new_suffix = suffix + 1;
new_name = new_name new_suffix;
insert_string("\n # Function too long, had to be split\n");
insert_string(" load_user_" new_name "(type);\n");
end_section(old_name);
create_header(new_name, 1);
return new_suffix;
}
local function write_styles()
{
local n = 1, FG = 0, BG = 1, still_valid = TRUE;
local fg, bg, BAD = 0xFF000000, outline;
local at_least_one = FALSE;
create_header("styles");
while((n < 256) && still_valid)
{
fg = query_syntax_style(n, FG);
bg = query_syntax_style(n, BG);
still_valid = ((fg != BAD) && (bg != BAD));
if(still_valid)
{
at_least_one = TRUE;
outline = sprintf(" defined_styles[%d][%d] = ", fg, bg);
insert_string(outline);
if((fg < 0) || (bg < 0))
{
if((fg < 0) && (bg < 0))
outline = sprintf("create_syntax_style(%d, %d);\n", fg, bg);
else if(fg <0)
outline = sprintf("create_syntax_style(%d, 0x%lx);\n", fg, bg);
else
outline = sprintf("create_syntax_style(0x%lx, %d);\n", fg, bg);
}
else
outline = sprintf("create_syntax_style(0x%lx, 0x%lx);\n", fg, bg);
insert_string(outline);
}
n++;
}
if(!at_least_one)
insert_string("optional_function(\"load_factory_default_styles\");\n");
end_section("styles");
}
local function write_colors()
{
local color, outline;
create_header("syntax_colors");
insert_string(" # Foreground colors for syntax highlighting\n");
for(color in syntax_colors_fg)
{
outline = sprintf(" syntax_colors_fg[%d] = 0x%06x;\n", color, syntax_colors_fg[color]);
insert_string(outline);
}
insert_string("\n # Background colors for syntax highlighting\n");
for(color in syntax_colors_bg)
{
outline = sprintf(" syntax_colors_bg[%d] = 0x%06x;\n", color, syntax_colors_bg[color]);
insert_string(outline);
}
end_section("syntax_colors");
}
local function create_header(type, parm)
{
save_position();
goto_buffer_top();
if(!search("function load_user_" type "(", SEARCH_FORWARD))
{
restore_position(TRUE);
if(parm)
insert_string("\nlocal function load_user_" type "(type)\n{\n\n\n} # End " type "\n");
else
insert_string("\nglobal function load_user_" type "()\n{\n\n\n} # End " type "\n");
up(5);
}
else
{
restore_position();
}
down(2);
goto_bol();
}
local function end_section(type)
{
begin_selection(NORMAL_SELECTION);
if(search("} # End "type, SEARCH_FORWARD))
{
up();
goto_bol();
delete_chars();
down(2);
}
else
{
end_selection();
}
}