home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / ME494-3.ZIP / MULTI_ED.SRC < prev    next >
Encoding:
Text File  |  1990-05-28  |  13.6 KB  |  634 lines

  1. $MACRO_FILE MULTI_ED;
  2. {******************************************************************************
  3.                                                             MULTI-EDIT MACRO FILE
  4.  
  5. Name: MULTI_ED
  6.  
  7. Description:  Language support for the Multi-Edit macro language.
  8.  
  9. MUL_IND - Smart Indenting
  10. MULTEMP - Template Editing
  11. MULMTCH - Construct matching
  12. MULHELP - Language sensitive help
  13.  
  14.                              (C) Copyright 1989 by American Cybernetics, Inc.
  15. ******************************************************************************}
  16.  
  17. $MACRO MUL_IND;
  18. {******************************************************************************
  19.                                                                 MULTI-EDIT MACRO
  20.  
  21. Name: MUL_IND
  22.  
  23. Description:  Performs smart indent for the Multi-Edit macro language.
  24.     Is called by the macro CR.
  25.  
  26.                              (C) Copyright 1989 by American Cybernetics, Inc.
  27. ******************************************************************************}
  28.  
  29.     DEF_INT( ind_count, new_col, paren_count, t_ins, t_undo, jx );
  30.     DEF_STR( fstr[40] );
  31.  
  32.     refresh := FALSE;
  33.     t_undo := undo_stat;
  34.     undo_stat := false;
  35.     reg_exp_stat := TRUE;
  36.     Mark_Pos;
  37.  
  38.     ind_count := 0;
  39.     new_col := c_col;
  40.     t_ins := Insert_Mode;
  41.     left;
  42.  {goto     search_again;}
  43. Find_Comment:
  44.     IF search_bwd('[@{@}'']', 50 ) THEN
  45.         IF found_str = '{' THEN
  46.             word_right;
  47.             new_col := c_col;
  48.             jx := c_line;
  49.             fstr := found_str;
  50.             goto_mark;
  51.             mark_pos;
  52.             IF jx <> c_line THEN
  53.                 first_word;
  54.                 new_col := c_col;
  55.             END;
  56.             GOTO Do_Indent;
  57.         ELSIF found_str = '''' THEN
  58.             left;
  59.  
  60.             IF search_bwd('{%@$MACRO }||{''}', 50 ) THEN
  61.                 IF (found_str = '''') THEN
  62.                     left;
  63.                     GOTO Find_Comment;
  64.                 END;
  65.             END;
  66.             GOTO CR_EXIT;
  67. {
  68.             IF NOT( search_bwd( '''', 100 )) THEN
  69.                 GOTO CR_EXIT;
  70.             END;
  71.             left;
  72.             GOTO Find_Comment;
  73. }
  74.         END;
  75.     END;
  76.     GOTO_MARK;
  77.     MARK_POS;
  78.     left;
  79.  
  80. Search_Again:
  81.     IF Search_Bwd(
  82.                                 '[''()@}]||{%||[|9 ;)]{ELSIF}||{ELSE}||{END}||{IF}||{WHILE}||{@$MACRO}$||[|9 ;.(]}',
  83.                                  20 )    THEN
  84.         WHILE NOT(AT_EOL) AND (XPOS( cur_char,'|9|255 ',1 ) <> 0) DO
  85.             right;
  86.         END;
  87.         IF found_str = '''' THEN
  88.             left;
  89.             IF Search_BWD( '''', 20 ) THEN
  90.                 left;
  91.                 GOTO Search_Again;
  92.             ELSE
  93.                 GOTO CR_Exit;
  94.             END;
  95.         END;
  96.         IF found_str = ')' THEN
  97.             left;
  98.             Paren_Count := 1;
  99.             WHILE Paren_Count <> 0 DO
  100.                 IF Search_BWD( '[''()]', 20 ) THEN
  101.                     IF found_str = '(' THEN
  102.                         --Paren_Count;
  103.                     ELSIF found_str = ')' THEN
  104.                         ++Paren_Count;
  105.                     ELSE
  106.                         IF NOT(search_bwd( '''', 20 )) THEN
  107.                             GOTO CR_Exit;
  108.                         END;
  109.                     END;
  110.                     left;
  111.                 ELSE
  112.                     GOTO CR_Exit;
  113.                 END;
  114.             END;
  115.             Goto Search_Again;
  116.         END;
  117.         IF found_str = '}' THEN
  118.             left;
  119.             Paren_Count := 1;
  120.             WHILE Paren_Count <> 0 DO
  121.                 IF Search_BWD( '[''@{@}]', 20 ) THEN
  122.                     IF found_str = '{' THEN
  123.                         --Paren_Count;
  124.                     ELSIF found_str = '}' THEN
  125.                         ++Paren_Count;
  126.                     ELSE
  127.                         IF NOT(search_bwd( '''', 20 )) THEN
  128.                             GOTO CR_Exit;
  129.                         END;
  130.                     END;
  131.                     left;
  132.                 ELSE
  133.                     GOTO CR_Exit;
  134.                 END;
  135.             END;
  136.             Goto Search_Again;
  137.         END;
  138.         new_col := c_col;
  139.         fstr := CAPS(Get_Word(' ([{|9;'));
  140.         IF fstr <> 'END' THEN
  141.             ++ind_count;
  142.         END;
  143.     ELSE
  144.         GOTO CR_Exit;
  145.     END;
  146.  
  147. Do_Indent:
  148.     make_message('Indenting from [' + fstr + ']' );
  149.     Goto_Col( new_col );
  150.     insert_mode := FALSE;
  151.     While ind_count > 0 DO
  152.         tab_right;
  153.         --ind_count;
  154.     END;
  155.     While ind_count < 0 DO
  156.         tab_left;
  157.         ++ind_count;
  158.     END;
  159.     Set_Indent_Level;
  160.     insert_mode := TRUE;
  161.  
  162. CR_EXIT:
  163.     Goto_Mark;
  164.     undo_stat := t_undo;
  165.     CR;
  166. EXIT:
  167.     Insert_Mode := t_ins;
  168.     undo_stat := t_undo;
  169. END_MACRO;
  170.  
  171. $MACRO MULTEMP;
  172. {******************************************************************************
  173.                                                                 MULTI-EDIT MACRO
  174.  
  175. Name: MULTEMP
  176.  
  177. Description:  Creates language constructs for the Multi-Edit macro language
  178.     based on a single character to the left of the cursor.
  179.  
  180.                              (C) Copyright 1989 by American Cybernetics, Inc.
  181. ******************************************************************************}
  182.  
  183.     DEF_INT(Temp_Col,Temp_Insert, tc, x, y);
  184.  
  185.     Temp_Insert := Insert_Mode;
  186.     If NOT(AT_EOL) Then
  187.         Goto END_OF_MAC;
  188.     End;
  189.  
  190.     Insert_Mode := True;
  191.     Temp_Col := C_COL;
  192.  
  193.     call calc_xy;
  194.     return_int := 0;
  195.     tc := 0;
  196.     IF c_col > 1 THEN
  197.         left;
  198.         RETURN_INT := XPOS( caps(cur_char), 'IWEM$', 1 );
  199.         IF RETURN_INT <> 0 THEN
  200.             tc := 1;
  201.             IF return_int > 4 THEN
  202.                 return_int := 4;
  203.             END;
  204.          ELSE
  205.             goto_col( temp_col );
  206.         END;
  207.     END;
  208.  
  209.  
  210.     RM( 'USERIN^XMENU /L=TEMPLATE/S=' + str(return_int) + '/X=' + str(x) + '/Y=' + str(y) +
  211.         '/T=1/B=1/M=IF...THEN()WHILE...DO()ELSIF THEN()$MACRO...END_MACRO()Complete macro/comment header()' );
  212.  
  213.     Insert_Mode := True;
  214.  
  215.     IF ( return_int > 0 ) THEN
  216.         IF not(at_eol) THEN
  217.             del_char;
  218.         END;
  219.         temp_col := c_col;
  220.     END;
  221.     IF ( RETURN_INT = 1 ) Then
  222.         Goto MAKEIF;
  223.     ELSIF (RETURN_INT = 2) Then
  224.         Goto MAKEWHILE;
  225.     ELSIF (RETURN_INT = 3) Then
  226.         Goto MAKEELSIF;
  227.     ELSIF (RETURN_INT = 4) Then
  228.         Goto MAKEMACRO;
  229.     ELSIF (RETURN_INT = 5) THEN
  230.         Goto MAKEMACHEADER;
  231.     END;
  232.  
  233.     Goto END_OF_MAC;
  234. MAKEIF:
  235.     goto_col(Temp_Col);
  236.     Text( 'IF () THEN' );
  237.     Cr;
  238.     Cr;
  239.     goto_col(Temp_Col);
  240.     Text( 'END;' );
  241.     Up;
  242.     goto_col(Temp_Col);
  243.     Indent;
  244.     Up;
  245.     goto_col(Temp_Col + 4);
  246.     Goto END_OF_MAC;
  247.  
  248. MAKEELSIF:
  249.     goto_col(Temp_Col);
  250.     Text( 'ELSIF () THEN' );
  251.     Cr;
  252.     goto_col(Temp_Col);
  253.     Indent;
  254.     Up;
  255.     goto_col(Temp_Col + 7);
  256.     Goto END_OF_MAC;
  257.  
  258.  
  259. MAKEMACRO:
  260.     goto_col(1);
  261.     TEXT( '$MACRO ;' );
  262.     Cr;
  263.     Cr;
  264.     goto_col(1);
  265.     TEXT( 'END_MACRO;' );
  266.     Up;
  267.     goto_col(1);
  268.     Indent;
  269.     Up;
  270.     goto_col(8);
  271.     Goto END_OF_MAC;
  272.  
  273.  
  274. MAKEWHILE:
  275.     goto_col(Temp_Col);
  276.     Text( 'WHILE () DO' );
  277.     Cr;
  278.     Cr;
  279.     goto_col(Temp_Col);
  280.     Text( 'END;' );
  281.     Up;
  282.     goto_col(Temp_Col);
  283.     Indent;
  284.     Up;
  285.     goto_col(Temp_Col + 7);
  286.     Goto END_OF_MAC;
  287.  
  288.  
  289. MAKEMACHEADER:
  290.     Return_Str := '';
  291.     RM('USERSTR /B=1/BL=Input Macro Name:/W=16/X=' + str(wherex) + '/Y=' + str(wherey - 1) );
  292.     goto_col( 1 ); Set_Indent_Level;
  293.     Text('{*******************************MULTI-EDIT MACRO******************************');
  294.     CR; CR;
  295.     Text('Name:  '); Mark_Pos; CR; CR;
  296.     Text('Description:'); CR; CR;
  297.     IF global_int('USER_ACI_COPYRIGHT') THEN
  298.         Text('***************(C) Copyright 19' + copy(date,7,2) 
  299.                     + ' by American Cybernetics, Inc.***************}');
  300.     ELSE
  301.         Text('******************************************************************************}');
  302.     END;
  303.     Cr;
  304.     Text('$MACRO ' + return_str + ';');
  305.     CR; CR;
  306.     Text('$END_MACRO; {' + return_str + '}');
  307.     CR;
  308.     Goto_Mark;
  309.     Text( return_str );
  310.     down; down;
  311.     eol;
  312.     right; right;
  313.     goto end_of_mac;
  314.  
  315. calc_xy:
  316.     x := (wherex - 9);
  317.     if (x + 18 + 2) > screen_width then
  318.         x := screen_width - ( 20 );
  319.     end;
  320.     if x < 1 then
  321.         x := 1;
  322.     end;
  323.     y := wherey - 7;
  324.     if y < 3 then
  325.         y := wherey + 1;
  326.         if y > (screen_length - 6) then
  327.             y := 3;
  328.         end;
  329.     end;
  330.     ret;
  331.  
  332.  
  333. END_OF_MAC:
  334.     Insert_Mode := Temp_Insert;
  335.  
  336. END_MACRO;
  337.  
  338. $MACRO MULMTCH TRANS;
  339. {******************************************************************************
  340.                                                                 MULTI-EDIT MACRO
  341.  
  342. Name: MULMTCH
  343.  
  344.                              (C) Copyright 1989 by American Cybernetics, Inc.
  345.                                                  Modified by Kevin Jackson
  346. ******************************************************************************}
  347.  
  348.     DEF_STR( Str1,     {Match strings}
  349.                      EStr1,
  350.                      T_Str, S_Str, FStr );
  351.  
  352.     DEF_INT( Direction,   {1 = search forward, 0 = backward}
  353.                      B_Count,     {Match count.  0 = match found}
  354.                      S_Res,       {Search results}
  355.                      Second_Time,
  356.                      match_line,
  357.                      match_col );
  358.  
  359.  
  360.     Second_Time := False;
  361.     Refresh := False;     {Turn screen refresh off}
  362.     Str1 := '';
  363.     EStr1 := '';
  364.     mark_pos;
  365.     match_line := 0;
  366.  
  367. Find_Match_Str:
  368.  
  369.     IF (Cur_Char = '(') THEN   {Setup match for '('}
  370.         Str1 := '(';
  371.         EStr1 := ')';
  372.         Direction := 1;
  373.         S_Str := '[()'']';
  374.         GOTO Start_Match;
  375.     ELSIF (Cur_Char = ')') THEN   {Setup match for ')'}
  376.         Str1 := ')';
  377.         EStr1 := '(';
  378.         Direction := 0;
  379.         S_Str := '[()'']';
  380.         GOTO Start_Match;
  381.     ELSIF (Cur_Char = '{') THEN   {Setup match for '{'}
  382.         Str1 := '{';
  383.         EStr1 := '}';
  384.         Direction := 1;
  385.         S_Str := '[@{@}'']';
  386.         GOTO Start_Match;
  387.     ELSIF (Cur_Char = '}') THEN   {Setup match for '}'}
  388.         Str1 := '}';
  389.         EStr1 := '{';
  390.         Direction := 0;
  391.         S_Str := '[@{@}'']';
  392.         GOTO Start_Match;
  393.     END;
  394.  
  395.     IF At_EOL THEN     {If we are at the end of a line the go to the first word}
  396.         First_Word;
  397.     END;
  398.  
  399.     IF (XPos(Cur_Char,' |9|255',1)) THEN{If we are on a blank space then find a word}
  400.         Word_Right;
  401.     END;
  402.  
  403.     S_Str := '['']||{%||[|9 ;)]{ELSIF}||{END}||{IF}||{WHILE}$||[|9 ;.(]}||{@{}||{@}}';
  404.  
  405.     T_Str := Caps( Get_Word(';. |9|255') );  {Get the current word}
  406.  
  407.     IF (T_Str = 'IF') OR (T_Str = 'ELSIF') OR (T_Str = 'WHILE') OR (T_Str = 'ELSE') THEN
  408.         Str1 := 'IF WHILE';
  409.         EStr1 := ' END ELSIF';
  410.         Direction := 1;
  411.         GOTO Start_Match;
  412.     END;
  413.  
  414.     IF T_Str = 'END' THEN
  415.         S_Str := '['']||{%||[|9 ;)]{END}||{IF}||{WHILE}$||[|9 ;.(]}||{@{}||{@}}';
  416.         Str1 := 'END';
  417.         Estr1 := ' IF WHILE';
  418.         Direction := 0;
  419.         Word_Left;
  420.         Left;
  421.         GOTO Start_Match;
  422.     END;
  423.  
  424.     {If we didn't find a word to match the first time then try again}
  425.     If NOT( Second_Time ) THEN
  426.         Second_Time := True;
  427.         First_Word;
  428.         GOTO Find_Match_Str;
  429.     END;
  430.  
  431.     Make_Message('NOTHING to Match');
  432.     GOTO Macro_Exit;
  433.  
  434. Start_Match:
  435.     Reg_Exp_Stat := True;
  436.     Ignore_Case := True;
  437.     B_Count := 1;
  438.     S_Res := 1;
  439.     Make_Message('Matching...  Press <ESC> to Stop.');
  440.     Working;
  441.  
  442. MATCH_LOOP:   {Main loop}
  443.                     {If the <ESC> key is pressed while matching then abort the search}
  444.     if check_key then
  445.         if key1 = 27 then
  446.             Make_Message('Match Aborted.');
  447.             goto macro_exit;
  448.         end;
  449.     end;
  450.  
  451.     If S_Res = 0 THEN   {If last search result was false then exit}
  452.         GOTO Error_Exit;
  453.     END;
  454.  
  455.     If B_Count = 0 THEN {If match count is 0 then success}
  456.         GOTO Found_Exit;
  457.     END;
  458.  
  459.     If Direction = 1 THEN {Perform search based on direction}
  460.         Right;
  461.         While NOT (At_EOL) and ((Cur_CHar = '|255') or (Cur_Char = '|9')) DO
  462.             Right;
  463.         END;
  464.         S_Res := Search_Fwd(S_Str,0);
  465.     ELSE
  466.         Left;
  467.         While (Cur_Char = '|255') or
  468.                     (Cur_Char = '|9') DO
  469.             Left;
  470.         END;
  471.         S_Res := Search_Bwd(S_Str,0);
  472.     END;
  473.  
  474.     If S_Res = 0 THEN   {If search failed then exit}
  475.         GOTO Macro_Exit;
  476.     END;
  477.  
  478.     FStr := Caps(Found_Str);
  479.  
  480.     IF Length(FStr) > 2 THEN
  481.         IF XPOS(Copy(FStr,1,1),'|9 ;()',1)  THEN  {If the first char is a space or a ;}
  482.             FStr := Copy(FStr,2,20);         {  then eliminate it}
  483.         END;
  484.                                                                             {If it ended in a space, ; or . then}
  485.         IF XPOS(Copy(FStr,Length(FStr),1),'|9 ;.()',1) THEN
  486.             FStr := Copy(FStr,1,Length(FStr) - 1);  {eliminate that char}
  487.         END;
  488.     END;
  489.  
  490.                                                             {If we found the first match string then}
  491.     IF XPOS(FStr,STR1,1) THEN
  492.         ++B_Count;   {Inc the match count}
  493.         GOTO Match_Loop;
  494.     END;
  495.  
  496.     IF XPOS(FStr,ESTR1,1) THEN          {If we found the second match string then}
  497. {04-09-90 09:17am I'm leaving this in the file, just in case there was a reason
  498. for it.  It caused the match not to work in many cases.
  499.     IF XPOS(' ' + FStr,ESTR1,1) THEN          {If we found the second match string then}
  500. }
  501.         IF fstr = 'ELSIF' THEN
  502.             IF b_count = 1 THEN
  503.                 b_count := 0;
  504.             END;
  505.         ELSE
  506.             --B_Count;    {  decrement the match count}
  507.         END;
  508.         GOTO Match_Loop;
  509.     END;
  510.  
  511.     {If we found a comment then match it}
  512.     IF (Direction = 1) AND (FStr = '{') THEN
  513.         again_1:
  514.         S_Res := Search_Fwd('[@}'']',0);
  515.         IF (s_res) AND (found_str = '''') THEN
  516.             call match_quote_fwd;
  517.             goto again_1;
  518.         END;
  519.         GOTO Match_Loop;
  520.     END;
  521.  
  522.     {If we found a comment then match it}
  523.     IF (Direction = 0) AND (FStr = '}') THEN
  524. again_2:
  525.         S_Res := Search_Bwd('[@{'']',0);
  526.         IF (s_res) AND (found_str = '''') THEN
  527.             call match_quote_bwd;
  528.             goto again_2;
  529.         END;
  530.         GOTO Match_Loop;
  531.     END;
  532.  
  533.     If FStr = '''''' THEN        {If we found two single quotes the skip it}
  534.         If Direction = 1 THEN
  535.             RIGHT;
  536.         ELSE
  537.             LEFT;
  538.         END;
  539.         GOTO Match_Loop;
  540.     END;
  541.                                                             {If we found a single quote then match it}
  542.     IF FStr = '''' THEN
  543.  
  544.         Quote_Loop:
  545.  
  546.             If Direction = 1 THEN
  547.                 RIGHT;
  548.                 S_Res := Search_Fwd('''',0);
  549.             ELSE
  550.                 LEFT;
  551.                 S_Res := Search_Bwd('''',0);
  552.             END;
  553.             If S_Res = 0 THEN
  554.                 GOTO Macro_Exit;
  555.             END;
  556.             FStr := Found_Str;
  557.             If FStr = '''''' THEN
  558.                 GOTO Quote_Loop;
  559.             END;
  560.             GOTO Match_Loop;
  561.  
  562.     END;
  563.     GOTO error_exit;
  564.  
  565. Match_Quote_Bwd:
  566.     left;
  567.     IF NOT(search_bwd( '''', 100 )) THEN
  568.         GOTO error_Exit;
  569.     END;
  570.     left;
  571.     RET;
  572.  
  573. Match_Quote_Fwd:
  574.     right;
  575.     IF NOT(search_fwd( '''', 100 )) THEN
  576.         GOTO error_Exit;
  577.     END;
  578.     right;
  579.     RET;
  580.  
  581.  
  582. Error_Exit:     {Go here for unsucessfull match}
  583.     goto_mark;
  584.     Make_Message('Match NOT Found');
  585.     GOTO Macro_Exit;
  586.  
  587. Found_Exit:     {Go here for successfull match}
  588.     While NOT (At_EOL) and ((Cur_CHar = '|255') or (Cur_Char = '|9')) DO
  589.         Right;
  590.     END;
  591.     match_line := c_line;
  592.     match_col := c_col;
  593.     goto_mark;
  594.     IF (match_line < c_line ) AND ((c_line - match_line) < 50) THEN
  595.         WHILE match_line < c_line DO
  596.             up;
  597.         END;
  598.     ELSIF (c_line < match_line ) AND ((match_line - c_line) < 50) THEN
  599.         WHILE c_line < match_line DO
  600.             down;
  601.         END;
  602.     END;
  603.     goto_line( match_line );
  604.     goto_col( match_col );
  605.  
  606.     Make_Message('Match Found');
  607. Macro_Exit:
  608.     Refresh := True;
  609.     Redraw;
  610. END_MACRO;
  611.  
  612. $MACRO MULHELP;
  613. {******************************************************************************
  614.                                                                 MULTI-EDIT MACRO
  615.  
  616. Name: MULHELP
  617.  
  618. Description:    Attempts to retrieve help on the current word the cursor is
  619.                             sitting on from the Multi-Edit macro language reference.
  620.  
  621.                              (C) Copyright 1989 by American Cybernetics, Inc.
  622. ******************************************************************************}
  623.  
  624.     def_str( hstr );
  625.  
  626.     right;
  627.     word_left;
  628.     hstr := get_word( '{};|9 |255()[]' );
  629.     rm('mehelp /F=macro/LK=INDEX%' + hstr);
  630.  
  631. END_MACRO;
  632.  
  633.  
  634.