home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / ME494-3.ZIP / SRC / BASIC.SRC < prev    next >
Encoding:
Text File  |  1990-02-06  |  10.0 KB  |  266 lines

  1. $macro_file BASIC;
  2.  
  3. {******************************************************************************}
  4. {                                MULTI-EDIT MACRO                              }
  5. {                                                                              }
  6. {Name: BASTEMP                                                                 }
  7. {                                                                              }
  8. {Description: Creates compiled or interpreted basic language constructs based  }
  9. {  on a single character to the left of the current cursor position.           }
  10. {                                                                              }
  11. {               (C) Copyright 1988 by American Cybernetics, Inc.               }
  12. {******************************************************************************}
  13.  
  14. $MACRO BASTEMP;
  15.  
  16.     DEF_INT(Temp_Col,Temp_Insert,Temp_Line_Num,Next_Line_Num,For);
  17.  
  18.     Temp_Insert := Insert_Mode;
  19.     If (At_EOL = FALSE) Then
  20.         Goto END_OF_MAC;
  21.     End;
  22.  
  23.     Insert_Mode := True;
  24.     Temp_Col := C_COL;
  25.  
  26.     Left;
  27. {check the character to the left of the cursor}
  28.  
  29.     If (XPos(Cur_Char,'Ii',1)) Then
  30. {If it is an 'I', then make an 'IF THEN' construct}
  31.         Goto_Col(Temp_Col);
  32. {Create construct}
  33.         Text('F  THEN');
  34.         Goto_Col(Temp_Col + 2);
  35.         Goto END_OF_MAC;
  36.     End;
  37.  
  38.     If (XPos(Cur_Char,'WwFf',1)) Then
  39. {If it is an 'W', then make an 'WHILE WEND' construct}
  40. {If it is an 'F', then make an 'FOR NEXT' construct}
  41.         For := (XPos(Cur_Char,'Ff',1) > 0);
  42.         Goto MAKE_FOR_WHILE;
  43.     End;
  44.  
  45. {If none of the above, then return cursor to the original position and exit}
  46.     Goto_Col(Temp_Col);
  47.     Goto END_OF_MAC;
  48.  
  49.  
  50. MAKE_FOR_WHILE:
  51. {See if line numbers are used}
  52.     Goto_Col(1);
  53.     If ((Val(Temp_Line_Num,Get_Word(' ')) > 0) or (C_Col = 1)) Then
  54. {If not, set the variable to zero so no line number with be created}
  55.         Temp_Line_Num := 0;
  56.     Else
  57. {if so, check to see if there is a line number below}
  58.         Down;
  59.         Goto_Col(1);
  60.         If ((Val(Next_Line_Num,Get_Word(' ')) > 0) or (C_Col = 1)) Then
  61.             Next_Line_Num := 0;
  62.         End;
  63.         Up;
  64.     End;
  65.     Goto_Col(Temp_Col);
  66. {Create first line of construct}
  67.     If (For) Then
  68.         Text('OR');
  69.     Else
  70.         Text('HILE');
  71.     End;
  72. {Create a new line}
  73.     Cr;
  74.     If (Temp_Line_Num <> 0) Then
  75. {If line numbers are used, then..}
  76.         Goto_Col(1);
  77.         If (Next_Line_Num <> 0) Then
  78. {If inserting between two numbered lines, then increment next line number by 1
  79. to allow as much room as possible for the body of the construct}
  80.             Text(Str(Temp_Line_Num + 1));
  81.         Else
  82. {Otherwise, increment by the "standard" 10}
  83.             Text(Str(Temp_Line_Num + 10));
  84.         End;
  85.     End;
  86. {Create the last line of the construct}
  87.     Cr;
  88.     If (Temp_Line_Num <> 0) Then
  89.         Goto_Col(1);
  90.         If (Next_Line_Num <> 0) Then
  91. {If inserting between two numbered lines, then number the last line one less
  92. than the next line to allow as much room as possible for the body of the
  93. construct}
  94.             Text(Str(Next_Line_Num - 1));
  95.         Else
  96. {Otherwise, increment by the "standard" 10}
  97.             Text(Str(Temp_Line_Num + 20));
  98.         End;
  99.     End;
  100.     Goto_Col(Temp_Col - 1);
  101. {Insert the proper ending statement}
  102.     If (For) Then
  103.         Text('NEXT');
  104.     Else
  105.         Text('WEND');
  106.     End;
  107.  
  108. {Place cursor in the proper place for the user to begin writing the condition
  109. clause}
  110.     Up;
  111.     Up;
  112.     Eol;
  113.     Right;
  114.     Goto END_OF_MAC;
  115.  
  116. END_OF_MAC:
  117.     Insert_Mode := Temp_Insert;
  118.  
  119. END_MACRO;
  120.  
  121.  
  122. {******************************************************************************}
  123. {                                MULTI-EDIT MACRO                              }
  124. {                                                                              }
  125. {Name: BAS_IND                                                                 }
  126. {                                                                              }
  127. {Discription: Performs semi-smart indenting for BASIC source code.             }
  128. {                                                                              }
  129. {             Looks for the beginning keywords:  For If While Sub Do Def       }
  130. {                   If it finds them it will INDENT                            }
  131. {                                                                                                                                                             }
  132. {                            Looks for the ending keywords:     End Wend Next Then Loop       }
  133. {                                        If it finds them it will UNDENT                            }
  134. {                                                                              }
  135. {               (C) Copyright 1988 by American Cybernetics, Inc.               }
  136. {******************************************************************************}
  137. $MACRO BAS_IND;
  138.     DEF_STR(Temp_String1,Temp_String2,Temp_String3);
  139.     DEF_INT(Temp_Line_Num,Temp_Col1,Temp_Col2,Next_Line_Num,using_lnums,l_num,key_word);
  140.  
  141.     key_word := 1;                                    {initialize key word flag}
  142.     using_lnums := 1;                                 {initialize using line no flag}
  143.  
  144.   If (At_EOL = False) Then                          {If we are not at the end of a line, then}
  145.      Cr;                                              {do a carrige return and exit}
  146.      Goto END_OF_MAC;
  147.     End;
  148.  
  149.     goto_col(1);                                      {go to col 1 and}
  150.     First_Word;                                       {get to first word}
  151.     temp_col1 := C_Col;                               {save col first word is on}
  152.  
  153.     temp_string1 := get_word(' ');
  154.  
  155.     if (length(temp_string1) <> 0)                    {if the line isnt blank convert it to}
  156.         Then                                            {it to an integer to see if they are using}
  157.        if (val(temp_line_num,temp_string1) = 0)       {line numbers if they are you must get the}
  158.          then using_lnums := 0;                                        {next word after the line number }
  159.                     while ((xpos(cur_char,word_delimits,1) <> 0)
  160.                         and (c_col < 40)) do
  161.                       right;
  162.                     end;
  163.                     temp_col2 := c_col;                       {save col first word after line no is on}
  164.                     Temp_String2 := Get_Word(' ');                        {read all letters until you reach a space }
  165.          end;
  166.         end;
  167.  
  168.     if ((using_lnums = 0) and (length(temp_string2) <> 0))                       {if using lnums and tstring2 isn't blank}
  169.        Then temp_string2 := ' ' + remove_space(lower(temp_string2)) + ' '; end;  {remove leading & trailing spaces}
  170.     if ((length(temp_string1)) <> 0)
  171.      then temp_string1 := ' ' + remove_space(lower(temp_string1)) + ' '; end;  {if no lnums remove spaces from tstr1}
  172.  
  173.             If (length(temp_string1) = 0)                {if str1 is blank just do a cr}
  174.                  Then
  175.                     Eol;
  176.                     cr;
  177.                  GOTO_COL(1);
  178.                  end;
  179.  
  180.       If ((length(temp_string2) = 0) and (using_lnums = 0))     {if using line nums & str2 is blank}
  181.                Then                                                   {you just need to write the next line no}
  182.                 call write_next_lnum;
  183.                  end;
  184.  
  185.       If (using_lnums = 0)
  186.                 Then
  187.            if (pos(temp_string2,' for if while sub do def ') <> 0)    {if you find a begin. keyword and }
  188.                 then                                                      {your using line nos you must write}
  189.                                      key_word := 0;                                     {the next line no and indent       }
  190.                                call write_next_lnum;
  191.                                      goto_col(temp_col2);
  192.                             indent;
  193.                         end;
  194.       else if (pos(temp_string1,' for if while sub do def ') <> 0)    {if you find a keyword and not using}
  195.                   then                                                      {line nos just indent }
  196.                                      key_word := 0;
  197.                              eol;
  198.                                cr;
  199.                                goto_col(temp_col1);       {goto where you typed the keyword and go forward}
  200.                              indent;                    {one tab stop}
  201.                         end;
  202.              end;
  203.  
  204.        if (using_lnums = 0)
  205.              then
  206.             if (pos(temp_string2,' next then wend end loop ') <> 0)        {if you find an ending keyword then }
  207.                then                                                         {and your using line nos you must write}
  208.                                      key_word := 0;                                        {the line number go back to the col you}
  209.                              call write_next_lnum;                                 {were at last and undent 1 tab stop}
  210.                           goto_col(temp_col2);
  211.                                undent;
  212.                                      if c_col = 1                                          {If you undent and you were only at the first}
  213.                                           then                                                {tab stop put cursor at the of the number}
  214.                                   while ((xpos(cur_char,word_delimits,1) = 0)) do
  215.                                  right;
  216.                                   end;
  217.                                                 right;
  218.                                             end;
  219.                         end;
  220.       else
  221.             if (pos(temp_string1,' next then wend end loop ') <> 0)
  222.                  then
  223.                                         key_word := 0;
  224.                               eol;
  225.                           cr;
  226.                               goto_col(temp_col1);
  227.                             undent;
  228.                      end;
  229.           end;
  230.  
  231.  if (key_word <> 0)
  232.       Then
  233.           if (using_lnums = 0) then
  234.                      if (length(temp_string2) <> 0)
  235.                        then call write_next_lnum;                {No keywords - with line no's}
  236.                                      goto_col(temp_col2);
  237.                                  end;
  238.        else if (length(temp_string1) <> 0)      {No keywords - no line no's - just text}
  239.                     then
  240.                 eol;
  241.                         cr;
  242.                         goto_col(temp_col1);
  243.                    end;
  244.              end;
  245.    end;
  246.  
  247. goto end_of_mac;
  248.  
  249.   write_next_lnum:                                                    {before writing the next line no go }
  250.         goto_col(1);                                                      {down and check the next line to see if}
  251.     Down;                                                             {another line Number below }
  252.       Temp_String3 := Get_Word(' ');
  253.       Up;
  254.       eol;
  255.       cr;
  256.         goto_col(1);
  257.       If ((Temp_String3 = '') or (Val(Next_Line_Num,Temp_String3) <> 0)) {if there is no line number below}
  258.              Then Text(Str(Temp_Line_Num + 10));                             {just increment the "standard" 10}
  259.               Else Text(Str(Temp_Line_Num + ((Next_Line_Num - Temp_Line_Num) / 2)));{Otherwise make increment approx. halfway}
  260.                  end;                                                                                                                {between the line number above and the below}
  261.         right;
  262.         ret;
  263.  
  264. END_OF_MAC:
  265.     redraw;
  266. END_MACRO;