home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
BSUPPORT.PEL
< prev
next >
Wrap
Text File
|
1995-02-10
|
18KB
|
700 lines
# $Header: P:\source\wmacros\bsupport.pev 1.8 10 Feb 1995 12:31:08 PFHJXM0 $
##############################################################################
#
##
## 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: bsupport.pel $: support modules for brief translated macros
#
# This module provides entry points for Brief compatible functionality.
# Whenever Brief macros are translated (using b2p.exe), the resulting code
# calls the functions below. This is generally the only use of the functions.
#
local bsupport_months;
local bsupport_bookmark_buffer[];
local bsupport_bookmark_line[];
local bsupport_bookmark_column[];
BEGIN {
bsupport_months[ "Jan" ] = 1
bsupport_months[ "Feb" ] = 2
bsupport_months[ "Mar" ] = 3
bsupport_months[ "Apr" ] = 4
bsupport_months[ "May" ] = 5
bsupport_months[ "Jun" ] = 6
bsupport_months[ "Jul" ] = 7
bsupport_months[ "Aug" ] = 8
bsupport_months[ "Sep" ] = 9
bsupport_months[ "Oct" ] = 10
bsupport_months[ "Nov" ] = 11
bsupport_months[ "Dec" ] = 12
}
function copy_keyboard(keymap_id)
{
warning("Body needed... see bsupport.pel @ copy_keyboard()");
}
global function inq_brief_level(){
return 0;
}
global function bsupport_atoi( str, standard ){
if (0+standard == 0)
return atoi( substr(str,1,1));
else
return atoi(str);
}
## ------- support routines for find_file()
#
local bsupport_first_find_file = 1;
local bsupport_find_file_pattern = "";
local bsupport_find_file_name;
function bsupport_file_pattern( pattern ){
bsupport_find_file_pattern = pattern;
bsupport_first_find_file = 1;
}
function bsupport_find_file( pattern, name, size, date, time, attribute ){
return pattern;
}
function bsupport_find_first(){
if (bsupport_find_file_pattern){
if (bsupport_first_find_file) {
bsupport_first_find_file = 0;
return bsupport_find_file_name = findfirst( bsupport_find_file_pattern );
} else {
return bsupport_find_file_name = findnext();
}
}
}
function bsupport_find_file_name(){
return path_fname( bsupport_find_file_name ) path_ext( bsupport_find_file_name );
}
function bsupport_filedate(){}
function bsupport_filetime(){}
#
#------------------- end of find_file() support
function bsupport_borders( mode ) {
if (argcount())
toggle_borders( mode )
else
toggle_borders();
}
function bsupport_cd( dir ){
if (dir)
return chdir( dir )
message( getcwd() );
return 1;
}
local NORTH = 0x01
local EAST = 0x02
local SOUTH = 0x04
local WEST = 0x08
local function bsupport_window_edge( direction ) {
if (direction+0 == 0)
return NORTH;
else if (direction+0 == 1)
return EAST;
else if (direction+0 == 2)
return SOUTH;
else if (direction+0 == 3)
return WEST;
return -1;
}
function bsupport_change_window( direction )
{
return next_window();
# if (argcount())
# return brief_change_window( bsupport_window_edge( direction ))
# else
# return brief_change_window();
}
function bsupport_create_edge( direction ){
if (argcount())
return brief_create_window( bsupport_window_edge( direction ))
else
return brief_create_window();
}
function bsupport_delete_edge( direction ){
if (argcount())
return brief_delete_window( bsupport_window_edge( direction ))
else
return brief_delete_window();
}
function bsupport_display_windows(turn_on)
{
if(turn_on)
window_tile();
else
delete_all_windows();
}
function bsupport_move_edge( direction, amount ){
if (argcount())
return brief_resize_window( bsupport_window_edge( 0+direction), amount+0)
else
return brief_resize_window();
}
function bsupport_cut( append )
{
local status, top_id, bottom_id;
if (argcount() && 0+append)
{
top_id = selection_mark_top();
bottom_id = selection_mark_bottom();
status = copy_to_scrap_key( 0+append );
goto_mark(top_id);
begin_selection(NORMAL_SELECTION);
goto_mark(bottom_id);
delete_chars();
end_selection();
}
else
status = delete_to_scrap();
return status
}
function bsupport_date( year, month, day, month_string, weekday_string){}
function bsupport_drop_bookmark( bnum, overwrite, buffer_id, line, column ){
local status = 1;
local num;
local oldbuf = current_buffer;
local newbuf = current_buffer;
local mdefined = 0;
if (argcount() < 1) {
bnum = confirm( "Drop bookmark[0-9]?", "0123456789" );
if (!bnum)
return 0;
}
num = 0 + bnum;
if (num == 0)
num = 10;
if (overwrite != "y")
overwrite = "n"
if ( argcount() > 2 ) {
if (current_buffer != buffer_id) {
current_buffer = buffer_id;
if (current_buffer == oldbuf)
return 0;
newbuf = current_buffer;
mdefined = mark_defined( num );
current_buffer = oldbuf;
}
} else {
line = current_line;
column = current_column;
}
if ( mdefined && (overwrite != "y"))
if (tolower(confirm( "Overwrite existing bookmark [yn]?", "yYnN" )) \
!= "y")
return 0;
current_buffer = newbuf;
status = create_mark( num, line, column );
bsupport_bookmark_buffer[ num ] = current_buffer;
bsupport_bookmark_line[ num ] = line;
bsupport_bookmark_column[ num ] = column;
current_buffer = oldbuf;
return status;
}
global function bsupport_goto_bookmark( success, num, buffid, line, column ){
return success;
}
global function bsupport_find_bookmark( bnum ){
local num;
if (argcount() != 1){
bnum = confirm( "Go to bookmark[1-10]? ", "0123456789" );
if (!bnum)
return 0;
}
num = 0 + bnum;
if ( !bsupport_bookmark_buffer[ num ] )
return 0;
current_buffer = bsupport_bookmark_buffer[ num ];
current_line = bsupport_bookmark_line[ num ];
current_column = bsupport_bookmark_column[ num ];
return 1;
}
global function bsupport_inq_mark_size(){
local diff, i
local mark2
if (selection_type()) {
save_position()
goto_mark( selection_mark_top() )
if ( selection_type() == 3 ) { # line selection
goto_bol()
}
i = buffer_offset
mark2 = selection_mark_bottom()
if ( mark2 ){
goto_mark( mark2 )
} else {
restore_position(1)
save_position()
}
if (selection_type() == 3) { # line selection
goto_eol()
}
diff = buffer_offset - i
restore_position(1);
return diff;
} else {
return 0;
}
}
function bsupport_inq_modified( buffid ) {
return bsupport_inq_buffer_flag( buffid, BUFFER_MODIFIED );
}
function bsupport_inq_system( buffid ) {
return bsupport_inq_buffer_flag( buffid, BUFFER_SYSTEM );
}
function bsupport_inq_buffer_flag( buffid, flag )
{
local save_buffid;
local bflag = and( buffer_flags, flag );
if (buffid) {
save_buffid = current_buffer;
current_buffer = buffid;
bflag = and( buffer_flags, flag );
current_buffer = save_buffid;
}
return bflag;
}
function bsupport_inq_marked( a,b,c,d )
{
return selection_type();
}
function bsupport_inq_names( full_name, extension, buffer_name ){}
function bsupport_inq_position( line, col ){return 0;}
function bsupport_inq_screen_size( line, col ){}
function bsupport_inq_window_size( line, col, shift ){}
# TODO;
# This function should be removed and, the translator should use toggle_buffer_flags
#
#function bsupport_insert_mode( insert )
#{
# if (argcount())
# toggle_insert_mode( insert );
# else
# toggle_insert_mode();
#}
function bsupport_inq_views( buffid )
{
return buffer_views( buffid );
}
function bsupport_keyboard_typeables(){
local i;
for (i = 32; i < 127; i++)
assign_key( chr(i), "insert_key" );
assign_key( "<Backspace>", "brief_backspace" );
assign_key( "<Tab>", "insert_key" );
assign_key( "<Enter>","insert_newline" );
}
function bsupport_mark( type ) {
type = 0+type
if ((type == 1) || (!argcount()) )
set_exclusive_mark();
else if (type == 2)
set_column_mark();
else if (type == 3)
set_line_mark();
else if (type == 4)
set_inclusive_mark();
}
function bsupport_move_rel( lines, cols )
{
local old_line = current_line, old_column = current_column;
goto_pos(current_line + lines, current_column + cols);
return !((old_line == current_line) && (old_column == current_column));
}
function bsupport_pause_on_error( mode ) {
if (!argcount())
pause_on_error = !pause_on_error;
else
pause_on_error = 0+mode;
}
function bsupport_time( hours, minutes, seconds ){}
function bsupport_translate( patt, repl, gflag, reflag, cflag, bflag, fflag ) {
local i = argcount();
search_flags = or(SEARCH_REGEX+SEARCH_FORWARD, and(search_flags,SEARCH_CASE));
if ((i >= 3) && (typeof(gflag) == "int"))
if (gflag)
search_flags = or(search_flags,SEARCH_GLOBAL);
if ((i >= 4) && (typeof(reflag) == "int" ))
if (!reflag)
search_flags = xor(search_flags, SEARCH_REGEX);
if ((i >= 5) && (typeof(cflag) == "int")) {
if (cflag)
search_flags = or(search_flags, SEARCH_CASE );
else
search_flags = and( search_flags, not(SEARCH_CASE) );
}
if ((i >= 6) && (typeof(bflag) == "int"))
if (bflag)
search_flags = or(search_flags, SEARCH_BLOCK);
if ((i <= 7) && (typeof(fflag) == "int"))
if (!fflag)
search_flags = xor(search_flags, SEARCH_FORWARD);
if (and(search_flags, SEARCH_REGEX)) {
if ((i >= 1) && patt)
patt = bsupport_new_regex_pattern( patt, 0 );
if ((i >= 2) && repl)
repl = bsupport_new_regex_pattern( repl, 1 );
}
if (and(search_flags, SEARCH_FORWARD))
replace_forward( patt, repl );
else
replace_backward( patt, repl );
}
function bsupport_color( back, normal, sel, msgs, errs, marked ) {
local i = argcount();
if (i >= 1) {
color_window_bg = convert_color(back);
if (i >= 2) {
color_window_fg = convert_color(normal);
if (i >= 3) {
if (i >= 4) {
color_message_fg = convert_color(msgs);
if (i >= 5) {
color_warning_fg = convert_color(errs);
}
}
}
}
}
}
local BLACK = 0;
local BLUE = 1;
local GREEN = 2;
local CYAN = 3;
local RED = 4;
local MAGENTA = 5;
local BROWN = 6;
local WHITE = 7;
local DKGREY = 8;
local BRBLUE = 9;
local BRGREEN = 10;
local BRCYAN = 11;
local BRRED = 12;
local BRMAGENTA = 13;
local YELLOW = 14;
local BRWHITE = 15;
function convert_color(index)
{
local result;
if(index == BLACK) result = 0x00000000;
if(index == BLUE) result = 0x000000ff;
if(index == GREEN) result = 0x0000ff00;
if(index == CYAN) result = 0x0000ffff;
if(index == RED) result = 0x00ff0000;
if(index == MAGENTA) result = 0x00ff00ff;
if(index == BROWN) result = 0x00000000;
if(index == WHITE) result = 0x00ffffff;
if(index == DKGREY) result = 0x00333333;
if(index == BRBLUE) result = 0x00000088;
if(index == BRGREEN) result = 0x00008800;
if(index == BRCYAN) result = 0x00008888;
if(index == BRRED) result = 0x00880000;
if(index == BRMAGENTA) result = 0x00880088;
if(index == YELLOW) result = 0x00ffff00;
if(index == BRWHITE) result = 0x00ffffff;
return result;
}
function bsupport_registered_macroid( id ) {
if (id == 0)
return EVENT.KEYPRESS;
else if (id == 1)
return EVENT.NEW_CURNT_BUFFER;
else if (id == 2)
return EVENT.HELP_INVOKED;
else if (id == 3)
return EVENT.UNASSGN_KEY;
else if (id == 4)
return EVENT.IDLE_TIME;
else if (id == 5)
return EVENT.EXIT_EDITOR;
else if (id == 6)
return EVENT.NEW_EDIT_FILE;
else if (id == 7)
return EVENT.CTRL_BREAK;
else if (id == 8)
return EVENT.INVALID_PCHAR;
}
local function newReFlags( re ){
if (re == 0)
return 0
else if ((re >= 1) && (re <= 3))
return SEARCH_REGEX;
else
return SEARCH_MAXIMAL_MATCH + SEARCH_REGEX;
}
function bsupport_search_fwd( patt, re, ccase, block, len ){
local argc = argcount(), flags = SEARCH_FORWARD;
re = (argc >=2) ? newReFlags(re+0) : newReFlags(1);
flags = or(re, flags);
if((argc >= 1) && patt && and(flags, SEARCH_REGEX))
patt = bsupport_new_regex_pattern( patt, 0 );
if((argc >= 3) && (ccase != 0))
flags = or( search_flags, SEARCH_CASE );
if((argc >= 4) && (block != 0))
flags = or(flags, SEARCH_BLOCK);
# len is ignored for now
return search(patt, flags);
}
function bsupport_search_back( patt, re, ccase, block, len ){
local argc = argcount(), flags = 0;
re = (argc >=2) ? newReFlags(re+0) : newReFlags(1);
flags = or(re, flags);
if((argc >= 1) && patt && and(flags, SEARCH_REGEX))
patt = bsupport_new_regex_pattern( patt, 0 );
if((argc >= 3) && (ccase != 0))
flags = or( search_flags, SEARCH_CASE );
if((argc >= 4) && (block != 0))
flags = or(flags, SEARCH_BLOCK);
# len is ignored for now
return search(patt, flags);
}
function bsupport_search_string( pattern, string, length, re, icase ){
local argc = argcount();
local pos = 0;
if (argc < 3 && length)
string = substr( string, 1, length );
if (argc < 4 || re) {
pattern = bsupport_new_regex_pattern( pattern, 0 );
pos = match( string, pattern );
} else {
pos = index( string, pattern );
}
return pos;
}
function bsupport_set_top_left( top, left ) {
if (argcount() == 1)
current_line = 0+top;
scroll_vertical( distance_to_window_top());
current_line -= distance_to_window_top()
if (argcount() == 2) {
current_column = 0+left;
scroll_horizontal( distance_to_window_left() );
current_column -= distance_to_window_left();
}
}
function bsupport_window_color( color ) {
color_window_bg = convert_color(color);
return shiftr(color,8)
}
local regex_patt
function bsupport_new_regex_pattern( patt, replacing ){
local newpatt = ""
local ch
regex_patt = patt;
ch = get_regex_ch();
while (ch) {
if (ch == "\\\\") {
newpatt = newpatt ch
ch = get_regex_ch();
if (replacing) {
if ((ch >= "0") || (ch <= "9"))
ch = ch - 1;
}
newpatt = newpatt ch;
} else if ((ch == "<") || (ch == "%")) {
newpatt = newpatt "^";
} else if ((ch == ">") || (ch == "$")) {
newpatt = newpatt "$";
} else if (ch == "*") {
newpatt = newpatt ".*";
} else if (ch == "@") {
newpatt = newpatt "*";
} else if (ch == "?") {
newpatt = newpatt ".";
} else if (ch == "["){
newpatt = newpatt ch;
if ( (ch = get_regex_ch()) == "~")
ch = "^";
newpatt = newpatt ch;
while ( (ch = get_regex_ch()) != "]" ) {
newpatt = newpatt ch
if (ch == "\\")
newpatt = newpatt get_regex_ch();
}
continue;
} else {
newpatt = newpatt ch;
}
ch = get_regex_ch();
}
return newpatt;
}
local function get_regex_ch(){
local ch = substr( regex_patt, 1, 1 )
regex_patt = substr( regex_patt, 2 );
return ch;
}
local bsupport_use_tab_setting = 0; # default is off
global function bsupport_use_tab_char( value ){
local prev_setting
local cb = current_buffer;
local nb;
prev_setting = bsupport_use_tab_setting ? "n" : "y";
if (!argcount()) {
bsupport_use_tab_setting = !bsupport_use_tab_setting;
} else {
bsupport_use_tab_setting = (value == "y") ? 1 : 0;
}
default_buffer_flags = (bsupport_use_tab_setting) \
? or( default_buffer_flags, BUFFER_TABS_TO_SPACES ) \
: and( default_buffer_flags, not( BUFFER_TABS_TO_SPACES ));
nb = next_buffer("", 1, 1);
do {
if (!and( buffer_flags, BUFFER_SYSTEM ))
{
buffer_flags = (bsupport_use_tab_setting) \
? or( buffer_flags, BUFFER_TABS_TO_SPACES ) \
: and( buffer_flags, not( BUFFER_TABS_TO_SPACES ));
}
next_buffer("", 1, 1);
} while (current_buffer != nb);
current_buffer = cb;
return prev_setting;
}