home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / p2demo21.exe / PEL / BSUPPORT.PEL < prev    next >
Text File  |  1995-02-10  |  18KB  |  700 lines

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