home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 16 / 16.iso / w / w055 / 4.ddi / SOURCES.LIF / BSUPPORT.PEL < prev    next >
Encoding:
Text File  |  1990-09-27  |  15.3 KB  |  651 lines

  1. # $Header:   P:/source/ppee/macros/bsupport.pev   1.16   02 Aug 1990 14:16:34   ericj  $
  2.  
  3. ##############################################################################
  4. #
  5. #           Sage Software - POLYTRON Division
  6. #             1700 NW 167th Place
  7. #               Beaverton, OR 97006
  8. #
  9. #   Copyright 1990, Sage Software, Inc.
  10. #
  11. #   Permission is hereby granted for licensed users of Sage Professional
  12. #   Editor and PolyAwk to copy and modify this source code for their own
  13. #   personal use.  These derivative works may be distributed only to other
  14. #   licensed Sage Professional Editor and PolyAwk users.  All other usage
  15. #   is prohibited without express written permission from Sage Software.
  16. #
  17. ##############################################################################
  18.  
  19. #### $Workfile:   bsupport.pel  $: support modules for brief translated macros
  20.  
  21.  
  22.  
  23. #
  24. # This module provides entry points for Brief compatible functionality.
  25. # Whenever Brief macros are translated (using b2p.exe), the resulting code 
  26. # calls the functions below.  This is generally the only use of the functions.
  27. #
  28.  
  29. global bsupport_months;
  30. global bsupport_bookmark_buffer[];
  31. global bsupport_bookmark_line[];
  32. global bsupport_bookmark_column[];
  33.  
  34. BEGIN {
  35.     bsupport_months[ "Jan" ] = 1
  36.     bsupport_months[ "Feb" ] = 2
  37.     bsupport_months[ "Mar" ] = 3
  38.     bsupport_months[ "Apr" ] = 4
  39.     bsupport_months[ "May" ] = 5
  40.     bsupport_months[ "Jun" ] = 6
  41.     bsupport_months[ "Jul" ] = 7
  42.     bsupport_months[ "Aug" ] = 8
  43.     bsupport_months[ "Sep" ] = 9
  44.     bsupport_months[ "Oct" ] = 10
  45.     bsupport_months[ "Nov" ] = 11
  46.     bsupport_months[ "Dec" ] = 12
  47. }
  48.  
  49.  
  50. global function inq_brief_level(){
  51.     return 0;
  52. }
  53.  
  54. global function bsupport_atoi( str, standard ){
  55.     if (0+standard == 0)
  56.         return atoi( substr(str,1,1));
  57.     else
  58.         return atoi(str);
  59. }
  60.  
  61.  
  62. ## ------- support routines for find_file()
  63. #
  64. local bsupport_first_find_file = 1;
  65. local bsupport_find_file_pattern = "";
  66. local bsupport_find_file_name;
  67.  
  68. function bsupport_file_pattern( pattern ){
  69.     bsupport_find_file_pattern = pattern;
  70.     bsupport_first_find_file = 1;
  71. }
  72.  
  73.  
  74. function bsupport_find_file( pattern, name, size, date, time, attribute ){
  75.     return pattern;
  76. }
  77.  
  78. function bsupport_find_first(){
  79.     if (bsupport_find_file_pattern){
  80.         if (bsupport_first_find_file) {
  81.             bsupport_first_find_file = 0;
  82.             return bsupport_find_file_name = findfirst( bsupport_find_file_pattern );
  83.         } else {
  84.             return bsupport_find_file_name = findnext();
  85.         }
  86.     }
  87. }
  88.  
  89. function bsupport_find_file_name(){
  90.     return path_fname( bsupport_find_file_name ) path_ext( bsupport_find_file_name );
  91. }
  92.  
  93. function bsupport_filedate(){}
  94. function bsupport_filetime(){}
  95. #
  96. #------------------- end of find_file() support
  97.  
  98. function bsupport_abs( value ) {
  99.     value = 0+value;
  100.     return value < 0 ? -value : value;
  101. }
  102.  
  103.  
  104. function bsupport_borders( mode ) {
  105.     if (argcount())
  106.          toggle_borders( mode )
  107.     else 
  108.         toggle_borders();
  109. }
  110.  
  111. function bsupport_cd( dir ){
  112.     if (dir)
  113.         return chdir( dir )
  114.     message( getcwd() );
  115.     return 1;
  116. }
  117.  
  118. local    NORTH    = 0x01
  119. local    EAST    = 0x02
  120. local    SOUTH    = 0x04
  121. local    WEST    = 0x08
  122.  
  123. local function bsupport_window_edge( direction ) {
  124.  
  125.     if (direction+0 == 0)
  126.         return NORTH;
  127.     else if (direction+0 == 1)
  128.         return EAST;
  129.     else if (direction+0 == 2)
  130.         return SOUTH;
  131.     else if (direction+0 == 3)
  132.         return WEST;
  133.     return -1;
  134. }
  135.  
  136.  
  137. function bsupport_change_window( direction ) {
  138.     if (argcount())
  139.         return brief_change_window( bsupport_window_edge( direction ))
  140.     else
  141.         return brief_change_window();
  142. }
  143.  
  144.  
  145. function bsupport_create_edge( direction ){
  146.     if (argcount())
  147.         return brief_create_window( bsupport_window_edge( direction ))
  148.     else
  149.         return brief_create_window();
  150. }
  151.  
  152. function bsupport_delete_edge( direction ){
  153.     if (argcount())
  154.         return brief_delete_window( bsupport_window_edge( direction ))
  155.     else
  156.         return brief_delete_window();
  157. }
  158.  
  159. function bsupport_move_edge( direction, amount ){
  160.     if (argcount())
  161.         return brief_resize_window( bsupport_window_edge( 0+direction), amount+0)
  162.     else
  163.         return brief_resize_window();
  164. }
  165.  
  166.  
  167. function bsupport_cut( append ){
  168.     local    status;
  169.  
  170.     if (argcount() && 0+append)
  171.         status = copy_to_scrap_key( 0+append );
  172.     else
  173.         status = copy_to_scrap_key();
  174.     delete_chars()
  175.     return status
  176. }
  177.  
  178. function bsupport_date( year, month, day, month_string, weekday_string){}
  179.  
  180.  
  181. function bsupport_drop_bookmark( bnum, overwrite, buffer_id, line, column ){
  182.     local    status = 1;     
  183.     local    num;
  184.     local    oldbuf = current_buffer;
  185.     local    newbuf = current_buffer;
  186.     local    mdefined = 0;
  187.  
  188.     if (argcount() < 1) {
  189.         bnum = confirm( "Drop bookmark[0-9]?", "0123456789" );
  190.         if (!bnum)
  191.             return 0;
  192.     }
  193.     num = 0 + bnum;
  194.  
  195.     if (num == 0) 
  196.         num = 10;
  197.  
  198.     if (overwrite != "y")
  199.         overwrite = "n"
  200.  
  201.     if ( argcount() > 2 ) {
  202.         if (current_buffer != buffer_id) {
  203.             current_buffer = buffer_id;
  204.             if (current_buffer == oldbuf)
  205.                 return 0;
  206.             newbuf = current_buffer;
  207.             mdefined = mark_defined( num );
  208.             current_buffer = oldbuf;
  209.         }
  210.     } else {
  211.         line = current_line;
  212.         column = current_column;
  213.     }
  214.  
  215.  
  216.     if ( mdefined && (overwrite != "y"))
  217.         if (tolower(confirm( "Overwrite existing bookmark [yn]?", "yYnN" )) \
  218.                 != "y")
  219.             return 0;
  220.  
  221.     current_buffer = newbuf;
  222.     status = create_mark( num, line, column );
  223.     bsupport_bookmark_buffer[ num ] = current_buffer;
  224.     bsupport_bookmark_line[ num ]   = line;
  225.     bsupport_bookmark_column[ num ] = column;
  226.     current_buffer = oldbuf;
  227.     return status;
  228. }
  229.  
  230. global function bsupport_goto_bookmark( success, num, buffid, line, column ){
  231.     return success;
  232. }
  233.  
  234. global function bsupport_find_bookmark( bnum ){
  235.     local num;
  236.  
  237.     if (argcount() != 1){
  238.         bnum = confirm( "Go to bookmark[1-10]? ", "0123456789" );
  239.         if (!bnum)
  240.             return 0;
  241.     }
  242.  
  243.     num = 0 + bnum;
  244.     if ( !bsupport_bookmark_buffer[ num ] )
  245.         return 0;
  246.     current_buffer = bsupport_bookmark_buffer[ num ];
  247.     current_line   = bsupport_bookmark_line[ num ];
  248.     current_column = bsupport_bookmark_column[ num ];
  249.     return 1;
  250. }
  251.  
  252.  
  253.  
  254. global function bsupport_inq_mark_size(){
  255.     local    diff,i,eol;
  256.  
  257.     if (region_type()) {
  258.         save_position()
  259.         swap_marks()
  260.         if (region_type() == 3)    {    # line selection
  261.             if (mark_line() >= current_line) {
  262.                 eol = 0;
  263.                 goto_bol();
  264.             } else {
  265.                 eol = 1;
  266.                 goto_eol();
  267.             }
  268.         }
  269.         i = buffer_offset
  270.         swap_marks()
  271.         if (region_type() == 3)    {    # line selection
  272.             if (eol)    goto_bol();
  273.             else         goto_eol();
  274.         }
  275.         diff = bsupport_abs( buffer_offset - i )
  276.         restore_position(1);
  277.         return diff;
  278.     } else {
  279.         return 0;
  280.     }
  281. }
  282.  
  283.  
  284. function bsupport_inq_modified( buffid ) {
  285.     return bsupport_inq_buffer_flag( buffid, BUFFER_MODIFIED );
  286. }
  287.  
  288.  
  289. function bsupport_inq_system( buffid ) {
  290.     return bsupport_inq_buffer_flag( buffid, BUFFER_SYSTEM );
  291. }
  292.  
  293.  
  294. function bsupport_inq_buffer_flag( buffid, flag )
  295. {
  296.     local    save_buffid;
  297.     local    bflag = and( buffer_flags, flag );
  298.  
  299.     if (buffid) {
  300.         save_buffid = current_buffer;
  301.         current_buffer = buffid;
  302.         bflag = and( buffer_flags, flag );
  303.         current_buffer = save_buffid;
  304.     }
  305.     return bflag;
  306. }
  307.  
  308. function bsupport_inq_marked( a,b,c,d ) 
  309. {
  310.     return region_type();
  311. }
  312. function bsupport_inq_names( full_name, extension, buffer_name ){}
  313. function bsupport_inq_position( line, col ){return 0;}
  314. function bsupport_inq_screen_size( line, col ){}
  315. function bsupport_inq_window_size( line, col, shift ){}
  316.  
  317. function bsupport_insert_mode( insert ) {
  318.     if (argcount())
  319.         toggle_insert_mode( insert );
  320.     else 
  321.         toggle_insert_mode();
  322. }
  323.  
  324. function bsupport_inq_views( buffid )
  325. {
  326.     return buffer_views( buffid );
  327. }
  328.  
  329. function bsupport_keyboard_typeables(){
  330.     local    i;
  331.     for (i = 32; i < 127; i++)
  332.         assign_key( chr(i), "insert_key" );
  333.     assign_key( "<Bksp>", "brief_backspace" );
  334.     assign_key( "<Tab>",  "insert_key" );
  335.     assign_key( "<Enter>","insert_newline" );
  336. }
  337.  
  338. function bsupport_mark( type ) {
  339.     type = 0+type
  340.     if ((type == 1) || (!argcount()) )
  341.         set_exclusive_mark();
  342.     else if (type == 2)
  343.         set_column_mark();
  344.     else if (type == 3)
  345.         set_line_mark();
  346.     else if (type == 4)
  347.         set_inclusive_mark();
  348. }
  349.  
  350.  
  351. function bsupport_move_rel( lines, cols ){}
  352.  
  353. function bsupport_pause_on_error( mode ) {
  354.     if (!argcount())
  355.         pause_on_error = !pause_on_error;
  356.     else
  357.         pause_on_error = 0+mode;
  358. }
  359.  
  360.  
  361. function bsupport_time( hours, minutes, seconds ){}
  362.  
  363.  
  364. function bsupport_translate( patt, repl, gflag, reflag, cflag, bflag, fflag ) {
  365.     local    i = argcount();
  366.  
  367.     search_flags = or(SEARCH_REGEX+SEARCH_FORWARD, and(search_flags,SEARCH_IGNORE_CASE));
  368.     if ((i >= 3) && (typeof(gflag) == "int"))
  369.         if (gflag)
  370.             search_flags = or(search_flags,SEARCH_GLOBAL);
  371.     if ((i >= 4) && (typeof(reflag) == "int" ))
  372.         if (!reflag)
  373.             search_flags = xor(search_flags, SEARCH_REGEX);
  374.     if ((i >= 5) && (typeof(cflag) == "int")) {
  375.         if (cflag)
  376.             search_flags = or(search_flags, SEARCH_IGNORE_CASE );
  377.         else
  378.             search_flags = and( search_flags, not(SEARCH_IGNORE_CASE) );
  379.     }
  380.     if ((i >= 6) && (typeof(bflag) == "int"))
  381.         if (bflag)
  382.             search_flags = or(search_flags, SEARCH_BLOCK);
  383.     if ((i <= 7) && (typeof(fflag) == "int"))
  384.         if (!fflag)
  385.             search_flags = xor(search_flags, SEARCH_FORWARD);
  386.  
  387.  
  388.  
  389.     if (and(search_flags, SEARCH_REGEX)) {
  390.         if ((i >= 1) && patt)
  391.             patt = bsupport_new_regex_pattern( patt, 0 );
  392.         if ((i >= 2) && repl)
  393.             repl = bsupport_new_regex_pattern( repl, 1 );
  394.     }
  395.  
  396.  
  397.     if (and(search_flags, SEARCH_FORWARD))
  398.         replace_forward( patt, repl );
  399.     else
  400.         replace_backward( patt, repl );
  401. }
  402.  
  403.  
  404.  
  405. function bsupport_color( back, normal, sel, msgs, errs, marked ) {
  406.     local    i = argcount();
  407.     if (i == 1) {
  408.         color_text = and( color_text, 0x0F );
  409.         color_text = and( color_text, shiftl( back, 4 ) );
  410.         default_color_text = color_text;
  411.         color_background = back;
  412.         if (i == 2) {
  413.             color_text = and( color_text, 0xF0 );
  414.             color_text = and( color_text, normal );
  415.             default_color_text = color_text;
  416.             if (i == 3) {
  417.                 color_title = and( color_title, 0xF0 );
  418.                 color_title = and( color_title, sel );
  419.                 default_color_title = color_title;
  420.                 if (i == 4) {
  421.                     color_messages = and( color_messages, 0xF0 );
  422.                     color_messages = and( color_messages, msgs );
  423.                     if (i == 5) {
  424.                         color_errors = and( color_errors, 0xF0 );
  425.                         color_errors = and( color_errors, errs );
  426.                         if (i == 6) {
  427.                             color_highlight = and( color_highlight, 0xF0 );
  428.                             color_highlight = and( color_highlight, marked );
  429.                             default_color_highlight = color_highlight;
  430.                         }
  431.                     }
  432.                 }
  433.             }
  434.         }
  435.     }
  436. }
  437.  
  438. function bsupport_registered_macroid( id ) {
  439.     if (id == 0)
  440.         return EVENT_KEYPRESS;
  441.     else if (id == 1)
  442.         return EVENT_NEW_CURNT_BUFFER;
  443.     else if (id == 2)
  444.         return EVENT_HELP_INVOKED;
  445.     else if (id == 3)
  446.         return EVENT_UNASSGN_KEY;
  447.     else if (id == 4)
  448.         return EVENT_IDLE_TIME;
  449.     else if (id == 5)
  450.         return EVENT_EXIT_EDITOR;
  451.     else if (id == 6)
  452.         return EVENT_NEW_EDIT_FILE;
  453.     else if (id == 7)
  454.         return EVENT_CTRL_BREAK;
  455.     else if (id == 8)
  456.         return EVENT_INVALID_PCHAR;
  457. }
  458.  
  459.  
  460.  
  461. local function newReFlags( re ){
  462.     if (re == 0)
  463.         return 0
  464.     else if ((re >= 1) && (re <= 3))
  465.         return SEARCH_REGEX;
  466.     else 
  467.         return SEARCH_MAXIMAL_MATCH + SEARCH_REGEX;
  468. }
  469.  
  470. function bsupport_search_fwd( patt, re, ccase, block, len ){
  471.     local    argc = argcount();
  472.  
  473.  
  474.     re = newReFlags( (argc >= 3) && (typeof(re) == "int") \
  475.              ? re : 1 );
  476.  
  477.     if ((argc >= 1) && patt && and(re,SEARCH_REGEX))
  478.         patt = bsupport_new_regex_pattern( patt, 0 );
  479.  
  480.     search_flags = or( search_flags, re );
  481.     if ((argc >= 4) && (typeof(ccase) == "int"))
  482.         search_flags = or( search_flags, SEARCH_IGNORE_CASE );
  483.         if (ccase)
  484.             search_flags = xor( search_flags, SEARCH_IGNORE_CASE );
  485.     if ((argc >= 5) && (typeof(block) == "int"))
  486.         search_flags = or( search_flags, SEARCH_BLOCK );
  487.         if (!block)
  488.             search_flags = xor( search_flags, SEARCH_BLOCK );
  489.  
  490.     # len is ignored for now
  491.  
  492.     search_forward( patt );
  493. }
  494.  
  495. function bsupport_search_back( patt, re, ccase, block, len ){
  496.     local    argc = argcount();
  497.  
  498.  
  499.     re = newReFlags( (argc >= 3) && (typeof(re) == "int") \
  500.              ? re : 1 );
  501.  
  502.     if ((argc >= 1) && patt && and(re,SEARCH_REGEX))
  503.         patt = bsupport_new_regex_pattern( patt, 0 );
  504.  
  505.     search_flags = or( search_flags, re );
  506.     if ((argc >= 4) && (typeof(ccase) == "int"))
  507.         search_flags = or( search_flags, SEARCH_IGNORE_CASE );
  508.         if (ccase)
  509.             search_flags = xor( search_flags, SEARCH_IGNORE_CASE );
  510.     if ((argc >= 5) && (typeof(block) == "int"))
  511.         search_flags = or( search_flags, SEARCH_BLOCK );
  512.         if (!block)
  513.             search_flags = xor( search_flags, SEARCH_BLOCK );
  514.  
  515.     # len is ignored for now
  516.  
  517.     search_backward( patt );
  518. }
  519.  
  520.  
  521. function bsupport_search_string( pattern, string, length, re, icase ){
  522.     local    argc = argcount();
  523.     local   pos = 0;
  524.  
  525.     if (argc < 3 && length)
  526.         string = substr( string, 1, length );
  527.  
  528.     if (argc < 4 || re) {
  529.         pattern = bsupport_new_regex_pattern( pattern, 0 );
  530.         pos = match( string, pattern );
  531.     } else {
  532.         pos = index( string, pattern );
  533.     }
  534.  
  535.  
  536.     return pos;
  537. }
  538.  
  539.  
  540. function bsupport_set_top_left( top, left ) {
  541.     if (argcount() == 1)
  542.         current_line = 0+top;
  543.  
  544.     scroll_vertical( distance_to_window_top());
  545.     current_line -= distance_to_window_top()
  546.  
  547.     if (argcount() == 2) {
  548.         current_column = 0+left;
  549.         scroll_horizontal( distance_to_window_left() );
  550.         current_column -= distance_to_window_left();
  551.     }
  552. }
  553.  
  554.  
  555. function bsupport_window_color( color ) {
  556.     color = argcount() ? shiftl( 0+color, 4 ) : and(color_text,0x00F0);
  557.     color_text = or( and( color_text, 0x0F ), color );    
  558.     return shiftr(color,8)
  559. }
  560.  
  561.  
  562.  
  563. local    regex_patt
  564.  
  565. function bsupport_new_regex_pattern( patt, replacing ){
  566.     local    newpatt = ""
  567.     local    ch
  568.  
  569.     regex_patt = patt;
  570.  
  571.     ch = get_regex_ch();
  572.     while (ch) {
  573.         if (ch == "\\\\") {
  574.             newpatt = newpatt ch
  575.             ch = get_regex_ch();
  576.             if (replacing) {
  577.                 if ((ch >= "0") || (ch <= "9"))
  578.                     ch = ch - 1;
  579.             } 
  580.             newpatt = newpatt ch;
  581.         } else if ((ch == "<") || (ch == "%")) {
  582.             newpatt = newpatt "^";
  583.         } else if ((ch == ">") || (ch == "$")) {
  584.             newpatt = newpatt "$";
  585.         } else if (ch == "*") {
  586.             newpatt = newpatt ".*";
  587.         } else if (ch == "@") {
  588.             newpatt = newpatt "*";
  589.         } else if (ch == "?") {
  590.             newpatt = newpatt ".";
  591.         } else if (ch == "["){
  592.             newpatt = newpatt ch;
  593.             if ( (ch = get_regex_ch()) == "~")
  594.                 ch = "^";
  595.             newpatt = newpatt ch;
  596.             while ( (ch = get_regex_ch()) != "]" )  {
  597.                 newpatt = newpatt ch
  598.                 if (ch == "\\")
  599.                     newpatt = newpatt get_regex_ch();
  600.             }
  601.             continue;
  602.         } else {
  603.             newpatt = newpatt ch;
  604.         }
  605.         ch = get_regex_ch();
  606.     }
  607.     return newpatt;
  608. }
  609.  
  610. local function get_regex_ch(){
  611.     local ch = substr( regex_patt, 1, 1 )
  612.     regex_patt = substr( regex_patt, 2 );
  613.     return ch;
  614. }
  615.  
  616.  
  617. local bsupport_use_tab_setting = 0;    # default is off
  618.  
  619. global function bsupport_use_tab_char( value ){
  620.     local prev_setting
  621.     local cb = current_buffer;
  622.     local nb;
  623.  
  624.     prev_setting = bsupport_use_tab_setting ? "n" : "y";
  625.  
  626.     if (!argcount()) {
  627.         bsupport_use_tab_setting = !bsupport_use_tab_setting;
  628.     } else {
  629.          bsupport_use_tab_setting = (value == "y") ? 1 : 0;
  630.     }
  631.  
  632.     default_buffer_flags = (bsupport_use_tab_setting) \
  633.         ? or( default_buffer_flags, BUFFER_TABS_TO_SPACES ) \
  634.         : and( default_buffer_flags, not( BUFFER_TABS_TO_SPACES ));
  635.  
  636.  
  637.     nb = next_buffer();
  638.     do {
  639.         if (!and( buffer_flags, BUFFER_SYSTEM )) {
  640.             buffer_flags = (bsupport_use_tab_setting) \
  641.                 ? or( buffer_flags, BUFFER_TABS_TO_SPACES ) \
  642.                 : and( buffer_flags, not( BUFFER_TABS_TO_SPACES ));
  643.         }
  644.         next_buffer();
  645.     } while (current_buffer != nb);
  646.  
  647.  
  648.     current_buffer = cb;
  649.     return prev_setting;
  650. }
  651.