home *** CD-ROM | disk | FTP | other *** search
- # $Header: P:/source/ppee/macros/bsupport.pev 1.16 02 Aug 1990 14:16:34 ericj $
-
- ##############################################################################
- #
- # Sage Software - POLYTRON Division
- # 1700 NW 167th Place
- # Beaverton, OR 97006
- #
- # Copyright 1990, Sage Software, Inc.
- #
- # Permission is hereby granted for licensed users of Sage Professional
- # Editor and PolyAwk to copy and modify this source code for their own
- # personal use. These derivative works may be distributed only to other
- # licensed Sage Professional Editor and PolyAwk users. All other usage
- # is prohibited without express written permission from Sage Software.
- #
- ##############################################################################
-
- #### $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.
- #
-
- global bsupport_months;
- global bsupport_bookmark_buffer[];
- global bsupport_bookmark_line[];
- global 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
- }
-
-
- 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_abs( value ) {
- value = 0+value;
- return value < 0 ? -value : value;
- }
-
-
- 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 ) {
- 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_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;
-
- if (argcount() && 0+append)
- status = copy_to_scrap_key( 0+append );
- else
- status = copy_to_scrap_key();
- delete_chars()
- 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,eol;
-
- if (region_type()) {
- save_position()
- swap_marks()
- if (region_type() == 3) { # line selection
- if (mark_line() >= current_line) {
- eol = 0;
- goto_bol();
- } else {
- eol = 1;
- goto_eol();
- }
- }
- i = buffer_offset
- swap_marks()
- if (region_type() == 3) { # line selection
- if (eol) goto_bol();
- else goto_eol();
- }
- diff = bsupport_abs( 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 region_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 ){}
-
- 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( "<Bksp>", "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 ){}
-
- 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_IGNORE_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_IGNORE_CASE );
- else
- search_flags = and( search_flags, not(SEARCH_IGNORE_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_text = and( color_text, 0x0F );
- color_text = and( color_text, shiftl( back, 4 ) );
- default_color_text = color_text;
- color_background = back;
- if (i == 2) {
- color_text = and( color_text, 0xF0 );
- color_text = and( color_text, normal );
- default_color_text = color_text;
- if (i == 3) {
- color_title = and( color_title, 0xF0 );
- color_title = and( color_title, sel );
- default_color_title = color_title;
- if (i == 4) {
- color_messages = and( color_messages, 0xF0 );
- color_messages = and( color_messages, msgs );
- if (i == 5) {
- color_errors = and( color_errors, 0xF0 );
- color_errors = and( color_errors, errs );
- if (i == 6) {
- color_highlight = and( color_highlight, 0xF0 );
- color_highlight = and( color_highlight, marked );
- default_color_highlight = color_highlight;
- }
- }
- }
- }
- }
- }
- }
-
- 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();
-
-
- re = newReFlags( (argc >= 3) && (typeof(re) == "int") \
- ? re : 1 );
-
- if ((argc >= 1) && patt && and(re,SEARCH_REGEX))
- patt = bsupport_new_regex_pattern( patt, 0 );
-
- search_flags = or( search_flags, re );
- if ((argc >= 4) && (typeof(ccase) == "int"))
- search_flags = or( search_flags, SEARCH_IGNORE_CASE );
- if (ccase)
- search_flags = xor( search_flags, SEARCH_IGNORE_CASE );
- if ((argc >= 5) && (typeof(block) == "int"))
- search_flags = or( search_flags, SEARCH_BLOCK );
- if (!block)
- search_flags = xor( search_flags, SEARCH_BLOCK );
-
- # len is ignored for now
-
- search_forward( patt );
- }
-
- function bsupport_search_back( patt, re, ccase, block, len ){
- local argc = argcount();
-
-
- re = newReFlags( (argc >= 3) && (typeof(re) == "int") \
- ? re : 1 );
-
- if ((argc >= 1) && patt && and(re,SEARCH_REGEX))
- patt = bsupport_new_regex_pattern( patt, 0 );
-
- search_flags = or( search_flags, re );
- if ((argc >= 4) && (typeof(ccase) == "int"))
- search_flags = or( search_flags, SEARCH_IGNORE_CASE );
- if (ccase)
- search_flags = xor( search_flags, SEARCH_IGNORE_CASE );
- if ((argc >= 5) && (typeof(block) == "int"))
- search_flags = or( search_flags, SEARCH_BLOCK );
- if (!block)
- search_flags = xor( search_flags, SEARCH_BLOCK );
-
- # len is ignored for now
-
- search_backward( patt );
- }
-
-
- 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 = argcount() ? shiftl( 0+color, 4 ) : and(color_text,0x00F0);
- color_text = or( and( color_text, 0x0F ), 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();
- 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();
- } while (current_buffer != nb);
-
-
- current_buffer = cb;
- return prev_setting;
- }
-